48KoColor::KoColor( int a, int b, int c, cSpace m)
82KoColor::KoColor( int c, int m, int y, int k)
92KoColor::KoColor( const TQColor &c)
101KoColor::KoColor( const TQString &name)
106int KoColor::R() const
113int KoColor::G() const
120int KoColor::B() const
127int KoColor::H() const
134int KoColor::S() const
141int KoColor::V() const
148int KoColor::C() const
155int KoColor::M() const
162int KoColor::Y() const
169int KoColor::K() const
176int KoColor::L() const
183int KoColor::a() const
190int KoColor::b() const
197void KoColor::rgb( int *R, int *G, int *B) const
206void KoColor::hsv( int *H, int *S, int *V) const
215void KoColor::lab( int *L, int *a, int *b) const
224void KoColor::cmyk( int *C, int *M, int *Y, int *K) const
234TQString KoColor::name() const
240 s.sprintf( "#%02x%02x%02x", R(), G(), B());
243 s.sprintf( "$%02x%02x%02x", H(), S(), V());
246 s.sprintf( "@%02x%02x%02x%02x", C(), M(), Y(), K());
249 s.sprintf( "*%02x%02x%02x", L(), a(), b());
252 s.sprintf( "#%02x%02x%02x", R(), G(), B());
257TQColor KoColor::color() const
261 return TQColor(mR, mG, mB);
264void KoColor::setRGB( int R, int G, int B)
273void KoColor::setHSV( int H, int S, int V)
282void KoColor::setLab( int L, int a, int b)
291void KoColor::setCMYK( int C, int M, int Y, int K)
301void KoColor::setNamedColor( const TQString &name)
306 mR = (hex2int(name[1]) << 4) + hex2int(name[2]);
307 mG = (hex2int(name[3]) << 4) + hex2int(name[4]);
308 mB = (hex2int(name[5]) << 4) + hex2int(name[6]);
313 mH = (hex2int(name[1]) << 4) + hex2int(name[2]);
314 mS = (hex2int(name[3]) << 4) + hex2int(name[4]);
315 mV = (hex2int(name[5]) << 4) + hex2int(name[6]);
320 mC = (hex2int(name[1]) << 4) + hex2int(name[2]);
321 mM = (hex2int(name[3]) << 4) + hex2int(name[4]);
322 mY = (hex2int(name[5]) << 4) + hex2int(name[6]);
323 mK = (hex2int(name[7]) << 4) + hex2int(name[8]);
328 mL = (hex2int(name[1]) << 4) + hex2int(name[2]);
329 ma = (hex2int(name[3]) << 4) + hex2int(name[4]);
330 mb = (hex2int(name[5]) << 4) + hex2int(name[6]);
343void KoColor::setColor( const TQColor &c)
352void KoColor::RGBtoHSV( int R, int G, int B, int *H, int *S, int *V)
354 unsigned int max = R;
355 unsigned int min = R;
356 unsigned char maxValue = 0;
359 if( static_cast<unsigned int>(G) > max)
364 if( static_cast<unsigned int>(B) > max)
370 if( static_cast<unsigned int>(G) < min)
372 if( static_cast<unsigned int>(B) < min )
375 int delta = max - min;
377 *S = max ? (510 * delta + max) / ( 2 * max) : 0;
388 *H = (120 * (G - B) + delta) / (2 * delta);
390 *H = (120 * (G - B + delta) + delta) / (2 * delta) + 300;
394 *H = 120 + (120 * (B - R) + delta) / (2 * delta);
396 *H = 60 + (120 * (B - R + delta) + delta) / (2 * delta);
400 *H = 240 + (120 * (R - G) + delta) / (2 * delta);
402 *H = 180 + (120 * (R - G + delta) + delta) / (2 * delta);
408void KoColor::RGBtoLAB( int R, int G, int B, int *L, int *a, int *b)
414 double X, Y, Z, fX, fY, fZ;
416 X = 0.412453 * R + 0.357580 * G + 0.180423 * B;
417 Y = 0.212671 * R + 0.715160 * G + 0.072169 * B;
418 Z = 0.019334 * R + 0.119193 * G + 0.950227 * B;
420 X /= (255 * 0.950456);
422 Z /= (255 * 1.088754);
426 fY = pow(Y, 1.0 / 3.0);
427 *L = static_cast<int>(116.0 * fY - 16.0 + 0.5);
431 fY = 7.787 * Y + 16.0 / 116.0;
432 *L = static_cast<int>(903.3 * Y + 0.5);
436 fX = pow(X, 1.0 / 3.0);
438 fX = 7.787 * X + 16.0 / 116.0;
441 fZ = pow(Z, 1.0 / 3.0);
443 fZ = 7.787 * Z + 16.0 / 116.0;
445 *a = static_cast<int>(500.0 * (fX - fY) + 0.5);
446 *b = static_cast<int>(200.0 * (fY - fZ) + 0.5);
449void KoColor::RGBtoCMYK( int R, int G, int B, int *C, int *M, int *Y, int *K)
460 int min = (*C < *M) ? *C : *M;
461 *K = (min < *Y) ? min : *Y;
470void KoColor::HSVtoRGB( int H, int S, int V, int *R, int *G, int *B)
474 if(S != 0 && H != -1)
479 unsigned int f = H % 60;
481 unsigned int p = static_cast<unsigned int>(2*V*(255-S)+255)/510;
486 q = static_cast<unsigned int>(2 * V * (15300 - S * f) + 15300) / 30600;
490 *R = static_cast<int>(q);
491 *G = static_cast<int>(V);
492 *B = static_cast<int>(p);
495 *R = static_cast<int>(p);
496 *G = static_cast<int>(q);
497 *B = static_cast<int>(V);
500 *R = static_cast<int>(V);
501 *G = static_cast<int>(p);
502 *B = static_cast<int>(q);
508 t = static_cast<unsigned int>(2 * V * (15300 - (S * (60 - f))) + 15300) / 30600;
512 *R = static_cast<int>(V);
513 *G = static_cast<int>(t);
514 *B = static_cast<int>(p);
517 *R = static_cast<int>(p);
518 *G = static_cast<int>(V);
519 *B = static_cast<int>(t);
522 *R = static_cast<int>(t);
523 *G = static_cast<int>(p);
524 *B = static_cast<int>(V);
531void KoColor::HSVtoLAB( int H, int S, int V, int *L, int *a, int *b)
534 HSVtoRGB(H, S, V, &R, &G, &B);
535 RGBtoLAB(R, G, B, L, a, b);
538void KoColor::HSVtoCMYK( int H, int S, int V, int *C, int *M, int *Y, int*K)
541 HSVtoRGB(H, S, V, &R, &G, &B);
542 RGBtoCMYK(R, G, B, C, M, Y, K);
545void KoColor::LABtoRGB( int L, int a, int b, int *R, int *G, int *B)
551 double X, Y, Z, fX, fY, fZ;
554 fY = pow((L + 16.0) / 116.0, 3.0);
560 fY = pow(fY, 1.0 / 3.0);
562 fY = 7.787 * fY + 16.0 / 116.0;
568 X = (fX - 16.0 / 116.0) / 7.787;
574 Z = (fZ - 16.0/116.0) / 7.787;
580 RR = static_cast<int>(3.240479 * X - 1.537150 * Y - 0.498535 * Z + 0.5);
581 GG = static_cast<int>(-0.969256 * X + 1.875992 * Y + 0.041556 * Z + 0.5);
582 BB = static_cast<int>(0.055648 * X - 0.204043 * Y + 1.057311 * Z + 0.5);
584 *R = RR < 0 ? 0 : RR > 255 ? 255 : RR;
585 *G = GG < 0 ? 0 : GG > 255 ? 255 : GG;
586 *B = BB < 0 ? 0 : BB > 255 ? 255 : BB;
589void KoColor::LABtoHSV( int L, int a, int b, int *H, int *S, int *V)
592 LABtoRGB(L, a, b, &R, &G, &B);
593 RGBtoHSV(R, G, B, H, S, V);
596void KoColor::LABtoCMYK( int L, int a, int b, int *C, int *M, int *Y, int*K)
599 LABtoRGB(L, a, b, &R, &G, &B);
600 RGBtoCMYK(R, G, B, C, M, Y, K);
603void KoColor::CMYKtoRGB( int C, int M, int Y, int K, int *R, int *G, int *B)
610void KoColor::CMYKtoHSV( int C, int M, int Y, int K, int *H, int *S, int *V)
613 CMYKtoRGB(C, M, Y, K, &R, &G, &B);
614 RGBtoHSV(R, G, B, H, S, V);
617void KoColor::CMYKtoLAB( int C, int M, int Y, int K, int *L, int *a, int *b)
620 CMYKtoRGB(C, M, Y, K, &R, &G, &B);
621 RGBtoLAB(R, G, B, L, a, b);
624int KoColor::hex2int(TQChar c)
627 return c.digitValue();
628 else if( 'A' <= ( int)c && ( int)c <= 'F')
630 else if( 'a' <= ( int)c && ( int)c <= 'f')
636void KoColor::calcRGB() const
641 HSVtoRGB(mH, mS, mV, &mR, &mG, &mB);
644 LABtoRGB(mL, ma, mB, &mR, &mG, &mB);
647 CMYKtoRGB(mC, mM, mY, mK, &mR, &mG, &mB);
655void KoColor::calcHSV() const
660 RGBtoHSV(mR, mG, mB, &mH, &mS, &mV);
663 LABtoHSV(mL, ma, mB, &mH, &mS, &mV);
666 CMYKtoHSV(mC, mM, mY, mK, &mH, &mS, &mV);
674void KoColor::calcCMYK() const
679 RGBtoCMYK(mR, mG, mB, &mC, &mM, &mY, &mK);
682 LABtoCMYK(mL, ma, mB, &mC, &mM, &mY, &mK);
685 HSVtoCMYK(mH, mS, mV, &mC, &mM, &mY, &mK);
693void KoColor::calcLAB() const
698 RGBtoLAB(mR, mG, mB, &mL, &ma, &mB);
701 HSVtoLAB(mH, mS, mV, &mL, &ma, &mB);
704 CMYKtoLAB(mC, mM, mY, mK, &mL, &ma, &mB);
712void KoColor::rgbChanged() const
720void KoColor::hsvChanged() const
728void KoColor::cmykChanged() const
736void KoColor::labChanged() const
|