From b9f94b7632d89437e6f92881d8078e0da14e8aa4 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Fri, 4 Oct 2013 13:24:47 -0700 Subject: [PATCH] adding RGBa->RGBA conversion --- libImaging/Convert.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/libImaging/Convert.c b/libImaging/Convert.c index ab02910a7..2caf219ea 100644 --- a/libImaging/Convert.c +++ b/libImaging/Convert.c @@ -289,6 +289,31 @@ rgba2rgba(UINT8* out, const UINT8* in, int xsize) } } +/* RGBa -> RGBA conversion to remove premultiplication + Needed for correct transforms/resizing on RGBA images */ +static void +rgba2rgbA(UINT8* out, const UINT8* in, int xsize) +{ + int x; + unsigned int alpha; + for (x = 0; x < xsize; x++, in+=4) { + alpha = in[3]; + if (alpha) { + *out++ = CLIP((255 * in[0]) / alpha); + *out++ = CLIP((255 * in[1]) / alpha); + *out++ = CLIP((255 * in[2]) / alpha); + } else { + *out++ = in[0]; + *out++ = in[1]; + *out++ = in[2]; + } + *out++ = in[3]; + + } +} + + + /* ---------------- */ /* CMYK conversions */ /* ---------------- */ @@ -619,6 +644,8 @@ static struct { { "RGBA", "CMYK", rgb2cmyk }, { "RGBA", "YCbCr", ImagingConvertRGB2YCbCr }, + { "RGBa", "RGBA", rgba2rgbA }, + { "RGBX", "1", rgb2bit }, { "RGBX", "L", rgb2l }, { "RGBA", "I", rgb2i },