ColourContextHSVT Class Reference

Object class representing colour contexts based upon the HSVT colour model (Red, Green, Blue, Transparent). More...

#include <colcontx.h>

Inheritance diagram for ColourContextHSVT:

ColourContext ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 ColourContextHSVT (View *Scope)
 Constructor for an HSVT Colour context.
void ConvertToCIET (ColourGeneric *Source, DColourCIET *Result)
 Converts the given colour from our HSVT colourspace to CIET colourspace Notes: -.
void ConvertFromCIET (DColourCIET *Source, ColourGeneric *Result)
 Converts the given colour to our HSVT colourspace from CIET colourspace Notes: -.
void CreateExternalTransform ()
 Create an external transform to be used during colour conversions from HSV to the current RCS space. This function uses the Winoil CMS Manager to create the transform. Both forward and backward transforms use a physical printer profile description.
virtual void GetModelName (StringBase *Result)
 Returns the name of this context's colour model Notes:.
virtual BOOL GetComponentName (INT32 ComponentID, StringBase *Result, BOOL LongName=FALSE)
 Returns the name of one of this context's colour components.
virtual UINT32 GetComponentCount ()
 Provides number of components in the colour context's colour model.
virtual void ApplyTint (ColourValue TintFraction, ColourGeneric *SourceAndResult)
 Tints a colour (mixes it with white).
virtual void ApplyShade (ColourValue XFraction, ColourValue YFraction, ColourGeneric *SourceAndResult)
 Shades a colour (tweaks the saturation and value in a relative way).
virtual void GetWhite (ColourGeneric *Result)
 An easy way to get a colour definition in this colour model which is white (paper colour).

Protected Member Functions

virtual void PackColour (ColourGeneric *Source, ColourPacked *Result)
 Converts 128-bit colour representation to 32-bit packed form.
virtual void UnpackColour (ColourPacked *Source, ColourGeneric *Result)
 Converts 32-bit packed colour representation to 128-bit form.
virtual UnitGroup ** GetComponentUnitGroups ()
 Provides an array of UnitGroups primarily for use by the base class (ColourContext) members Set/GetComponentUnitGroup().

Private Types

enum  { MAX_COMPONENTS = 3 }

Static Private Attributes

static UnitGroupm_pUnitGroupArray [MAX_COMPONENTS]

Friends

class DocColour
class ColourContextList
class GRenderRegion
class OSRenderRegion

Detailed Description

Object class representing colour contexts based upon the HSVT colour model (Red, Green, Blue, Transparent).

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/04/94
See also:
Colour; ColourModel; ColourContext; ColourContextHSVT::ColourContextHSVT Documentation: HowToUse.doc

Definition at line 1159 of file colcontx.h.


Member Enumeration Documentation

anonymous enum [private]
 

Enumerator:
MAX_COMPONENTS 

Definition at line 1193 of file colcontx.h.

01194     {
01195         MAX_COMPONENTS = 3                                  // Number of components in colour context
01196     };


Constructor & Destructor Documentation

ColourContextHSVT::ColourContextHSVT View Scope  ) 
 

Constructor for an HSVT Colour context.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/04/94
Parameters:
Scope - The view in which this context is to be used, or NULL [INPUTS]
- [OUTPUTS]
Returns:
-
Notes: Colour Contexts should not be created and used directly. See the notes in the SeeAlso's for instructions on proper care and use.

Returns:
Errors: -
See also:
ColourContext::ColourContext; ColourContextList::AddContext

Definition at line 3047 of file colcontx.cpp.

03048                   : ColourContext(Scope)
03049 {
03050     ColModel = COLOURMODEL_HSVT;
03051 
03052     CreateExternalTransform();
03053 }


Member Function Documentation

void ColourContextHSVT::ApplyShade ColourValue  XFraction,
ColourValue  YFraction,
ColourGeneric SourceAndResult
[virtual]
 

Shades a colour (tweaks the saturation and value in a relative way).

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/8/95
Parameters:
XFraction - The fraction (as a FIXED24 ColourValue) by which the colour [INPUTS] should be saturated. This value is expected to lie between -1.0 and 1.0 inclusive Values below 0.0 mean tint towards 0, while values above mean tint towards 1. 0.0 means no tinting
YFraction - The fraction (as a FIXED24 ColourValue) by which the colour should be shaded. This value is expected to lie between -1.0 and 1.0 inclusive Values below 0.0 mean shade towards 0, while values above mean shade towards 1. 0.0 means no shading

SourceAndResult - The source colour to be tinted, as defined in this colour model

