GradTable Class Reference

A kernel representation of a graduation table. (This is a table of 8-bpp dither pattern specifiers for GDraw). More...

#include <gradtbl.h>

Inheritance diagram for GradTable:

CCObject SimpleCCObject List of all members.

Public Member Functions

 GradTable (BOOL LargeTable=FALSE)
 Default constructor for a GradTable.
 ~GradTable ()
 Destructor for a GradTable.
void SetTableSize (BOOL LargeTable)
 To set the size of this Grad table.
INT32 GetTableLength (void)
BOOL BuildTable (DocColour &StartCol, DocColour &EndCol, View *ContextView, EFFECTTYPE Effect, BOOL LargeTable=FALSE)
 Builds a GradTable from StartCol to EndCol, filling in the entire table with appropriate GDraw dither patterns.
BOOL BuildTable (DocColour &StartCol, DocColour &EndCol, View *ContextView, EFFECTTYPE Effect, CProfileBiasGain &BiasGain, BOOL LargeTable=FALSE)
 Generates a graduated fill table that is modified by biasgain values.
BOOL BuildTable (DocColour &StartCol, DocColour &EndCol, ColourRamp *pColourRamp, View *ContextView, EFFECTTYPE Effect, BOOL LargeTable=FALSE)
 Writes a colour ramp fill record to the filter.
BOOL BuildHighQualityRepeatTable (DocColour &StartCol, DocColour &EndCol, ColourRamp *pColourRamp, View *ContextView, EFFECTTYPE Effect)
 Generates a high quality repeating graduated fill table. Handles both those with fill ramps and those without.
BOOL BuildHighQualityRepeatTable (DocColour &StartCol, DocColour &EndCol, View *ContextView, EFFECTTYPE Effect, CProfileBiasGain &BiasGain)
 Generates a high quality repeating graduated fill table for the supplied profile.
BOOL BuildTable (DocColour &StartCol, DocColour &EndCol, View *ContextView, EFFECTTYPE Effect, DWORD FirstEntry, DWORD LastEntry)
 Builds a GradTable from StartCol to EndCol, filling in a portion of the table with appropriate GDraw dither patterns.
BOOL AddToTable (DocColour &NewCol, View *ContextView, DWORD Index)
 Adds a colour to a GradTable, at the specified index This is used for multi-stage fills.
GraduationTableGetTable (void)
BOOL IsLarge (void)

Protected Member Functions

void FillTable (DWORD StartIndex, DWORD EndIndex, PColourRGBT *StartDef, PColourRGBT *EndDef)
 Builds a GradTable from StartIndex to EndIndex by linearly interpolating between the StartDef and EndDef RGB colours.
INT32 GetTableSize (GDrawContext *GD, BOOL LargeTable)
INT32 GetTableLength (GDrawContext *GD, BOOL LargeTable)

Private Attributes

BOOL m_bLargeTable
GraduationTablem_pTable

Detailed Description

A kernel representation of a graduation table. (This is a table of 8-bpp dither pattern specifiers for GDraw).

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/9/94
See also:
GradTable32
Notes: There are now 3 base functions in GradTable and GradTable32 which build graduation tables. The tables are actually identical in meaning, but are encoded as: (a) Gavin 8bpp dither patterns, (b) RGBQUAD RGB structures, (c) COLORREF RGB values this is because the different places that use these tables demand the different formats, and converting all the code to use only one table format is non-trivial and/or inefficient.

Definition at line 138 of file gradtbl.h.


Constructor & Destructor Documentation

GradTable::GradTable BOOL  LargeTable = FALSE  ) 
 

Default constructor for a GradTable.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/9/94
Notes: Sets the default table size to 0x100 entries long

See also:
GradTable::SetTableSize

Definition at line 167 of file gradtbl.cpp.

00168 {
00169     m_bLargeTable = LargeTable;
00170     m_pTable = NULL;
00171 }

GradTable::~GradTable  ) 
 

Destructor for a GradTable.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
16/10/96

Definition at line 185 of file gradtbl.cpp.

00186 {
00187     if (m_pTable != NULL)
00188     {
00189         CCFree(m_pTable);
00190         m_pTable = NULL;
00191     }
00192 }


Member Function Documentation

BOOL GradTable::AddToTable DocColour NewCol,
View ContextView,
DWORD  Index
 

Adds a colour to a GradTable, at the specified index This is used for multi-stage fills.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/9/94
Parameters:
NewCol - The colour to place into the GradTable [INPUTS] ContextView - Points to the view in which the gradation is to be displayed. (This is necessary for correction and separation etc. If proper colour handling is not needed, then you may pass NULL, but generally, this parameter should be sensible)
Index - The index of the table entry to overwrite

