00001 // $Id: colcontx.h 1282 2006-06-09 09:46:49Z 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 // colcontx.h - Output colour context 00099 00100 00101 #ifndef INC_COLCONTX 00102 #define INC_COLCONTX 00103 00104 00105 //#include "colcarry.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00106 //#include "colmodel.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00107 //#include "doccolor.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00108 //#include "document.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00109 //#include "ensure.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00110 //#include "list.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00111 //#include "listitem.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00112 //#include "xaracms.h" 00113 00114 00115 class StringBase; 00116 class UnitGroup; 00117 class View; 00118 00119 // Phil 24/02/2004 00120 // Define this variable if you want to disable the old WEBRGBT colour model and 00121 // transfer any remaining use of it (for instance in old documents) to the RGBT model 00122 #define DISABLE_WEBRGBT 1 00123 00124 00126 // ColourContextHandle 00127 // This is a handle which uniquely identifies a given Colour Context 00128 // The value is only 16 bits wide, hence it is safe to use an 'INT32' 00129 // The handle 0 may be used internally to indicate invalid contexts 00130 // 00131 // NOTE: To remove dependencies, this is also defined in doccolor.h, colourix.h 00132 00133 typedef UINT32 ColourContextHandle; 00134 00135 00136 /******************************************************************************************** 00137 00138 > class ColourContext : public ListItem 00139 00140 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00141 Created: 30/03/94 00142 Purpose: 00143 This class defines a colour context. This is a description of the context 00144 in which a colour has been defined, including a colour model and extra 00145 information on special conversion transformations (e.g. for the RGB colour 00146 model, an extra conversion parameter is 'Gamma correction'). 00147 00148 To use any Colour, the colour context in which it is defined must be 00149 available. A set of default colour contexts (one per available colour model) 00150 is kept globally, within each Camelot document, and for each Camelot View. 00151 (Actually, the document defaults are a bit defunct now). 00152 00153 To convert a colour to a different colour model, it is necessary to supply 00154 the colour context in which the colour is defined, plus a colour context 00155 describing the destination format (although in most cases the former is 00156 described implicitly) 00157 00158 Colour contexts make it possible to have several different instantiations 00159 of a colour model in use at once (e.g. RGB, RGB with gamma correction, and 00160 RGB for display of the Cyan plate of a CMYK separation), and are also used 00161 to allow caching of colours in output colour contexts in order to speed 00162 up time critical operations such as rendering. 00163 00164 SeeAlso: Colour; ColourModel; ColourContextList; ColourPlate 00165 Documentation: HowToUse\colours.doc 00166 00167 ********************************************************************************************/ 00168 00169 class CCAPI ColourContextRGBT; 00170 class CCAPI ColourPlate; 00171 00172 00173 class CCAPI ColourContext : public ListItem 00174 { 00175 friend class DocColour; // Give DocColour access to [Un]PackColour() etc 00176 friend class ColourContextList; // Give CCList access to Init etc functions 00177 00178 friend class GRenderRegion; 00179 friend class OSRenderRegion; 00180 00181 CC_DECLARE_MEMDUMP(ColourContext) 00182 00183 public: 00184 // Constructor 00185 ColourContext(View *Scope); 00186 00187 00188 // Destructor 00189 virtual ~ColourContext(); 00190 00191 00192 // Class initialiser/deinitialiser (called from app.cpp on init/deinit) 00193 static BOOL InitColourContexts(void); 00194 static void DeinitColourContexts(void); 00195 00196 00197 // Interface 00198 virtual BOOL IsDifferent(ColourContext *Other) const; 00199 00200 inline void ConvertColour(DocColour *Source, ColourGeneric *Result); 00201 void ConvertColour(IndexedColour *Source, ColourGeneric *Result); 00202 void ConvertColour(ColourContext *SourceContext, ColourGeneric *SourceColour, 00203 ColourGeneric *Result); 00204 00205 virtual void ConvertToCIET(ColourGeneric *Source, DColourCIET *Result) = 0; 00206 virtual void ConvertFromCIET(DColourCIET *Source,ColourGeneric *Result) = 0; 00207 virtual void CreateExternalTransform(); 00208 00209 inline ColourModel GetColourModel(void) const; 00210 00211 // Access to global default colour contexts 00212 inline static ColourContext *GetGlobalDefault(ColourModel ColModel); 00213 inline static void GetGlobalDefaults(ColourContextArray *Destination); 00214 inline static ColourContextRGBT *GetCurrentForScreen(void); 00215 00216 // Determining the text names of this context's colour model and colour components 00217 virtual void GetModelName(StringBase *Result) = 0; 00218 virtual BOOL GetComponentName(INT32 ComponentID, StringBase *Result, BOOL LongName = FALSE) = 0; 00219 virtual UINT32 GetComponentCount() = 0; 00220 virtual BOOL SetComponentUnitGroup(UINT32 ComponentID, UnitGroup *pComponentUnitGroup); 00221 virtual UnitGroup *GetComponentUnitGroup(UINT32 ComponentID); 00222 00223 // Applying Tinting and Shading to a source colour 00224 virtual void ApplyTint(ColourValue TintFraction, ColourGeneric *SourceAndResult) = 0; 00225 virtual void ApplyShade(ColourValue XFraction, ColourValue YFraction, ColourGeneric *SourceAndResult) = 0; 00226 00227 // Pre/Post-processing output colours for providing Colour Separations etc 00228 virtual void ApplyInputFilter(ColourPlate *FilterDescription, ColourContext *DestContext, 00229 ColourGeneric *OutputColour, IndexedColour *SourceIxCol); 00230 virtual void ApplyOutputFilter(ColourPlate *FilterDescription, ColourContext *SourceContext, 00231 ColourGeneric *OutputColour, IndexedColour *SourceIxCol); 00232 00233 // Setting/Reading the ColourPlate descriptor for this context's output filter 00234 void SetColourPlate(ColourPlate *NewColourPlate); 00235 ColourPlate *GetColourPlate(void); 00236 ColourPlate *DetachColourPlate(void); 00237 00238 // Internal function for ColourPlates - this "flushes" all cached colours in this context 00239 // by changing our ColourContextHandle. Should be used as infrequently as possible! 00240 void ColourPlateHasChanged(void); 00241 00242 // Getting white as it is expressed in this colour model 00243 virtual void GetWhite(ColourGeneric *Result) = 0; 00244 virtual BOOL GetProfileTables(BYTE* Tables) { return FALSE; } 00245 00246 // Determine whether this colour context is logical or physical (device) 00247 PORTNOTE("other","Removed HCMTRANSFORM usage") 00248 #ifndef EXCLUDE_FROM_XARALX 00249 virtual BOOL IsDeviceContext() const { return CMSTransform != NULL; } 00250 #endif 00251 00252 protected: 00253 ColourContextHandle MyHandle; // Our own OutputColourContext handle 00254 INT32 UsageCount; // Count of references to this object 00255 00256 ColourModel ColModel; // The contexts colour model 00257 00258 ColourPlate *ColPlate; // Describes colour plate/separation 00259 00260 PORTNOTE("other","Removed HCMTRANSFORM usage") 00261 #ifndef EXCLUDE_FROM_XARALX 00262 HCMTRANSFORM CMSTransform; // A handle to the calibration manager transform, or NULL 00263 #endif 00264 00265 View *ScopeView; // The view within which this context lives. Used to 00266 // find "sibling" colour contexts when colour separating 00267 00268 protected: 00269 static ColourContextHandle NextColourContextHandle; 00270 // Used to generate unique Context handles 00271 00272 protected: 00273 // Functions used by our Friend class, ColourContextList 00274 // Colour contexts *cannot* be used wihtout first being added to the 00275 // global ColourContext list. IncrementUsage and DecrementUsage therefore 00276 // should only be called by the list when another instance of the thing 00277 // is added/removed. 00278 // SetDefault is used by ColourContextList::InitCC's to set our static data 00279 virtual BOOL Init(void); 00280 inline static void SetGlobalDefault(ColourModel ColModel, ColourContext *Default); 00281 00282 BOOL DecrementUsage(void); 00283 inline void IncrementUsage(void); 00284 00285 00286 // Functions used by our Friend class, DocColour. 00287 // {Un}PackColour are used on generic colour structs. Derived classes will 00288 // override this function if necessary to change its default behaviour 00289 virtual void PackColour(ColourGeneric *Source, ColourPacked *Result); 00290 virtual void UnpackColour(ColourPacked *Source, ColourGeneric *Result); 00291 00292 void ConvertColourInternal(DocColour *Source, ColourGeneric *Result); 00293 void ConvertColourInternal(DocColour *Source, ColourPacked *Result); 00294 00295 // Functions for use only in colcontx.cpp 00296 inline PColourValue PackColour128(ColourValue Source); 00297 inline void UnpackColour128(PColourValue Source, FIXED24 *Result); 00298 00299 inline PColourValue PackColour256(ColourValue Source); 00300 inline void UnpackColour256(PColourValue Source, FIXED24 *Result); 00301 00302 inline PColourValue PackColour360(ColourValue Source); 00303 inline void UnpackColour360(PColourValue Source, FIXED24 *Result); 00304 00305 virtual UnitGroup **GetComponentUnitGroups() = 0; 00306 00307 public: 00308 // Functions for whipping out a colour in a packed format. These are not intended 00309 // for general use (mainly for getting 24bit RGB easily for rendering). 00310 inline void ConvertColour(DocColour *Source, ColourPacked *Result); 00311 00312 private: 00313 static ColourContextArray GlobalDefaultContext; 00314 00315 protected: 00316 virtual void ConvertColourBase(ColourContext *SourceContext, 00317 ColourGeneric *Source, ColourGeneric *Result, 00318 IndexedColour *SourceIxCol = NULL); 00319 }; 00320 00321 00322 00323 /******************************************************************************************** 00324 00325 > inline void ColourContext::IncrementUsage(void) 00326 00327 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00328 Created: 31/03/94 00329 Inputs: - 00330 Outputs: - 00331 Returns: - 00332 Purpose: Increments usage-count for a colour context. This count allows us to 00333 determine when we can delete unused contexts. 00334 00335 Notes: The usage count for a colour context defaults to 0 00336 ("not in use"). When using colour contexts, you should always 00337 register them with the global ColContextList object (see 00338 ColourContextList::AddContext for details) 00339 00340 Errors: - 00341 SeeAlso: ColourContext::DecrementUsage; ColourContextList::AddContext 00342 00343 ********************************************************************************************/ 00344 00345 inline void ColourContext::IncrementUsage(void) 00346 { 00347 UsageCount++; 00348 } 00349 00350 00351 00352 /******************************************************************************************** 00353 00354 > inline ColourModel ColourContext::GetColourModel(void) 00355 00356 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00357 Created: 31/03/94 00358 Inputs: - 00359 Outputs: - 00360 Returns: The colour model on which this colour context is based 00361 Purpose: Determines the colour model on which this colour context is based 00362 Errors: - 00363 SeeAlso: - 00364 00365 ********************************************************************************************/ 00366 00367 inline ColourModel ColourContext::GetColourModel(void) const 00368 { 00369 return(ColModel); 00370 } 00371 00372 00373 00374 /******************************************************************************************** 00375 00376 > inline static ColourContext *ColourContext::GetCurrentForScreen(void) 00377 00378 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00379 Created: 23/04/94 00380 Inputs: - 00381 Outputs: - 00382 Returns: A pointer to the current screen output colour context for the given colour 00383 model. (This will either be the Selected Document's RGBT output context, or 00384 the global default output context, if Selected Document returns NULL) 00385 00386 Purpose: Code used by all renderers to find the current screen output context 00387 00388 Notes: If you're colour separating, then you should use the context for your 00389 current render View - this function just gives a logical global default. 00390 00391 ********************************************************************************************/ 00392 00393 inline ColourContextRGBT *ColourContext::GetCurrentForScreen(void) 00394 { 00395 Document *Scope = Document::GetSelected(); 00396 00397 if (Scope == NULL) 00398 return((ColourContextRGBT *) GlobalDefaultContext.Context[COLOURMODEL_RGBT]); 00399 else 00400 return((ColourContextRGBT *) 00401 Scope->GetDefaultColourContexts()->Context[COLOURMODEL_RGBT]); 00402 } 00403 00404 00405 00406 /******************************************************************************************** 00407 00408 > inline static ColourContext *ColourContext::GetGlobalDefault(ColourModel ColModel) 00409 00410 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00411 Created: 13/04/94 00412 Inputs: - 00413 Outputs: - 00414 Returns: A pointer to the default colour context for the given colour model, 00415 within the GLOBAL scope. 00416 Purpose: Find a default colour context for a given colour model number within 00417 GLOBAL scope. This is a static function, so may be called without 00418 having to create an actual ColourContext instance. 00419 Errors: - 00420 SeeAlso: ColourContext::GetDefault 00421 00422 ********************************************************************************************/ 00423 00424 inline ColourContext *ColourContext::GetGlobalDefault(ColourModel ColModel) 00425 { 00426 #ifdef DISABLE_WEBRGBT 00427 if (ColModel==COLOURMODEL_WEBRGBT) 00428 ColModel = COLOURMODEL_RGBT; 00429 #endif 00430 ENSURE(ColModel >= 0 && ColModel < MAX_COLOURMODELS, 00431 "ColourContext::GetGlobalDefault - Illegal colour model!"); 00432 00433 ENSURE(GlobalDefaultContext.Context[ColModel] != NULL, 00434 "Requested global default Colour Context is NULL!"); 00435 00436 return(GlobalDefaultContext.Context[ColModel]); 00437 } 00438 00439 00440 00441 /******************************************************************************************** 00442 00443 > inline static void GetGlobalDefaults(ColourContextArray *Destination) 00444 00445 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00446 Created: 13/04/94 00447 Inputs: - 00448 Outputs: The supplied destination ColourContextArray will be filled with 00449 a copy of the global array of default colour context pointers 00450 Returns: - 00451 Purpose: Find the default contexts used by this 00452 Scope: Pretty private. Should only need to be used by document.cpp 00453 Errors: - 00454 SeeAlso: - 00455 00456 ********************************************************************************************/ 00457 00458 inline void ColourContext::GetGlobalDefaults(ColourContextArray *Destination) 00459 { 00460 memcpy(Destination, &GlobalDefaultContext, sizeof(ColourContextArray)); 00461 } 00462 00463 00464 00465 /******************************************************************************************** 00466 00467 > inline static void ColourContext::SetGlobalDefault(ColourModel ColModel, ColourContext *Default) 00468 00469 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00470 Created: 13/04/94 00471 Inputs: - 00472 Outputs: - 00473 Returns: - 00474 Purpose: Set the default colour context for a given colour model number 00475 Scope: private - used internally by ColourContextList::InitColourContexts 00476 Errors: - 00477 SeeAlso: - 00478 00479 ********************************************************************************************/ 00480 00481 inline void ColourContext::SetGlobalDefault(ColourModel ColModel, ColourContext *Default) 00482 { 00483 #ifdef DISABLE_WEBRGBT 00484 if (ColModel==COLOURMODEL_WEBRGBT) 00485 ColModel = COLOURMODEL_RGBT; 00486 #endif 00487 GlobalDefaultContext.Context[ColModel] = Default; 00488 } 00489 00490 00491 00492 /******************************************************************************************** 00493 00494 > inline PColourValue ColourContext::PackColour128(ColourValue Source) 00495 00496 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00497 Created: 13/04/94 00498 Inputs: Source - The source FIXED24 value to be packed into an 8-bit value 00499 Returns: A packed representation of the input value 00500 00501 Purpose: Given a 32-bit (FIXED24) colour definition value, packs it into a 00502 7-bit (unsigned byte) colour definition value. The value is rounded 00503 and clipped to lie within gamut (0.0 <= g <= 1.0). 00504 00505 Scope: private - used internally by ColourContext code 00506 SeeAlso: ColourContext::UnpackColour128 00507 00508 ********************************************************************************************/ 00509 00510 inline PColourValue ColourContext::PackColour128(ColourValue Source) 00511 { 00512 // Get the value as a fixed24 INT32, and round it up by half a 0..127 value 00513 INT32 result = Source.GetAsFixed24() + 0x00010000; 00514 00515 // Clip the value into the FIXED24 range 0.0 - 1.0 00516 if (result > 0x01000000) 00517 result = 0x01000000; 00518 00519 if (result < 0) 00520 result = 0; 00521 00522 // Multiply by 127, and shift the resulting value down to get a 7-bit value 00523 result = (result * 127) >> 24; 00524 00525 return((PColourValue) result); 00526 } 00527 00528 00529 00530 /******************************************************************************************** 00531 00532 > inline void ColourContext::UnpackColour128(PColourValue Source, FIXED24 *Result) 00533 00534 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00535 Created: 13/04/94 00536 Inputs: Source - The packed input value, as a 7-bit (0..127) value. 00537 Outputs: Result - is filled in on exit with an unpacked (FIXED24) version of the 00538 source 7-bit value 00539 00540 Purpose: Unpacks the packed source colour value into a FIXED24 unpacked format 00541 00542 Scope: private - used internally by ColourContext code 00543 SeeAlso: ColourContext::PackColour128 00544 00545 ********************************************************************************************/ 00546 00547 inline void ColourContext::UnpackColour128(PColourValue Source, FIXED24 *Result) 00548 { 00549 INT32 temp = (INT32) Source; 00550 00551 if (temp >= 127) // If hit upper limit of gamut, return 1.0 00552 *Result = 1.0; 00553 else 00554 { 00555 if (temp <= 0) // if hit lower limit of gamut, return 0.0 00556 *Result = 0; 00557 else 00558 { 00559 // Repeat the 7 bit value 4 times in the bottom 24 bits of the word 00560 // (losing the LS 4 bits of the LS copy off the end, hence ">>4") 00561 Result->SetAsFixed24((temp >> 4) | (temp << 3) | (temp << 10) | (temp << 17)); 00562 } 00563 } 00564 } 00565 00566 00567 00568 /******************************************************************************************** 00569 00570 > inline PColourValue ColourContext::PackColour256(ColourValue Source) 00571 00572 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00573 Created: 13/04/94 00574 Inputs: Source - The source FIXED24 value to be packed into an 8-bit value 00575 Returns: A packed representation of the input value 00576 00577 Purpose: Given a 32-bit (FIXED24) colour definition value, packs it into an 00578 8-bit (unsigned byte) colour definition value. The value is rounded 00579 and clipped to lie within gamut (0.0 <= g <= 1.0). 00580 00581 Scope: private - used internally by ColourContext code 00582 SeeAlso: ColourContext::UnpackColour256 00583 00584 ********************************************************************************************/ 00585 00586 inline PColourValue ColourContext::PackColour256(ColourValue Source) 00587 { 00588 // Get the value as a fixed24 INT32, and round it up by half a 0..255 value 00589 INT32 result = Source.GetAsFixed24() + 0x00008000; 00590 00591 // Clip the value into the FIXED24 range 0.0 - 1.0 00592 if (result > 0x01000000) 00593 result = 0x01000000; 00594 00595 if (result < 0) 00596 result = 0; 00597 00598 // Multiply by 255, and shift the resulting value down to get a byte value 00599 result = (result * 255) >> 24; 00600 00601 return((PColourValue) result); 00602 } 00603 00604 00605 00606 /******************************************************************************************** 00607 00608 > inline void ColourContext::UnpackColour256(PColourValue Source, FIXED24 *Result) 00609 00610 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00611 Created: 13/04/94 00612 Inputs: Source - The packed input value, as a 8-bit (0..255) value. 00613 Outputs: Result - is filled in on exit with an unpacked (FIXED24) version of the 00614 source 8-bit value 00615 00616 Purpose: Unpacks the packed source colour value into a FIXED24 unpacked format 00617 00618 Scope: private - used internally by ColourContext code 00619 SeeAlso: ColourContext::PackColour256 00620 00621 ********************************************************************************************/ 00622 00623 inline void ColourContext::UnpackColour256(PColourValue Source, FIXED24 *Result) 00624 { 00625 INT32 temp = (INT32) Source; 00626 00627 if (temp >= 255) // If hit upper limit of gamut, return 1.0 00628 *Result = 1.0; 00629 else 00630 { 00631 if (temp <= 0) // If hit lower limit of gamut, return 0.0 00632 *Result = 0; 00633 else 00634 Result->SetAsFixed24(temp | (temp << 8) | (temp << 16)); 00635 } 00636 } 00637 00638 00639 00640 /******************************************************************************************** 00641 00642 > inline PColourValue ColourContext::PackColour360(ColourValue Source) 00643 00644 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00645 Created: 13/04/94 00646 Inputs: Source - The source FIXED24 value to be packed into a 9-bit value 00647 Returns: A packed representation of the input value 00648 00649 Purpose: Given a 32-bit (FIXED24) colour definition value, packs it into a 00650 9-bit (0..359) colour definition value. The value is rounded 00651 and clipped to lie within gamut (0.0 <= g <= 1.0). 00652 00653 Scope: private - used internally by ColourContext code 00654 SeeAlso: ColourContext::UnpackColour360 00655 00656 ********************************************************************************************/ 00657 00658 inline PColourValue ColourContext::PackColour360(ColourValue Source) // 8-bit (Most values) 00659 { 00660 /* 00661 // Get the value as a fixed24 INT32, and round it up by half a 0..360 value 00662 INT32 result = Source.GetAsFixed24() + 0x00005606; 00663 00664 // Clip the value into the FIXED24 range 0.0 - 1.0 00665 if (result > 0x01000000) 00666 result = 0x01000000; 00667 00668 if (result < 0) 00669 result = 0; 00670 00671 // Convert to 9.23 bit fixed point, to avoid overflow in the multiply below 00672 result >>= 1; 00673 00674 // Multiply by 255, and shift the resulting value down to get a byte value 00675 result = (result * 359) >> 23; 00676 */ 00677 00678 // Doubles are more accurate, simpler, and quite possibly faster than the code above 00679 double result = (Source.MakeDouble() * 359.0) + 0.5; 00680 00681 if (result > 359.0) 00682 result = 359.0; 00683 00684 if (result < 0.0) 00685 result = 0.0; 00686 00687 return((PColourValue) result); 00688 } 00689 00690 00691 00692 /******************************************************************************************** 00693 00694 > inline void ColourContext::UnpackColour360(PColourValue Source, FIXED24 *Result) 00695 00696 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00697 Created: 13/04/94 00698 Inputs: Source - The packed input value, as a 9-bit (0..359) value. 00699 Outputs: Result - is filled in on exit with an unpacked (FIXED24) version of the 00700 source 9-bit value 00701 00702 Purpose: Unpacks the packed source colour value into a FIXED24 unpacked format 00703 00704 Scope: private - used internally by ColourContext code 00705 SeeAlso: ColourContext::PackColour360 00706 00707 ********************************************************************************************/ 00708 00709 inline void ColourContext::UnpackColour360(PColourValue Source, FIXED24 *Result) 00710 { 00711 /* 00712 INT32 temp = (INT32) Source; 00713 00714 if (temp > 359) temp = 359; 00715 if (temp < 0) temp = 0; 00716 00717 // The number fits into 9 bits, so shift it up to get 9.23 bit fixed point 00718 // then divide by 359 to scale it, then shift it up by one more bit 00719 // to convert into 8.24 fixed point (thus we lose the 24th bit of accuracy) 00720 00721 temp = (temp << 23) / 359; // Get scaled value as 9.23 bit fp 00722 00723 Result->SetAsFixed24(temp << 1); // Convert to 8.24 fp and then to FIXED24 00724 */ 00725 00726 // Doubles are more accurate, simpler, and quite possibly faster than the code above 00727 double temp = Source; 00728 00729 temp /= 359.0; 00730 00731 if (temp < 0.0) 00732 temp = 0.0; 00733 00734 if (temp > 1.0) 00735 temp = 1.0; 00736 00737 *Result = temp; 00738 } 00739 00740 00741 00742 /******************************************************************************************** 00743 00744 > inline void ColourContext::ConvertColour(DocColour *Source, ColourGeneric *Result) 00745 00746 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00747 Created: 29/04/94 00748 Inputs: Source - A Colour to convert 00749 Result - A ColourGeneric structure to recieve the resulting converted colour, 00750 as defined in this ColourContext. 00751 Outputs: - 00752 Returns: - 00753 Purpose: Converts a Colour into this colour context. 00754 The converted colour will be supplied from a cache where possible 00755 Errors: - 00756 SeeAlso: - 00757 00758 ********************************************************************************************/ 00759 00760 inline void ColourContext::ConvertColour(DocColour *Source, ColourGeneric *Result) 00761 { 00762 ENSURE(UsageCount > 0, "Colour context being used when not initialised!"); 00763 ConvertColourInternal(Source, Result); 00764 } 00765 00766 00767 00768 /******************************************************************************************** 00769 00770 > inline void ColourContext::ConvertColour(DocColour *Source, ColourPacked *Result) 00771 00772 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00773 Created: 14/04/94 00774 Inputs: Source - A Colour to convert 00775 Result - A PColourGeneric structure to recieve the resulting converted colour, 00776 as defined in this ColourContext. 00777 Outputs: - 00778 Returns: - 00779 Purpose: Converts a Colour into this colour context. 00780 The converted colour will be supplied from a cache where possible 00781 Scope: PRIVATE - for use only by 'friend' rendering classes: 00782 OSRenderRegion, GRenderRegion 00783 Errors: - 00784 SeeAlso: - 00785 00786 ********************************************************************************************/ 00787 00788 inline void ColourContext::ConvertColour(DocColour *Source, ColourPacked *Result) 00789 { 00790 ENSURE(UsageCount > 0, "Colour context being used when not initialised!"); 00791 ConvertColourInternal(Source, Result); 00792 } 00793 00794 00795 00796 00797 00798 00799 00800 00801 00802 00803 00804 00805 00806 00807 00808 00809 00810 00811 00812 /******************************************************************************************** 00813 00814 > class ColourContextList : public List 00815 00816 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00817 Created: 02/04/94 00818 Purpose: Defines a list of colour contexts, as must be kept on a global basis. 00819 This is a perfectly normal list, except it has a special function to 00820 add a ColourContext item to the list, which ensures that no duplicate 00821 colour contexts are ever used, and that the usage count for any shared 00822 context is properly updated. 00823 00824 SeeAlso: ColourContextList::AddContext; ColourContextList::RemoveContext; 00825 List; Colour; ColourModel; ColourContext 00826 Documentation: HowToUse\colours.doc 00827 00828 ********************************************************************************************/ 00829 00830 00831 class CCAPI ColourContextList : public List 00832 { 00833 00834 CC_DECLARE_MEMDUMP(ColourContextList) 00835 00836 public: 00837 // Specialised methods to add/remove contexts to/from the list 00838 void AddContext(ColourContext **NewContext); 00839 void RemoveContext(ColourContext **OldContext); 00840 00841 00842 // Class initialiser/deinitialiser (called from app.cpp on init/deinit) 00843 static BOOL InitColourContexts(void); 00844 static void DeinitColourContexts(void); 00845 00846 // Access to 'global' data structure 'ColContextList' 00847 inline static ColourContextList *GetList(void); 00848 00849 00850 private: 00851 static ColourContextList *ColContextList; 00852 }; 00853 00854 00855 00856 /******************************************************************************************** 00857 00858 > inline static ColourContextList *ColourContextList::GetList(void) 00859 00860 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00861 Created: 13/04/94 00862 Inputs: - 00863 Outputs: - 00864 Returns: A pointer to the list of colour contexts 00865 Purpose: Find the 'global' list of current colour contexts 00866 Errors: - 00867 SeeAlso: - 00868 00869 ********************************************************************************************/ 00870 00871 inline ColourContextList *ColourContextList::GetList(void) 00872 { 00873 return(ColContextList); 00874 } 00875 00876 00877 00878 00879 00880 00881 00882 00883 00884 00885 /******************************************************************************************** 00886 00887 > class ColourContextRGBT : public ColourContext 00888 00889 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00890 Created: 02/04/94 00891 Purpose: Object class representing colour contexts based upon the RGBT 00892 colour model (Red, Green, Blue, Transparent) 00893 SeeAlso: Colour; ColourModel; ColourContext; 00894 ColourContextRGBT::ColourContextRGBT 00895 Documentation: HowToUse\colours.doc 00896 00897 ********************************************************************************************/ 00898 00899 class CCAPI ColourContextRGBT : public ColourContext 00900 { 00901 friend class DocColour; // Give DocColour access to [Un]PackColour() etc 00902 friend class ColourContextList; // Give CCList access to Init etc functions 00903 00904 friend class Colour; // Colour needs access to [Un]PackColour() but 00905 // ONLY in an RGBT output context 00906 00907 friend class GRenderRegion; 00908 friend class OSRenderRegion; 00909 00910 CC_DECLARE_MEMDUMP(ColourContextRGBT) 00911 00912 public: // Overridden Constructor 00913 ColourContextRGBT(View *Scope, double GammaValue = 1.0); 00914 00915 00916 public: // Overridden Interface 00917 void ConvertToCIET(ColourGeneric *Source, DColourCIET *Result); 00918 void ConvertFromCIET(DColourCIET *Source,ColourGeneric *Result); 00919 void CreateExternalTransform(); 00920 virtual void GetModelName(StringBase *Result); 00921 virtual BOOL GetComponentName(INT32 ComponentID, StringBase *Result, BOOL LongName = FALSE); 00922 virtual UINT32 GetComponentCount(); 00923 00924 virtual BOOL IsDifferent(ColourContext *Other) const; 00925 00926 00927 virtual void ApplyTint(ColourValue TintFraction, ColourGeneric *SourceAndResult); 00928 virtual void ApplyShade(ColourValue XFraction, ColourValue YFraction, ColourGeneric *SourceAndResult); 00929 00930 virtual void ApplyOutputFilter(ColourPlate *FilterDescription, ColourContext *SourceContext, 00931 ColourGeneric *OutputColour, IndexedColour *SourceIxCol); 00932 00933 virtual void GetWhite(ColourGeneric *Result); 00934 00935 public: // Derived-Class Interface 00936 double GetGamma(void) const; 00937 00938 inline DWORD ConvertToScreenWord(DocColour *Source); // For Renderers only 00939 inline DWORD ConvertToTransparentScreenWord(DocColour *Source); 00940 00941 00942 protected: 00943 double Gamma; // Example wossname data for an individual context 00944 00945 virtual UnitGroup **GetComponentUnitGroups(); 00946 00947 private: 00948 enum 00949 { 00950 MAX_COMPONENTS = 3 // Number of components in colour context 00951 }; 00952 static UnitGroup *m_pUnitGroupArray[MAX_COMPONENTS]; // unit groups used by RGB components 00953 }; 00954 00955 00956 00957 /******************************************************************************************** 00958 00959 > class ColourContextWebRGBT : public ColourContextRGBT 00960 00961 Author: Chris_Snook (Xara Group Ltd) <camelotdev@xara.com> 00962 Created: 6/11/99 00963 Purpose: This class inherits from class ColourContextRGBT, and although (at the 00964 moment) does not add any new functionality - provides us with an appropriate 00965 way of allowing us to edit RGBT in hexadecimal (i.e. rrggbb or 0xrrggbb web 00966 format). Reasons for this are: 1) so that I did NOT have to keep copying 00967 and pasting code for all the places that a colour model combobox appears. 00968 2) allow us to integrate correctly with the edit dialog (thereby not doing 00969 2). 3) make the addition of subsequent ColourContexts easier (since you 00970 won't have to worry about this class at all); and 4) cause I felft like it. 00971 SeeAlso: Colour; ColourModel; ColourContext; 00972 ColourContextRGBT::ColourContextRGBT 00973 Documentation: HowToUse\colours.doc 00974 00975 ********************************************************************************************/ 00976 00977 class CCAPI ColourContextWebRGBT : public ColourContextRGBT 00978 { 00979 CC_DECLARE_MEMDUMP(ColourContextWebRGBT) 00980 00981 public: // Overridden Constructor 00982 ColourContextWebRGBT(View *Scope, double GammaValue = 1.0); 00983 00984 virtual void GetModelName(StringBase *Result); 00985 }; 00986 00987 00988 00989 /******************************************************************************************** 00990 00991 > inline DWORD ColourContextRGBT::ConvertToScreenWord(DocColour *Source) 00992 00993 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00994 Created: 23/04/94 00995 Inputs: Source - the DocColour to convert 00996 Outputs: - 00997 Returns: The colour, converted into the current screen RGBT context, in the 00998 form of an RGB WORD (in the same format as a Microsoft/Gavin RGB word) 00999 i.e. 0x00BBGGRR 01000 Purpose: Conversion of colours for screen output, NOT including a transparency 01001 value (i.e. in a Windows GDI compatible format) 01002 Scope: Pretty private. Should only need to be used by renderers 01003 Errors: - 01004 SeeAlso: - 01005 01006 ********************************************************************************************/ 01007 01008 inline DWORD ColourContextRGBT::ConvertToScreenWord(DocColour *Source) 01009 { 01010 ColourPacked Result; 01011 01012 ConvertColour(Source, &Result); 01013 01014 DWORD tmp = (DWORD) Result.RGBT.Red; // (Compiler bug?) forced me 01015 tmp |= ((DWORD)Result.RGBT.Green) << 8; // to do this as 3 stmts instead 01016 tmp |= ((DWORD)Result.RGBT.Blue) << 16; // of only one. 01017 01018 return(tmp); 01019 } 01020 01021 01022 01023 /******************************************************************************************** 01024 01025 > inline DWORD ColourContextRGBT::ConvertToTransparentScreenWord(DocColour *Source) 01026 01027 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 01028 Created: 23/04/94 01029 Inputs: Source - the DocColour to convert 01030 Outputs: - 01031 Returns: The colour, converted into the current screen RGBT context, in the 01032 form of an RGB WORD (in the same format as a Gavin RGBT word) 01033 i.e. 0xTTBBGGRR 01034 Purpose: Conversion of colours for screen output, including a transparency 01035 value. (i.e in a Gavin compatible format, but NOT Windows GDI compatible) 01036 Scope: Pretty private. Should only need to be used by renderers 01037 Errors: - 01038 SeeAlso: - 01039 01040 ********************************************************************************************/ 01041 01042 inline DWORD ColourContextRGBT::ConvertToTransparentScreenWord(DocColour *Source) 01043 { 01044 ColourPacked Result; 01045 01046 ConvertColour(Source, &Result); 01047 01048 DWORD tmp = (DWORD) Result.RGBT.Red; 01049 tmp |= ((DWORD)Result.RGBT.Green) << 8; 01050 tmp |= ((DWORD)Result.RGBT.Blue) << 16; 01051 tmp |= ((DWORD)Result.RGBT.Transparent) << 24; 01052 01053 return(tmp); 01054 } 01055 01056 01057 01058 01059 01060 01061 01062 01063 01064 /******************************************************************************************** 01065 01066 > class ColourContextCMYK : public ColourContext 01067 01068 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 01069 Created: 14/04/94 01070 Purpose: Object class representing colour contexts based upon the CMYK 01071 colour model (Cyan, Magenta, Yellow, Key) 01072 SeeAlso: Colour; ColourModel; ColourContext; 01073 ColourContextCMYK::ColourContextCMYK 01074 Documentation: HowToUse\colours.doc 01075 01076 ********************************************************************************************/ 01077 01078 class CCAPI ColourContextCMYK : public ColourContext 01079 { 01080 friend class DocColour; // Give DocColour access to [Un]PackColour() etc 01081 friend class ColourContextList; // Give CCList access to Init etc functions 01082 01083 friend class GRenderRegion; 01084 friend class OSRenderRegion; 01085 01086 CC_DECLARE_MEMDUMP(ColourContextCMYK) 01087 01088 public: // Overridden Constructor 01089 ColourContextCMYK(View *Scope); 01090 // Construct a "logical" CMYK context 01091 01092 ColourContextCMYK(View *Scope, StringBase *NewProfileName); 01093 // Construct a CMYK context for a specific device profile 01094 01095 01096 public: // Overridden Interface 01097 void ConvertToCIET(ColourGeneric *Source, DColourCIET *Result); 01098 void ConvertFromCIET(DColourCIET *Source,ColourGeneric *Result); 01099 void CreateExternalTransform(); 01100 virtual void GetModelName(StringBase *Result); 01101 virtual BOOL GetComponentName(INT32 ComponentID, StringBase *Result, BOOL LongName = FALSE); 01102 virtual UINT32 GetComponentCount(); 01103 01104 virtual void ApplyTint(ColourValue TintFraction, ColourGeneric *SourceAndResult); 01105 virtual void ApplyShade(ColourValue XFraction, ColourValue YFraction, ColourGeneric *SourceAndResult); 01106 01107 virtual void ApplyInputFilter(ColourPlate *FilterDescription, ColourContext *DestContext, 01108 ColourGeneric *OutputColour, IndexedColour *SourceIxCol); 01109 virtual void ApplyOutputFilter(ColourPlate *FilterDescription, ColourContext *SourceContext, 01110 ColourGeneric *OutputColour, IndexedColour *SourceIxCol); 01111 01112 virtual BOOL IsDifferent(ColourContext *Other) const; 01113 01114 virtual void GetWhite(ColourGeneric *Result); 01115 01116 virtual BOOL GetProfileTables(BYTE* Tables); 01117 01118 public: // Derived-Class Interface 01119 String_256 *GetProfileName(void) { return(&ProfileName); }; 01120 01121 01122 protected: 01123 virtual UnitGroup **GetComponentUnitGroups(); 01124 01125 private: 01126 enum 01127 { 01128 MAX_COMPONENTS = 4 // Number of components in colour context 01129 }; 01130 static UnitGroup *m_pUnitGroupArray[MAX_COMPONENTS]; // unit groups used by RGB components 01131 01132 protected: // Special base-class override 01133 virtual void ConvertColourBase(ColourContext *SourceContext, 01134 ColourGeneric *Source, ColourGeneric *Result, 01135 IndexedColour *SourceIxCol = NULL); 01136 01137 protected: 01138 String_256 ProfileName; 01139 }; 01140 01141 01142 01143 01144 01145 /******************************************************************************************** 01146 01147 > class ColourContextHSVT : public ColourContext 01148 01149 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 01150 Created: 02/04/94 01151 Purpose: Object class representing colour contexts based upon the HSVT 01152 colour model (Red, Green, Blue, Transparent) 01153 SeeAlso: Colour; ColourModel; ColourContext; 01154 ColourContextHSVT::ColourContextHSVT 01155 Documentation: HowToUse\colours.doc 01156 01157 ********************************************************************************************/ 01158 01159 class CCAPI ColourContextHSVT : public ColourContext 01160 { 01161 friend class DocColour; // Give DocColour access to [Un]PackColour() etc 01162 friend class ColourContextList; // Give CCList access to Init etc functions 01163 01164 friend class GRenderRegion; 01165 friend class OSRenderRegion; 01166 01167 CC_DECLARE_MEMDUMP(ColourContextHSVT) 01168 01169 public: // Overridden Constructor 01170 ColourContextHSVT(View *Scope); 01171 01172 01173 public: // Overridden Interface 01174 void ConvertToCIET(ColourGeneric *Source, DColourCIET *Result); 01175 void ConvertFromCIET(DColourCIET *Source,ColourGeneric *Result); 01176 void CreateExternalTransform(); 01177 virtual void GetModelName(StringBase *Result); 01178 virtual BOOL GetComponentName(INT32 ComponentID, StringBase *Result, BOOL LongName = FALSE); 01179 virtual UINT32 GetComponentCount(); 01180 01181 virtual void ApplyTint(ColourValue TintFraction, ColourGeneric *SourceAndResult); 01182 virtual void ApplyShade(ColourValue XFraction, ColourValue YFraction, ColourGeneric *SourceAndResult); 01183 01184 virtual void GetWhite(ColourGeneric *Result); 01185 01186 protected: 01187 virtual void PackColour(ColourGeneric *Source, ColourPacked *Result); 01188 virtual void UnpackColour(ColourPacked *Source, ColourGeneric *Result); 01189 01190 virtual UnitGroup** GetComponentUnitGroups(); 01191 01192 private: 01193 enum 01194 { 01195 MAX_COMPONENTS = 3 // Number of components in colour context 01196 }; 01197 static UnitGroup *m_pUnitGroupArray[MAX_COMPONENTS]; // unit groups used by RGB components 01198 }; 01199 01200 01201 01202 01203 /******************************************************************************************** 01204 01205 > class ColourContextGreyT : public ColourContext 01206 01207 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 01208 Created: 02/06/94 01209 Purpose: Object class representing colour contexts based upon the GreyT 01210 colour model (Greyscale intensity, Transparent) 01211 SeeAlso: Colour; ColourModel; ColourContext; 01212 ColourContextGreyT::ColourContextGreyT 01213 Documentation: HowToUse\colours.doc 01214 01215 ********************************************************************************************/ 01216 01217 class CCAPI ColourContextGreyT : public ColourContext 01218 { 01219 friend class DocColour; // Give DocColour access to [Un]PackColour() etc 01220 friend class ColourContextList; // Give CCList access to Init etc functions 01221 01222 friend class GRenderRegion; 01223 friend class OSRenderRegion; 01224 01225 CC_DECLARE_MEMDUMP(ColourContextGreyT) 01226 01227 public: // Overridden Constructor 01228 ColourContextGreyT(View *Scope); 01229 01230 01231 public: // Overridden Interface 01232 void ConvertToCIET(ColourGeneric *Source, DColourCIET *Result); 01233 void ConvertFromCIET(DColourCIET *Source,ColourGeneric *Result); 01234 void CreateExternalTransform(); 01235 virtual void GetModelName(StringBase *Result); 01236 virtual BOOL GetComponentName(INT32 ComponentID, StringBase *Result, BOOL LongName = FALSE); 01237 virtual UINT32 GetComponentCount(); 01238 01239 virtual void ApplyTint(ColourValue TintFraction, ColourGeneric *SourceAndResult); 01240 virtual void ApplyShade(ColourValue XFraction, ColourValue YFraction, ColourGeneric *SourceAndResult); 01241 01242 virtual void GetWhite(ColourGeneric *Result); 01243 01244 protected: 01245 virtual UnitGroup **GetComponentUnitGroups(); 01246 01247 private: 01248 enum 01249 { 01250 MAX_COMPONENTS = 3 // Number of components in colour context 01251 }; 01252 static UnitGroup *m_pUnitGroupArray[MAX_COMPONENTS]; // unit groups used by RGB components 01253 }; 01254 01255 01256 #endif // INC_COLCONTX 01257 01258