package cairo2
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Module Cairo.Image
Source
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).
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 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.
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.
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
.
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.