summaryrefslogtreecommitdiff
path: root/cbz
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2013-01-25 19:24:49 +0000
committerRobin Watts <robin.watts@artifex.com>2013-02-06 19:24:12 +0000
commitd3aa37962470253083714b5092a1ba759f674d47 (patch)
treeec60a0857cd3d44d3db5bc0c95aa69335b6b2d47 /cbz
parentc42dac496e0994c4253eb50ce67ceaec864ed379 (diff)
downloadmupdf-d3aa37962470253083714b5092a1ba759f674d47.tar.xz
Change to pass structures by reference rather than value.
This is faster on ARM in particular. The primary changes involve fz_matrix, fz_rect and fz_bbox. Rather than passing 'fz_rect r' into a function, we now consistently pass 'const fz_rect *r'. Where a rect is passed in and modified, we miss the 'const' off. Where possible, we return the pointer to the modified structure to allow 'chaining' of expressions. The basic upshot of this work is that we do far fewer copies of rectangle/matrix structures, and all the copies we do are explicit. This has opened the way to other optimisations, also performed in this commit. Rather than using expressions like: fz_concat(fz_scale(sx, sy), fz_translate(tx, ty)) we now have fz_pre_{scale,translate,rotate} functions. These can be implemented much more efficiently than doing the fully fledged matrix multiplication that fz_concat requires. We add fz_rect_{min,max} functions to return pointers to the min/max points of a rect. These can be used to in transformations to directly manipulate values. With a little casting in the path transformation code we can avoid more needless copying. We rename fz_widget_bbox to the more consistent fz_bound_widget.
Diffstat (limited to 'cbz')
-rw-r--r--cbz/mucbz.c18
-rw-r--r--cbz/mucbz.h4
2 files changed, 11 insertions, 11 deletions
diff --git a/cbz/mucbz.c b/cbz/mucbz.c
index 101a3d8d..05119938 100644
--- a/cbz/mucbz.c
+++ b/cbz/mucbz.c
@@ -436,25 +436,25 @@ cbz_free_page(cbz_document *doc, cbz_page *page)
fz_free(doc->ctx, page);
}
-fz_rect
-cbz_bound_page(cbz_document *doc, cbz_page *page)
+fz_rect *
+cbz_bound_page(cbz_document *doc, cbz_page *page, fz_rect *bbox)
{
cbz_image *image = page->image;
- fz_rect bbox;
- bbox.x0 = bbox.y0 = 0;
- bbox.x1 = image->base.w * DPI / image->xres;
- bbox.y1 = image->base.h * DPI / image->yres;
+ bbox->x0 = bbox->y0 = 0;
+ bbox->x1 = image->base.w * DPI / image->xres;
+ bbox->y1 = image->base.h * DPI / image->yres;
return bbox;
}
void
-cbz_run_page(cbz_document *doc, cbz_page *page, fz_device *dev, fz_matrix ctm, fz_cookie *cookie)
+cbz_run_page(cbz_document *doc, cbz_page *page, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie)
{
+ fz_matrix local_ctm = *ctm;
cbz_image *image = page->image;
float w = image->base.w * DPI / image->xres;
float h = image->base.h * DPI / image->yres;
- ctm = fz_concat(fz_scale(w, h), ctm);
- fz_fill_image(dev, &image->base, ctm, 1);
+ fz_pre_scale(&local_ctm, w, h);
+ fz_fill_image(dev, &image->base, &local_ctm, 1);
}
static int
diff --git a/cbz/mucbz.h b/cbz/mucbz.h
index 24a40315..0dd47b6e 100644
--- a/cbz/mucbz.h
+++ b/cbz/mucbz.h
@@ -44,8 +44,8 @@ void cbz_close_document(cbz_document *doc);
int cbz_count_pages(cbz_document *doc);
cbz_page *cbz_load_page(cbz_document *doc, int number);
-fz_rect cbz_bound_page(cbz_document *doc, cbz_page *page);
+fz_rect *cbz_bound_page(cbz_document *doc, cbz_page *page, fz_rect *rect);
void cbz_free_page(cbz_document *doc, cbz_page *page);
-void cbz_run_page(cbz_document *doc, cbz_page *page, fz_device *dev, fz_matrix ctm, fz_cookie *cookie);
+void cbz_run_page(cbz_document *doc, cbz_page *page, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie);
#endif