#ifndef MUPDF_FITZ_PIXMAP_H1#define MUPDF_FITZ_PIXMAP_H23#include "mupdf/fitz/system.h"4#include "mupdf/fitz/context.h"5#include "mupdf/fitz/math.h"6#include "mupdf/fitz/store.h"7#include "mupdf/fitz/colorspace.h"89/*10Pixmaps represent a set of pixels for a 2 dimensional region of a11plane. Each pixel has n components per pixel, the last of which is12always alpha. The data is in premultiplied alpha when rendering, but13non-premultiplied for colorspace conversions and rescaling.14*/15typedef struct fz_pixmap_s fz_pixmap;1617/*18fz_pixmap_bbox: Return the bounding box for a pixmap.19*/20fz_irect *fz_pixmap_bbox(fz_context *ctx, fz_pixmap *pix, fz_irect *bbox);2122/*23fz_pixmap_width: Return the width of the pixmap in pixels.24*/25int fz_pixmap_width(fz_context *ctx, fz_pixmap *pix);2627/*28fz_pixmap_height: Return the height of the pixmap in pixels.29*/30int fz_pixmap_height(fz_context *ctx, fz_pixmap *pix);3132/*33fz_new_pixmap: Create a new pixmap, with it's origin at (0,0)3435cs: The colorspace to use for the pixmap, or NULL for an alpha36plane/mask.3738w: The width of the pixmap (in pixels)3940h: The height of the pixmap (in pixels)4142Returns a pointer to the new pixmap. Throws exception on failure to43allocate.44*/45fz_pixmap *fz_new_pixmap(fz_context *ctx, fz_colorspace *cs, int w, int h);4647/*48fz_new_pixmap_with_bbox: Create a pixmap of a given size,49location and pixel format.5051The bounding box specifies the size of the created pixmap and52where it will be located. The colorspace determines the number53of components per pixel. Alpha is always present. Pixmaps are54reference counted, so drop references using fz_drop_pixmap.5556colorspace: Colorspace format used for the created pixmap. The57pixmap will keep a reference to the colorspace.5859bbox: Bounding box specifying location/size of created pixmap.6061Returns a pointer to the new pixmap. Throws exception on failure to62allocate.63*/64fz_pixmap *fz_new_pixmap_with_bbox(fz_context *ctx, fz_colorspace *colorspace, const fz_irect *bbox);6566/*67fz_new_pixmap_with_data: Create a new pixmap, with it's origin at68(0,0) using the supplied data block.6970cs: The colorspace to use for the pixmap, or NULL for an alpha71plane/mask.7273w: The width of the pixmap (in pixels)7475h: The height of the pixmap (in pixels)7677samples: The data block to keep the samples in.7879Returns a pointer to the new pixmap. Throws exception on failure to80allocate.81*/82fz_pixmap *fz_new_pixmap_with_data(fz_context *ctx, fz_colorspace *colorspace, int w, int h, unsigned char *samples);8384/*85fz_new_pixmap_with_bbox_and_data: Create a pixmap of a given size,86location and pixel format, using the supplied data block.8788The bounding box specifies the size of the created pixmap and89where it will be located. The colorspace determines the number90of components per pixel. Alpha is always present. Pixmaps are91reference counted, so drop references using fz_drop_pixmap.9293colorspace: Colorspace format used for the created pixmap. The94pixmap will keep a reference to the colorspace.9596bbox: Bounding box specifying location/size of created pixmap.9798samples: The data block to keep the samples in.99100Returns a pointer to the new pixmap. Throws exception on failure to101allocate.102*/103fz_pixmap *fz_new_pixmap_with_bbox_and_data(fz_context *ctx, fz_colorspace *colorspace, const fz_irect *rect, unsigned char *samples);104105/*106fz_keep_pixmap: Take a reference to a pixmap.107108pix: The pixmap to increment the reference for.109110Returns pix. Does not throw exceptions.111*/112fz_pixmap *fz_keep_pixmap(fz_context *ctx, fz_pixmap *pix);113114/*115fz_drop_pixmap: Drop a reference and free a pixmap.116117Decrement the reference count for the pixmap. When no118references remain the pixmap will be freed.119120Does not throw exceptions.121*/122void fz_drop_pixmap(fz_context *ctx, fz_pixmap *pix);123124/*125fz_pixmap_colorspace: Return the colorspace of a pixmap126127Returns colorspace. Does not throw exceptions.128*/129fz_colorspace *fz_pixmap_colorspace(fz_context *ctx, fz_pixmap *pix);130131/*132fz_pixmap_components: Return the number of components in a pixmap.133134Returns the number of components. Does not throw exceptions.135*/136int fz_pixmap_components(fz_context *ctx, fz_pixmap *pix);137138/*139fz_pixmap_samples: Returns a pointer to the pixel data of a pixmap.140141Returns the pointer. Does not throw exceptions.142*/143unsigned char *fz_pixmap_samples(fz_context *ctx, fz_pixmap *pix);144145void fz_pixmap_set_resolution(fz_pixmap *pix, int res);146147/*148fz_clear_pixmap_with_value: Clears a pixmap with the given value.149150pix: The pixmap to clear.151152value: Values in the range 0 to 255 are valid. Each component153sample for each pixel in the pixmap will be set to this value,154while alpha will always be set to 255 (non-transparent).155156Does not throw exceptions.157*/158void fz_clear_pixmap_with_value(fz_context *ctx, fz_pixmap *pix, int value);159160/*161fz_clear_pixmap_with_value: Clears a subrect of a pixmap with the given value.162163pix: The pixmap to clear.164165value: Values in the range 0 to 255 are valid. Each component166sample for each pixel in the pixmap will be set to this value,167while alpha will always be set to 255 (non-transparent).168169r: the rectangle.170171Does not throw exceptions.172*/173void fz_clear_pixmap_rect_with_value(fz_context *ctx, fz_pixmap *pix, int value, const fz_irect *r);174175/*176fz_clear_pixmap_with_value: Sets all components (including alpha) of177all pixels in a pixmap to 0.178179pix: The pixmap to clear.180181Does not throw exceptions.182*/183void fz_clear_pixmap(fz_context *ctx, fz_pixmap *pix);184185/*186fz_invert_pixmap: Invert all the pixels in a pixmap. All components187of all pixels are inverted (except alpha, which is unchanged).188189Does not throw exceptions.190*/191void fz_invert_pixmap(fz_context *ctx, fz_pixmap *pix);192193/*194fz_tint_pixmap: Tint all the pixels in an RGB or Gray pixmap.195196Multiplies all the samples with the input color argument.197198r,g,b: The color to tint with, in 0 to 255 range.199*/200void fz_tint_pixmap(fz_context *ctx, fz_pixmap *pix, int r, int g, int b);201202/*203fz_invert_pixmap: Invert all the pixels in a given rectangle of a204pixmap. All components of all pixels in the rectangle are inverted205(except alpha, which is unchanged).206207Does not throw exceptions.208*/209void fz_invert_pixmap_rect(fz_context *ctx, fz_pixmap *image, const fz_irect *rect);210211/*212fz_gamma_pixmap: Apply gamma correction to a pixmap. All components213of all pixels are modified (except alpha, which is unchanged).214215gamma: The gamma value to apply; 1.0 for no change.216217Does not throw exceptions.218*/219void fz_gamma_pixmap(fz_context *ctx, fz_pixmap *pix, float gamma);220221/*222fz_unmultiply_pixmap: Convert a pixmap from premultiplied to223non-premultiplied format.224225Does not throw exceptions.226*/227void fz_unmultiply_pixmap(fz_context *ctx, fz_pixmap *pix);228229/*230fz_convert_pixmap: Convert from one pixmap to another (assumed to be231the same size, but possibly with a different colorspace).232233dst: the source pixmap.234235src: the destination pixmap.236*/237void fz_convert_pixmap(fz_context *ctx, fz_pixmap *dst, fz_pixmap *src);238239/*240Pixmaps represent a set of pixels for a 2 dimensional region of a241plane. Each pixel has n components per pixel, the last of which is242always alpha. The data is in premultiplied alpha when rendering, but243non-premultiplied for colorspace conversions and rescaling.244245x, y: The minimum x and y coord of the region in pixels.246247w, h: The width and height of the region in pixels.248249n: The number of color components in the image. Always250includes a separate alpha channel. For mask images n=1, for greyscale251(plus alpha) images n=2, for rgb (plus alpha) images n=3.252253interpolate: A boolean flag set to non-zero if the image254will be drawn using linear interpolation, or set to zero if255image will be using nearest neighbour sampling.256257xres, yres: Image resolution in dpi. Default is 96 dpi.258259colorspace: Pointer to a colorspace object describing the colorspace260the pixmap is in. If NULL, the image is a mask.261262samples: A simple block of memory w * h * n bytes of memory in which263the components are stored. The first n bytes are components 0 to n-1264for the pixel at (x,y). Each successive n bytes gives another pixel265in scanline order. Subsequent scanlines follow on with no padding.266267free_samples: Is zero when an application has provided its own268buffer for pixel data through fz_new_pixmap_with_bbox_and_data.269If non-zero the buffer will be freed along with the the pixmap.270*/271struct fz_pixmap_s272{273fz_storable storable;274int x, y, w, h, n;275int interpolate;276int xres, yres;277fz_colorspace *colorspace;278unsigned char *samples;279int free_samples;280};281282void fz_drop_pixmap_imp(fz_context *ctx, fz_storable *pix);283284void fz_copy_pixmap_rect(fz_context *ctx, fz_pixmap *dest, fz_pixmap *src, const fz_irect *r);285void fz_premultiply_pixmap(fz_context *ctx, fz_pixmap *pix);286fz_pixmap *fz_alpha_from_gray(fz_context *ctx, fz_pixmap *gray, int luminosity);287unsigned int fz_pixmap_size(fz_context *ctx, fz_pixmap *pix);288289fz_pixmap *fz_scale_pixmap(fz_context *ctx, fz_pixmap *src, float x, float y, float w, float h, fz_irect *clip);290291typedef struct fz_scale_cache_s fz_scale_cache;292293fz_scale_cache *fz_new_scale_cache(fz_context *ctx);294void fz_drop_scale_cache(fz_context *ctx, fz_scale_cache *cache);295fz_pixmap *fz_scale_pixmap_cached(fz_context *ctx, fz_pixmap *src, float x, float y, float w, float h, const fz_irect *clip, fz_scale_cache *cache_x, fz_scale_cache *cache_y);296297void fz_subsample_pixmap(fz_context *ctx, fz_pixmap *tile, int factor);298299fz_irect *fz_pixmap_bbox_no_ctx(fz_pixmap *src, fz_irect *bbox);300301void fz_decode_tile(fz_context *ctx, fz_pixmap *pix, float *decode);302void fz_decode_indexed_tile(fz_context *ctx, fz_pixmap *pix, float *decode, int maxval);303void fz_unpack_tile(fz_context *ctx, fz_pixmap *dst, unsigned char * restrict src, int n, int depth, int stride, int scale);304305/*306fz_md5_pixmap: Return the md5 digest for a pixmap307*/308void fz_md5_pixmap(fz_context *ctx, fz_pixmap *pixmap, unsigned char digest[16]);309310fz_pixmap *fz_new_pixmap_from_8bpp_data(fz_context *ctx, int x, int y, int w, int h, unsigned char *sp, int span);311fz_pixmap *fz_new_pixmap_from_1bpp_data(fz_context *ctx, int x, int y, int w, int h, unsigned char *sp, int span);312313#endif314315316