Parameters:
SourceAndResult is shaded by the given Fractions [OUTPUTS] Any invalid value is clipped to 0.0
Returns:
-

Implements ColourContext.

Definition at line 3577 of file colcontx.cpp.

03579 {
03580     ColourHSVT *Result = (ColourHSVT *) SourceAndResult;
03581 
03582     ERROR3IF(XFraction < FIXED24(-1.0) || XFraction > FIXED24(1.0), "Illegal X Shading value");
03583     ERROR3IF(YFraction < FIXED24(-1.0) || YFraction > FIXED24(1.0), "Illegal Y Shading value");
03584 
03585     // Adjust the Saturation according to XFraction
03586     if (XFraction != FIXED24(0.0))
03587     {
03588         if (XFraction < FIXED24(0.0))
03589         {
03590             XFraction = -XFraction;
03591             Result->Saturation = Result->Saturation * (FIXED24(1.0) - XFraction);
03592         }
03593         else
03594             Result->Saturation = XFraction + Result->Saturation * (FIXED24(1.0) - XFraction);
03595     }
03596 
03597 
03598     // Adjust the Value according to YFraction
03599     if (YFraction != FIXED24(0.0))
03600     {
03601         if (YFraction < FIXED24(0.0))
03602         {
03603             YFraction = -YFraction;
03604             Result->Value = Result->Value * (FIXED24(1.0) - YFraction);
03605         }
03606         else
03607             Result->Value = YFraction + Result->Value * (FIXED24(1.0) - YFraction);
03608     }
03609 }

void ColourContextHSVT::ApplyTint ColourValue  TintFraction,
ColourGeneric SourceAndResult
[virtual]
 

Tints a colour (mixes it with white).

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/11/94
Parameters:
TintFraction - The fraction (as a FIXED24 ColourValue) by which the colour [INPUTS] should be tinted. This value is expected to lie between 0.0 and 1.0 inclusive
SourceAndResult - The source colour to be tinted, as defined in this colour model

Parameters:
SourceAndResult is tinted by the given TintFraction [OUTPUTS] If TintFraction <= 0.0, White is output If TintFraction >= 1.0, The source colour is output
Returns:
-
Notes: If the tinting value is out of range, either source-colour ow white (as appropriate) will be output.

Implements ColourContext.

Definition at line 3527 of file colcontx.cpp.

03528 {
03529     ColourHSVT *Result = (ColourHSVT *) SourceAndResult;
03530     
03531     if (TintFraction <= FIXED24(0.0))       // 0% tint = White
03532     {
03533         Result->Saturation = 0;
03534         Result->Value = FIXED24(1.0);
03535         return;
03536     }
03537 
03538     if (TintFraction >= FIXED24(1.0))       // The Result colour is identical to the source
03539         return;
03540 
03541     // Otherwise, tint the colour...
03542     // Hue remains constant
03543     Result->Saturation = Result->Saturation * TintFraction;
03544     Result->Value = FIXED24(1.0) - (TintFraction - (Result->Value * TintFraction));
03545 }

void ColourContextHSVT::ConvertFromCIET DColourCIET Source,
ColourGeneric Result
[virtual]
 

Converts the given colour to our HSVT colourspace from CIET colourspace Notes: -.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/04/94
Parameters:
Source - A Colour defined in the CIET colourspace [INPUTS] Result - pointer to a structure to recieve the resulting colour as defined in the HSVT space described by this colour context.
- [OUTPUTS]
Returns:
-

Errors: -

See also:
ColourContextHSVT::ConvertToCIET

Implements ColourContext.

Definition at line 3203 of file colcontx.cpp.

