diff options
Diffstat (limited to 'draw/draw_mesh.c')
-rw-r--r-- | draw/draw_mesh.c | 81 |
1 files changed, 47 insertions, 34 deletions
diff --git a/draw/draw_mesh.c b/draw/draw_mesh.c index ef4ed95b..06c1f55a 100644 --- a/draw/draw_mesh.c +++ b/draw/draw_mesh.c @@ -523,52 +523,65 @@ void fz_paint_shade(fz_context *ctx, fz_shade *shade, fz_matrix ctm, fz_pixmap *dest, fz_bbox bbox) { unsigned char clut[256][FZ_MAX_COLORS]; - fz_pixmap *temp, *conv; + fz_pixmap *temp = NULL; + fz_pixmap *conv = NULL; float color[FZ_MAX_COLORS]; int i, k; - ctm = fz_concat(shade->matrix, ctm); + fz_var(temp); + fz_var(conv); - if (shade->use_function) + fz_try(ctx) { - for (i = 0; i < 256; i++) + ctm = fz_concat(shade->matrix, ctm); + + if (shade->use_function) { - fz_convert_color(ctx, shade->colorspace, shade->function[i], dest->colorspace, color); - for (k = 0; k < dest->colorspace->n; k++) - clut[i][k] = color[k] * 255; - clut[i][k] = shade->function[i][shade->colorspace->n] * 255; + for (i = 0; i < 256; i++) + { + fz_convert_color(ctx, shade->colorspace, shade->function[i], dest->colorspace, color); + for (k = 0; k < dest->colorspace->n; k++) + clut[i][k] = color[k] * 255; + clut[i][k] = shade->function[i][shade->colorspace->n] * 255; + } + conv = fz_new_pixmap_with_rect(ctx, dest->colorspace, bbox); + temp = fz_new_pixmap_with_rect(ctx, fz_device_gray, bbox); + fz_clear_pixmap(temp); + } + else + { + temp = dest; } - conv = fz_new_pixmap_with_rect(ctx, dest->colorspace, bbox); - temp = fz_new_pixmap_with_rect(ctx, fz_device_gray, bbox); - fz_clear_pixmap(temp); - } - else - { - temp = dest; - } - switch (shade->type) - { - case FZ_LINEAR: fz_paint_linear(shade, ctm, temp, bbox); break; - case FZ_RADIAL: fz_paint_radial(shade, ctm, temp, bbox); break; - case FZ_MESH: fz_paint_mesh(ctx, shade, ctm, temp, bbox); break; - } + switch (shade->type) + { + case FZ_LINEAR: fz_paint_linear(shade, ctm, temp, bbox); break; + case FZ_RADIAL: fz_paint_radial(shade, ctm, temp, bbox); break; + case FZ_MESH: fz_paint_mesh(ctx, shade, ctm, temp, bbox); break; + } - if (shade->use_function) - { - unsigned char *s = temp->samples; - unsigned char *d = conv->samples; - int len = temp->w * temp->h; - while (len--) + if (shade->use_function) { - int v = *s++; - int a = fz_mul255(*s++, clut[v][conv->n - 1]); - for (k = 0; k < conv->n - 1; k++) - *d++ = fz_mul255(clut[v][k], a); - *d++ = a; + unsigned char *s = temp->samples; + unsigned char *d = conv->samples; + int len = temp->w * temp->h; + while (len--) + { + int v = *s++; + int a = fz_mul255(*s++, clut[v][conv->n - 1]); + for (k = 0; k < conv->n - 1; k++) + *d++ = fz_mul255(clut[v][k], a); + *d++ = a; + } + fz_paint_pixmap(dest, conv, 255); + fz_drop_pixmap(ctx, conv); + fz_drop_pixmap(ctx, temp); } - fz_paint_pixmap(dest, conv, 255); + } + fz_catch(ctx) + { fz_drop_pixmap(ctx, conv); fz_drop_pixmap(ctx, temp); + fz_rethrow(ctx); } } |