summaryrefslogtreecommitdiff
path: root/source/pdf/pdf-shade.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2018-06-25 13:15:50 +0200
committerTor Andersson <tor.andersson@artifex.com>2018-07-05 15:32:34 +0200
commit4a99615a609eec2b84bb2341d74fac46a5998137 (patch)
tree486eacff07448e4c655df1fa1bcb20df709dd8df /source/pdf/pdf-shade.c
parent2aa62902447760764e7a763dea322145d9c4808c (diff)
downloadmupdf-4a99615a609eec2b84bb2341d74fac46a5998137.tar.xz
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.
Diffstat (limited to 'source/pdf/pdf-shade.c')
-rw-r--r--source/pdf/pdf-shade.c15
1 files changed, 3 insertions, 12 deletions
diff --git a/source/pdf/pdf-shade.c b/source/pdf/pdf-shade.c
index 5476c8b8..d34e8440 100644
--- a/source/pdf/pdf-shade.c
+++ b/source/pdf/pdf-shade.c
@@ -54,7 +54,6 @@ pdf_load_function_based_shading(fz_context *ctx, pdf_document *doc, fz_shade *sh
pdf_obj *obj;
float x0, y0, x1, y1;
float fv[2];
- fz_matrix matrix;
int xx, yy;
float *p;
int n = fz_colorspace_n(ctx, shade->colorspace);
@@ -70,12 +69,7 @@ pdf_load_function_based_shading(fz_context *ctx, pdf_document *doc, fz_shade *sh
y1 = pdf_array_get_real(ctx, obj, 3);
}
- obj = pdf_dict_get(ctx, dict, PDF_NAME(Matrix));
- if (obj)
- pdf_to_matrix(ctx, obj, &matrix);
- else
- matrix = fz_identity;
- shade->u.f.matrix = matrix;
+ shade->u.f.matrix = pdf_to_matrix(ctx, pdf_dict_get(ctx, dict, PDF_NAME(Matrix)));
shade->u.f.xdivs = FUNSEGS;
shade->u.f.ydivs = FUNSEGS;
shade->u.f.fn_vals = fz_malloc(ctx, (FUNSEGS+1)*(FUNSEGS+1)*n*sizeof(float));
@@ -346,7 +340,7 @@ pdf_load_shading_dict(fz_context *ctx, pdf_document *doc, pdf_obj *dict, const f
obj = pdf_dict_get(ctx, dict, PDF_NAME(BBox));
if (pdf_is_array(ctx, obj))
- pdf_to_rect(ctx, obj, &shade->bbox);
+ shade->bbox = pdf_to_rect(ctx, obj);
obj = pdf_dict_get(ctx, dict, PDF_NAME(Function));
if (pdf_is_dict(ctx, obj))
@@ -449,10 +443,7 @@ pdf_load_shading(fz_context *ctx, pdf_document *doc, pdf_obj *dict)
if (pdf_dict_get(ctx, dict, PDF_NAME(PatternType)))
{
obj = pdf_dict_get(ctx, dict, PDF_NAME(Matrix));
- if (obj)
- pdf_to_matrix(ctx, obj, &mat);
- else
- mat = fz_identity;
+ mat = pdf_to_matrix(ctx, obj);
obj = pdf_dict_get(ctx, dict, PDF_NAME(ExtGState));
if (obj)