Returns:
Errors: -

Definition at line 996 of file gradtbl.cpp.

00997 {
00998     ColourContextRGBT *cc = (ColourContextRGBT *)
00999                             ColourManager::GetColourContext(COLOURMODEL_RGBT, ContextView);
01000 
01001     ERROR3IF(cc == NULL, "Unable to find an RGB colour context for the view");
01002     ERROR3IF(Index >= m_pTable->Length, "Illegal table index");
01003 
01004     PColourRGBT Result;
01005     cc->ConvertColour(&NewCol, (ColourPacked *) &Result);
01006 
01007     COLORREF Col = RGB(Result.Red, Result.Green, Result.Blue);
01008 
01009     // Get GDraw to fill in the table entry for us. FALSE => RGB colour
01010     return(GRenderRegion::GetStaticDrawContext()->AddToGraduationTable(Col, FALSE, m_pTable, Index));
01011 }

BOOL GradTable::BuildHighQualityRepeatTable DocColour StartCol,
DocColour EndCol,
View ContextView,
EFFECTTYPE  Effect,
CProfileBiasGain BiasGain
 

Generates a high quality repeating graduated fill table for the supplied profile.

Author:
Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
Date:
4/2/2000
Parameters:
StartCol,EndCol - Define the end colours of the graduation [INPUTS] pColourRamp - Define the colours and positions of a colour ramp ContextView - Points to the view in which the gradation is to be displayed. (This is necessary for correction and separation etc. If proper colour handling is not needed, then you may pass NULL, but generally, this parameter should be sensible)
Effect - EFFECT_FADE, EFFECT_HSV_SHORT, or EFFECT_HSV_LONG

BiasGain - the profile to build for

Returns:
TRUE, error thrown otherwise (but only for input variables)
See also:
-

Definition at line 819 of file gradtbl.cpp.

00822 {
00823     // Find a GDraw context to generate dithertable entries for us
00824     GDrawContext *GD = GRenderRegion::GetStaticDrawContext();
00825     ERROR3IF(GD == NULL, "GradTable::BuildHighQualityRepeatTable - No GDraw context?!");
00826 
00827     // Determine if either the start or end colour is a spot colour - if it is, we must
00828     // coerce the fill into a "mix" (rgb) rather than rainbow fill style
00829     if (Effect != EFFECT_RGB && (StartCol.GetSpotParent() != NULL || EndCol.GetSpotParent() != NULL))
00830         Effect = EFFECT_RGB;
00831 
00832     // Get colour contexts: we need 2 - first, an RGB context for the ContextView, which
00833     // will be used to get colour-corrected/separated/etc output colour in RGB; and second,
00834     // a generic RGB or HSV context to provide a "mixing colourspace" for the graduations.
00835     ColourContext *cc = NULL;
00836     ColourContext *ccRGB = ColourManager::GetColourContext(COLOURMODEL_RGBT, ContextView);
00837 
00838     if (Effect == EFFECT_RGB)
00839         cc = ColourManager::GetColourContext(COLOURMODEL_RGBT);     // RGB fade
00840     else
00841         cc = ColourManager::GetColourContext(COLOURMODEL_HSVT);     // HSV fade
00842 
00843     // If we can't find RGB/HSV contexts, something is seriously broken
00844     ERROR3IF(cc == NULL || ccRGB == NULL,
00845             "GradTable::BuildHighQualityRepeatTable - Can't find my colour context!");
00846 
00847     // Fill in the Start and End colours of the table, if we've hit them
00848     PColourRGBT Result;
00849 
00850     // set our table size for this grad
00851     SetTableSize(TRUE);
00852 
00853     ccRGB->ConvertColour(&StartCol, (ColourPacked *) &Result);
00854     m_pTable->StartColour = RGB(Result.Red, Result.Green, Result.Blue);
00855 
00856     ccRGB->ConvertColour(&EndCol, (ColourPacked *) &Result);
00857     m_pTable->EndColour = RGB(Result.Red, Result.Green, Result.Blue);
00858 
00859     const INT32 TableLength = m_pTable->Length;
00860     INT32 halfTableLength = TableLength/2;
00861     double MixFraction;
00862 
00863     BiasGain.SetIntervals (AFp (0), AFp (m_pTable->Length/2));
00864     
00865     DocColour temp;
00866     INT32 r, g, b;
00867     double res;
00868 
00869     BOOL secondHalf = FALSE;
00870     INT32 secondHalfVal =0;
00871 
00872     // NOTE:  this loop could be optimised to avoid calculating the same colour value twice
00873 
00874     for (INT32 col = 0; col < TableLength; col++)
00875     {   
00876         if (!secondHalf)
00877         {
00878             res = BiasGain.MapInterval( AFp( col) );
00879         }
00880         else
00881         {
00882             res = BiasGain.MapInterval( AFp( secondHalfVal) );
00883         }
00884         
00885         MixFraction = res / halfTableLength;
00886         
00887         // Create a new colour which is an appropriate mixture of the start/end colours
00888         temp.Mix(&StartCol, &EndCol, MixFraction, cc, (Effect == EFFECT_HSV_LONG), ccRGB);
00889         temp.GetRGBValue (&r, &g, &b);
00890 
00891         // Get GDraw to fill in the dither entry for us (FALSE means it's an RGB colour)
00892         GD->AddToGraduationTable(RGB(r, g, b), FALSE, m_pTable, col);
00893 
00894         if (!(col < halfTableLength))
00895         {
00896             secondHalfVal = TableLength - col;
00897             secondHalf = TRUE;
00898         }
00899     }
00900     
00901     return (TRUE);
00902 }

