summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2015-07-13 16:23:14 +0100
committerRobin Watts <robin.watts@artifex.com>2015-07-20 17:19:03 +0100
commit269fdfce2527cbba02e68d658af3f4b92ef40be0 (patch)
treec75e9e4abdae745c64f98eaafa86d572e747f536 /include
parentd8353609755104010afaf3e1967a36959f28c5dc (diff)
downloadmupdf-269fdfce2527cbba02e68d658af3f4b92ef40be0.tar.xz
Improve Grid fitting of images for .gproof files.
By default in MuPDF, when we render an axis aligned image, we 'gridfit' it. This is a heuristic used to improve the rendering of tiled images, and avoid the background showing through on the antialiased edges. The general algorithm we use is to expand any image outwards so that it completely covers any pixels that it touches any part of. This is 'safe' in that we never cause any pixels to not be covered that should otherwise be so, and is important when we have images that are aligned with (say) line art rectangles. For gproof files though, this gives nasty results - because we have multiple images tiled across the page all exactly abutting, in most cases the edges will not be on exact integer coordinates. This means we expand both images and 1 (destination) pixel is lost. This severely hurts the rendering (in particular on text based pages). We therefore introduce a new type of grid fitting, where we simply align the edges of images to the closest integer pixel. This is safe because we know that neighbouring images will be adjusted identically and edges will stay coincident. We enable/disable this behaviour through a new device flag, and make the gproof interpreter set/clear this flag when generating the page - thus normal rendering is unaffected. We *could* have just poked the dev->flags fields directly, but that would require magic in the display list device to check for them being set/unset and to poke the dev->flags fields on playback, so instead we introduce a new fz_render_flags function (that calls a device function) to set/unset flags. The other attraction of this is that if we ever have devices that 'filter', we can neatly handle passing flag changes on with those. Currently the display list implementation only copes with set/clear of the FZ_DEVFLAG_GRIDFIT_AS_TILED option. We only readily have 6 bits available to us, so we'll just extend this as required if we add new render flags.
Diffstat (limited to 'include')
-rw-r--r--include/mupdf/fitz/device.h4
-rw-r--r--include/mupdf/fitz/math.h2
2 files changed, 5 insertions, 1 deletions
diff --git a/include/mupdf/fitz/device.h b/include/mupdf/fitz/device.h
index ac1c15a5..e3b17fc6 100644
--- a/include/mupdf/fitz/device.h
+++ b/include/mupdf/fitz/device.h
@@ -41,6 +41,7 @@ enum
* undefined, but that causes problems; do we assume that it should
* always be set to non-dashing at the start of every glyph? */
FZ_DEVFLAG_BBOX_DEFINED = 2048,
+ FZ_DEVFLAG_GRIDFIT_AS_TILED = 4096,
};
enum
@@ -131,6 +132,8 @@ struct fz_device_s
int (*begin_tile)(fz_context *, fz_device *, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm, int id);
void (*end_tile)(fz_context *, fz_device *);
+ void (*render_flags)(fz_context *, fz_device *, int set, int clear);
+
fz_rect d1_rect;
int error_depth;
@@ -165,6 +168,7 @@ void fz_end_group(fz_context *ctx, fz_device *dev);
void fz_begin_tile(fz_context *ctx, fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm);
int fz_begin_tile_id(fz_context *ctx, fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm, int id);
void fz_end_tile(fz_context *ctx, fz_device *dev);
+void fz_render_flags(fz_context *ctx, fz_device *dev, int set, int clear);
void *fz_new_device(fz_context *ctx, int size);
diff --git a/include/mupdf/fitz/math.h b/include/mupdf/fitz/math.h
index 9e413b7c..f16b3627 100644
--- a/include/mupdf/fitz/math.h
+++ b/include/mupdf/fitz/math.h
@@ -607,7 +607,7 @@ fz_rect *fz_transform_rect(fz_rect *restrict rect, const fz_matrix *restrict tra
*/
void fz_normalize_vector(fz_point *p);
-void fz_gridfit_matrix(fz_matrix *m);
+void fz_gridfit_matrix(int as_tiled, fz_matrix *m);
float fz_matrix_max_expansion(const fz_matrix *m);