00001
00088 #ifndef INC_MI32_COLOR_H
00089 #define INC_MI32_COLOR_H
00090
00091 #ifndef INC_MI32_INIBASE_H
00092 #include <mi32/inibase.h>
00093 #endif
00094
00095 #ifndef INC_MI32_COLORSPC_H
00096 #include <mi32/colorspc.h>
00097 #endif
00098
00099 #ifndef INC_MI32_MEMBUF_H
00100 #include <mi32/membuf.h>
00101 #endif
00102
00103 #ifndef GENERATING_DOXYGEN_OUTPUT
00104 class COLOR_ARRAY;
00105 #endif
00106
00107
00108
00109
00110
00111 #define STD64STEP 21845
00112 #define NUMSTDCOLORS 80
00113
00114
00116
00117
00118 enum COLORMODEL {
00119 COLORMODEL_RGB = 0,
00120 COLORMODEL_CMY = 1,
00121 COLORMODEL_CMYK = 2,
00122 COLORMODEL_COUNT
00123 };
00124
00125 #ifdef MISYSTEMDLL
00126 #define CLASSLIBEXPORT MI_DLLCLASSEXPORT
00127 #else
00128 #define CLASSLIBEXPORT MI_DLLCLASSIMPORT
00129 #endif
00130
00131
00132
00136 struct CLASSLIBEXPORT COLOR {
00137 public:
00138
00140
00141 enum NAME {
00142
00143 BLACK = 0x00000000,
00144 RED = 0x000000FF,
00145 GREEN = 0x0000FF00,
00146 BLUE = 0x00FF0000,
00147 CYAN = 0x00FFFF00,
00148 MAGENTA = 0x00FF00FF,
00149 YELLOW = 0x0000FFFF,
00150 GRAY25 = 0x003F3F3F,
00151 GRAY50 = 0x007F7F7F,
00152 GRAY75 = 0x00BFBFBF,
00153 GRAY = GRAY50,
00154 ORANGE = 0x0000A5FF,
00155 BROWN = 0x002A2AA5,
00156 PURPLE = 0x00A020F0,
00157 DARKRED = 0x00000080,
00158 DARKGREEN = 0x00008000,
00159 DARKBLUE = 0x00800000,
00160 DARKCYAN = 0x00808000,
00161 DARKMAGENTA = 0x00A000A0,
00162 DARKYELLOW = 0x00008080,
00163 FORESTGREEN = 0x00228B22,
00164 WHITE = 0x00FFFFFF,
00165 INTERFACE_RED = 0x009C9CFF,
00166 INTERFACE_YELLOW = 0x009CFFFF,
00167 INTERFACE_GREEN = 0x009CFF9C,
00168 INTERFACE_CYAN = 0x00FFFF9C
00169 };
00170
00172
00173
00174 enum MODEL {
00175 MODEL_RGB = 0,
00176 MODEL_CMY = 1,
00177 MODEL_CMYK = 2,
00178 MODEL_COUNT
00179 };
00180
00182 enum CAPABILITY {
00183 CAPABILITY_NoTransparency = 0,
00184 CAPABILITY_AllowTransparent = 1,
00185 CAPABILITY_AllowTransparency = 2,
00186 CAPABILITY_AsPrevious = 3
00187 };
00188
00190 COLOR (
00191 ) :
00192 m_u64(0)
00193 { }
00194
00196 COLOR (
00197 UINT16 r16,
00198 UINT16 g16,
00199 UINT16 b16
00200 ):
00201 m_u64(0)
00202 { SetRGB(r16,g16,b16); }
00203
00205 explicit COLOR (
00206 UINT32 ColorRef
00207 ):
00208 m_u64(0)
00209 { SetColorRef(ColorRef); }
00210
00212 COLOR (
00213 NAME name
00214 ) :
00215 m_u64(0)
00216 { SetColorXBGR32(name); }
00217
00220 COLOR& operator= (
00221 COLOR::NAME name
00222 ) { SetColorXBGR32(name); return (*this); }
00223
00226 void Blend (
00227 const COLOR& other,
00228 UINT8 alpha = 128
00229 );
00230
00232 void Clear (
00233 ) { m_u64 = 0; }
00234
00238 ERRVALUE GetByColorSpace (
00239 COLORSPACE colorspace,
00240 void *values
00241 ) const;
00242
00244 void GetCMY (
00245 UINT8& c8,
00246 UINT8& m8,
00247 UINT8& y8
00248 ) const;
00249
00251 void GetCMY (
00252 UINT16& c16,
00253 UINT16& m16,
00254 UINT16& y16
00255 ) const;
00256
00258 void GetCMYK (
00259 UINT8& c8,
00260 UINT8& m8,
00261 UINT8& y8,
00262 UINT8& k8
00263 ) const;
00264
00266 void GetCMYK (
00267 UINT16& c16,
00268 UINT16& m16,
00269 UINT16& y16,
00270 UINT16& k16
00271 ) const;
00272
00275 UINT32 GetColor0BGR32 (
00276 ) const;
00277
00280 UINT32 GetColor0RGB32 (
00281 ) const;
00282
00285 UINT32 GetColorABGR32 (
00286 ) const;
00287
00290 UINT32 GetColorARGB32 (
00291 ) const;
00292
00294 DEPRECATED COLORMODEL GetColorModel (
00295 ) const;
00296
00298 UINT32 GetColorRef (
00299 ) const { return (GetColor0BGR32()); }
00300
00302 void GetIniValues (
00303 UINT16 values[4]
00304 ) const;
00305
00307 MODEL GetModel (
00308 ) const;
00309
00311 UINT8 GetOpacity (
00312 ) const { return (UINT8_MAX - GetTransparency()); }
00313
00315 void GetRGB (
00316 UINT8& r8,
00317 UINT8& g8,
00318 UINT8& b8
00319 ) const;
00320
00322 void GetRGB (
00323 UINT8 *rgb
00324 ) const { GetRGB(rgb[0],rgb[1],rgb[2]); }
00325
00327 void GetRGB (
00328 UINT16& r16,
00329 UINT16& g16,
00330 UINT16& b16
00331 ) const;
00332
00334 void GetRGB (
00335 UINT16 *rgb
00336 ) const { GetRGB(rgb[0],rgb[1],rgb[2]); }
00337
00339 void GetRGBA (
00340 float& r,
00341 float& g,
00342 float& b,
00343 float& a
00344 ) const;
00345
00348 UINT8 GetTransparency (
00349 ) const { return (m_u8[I_transparency]); }
00350
00352 bool HasTransparency (
00353 ) const { return (m_u8[I_transparency] != 0); }
00354
00356 bool HasValue (
00357 ) const { return (m_u64 != 0); }
00358
00360 bool IniRead (
00361 INIHANDLE hdl,
00362 const char *group,
00363 const char *field
00364 );
00365
00367 void IniWrite (
00368 INIHANDLE hdl,
00369 const char *group,
00370 const char *field
00371 ) const;
00372
00374 bool IsEqualNoTransp (
00375 const COLOR& rhs
00376 ) const;
00377
00379 bool IsEqualTo (
00380 const COLOR& rhs
00381 ) const { return (m_u64 == rhs.m_u64); }
00382
00386 bool IsICMCorrected (
00387 ) const {
00388 return ((m_u8[I_status] & (STATUS_NonRGB | STATUS_ICMCorrected)) != 0);
00389 }
00390
00392 bool IsInvisible (
00393 ) const {
00394 return (m_u8[I_transparency] == UINT8_MAX);
00395 }
00396
00399 bool IsReserved (
00400 ) const {
00401 return ((m_u8[I_status] & STATUS_Reserved) && !(m_u8[I_status] & STATUS_NonRGB));
00402 }
00403
00405 void SerialGetString (
00406 char *string
00407 ) const;
00408
00410 void SerialSetString (
00411 const char *string
00412 );
00413
00417 ERRVALUE SetByColorSpace (
00418 COLORSPACE colorspace,
00419 const void *values
00420 );
00421
00425 bool SetByName (
00426 const char *string
00427 );
00428
00430 void SetCMY (
00431 int cyan,
00432 int magenta,
00433 int yellow,
00434 int range
00435 );
00436
00438 void SetCMY8 (
00439 UINT8 c8,
00440 UINT8 m8,
00441 UINT8 y8
00442 );
00443
00445 void SetCMYK (
00446 int cyan,
00447 int magenta,
00448 int yellow,
00449 int black,
00450 int range
00451 );
00452
00454 void SetCMYK8 (
00455 UINT8 c8,
00456 UINT8 m8,
00457 UINT8 y8,
00458 UINT8 k8
00459 );
00460
00463 void SetColor (
00464 const COLOR& color
00465 );
00466
00469 void SetColorABGR32 (
00470 UINT32 abgr32
00471 );
00472
00475 void SetColorARGB32 (
00476 UINT32 argb32
00477 );
00478
00481 void SetColorXBGR32 (
00482 UINT32 xbgr32
00483 );
00484
00487 void SetColorXRGB32 (
00488 UINT32 xrgb32
00489 );
00490
00493 void SetColorRef (
00494 UINT32 ColorRef
00495 ) { SetColorXBGR32(ColorRef); }
00496
00498 void SetIniValues (
00499 const UINT16 values[4]
00500 );
00501
00508 void SetIsICMCorrected (
00509 bool bCorrected
00510 );
00511
00513 void SetOpacity (
00514 UINT8 opacity
00515 );
00516
00518 void SetReserved (
00519 bool reserved = true
00520 );
00521
00524 void SetRGB (
00525 UINT16 red,
00526 UINT16 green,
00527 UINT16 blue
00528 );
00529
00532 DEPRECATED_MSG("Deprecated, use SetColor method instead.") void SetRGB (
00533 const COLOR& color
00534 );
00535
00538 void SetRGB (
00539 int red,
00540 int green,
00541 int blue,
00542 int range
00543 );
00544
00547 void SetRGB8 (
00548 UINT8 r8,
00549 UINT8 g8,
00550 UINT8 b8
00551 );
00552
00554 void SetTransparency (
00555 UINT8 transparency
00556 );
00557
00559 void SwapBytes ()
00560 { ::SwapBytes(m_u16, 4); }
00561
00563 void Validate (
00564 );
00565
00566 private:
00567 #ifndef GENERATING_DOXYGEN_OUTPUT
00568
00569
00570 enum I_U8 {
00571 #ifdef BYTEORDER_LoHi
00572 I_Lo0 = 0,
00573 I_Hi0 = 1,
00574 I_Lo1 = 2,
00575 I_Hi1 = 3,
00576 I_Lo2 = 4,
00577 I_Hi2 = 5,
00578 I_status = 6,
00579 I_transparency = 7,
00580 #else
00581 I_Hi0 = 0,
00582 I_Lo0 = 1,
00583 I_Hi1 = 2,
00584 I_Lo1 = 3,
00585 I_Hi2 = 4,
00586 I_Lo2 = 5,
00587 I_transparency = 6,
00588 I_status = 7,
00589 #endif
00590
00591 RGB16_R8 = I_Hi0,
00592 RGB16_G8 = I_Hi1,
00593 RGB16_B8 = I_Hi2,
00594 RGB16_R8L = I_Lo0,
00595 RGB16_G8L = I_Lo1,
00596 RGB16_B8L = I_Lo2,
00597
00598 CMY16_C8 = I_Hi0,
00599 CMY16_M8 = I_Hi1,
00600 CMY16_Y8 = I_Hi2,
00601 CMY16_C8L = I_Lo0,
00602 CMY16_M8L = I_Lo1,
00603 CMY16_Y8L = I_Lo2,
00604
00605 CMYK12_C8 = I_Lo0,
00606 CMYK12_M8 = I_Hi0,
00607 CMYK12_Y8 = I_Lo1,
00608 CMYK12_K8 = I_Hi1,
00609 CMYK12_CM4L = I_Lo2,
00610 CMYK12_YK4L = I_Hi2,
00611 };
00612
00613
00614 enum I_U16 {
00615 RGB16_R = 0,
00616 RGB16_G = 1,
00617 RGB16_B = 2,
00618 CMY16_C = 0,
00619 CMY16_M = 1,
00620 CMY16_Y = 2,
00621 };
00622
00623 enum STATUS {
00624 STATUS_ValueSet = 0x01,
00625 LEGACY_Writable = 0x02,
00626 STATUS_Reserved = 0x04,
00627 LEGACY_Invisible = 0x08,
00628 LEGACY_Stored = 0x10,
00629 STATUS_ICMCorrected = 0x20,
00630 STATUS_NonRGB = 0x80
00631 };
00632
00633 union {
00634 UINT64 m_u64;
00635 UINT16 m_u16[4];
00636 UINT8 m_u8[8];
00637 };
00638
00639 CHECKSIZE(8);
00640 #endif // GENERATING_DOXYGEN_OUTPUT
00641 };
00642
00643
00645 inline bool operator== (
00646 const COLOR& lhs,
00647 const COLOR& rhs
00648 ) {
00649 return (lhs.IsEqualTo(rhs));
00650 }
00651
00652
00654 inline bool operator!= (
00655 const COLOR& lhs,
00656 const COLOR& rhs
00657 ) {
00658 return (!lhs.IsEqualTo(rhs));
00659 }
00660
00661
00663 inline int IniRead (INIHANDLE hdl, const char *group, const char *field, COLOR& value) { return (_iniRead(hdl,group,field,INITYPE_COLOR,&value,1)); }
00664
00666 inline int IniRead (INIHANDLE hdl, const char *group, const char *field, COLOR& value, const COLOR& dft) { value = dft; return (IniRead(hdl,group,field,value)); }
00667
00669 inline int IniWrite (INIHANDLE hdl, const char *group, const char *field, const COLOR& value) { return (_iniWrite(hdl,group,field,INITYPE_COLOR,&value,1)); }
00670
00672 inline void SwapBytes (
00673 COLOR& color
00674 ) {
00675 color.SwapBytes();
00676 }
00677
00678
00679
00680 #undef CLASSLIBEXPORT
00681
00682 #endif // INC_MI32_COLOR_H