doccolor.h

Go to the documentation of this file.
00001 // $Id: doccolor.h 1605 2006-07-29 19:26:03Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 // doccolor.h - definitions for Camelot DocColour class
00099 
00100 
00101 #ifndef INC_DOCCOLOR
00102 #define INC_DOCCOLOR
00103 
00104 
00105 #include "colmodel.h"
00106 #include "stockcol.h"
00107 
00108 
00109 
00110 // This is defined in colcontx.h, but we define it here to eliminate dependencies
00111 #ifndef INC_COLCONTX
00112 class ColourContext;
00113 typedef UINT32 ColourContextHandle;
00114 #endif
00115 
00116 
00117 // these constants are used to set the Reserved flag in the Info struct when
00118 // colours are converted for use in Brush Attributes. - DY 12/4/2000
00119 const UINT32 COL_NAMED = 1;
00120 const UINT32 COL_BLACK = 2;
00121 const UINT32 COL_WHITE = 3;
00122 const UINT32 COL_OVERRIDABLE = 4;
00123 
00125 // DocColour Information struct
00126 // Each DocColour contains this information on its contents
00127 // Note:     The order of fields was chosen to encourage byte/word16 alignment
00128 // See Also: IndexedColourInfo (in colourix.h)
00129 
00130 typedef struct
00131 {
00132     UINT32 OCContextHandle  : 16;   // Handle of context of the cached colour
00133     UINT32 SourceColourModel    : 4;    // The ColourModel of the source colour data
00134     UINT32 CacheColourModel : 4;    // The ColourModel of the cached colour data
00135 
00136     UINT32 IsSeparable      : 1;    // TRUE if this colour should be separated
00137 
00138     UINT32 ForceRounding        : 1;    // TRUE if this colour should always be shown rounded to half-percents
00139                                             // (A bodge for PANTONE colours!)
00140     UINT32 Reserved         : 5;
00141 
00142     UINT32 NoColour         : 1;    // 'None' Flag: Colour is 100% transparent
00143 } ColourInfo;
00144 
00145 
00146 
00147 /********************************************************************************************
00148 
00149 >   class DocColour : public CC_CLASS_MEMDUMP
00150 
00151     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00152     Created:    30/03/94
00153     Purpose:    This class defines a colour.
00154                 A DocColour stores an original definition of a colour, a cache
00155                 containing the definition of the colour in the last colour
00156                 context in which it was used, and sundry information. DocColours
00157                 have been designed to be small things to put in attributes.
00158 
00159                 DocColours cannot be used on their own, however. They have meaning
00160                 only within the scope of a given colour context.
00161 
00162                 DocColours can be defined in any of the available colour models.
00163 
00164                 DocColours are stored to "low" (32-bit) precision, except when they
00165                 are references to IndexedColours (which are 128-bit precision).
00166                 However, colour calculations, and access to values stored in
00167                 colours are generally only available through the 128bit interface.
00168 
00169     Notes:      NOTE that any use of a DocColour may result in updating its cache,
00170                 so you must NOT treat DocColours as const anywhere. Also, work on
00171                 original DocColours rather than copies if you want the cache to
00172                 be kept fresh on the original.
00173 
00174     SeeAlso:    IndexedColour; ColourModel; ColourContext
00175     Documentation:  HowToUse\colours.doc
00176             
00177 ********************************************************************************************/
00178 
00179 class CCAPI DocColour : public CC_CLASS_MEMDUMP
00180 {
00181 friend class ColourContext;
00182 
00183 CC_DECLARE_MEMDUMP(DocColour)
00184 
00185 public:     // Construction/Destruction
00186     DocColour();
00187     ~DocColour();
00188 
00189     DocColour(StockColour Col);
00190             // Initialise with a non-separating stock colour. See kernel\stockcol.h
00191 
00192     DocColour(ColourModel ColModel, ColourGeneric *Col);
00193             // Initialise with a given colour definition
00194 
00195     DocColour(ColourValue Red, ColourValue Green, ColourValue Blue);
00196             // Initialise with RGB values (in the range 0.0-1.0)
00197 
00198     DocColour(const DocColour &other);
00199     DocColour& operator=(const DocColour&);
00200             // Copy constructor, assignment operator
00201 
00202 public:     // Linking to IndexedColours
00203     void MakeRefToIndexedColour(IndexedColour *Other);
00204             // Link this DocColour to a given IndexedColour parent
00205 
00206     inline IndexedColour *FindParentIndexedColour(void);
00207             // Get a pointer (or NULL if none) to this colour's IndexedColour parent
00208 
00209 #ifdef _DEBUG
00210             // Special function to provide extra tracing for Jason to detect where
00211             // "IndexedColour in use" problems originate. Only used in debug builds
00212 #define MakeRefToIndexedColour(Bob) MakeRefToIndexedColourDBG(Bob, THIS_FILE, __LINE__)
00213 #endif
00214 
00215     void MakeRefToIndexedColourDBG(IndexedColour *Other, LPCSTR TheFile = NULL, INT32 TheLine = 0);
00216             // Special debug version of MakeRefToIndexedColour
00217 
00218     IndexedColour *GetSpotParent(void);
00219             // Get the ultimate spot colour parent of this DocColour, if any
00220 
00221 
00222 public:     // Comparison operators
00223     BOOL operator==(const DocColour) const;
00224     BOOL operator!=(const DocColour) const;
00225 
00226 
00227 public:     // Interface
00228     ColourModel GetColourModel(void) const;
00229             // Get the colour model in which this colour is defined
00230 
00231     void GetSourceColour(ColourGeneric *Result);
00232             // Read the original colour definition in the GetColourModel() colour model
00233 
00234     inline BOOL IsTransparent(void) const;
00235             // Returns TRUE if this is "no colour"
00236 
00237     inline BOOL IsSeparable(void) const;
00238     void SetSeparable(BOOL IsSeparable = TRUE);
00239             // Determine/set flag to enable/disable separation and colour correction
00240 
00241     void Mix(DocColour *BlendStart, DocColour *BlendEnd, double BlendFraction,
00242                 ColourContext *BlendContext, BOOL BlendTheLongWay = FALSE,
00243                 ColourContext *OutputContext = NULL);
00244             // Redefine this colour as a blend/mix of two other colours
00245 
00246     void ForceRounding(BOOL RoundingOn) { Info.ForceRounding = RoundingOn; };
00247     BOOL IsForcedToRound(void) { return(Info.ForceRounding); };
00248             // Bodge for PANTONE colours - When Rounding is in effect, GetSourceColour will round all
00249             // returned components to the nearest half percent, which corrects the errors introduced
00250             // by using 0..255 values to represent the 200 possible half-percent values PANTONE use.
00251             // DO NOT USE THESE FUNCTIONS unless you know what you're doing
00252 
00253 
00254     // new functions to access the reserved flag
00255     void SetReservedFlag(UINT32 Value);
00256     UINT32 GetReservedFlag();
00257 
00258     BOOL IsNamed();
00259     void HackColReplacerPreDestruct();
00260 
00261 protected:      // Internal helper functions for RGB and HSV mixing
00262     void MixRGB(DocColour *BlendStart, DocColour *BlendEnd, double BlendFraction,
00263                 ColourContext *BlendContext);
00264             // Redefine this colour as a blend/mix of two other colours
00265 
00266     void MixCMYK(DocColour *BlendStart, DocColour *BlendEnd, double BlendFraction,
00267                 ColourContext *BlendContext);
00268             // Redefine this colour as a blend/mix of two other colours
00269 
00270     void MixHSV(DocColour *BlendStart, DocColour *BlendEnd, double BlendFraction,
00271                 ColourContext *BlendContext, BOOL BlendTheLongWay = FALSE);
00272             // Redefine this colour as a blend/mix of two other colours
00273 
00274     void MixTint(IndexedColour *SpotParent, IndexedColour *StartTint,
00275                     IndexedColour *EndTint, double BlendFraction);
00276             // Does a linear interpolation for tints, generating new local IndexedColours
00277             // to represent the resulting tint/shade values. Must only be used sparingly,
00278             // to avoid making millions of new local colours
00279 
00280 
00281 public:     // Debug helpers
00282     void GetDebugDetails(StringBase* Str);  // Appends details of self to Str
00283                                             // e.g. Str = "GradFill"
00284                                             // GetDebugDetails(&Str);
00285                                             // gives: "GradFill colour = (...)"
00286 
00287 
00288 public:     // Old interface - do not use these calls any more!
00289     void SetRGBValue(INT32 Red, INT32 Green, INT32 Blue);
00290     void GetRGBValue(INT32* Red, INT32* Green, INT32* Blue);
00291 
00292     void SetCMYKValue(PColourCMYK *New); 
00293     void GetCMYKValue(PColourCMYK *Result);
00294     void GetCMYKValue(ColourContext* pContext, PColourCMYK *Result);
00295 
00296     void SetHSVValue(INT32 h, INT32 s, INT32 v);
00297     void GetHSVValue(INT32* h, INT32* s, INT32* v);
00298 
00299     DocColour(INT32 Red, INT32 Green, INT32 Blue);
00300 
00301 
00302 protected:
00303     ColourInfo      Info;
00304     ColourPacked    SourceColour;
00305     ColourPacked    CachedColour;
00306 
00307 
00308 protected:
00309     void InitialiseInfoField(ColourModel ColModel);
00310 
00311     // We need this because the ColourPacked entries are different sizes, and therefore incompletely
00312     // initialized when set up with a colour model smaller than the default. This causes issues on
00313     // retail builds because we later memcmp the entire structure to tell if colours are the same.
00314     void ZapSourceColour() {memset(&SourceColour, 0, sizeof(SourceColour)); memset(&CachedColour, 0, sizeof(CachedColour)); }
00315 };
00316 
00317 
00318 
00319 
00320 /********************************************************************************************
00321 
00322 <   DOCCOLOUR_RGBT(col)
00323 <   DOCCOLOUR_HSVT(col)
00324 <   DOCCOLOUR_CMYK(col)
00325 <   DOCCOLOUR_CIET(col)
00326 
00327     Comment:    These macros simplify construction of DocColour objects in
00328                 given colour models. Use something like this:
00329 
00330                 {
00331 
00332                     ColourRGBT TheDefinition;
00333 
00334                     DocColour  TheColour = DOCCOLOURRGBT(&TheDefinition);
00335 
00336                 }
00337 
00338     Notes:      Note that these macros explicitly cast 'col' to a
00339                 (ColourGeneric *), so if it is not a pointer to a 128-bit
00340                 colour structure (ColourGeneric, ColourRGBT, ColourCIET etc)
00341                 then nasty things may occur.
00342 
00343     SeeAlso:    DocColour::DocColour
00344 
00345 ********************************************************************************************/
00346 
00347 #define DOCCOLOUR_RGBT(col) DocColour(COLOURMODEL_RGBT, (ColourGeneric *) col)
00348 #define DOCCOLOUR_HSVT(col) DocColour(COLOURMODEL_HSVT, (ColourGeneric *) col)
00349 #define DOCCOLOUR_CMYK(col) DocColour(COLOURMODEL_CMYK, (ColourGeneric *) col)
00350 #define DOCCOLOUR_CIET(col) DocColour(COLOURMODEL_CIET, (ColourGeneric *) col)
00351 
00352 
00353 
00354 
00355 
00356 /********************************************************************************************
00357 
00358 >   inline BOOL DocColour::IsTransparent() const
00359 
00360     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00361     Created:    14/04/94
00362     Inputs:     -
00363     Outputs:    -
00364     Returns:    TRUE if the colour is "no colour" ("transparent").
00365     Purpose:    Determines if a colour's "no colour" flag is set
00366     SeeAlso:    -
00367 
00368 ********************************************************************************************/
00369 
00370 inline BOOL DocColour::IsTransparent(void) const
00371 {
00372     return(Info.NoColour);
00373 }
00374 
00375 /********************************************************************************************
00376 
00377 >   inline BOOL DocColour::IsSeparable() const
00378 
00379     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00380     Created:    17/5/96
00381 
00382     Returns:    TRUE if the colour is allowed to be colour separated and/or corrected
00383                 during colour conversions.
00384 
00385     Purpose:    Determines if a colour's "IsSeparable" flag is set
00386     SeeAlso:    DocColour::SetSeparable
00387 
00388 ********************************************************************************************/
00389 
00390 inline BOOL DocColour::IsSeparable(void) const
00391 {
00392     return(Info.IsSeparable);
00393 }
00394 
00395 
00396 
00397 /********************************************************************************************
00398 
00399 >   inline IndexedColour *DocColour::FindParentIndexedColour(void);
00400 
00401     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00402     Created:    7/6/94
00403     Inputs:     -
00404     Outputs:    -
00405     Returns:    NULL if this is an immediate colour
00406                 else a pointer to the IndexedColour which this DocColour references
00407     Purpose:    Determines if a colour references an IndexedColour, and if so, gives
00408                 access to the parent colour.
00409     SeeAlso:    DocColour::MakeRefToIndexedColour
00410 
00411 ********************************************************************************************/
00412 
00413 inline IndexedColour *DocColour::FindParentIndexedColour(void)
00414 {
00415     if (Info.SourceColourModel != COLOURMODEL_INDEXED)
00416         return(NULL);
00417 
00418     return(SourceColour.Indexed.Colour);
00419 }
00420 
00421 #endif      // INC_DOCCOLOR
00422 

Generated on Sat Nov 10 03:45:02 2007 for Camelot by  doxygen 1.4.4