KoColor && CMYK -> RGB
Patrick Julien
freak at codepimps.org
Thu Oct 23 20:52:48 CEST 2003
On October 23, 2003 06:11 pm, Boudewijn Rempt wrote:
> On Thursday 23 October 2003 23:09, Boudewijn Rempt wrote:
> > Well, my CMYK strategy works now without crashes -- and it gets called,
> > too, so that's nice. But I fear that there might be a bug in KoColor.
> > Since KoColor isn't used anywhere but on in Krita, but is still in the
> > koffice lib, I crossposted. Is there still anyone maintaining this
> > useful class?
No, not really, this library was maintained by the Kontour people.
> >
> > Anyway, given a nice, white RGB color (255, 255, 255), this function
> > gives (255, 255, 255, 255) -- which is as black as can be.
> >
> > void KoColor::RGBtoCMYK(int R, int G, int B, int *C, int *M, int *Y, int
> > *K) {
> > int min = (R < G) ? R : G;
> > *K = (min < B) ? min : B;
> >
> > *C = 255 - (R - *K);
> > *M = 255 - (G - *K);
> > *Y = 255 - (B - *K);
> > }
>
The error here is actually the extra parentheses, that and the test for K was
inverted . This would actually be
void KoColor::RGBtoCMYK(int R, int G, int B, int *C, int *M, int *Y, int *K) {
int max = (R > G) ? R : G;
*K = 255 - (max > B) ? max : B;
*C = 255 - R - *K;
*M = 255 - G - *K;
*Y = 255 - B - *K;
}
> I've changed this to
>
> void KoColor::RGBtoCMYK(int R, int G, int B, int *C, int *M, int *Y, int
> *K) {
> *C = 255 - R;
> *M = 255 - G;
> *Y = 255 - B;
>
> int min = (*C < *M) ? *C : *M;
> *K = (min < *Y) ? min : *Y;
>
> *C = *C - *K;
> *M = *M - *K;
> *Y = *Y - *K;
> }
>
> In the end, following Foley etc., who I should have consulted first,
> instead of googling. The difference with the previous being that I first
> convert to CMY, instead of subtracting the K from RG and B.
>
> Anyway, since this is a real, life koffice lib -- can I check this in? It
> seems to produce the right results in Krita.
Both corrections are, well, correct, so I don't why not since the old code
isn't doing CMYK.
More information about the kimageshop
mailing list