color.h

Go to the documentation of this file.
00001 /**
00002  * \file color.h <mi32/color.h>
00003  * \brief Definitions for COLOR structure and functions
00004  *
00005  * \if NODOC
00006  * $Id: color.h_v 1.56 2004/11/09 18:04:50 dwilliss Exp $
00007  *
00008  * $Log: color.h_v $
00009  * Revision 1.56  2004/11/09 18:04:50  dwilliss
00010  * Fix the dark colors
00011  *
00012  * Revision 1.55  2004/09/14 16:31:32  dwilliss
00013  * Define some new color names (darker versions)
00014  *
00015  * Revision 1.54  2004/07/09 21:52:52  vdronov
00016  * *** empty log message ***
00017  *
00018  * Revision 1.53  2004/03/03 15:56:38  mju
00019  * Use specified range in setcmyk when eventually set RGB.
00020  *
00021  * Revision 1.52  2004/03/02 22:48:18  scowan
00022  * Made most methods inline.
00023  *
00024  * Revision 1.51  2004/02/10 18:45:10  mju
00025  * Add GetRGB.
00026  *
00027  * Revision 1.50  2003/09/25 21:29:07  dwilliss
00028  * Don't capitalize enum any more. Genitor needed it, doxygen doesn't like it.
00029  *
00030  * Revision 1.49  2003/09/15 13:49:56  fileserver!dwilliss
00031  * Doxygen
00032  *
00033  * Revision 1.48  2003/05/22 22:58:38  scowan
00034  * Moved to misystem.
00035  *
00036  * Revision 1.47  2003/05/22 21:36:10  scowan
00037  * Removed assignment operator from name string.
00038  *
00039  * Revision 1.46  2003/05/22 21:19:38  mju
00040  * Remove ctor taking char* name.
00041  *
00042  * Revision 1.45  2003/05/22 15:49:54  dwilliss
00043  * GetRed/GetGreen/GetBlue no longer inlines that just return members
00044  * They now depend on what colorspace the color is in
00045  *
00046  * Revision 1.44  2003/05/21 22:39:44  dwilliss
00047  * Added support for non-rgb colorspace storage
00048  *
00049  * Revision 1.43  2003/02/28 18:57:42  msmith
00050  * Fixed ORANGE color - it was backwards.
00051  *
00052  * Revision 1.42  2003/02/07 14:30:47  mju
00053  * Remove ; to fix mac warning.
00054  *
00055  * Revision 1.41  2003/01/23 16:17:10  dwilliss
00056  * Changed comments on Blend to indicate correct range for alpha.
00057  *
00058  * Revision 1.40  2003/01/23 15:17:31  dwilliss
00059  * Changed Blend to use UINT8 alpha value and avoid floating-point
00060  *
00061  * Revision 1.39  2003/01/22 23:04:03  dwilliss
00062  * Added a Blend method
00063  *
00064  * Revision 1.38  2002/11/22 15:26:35  mju
00065  * Add IsEqualNoTransp.
00066  *
00067  * Revision 1.37  2002/11/19 22:58:12  mju
00068  * Add COLORMODEL enum.
00069  *
00070  * Revision 1.36  2002/11/19 22:48:20  mju
00071  * Add SetCMYK.
00072  *
00073  * Revision 1.35  2002/11/18 15:57:50  mju
00074  * Add Get/SetByColorSpace.
00075  *
00076  * Revision 1.34  2002/11/14 23:02:23  mju
00077  * Change SetRGB from COLOR to use Get methods so will do colorspace conversione when implemented.
00078  *
00079  * Revision 1.33  2002/11/14 22:58:13  mju
00080  * Make GetRed/Green/Blue have separate implemention for non-range for efficiency.
00081  * Add STATUS_NonRGB for non-RGB colorspace storage.
00082  *
00083  * Revision 1.32  2002/11/11 15:58:54  mju
00084  * Deperecate stringtocolor.
00085  *
00086  * Revision 1.30  2002/11/07 14:03:13  mju
00087  * Init flags in ctor by name string.
00088  *
00089  * Revision 1.29  2002/10/25 14:56:17  mju
00090  * Add Validate method.
00091  *
00092  * Revision 1.28  2002/10/23 17:48:39  mju
00093  * Add IsReserved/SetReserved methods.
00094  * Deprecate old flags, add private enum for flags etc.
00095  *
00096  * Revision 1.27  2002/10/22 17:44:33  mju
00097  * Return value from op=.
00098  *
00099  * Revision 1.26  2002/10/22 14:57:15  mju
00100  * Remove setInvisible, use SetTransparency(255) instead.
00101  *
00102  * Revision 1.25  2002/10/22 14:26:37  mju
00103  * Change HasValue to check if any member set except certain flags.
00104  *
00105  * Revision 1.24  2002/10/21 20:55:48  mju
00106  * Deprecate NextColor fns.
00107  *
00108  * Revision 1.23  2002/10/21 20:49:55  dwilliss
00109  * Was missing a ";" after PREVENT_MEMCMP()
00110  *
00111  * Revision 1.22  2002/10/21 20:46:16  mju
00112  * Add Clear() and HasValue() methods.
00113  * Check appropriate flags in IsEqualTo method.
00114  *
00115  * Revision 1.21  2002/10/21 20:24:44  mju
00116  * Add SetByName and use in ctor/op=.
00117  * Make SetRGB non-inline with range.
00118  * Add PREVENT_MEMCMP.
00119  *
00120  * Revision 1.20  2002/10/21 16:53:35  mju
00121  * Deprecate access to COLOR data members.
00122  * Add various Get methods for accessing data members.
00123  * Add SetRGB method using range.
00124  *
00125  * Revision 1.19  2002/09/09 13:27:06  mju
00126  * Remove deprecated inline.
00127  *
00128  * Revision 1.18  2001/12/11 15:54:02  scowan
00129  * Added include for membuf for swap bytes.
00130  *
00131  * Revision 1.17  2001/12/11 15:50:07  scowan
00132  * Added swap bytes function to swap color structures correctly.
00133  *
00134  * Revision 1.16  2001/11/14 22:07:03  msmith
00135  * GetTransparency returns flags >> 8 now, not flags > 8
00136  *
00137  * Revision 1.15  2001/11/05 16:49:10  mju
00138  * Add ctor from colorref.
00139  *
00140  * Revision 1.14  2001/08/17 17:08:52  mju
00141  * Add SetRGB using color reference.
00142  *
00143  * Revision 1.13  2001/08/16 21:08:58  mju
00144  * Add SetColorRef() method.
00145  *
00146  * Revision 1.12  2001/02/19 15:21:07  mju
00147  * Add color::GetColorRef().
00148  *
00149  * Revision 1.11  2000/05/04 16:26:56  mju
00150  * Add SetTransparency method.
00151  * Add Genitor docs.
00152  *
00153  * Revision 1.1  1999/04/28  14:08:58  mju
00154  * Initial revision
00155  * \endif
00156 **/
00157 
00158 #ifndef  INC_MI32_COLOR_H
00159 #define  INC_MI32_COLOR_H
00160 
00161 #ifndef  INC_MI32_STDDEFNS_H
00162 #include <mi32/stddefns.h>
00163 #endif
00164 
00165 #ifndef  INC_MI32_COLORSPC_H
00166 #include <mi32/colorspc.h>
00167 #endif
00168 
00169 #ifndef  INC_MI32_MEMBUF_H
00170 #include <mi32/membuf.h>
00171 #endif
00172 
00173 //----------------------------------------------------------------------------
00174 //!      Constants
00175 //----------------------------------------------------------------------------
00176 
00177 #define  STD64STEP      21845    //!< Step value for creating 64 "standard" colors (65535 / 3)
00178 #define  NUMSTDCOLORS   80       //!< 64 color + 16 gray
00179 
00180 //===================================================================================================================
00181 //! Color "model" enumeration.
00182 // Values are passed to DLLs and stored in files and cannot be changed.
00183 // Values must be assigned contiguously and may not exceed 127
00184 enum COLORMODEL {
00185    COLORMODEL_RGB =           0,    //!< Red-Green-Blue
00186    COLORMODEL_CMY =           1,    //!< Cyan-Magenta-Yellow
00187    COLORMODEL_CMYK =          2,    //!< Cyan-Magenta-Yellow-Black
00188    COLORMODEL_HIS =           3,    //!< Hue-Intensity-Saturation single hexcone
00189    COLORMODEL_HBS =           4,    //!< Hue-Brightness-Saturation double hexcone
00190    COLORMODEL_MunsellHSV =    5,    //!< Munsell Hue-Saturation-Value
00191    COLORMODEL_XYZ =           6,    //!< CIE XYZ (fixed point)
00192    COLORMODEL_Lab =           7,    //!< CIE Lab (fixed point)
00193    COLORMODEL_Pantone =       8,    //!< Pantone named colors (16 bit color number) 
00194    COLORMODEL_COUNT
00195    };
00196 
00197 #ifdef MISYSTEMDLL
00198    #define CLASSLIBEXPORT MI_DLLCLASSEXPORT
00199 #else
00200    #define CLASSLIBEXPORT MI_DLLCLASSIMPORT
00201 #endif
00202 
00203 //===================================================================================================================
00204 //! Structure to contain single color specification with possible transparency.
00205 //!
00206 //! This structure is stored in files and will never change in size.
00207 struct CLASSLIBEXPORT COLOR {
00208    public:
00209 
00210       //! Enumerated color names.
00211       // Note, names are equal to COLORREF values to simplify assignment.
00212       enum NAME {
00213          //               xxBBGGRR
00214          BLACK =        0x00000000,
00215          RED =          0x000000FF,
00216          GREEN =        0x0000FF00,
00217          BLUE =         0x00FF0000,
00218          CYAN =         0x00FFFF00,
00219          MAGENTA =      0x00FF00FF,
00220          YELLOW =       0x0000FFFF,
00221          GRAY25 =       0x003F3F3F,
00222          GRAY50 =       0x007F7F7F,
00223          GRAY75 =       0x00BFBFBF,
00224          GRAY =         GRAY50,
00225          ORANGE =       0x0000A5FF,
00226          BROWN =        0x00A52A2A,
00227          PURPLE =       0x00A020F0,
00228          DARKRED =      0x00000080,
00229          DARKGREEN =    0x00008000,
00230          DARKBLUE =     0x00800000,
00231          DARKCYAN =     0x00808000,
00232          DARKMAGENTA =  0x00A000A0,
00233          DARKYELLOW =   0x00008080,
00234          FORESTGREEN =  0x00228B22,
00235          WHITE =        0x00FFFFFF
00236          };
00237 
00238       enum FLAGS {
00239          STATUS_ValueSet =       0x0001,
00240 //    LEGACY_Writable =       0x0002,
00241          STATUS_Reserved =       0x0004,
00242          STATUS_Invisible =      0x0008,
00243 //    LEGACY_Stored =         0x0010,
00244          STATUS_ICMCorrected =   0x0020,  //!< ICM correction already done. Note, NonRGB imlies ICM's already been done too
00245          STATUS_NonRGB =         0x0080,  //!< If set, other flags are usurped to hold COLORMODEL
00246          MASK_Compare =          0xFFE9,
00247          MASK_CompareNoTransp =  0x00E5,
00248          MASK_Transparency =     0xFF00,
00249          LEGACY_Invalid =        0xFFFF
00250          };
00251 
00252       //! Default constructor.
00253       COLOR (
00254          ) : 
00255          m_Red(0), 
00256          m_Green(0), 
00257          m_Blue(0), 
00258          m_flags(0)
00259          {}
00260 
00261       //! Construct with specified red, green, blue values.
00262       COLOR (
00263          UINT16 red,
00264          UINT16 green,
00265          UINT16 blue
00266          ) : 
00267          m_Red(red), 
00268          m_Green(green), 
00269          m_Blue(blue), 
00270          m_flags(STATUS_ValueSet)
00271          {}
00272 
00273       //! Construct by color reference.
00274       explicit COLOR (
00275          UINT32 ColorRef
00276          ) :
00277          m_Red(static_cast<UINT16>((ColorRef << 8) & 0xFF00)),
00278          m_Green(static_cast<UINT16>(ColorRef & 0xFF00)),
00279          m_Blue(static_cast<UINT16>((ColorRef >> 8) & 0xFF00)),
00280          m_flags(STATUS_ValueSet)
00281          {}
00282 
00283       //! Construct by enumerated name.
00284       COLOR (
00285          NAME name
00286          ) :
00287          m_Red(static_cast<UINT16>((name << 8) & 0xFF00)),
00288          m_Green(static_cast<UINT16>(name & 0xFF00)),
00289          m_Blue(static_cast<UINT16>((name >> 8) & 0xFF00)),
00290          m_flags(STATUS_ValueSet)
00291          {}
00292 
00293       //! Assign by enumerated name.
00294       //! Original flag and transparency values are retained.
00295       COLOR& operator= (
00296          COLOR::NAME name
00297          ) {
00298          m_Red = static_cast<UINT16>((name << 8) & 0xFF00);
00299          m_Green = static_cast<UINT16>(name & 0xFF00);
00300          m_Blue = static_cast<UINT16>((name >> 8) & 0xFF00);
00301          m_flags |= STATUS_ValueSet;
00302          return (*this);
00303          }
00304 
00305       //! Blend this color with another color.
00306       //! The range of values for alpha is 0-255.  
00307       void Blend (
00308          const COLOR& other,
00309          UINT8 alpha = 128    //!< 0 == all "this", 255 = all "other"
00310          ) {
00311          // Note: technically, alpha _should_ be 0-256, but for consistancy
00312          // it's a UINT8. Since we divide by shifting, the best we can get is
00313          // alpha == 255/256, which doesn't quite allow 1.0.  But if you really
00314          // wanted all the "other" color, you could just do an assignment.
00315          UINT32 inv = 256 - alpha;
00316          SetRGB ( 
00317             (UINT16)((GetRed() * inv + other.GetRed() * (UINT32)alpha) >> 8),
00318             (UINT16)((GetGreen() * inv + other.GetGreen() * (UINT32)alpha) >> 8),
00319             (UINT16)((GetBlue() * inv + other.GetBlue() * (UINT32)alpha) >> 8)
00320             );
00321          return;
00322          }
00323       
00324       //! Clear current color setting.
00325       void Clear (
00326          ) { 
00327          m_Red = m_Green = m_Blue = m_flags = 0;
00328          return;
00329          }
00330 
00331       //! Get Blue as UINT16 (0-65535).
00332       UINT16 GetBlue (
00333          ) const {
00334          return (m_Blue);
00335          }
00336 
00337       //! Get Blue in range specified.
00338       UINT16 GetBlue (
00339          UINT16 range                     //!< Range 1-65535
00340          ) const { 
00341          return (static_cast<UINT16>((static_cast<UINT32>(GetBlue()) * range + 32767) / 65535));
00342          }
00343 
00344       //! Get Blue as byte (0-255).
00345       UINT8 GetBlueByte (
00346          ) const { 
00347          return (static_cast<UINT8>(GetBlue() >> 8));
00348          }
00349 
00350       COLORMODEL GetColorModel (
00351          ) const {
00352          if (m_flags & STATUS_NonRGB) {
00353             return (static_cast<COLORMODEL>(m_flags & 0x7F));
00354             }
00355          return (COLORMODEL_RGB);
00356          }
00357 
00358       //! Get values in specified COLORSPACE.
00359       //! For colorspaces containing an "alpha" component, "alpha" is considered to be "opacity".
00360       //! Binary, grayscale and indexed colorspaces are not supported and an error will be returned for such.
00361       ERRVALUE GetByColorSpace (
00362          COLORSPACE colorspace,           //!< Color space
00363          void *values                     //!< Buffer to hold returned values, size depends on colorspace
00364          ) const;
00365 
00366       //! Get WIN32 color reference (0x00BBGGRR).
00367       UINT32 GetColorRef (
00368          ) const { 
00369          return ((m_Red >> 8) | (m_Green & 0xFF00) | (((INT32)(m_Blue & 0xFF00)) << 8));
00370          }
00371 
00372       //! Get Green as UINT16 (0-65535).
00373       UINT16 GetGreen (
00374          ) const {
00375          return (m_Green);
00376          }
00377 
00378       //! Get Green in range specified.
00379       UINT16 GetGreen (
00380          UINT16 range                     //!< Range 1-65535
00381          ) const { 
00382          return (static_cast<UINT16>((static_cast<UINT32>(GetGreen()) * range + 32767) / 65535));
00383          }
00384 
00385       //! Get Green as byte (0-255).
00386       UINT8 GetGreenByte (
00387          ) const { 
00388          return (static_cast<UINT8>(GetGreen() >> 8));
00389          }
00390 
00391       //! Get opacity value (0-255).
00392       UINT8 GetOpacity (
00393          ) const { 
00394          // STATUS_Invisible may be set if color was read in from old data
00395          if (!(m_flags & STATUS_NonRGB) && (m_flags & STATUS_Invisible)) {
00396             return (0);
00397             }
00398          return (static_cast<UINT8>(255 - (m_flags >> 8))); 
00399          }
00400 
00401       //! Get Red as UINT16 (0-65535).
00402       UINT16 GetRed (
00403          ) const {
00404          return (m_Red);
00405          }
00406 
00407       //! Get Red in range specified.
00408       UINT16 GetRed (
00409          UINT16 range                     //!< Range 1-65535
00410          ) const { 
00411          return (static_cast<UINT16>((static_cast<UINT32>(GetRed()) * range + 32767) / 65535)); 
00412          }
00413 
00414       //! Get Red as byte (0-255).
00415       UINT8 GetRedByte (
00416          ) const { 
00417          return (static_cast<UINT8>(GetRed() >> 8)); 
00418          }
00419 
00420       //! Get Red, Green, Blue values in single call for efficiency.
00421       void GetRGB (
00422          UINT16& red,
00423          UINT16& green,
00424          UINT16& blue
00425          ) const {
00426          red = m_Red;
00427          green = m_Green;
00428          blue = m_Blue;
00429          return;
00430          }
00431 
00432       //! Retrieve transparency value.
00433       //! @return Transparency (0 - 255), 0 = opaque, 255 = 100% transparent.
00434       UINT8 GetTransparency (
00435          ) const { 
00436          // STATUS_Invisible may be set if COLOR comes from old data
00437          if (!(m_flags & STATUS_NonRGB) && (m_flags & STATUS_Invisible)) {
00438             return (255);
00439             }
00440          return (static_cast<UINT8>(m_flags >> 8)); 
00441          }
00442 
00443       //! Determine if has any transparency value (including invisible).
00444       bool HasTransparency (
00445          ) const { 
00446          // STATUS_Invisible may be set if COLOR comes from old data
00447          if ((m_flags & MASK_Transparency) != 0) return (true);
00448          return (!(m_flags & STATUS_NonRGB) && (m_flags & STATUS_Invisible));
00449          }
00450 
00451       //! Determine if a color value has been set.
00452       bool HasValue (
00453          ) const { 
00454          return ((m_flags & MASK_Compare) != 0 || m_Red != 0 || m_Green != 0 || m_Blue != 0); 
00455          }
00456 
00457       //! Compare colors for equality, excluding transparency settings.
00458       bool IsEqualNoTransp (
00459          const COLOR& rhs     
00460          ) const { 
00461          if (((rhs.m_flags | m_flags) & STATUS_NonRGB) != 0) {
00462             // one or both are non-rgb. Compare all flags except transparency byte
00463             return (m_Red == rhs.m_Red && m_Green == rhs.m_Green && m_Blue == rhs.m_Blue && (m_flags & 0x00FF) == (rhs.m_flags & 0x00FF)); 
00464             }
00465          // Old data may also have the STATUS_Invisible flag set.
00466          return (m_Red == rhs.m_Red && m_Green == rhs.m_Green && m_Blue == rhs.m_Blue && (m_flags & MASK_CompareNoTransp) == (rhs.m_flags & MASK_CompareNoTransp)); 
00467          }
00468 
00469       //! Compare colors for equality, including transparency, etc.
00470       bool IsEqualTo (
00471          const COLOR& rhs     
00472          ) const { 
00473          if (((rhs.m_flags | m_flags) & STATUS_NonRGB) != 0) {
00474             // one or both are non-rgb. Compare all flags 
00475             return (m_Red == rhs.m_Red && m_Green == rhs.m_Green && m_Blue == rhs.m_Blue && m_flags == rhs.m_flags); 
00476             }
00477          // Legacy data may have some bits set that we want to ignore.
00478          return (m_Red == rhs.m_Red && m_Green == rhs.m_Green && m_Blue == rhs.m_Blue && (m_flags & MASK_Compare) == (rhs.m_flags & MASK_Compare)); 
00479          }
00480 
00481       //! Determine if the color has been run through an ICM transformation.
00482       //! This is used to insure that the same color isn't translated more
00483       //! than once.
00484       bool IsICMCorrected (
00485          ) const {
00486          if (m_flags & STATUS_NonRGB) return (true);
00487          return ((m_flags & STATUS_ICMCorrected) != 0);
00488          }
00489 
00490       //! Determine if color is 'invisible' (100% transparent).
00491       bool IsInvisible (
00492          ) const { 
00493          if (m_flags & STATUS_NonRGB) {
00494             return ((m_flags & 0xFF00) == 0xFF00);
00495             }
00496          // Legacy data may have STATUS_Invisible set
00497          return ((m_flags & STATUS_Invisible) != 0 || (m_flags & 0xFF00) == 0xFF00);
00498          }
00499 
00500       //! Determine if color is 'reserved' for application-specific use.
00501       //! In color search and allocation operations 'reserved' colors are not used or changed.
00502       bool IsReserved (
00503          ) const { 
00504          if (m_flags & STATUS_NonRGB) return (false); // NonRGB can't be reserved
00505          return ((m_flags & STATUS_Reserved) != 0); 
00506          }
00507 
00508       //! Get as string for serializer writing.
00509       void SerialGetString (
00510          char *string                     //!< String to contain values, should be at least 32 bytes
00511          ) const;
00512 
00513       //! Set from string for serializer reading.
00514       void SerialSetString (
00515          const char *string               //!< String to set from
00516          );
00517 
00518       //! Set values using specified COLORSPACE.
00519       //! For colorspaces containing an "alpha" component, "alpha" is considered to be "opacity".
00520       //! Binary, grayscale and indexed colorspaces are not supported and an error will be returned for such.
00521       ERRVALUE SetByColorSpace (
00522          COLORSPACE colorspace,           //!< Color space
00523          const void *values               //!< Buffer holding values to set, size depends on colorspace
00524          );
00525 
00526       //! Set color by name string.
00527       //! @return 'true' if name found, 'false' if not.
00528       //! Also supports strings in forms "redpct greenpct bluepct" and "redpct,greenpct,bluepct".
00529       bool SetByName (
00530          const char *string               //!< Color name, case-insensitive
00531          );
00532 
00533       //! Set from Cyan, Magenta, Yellow in specified range.
00534       void SetCMY (
00535          int cyan,
00536          int magenta,
00537          int yellow,
00538          int range                        //!< Range, 1-65535
00539          ) {
00540          SetRGB(range-cyan,range-magenta,range-yellow,range);
00541          return;
00542          }
00543 
00544       //! Set from Cyan, Magenta, Yellow, Black in specified range.
00545       void SetCMYK (
00546          int cyan,
00547          int magenta,
00548          int yellow,
00549          int black,
00550          int range                        //!< Range, 1-65535
00551          ) {
00552          int r = range - cyan - black;
00553          int g = range - magenta - black;
00554          int b = range - yellow - black;
00555          SetRGB(MAX(0,r),MAX(0,g),MAX(0,b),range);
00556          return;
00557          }
00558 
00559       //! Set red, green, blue values from WIN32 color reference (0x00BBGGRR).
00560       //! Original flag and transparency values are retained.
00561       void SetColorRef (
00562          UINT32 ColorRef
00563          ) {
00564          m_Red = static_cast<UINT16>((ColorRef << 8) & 0xFF00);
00565          m_Green = static_cast<UINT16>(ColorRef & 0xFF00);
00566          m_Blue = static_cast<UINT16>((ColorRef >> 8) & 0xFF00);
00567          if (m_flags & STATUS_NonRGB) m_flags &= ~0x00FF;
00568          m_flags |= STATUS_ValueSet;
00569          return;
00570          }
00571 
00572       //! Specify whether the color has been run through an ICM transformation.
00573       //! This is used to insure that the same color isn't translated more
00574       //! than once.
00575       //! Of course there's no way to specify which target profile it's been
00576       //! corrected to.  ICM-corrected colors should never be stored in files
00577       //! unless the whole file is corrected to some target device profile.
00578       void SetIsICMCorrected (
00579          bool bCorrected
00580          ) {
00581          if (m_flags & STATUS_NonRGB) return;   // It's implied for non RGB
00582          if (bCorrected) {
00583             m_flags |= STATUS_ICMCorrected;
00584             }
00585          else {
00586             m_flags &= ~STATUS_ICMCorrected;
00587             }
00588          return;
00589          }
00590 
00591       //! Set opacity value.
00592       void SetOpacity (
00593          UINT8 opacity                    //!< Value to set, 0 = invisible, 255 = 100% opaque
00594          ) {
00595          m_flags &= ~MASK_Transparency;
00596          m_flags |= static_cast<UINT16>(255-opacity) << 8;
00597          return;
00598          }
00599 
00600       //! Set whether color is 'reserved' or not.
00601       void SetReserved (
00602          bool reserved = true             //!< 'true' to make reserved, 'false' to not
00603          ) { 
00604          if (m_flags & STATUS_NonRGB) return;   // non-rgb can't be "reserved"
00605          if (reserved) {
00606             m_flags |= STATUS_Reserved; 
00607             }
00608          else {
00609             m_flags &= ~STATUS_Reserved;
00610             }
00611          return;
00612          }
00613 
00614       //! Set red, green, blue values in range 0-65535.
00615       //! Original flag and transparency values are retained.
00616       void SetRGB (
00617          UINT16 red,
00618          UINT16 green,
00619          UINT16 blue
00620          ) { 
00621          if (m_flags & STATUS_NonRGB) m_flags &= 0xFF00;
00622          m_Red = red; 
00623          m_Green = green; 
00624          m_Blue = blue; 
00625          m_flags |= STATUS_ValueSet; 
00626          return;
00627          }
00628 
00629       //! Set red, green, blue values from COLOR.
00630       //! Original flag and transparency values are retained.
00631       void SetRGB (
00632          const COLOR& color
00633          ) { 
00634          SetRGB(color.GetRed(),color.GetGreen(),color.GetBlue());
00635          return;
00636          }
00637 
00638       //! Set from Red, Green, Blue in specified range.
00639       //! Values outside the range will be limited to the range specified.
00640       void SetRGB (
00641          int red,                      //!< Red in range specified
00642          int green,                    //!< Green in range specified
00643          int blue,                     //!< Blue in range specified
00644          int range                     //!< Range, 1-65535
00645          ) {
00646          if (range < 1 || range > 65535) return;
00647          m_Red = static_cast<UINT16>((static_cast<UINT32>(bound(red,0,range)) * 65535 + range/2) / range);
00648          m_Green = static_cast<UINT16>((static_cast<UINT32>(bound(green,0,range)) * 65535 + range/2) / range);
00649          m_Blue = static_cast<UINT16>((static_cast<UINT32>(bound(blue,0,range)) * 65535 + range/2) / range);
00650          m_flags |= STATUS_ValueSet;
00651          m_flags &= ~STATUS_NonRGB;
00652          return;
00653          }
00654 
00655       //! Set transparency value.
00656       void SetTransparency (
00657          UINT8 transparency               //!< Value to set, 0 = opaque, 255 = 100% transparent
00658          ) {
00659          m_flags &= ~MASK_Transparency;
00660          m_flags |= static_cast<UINT16>(transparency) << 8;
00661          if (transparency < 255) m_flags &= ~STATUS_Invisible;
00662          return;
00663          }
00664 
00665       //! Validate status for some legacy stored color instances.
00666       void Validate (
00667          ) { 
00668          if (m_flags == LEGACY_Invalid) m_flags = STATUS_ValueSet;
00669          return;
00670          }
00671 
00672    private:
00673       #ifndef GENERATING_DOXYGEN_OUTPUT
00674       UINT16 m_Red;
00675       UINT16 m_Green;
00676       UINT16 m_Blue;
00677       UINT16 m_flags;
00678 
00679    CHECKSIZE(8);
00680       #endif //!< GENERATING_DOXYGEN_OUTPUT
00681    };
00682 
00683 PREVENT_MEMCMP(COLOR)
00684 #undef   CLASSLIBEXPORT
00685 
00686 
00687 //! Compare COLORs for equality.
00688 inline bool operator== (
00689    const COLOR& lhs,
00690    const COLOR& rhs
00691    ) {
00692    return (lhs.IsEqualTo(rhs));
00693    }
00694 
00695 
00696 //! Compare COLORs for inequality.
00697 inline bool operator!= (
00698    const COLOR& lhs,
00699    const COLOR& rhs
00700    ) {
00701    return (!lhs.IsEqualTo(rhs));
00702    }
00703 
00704 
00705 inline void SwapBytes (
00706    COLOR& color
00707    ) {
00708    SwapBytes(reinterpret_cast<UINT16*>(&color), 4);
00709    return;
00710    }
00711 
00712 //===================================================================================================================
00713 
00714 #endif   //!< INC_MI32_COLOR_H

Generated on Tue Dec 14 13:18:19 2004 for TNTsdk by  doxygen 1.3.8-20040913