diff options
author | Robin Watts <robin.watts@artifex.com> | 2012-11-27 18:47:14 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2012-11-27 18:53:54 +0000 |
commit | deac1b9b44977b9e8db758d01867bf8a3ca922ce (patch) | |
tree | 36cbb75a7b44fedd52bded0c12524b1fe9617eee /fitz | |
parent | 9bf73f2cd88abd305ebac405411cc3f260ff9da9 (diff) | |
download | mupdf-deac1b9b44977b9e8db758d01867bf8a3ca922ce.tar.xz |
Tweak image color conversion
Use just 1 loop rather than 2, and count downwards as this is faster
on most architectures.
For the 'hash tabled memoized' general case, the time taken to form the
hashes is significant. Add some code to check that the pixel isn't the
same as the one we just did and bypass the hash.
Diffstat (limited to 'fitz')
-rw-r--r-- | fitz/res_colorspace.c | 69 |
1 files changed, 37 insertions, 32 deletions
diff --git a/fitz/res_colorspace.c b/fitz/res_colorspace.c index 81b08e54..04d895d3 100644 --- a/fitz/res_colorspace.c +++ b/fitz/res_colorspace.c @@ -711,6 +711,7 @@ fz_std_conv_pixmap(fz_context *ctx, fz_pixmap *dst, fz_pixmap *src) float dstv[FZ_MAX_COLORS]; int srcn, dstn; int y, x, k, i; + unsigned int xy; fz_colorspace *ss = src->colorspace; fz_colorspace *ds = dst->colorspace; @@ -725,44 +726,40 @@ fz_std_conv_pixmap(fz_context *ctx, fz_pixmap *dst, fz_pixmap *src) srcn = ss->n; dstn = ds->n; + xy = (unsigned int)(src->w * src->h); + /* Special case for Lab colorspace (scaling of components to float) */ if (!strcmp(ss->name, "Lab") && srcn == 3) { - for (y = 0; y < src->h; y++) + for (; xy > 0; xy--) { - for (x = 0; x < src->w; x++) - { - srcv[0] = *s++ / 255.0f * 100; - srcv[1] = *s++ - 128; - srcv[2] = *s++ - 128; + srcv[0] = *s++ / 255.0f * 100; + srcv[1] = *s++ - 128; + srcv[2] = *s++ - 128; - fz_convert_color(ctx, ds, dstv, ss, srcv); + fz_convert_color(ctx, ds, dstv, ss, srcv); - for (k = 0; k < dstn; k++) - *d++ = dstv[k] * 255; + for (k = 0; k < dstn; k++) + *d++ = dstv[k] * 255; - *d++ = *s++; - } + *d++ = *s++; } } /* Brute-force for small images */ - else if (src->w * src->h < 256) + else if (xy < 256) { - for (y = 0; y < src->h; y++) + for (; xy > 0; xy--) { - for (x = 0; x < src->w; x++) - { - for (k = 0; k < srcn; k++) - srcv[k] = *s++ / 255.0f; + for (k = 0; k < srcn; k++) + srcv[k] = *s++ / 255.0f; - fz_convert_color(ctx, ds, dstv, ss, srcv); + fz_convert_color(ctx, ds, dstv, ss, srcv); - for (k = 0; k < dstn; k++) - *d++ = dstv[k] * 255; + for (k = 0; k < dstn; k++) + *d++ = dstv[k] * 255; - *d++ = *s++; - } + *d++ = *s++; } } @@ -779,15 +776,12 @@ fz_std_conv_pixmap(fz_context *ctx, fz_pixmap *dst, fz_pixmap *src) lookup[i * dstn + k] = dstv[k] * 255; } - for (y = 0; y < src->h; y++) + for (; xy > 0; xy--) { - for (x = 0; x < src->w; x++) - { - i = *s++; - for (k = 0; k < dstn; k++) - *d++ = lookup[i * dstn + k]; - *d++ = *s++; - } + i = *s++; + for (k = 0; k < dstn; k++) + *d++ = lookup[i * dstn + k]; + *d++ = *s++; } } @@ -796,13 +790,24 @@ fz_std_conv_pixmap(fz_context *ctx, fz_pixmap *dst, fz_pixmap *src) { fz_hash_table *lookup; unsigned char *color; + unsigned char dummy = s[0] ^ 255; + unsigned char *sold = &dummy; lookup = fz_new_hash_table(ctx, 509, srcn, -1); - for (y = 0; y < src->h; y++) + for (; xy > 0; xy--) { - for (x = 0; x < src->w; x++) + if (*s == *sold && memcmp(sold,s,srcn) == 0) + { + sold = s; + memcpy(d, d-dstn-1, dstn); + d += dstn; + s += srcn; + *d++ = *s++; + } + else { + sold = s; color = fz_hash_find(ctx, lookup, s); if (color) { |