summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2018-01-10 13:56:07 +0100
committerTor Andersson <tor.andersson@artifex.com>2018-01-10 16:06:17 +0100
commita2a4ad9dceef9610ddc98b2eadb46c3f377516d1 (patch)
tree0726ae364e3cbab7feef5f5cf7a76064dc257a5d /source
parentbec33a470ea600599d3ad9df472b815e7b46e824 (diff)
downloadmupdf-a2a4ad9dceef9610ddc98b2eadb46c3f377516d1.tar.xz
Handle pixmaps without alpha in fz_tint_pixmap.
Diffstat (limited to 'source')
-rw-r--r--source/fitz/pixmap.c54
1 files changed, 25 insertions, 29 deletions
diff --git a/source/fitz/pixmap.c b/source/fitz/pixmap.c
index d3d8b847..a0abb5de 100644
--- a/source/fitz/pixmap.c
+++ b/source/fitz/pixmap.c
@@ -784,50 +784,46 @@ void
fz_tint_pixmap(fz_context *ctx, fz_pixmap *pix, int r, int g, int b)
{
unsigned char *s = pix->samples;
- int x, y;
+ int n = pix->n;
+ int x, y, save;
- if (pix->colorspace == fz_device_bgr(ctx))
- {
- int save = r;
- r = b;
- b = save;
- }
- else if (pix->colorspace == fz_device_gray(ctx))
+ switch (fz_colorspace_type(ctx, pix->colorspace))
{
+ case FZ_COLORSPACE_GRAY:
g = (r + g + b) / 3;
- }
- else if (pix->colorspace != fz_device_rgb(ctx))
- {
- fz_throw(ctx, FZ_ERROR_GENERIC, "can only tint RGB, BGR and Gray pixmaps");
- }
-
- if (pix->n == 4)
- {
- assert(pix->alpha);
for (y = 0; y < pix->h; y++)
{
for (x = 0; x < pix->w; x++)
{
- s[0] = fz_mul255(s[0], r);
- s[1] = fz_mul255(s[1], g);
- s[2] = fz_mul255(s[2], b);
- s += 4;
+ *s = fz_mul255(*s, g);
+ s += n;
}
- s += pix->stride - pix->w * 4;
+ s += pix->stride - pix->w * n;
}
- }
- else if (pix->n == 2)
- {
- assert(pix->alpha);
+ break;
+
+ case FZ_COLORSPACE_BGR:
+ save = r;
+ r = b;
+ b = save;
+ /* fall through */
+ case FZ_COLORSPACE_RGB:
for (y = 0; y < pix->h; y++)
{
for (x = 0; x < pix->w; x++)
{
- *s = fz_mul255(*s, g);
- s += 2;
+ s[0] = fz_mul255(s[0], r);
+ s[1] = fz_mul255(s[1], g);
+ s[2] = fz_mul255(s[2], b);
+ s += n;
}
- s += pix->stride - pix->w * 2;
+ s += pix->stride - pix->w * n;
}
+ break;
+
+ default:
+ fz_throw(ctx, FZ_ERROR_GENERIC, "can only tint RGB, BGR and Gray pixmaps");
+ break;
}
}