03204 {
03205     ENSURE(UsageCount > 0, "Colour context being used when not initialised!");
03206 
03207     // First, we'll convert from CIE to RGB
03208     double R, G, B;
03209 
03210 #ifndef NO_XARACMS
03211     // If we've got a CMS manager, use it, else use the version 1.1 bodge
03212     XaraCMS* lpCMSMan = GetApplication()->GetCMSManager();
03213 
03214     if (lpCMSMan != NULL)
03215     {
03216         // The new colour calibration method
03217         CMSColour icol, ocol;
03218         icol.c0 = Source->X;
03219         icol.c1 = Source->Y;
03220         icol.c2 = Source->Z;
03221 
03222         // If we have no colour transform, or if we don't want the colour corrected/separated,
03223         // then we will just do a "logical" conversion.
03224         if (CMSTransform == NULL || (ColPlate != NULL && ColPlate->IsDisabled()))
03225             lpCMSMan->ConvCIEXYZtoRGB(icol, ocol);
03226         else
03227             lpCMSMan->GTransform(CMSTransform, cmsReverse, icol, ocol);
03228 
03229         R = ocol.c0;
03230         G = ocol.c1;
03231         B = ocol.c2;
03232     }
03233     else
03234 #endif
03235     {
03236         // The old rgb system
03237         R = Source->X;
03238         G = Source->Y;
03239         B = Source->Z;
03240     }
03241 
03242 
03243     // Now, convert the RGB value into HSV
03244     double Min, Max, Delta, H, S, V;
03245     Min = min(R, G);
03246     Min = min(Min, B);
03247     Max = max(R, G);
03248     Max = max(Max, B);
03249 
03250     V = Max;
03251     Delta = Max - Min;
03252 
03253     if (fabs(Delta) > 0.000001)
03254     {
03255         if (Max > 0.0)
03256             S = Delta / Max;
03257         else
03258             S = 0.0;
03259 
03260         if (R == Max)
03261             H = (G - B) / Delta;
03262         else if (G == Max)
03263             H = 2.0 + (B - R) / Delta;
03264         else
03265             H = 4 + (R - G) / Delta;
03266 
03267 
03268         H = H / 6.0;
03269         if (H < 0.0) H += 1.0;
03270     }
03271     else
03272     {
03273         H = S = 0.0;
03274     }
03275 
03276     ((ColourHSVT *)Result)->Hue         = H;
03277     ((ColourHSVT *)Result)->Saturation  = S;
03278     ((ColourHSVT *)Result)->Value       = V;
03279     ((ColourHSVT *)Result)->Transparent = 0; //Source->Transparent;
03280 }

void ColourContextHSVT::ConvertToCIET ColourGeneric Source,
DColourCIET Result
[virtual]
 

Converts the given colour from our HSVT colourspace to CIET colourspace Notes: -.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/04/94
Parameters:
Source - A Colour defined in this HSVT context [INPUTS] Result - pointer to a structure to recieve the resulting colour as defined in CIE space
- [OUTPUTS]
Returns:
-

Errors: -

See also:
ColourContextHSVT::ConvertFromCIET

Implements ColourContext.

Definition at line 3109 of file colcontx.cpp.

03110 {
03111     ENSURE(UsageCount > 0, "Colour context being used when not initialised!");
03112 
03113     // First, let's convert the HSV into RGB
03114     FIXED24 H,S,V, R,G,B, F, P,Q,T;         // Sorry, I just have to override the style guide here!
03115 
03116     H = ((ColourHSVT *)Source)->Hue;
03117     S = ((ColourHSVT *)Source)->Saturation;
03118     V = ((ColourHSVT *)Source)->Value;
03119 
03120     if (S == FIXED24(0))
03121     {
03122         R = V;
03123         G = V;
03124         B = V;
03125     }
03126     else
03127     {
03128         H *= 6;
03129         INT32 I = H.MakeInt();
03130         F = H - I;
03131         P = V * (1.0 - S);
03132         Q = V * (1.0 - (S * F));
03133         T = V * (1.0 - (S * (1.0 - F)));
03134 
03135         switch (I)
03136         {
03137             case 1:  R = Q; G = V; B = P; break;
03138             case 2:  R = P; G = V; B = T; break;
03139             case 3:  R = P; G = Q; B = V; break;
03140             case 4:  R = T; G = P; B = V; break;
03141             case 5:  R = V; G = P; B = Q; break;
03142             default: R = V; G = T; B = P; break;
03143         }
03144     }
03145 
03146 #ifndef NO_XARACMS
03147     // Now, convert the RGB to CIE
03148     // If we've got a CMS manager, use it, else use the version 1.1 bodge
03149     XaraCMS* lpCMSMan = GetApplication()->GetCMSManager();
03150 
03151     if (lpCMSMan != NULL)
03152     {
03153         // The new colour calibration method
03154         CMSColour icol, ocol;
03155         icol.c0 = R.MakeDouble();
03156         icol.c1 = G.MakeDouble();
03157         icol.c2 = B.MakeDouble();
03158         
03159         // If we have no colour transform, or if we don't want the colour corrected/separated,
03160         // then we will just do a "logical" conversion.
03161         if (CMSTransform == NULL || (ColPlate != NULL && ColPlate->IsDisabled()))
03162             lpCMSMan->ConvRGBtoCIEXYZ(icol, ocol);
03163         else
03164             lpCMSMan->GTransform(CMSTransform, cmsForward, icol, ocol);
03165         
03166         Result->X = ocol.c0;
03167         Result->Y = ocol.c1;
03168         Result->Z = ocol.c2;
03169         Result->Transparent = 0.0;//bob->Transparent;
03170     }
03171     else
03172 #endif
03173     {
03174         // The old rgb system
03175         Result->X = R.MakeDouble();
03176         Result->Y = G.MakeDouble();
03177         Result->Z = B.MakeDouble();
03178         Result->Transparent = 0;//((ColourHSVT *)Source)->Transparent;
03179     }
03180 }

