1 // ------------------------------------------------------------------------------------------------ 2 // MODULE : Couleur 3 // LANGUAGE : C++ 4 // AUTHOR : Adolfo VIDE 5 // DATE : 09/15/92 6 // DESCRIPTION : Color classes 7 // COMMENT : 8 // SCCSID : @(#)color.h 1.1 11:49:57 18 Dec 1996 9 // ---------------------------------------------------------------------------- 10 // Copyright (c) 1999 Digital Imaging Group, Inc. 11 // For conditions of distribution and use, see copyright notice 12 // in Flashpix.h 13 // ---------------------------------------------------------------------------- 14 // ------------------------------------------------------------------------------------------------ 15 #ifndef Couleur_h 16 #define Couleur_h 17 #ifndef Commun_h 18 #include "common.h" 19 #endif 20 // ------------------------------------------------------------------------------------------------ 21 22 // Includes 23 // -------- 24 25 #include "b_types.h" 26 #include "mac_comp.h" 27 28 #include "npixel.h" 29 30 // to avoid inclusion of ColorMatching.h 31 class obj_ColorMatching; 32 33 // Constants 34 // --------- 35 36 enum SpotType { Spot_None, Spot_Custom, Spot_PantoneProcess, Spot_PantoneInk, Spot_ToyoInk }; 37 38 // Classes declaration 39 // ------------------- 40 41 struct Couleur; 42 typedef Couleur* ptr_Couleur; 43 typedef Couleur& ref_Couleur; 44 45 struct CouleurTransparente; 46 typedef CouleurTransparente* ptr_CouleurTransparente; 47 typedef CouleurTransparente& ref_CouleurTransparente; 48 49 struct CouleurCMYKtransparente; 50 typedef CouleurCMYKtransparente* ptr_CouleurCMYKtransparente; 51 typedef CouleurCMYKtransparente& ref_CouleurCMYKtransparente; 52 53 typedef short ComposanteC; 54 typedef float GCR; 55 typedef unsigned16 Canal; 56 57 struct CouleurRGB; 58 typedef CouleurRGB* ptr_CouleurRGB; 59 typedef CouleurRGB& ref_CouleurRGB; 60 61 struct CouleurCMYK; 62 typedef CouleurCMYK* ptr_CouleurCMYK; 63 typedef CouleurCMYK& ref_CouleurCMYK; 64 65 typedef NPixel PixelUG; 66 typedef PixelUG* ptr_PixelUG; 67 typedef PixelUG& ref_PixelUG; 68 69 #define COL_INVALID -32768 70 71 // Classes definition 72 // ------------------ 73 74 struct Couleur { 75 76 Couleur(); 77 Couleur(const Couleur& col); 78 Couleur(const Pixel& pixel); 79 Couleur(const NPixel& pixel); 80 Couleur(ComposanteC r, ComposanteC g, ComposanteC b); 81 Couleur(ComposanteC y, ComposanteC m, ComposanteC c, ComposanteC k); 82 83 operator Pixel() const; 84 operator NPixel() const; 85 86 ComposanteC rouge; 87 ComposanteC vert; 88 ComposanteC bleu; 89 90 ComposanteC cyan; 91 ComposanteC magenta; 92 ComposanteC jaune; 93 ComposanteC noir; 94 95 private: 96 97 static GCR gcrCourant; 98 }; 99 100 // CAUTION: PARTS OF THE CODE MAKE AN ASSUMPTION ON THE SIZE OF THIS CLASS 101 struct CouleurTransparente { 102 short presence; // normalise a 0x1000 103 short rouge; // normalise a 0x1000 104 short vert; // normalise a 0x1000 105 short bleu; // normalise a 0x1000 106 }; 107 108 109 // CAUTION: PARTS OF THE CODE MAKE AN ASSUMPTION ON THE SIZE OF THIS CLASS 110 struct CouleurCMYKtransparente { 111 CouleurCMYKtransparente(); 112 CouleurCMYKtransparente (short c, short m, short y, short k, short presence); 113 114 void Clear (); 115 void operator*=(const CouleurCMYKtransparente& a); 116 117 118 short presence; // normalise a 0x1000 119 short c; 120 short m; 121 short y; 122 short k; 123 }; 124 125 // CAUTION: PARTS OF THE CODE MAKE AN ASSUMPTION ON THE SIZE OF THIS CLASS 126 struct CouleurRGB { 127 128 CouleurRGB(); 129 CouleurRGB(Coef c); 130 CouleurRGB(ComposanteC r, ComposanteC g, ComposanteC b); 131 CouleurRGB(const Couleur& col); 132 133 Coef rouge; 134 Coef vert; 135 Coef bleu; 136 137 Boolean operator==(const CouleurRGB& a) const; 138 Boolean operator!=(const CouleurRGB& a) const; 139 CouleurRGB operator+(const CouleurRGB& a) const; 140 void operator+=(const CouleurRGB& a); 141 CouleurRGB operator-(const CouleurRGB& a) const; 142 void operator-=(const CouleurRGB& a); 143 CouleurRGB operator*(short x) const; 144 void operator*=(short x); 145 CouleurRGB operator/(short x) const; 146 void operator/=(short x); 147 148 void Average (const CouleurRGB& a, const CouleurRGB& b); 149 void Average (const CouleurRGB& a, const CouleurRGB& b, 150 const CouleurRGB& c, const CouleurRGB& d); 151 }; 152 153 // CAUTION: PARTS OF THE CODE MAKE AN ASSUMPTION ON THE SIZE OF THIS CLASS 154 struct CouleurCMYK { 155 156 CouleurCMYK(); 157 CouleurCMYK(Canal c, Canal m, Canal y, Canal k); 158 CouleurCMYK(const Couleur& col); 159 160 Boolean operator ==(const CouleurCMYK& cmyk) const; 161 Boolean operator !=(const CouleurCMYK& cmyk) const; 162 163 Canal c; 164 Canal m; 165 Canal y; 166 Canal k; 167 }; 168 169 170 171 // Inline methods 172 // -------------- 173 Couleur()174 inline Couleur::Couleur() 175 : rouge(0), 176 vert(0), 177 bleu(0), 178 cyan(COL_INVALID), 179 magenta(COL_INVALID), 180 jaune(COL_INVALID), 181 noir(COL_INVALID) 182 183 { 184 } 185 Couleur(const Couleur & col)186 inline Couleur::Couleur(const Couleur& col) 187 { 188 BlockMove (&col, this, sizeof *this); 189 } 190 Couleur(const Pixel & pixel)191 inline Couleur::Couleur(const Pixel& pixel) 192 : cyan(COL_INVALID), 193 magenta(COL_INVALID), 194 jaune(COL_INVALID), 195 noir(COL_INVALID) 196 { 197 rouge = pixel.rouge; 198 vert = pixel.vert; 199 bleu = pixel.bleu; 200 } 201 Couleur(const NPixel & pixel)202 inline Couleur::Couleur(const NPixel& pixel) 203 : cyan(COL_INVALID), 204 magenta(COL_INVALID), 205 jaune(COL_INVALID), 206 noir(COL_INVALID) 207 { 208 rouge = pixel.Red(); 209 vert = pixel.Green(); 210 bleu = pixel.Blue(); 211 } 212 Pixel()213 inline Couleur::operator Pixel() const 214 { 215 Pixel pixel; 216 217 pixel.rouge = (unsigned char)rouge; 218 pixel.vert = (unsigned char)vert; 219 pixel.bleu = (unsigned char)bleu; 220 pixel.alpha = (unsigned char)0; 221 222 return pixel; 223 } 224 NPixel()225 inline Couleur::operator NPixel() const 226 { 227 NPixel pixel; 228 229 pixel.Red() = (unsigned char)rouge; 230 pixel.Green() = (unsigned char)vert; 231 pixel.Blue() = (unsigned char)bleu; 232 pixel.Alpha() = (unsigned char)0; 233 234 return pixel; 235 } 236 237 CouleurCMYKtransparente()238 inline CouleurCMYKtransparente::CouleurCMYKtransparente () 239 : presence(0x1000), c(0), m(0), y(0), k(0) 240 { 241 } 242 CouleurCMYKtransparente(short c,short m,short y,short k,short presence)243 inline CouleurCMYKtransparente::CouleurCMYKtransparente (short c, short m, short y, short k, short presence) 244 { 245 this->c = c; 246 this->m = m; 247 this->y = y; 248 this->k = k; 249 this->presence = presence; 250 } 251 Clear()252 inline void CouleurCMYKtransparente::Clear () 253 { 254 c = 0; 255 m = 0; 256 y = 0; 257 k = 0; 258 presence = 0x1000; 259 } 260 261 inline void CouleurCMYKtransparente::operator*=(const CouleurCMYKtransparente& a) 262 { 263 long cmp = 0x1000 - a.presence; 264 265 c = (short)((a.presence * c + cmp * a.c) >> 12); 266 m = (short)((a.presence * m + cmp * a.m) >> 12); 267 y = (short)((a.presence * y + cmp * a.y) >> 12); 268 k = (short)((a.presence * k + cmp * a.k) >> 12); 269 270 presence = (presence * a.presence) >> 12; 271 } 272 CouleurRGB(Coef c)273 inline CouleurRGB::CouleurRGB(Coef c) : rouge(c), vert(c), bleu(c) 274 275 { 276 } 277 CouleurRGB(const Couleur & col)278 inline CouleurRGB::CouleurRGB(const Couleur& col) 279 280 { 281 rouge = col.rouge; 282 vert = col.vert; 283 bleu = col.bleu; 284 } 285 CouleurRGB(Coef r,Coef g,Coef b)286 inline CouleurRGB::CouleurRGB(Coef r, Coef g, Coef b) : rouge(r), vert(g), bleu(b) 287 288 { 289 } 290 291 inline Boolean CouleurRGB::operator==(const CouleurRGB& a) const 292 293 { 294 return ( (a.rouge == rouge) && (a.vert == vert) && (a.bleu == bleu) ); 295 } 296 297 inline Boolean CouleurRGB::operator!=(const CouleurRGB& a) const 298 299 { 300 return ! ((*this) == a); 301 } 302 303 inline CouleurRGB CouleurRGB::operator+(const CouleurRGB& a) const 304 305 { 306 CouleurRGB b; 307 308 b.rouge = rouge + a.rouge; 309 b.vert = vert + a.vert; 310 b.bleu = bleu + a.bleu; 311 312 return b; 313 } 314 315 inline void CouleurRGB::operator+=(const CouleurRGB& a) 316 317 { 318 rouge += a.rouge; 319 vert += a.vert; 320 bleu += a.bleu; 321 } 322 323 inline CouleurRGB CouleurRGB::operator-(const CouleurRGB& a) const 324 325 { 326 CouleurRGB b; 327 328 b.rouge = rouge - a.rouge; 329 b.vert = vert - a.vert; 330 b.bleu = bleu - a.bleu; 331 332 return b; 333 } 334 335 inline void CouleurRGB::operator-=(const CouleurRGB& a) 336 337 { 338 rouge = rouge - a.rouge; 339 vert = vert - a.vert; 340 bleu = bleu - a.bleu; 341 } 342 343 inline CouleurRGB CouleurRGB::operator*(short x) const 344 345 { 346 CouleurRGB b; 347 348 b.rouge = (ComposanteC)(((long)rouge * x) >> 12); 349 b.vert = (ComposanteC)(((long)vert * x) >> 12); 350 b.bleu = (ComposanteC)(((long)bleu * x) >> 12); 351 352 return b; 353 } 354 355 inline void CouleurRGB::operator*=(short x) 356 357 { 358 rouge = (ComposanteC)(((long)rouge * x) >> 12); 359 vert = (ComposanteC)(((long)vert * x) >> 12); 360 bleu = (ComposanteC)(((long)bleu * x) >> 12); 361 } 362 363 inline CouleurRGB CouleurRGB::operator/(short x) const 364 365 { 366 CouleurRGB b; 367 368 b.rouge = (ComposanteC)(((long)rouge << 12)/ x); 369 b.vert = (ComposanteC)(((long)vert << 12)/ x); 370 b.bleu = (ComposanteC)(((long)bleu << 12)/ x); 371 372 return b; 373 } 374 375 inline void CouleurRGB::operator/=(short x) 376 377 { 378 rouge = (ComposanteC)(((long)rouge << 12)/ x); 379 vert = (ComposanteC)(((long)vert << 12)/ x); 380 bleu = (ComposanteC)(((long)bleu << 12)/ x); 381 } 382 Average(const CouleurRGB & a,const CouleurRGB & b)383 inline void CouleurRGB::Average(const CouleurRGB& a, const CouleurRGB& b) 384 385 { 386 rouge = (a.rouge + b.rouge) >> 1; 387 vert = (a.vert + b.vert ) >> 1; 388 bleu = (a.bleu + b.bleu ) >> 1; 389 } 390 Average(const CouleurRGB & a,const CouleurRGB & b,const CouleurRGB & c,const CouleurRGB & d)391 inline void CouleurRGB::Average(const CouleurRGB& a, const CouleurRGB& b, 392 const CouleurRGB& c, const CouleurRGB& d) 393 394 { 395 rouge = (a.rouge + b.rouge + c.rouge + d.rouge) >> 2; 396 vert = (a.vert + b.vert + c.vert + d.vert ) >> 2; 397 bleu = (a.bleu + b.bleu + c.bleu + d.bleu ) >> 2; 398 } 399 CouleurCMYK()400 inline CouleurCMYK::CouleurCMYK () 401 { 402 c = m = y = k = 0; 403 } 404 CouleurCMYK(Canal c,Canal m,Canal y,Canal k)405 inline CouleurCMYK::CouleurCMYK (Canal c, Canal m, Canal y, Canal k) 406 { 407 this->c = c; 408 this->m = m; 409 this->y = y; 410 this->k = k; 411 } 412 CouleurCMYK(const Couleur & col)413 inline CouleurCMYK::CouleurCMYK (const Couleur& col) 414 415 { 416 c = col.cyan; 417 m = col.magenta; 418 y = col.jaune; 419 k = col.noir; 420 } 421 422 inline Boolean CouleurCMYK::operator ==(const CouleurCMYK& cmyk) const 423 { 424 return (c == cmyk.c) && (m == cmyk.m) && (y == cmyk.y) && (k == cmyk.k); 425 } 426 427 inline Boolean CouleurCMYK::operator !=(const CouleurCMYK& cmyk) const 428 { 429 return ! (*this == cmyk); 430 } 431 432 433 // Exported C functions 434 // -------------------- 435 436 extern void Interpole16CouleurRGB ( const CouleurRGB &q0, const CouleurRGB &q1, 437 const CouleurRGB &q2, const CouleurRGB &q3, 438 ptr_CouleurRGB R); 439 440 extern void Interpole64CouleurRGB ( const CouleurRGB &qNW, const CouleurRGB &qNE, 441 const CouleurRGB &qSW, const CouleurRGB &qSE, 442 ptr_CouleurRGB R); 443 444 extern Boolean IsColorDispersion (ptr_CouleurRGB tile, long size); 445 446 447 // ------------------------------------------------------------------------------------------------ 448 #endif // Couleur_h 449 // ------------------------------------------------------------------------------------------------ 450