summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--draw/imageunpack.c23
-rw-r--r--fitz/fitz.h2
-rw-r--r--mupdf/mupdf.h2
-rw-r--r--mupdf/pdf_image.c48
4 files changed, 28 insertions, 47 deletions
diff --git a/draw/imageunpack.c b/draw/imageunpack.c
index 6d09253b..a1afe49b 100644
--- a/draw/imageunpack.c
+++ b/draw/imageunpack.c
@@ -161,24 +161,24 @@ fz_unpacktile(fz_pixmap *dst, unsigned char * restrict src, int n, int depth, in
/* Apply decode array */
void
-fz_decodetile(fz_pixmap *pix, float *decode)
+fz_decodetile(fz_pixmap *pix, float *decode, int maxval)
{
- int min[FZ_MAXCOLORS + 2];
- int max[FZ_MAXCOLORS + 2];
- int sub[FZ_MAXCOLORS + 2];
+ int min[FZ_MAXCOLORS];
+ int max[FZ_MAXCOLORS];
+ int sub[FZ_MAXCOLORS];
unsigned char *p = pix->samples;
int len = pix->w * pix->h;
- int n = pix->n;
+ int n = pix->n - 1;
int needed;
int k;
needed = 0;
for (k = 0; k < n; k++)
{
- min[k] = decode[k * 2] * 255;
- max[k] = decode[k * 2 + 1] * 255;
- sub[k] = max[k] - min[k];
- needed |= min[k] != 0 || max[k] != 255;
+ min[k] = decode[k * 2] * 256;
+ max[k] = decode[k * 2 + 1] * 256;
+ sub[k] = (max[k] - min[k]) / maxval;
+ needed |= min[k] != 0 || max[k] != maxval * 256;
}
if (!needed)
@@ -187,7 +187,8 @@ fz_decodetile(fz_pixmap *pix, float *decode)
while (len--)
{
for (k = 0; k < n; k++)
- p[k] = min[k] + fz_mul255(sub[k], p[k]);
- p += n;
+ p[k] = (min[k] + (((p[k] << 8) * sub[k]) >> 8)) >> 8;
+ p += n + 1;
}
}
+
diff --git a/fitz/fitz.h b/fitz/fitz.h
index bff0ce70..5aa2dd0b 100644
--- a/fitz/fitz.h
+++ b/fitz/fitz.h
@@ -1135,7 +1135,7 @@ void fz_executedisplaylist(fz_displaylist *list, fz_device *dev, fz_matrix ctm);
void fz_accelerate(void);
void fz_acceleratearch(void);
-void fz_decodetile(fz_pixmap *pix, float *decode);
+void fz_decodetile(fz_pixmap *pix, float *decode, int maxval);
void fz_unpacktile(fz_pixmap *dst, unsigned char * restrict src, int n, int depth, int stride, int scale);
void fz_blendpixmapswithmode(fz_pixmap *dst, fz_pixmap *src, fz_blendmode blendmode);
diff --git a/mupdf/mupdf.h b/mupdf/mupdf.h
index 25f01b8e..3c247bc0 100644
--- a/mupdf/mupdf.h
+++ b/mupdf/mupdf.h
@@ -267,7 +267,7 @@ struct pdf_image_s
pdf_image *mask; /* explicit mask/softmask image */
int usecolorkey; /* color-keyed masking */
int colorkey[FZ_MAXCOLORS * 2];
- float decode[FZ_MAXCOLORS * 2 + 2];
+ float decode[FZ_MAXCOLORS * 2];
int stride;
fz_buffer *samples;
};
diff --git a/mupdf/pdf_image.c b/mupdf/pdf_image.c
index f0bddb70..ce258c10 100644
--- a/mupdf/pdf_image.c
+++ b/mupdf/pdf_image.c
@@ -90,20 +90,9 @@ pdf_loadimageheader(pdf_image **imgp, pdf_xref *xref, fz_obj *rdb, fz_obj *dict)
}
else
{
+ float maxval = img->indexed ? (1 << img->bpc) - 1 : 1;
for (i = 0; i < img->n * 2; i++)
- {
- if (i & 1)
- {
- if (img->indexed)
- img->decode[i] = (1 << img->bpc) - 1;
- else
- img->decode[i] = 1;
- }
- else
- {
- img->decode[i] = 0;
- }
- }
+ img->decode[i] = i & 1 ? maxval : 0;
}
/* Not allowed for inline images */
@@ -138,12 +127,6 @@ pdf_loadimageheader(pdf_image **imgp, pdf_xref *xref, fz_obj *rdb, fz_obj *dict)
img->colorspace = nil;
}
}
- else
- {
- /* add an entry for alpha channel */
- img->decode[img->n * 2] = 0;
- img->decode[img->n * 2 + 1] = 1;
- }
img->stride = (img->w * img->n * img->bpc + 7) / 8;
@@ -249,7 +232,7 @@ pdf_loadimage(pdf_image **imgp, pdf_xref *xref, fz_obj *rdb, fz_obj *dict)
}
static void
-pdf_maskcolorkey(fz_pixmap *pix, int n, int *colorkey, int scale)
+pdf_maskcolorkey(fz_pixmap *pix, int n, int *colorkey)
{
unsigned char *p = pix->samples;
int len = pix->w * pix->h;
@@ -258,7 +241,7 @@ pdf_maskcolorkey(fz_pixmap *pix, int n, int *colorkey, int scale)
{
t = 1;
for (k = 0; k < n; k++)
- if (p[k] < colorkey[k * 2] * scale || p[k] > colorkey[k * 2 + 1] * scale)
+ if (p[k] < colorkey[k * 2] || p[k] > colorkey[k * 2 + 1])
t = 0;
if (t)
for (k = 0; k < pix->n; k++)
@@ -276,29 +259,26 @@ pdf_loadtile(pdf_image *img /* ...bbox/y+h should go here... */)
tile = fz_newpixmap(img->colorspace, 0, 0, img->w, img->h);
scale = 1;
- switch (img->bpc)
+ if (!img->indexed)
{
- case 1: scale = 255; break;
- case 2: scale = 85; break;
- case 4: scale = 17; break;
+ switch (img->bpc)
+ {
+ case 1: scale = 255; break;
+ case 2: scale = 85; break;
+ case 4: scale = 17; break;
+ }
}
fz_unpacktile(tile, img->samples->bp, img->n, img->bpc, img->stride, scale);
if (img->usecolorkey)
- pdf_maskcolorkey(tile, img->n, img->colorkey, scale);
+ pdf_maskcolorkey(tile, img->n, img->colorkey);
if (img->indexed)
{
fz_pixmap *conv;
- float decode[4];
-
- decode[0] = img->decode[0] * scale / 255;
- decode[1] = img->decode[1] * scale / 255;
- decode[2] = img->decode[2];
- decode[3] = img->decode[3];
- fz_decodetile(tile, decode);
+ fz_decodetile(tile, img->decode, (1 << img->bpc) - 1);
conv = pdf_expandindexedpixmap(tile);
fz_droppixmap(tile);
@@ -306,7 +286,7 @@ pdf_loadtile(pdf_image *img /* ...bbox/y+h should go here... */)
}
else
{
- fz_decodetile(tile, img->decode);
+ fz_decodetile(tile, img->decode, 1);
}
return tile;