void ColourContextHSVT::CreateExternalTransform  )  [virtual]
 

Create an external transform to be used during colour conversions from HSV to the current RCS space. This function uses the Winoil CMS Manager to create the transform. Both forward and backward transforms use a physical printer profile description.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/05/96
Parameters:
- [INPUTS]
Returns:
-

Reimplemented from ColourContext.

Definition at line 3070 of file colcontx.cpp.

03071 {
03072 #ifndef NO_XARACMS
03073     CMSColourSpace cmsSpace;
03074     XaraCMS* lpCMSMan = GetApplication()->GetCMSManager();
03075     
03076     if (lpCMSMan != NULL)
03077     {
03078         // first read our internal colour calibration space
03079         lpCMSMan->GetLogicalProfile(&cmsSpace);
03080         // set this as the active colour profile
03081         UINT32 err = lpCMSMan->SetProfile(cmsSpace);
03082         // if we haven't got an error, create that transform
03083         if (err==0)
03084             CMSTransform = lpCMSMan->CreateTransform(DISPLAY_RCS);
03085     }
03086 #endif
03087 }

UINT32 ColourContextHSVT::GetComponentCount  )  [virtual]
 

Provides number of components in the colour context's colour model.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96
Returns:
The number of components

Implements ColourContext.

Definition at line 3495 of file colcontx.cpp.

03496 {
03497     return MAX_COMPONENTS;
03498 }

BOOL ColourContextHSVT::GetComponentName INT32  ComponentID,
StringBase Result,
BOOL  LongName = FALSE
[virtual]
 

Returns the name of one of this context's colour components.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/7/94
Parameters:
ComponentID - Index [1..4] of the component you want the name of [INPUTS] (Result is an output) LongName - TRUE to get the long name, FALSE to get the short name (e.g. "Magenta" vs "M", "Saturation" vs "Sat")
Result returns containing a String of the name of the given component [OUTPUTS] of colours defined in this context. This string is guaranteed to fit within a String_32 - this is the minimum size you should allocate. (Most names, in English at least, are shorter than this (10 chars max, e.g. 'Red' 'Hue' 'Saturation') so allow at least 10 chars of space in your displays as well)
Note that Result can be passed in NULL in order to only determine if the context supports a given component.

Returns:
FALSE if this component is not used by this model.
Notes: The components are given in the same order as they appear in the high-precision ColourXYZ structures defined in colmodel.h

Implements ColourContext.

Definition at line 3414 of file colcontx.cpp.

03415 {
03416     UINT32 StringID = 0;
03417     BOOL Used = TRUE;
03418 
03419     switch(ComponentID)
03420     {
03421         case 1:
03422             StringID = (LongName) ? _R(IDS_COLCOMPL_HUE) : _R(IDS_COLCOMP_HUE);
03423             break;
03424             
03425         case 2:
03426             StringID = (LongName) ? _R(IDS_COLCOMPL_SATURATION) : _R(IDS_COLCOMP_SATURATION);
03427             break;
03428 
03429         case 3:
03430             StringID = (LongName) ? _R(IDS_COLCOMPL_VALUE) : _R(IDS_COLCOMP_VALUE);
03431             break;
03432 
03433 #ifdef TRANSPARENTCOLOUR
03434         default:
03435             StringID = _R(IDS_COLCOMP_TRANS);
03436             break;
03437 #else
03438         default:
03439             Used = FALSE;
03440             break;
03441 #endif
03442     }
03443 
03444     if (Result != NULL && StringID != 0)
03445         *Result = String_32(StringID);
03446 
03447     return(Used);
03448 }

UnitGroup ** ColourContextHSVT::GetComponentUnitGroups  )  [protected, virtual]
 

Provides an array of UnitGroups primarily for use by the base class (ColourContext) members Set/GetComponentUnitGroup().

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
A pointer to the UnitGroup array

Errors: - See Also: ColourContext::GetComponentUnitGroup() ColourContext::SetComponentUnitGroup()

Implements ColourContext.

Definition at line 3469 of file colcontx.cpp.

03470 {
03471     return m_pUnitGroupArray;
03472 }