BOOL GradTable::BuildHighQualityRepeatTable DocColour StartCol,
DocColour EndCol,
ColourRamp pColourRamp,
View ContextView,
EFFECTTYPE  Effect
 

Generates a high quality repeating graduated fill table. Handles both those with fill ramps and those without.

Author:
Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
Date:
4/2/2000
Parameters:
StartCol,EndCol - Define the end colours of the graduation [INPUTS] pColourRamp - Define the colours and positions of a colour ramp ContextView - Points to the view in which the gradation is to be displayed. (This is necessary for correction and separation etc. If proper colour handling is not needed, then you may pass NULL, but generally, this parameter should be sensible)
Effect - EFFECT_FADE, EFFECT_HSV_SHORT, or EFFECT_HSV_LONG

Returns:
TRUE, error thrown otherwise (but only for input variables)
See also:
-

Definition at line 694 of file gradtbl.cpp.

00696 {
00697     if (!pColourRamp)
00698     {
00699         // Find a GDraw context to generate dithertable entries for us
00700         GDrawContext *GD = GRenderRegion::GetStaticDrawContext();
00701         ERROR3IF(GD == NULL, "GradTable::BuildHighQualityRepeatTable - No GDraw context?!");
00702 
00703         // Determine if either the start or end colour is a spot colour - if it is, we must
00704         // coerce the fill into a "mix" (rgb) rather than rainbow fill style
00705         if (Effect != EFFECT_RGB && (StartCol.GetSpotParent() != NULL || EndCol.GetSpotParent() != NULL))
00706             Effect = EFFECT_RGB;
00707 
00708         // Get colour contexts: we need 2 - first, an RGB context for the ContextView, which
00709         // will be used to get colour-corrected/separated/etc output colour in RGB; and second,
00710         // a generic RGB or HSV context to provide a "mixing colourspace" for the graduations.
00711         ColourContext *cc = NULL;
00712         ColourContext *ccRGB = ColourManager::GetColourContext(COLOURMODEL_RGBT, ContextView);
00713 
00714         if (Effect == EFFECT_RGB)
00715             cc = ColourManager::GetColourContext(COLOURMODEL_RGBT);     // RGB fade
00716         else
00717             cc = ColourManager::GetColourContext(COLOURMODEL_HSVT);     // HSV fade
00718 
00719         // If we can't find RGB/HSV contexts, something is seriously broken
00720         ERROR3IF(cc == NULL || ccRGB == NULL,
00721                 "GradTable::BuildHighQualityRepeatTable - Can't find my colour context!");
00722 
00723         // Fill in the Start and End colours of the table, if we've hit them
00724         PColourRGBT Result;
00725 
00726         // set our table size for this grad
00727         SetTableSize(TRUE);
00728 
00729         ccRGB->ConvertColour(&StartCol, (ColourPacked *) &Result);
00730         ccRGB->ConvertColour(&  EndCol, (ColourPacked *) &Result);
00731         m_pTable->StartColour = RGB(Result.Red, Result.Green, Result.Blue);
00732         m_pTable->EndColour   = RGB(Result.Red, Result.Green, Result.Blue);
00733 
00734         const INT32 TableLength = m_pTable->Length;
00735         double MixFraction = 0.0;
00736         double MixStep = 0;
00737                 
00738         if (TableLength != 0)
00739             MixStep = 2.0 / TableLength;
00740 
00741         DocColour temp;
00742         INT32 r, g, b;
00743 
00744         // NOTE:  this loop could be optimised to avoid calculating the same colour value twice
00745 
00746         for (INT32 col = 0 ; (col<<1)<TableLength ; col++)
00747         {   
00748             // Create a new colour which is an appropriate mixture of the start/end colours
00749             temp.Mix(&StartCol, &EndCol, MixFraction, cc, (Effect == EFFECT_HSV_LONG), ccRGB);
00750             temp.GetRGBValue (&r, &g, &b);
00751 
00752             // Get GDraw to fill in the dither entry for us (FALSE means it's an RGB colour)
00753             GD->AddToGraduationTable(RGB(r, g, b), FALSE, m_pTable, col);
00754             GD->AddToGraduationTable(RGB(r, g, b), FALSE, m_pTable, TableLength-col-1);
00755 
00756             MixFraction += MixStep;
00757         }
00758     }
00759     else
00760     {
00761         // set our table size for this grad
00762         SetTableSize(TRUE);
00763         
00764         ColRampItem *pCTI = pColourRamp->GetFirstCol();
00765         if (pCTI!=NULL)
00766         {
00767             DocColour *pFirstCol=&StartCol, *pSecondCol;
00768             
00769             DWORD fi=0 , si=0;
00770             
00771             while (pCTI)
00772             {
00773                 // whip out the colour definition
00774                 pSecondCol = pCTI->GetColourAddr();
00775                 // calculate the index for the next colour
00776                 si = (DWORD)((pCTI->GetPosition() * m_pTable->Length)+0.5);
00777                 // build this section of the table
00778                 if (!BuildTable(*pFirstCol, *pSecondCol, ContextView, Effect, fi, si))
00779                     return FALSE;
00780                 // now skip round to the next               
00781                 pFirstCol = pSecondCol;
00782                 fi = si;
00783                 pCTI = pColourRamp->GetNextCol(pCTI);
00784             }
00785 
00786             // do the final section
00787             return BuildTable(*pSecondCol, StartCol, ContextView, Effect, si, m_pTable->Length);
00788         }               
00789     }
00790     
00791     return (TRUE);
00792 }

