summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2012-10-01 16:55:08 +0100
committerRobin Watts <robin.watts@artifex.com>2012-10-05 15:51:26 +0100
commit8aa48c0f5766a0d62489cb42225cd03f3d1a2a62 (patch)
tree151cd16ac806c00c2ff84f22a730bb90b83b34c8
parent9463d7a87f46c4f50cb1074424c9c3ecda7a5da1 (diff)
downloadmupdf-8aa48c0f5766a0d62489cb42225cd03f3d1a2a62.tar.xz
Make shadings hold the data streams compressed.
This reduces memory use by another 10% on the 2 testfiles mentioned in the previous commit (see bug 693330).
-rw-r--r--fitz/fitz-internal.h4
-rw-r--r--fitz/res_shade.c10
-rw-r--r--fitz/stm_comp_buf.c10
-rw-r--r--pdf/pdf_shade.c26
4 files changed, 24 insertions, 26 deletions
diff --git a/fitz/fitz-internal.h b/fitz/fitz-internal.h
index 5c9270a1..b34f27f5 100644
--- a/fitz/fitz-internal.h
+++ b/fitz/fitz-internal.h
@@ -697,7 +697,9 @@ fz_bbox fz_pixmap_bbox_no_ctx(fz_pixmap *src);
typedef struct fz_compression_params_s fz_compression_params;
typedef struct fz_compressed_buffer_s fz_compressed_buffer;
+unsigned int fz_compressed_buffer_size(fz_compressed_buffer *buffer);
+fz_stream *fz_open_compressed_buffer(fz_context *ctx, fz_compressed_buffer *);
fz_stream *fz_open_image_decomp_stream(fz_context *ctx, fz_compressed_buffer *, int *factor);
enum
@@ -1077,7 +1079,7 @@ struct fz_shade_s
} f;
} u;
- fz_buffer *buffer;
+ fz_compressed_buffer *buffer;
};
fz_shade *fz_keep_shade(fz_context *ctx, fz_shade *shade);
diff --git a/fitz/res_shade.c b/fitz/res_shade.c
index 80acbcf8..aa53a63b 100644
--- a/fitz/res_shade.c
+++ b/fitz/res_shade.c
@@ -249,7 +249,7 @@ static inline float read_sample(fz_stream *stream, int bits, float min, float ma
static void
fz_mesh_type4_process(fz_context *ctx, fz_shade *shade, fz_matrix ctm, fz_mesh_processor *painter)
{
- fz_stream *stream = fz_open_buffer(ctx, shade->buffer);
+ fz_stream *stream = fz_open_compressed_buffer(ctx, shade->buffer);
fz_vertex v[4];
fz_vertex *va = &v[0];
fz_vertex *vb = &v[1];
@@ -328,7 +328,7 @@ fz_mesh_type4_process(fz_context *ctx, fz_shade *shade, fz_matrix ctm, fz_mesh_p
static void
fz_mesh_type5_process(fz_context *ctx, fz_shade *shade, fz_matrix ctm, fz_mesh_processor *painter)
{
- fz_stream *stream = fz_open_buffer(ctx, shade->buffer);
+ fz_stream *stream = fz_open_compressed_buffer(ctx, shade->buffer);
fz_vertex *buf = NULL;
fz_vertex *ref = NULL;
int first;
@@ -645,7 +645,7 @@ make_tensor_patch(tensor_patch *p, int type, fz_point *pt)
static void
fz_mesh_type6_process(fz_context *ctx, fz_shade *shade, fz_matrix ctm, fz_mesh_processor *painter)
{
- fz_stream *stream = fz_open_buffer(ctx, shade->buffer);
+ fz_stream *stream = fz_open_compressed_buffer(ctx, shade->buffer);
int haspatch, hasprevpatch;
float prevc[4][FZ_MAX_COLORS];
fz_point prevp[12];
@@ -773,7 +773,7 @@ fz_mesh_type6_process(fz_context *ctx, fz_shade *shade, fz_matrix ctm, fz_mesh_p
static void
fz_mesh_type7_process(fz_context *ctx, fz_shade *shade, fz_matrix ctm, fz_mesh_processor *painter)
{
- fz_stream *stream = fz_open_buffer(ctx, shade->buffer);
+ fz_stream *stream = fz_open_compressed_buffer(ctx, shade->buffer);
int bpflag = shade->u.m.bpflag;
int bpcoord = shade->u.m.bpcoord;
int bpcomp = shade->u.m.bpcomp;
@@ -942,7 +942,7 @@ fz_free_shade_imp(fz_context *ctx, fz_storable *shade_)
fz_drop_colorspace(ctx, shade->colorspace);
if (shade->type == FZ_FUNCTION_BASED)
fz_free(ctx, shade->u.f.fn_vals);
- fz_drop_buffer(ctx, shade->buffer);
+ fz_free_compressed_buffer(ctx, shade->buffer);
fz_free(ctx, shade);
}
diff --git a/fitz/stm_comp_buf.c b/fitz/stm_comp_buf.c
index 93df0ef0..54653536 100644
--- a/fitz/stm_comp_buf.c
+++ b/fitz/stm_comp_buf.c
@@ -60,9 +60,17 @@ fz_open_image_decomp_stream(fz_context *ctx, fz_compressed_buffer *buffer, int *
}
fz_stream *
-fz_open_compressed_stream(fz_context *ctx, fz_compressed_buffer *buffer)
+fz_open_compressed_buffer(fz_context *ctx, fz_compressed_buffer *buffer)
{
int factor = 1;
return fz_open_image_decomp_stream(ctx, buffer, &factor);
}
+
+unsigned int
+fz_compressed_buffer_size(fz_compressed_buffer *buffer)
+{
+ if (!buffer || !buffer->buffer)
+ return 0;
+ return (unsigned int)buffer->buffer->cap;
+}
diff --git a/pdf/pdf_shade.c b/pdf/pdf_shade.c
index a53526fc..899315ba 100644
--- a/pdf/pdf_shade.c
+++ b/pdf/pdf_shade.c
@@ -256,16 +256,13 @@ pdf_load_type4_shade(fz_shade *shade, pdf_document *xref, pdf_obj *dict,
int funcs, pdf_function **func)
{
fz_context *ctx = xref->ctx;
- fz_stream *stream;
pdf_load_mesh_params(shade, xref, dict);
if (funcs > 0)
pdf_sample_shade_function(ctx, shade, funcs, func, shade->u.m.c0[0], shade->u.m.c1[0]);
- stream = pdf_open_stream(xref, pdf_to_num(dict), pdf_to_gen(dict));
- shade->buffer = fz_read_all(stream, 1024 /* FIXME */);
- fz_close(stream);
+ shade->buffer = pdf_load_compressed_stream(xref, pdf_to_num(dict), pdf_to_gen(dict));
}
static void
@@ -273,16 +270,13 @@ pdf_load_type5_shade(fz_shade *shade, pdf_document *xref, pdf_obj *dict,
int funcs, pdf_function **func)
{
fz_context *ctx = xref->ctx;
- fz_stream *stream;
pdf_load_mesh_params(shade, xref, dict);
if (funcs > 0)
pdf_sample_shade_function(ctx, shade, funcs, func, shade->u.m.c0[0], shade->u.m.c1[0]);
- stream = pdf_open_stream(xref, pdf_to_num(dict), pdf_to_gen(dict));
- shade->buffer = fz_read_all(stream, 1024 /* FIXME */);
- fz_close(stream);
+ shade->buffer = pdf_load_compressed_stream(xref, pdf_to_num(dict), pdf_to_gen(dict));
}
/* Type 6 & 7 -- Patch mesh shadings */
@@ -292,16 +286,13 @@ pdf_load_type6_shade(fz_shade *shade, pdf_document *xref, pdf_obj *dict,
int funcs, pdf_function **func)
{
fz_context *ctx = xref->ctx;
- fz_stream *stream;
pdf_load_mesh_params(shade, xref, dict);
if (funcs > 0)
pdf_sample_shade_function(ctx, shade, funcs, func, shade->u.m.c0[0], shade->u.m.c1[0]);
- stream = pdf_open_stream(xref, pdf_to_num(dict), pdf_to_gen(dict));
- shade->buffer = fz_read_all(stream, 1024 /* FIXME */);
- fz_close(stream);
+ shade->buffer = pdf_load_compressed_stream(xref, pdf_to_num(dict), pdf_to_gen(dict));
}
static void
@@ -309,16 +300,13 @@ pdf_load_type7_shade(fz_shade *shade, pdf_document *xref, pdf_obj *dict,
int funcs, pdf_function **func)
{
fz_context *ctx = xref->ctx;
- fz_stream *stream;
pdf_load_mesh_params(shade, xref, dict);
if (funcs > 0)
pdf_sample_shade_function(ctx, shade, funcs, func, shade->u.m.c0[0], shade->u.m.c1[0]);
- stream = pdf_open_stream(xref, pdf_to_num(dict), pdf_to_gen(dict));
- shade->buffer = fz_read_all(stream, 1024 /* FIXME */);
- fz_close(stream);
+ shade->buffer = pdf_load_compressed_stream(xref, pdf_to_num(dict), pdf_to_gen(dict));
}
/* Load all of the shading dictionary parameters, then switch on the shading type. */
@@ -445,9 +433,9 @@ fz_shade_size(fz_shade *s)
{
if (s == NULL)
return 0;
- if (s->type != 1)
- return sizeof(*s);
- return sizeof(*s) + sizeof(float) * s->u.f.xdivs * s->u.f.ydivs * s->colorspace->n;
+ if (s->type == FZ_FUNCTION_BASED)
+ return sizeof(*s) + sizeof(float) * s->u.f.xdivs * s->u.f.ydivs * s->colorspace->n;
+ return sizeof(*s) + fz_compressed_buffer_size(s->buffer);
}
fz_shade *