|
Loading...
|
image-sig@python.org
[Prev] Thread [Next] | [Prev] Date [Next]
Re: [Image-SIG] [raclette] 1.1.7 status Florian Höch Mon Mar 16 01:01:32 2009
I wrote a patch for CMYK undercolor removal for the "dumb" (non-ICC) conversion a while ago, but I think I never posted it anywhere - so here goes (it works flawlessly as far as I can tell, but I as I'm no seasoned C-programmer the code is maybe not very efficient). Only drawback I can think of is that the results are of course inconsistent with previous PIL versions, but you gain the benefit that the conversion can be easily inverted.Something else I'd like to see is 16-bits-per-channel support for image types that can do it (hmm, TIFF, PSD?), but I have no idea how much work that'd be, so maybe not for 1.1.7.
Regards, Florian Höch Fredrik Lundh wrote:
By the way, here's a rough version history for the current 1.1.7
snapshot available from here:
http://bitbucket.org/effbot/pil-2009-raclette/src/874f7005c34c/
Let me know if I've missed some patch that absolutely should go into
1.1.7, or some bug that absolutely needs to be fixed.
cheers /F
--- Convert.c.bak Sun Dec 03 12:37:26 2006
+++ Convert.c Sat Mar 14 09:22:51 2009
@@ -309,12 +309,38 @@
rgb2cmyk(UINT8* out, const UINT8* in, int xsize)
{
int x;
- for (x = 0; x < xsize; x++) {
- /* Note: no undercolour removal */
- *out++ = ~(*in++);
- *out++ = ~(*in++);
- *out++ = ~(*in++);
- *out++ = 0; in++;
+ int R;
+ int G;
+ int B;
+ float C;
+ float M;
+ float Y;
+ int K;
+ for (x = 0; x < xsize; x++, in += 4) {
+ R = in[0];
+ G = in[1];
+ B = in[2];
+
+ C = 255 - R;
+ M = 255 - G;
+ Y = 255 - B;
+ K = 255;
+ if (C < K) { K = C; }
+ if (M < K) { K = M; }
+ if (Y < K) { K = Y; }
+ if (K < 255) {
+ C = (C - K) / (255 - K) * 255;
+ M = (M - K) / (255 - K) * 255;
+ Y = (Y - K) / (255 - K) * 255;
+ } else {
+ C = 0;
+ M = 0;
+ Y = 0;
+ }
+ *out++ = C;
+ *out++ = M;
+ *out++ = Y;
+ *out++ = K;
}
}
@@ -322,11 +348,24 @@
cmyk2rgb(UINT8* out, const UINT8* in, int xsize)
{
int x;
+ float C;
+ float M;
+ float Y;
+ int K;
for (x = 0; x < xsize; x++, in += 4) {
- *out++ = CLIP(255 - (in[0] + in[3]));
- *out++ = CLIP(255 - (in[1] + in[3]));
- *out++ = CLIP(255 - (in[2] + in[3]));
- *out++ = 255;
+ C = in[0];
+ M = in[1];
+ Y = in[2];
+ K = in[3];
+ if (K > 0) {
+ C = (C / 255) * (255 - K) + K;
+ M = (M / 255) * (255 - K) + K;
+ Y = (Y / 255) * (255 - K) + K;
+ }
+ *out++ = 255 - C;
+ *out++ = 255 - M;
+ *out++ = 255 - Y;
+ *out++ = 255;
}
}
_______________________________________________ Image-SIG maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/image-sig
- [Image-SIG] [raclette] 1.1.7 status Fredrik Lundh 2009/03/13
- Re: [Image-SIG] [raclette] 1.1.7 status Florian Höch 2009/03/16 <=
- Re: [Image-SIG] [raclette] 1.1.7 status Glenn Linderman 2009/03/16
- Re: [Image-SIG] [raclette] 1.1.7 status Florian Höch 2009/03/16
- Re: [Image-SIG] [raclette] 1.1.7 status charlie 2009/03/17