BOOL GradTable::BuildTable DocColour StartCol,
DocColour EndCol,
View ContextView,
EFFECTTYPE  Effect,
DWORD  FirstEntry,
DWORD  LastEntry
 

Builds a GradTable from StartCol to EndCol, filling in a portion of the table with appropriate GDraw dither patterns.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> (Will)
Date:
14/5/96 (14/9/94)
Parameters:
StartCol,EndCol - Define the end colours of the graduation [INPUTS] ContextView - Points to the view in which the gradation is to be displayed. (This is necessary for correction and separation etc. If proper colour handling is not needed, then you may pass NULL, but generally, this parameter should be sensible)
Effect - EFFECT_FADE, EFFECT_HSV_SHORT, or EFFECT_HSV_LONG

FirstEntry - The index of the first entry (inclusive) to fill in (0 is the first) LastEntry - The index of the last entry (exclusive) to fill in (TableSize is the last) (i.e. to fill entire table use (0,TableSize) which will fill in entries 0..Tablesize-1)

Returns:
FALSE if it fails
Notes: GDraw requires the Start and End colours for the entire table to be set separately in the table structure. These will be set if FirstEntry==0 and/or if LastEntry==TableSize, respectively.

No longer calls GDraw to build the table. The colours are generated by us (mainly so that we can support proper colour correction and separation by allowing the colour system to do its stuff)

This method could be somewhat more optimal than it is, if we start poking around more in the internals of the colour system. For the time being, I'm leaving it tidy, however.

Returns:
Errors: ERROR2's if it runs out of memory
See also:
GradTable::SetTableSize

Definition at line 437 of file gradtbl.cpp.

