Legend:
Library
Module
Module type
Parameter
Class
Class type
Library
Module
Module type
Parameter
Class
Class type
Image surfaces provide the ability to render to memory buffers either allocated by cairo or by the calling code. The supported image formats are those defined in Cairo.Image.format
.
type format =
| ARGB32
each pixel is a 32-bit quantity, with alpha in the upper 8 bits, then red, then green, then blue. The 32-bit quantities are stored native-endian. Pre-multiplied alpha is used. (That is, 50% transparent red is 0x80800000, not 0x80ff0000.)
*)| RGB24
each pixel is a 32-bit quantity, with the upper 8 bits unused. Red, Green, and Blue are stored in the remaining 24 bits in that order.
*)| A8
each pixel is a 8-bit quantity holding an alpha value.
*)| A1
each pixel is a 1-bit quantity holding an alpha value. Pixels are packed together into 32-bit quantities. The ordering of the bits matches the endianess of the platform. On a big-endian machine, the first pixel is in the uppermost bit, on a little-endian machine the first pixel is in the least-significant bit.
*)This is used to identify the memory format of image data.
Creates an image surface of the specified format and dimensions. Initially the surface contents are all 0. (Specifically, within each pixel, each color or alpha channel belonging to format will be 0. The contents of bits within a pixel, but not belonging to the given format are undefined).
type data8 =
(int, Stdlib.Bigarray.int8_unsigned_elt, Stdlib.Bigarray.c_layout)
Stdlib.Bigarray.Array1.t
Images represented as an array of 8 bytes values.
Images represented as an array of 32 bytes (RGB or RGBA) values.
create_for_data8 data format ?stride width height
creates an image surface for the provided pixel data. The initial contents of buffer will be used as the initial image contents; you must explicitly clear the buffer, using, for example, Cairo.rectangle
and Cairo.fill
if you want it cleared.
create_for_data32 ?w ?h ?alpha data
same as Cairo.Image.create_for_data8
except that the stride will necessarily be according to the bigarray 1st dimension (so that matrix coordinates correspond to pixels) and the width w
and height h
will be by default taken from the bigarray 1st and 2nd dimensions respectively. If alpha
is true (default), the ARGB32
format is selected, otherwise RGB24
is used.
Get the data of the image surface (shared), for direct inspection or modification. A call to Cairo.Surface.mark_dirty
or Cairo.Surface.mark_dirty_rectangle
is required after the data is modified.
Get the data of the image surface (shared), for direct inspection or modification. The 1st (resp. 2nd) dimension of the bigarray correspond to the height (resp. width) of the surface. A call to Cairo.Surface.mark_dirty
or Cairo.Surface.mark_dirty_rectangle
is required after the data is modified.
val get_width : Surface.t -> int
Get the width of the image surface in pixels.
val get_height : Surface.t -> int
Get the height of the image surface in pixels.
val get_stride : Surface.t -> int
Get the stride of the image surface in bytes. Note that in order to convert this stride in bytes to a stride in the bigarray indices, the type of the surface has to be taken into account: for ARGB32
and RGB24
, the stride has to be divided by 4.
val stride_for_width : format -> int -> int
stride_for_width format w
a stride value that will respect all alignment requirements of the accelerated image-rendering code within cairo. See create_for_data8
.
val output_ppm : Stdlib.out_channel -> ?w:int -> ?h:int -> data32 -> unit
output_ppm ch width height data
convenience function to write the subarray of size (width
, height
) representing an image to the PPM format. The possible alpha channel is ignored.