void ColourContextHSVT::GetModelName StringBase Result  )  [virtual]
 

Returns the name of this context's colour model Notes:.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/6/94
Parameters:
- [INPUTS]
Result returns continaing a String of the name of the context. [OUTPUTS] This string is guaranteed to fit within a String_32 - this is the minimum size you should allocate. (Most names, in English at least, are shorter than this (10 chars max, e.g. 'RGB' 'HSV' 'Greyscale') so allow at least 10 chars of space in your displays as well)
Returns:
-

Implements ColourContext.

Definition at line 3375 of file colcontx.cpp.

03376 {
03377     ENSURE(Result != NULL, "ColourContext::GetModelName called with NULL result pointer!");
03378 
03379     *Result = String_32(_R(IDS_COLMODEL_HSVT));
03380 }

void ColourContextHSVT::GetWhite ColourGeneric Result  )  [virtual]
 

An easy way to get a colour definition in this colour model which is white (paper colour).

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/6/96
Parameters:
Result - Will be filled in with White, however that is defined in [OUTPUTS] this context's colour model. (i.e. RGB(1,1,1) or CMYK(0,0,0,0), etc)

Implements ColourContext.

Definition at line 3628 of file colcontx.cpp.

03629 {
03630     ColourHSVT *hsvt = (ColourHSVT *) Result;
03631     hsvt->Hue = hsvt->Saturation = 0;
03632     hsvt->Value = 1.0;
03633     hsvt->Transparent = 0;
03634 }

void ColourContextHSVT::PackColour ColourGeneric Source,
ColourPacked Result
[protected, virtual]
 

Converts 128-bit colour representation to 32-bit packed form.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/04/94
Parameters:
Source - A ColourHSVT structure defining the colour in the model [INPUTS] pertaining to this colour context (HSVT) Result - A Packed colour structure in the same model, into which the result is copied.
- [OUTPUTS]
Returns:
-
Overrides the base class to provide special packing of HSV colours, which use a 9-bit component for packed Hue, and a different component ordering within the PColourHSVT structure.

Scope: Private (used internally by friend class DocColour)

Returns:
Errors: -
See also:
ColourContextHSVT::UnpackColour

Reimplemented from ColourContext.

Definition at line 3309 of file colcontx.cpp.

03310 {
03311     PColourHSVT *bob = (PColourHSVT *) Result;
03312 
03313     bob->Hue            = PackColour360(Source->Component1);
03314     bob->Saturation     = PackColour256(Source->Component2);
03315     bob->Value          = PackColour256(Source->Component3);
03316     bob->Transparent    = 0; //PackColour128(Source->Transparent);
03317 }

void ColourContextHSVT::UnpackColour ColourPacked Source,
ColourGeneric Result
[protected, virtual]
 

Converts 32-bit packed colour representation to 128-bit form.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/04/94
Parameters:
Source - A Packed Colour structure defining the colour in the model [INPUTS] pertaining to this colour context (HSVT) Result - A ColourGeneric structure in the same model, into which the result is copied.
- [OUTPUTS]
Returns:
-
Overrides the base class to provide special packing of HSV colours, which use a 9-bit component for packed Hue, and a different component ordering within the PColourHSVT structure.

Scope: Private (used internally by friend class DocColour)

Returns:
Errors: -
See also:
ColourContextHSVT::PackColour

Reimplemented from ColourContext.

Definition at line 3345 of file colcontx.cpp.

03346 {
03347     PColourHSVT *bob = (PColourHSVT *) Source;
03348 
03349     UnpackColour360(bob->Hue,        &Result->Component1);
03350     UnpackColour256(bob->Saturation, &Result->Component2);
03351     UnpackColour256(bob->Value,      &Result->Component3);
03352     Result->Component4 = 0;//UnpackColour128(bob->Transparent, &Result->Transparent);
03353 }


Friends And Related Function Documentation

friend class ColourContextList [friend]
 

Reimplemented from ColourContext.

Definition at line 1162 of file colcontx.h.

friend class DocColour [friend]
 

Reimplemented from ColourContext.

Definition at line 1161 of file colcontx.h.

friend class GRenderRegion [friend]
 

Reimplemented from ColourContext.

Definition at line 1164 of file colcontx.h.

friend class OSRenderRegion [friend]
 

Reimplemented from ColourContext.

Definition at line 1165 of file colcontx.h.


Member Data Documentation

UnitGroup * ColourContextHSVT::m_pUnitGroupArray [static, private]
 

Initial value:

Definition at line 1197 of file colcontx.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:52:48 2007 for Camelot by  doxygen 1.4.4