Package: cairo

Function cairo:image-surface-create-for-data

Lambda List

cairo:image-surface-create-for-data (data format width height stride)

Arguments

data -- a pointer to a buffer supplied by the application in which to write contents, this pointer must be suitably aligned for any kind of variable, for example, a pointer returned by malloc()
format -- a cairo:format-t value for the format of pixels in the surface to create
width -- an integer for the width of the image to be stored in the buffer
height -- an integer for the height of the image to be stored in the buffer
stride -- an integer for the number of bytes between the start of rows in the buffer as allocated, this value should always be computed by the cairo:format-stride-for-width function before allocating the data buffer

Return Value

The newly created cairo:surface-t instance. The caller owns the surface and should call the cairo:surface-destroy function when done with it. This function always returns a valid surface, but it will return a "nil" surface in the case of an error such as out of memory or an invalid stride value. In case of invalid stride value the error status of the returned surface will be :invalid-stride. You can use the cairo:surface-status function to check for this.

Details

Creates an image surface for the provided pixel data. The output buffer must be kept around until the Cairo surface is destroyed or the cairo:surface-finish function is called on the surface. The initial contents of data will be used as the initial image contents. You must explicitly clear the buffer, using, for example, the cairo:rectangle and cairo:fill functions if you want it cleared.

Note that the stride may be larger than width x bytes per pixel to provide proper alignment for each pixel and row. This alignment is required to allow high-performance rendering within Cairo. The correct way to obtain a legal stride value is to call the cairo:format-stride-for-width function with the desired format and maximum image width value, and then use the resulting stride value to allocate the data and to create the image surface. See the cairo:format-stride-for-width function for example code.
 

See also

2025-1-29