Module Cairo.Image


module Image: sig .. end
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.
val create : format -> width:int -> height:int -> Cairo.Surface.t
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, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t 
Images represented as an array of 8 bytes values.
type data32 = (int32, Bigarray.int32_elt, Bigarray.c_layout) Bigarray.Array2.t 
Images represented as an array of 32 bytes (RGB or RGBA) values.
val create_for_data8 : data8 ->
format -> ?stride:int -> int -> int -> Cairo.Surface.t
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.
val create_for_data32 : ?width:int ->
?height:int -> ?alpha:bool -> data32 -> Cairo.Surface.t
create_for_data32 ?width ?height ?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 and height 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.
val get_data8 : Cairo.Surface.t -> data8
Get the data of the image surface (shared), for direct inspection or modification.
val get_data32 : Cairo.Surface.t -> data32
Get the data of the image surface (shared), for direct inspection or modification. The 1st (resp. 2nd) dimension of the bigarray correspond to the width (resp. height) of the surface.
Raises Invalid_argument if the format is not ARGB32 or RGB24 because the array dimensions would not reflect the image coordinates.
val get_format : Cairo.Surface.t -> format
Get the format of the surface.
val get_width : Cairo.Surface.t -> int
Get the width of the image surface in pixels.
val get_height : Cairo.Surface.t -> int
Get the height of the image surface in pixels.
val get_stride : Cairo.Surface.t -> int
Get the stride of the image surface in bytes.
val output_ppm : Pervasives.out_channel ->
?width:int -> ?height:int -> data32 -> unit
Convenience function to write the subarray of size (width, height) representing an image to the PPM format. The possible alpha channel is ignored.