diff options
author | Sebastian Rasmussen <sebras@hotmail.com> | 2008-08-21 19:02:43 +0200 |
---|---|---|
committer | Sebastian Rasmussen <sebras@hotmail.com> | 2008-08-21 19:02:43 +0200 |
commit | e739f8220e3491f1f2038cbbe8ad0eb1ff2ce115 (patch) | |
tree | 0bccce803c5067ee100569a6e15dbc48a08d0f46 | |
parent | 8ab57f80f85f106c78eb95dcbd72ccd31e94f3d7 (diff) | |
download | mupdf-e739f8220e3491f1f2038cbbe8ad0eb1ff2ce115.tar.xz |
Dynamically grow triangle mesh for type 4 shadings instead of hardcoding its size.
-rw-r--r-- | mupdf/pdf_shade4.c | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/mupdf/pdf_shade4.c b/mupdf/pdf_shade4.c index 2f546119..358d9a15 100644 --- a/mupdf/pdf_shade4.c +++ b/mupdf/pdf_shade4.c @@ -9,6 +9,23 @@ struct pdf_tensorpatch_s { float color[4][FZ_MAXCOLORS]; }; +static fz_error * +growshademesh(fz_shade *shade, int amount) +{ + float *newmesh; + int newcap; + + newcap = shade->meshcap + amount; + newmesh = fz_realloc(shade->mesh, sizeof(float) * newcap); + if (!newmesh) + return fz_outofmem; + + shade->mesh = newmesh; + shade->meshcap = newcap; + + return fz_okay; +} + fz_error * pdf_loadtype4shade(fz_shade *shade, pdf_xref *xref, fz_obj *shading, fz_obj *ref) { @@ -292,17 +309,24 @@ pdf_loadtype5shade(fz_shade *shade, pdf_xref *xref, fz_obj *shading, fz_obj *ref #define ADD_VERTEX(idx) \ {\ int z;\ + if (shade->meshlen + 2 + shade->cs->n >= shade->meshcap) \ + { \ + error = growshademesh(shade, shade->meshcap + 1024); \ + if (error) \ + goto cleanup; \ + } \ shade->mesh[j++] = x[idx];\ shade->mesh[j++] = y[idx];\ - for (z = 0; z < shade->cs->n; ++z) {\ + for (z = 0; z < shade->cs->n; ++z) \ shade->mesh[j++] = c[z][idx];\ - }\ + shade->meshlen += 2 + shade->cs->n; \ }\ vpc = q; - shade->meshcap = 0; - shade->mesh = fz_malloc(sizeof(float) * 1024); + shade->meshlen = 0; + shade->meshcap = 1024; + shade->mesh = fz_malloc(sizeof(float) * shade->meshcap); if (!shade->mesh) { error = fz_outofmem; goto cleanup; @@ -321,7 +345,8 @@ pdf_loadtype5shade(fz_shade *shade, pdf_xref *xref, fz_obj *shading, fz_obj *ref } } - shade->meshlen = j / n / 3; + shade->meshlen /= n; + shade->meshlen /= 3; fz_free(x); fz_free(y); @@ -470,23 +495,6 @@ split_stripe(pdf_tensorpatch *s0, pdf_tensorpatch *s1, const pdf_tensorpatch *p) copycolor(s1->color[3], p->color[3]); } -static fz_error * -growshademesh(fz_shade *shade, int amount) -{ - float *newmesh; - int newcap; - - newcap = shade->meshcap + amount; - newmesh = fz_realloc(shade->mesh, sizeof(float) * newcap); - if (!newmesh) - return fz_outofmem; - - shade->mesh = newmesh; - shade->meshcap = newcap; - - return fz_okay; -} - static inline int setvertex(float *mesh, fz_point pt, float *color, int ptr, int ncomp) { int i; |