summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2011-12-17 11:16:22 +0000
committerRobin Watts <robin.watts@artifex.com>2011-12-17 11:16:22 +0000
commit880ed0a3dd992d4ab6b8f1d73f862fb930dc2eaa (patch)
treeaa2d80d55cc66f9be936ea4d1459130e1d7be258
parentb20c8c628feab388f5d9b738326b8fbc35d8a742 (diff)
downloadmupdf-880ed0a3dd992d4ab6b8f1d73f862fb930dc2eaa.tar.xz
More Memory Squeezing fixes.
-rw-r--r--draw/draw_device.c48
-rw-r--r--draw/draw_edge.c2
-rw-r--r--draw/draw_mesh.c81
-rw-r--r--fitz/res_pixmap.c12
4 files changed, 89 insertions, 54 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);
}
}
diff --git a/fitz/res_pixmap.c b/fitz/res_pixmap.c
index 1f81e0e1..99132a31 100644
--- a/fitz/res_pixmap.c
+++ b/fitz/res_pixmap.c
@@ -50,14 +50,22 @@ fz_new_pixmap_with_data(fz_context *ctx, fz_colorspace *colorspace, int w, int h
pix->n = 1 + colorspace->n;
}
+ pix->samples = samples;
if (samples)
{
- pix->samples = samples;
pix->free_samples = 0;
}
else
{
- pix->samples = fz_malloc_array(ctx, pix->h, pix->w * pix->n);
+ fz_try(ctx)
+ {
+ pix->samples = fz_malloc_array(ctx, pix->h, pix->w * pix->n);
+ }
+ fz_catch(ctx)
+ {
+ fz_free(ctx, pix);
+ fz_rethrow(ctx);
+ }
pix->free_samples = 1;
}