From 4a99615a609eec2b84bb2341d74fac46a5998137 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Mon, 25 Jun 2018 13:15:50 +0200 Subject: Pass rect and matrix by value in geometry functions. Several things irk me about passing values as const pointers: * They can be NULL, which is not a valid value. * They require explicit temporary variables for storage. * They don't compose easily in a legible manner, requiring weird pointer passing semantics where the variable being assigned is hidden as an argument in the innermost function call. * We can't change the value through the pointer, requiring yet more local variables to hold copies of the input value. In the device interface where we pass a matrix to a function, we often find ourselves making a local copy of the matrix so we can concatenate other transforms to it. This copying is a lot of unnecessary busywork that I hope to eventually avoid by laying the groundwork with this commit. This is a rather large API change, so I apologize for the inconvenience, but I hope the end result and gain in legibility will be worth the pain. --- source/cbz/muimg.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'source/cbz/muimg.c') diff --git a/source/cbz/muimg.c b/source/cbz/muimg.c index 8ef4855b..bc7e6e92 100644 --- a/source/cbz/muimg.c +++ b/source/cbz/muimg.c @@ -36,17 +36,18 @@ img_count_pages(fz_context *ctx, fz_document *doc_) return doc->page_count; } -static fz_rect * -img_bound_page(fz_context *ctx, fz_page *page_, fz_rect *bbox) +static fz_rect +img_bound_page(fz_context *ctx, fz_page *page_) { img_page *page = (img_page*)page_; fz_image *image = page->image; int xres, yres; + fz_rect bbox; fz_image_resolution(image, &xres, &yres); - bbox->x0 = bbox->y0 = 0; - bbox->x1 = image->w * DPI / xres; - bbox->y1 = image->h * DPI / yres; + bbox.x0 = bbox.y0 = 0; + bbox.x1 = image->w * DPI / xres; + bbox.y1 = image->h * DPI / yres; return bbox; } @@ -54,7 +55,7 @@ static void img_run_page(fz_context *ctx, fz_page *page_, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie) { img_page *page = (img_page*)page_; - fz_matrix local_ctm = *ctm; + fz_matrix local_ctm; fz_image *image = page->image; int xres, yres; float w, h; @@ -62,7 +63,7 @@ img_run_page(fz_context *ctx, fz_page *page_, fz_device *dev, const fz_matrix *c fz_image_resolution(image, &xres, &yres); w = image->w * DPI / xres; h = image->h * DPI / yres; - fz_pre_scale(&local_ctm, w, h); + local_ctm = fz_pre_scale(*ctm, w, h); fz_fill_image(ctx, dev, image, &local_ctm, 1, NULL); } -- cgit v1.2.3