cairo::image_surface
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::format_t.
Index
Functions
fn create(format: cairo::format_t, width: int, height: int) (*cairo::surface_t | cairo::error);
fn create_for_data(data: *u8, format: cairo::format_t, width: int, height: int, stride: int) (*cairo::surface_t | cairo::error);
fn create_from_png(filename: str) (*cairo::surface_t | cairo::error);
fn get_data(surface: *cairo::surface_t) (*u8 | cairo::error);
fn get_format(surface: *cairo::surface_t) cairo::format_t;
fn get_height(surface: *cairo::surface_t) int;
fn get_stride(surface: *cairo::surface_t) int;
fn get_width(surface: *cairo::surface_t) int;
Functions
fn create
fn create(format: cairo::format_t, width: int, height: int) (*cairo::surface_t | cairo::error);
Creates an image surface of the specified format and dimensions. Initially the surface contents are set to 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).
Parameters
- format: cairo::format_t of pixels in the surface to create
- width: width of the surface, in pixels
- height: height of the surface, in pixels
Returns the newly created surface. The caller owns the surface and should call cairo::surface::destroy when done with it. If an error such as out of memory occurs, cairo::error is returned instead.
fn create_for_data
fn create_for_data(data: *u8, format: cairo::format_t, width: int, height: int, stride: int) (*cairo::surface_t | cairo::error);
XXX: Creates an image surface for the provided pixel data. The output buffer must be kept around until the cairo::surface_t is destroyed or cairo::surface::finish 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, cairo::rectangle and cairo::fill if you want it cleared.
Note that the stride may be larger than width*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 format_stride_for_width 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 format_stride_for_width for example code.
Parameters
- 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: the format of pixels in the buffer
- width: the width of the image to be stored in the buffer
- height: the height of the image to be stored in the buffer
- stride: the number of bytes between the start of rows in the buffer as allocated. This value should always be computed by format_stride_for_width before allocating the data buffer.
Returns the newly created surface. The caller owns the surface and should call cairo::surface::destroy when done with it. In case of an error such as out of memory or an invalid stride value, cairo::error is returned instead.
See cairo::surface::set_user_data for a means of attaching a destroy-notification fallback to the surface if necessary.
fn create_from_png
fn create_from_png(filename: str) (*cairo::surface_t | cairo::error);
Returns a new cairo::surface_t initialized with the contents of the PNG file, or a cairo::error if any error occurred.
fn get_data
fn get_data(surface: *cairo::surface_t) (*u8 | cairo::error);
XXX: Get a pointer to the data of the image surface, for direct inspection or modification.
A call to cairo::surface::flush is required before accessing the pixel data to ensure that all pending drawing operations are finished. A call to cairo::surface::mark_dirty is required after the data is modified.
Returns a pointer to the image data of this surface or cairo::error if surface is not an image surface, or if cairo::surface::finish has been called.
fn get_format(surface: *cairo::surface_t) cairo::format_t;
Get the format cairo::format_t of the surface.
fn get_height
fn get_height(surface: *cairo::surface_t) int;
Get the height of the image surface in pixels.
fn get_stride
fn get_stride(surface: *cairo::surface_t) int;
Returns the stride of the image surface in bytes (or 0 if surface is not an image surface). The stride is the distance in bytes from the beginning of one row of the image data to the beginning of the next row.
fn get_width
fn get_width(surface: *cairo::surface_t) int;
Get the width of the image surface in pixels.