Cairo.Image
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 =
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.
type data32 =
( int32, Stdlib.Bigarray.int32_elt, Stdlib.Bigarray.c_layout )
Stdlib.Bigarray.Array2.t
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 be set so that data.{y,x}
refers to the pixel (x
,y
) (where (0,0) is the top left pixel and the Y axis is directed downwards).
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.