diff options
-rw-r--r-- | source/fitz/pixmap.c | 54 |
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; } } |