00440 {
00441     // The range should be within the table size. We only ERROR3, though, because
00442     // the physical table is always large enough for the maximum number of entries.
00443 
00444     ERROR3IF(FirstEntry < 0 || FirstEntry > LastEntry || LastEntry > m_pTable->Length,
00445                 "GradTable::BuildTable expects sensible First/Last Entry values");
00446 
00447     // Find a GDraw context to generate dithertable entries for us
00448     GDrawContext *GD = GRenderRegion::GetStaticDrawContext();
00449     ERROR3IF(GD == NULL, "GradTable::BuildTable - No GDraw context?!");
00450 
00451     // Determine if either the start or end colour is a spot colour - if it is, we must
00452     // coerce the fill into a "mix" (rgb) rather than rainbow fill style
00453     if (Effect != EFFECT_RGB && (StartCol.GetSpotParent() != NULL || EndCol.GetSpotParent() != NULL))
00454         Effect = EFFECT_RGB;
00455 
00456     // Get colour contexts: we need 2 - first, an RGB context for the ContextView, which
00457     // will be used to get colour-corrected/separated/etc output colour in RGB; and second,
00458     // a generic RGB or HSV context to provide a "mixing colourspace" for the graduations.
00459     ColourContext *cc = NULL;
00460     ColourContext *ccRGB = ColourManager::GetColourContext(COLOURMODEL_RGBT, ContextView);
00461 
00462     if (Effect == EFFECT_RGB)
00463         cc = ColourManager::GetColourContext(COLOURMODEL_RGBT);     // RGB fade
00464     else
00465         cc = ColourManager::GetColourContext(COLOURMODEL_HSVT);     // HSV fade
00466 
00467     // If we can't find RGB/HSV contexts, something is seriously broken
00468     ERROR3IF(cc == NULL || ccRGB == NULL,
00469             "GradTable::BuildTable - Can't find my colour context!");
00470 
00471     // Fill in the Start and End colours of the table, if we've hit them
00472     PColourRGBT Result;
00473 
00474     if (FirstEntry == 0)
00475     {
00476         ccRGB->ConvertColour(&StartCol, (ColourPacked *) &Result);
00477         m_pTable->StartColour = RGB(Result.Red, Result.Green, Result.Blue);
00478     }
00479 
00480     if (LastEntry >= m_pTable->Length)
00481     {
00482         LastEntry = m_pTable->Length;
00483         ccRGB->ConvertColour(&EndCol, (ColourPacked *) &Result);
00484         m_pTable->EndColour = RGB(Result.Red, Result.Green, Result.Blue);
00485     }
00486 
00487     const BOOL ValidColourPlate = (ccRGB->GetColourPlate() != NULL && !ccRGB->GetColourPlate()->IsDisabled());
00488 
00489     if (ValidColourPlate || 
00490         FirstEntry > 0 || 
00491         LastEntry < m_pTable->Length)
00492     {
00493         if (ValidColourPlate && ccRGB->GetColourPlate()->GetType() == COLOURPLATE_COMPOSITE)
00494         {
00495             // We're doing a composite print preview.
00496             PColourRGBT StartDef;
00497             PColourRGBT EndDef;
00498             ccRGB->ConvertColour(&StartCol, (ColourPacked *) &EndDef);
00499 
00500             DWORD StartIndex = FirstEntry;
00501             DWORD EndIndex;
00502 
00503             DocColour TempCol;
00504 
00505             while (StartIndex < LastEntry)
00506             {
00507                 // Move the last run's end colour into Start
00508                 memcpy(&StartDef, &EndDef, sizeof(PColourRGBT));
00509 
00510                 // Calculate the end of this run
00511                 EndIndex = StartIndex + FillStep;
00512                 if (EndIndex > LastEntry)
00513                     EndIndex = LastEntry;
00514     
00515                 // Calculate the colour at the end of this run, and convert into EndDef
00516                 TempCol.Mix(&StartCol, &EndCol,
00517                             ((double)(EndIndex - FirstEntry)) / ((double)(LastEntry - FirstEntry)),
00518                             cc, (Effect == EFFECT_HSV_LONG), ccRGB);
00519 
00520                 ccRGB->ConvertColour(&TempCol, (ColourPacked *) &EndDef);
00521 
00522                 // Linearly interpolate all colours in the run
00523                 FillTable(StartIndex, EndIndex, &StartDef, &EndDef);
00524 
00525                 // And step on to the next run
00526                 StartIndex = EndIndex;
00527             }
00528         }
00529         else
00530         {
00531             // We have some type of colour separation on the go - we must convert all intermediate
00532             // colours through the colour system in order to ensure the results are correct.
00533             // This is quite slow, but acceptable (ish) when printing.
00534             double MixFraction  = 0.0;
00535             // This next line requires the -1 because otherwise it doesn't reach the end colour
00536             // This is ok if LastEntry = StartEntry + 1 as MixStep will be calculated as zero
00537             // and the StartCol will be used to fill in the single entry required
00538             double denumerator = (double) (LastEntry - FirstEntry - 1);
00539             double MixStep = 0;
00540             if (denumerator != 0)
00541             {
00542                 MixStep = 1.0 / denumerator;
00543             }
00544 
00545             DocColour temp;
00546             for (DWORD col = FirstEntry; col < LastEntry; col++)
00547             {
00548                 // Create a new colour which is an appropriate mixture of the start/end colours
00549                 temp.Mix(&StartCol, &EndCol, MixFraction, cc, (Effect == EFFECT_HSV_LONG), ccRGB);
00550 
00551                 // Convert back to the raw RGB and place it in the palette.
00552                 // Note that this will colour correct and separate in an appropriate manner.
00553                 // Note also that we're using a special ConvertColour call which returns 8-bit 
00554                 // "packed" component values instead of FIXED24's.
00555                 ccRGB->ConvertColour(&temp, (ColourPacked *) &Result);
00556 
00557                 // Get GDraw to fill in the dither entry for us (FALSE means it's an RGB colour)
00558                 GD->AddToGraduationTable(RGB(Result.Red, Result.Green, Result.Blue), FALSE, m_pTable, col);
00559 
00560                 // And step to the next mix fraction value
00561                 MixFraction += MixStep;
00562             }
00563         }
00564     }
00565     else
00566     {
00567         // We're doing a completely normal view, and building the entire 256-entry table, so
00568         // call GDraw to blindly interpolate between the colours, which is much (much) faster.
00569         GD->BuildGraduationTable(m_pTable->StartColour, m_pTable->EndColour, Effect, m_pTable);
00570     } 
00571 
00572     return(TRUE);
00573 }

