diff options
Diffstat (limited to 'draw')
-rw-r--r-- | draw/draw_device.c | 48 | ||||
-rw-r--r-- | draw/draw_edge.c | 2 | ||||
-rw-r--r-- | draw/draw_mesh.c | 81 |
3 files changed, 79 insertions, 52 deletions
diff --git a/draw/draw_device.c b/draw/draw_device.c index 0a1cc812..5ee84d4f 100644 --- a/draw/draw_device.c +++ b/draw/draw_device.c @@ -1531,25 +1531,37 @@ fz_draw_free_user(fz_device *devp) fz_device * fz_new_draw_device(fz_context *ctx, fz_glyph_cache *cache, fz_pixmap *dest) { - fz_device *dev; + fz_device *dev = NULL; fz_draw_device *ddev = fz_malloc_struct(ctx, fz_draw_device); - ddev->cache = cache; - ddev->gel = fz_new_gel(ctx); - ddev->dest = dest; - ddev->shape = NULL; - ddev->top = 0; - ddev->blendmode = 0; - ddev->flags = 0; - ddev->ctx = ctx; - ddev->stack = &ddev->init_stack[0]; - ddev->stack_max = STACK_SIZE; - - ddev->scissor.x0 = dest->x; - ddev->scissor.y0 = dest->y; - ddev->scissor.x1 = dest->x + dest->w; - ddev->scissor.y1 = dest->y + dest->h; - - dev = fz_new_device(ctx, ddev); + ddev->gel = NULL; + + fz_var(dev); + fz_try(ctx) + { + ddev->cache = cache; + ddev->gel = fz_new_gel(ctx); + ddev->dest = dest; + ddev->shape = NULL; + ddev->top = 0; + ddev->blendmode = 0; + ddev->flags = 0; + ddev->ctx = ctx; + ddev->stack = &ddev->init_stack[0]; + ddev->stack_max = STACK_SIZE; + + ddev->scissor.x0 = dest->x; + ddev->scissor.y0 = dest->y; + ddev->scissor.x1 = dest->x + dest->w; + ddev->scissor.y1 = dest->y + dest->h; + + dev = fz_new_device(ctx, ddev); + } + fz_catch(ctx) + { + fz_free_gel(ddev->gel); + fz_free(ctx, ddev); + fz_rethrow(ctx); + } dev->free_user = fz_draw_free_user; dev->fill_path = fz_draw_fill_path; diff --git a/draw/draw_edge.c b/draw/draw_edge.c index 952050fa..76187bef 100644 --- a/draw/draw_edge.c +++ b/draw/draw_edge.c @@ -222,6 +222,8 @@ fz_reset_gel(fz_gel *gel, fz_bbox clip) void fz_free_gel(fz_gel *gel) { + if (gel == NULL) + return; fz_free(gel->ctx, gel->active); fz_free(gel->ctx, gel->edges); fz_free(gel->ctx, gel); 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); } } |