diff options
author | Robin Watts <robin.watts@artifex.com> | 2013-08-23 19:24:58 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2013-08-30 16:26:39 +0100 |
commit | 2b2c67836932b1dada7f7f28e42fe4ed06c4e4ed (patch) | |
tree | bed929cca0ac26018ffbc9c98cf177da63562536 /include | |
parent | 8f248600b2834fb121db4990aa756c40da8ddd0e (diff) | |
download | mupdf-2b2c67836932b1dada7f7f28e42fe4ed06c4e4ed.tar.xz |
Use RLE coding scheme for glyph bitmaps.
Rather than generating fz_pixmaps for glyphs, we generate fz_glyphs.
fz_glyphs can either contain a pixmap, or an RLEd representation
(if it's a mask, and it's smaller).
Should take less memory in the cache, and should be faster to plot.
Diffstat (limited to 'include')
-rw-r--r-- | include/mupdf/fitz.h | 1 | ||||
-rw-r--r-- | include/mupdf/fitz/glyph-cache.h | 10 | ||||
-rw-r--r-- | include/mupdf/fitz/glyph.h | 137 | ||||
-rw-r--r-- | include/mupdf/fitz/pixmap.h | 3 |
4 files changed, 146 insertions, 5 deletions
diff --git a/include/mupdf/fitz.h b/include/mupdf/fitz.h index 6edd0d3e..02c5778a 100644 --- a/include/mupdf/fitz.h +++ b/include/mupdf/fitz.h @@ -22,6 +22,7 @@ #include "mupdf/fitz/store.h" #include "mupdf/fitz/colorspace.h" #include "mupdf/fitz/pixmap.h" +#include "mupdf/fitz/glyph.h" #include "mupdf/fitz/bitmap.h" #include "mupdf/fitz/image.h" #include "mupdf/fitz/function.h" diff --git a/include/mupdf/fitz/glyph-cache.h b/include/mupdf/fitz/glyph-cache.h index 81dbd95c..e06889e0 100644 --- a/include/mupdf/fitz/glyph-cache.h +++ b/include/mupdf/fitz/glyph-cache.h @@ -20,11 +20,11 @@ void fz_purge_glyph_cache(fz_context *ctx); fz_path *fz_outline_ft_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *trm); fz_path *fz_outline_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *ctm); -fz_pixmap *fz_render_ft_glyph(fz_context *ctx, fz_font *font, int cid, const fz_matrix *trm, int aa); -fz_pixmap *fz_render_t3_glyph(fz_context *ctx, fz_font *font, int cid, const fz_matrix *trm, fz_colorspace *model, fz_irect scissor); -fz_pixmap *fz_render_ft_stroked_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *trm, const fz_matrix *ctm, fz_stroke_state *state); -fz_pixmap *fz_render_glyph(fz_context *ctx, fz_font*, int, const fz_matrix *, fz_colorspace *model, fz_irect scissor); -fz_pixmap *fz_render_stroked_glyph(fz_context *ctx, fz_font*, int, const fz_matrix *, const fz_matrix *, fz_stroke_state *stroke, fz_irect scissor); +fz_glyph *fz_render_ft_glyph(fz_context *ctx, fz_font *font, int cid, const fz_matrix *trm, int aa); +fz_glyph *fz_render_t3_glyph(fz_context *ctx, fz_font *font, int cid, const fz_matrix *trm, fz_colorspace *model, fz_irect scissor); +fz_glyph *fz_render_ft_stroked_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *trm, const fz_matrix *ctm, fz_stroke_state *state); +fz_glyph *fz_render_glyph(fz_context *ctx, fz_font*, int, const fz_matrix *, fz_colorspace *model, fz_irect scissor); +fz_glyph *fz_render_stroked_glyph(fz_context *ctx, fz_font*, int, const fz_matrix *, const fz_matrix *, fz_stroke_state *stroke, fz_irect scissor); void fz_render_t3_glyph_direct(fz_context *ctx, fz_device *dev, fz_font *font, int gid, const fz_matrix *trm, void *gstate, int nestedDepth); void fz_prepare_t3_glyph(fz_context *ctx, fz_font *font, int gid, int nestedDepth); void fz_dump_glyph_cache_stats(fz_context *ctx); diff --git a/include/mupdf/fitz/glyph.h b/include/mupdf/fitz/glyph.h new file mode 100644 index 00000000..f2cc6cc1 --- /dev/null +++ b/include/mupdf/fitz/glyph.h @@ -0,0 +1,137 @@ +#ifndef MUPDF_FITZ_GLYPH_H +#define MUPDF_FITZ_GLYPH_H + +#include "mupdf/fitz/system.h" +#include "mupdf/fitz/context.h" +#include "mupdf/fitz/math.h" +#include "mupdf/fitz/store.h" +#include "mupdf/fitz/colorspace.h" + +/* + Glyphs represent a run length encoded set of pixels for a 2 + dimensional region of a plane. +*/ +typedef struct fz_glyph_s fz_glyph; + +/* + fz_glyph_bbox: Return the bounding box for a glyph. +*/ +fz_irect *fz_glyph_bbox(fz_context *ctx, fz_glyph *glyph, fz_irect *bbox); + +/* + fz_glyph_width: Return the width of the glyph in pixels. +*/ +int fz_glyph_width(fz_context *ctx, fz_glyph *glyph); + +/* + fz_glyph_height: Return the height of the glyph in pixels. +*/ +int fz_glyph_height(fz_context *ctx, fz_glyph *glyph); + +/* + fz_new_glyph_from_pixmap: Create a new glyph from a pixmap + + Returns a pointer to the new glyph. Throws exception on failure to + allocate. +*/ +fz_glyph *fz_new_glyph_from_pixmap(fz_context *ctx, fz_pixmap *pix); + +/* + fz_new_glyph_from_8bpp_data: Create a new glyph from 8bpp data + + x, y: X and Y position for the glyph + + w, h: Width and Height for the glyph + + sp: Source Pointer to data + + span: Increment from line to line of data + + Returns a pointer to the new glyph. Throws exception on failure to + allocate. +*/ +fz_glyph *fz_new_glyph_from_8bpp_data(fz_context *ctx, int x, int y, int w, int h, unsigned char *sp, int span); + +/* + fz_new_glyph_from_1bpp_data: Create a new glyph from 1bpp data + + x, y: X and Y position for the glyph + + w, h: Width and Height for the glyph + + sp: Source Pointer to data + + span: Increment from line to line of data + + Returns a pointer to the new glyph. Throws exception on failure to + allocate. +*/fz_glyph *fz_new_glyph_from_1bpp_data(fz_context *ctx, int x, int y, int w, int h, unsigned char *sp, int span); + + +/* + fz_keep_glyph: Take a reference to a glyph. + + pix: The glyph to increment the reference for. + + Returns pix. Does not throw exceptions. +*/ +fz_glyph *fz_keep_glyph(fz_context *ctx, fz_glyph *pix); + +/* + fz_drop_glyph: Drop a reference and free a glyph. + + Decrement the reference count for the glyph. When no + references remain the glyph will be freed. + + Does not throw exceptions. +*/ +void fz_drop_glyph(fz_context *ctx, fz_glyph *pix); + +/* + Glyphs represent a set of pixels for a 2 dimensional region of a + plane. + + x, y: The minimum x and y coord of the region in pixels. + + w, h: The width and height of the region in pixels. + + samples: The sample data. The sample data is in a compressed format + designed to give reasonable compression, and to be fast to plot from. + + The first sizeof(int) * h bytes of the table, when interpreted as + ints gives the offset within the data block of that lines data. An + offset of 0 indicates that that line is completely blank. + + The data for individual lines is a sequence of bytes: + 00000000 = end of lines data + LLLLLL00 = extend the length given in the next run by the 6 L bits + given here. + LLLLLL01 = A run of length L+1 transparent pixels. + LLLLLE10 = A run of length L+1 solid pixels. If E then this is the + last run on this line. + LLLLLE11 = A run of length L+1 intermediate pixels followed by L+1 + bytes of literal pixel data. If E then this is the last run + on this line. +*/ +struct fz_glyph_s +{ + fz_storable storable; + int x, y, w, h; + fz_pixmap *pixmap; + int size; + unsigned char data[1]; +}; + +static unsigned int fz_glyph_size(fz_context *ctx, fz_glyph *glyph); + +fz_irect *fz_glyph_bbox_no_ctx(fz_glyph *src, fz_irect *bbox); + +static inline unsigned int +fz_glyph_size(fz_context *ctx, fz_glyph *glyph) +{ + if (glyph == NULL) + return 0; + return sizeof(fz_glyph) + glyph->size + fz_pixmap_size(ctx, glyph->pixmap); +} + +#endif diff --git a/include/mupdf/fitz/pixmap.h b/include/mupdf/fitz/pixmap.h index 6e3a7d61..8be72914 100644 --- a/include/mupdf/fitz/pixmap.h +++ b/include/mupdf/fitz/pixmap.h @@ -300,4 +300,7 @@ void fz_unpack_tile(fz_pixmap *dst, unsigned char * restrict src, int n, int dep */ void fz_md5_pixmap(fz_pixmap *pixmap, unsigned char digest[16]); +fz_pixmap *fz_new_pixmap_from_8bpp_data(fz_context *ctx, int x, int y, int w, int h, unsigned char *sp, int span); +fz_pixmap *fz_new_pixmap_from_1bpp_data(fz_context *ctx, int x, int y, int w, int h, unsigned char *sp, int span); + #endif |