BOOL GradTable::BuildTable DocColour StartCol,
DocColour EndCol,
ColourRamp pColRamp,
View ContextView,
EFFECTTYPE  Effect,
BOOL  LargeTable = FALSE
 

Writes a colour ramp fill record to the filter.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/2/97
Parameters:
StartCol,EndCol - Define the end colours of the graduation [INPUTS] pColList - Define the colours and positions of a colour ramp ContextView - Points to the view in which the gradation is to be displayed. (This is necessary for correction and separation etc. If proper colour handling is not needed, then you may pass NULL, but generally, this parameter should be sensible)
Effect - EFFECT_FADE, EFFECT_HSV_SHORT, or EFFECT_HSV_LONG

TableSize - The number of entries you wish to make the table (0x100 or 0x800)

Returns:
TRUE if record is written, FALSE if not
See also:
-

Definition at line 931 of file gradtbl.cpp.

00934 {
00935     // set our table size for this grad
00936     SetTableSize(LargeTable);
00937     
00938     // if we've been passed a colour table, lets use it
00939     if (pColRamp!=NULL)
00940     {
00941         ColRampItem *pCTI = pColRamp->GetFirstCol();
00942         if (pCTI!=NULL)
00943         {
00944             DocColour *pFirstCol=&StartCol, *pSecondCol;
00945             
00946             DWORD fi=0 , si=0;
00947             
00948             while (pCTI)
00949             {
00950                 // whip out the colour definition
00951                 pSecondCol = pCTI->GetColourAddr();
00952                 // calculate the index for the next colour
00953                 si = (DWORD)((pCTI->GetPosition() * m_pTable->Length)+0.5);
00954                 // build this section of the table
00955                 if (!BuildTable(*pFirstCol, *pSecondCol, ContextView, Effect, fi, si))
00956                     return FALSE;
00957                 // now skip round to the next               
00958                 pFirstCol = pSecondCol;
00959                 fi = si;
00960                 pCTI = pColRamp->GetNextCol(pCTI);
00961             }
00962 
00963             // do the final section
00964             return BuildTable(*pSecondCol, EndCol, ContextView, Effect, si, m_pTable->Length);
00965         }               
00966     }
00967 
00968     // otherwise do the normal double end linear fill.
00969     return (BuildTable(StartCol, EndCol, ContextView, Effect, 0, m_pTable->Length));
00970 }

BOOL GradTable::BuildTable DocColour StartCol,
DocColour EndCol,
View ContextView,
EFFECTTYPE  Effect,
CProfileBiasGain BiasGain,
BOOL  LargeTable = FALSE
 

Generates a graduated fill table that is modified by biasgain values.

Author:
Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
Date:
4/2/2000
Parameters:
StartCol,EndCol - Define the end colours of the graduation [INPUTS] pColList - Define the colours and positions of a colour ramp ContextView - Points to the view in which the gradation is to be displayed. (This is necessary for correction and separation etc. If proper colour handling is not needed, then you may pass NULL, but generally, this parameter should be sensible)
Effect - EFFECT_FADE, EFFECT_HSV_SHORT, or EFFECT_HSV_LONG

BiasGain - The baisgain values that are to alter the fill table

TableSize - The number of entries you wish to make the table (0x100 or 0x800)

Returns:
TRUE, error thrown otherwise (but only for input variables)
See also:
-

Definition at line 604 of file gradtbl.cpp.

