summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2012-11-19 16:37:56 +0000
committerRobin Watts <robin.watts@artifex.com>2012-11-19 16:49:28 +0000
commita8560c74b6b655386c4530383eebda4e7cc239c2 (patch)
tree64d4873c78a598fb8974f4cb3e3a778c60b9b6b1
parent019ec348606cf55616b478fda04fc214647e7881 (diff)
downloadmupdf-a8560c74b6b655386c4530383eebda4e7cc239c2.tar.xz
Tweak image decode downscale factor internals.
When calculating the factor to use for image downscales, calculate it as a shift rather than a divisor.
-rw-r--r--fitz/filt_dctd.c8
-rw-r--r--fitz/fitz-internal.h4
-rw-r--r--fitz/stm_comp_buf.c22
-rw-r--r--pdf/pdf_image.c35
4 files changed, 35 insertions, 34 deletions
diff --git a/fitz/filt_dctd.c b/fitz/filt_dctd.c
index 76f82abe..3503370d 100644
--- a/fitz/filt_dctd.c
+++ b/fitz/filt_dctd.c
@@ -12,7 +12,7 @@ struct fz_dctd_s
int color_transform;
int init;
int stride;
- int factor;
+ int l2factor;
unsigned char *scanline;
unsigned char *rp, *wp;
struct jpeg_decompress_struct cinfo;
@@ -157,7 +157,7 @@ read_dctd(fz_stream *stm, unsigned char *buf, int len)
break;
}
- cinfo->scale_num = 8/state->factor;
+ cinfo->scale_num = 8/(1<<state->l2factor);
cinfo->scale_denom = 8;
jpeg_start_decompress(cinfo);
@@ -228,7 +228,7 @@ fz_open_dctd(fz_stream *chain, int color_transform)
}
fz_stream *
-fz_open_resized_dctd(fz_stream *chain, int color_transform, int factor)
+fz_open_resized_dctd(fz_stream *chain, int color_transform, int l2factor)
{
fz_context *ctx = chain->ctx;
fz_dctd *state = NULL;
@@ -242,7 +242,7 @@ fz_open_resized_dctd(fz_stream *chain, int color_transform, int factor)
state->chain = chain;
state->color_transform = color_transform;
state->init = 0;
- state->factor = factor;
+ state->l2factor = l2factor;
}
fz_catch(ctx)
{
diff --git a/fitz/fitz-internal.h b/fitz/fitz-internal.h
index 043449db..528fb50a 100644
--- a/fitz/fitz-internal.h
+++ b/fitz/fitz-internal.h
@@ -753,7 +753,7 @@ fz_stream *fz_open_a85d(fz_stream *chain);
fz_stream *fz_open_ahxd(fz_stream *chain);
fz_stream *fz_open_rld(fz_stream *chain);
fz_stream *fz_open_dctd(fz_stream *chain, int color_transform);
-fz_stream *fz_open_resized_dctd(fz_stream *chain, int color_transform, int factor);
+fz_stream *fz_open_resized_dctd(fz_stream *chain, int color_transform, int l2factor);
fz_stream *fz_open_faxd(fz_stream *chain,
int k, int end_of_line, int encoded_byte_align,
int columns, int rows, int end_of_block, int black_is_1);
@@ -845,7 +845,7 @@ 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);
+fz_stream *fz_open_image_decomp_stream(fz_context *ctx, fz_compressed_buffer *, int *l2factor);
enum
{
diff --git a/fitz/stm_comp_buf.c b/fitz/stm_comp_buf.c
index 54653536..7fa48cb0 100644
--- a/fitz/stm_comp_buf.c
+++ b/fitz/stm_comp_buf.c
@@ -15,7 +15,7 @@ fz_free_compressed_buffer(fz_context *ctx, fz_compressed_buffer *buf)
fz_stream *
-fz_open_image_decomp_stream(fz_context *ctx, fz_compressed_buffer *buffer, int *factor)
+fz_open_image_decomp_stream(fz_context *ctx, fz_compressed_buffer *buffer, int *l2factor)
{
fz_stream *chain = fz_open_buffer(ctx, buffer->buffer);
fz_compression_params *params = &buffer->params;
@@ -23,7 +23,7 @@ fz_open_image_decomp_stream(fz_context *ctx, fz_compressed_buffer *buffer, int *
switch (params->type)
{
case FZ_IMAGE_FAX:
- *factor = 1;
+ *l2factor = 0;
return fz_open_faxd(chain,
params->u.fax.k,
params->u.fax.end_of_line,
@@ -33,26 +33,26 @@ fz_open_image_decomp_stream(fz_context *ctx, fz_compressed_buffer *buffer, int *
params->u.fax.end_of_block,
params->u.fax.black_is_1);
case FZ_IMAGE_JPEG:
- if (*factor > 8)
- *factor = 8;
- return fz_open_resized_dctd(chain, params->u.jpeg.color_transform, *factor);
+ if (*l2factor > 8)
+ *l2factor = 8;
+ return fz_open_resized_dctd(chain, params->u.jpeg.color_transform, *l2factor);
case FZ_IMAGE_RLD:
- *factor = 1;
+ *l2factor = 0;
return fz_open_rld(chain);
case FZ_IMAGE_FLATE:
- *factor = 1;
+ *l2factor = 0;
chain = fz_open_flated(chain);
if (params->u.flate.predictor > 1)
chain = fz_open_predict(chain, params->u.flate.predictor, params->u.flate.columns, params->u.flate.colors, params->u.flate.bpc);
return chain;
case FZ_IMAGE_LZW:
- *factor = 1;
+ *l2factor = 0;
chain = fz_open_lzwd(chain, params->u.lzw.early_change);
if (params->u.lzw.predictor > 1)
chain = fz_open_predict(chain, params->u.lzw.predictor, params->u.lzw.columns, params->u.lzw.colors, params->u.lzw.bpc);
return chain;
default:
- *factor = 1;
+ *l2factor = 0;
break;
}
@@ -62,9 +62,9 @@ fz_open_image_decomp_stream(fz_context *ctx, fz_compressed_buffer *buffer, int *
fz_stream *
fz_open_compressed_buffer(fz_context *ctx, fz_compressed_buffer *buffer)
{
- int factor = 1;
+ int l2factor = 0;
- return fz_open_image_decomp_stream(ctx, buffer, &factor);
+ return fz_open_image_decomp_stream(ctx, buffer, &l2factor);
}
unsigned int
diff --git a/pdf/pdf_image.c b/pdf/pdf_image.c
index 262be821..27a13100 100644
--- a/pdf/pdf_image.c
+++ b/pdf/pdf_image.c
@@ -6,7 +6,7 @@ typedef struct pdf_image_key_s pdf_image_key;
struct pdf_image_key_s {
int refs;
fz_image *image;
- int factor;
+ int l2factor;
};
static void pdf_load_jpx(pdf_document *xref, pdf_obj *dict, pdf_image *image);
@@ -36,7 +36,7 @@ pdf_make_hash_image_key(fz_store_hash *hash, void *key_)
pdf_image_key *key = (pdf_image_key *)key_;
hash->u.pi.ptr = key->image;
- hash->u.pi.i = key->factor;
+ hash->u.pi.i = key->l2factor;
return 1;
}
@@ -74,7 +74,7 @@ pdf_cmp_image_key(void *k0_, void *k1_)
pdf_image_key *k0 = (pdf_image_key *)k0_;
pdf_image_key *k1 = (pdf_image_key *)k1_;
- return k0->image == k1->image && k0->factor == k1->factor;
+ return k0->image == k1->image && k0->l2factor == k1->l2factor;
}
#ifndef NDEBUG
@@ -83,7 +83,7 @@ pdf_debug_image(void *key_)
{
pdf_image_key *key = (pdf_image_key *)key_;
- printf("(image %d x %d sf=%d) ", key->image->w, key->image->h, key->factor);
+ printf("(image %d x %d sf=%d) ", key->image->w, key->image->h, key->l2factor);
}
#endif
@@ -99,14 +99,15 @@ static fz_store_type pdf_image_store_type =
};
static fz_pixmap *
-decomp_image_from_stream(fz_context *ctx, fz_stream *stm, pdf_image *image, int in_line, int indexed, int factor, int cache)
+decomp_image_from_stream(fz_context *ctx, fz_stream *stm, pdf_image *image, int in_line, int indexed, int l2factor, int cache)
{
fz_pixmap *tile = NULL;
fz_pixmap *existing_tile;
int stride, len, i;
unsigned char *samples = NULL;
- int w = (image->base.w + (factor-1)) / factor;
- int h = (image->base.h + (factor-1)) / factor;
+ int f = 1<<l2factor;
+ int w = (image->base.w + f-1) >> l2factor;
+ int h = (image->base.h + f-1) >> l2factor;
pdf_image_key *key;
fz_var(tile);
@@ -204,7 +205,7 @@ decomp_image_from_stream(fz_context *ctx, fz_stream *stm, pdf_image *image, int
key = fz_malloc_struct(ctx, pdf_image_key);
key->refs = 1;
key->image = fz_keep_image(ctx, &image->base);
- key->factor = factor;
+ key->l2factor = l2factor;
existing_tile = fz_store_item(ctx, key, tile, fz_pixmap_size(ctx, tile), &pdf_image_store_type);
if (existing_tile)
{
@@ -246,7 +247,7 @@ pdf_image_get_pixmap(fz_context *ctx, fz_image *image_, int w, int h)
pdf_image *image = (pdf_image *)image_;
fz_pixmap *tile;
fz_stream *stm;
- int factor;
+ int l2factor;
pdf_image_key key;
/* Check for 'simple' images which are just pixmaps */
@@ -266,27 +267,27 @@ pdf_image_get_pixmap(fz_context *ctx, fz_image *image_, int w, int h)
/* What is our ideal factor? */
if (w == 0 || h == 0)
- factor = 1;
+ l2factor = 0;
else
- for (factor=1; image->base.w/(2*factor) >= w && image->base.h/(2*factor) >= h && factor < 8; factor *= 2);
+ for (l2factor=0; image->base.w>>(l2factor+1) >= w && image->base.h>>(l2factor+1) >= h && l2factor < 8; l2factor++);
/* Can we find any suitable tiles in the cache? */
key.refs = 1;
key.image = &image->base;
- key.factor = factor;
+ key.l2factor = l2factor;
do
{
tile = fz_find_item(ctx, fz_free_pixmap_imp, &key, &pdf_image_store_type);
if (tile)
return tile;
- key.factor >>= 1;
+ key.l2factor--;
}
- while (key.factor > 0);
+ while (key.l2factor >= 0);
/* We need to make a new one. */
- stm = fz_open_image_decomp_stream(ctx, image->buffer, &factor);
+ stm = fz_open_image_decomp_stream(ctx, image->buffer, &l2factor);
- return decomp_image_from_stream(ctx, stm, image, 0, 0, factor, 1);
+ return decomp_image_from_stream(ctx, stm, image, 0, 0, l2factor, 1);
}
static pdf_image *
@@ -449,7 +450,7 @@ pdf_load_image_imp(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict, fz_stream *c
stm = pdf_open_stream(xref, pdf_to_num(dict), pdf_to_gen(dict));
}
- image->tile = decomp_image_from_stream(ctx, stm, image, cstm != NULL, indexed, 1, 0);
+ image->tile = decomp_image_from_stream(ctx, stm, image, cstm != NULL, indexed, 0, 0);
}
fz_catch(ctx)
{