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/fitz/draw-mesh.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source/fitz/draw-mesh.c') diff --git a/source/fitz/draw-mesh.c b/source/fitz/draw-mesh.c index a248170e..5a3bef40 100644 --- a/source/fitz/draw-mesh.c +++ b/source/fitz/draw-mesh.c @@ -230,13 +230,13 @@ fz_paint_shade(fz_context *ctx, fz_shade *shade, fz_colorspace *colorspace, cons fz_try(ctx) { - fz_concat(&local_ctm, &shade->matrix, ctm); + local_ctm = fz_concat(shade->matrix, *ctm); if (shade->use_function) { /* We need to use alpha = 1 here, because the shade might not fill * the bbox. */ - temp = fz_new_pixmap_with_bbox(ctx, fz_device_gray(ctx), bbox, NULL, 1); + temp = fz_new_pixmap_with_bbox(ctx, fz_device_gray(ctx), *bbox, NULL, 1); fz_clear_pixmap(ctx, temp); } else @@ -249,7 +249,7 @@ fz_paint_shade(fz_context *ctx, fz_shade *shade, fz_colorspace *colorspace, cons ptd.bbox = bbox; fz_init_cached_color_converter(ctx, &ptd.cc, NULL, temp->colorspace, colorspace, color_params); - fz_process_shade(ctx, shade, &local_ctm, prepare_mesh_vertex, &do_paint_tri, &ptd); + fz_process_shade(ctx, shade, local_ctm, prepare_mesh_vertex, &do_paint_tri, &ptd); if (shade->use_function) { @@ -275,7 +275,7 @@ fz_paint_shade(fz_context *ctx, fz_shade *shade, fz_colorspace *colorspace, cons int n = fz_colorspace_n(ctx, colorspace); /* alpha = 1 here for the same reason as earlier */ - conv = fz_new_pixmap_with_bbox(ctx, colorspace, bbox, NULL, 1); + conv = fz_new_pixmap_with_bbox(ctx, colorspace, *bbox, NULL, 1); d = conv->samples; while (hh--) { @@ -322,7 +322,7 @@ fz_paint_shade(fz_context *ctx, fz_shade *shade, fz_colorspace *colorspace, cons } fz_drop_color_converter(ctx, &cc); - conv = fz_new_pixmap_with_bbox(ctx, dest->colorspace, bbox, dest->seps, 1); + conv = fz_new_pixmap_with_bbox(ctx, dest->colorspace, *bbox, dest->seps, 1); d = conv->samples; da = conv->alpha; while (hh--) -- cgit v1.2.3