00607 {   
00608     // Find a GDraw context to generate dithertable entries for us
00609     GDrawContext *GD = GRenderRegion::GetStaticDrawContext();
00610     ERROR3IF(GD == NULL, "GradTable::BuildTable - No GDraw context?!");
00611 
00612     // Determine if either the start or end colour is a spot colour - if it is, we must
00613     // coerce the fill into a "mix" (rgb) rather than rainbow fill style
00614     if (Effect != EFFECT_RGB && (StartCol.GetSpotParent() != NULL || EndCol.GetSpotParent() != NULL))
00615         Effect = EFFECT_RGB;
00616 
00617     // Get colour contexts: we need 2 - first, an RGB context for the ContextView, which
00618     // will be used to get colour-corrected/separated/etc output colour in RGB; and second,
00619     // a generic RGB or HSV context to provide a "mixing colourspace" for the graduations.
00620     ColourContext *cc = NULL;
00621     ColourContext *ccRGB = ColourManager::GetColourContext(COLOURMODEL_RGBT, ContextView);
00622 
00623     if (Effect == EFFECT_RGB)
00624         cc = ColourManager::GetColourContext(COLOURMODEL_RGBT);     // RGB fade
00625     else
00626         cc = ColourManager::GetColourContext(COLOURMODEL_HSVT);     // HSV fade
00627 
00628     // If we can't find RGB/HSV contexts, something is seriously broken
00629     ERROR3IF(cc == NULL || ccRGB == NULL,
00630             "GradTable::BuildTable - Can't find my colour context!");
00631 
00632     // Fill in the Start and End colours of the table, if we've hit them
00633     PColourRGBT Result;
00634 
00635     // set our table size for this grad
00636     SetTableSize(LargeTable);
00637 
00638     ccRGB->ConvertColour(&StartCol, (ColourPacked *) &Result);
00639     m_pTable->StartColour = RGB(Result.Red, Result.Green, Result.Blue);
00640 
00641     ccRGB->ConvertColour(&EndCol, (ColourPacked *) &Result);
00642     m_pTable->EndColour = RGB(Result.Red, Result.Green, Result.Blue);
00643 
00644     BiasGain.SetIntervals (AFp (0), AFp (m_pTable->Length));
00645 
00646     const INT32 TableLength = m_pTable->Length;
00647     double MixFraction;
00648     DocColour temp;
00649     INT32 r, g, b;
00650     double res;
00651 
00652     for (INT32 col = 0; col < TableLength; col++)
00653     {
00654         res = BiasGain.MapInterval( AFp( col ) );
00655         
00656         MixFraction = res / TableLength;
00657         
00658         // Create a new colour which is an appropriate mixture of the start/end colours
00659         temp.Mix(&StartCol, &EndCol, MixFraction, cc, (Effect == EFFECT_HSV_LONG), ccRGB);
00660         temp.GetRGBValue (&r, &g, &b);
00661 
00662         // Get GDraw to fill in the dither entry for us (FALSE means it's an RGB colour)
00663         GD->AddToGraduationTable(RGB(r, g, b), FALSE, m_pTable, col);
00664     }
00665     
00666     return (TRUE);
00667 }

BOOL GradTable::BuildTable DocColour StartCol,
DocColour EndCol,
View ContextView,
EFFECTTYPE  Effect,
BOOL  LargeTable = FALSE
 

Builds a GradTable from StartCol to EndCol, filling in the entire table with appropriate GDraw dither patterns.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> (Will)
Date:
14/5/96 (14/9/94)
Parameters:
StartCol,EndCol - Define the end colours of the graduation [INPUTS] ContextView - Points to the view in which the gradation is to be displayed. (This is necessary for correction and separation etc. If proper colour handling is not needed, then you may pass NULL, but generally, this parameter should be sensible)
Effect - EFFECT_FADE, EFFECT_HSV_SHORT, or EFFECT_HSV_LONG

TableSize - The number of entries you wish to make the table (0x100 or 0x800)

Returns:
FALSE if it fails
== NOTE that this version of the call also implicitly sets the table size! ==

See also:
GradTable::SetTableSize

Definition at line 324 of file gradtbl.cpp.

00327 {
00328     SetTableSize(LargeTable);
00329 
00330     return(BuildTable(StartCol, EndCol, ContextView, Effect, 0, m_pTable->Length));
00331 }

void GradTable::FillTable DWORD  StartIndex,
DWORD  EndIndex,
PColourRGBT StartDef,
PColourRGBT EndDef
[protected]
 

Builds a GradTable from StartIndex to EndIndex by linearly interpolating between the StartDef and EndDef RGB colours.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
21/7/96
Parameters:
StartIndex,EndIndex - Define the indices into the grad fill table [INPUTS] between which you want to fill in the table. NOTE that Table[StartIndex] is filled in, while table[EndIndex] is NOT. StartDef, EndDef - Define the end colours of the graduation
Notes: In order to correctly handle Rainbow fills, you must interpolate only small sections of the table - it is recommended that you fill no more than 16 entries of the table at a time with this linear interpolation.

