19.3 Creating Images
To create an image from a standard type, simply call the appropriate function. For
example, if you have a fz_buffer with the source data:
/* fz_new_image_from_buffer: Create a new image from a buffer of data, inferring its type from the format of the data. */ fz_image *fz_new_image_from_buffer(fz_context *ctx, fz_buffer *buffer);
If the data is in a file, use:
/* fz_image_from_file: Create a new image from the contents of a file, inferring its type from the format of the data. */ fz_image *fz_new_image_from_file(fz_context *ctx, const char *path);
This loads the data into memory, and calls fz_new_image_from_buffer
internally.
If the data cannot be recognised from its header, and more information is required,
then the data can be formed in a fz_compressed_buffer, and an image created
with:
/* fz_new_image_from_compressed_buffer: Create an image based on the data in the supplied compressed buffer. w,h: Width and height of the created image. bpc: Bits per component. colorspace: The colorspace (determines the number of components, and any color conversions required while decoding). xres, yres: The X and Y resolutions respectively. interpolate: 1 if interpolation should be used when decoding this image, 0 otherwise. imagemask: 1 if this is an imagemask (i.e. transparent), 0 otherwise. decode: NULL, or a pointer to to a decode array. The default decode array is [0 1] (repeated n times, for n color components). colorkey: NULL, or a pointer to a colorkey array. The default colorkey array is [0 255] (repeatd n times, for n color components). buffer: Buffer of compressed data and compression parameters. Ownership of this reference is passed in. mask: NULL, or another image to use as a mask for this one. Supplying a masked image as a mask to another image is illegal! */ fz_image *fz_new_image_from_compressed_buffer(fz_context *ctx, int w, int h, int bpc, fz_colorspace *colorspace, int xres, int yres, int interpolate, int imagemask, float *decode, int *colorkey, fz_compressed_buffer *buffer, fz_image *mask);
Finally, if we have a decoded fz_pixmap, we can form a new image from
it:
/* fz_new_image_from_pixmap: Create an image from the given pixmap. pixmap: The pixmap to base the image upon. A new reference to this is taken. mask: NULL, or another image to use as a mask for this one. A new reference is taken to this image. Supplying a masked image as a mask to another image is illegal! */ fz_image *fz_new_image_from_pixmap(fz_context *ctx, fz_pixmap *pixmap, fz_image *mask);