Definition at line 357 of file gradtbl.cpp.

00359 {
00360     GDrawContext *GD = GRenderRegion::GetStaticDrawContext();
00361 
00362     // Place the StartDef in as the first entry
00363     GD->AddToGraduationTable(RGB(StartDef->Red, StartDef->Green, StartDef->Blue),
00364                                 FALSE, m_pTable, StartIndex);
00365 
00366     // ...and start interpolating from the second entry
00367     DWORD MixStep = (1 << 24) / (EndIndex - StartIndex);
00368     DWORD MixFraction = MixStep;
00369 
00370     DWORD R,G,B;
00371     for (DWORD Index = StartIndex + 1; Index < EndIndex; Index++)
00372     {
00373         // Calculate intermediate RGB values into 8bpp values
00374         R = (StartDef->Red * (0x01000000 - MixFraction)) + (EndDef->Red * MixFraction);
00375         R >>= 24;
00376 
00377         G = (StartDef->Green * (0x01000000 - MixFraction)) + (EndDef->Green * MixFraction);
00378         G >>= 24;
00379 
00380         B = (StartDef->Blue * (0x01000000 - MixFraction)) + (EndDef->Blue * MixFraction);
00381         B >>= 24;
00382 
00383         // Get Gavin to fill in the dither entry for us (FALSE means it's an RGB Indexour)
00384         GD->AddToGraduationTable(RGB(R,G,B), FALSE, m_pTable, Index);
00385 
00386         MixFraction += MixStep;
00387     }
00388 }

GraduationTable* GradTable::GetTable void   )  [inline]
 

Definition at line 189 of file gradtbl.h.

00189 { return(m_pTable); };

INT32 GradTable::GetTableLength GDrawContext GD,
BOOL  LargeTable
[protected]
 

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/10/96
Parameters:
GD - pointer to GDraw context to use [INPUTS] LargeTable - if true then use a long grad table
Returns:
The number of entries in a grad table for the specified context

Definition at line 234 of file gradtbl.cpp.

00235 {
00236     if (LargeTable)
00237     {
00238         return(GD->GetLongGraduationTableLength());
00239     }
00240     else
00241     {
00242         return(GD->GetGraduationTableLength());
00243     }
00244 }

INT32 GradTable::GetTableLength void   )  [inline]
 

Definition at line 149 of file gradtbl.h.

00149 { return(m_pTable->Length); };

INT32 GradTable::GetTableSize GDrawContext GD,
BOOL  LargeTable
[protected]
 

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/10/96
Parameters:
GD - pointer to GDraw context to use [INPUTS] LargeTable - if true then use a long grad table
Returns:
The size in bytes of a grad table for the specified context

Definition at line 208 of file gradtbl.cpp.

00209 {
00210     if (LargeTable)
00211     {
00212         return(GD->GetLongGraduationTableSize());
00213     }
00214     else
00215     {
00216         return(GD->GetGraduationTableSize());
00217     }
00218 }

BOOL GradTable::IsLarge void   )  [inline]
 

Definition at line 192 of file gradtbl.h.

00192 { return(m_bLargeTable); };

void GradTable::SetTableSize BOOL  LargeTable  ) 
 

To set the size of this Grad table.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/10/96
Parameters:
LargeTable - if true then use a long grad table [INPUTS]
Notes: The table defaults to small

Definition at line 262 of file gradtbl.cpp.

00263 {
00264     // If we don't have the right table size or no table at all
00265     if ((LargeTable != m_bLargeTable) || (m_pTable == NULL))
00266     {
00267         m_bLargeTable = LargeTable;
00268 
00269         if (m_pTable != NULL)
00270         {
00271             CCFree(m_pTable);
00272             m_pTable = NULL;
00273         }
00274 
00275         GDrawContext *GD = GRenderRegion::GetStaticDrawContext();
00276 
00277         if (GD != NULL)
00278         {
00279             INT32 Size = GetTableSize(GD, m_bLargeTable);
00280             
00281             m_pTable = (GraduationTable*) CCMalloc(Size);
00282 
00283             if (m_pTable != NULL)
00284             {
00285                 m_pTable->Length = GetTableLength(GD, LargeTable);
00286             }
00287         }
00288     }
00289 }


Member Data Documentation

BOOL GradTable::m_bLargeTable [private]
 

Definition at line 206 of file gradtbl.h.

GraduationTable* GradTable::m_pTable [private]
 

Definition at line 207 of file gradtbl.h.


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