coplfilr.cpp

Go to the documentation of this file.
00001 // $Id: coplfilr.cpp 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 
00099 /*
00100 */
00101 
00102 #include "camtypes.h"
00103 #include "coplfilr.h"
00104 
00105 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00106 //#include "ccfile.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00107 #include "cdrcol.h"
00108 //#include "oilfltrs.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00109 #include "optsunit.h"
00110 #include "progress.h"
00111 #include "scunit.h"
00112 #include "sgcolour.h"
00113 //#include "isetres.h"
00114 
00115 //#include "ben.h"
00116 //#include "filtrres.h"
00117 //#include "peter.h"
00118 //#include "will2.h"
00119 
00120 DECLARE_SOURCE("$Revision: 1282 $");
00121 
00122 CC_IMPLEMENT_DYNAMIC(PaletteFilter, Filter)
00123 CC_IMPLEMENT_DYNAMIC(CorelPaletteFilter, PaletteFilter)
00124 CC_IMPLEMENT_DYNAMIC(MSPaletteFilter, PaletteFilter)
00125 CC_IMPLEMENT_DYNAMIC(AdobeColourTableFilter, PaletteFilter)
00126 CC_IMPLEMENT_DYNAMIC(AdobeColourSwatchFilter, PaletteFilter)
00127 CC_IMPLEMENT_DYNAMIC(JCWColourFilter, PaletteFilter)
00128 CC_IMPLEMENT_DYNAMIC(PaintShopProPaletteFilter, PaletteFilter)
00129 
00130 #define new CAM_DEBUG_NEW
00131 
00132 typedef struct {
00133     WORD Unknown;
00134     BYTE Entries[2];
00135 } cpl_header;
00136 
00137 #define CPL_MIN_ENTRY_SIZE      14      // minimum size of an entry in a cpl file
00138 #define CPL_MAX_ENTRY_SIZE      (13+32) // max size
00139 #define CPL_CHECK_TEXT_START    16      // place to start checking the text
00140 #define CPF_MAX_COLNAME_SIZE 32
00141 
00142 #define CPL_FVU     -1      // version unknown
00143 #define CPL_FV4     4       // version 4
00144 #define CPL_FV5     5       // version 5
00145 
00146 
00147 
00148 /********************************************************************************************
00149 >   PaletteFilter::PaletteFilter()
00150 
00151     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00152     Created:    30/4/96
00153     Inputs:     -
00154     Returns:    -
00155     Purpose:    Constructor for a base palette filter
00156     SeeAlso:    Filter
00157 ********************************************************************************************/
00158 PaletteFilter::PaletteFilter()
00159 {
00160     m_pNewColours = NULL;
00161 
00162     ImportIntoGallery = TRUE;
00163     CurrentGalleryGroup = NULL;
00164 }
00165 
00166 
00167 /********************************************************************************************
00168 >   PaletteFilter::~PaletteFilter()
00169 
00170     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00171     Created:    30/4/96
00172     Inputs:     -
00173     Returns:    -
00174     Purpose:    Destructor for a base palette filter
00175     SeeAlso:    Filter
00176 ********************************************************************************************/
00177 PaletteFilter::~PaletteFilter()
00178 {
00179     if (m_pNewColours != NULL)
00180     {
00181         m_pNewColours->DestroyColours();
00182         delete m_pNewColours;
00183         m_pNewColours = NULL;
00184     }
00185 }
00186 
00187 
00188 /********************************************************************************************
00189 >   virtual BOOL PaletteFilter::IsDefaultDocRequired(const TCHAR* pcszPathName)
00190 
00191     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00192     Created:    30/4/96
00193     Inputs:     pcszPathName - pointer to the name of the file that is about to be imported
00194     Returns:    TRUE if a document is required to import this file into,
00195                 FALSE if file supplies the document
00196     Purpose:    For determining wether this filter needs a document to be created to import
00197                 into.
00198 ********************************************************************************************/
00199 BOOL PaletteFilter::IsDefaultDocRequired(const TCHAR* pcszPathName)
00200 {
00201     // Since palette files are unlikely to supply a document we will return TRUE.
00202     // Derived classes can still virtually override this function and return FALSE if required.
00203 
00204     return TRUE;
00205 }
00206 
00207 
00208 /********************************************************************************************
00209 >   virtual BOOL PaletteFilter::DoImport(SelOperation* pOp, CCLexFile* pFile, Document* pDoc, BOOL AutoChosen, ImportPosition *Pos,
00210                              KernelBitmap** ppImportedBitmap, DocCoord* pPosTranslate, String_256* URL)
00211 
00212     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00213     Created:    30/4/96
00214     Inputs:     pOp     - The operation this import is running under
00215                 pFile   - The file to import from
00216                 pDoc    - The document to import into
00217                 AutoChosen  - TRUE if this filter was chosen by the system, FALSE if chosen by the user
00218                 ImportPos   - The position to import the file data at
00219                 Pos -
00220                 ppImportedBitmap - this is used mainly in the bitfltr.cpp for the HTML
00221                 import filter. HTMLFilter::DoImport() needs a pointer to a kernel bitmap
00222                 to set the background bitmap up into Camelot.
00223                 pPosTranslate - This is used too by the HTMLFilter in order to do a formatting.
00224                 URL - original URL of the imported file
00225     Returns:    TRUE for successful import, FALSE if an error occured.
00226     Purpose:    Base class for handling palette import
00227 
00228     Notes:      **** IMPORTANT **************************************************************
00229                 Palette filters can be called directly from the colour gallery (sgcolour.cpp)
00230                 library groups to import palette files directly into the gallery.
00231                 In this case, pOp and pDoc are NULL, and the member vars CurrentGalleryGroup
00232                 and ImportIntoGallery are set up suitably. It is this important that these
00233                 filters continue to be happy about not importing into a document!
00234                 *****************************************************************************
00235 
00236     SeeAlso:    Filter::DoImport
00237 ********************************************************************************************/
00238 BOOL PaletteFilter::DoImport(SelOperation* pOp, CCLexFile* pFile, Document* pDoc, BOOL AutoChosen, ImportPosition *Pos,
00239                              KernelBitmap** ppImportedBitmap, DocCoord* pPosTranslate, String_256* URL)
00240 {
00241     BOOL ok = TRUE;
00242 
00243     // Copy parameters into member vars.
00244     // NOTE that we allow pOp and pDoc to be NULL, when we are importing into a gallery!
00245     ERROR2IF(pFile==NULL, FALSE, "NULL parameter passed");
00246     m_pImportOp = pOp;
00247     m_pImportFile = pFile;
00248     m_pImportDoc = pDoc;
00249 
00250     // Determine if this is really a huge bodge and we're importing directly into the colour gallery
00251 #if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX)
00252     //ColourSGallery *ParentGal = (ColourSGallery *) OpDisplayColourGallery::FindGallery();
00253     ColourSGallery *ParentGal = ColourSGallery::GetInstance();
00254     if (ParentGal != NULL)
00255         CurrentGalleryGroup = ParentGal->GetCurrentImportGroup();
00256     else
00257 #endif
00258         CurrentGalleryGroup = NULL;
00259 
00260     ImportIntoGallery = (CurrentGalleryGroup != NULL);
00261     ERROR2IF(!ImportIntoGallery && (pDoc == NULL || pOp == NULL), FALSE, "NULL doc/op when not importing into gallery");
00262 
00263     // Initialise base class services
00264     if (ok)
00265         ok = PrepareForImport();
00266 
00267     // Call derived loading functions                                                                                   
00268     if (ok)
00269         ok = PreImport();
00270     if (ok)
00271         ok = ImportPalette();
00272     if (ok)
00273         ok = PostImport();
00274 
00275     // Finialise base class importation
00276     if (ok)
00277         ok = FinishImport(TRUE);
00278     else
00279         FinishImport(FALSE);
00280 
00281     CurrentGalleryGroup = NULL;
00282     ImportIntoGallery = FALSE;
00283 
00284     return ok;
00285 }
00286 
00287 
00288 /********************************************************************************************
00289 >   virtual BOOL PaletteFilter::DoExport(Operation* pOp, CCLexFile* pFile,
00290                                          PathName* pPath, Document* pDoc,
00291                                          BOOL ShowOptions)
00292     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00293     Created:    30/4/96
00294     Inputs:     pOp         - The operation this import is running under
00295                 pFile       - The file to import from
00296                 pPath       - Importing path
00297                 pDoc        - The document to import into
00298                 ShowOptions - Show the export options dialogue.
00299     Outputs:    -
00300     Returns:    TRUE for successful export, FALSE if an error occured.
00301     Purpose:    Base class for handling palette export
00302     SeeAlso:    Filter::DoImport
00303 ********************************************************************************************/
00304 BOOL PaletteFilter::DoExport(Operation* pOp, CCLexFile* pFile,
00305                              PathName* pPath, Document* pDoc,
00306                              BOOL ShowOptions)
00307 {
00308     // For the moment palettes are not exported.
00309     return FALSE;
00310 }
00311 
00312 
00313 /********************************************************************************************
00314 >   BOOL PaletteFilter::PrepareForImport()
00315 
00316     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00317     Created:    1/5/96
00318     Inputs:     -
00319     Outputs:    -
00320     Returns:    TRUE for success, FALSE if an error occured.
00321     Purpose:    Initialises the base class before import
00322 ********************************************************************************************/
00323 BOOL PaletteFilter::PrepareForImport()
00324 {
00325     if (!ImportIntoGallery)
00326     {
00327         ERROR2IF(m_pImportDoc==NULL, FALSE, "NULL pointer");
00328 
00329         // Find the colour list document component
00330         ColourListComponent* pColours = NULL;
00331         DocComponent *pComponent = m_pImportDoc->EnumerateDocComponents(NULL);
00332         while (pComponent != NULL)
00333         {
00334             // If this is the colour component, remember it
00335             if (IS_A(pComponent, ColourListComponent))
00336                 pColours = (ColourListComponent*) pComponent;
00337 
00338             // Look for next doc component
00339             pComponent = m_pImportDoc->EnumerateDocComponents(pComponent);
00340         }
00341         ERROR2IF(pColours==NULL, FALSE, "Import document had no colour list");
00342 
00343         // Create a new imported colours manager
00344         ERROR3IF(m_pNewColours != NULL, "ColourImport manager already present\n");
00345         if (m_pNewColours != NULL)
00346         {
00347             m_pNewColours->DestroyColours();
00348             delete m_pNewColours;
00349         }
00350 
00351         m_pNewColours = new ImportedColours(pColours, FALSE);
00352         if ((m_pNewColours == NULL) || !m_pNewColours->Init())
00353             return FALSE;
00354     }
00355 
00356     return TRUE;
00357 }
00358 
00359 
00360 /********************************************************************************************
00361 >   BOOL PaletteFilter::FinishImport(BOOL Success)
00362 
00363     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00364     Created:    1/5/96
00365     Inputs:     Success - TRUE if import has been successful
00366     Outputs:    -
00367     Returns:    TRUE for success, FALSE if an error occured.
00368     Purpose:    Finialises colour import
00369 ********************************************************************************************/
00370 BOOL PaletteFilter::FinishImport(BOOL Success)
00371 {
00372     BOOL ok = TRUE;
00373 
00374     if (!ImportIntoGallery)
00375     {
00376         // If we didn't even get to initialise, then return quietly.
00377         if (m_pNewColours == NULL)
00378             return FALSE;
00379 
00380         EndSlowJob();
00381         BeginSlowJob(-1, FALSE);
00382 
00383         // Import is finished, so add any outstanding colours to the document (if the
00384         // import was successful), and delete the colour table
00385         if (Success)
00386             ok = m_pNewColours->AddColoursToDocument();
00387         else
00388             m_pNewColours->DestroyColours();
00389 
00390         // Clean up claimed memory
00391         delete m_pNewColours;
00392         m_pNewColours = NULL;
00393     }
00394 
00395     return ok;
00396 }
00397 
00398 
00399 /********************************************************************************************
00400 >   BOOL PaletteFilter::ProcessRGBColour(double Red, double Green, double Blue, const StringBase* pColName = NULL)
00401 
00402     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00403     Created:    1/5/96
00404     Inputs:     Red - red value 0..1
00405                 Green - green value 0..1
00406                 Blue - blue value 0..1
00407                 pColName - name to give the colour (NULL if no name)
00408     Outputs:    -
00409     Returns:    TRUE for success, FALSE if an error occured.
00410     Purpose:    Generates a Camelot RGB colour and adds it to the imported colours list
00411 ********************************************************************************************/
00412 BOOL PaletteFilter::ProcessRGBColour(double Red, double Green, double Blue, const StringBase* pColName)
00413 {
00414     // Ensure colour components are in range
00415     ERROR3IF(Red<0, "Red component less than 0");
00416     ERROR3IF(Red>1, "Red component greater than 1");
00417     ERROR3IF(Green<0, "Green component less than 0");
00418     ERROR3IF(Green>1, "Green component greater than 1");
00419     ERROR3IF(Blue<0, "Blue component less than 0");
00420     ERROR3IF(Blue>1, "Blue component greater than 1");
00421     Red = ClampZeroToOne(Red);
00422     Green = ClampZeroToOne(Green);
00423     Blue = ClampZeroToOne(Blue);
00424 
00425     // Make a Camelot RGB colour
00426     ColourRGBT NewColour;
00427     NewColour.Red = Red;
00428     NewColour.Green = Green;
00429     NewColour.Blue = Blue;
00430     NewColour.Transparent = 0;
00431 
00432     // Name the colour
00433     String_64 NewColourName;
00434     BOOL ok = TRUE;
00435     if (pColName==NULL || pColName->IsEmpty())
00436         ok = NameRGBColour(&NewColour, &NewColourName);
00437     else
00438         NewColourName = *pColName;      
00439 
00440     if (ok)
00441     {
00442         if (ImportIntoGallery)
00443             ok = AddColourToGallery(PalettePrefix_None, &NewColourName, (ColourGeneric *)&NewColour, COLOURMODEL_RGBT);
00444         else
00445             ok = m_pNewColours->AddColour(&NewColourName, &NewColour);
00446     }
00447 
00448     return ok;
00449 }
00450 
00451 
00452 /********************************************************************************************
00453 >   BOOL PaletteFilter::ProcessCMYKColour(double Cyan, double Magenta, double Yellow, double Key, const StringBase* pColName = NULL)
00454 
00455     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00456     Created:    2/5/96
00457     Inputs:     Cyan - cyan value 0..1
00458                 Magenta - green value 0..1
00459                 Yellow - blue value 0..1
00460                 Key - black value 0..1
00461                 pColName - name to give the colour (NULL if no name)
00462     Outputs:    -
00463     Returns:    TRUE for success, FALSE if an error occured.
00464     Purpose:    Generates a Camelot CMYK colour and adds it to the imported colours list
00465 ********************************************************************************************/
00466 BOOL PaletteFilter::ProcessCMYKColour(double Cyan, double Magenta, double Yellow, double Key, const StringBase* pColName)
00467 {
00468     // Ensure colour components are in range
00469     ERROR3IF(Cyan<0, "Cyan component less than 0");
00470     ERROR3IF(Cyan>1, "Cyan component greater than 1");
00471     ERROR3IF(Magenta<0, "Magenta component less than 0");
00472     ERROR3IF(Magenta>1, "Magenta component greater than 1");
00473     ERROR3IF(Yellow<0, "Yellow component less than 0");
00474     ERROR3IF(Yellow>1, "Yellow component greater than 1");
00475     ERROR3IF(Key<0, "Key component less than 0");
00476     ERROR3IF(Key>1, "Key component greater than 1");
00477     Cyan = ClampZeroToOne(Cyan);
00478     Magenta = ClampZeroToOne(Magenta);
00479     Yellow = ClampZeroToOne(Yellow);
00480     Key = ClampZeroToOne(Key);
00481 
00482     // Make a Camelot CMYK colour
00483     ColourCMYK NewColour;
00484     NewColour.Cyan = Cyan;
00485     NewColour.Magenta = Magenta;
00486     NewColour.Yellow = Yellow;
00487     NewColour.Key = Key;
00488 
00489     // Name the colour
00490     String_64 NewColourName;
00491     BOOL ok = TRUE;
00492     if (pColName==NULL || pColName->IsEmpty())
00493         ok = NameCMYKColour(&NewColour, &NewColourName);
00494     else
00495         NewColourName = *pColName;      
00496 
00497     if (ok)
00498     {
00499         if (ImportIntoGallery)
00500             ok = AddColourToGallery(PalettePrefix_None, &NewColourName, (ColourGeneric *)&NewColour, COLOURMODEL_CMYK);
00501         else
00502             ok = m_pNewColours->AddColour(&NewColourName, &NewColour);
00503     }
00504 
00505     return ok;
00506 }
00507 
00508 
00509 /********************************************************************************************
00510 >   BOOL PaletteFilter::ProcessHSVColour(double Hue, double Sat, double Value, const StringBase* pColName = NULL)
00511 
00512     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00513     Created:    2/5/96
00514     Inputs:     Hue - Hue value 0..1
00515                 Sat - Saturation value 0..1
00516                 Value - Brightness value 0..1
00517                 pColName - name to give the colour (NULL if no name)
00518     Outputs:    -
00519     Returns:    TRUE for success, FALSE if an error occured.
00520     Purpose:    Generates a Camelot HSV colour and adds it to the imported colours list
00521 ********************************************************************************************/
00522 BOOL PaletteFilter::ProcessHSVColour(double Hue, double Sat, double Value, const StringBase* pColName)
00523 {
00524     // Ensure colour components are in range
00525     ERROR3IF(Hue<0, "Hue component less than 0");
00526     ERROR3IF(Hue>1, "Hue component greater than 1");
00527     ERROR3IF(Sat<0, "Saturation component less than 0");
00528     ERROR3IF(Sat>1, "Saturation component greater than 1");
00529     ERROR3IF(Value<0, "Value component less than 0");
00530     ERROR3IF(Value>1, "Value component greater than 1");
00531     Hue = ClampZeroToOne(Hue);
00532     Sat = ClampZeroToOne(Sat);
00533     Value = ClampZeroToOne(Value);
00534 
00535     // Make a Camelot HSV colour
00536     ColourHSVT NewColour;
00537     NewColour.Hue = Hue;
00538     NewColour.Saturation = Sat;
00539     NewColour.Value = Value;
00540     NewColour.Transparent = 0;
00541 
00542     // Name the colour
00543     String_64 NewColourName;
00544     BOOL ok = TRUE;
00545     if (pColName==NULL || pColName->IsEmpty())
00546         ok = NameHSVColour(&NewColour, &NewColourName);
00547     else
00548         NewColourName = *pColName;      
00549 
00550     if (ok)
00551     {
00552         if (ImportIntoGallery)
00553             ok = AddColourToGallery(PalettePrefix_None, &NewColourName, (ColourGeneric *)&NewColour, COLOURMODEL_HSVT);
00554         else
00555             ok = m_pNewColours->AddColour(&NewColourName, &NewColour);
00556     }
00557 
00558     return ok;
00559 }
00560 
00561 
00562 /********************************************************************************************
00563 >   BOOL PaletteFilter::ProcessLabColour(double Luminance, double A, double B, const StringBase* pColName = NULL)
00564 
00565     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00566     Created:    7/5/96
00567     Inputs:     Luminance - Luminance value 0..100 (black to white)
00568                 A - a value +127..-128 (green to red)
00569                 B - b value +127..-128 (blue to yellow)
00570                 pColName - name to give the colour (NULL if no name)
00571     Outputs:    -
00572     Returns:    TRUE for success, FALSE if an error occured.
00573     Purpose:    Generates a name for this colour and adds it to the imported colours list
00574                 N.B. Camelot does not support Lab colours so the colour is converted to 
00575                      RGB or greyscale.
00576 ********************************************************************************************/
00577 BOOL PaletteFilter::ProcessLabColour(double Luminance, double A, double B, const StringBase* pColName)
00578 {
00579     // Ensure colour components are in range
00580     ERROR3IF(Luminance<0, "Luminance component less than 0");
00581     ERROR3IF(Luminance>100, "Luminance component greater than 100");
00582     ERROR3IF(A<-128, "A component less than -128");
00583     ERROR3IF(A> 127, "A component greater than 127");
00584     ERROR3IF(B<-128, "B component less than -128");
00585     ERROR3IF(B> 127, "B component greater than 127");
00586     Luminance = __min(100, __max(0, Luminance));
00587     A = __min(127, __max(-128, A));
00588     B = __min(127, __max(-128, B));
00589 
00590     // Convert to RGB values
00591     Vector3D Lab(Luminance, A, B);
00592     Vector3D RGBResult;
00593     PaletteFilter::ConvertLABToRGB(Lab, &RGBResult);
00594 
00595     return ProcessRGBColour(RGBResult.x, RGBResult.y, RGBResult.z, pColName );
00596 }
00597 
00598 
00599 /********************************************************************************************
00600 >   BOOL PaletteFilter::ProcessGreyColour(double Intensity, const StringBase* pColName = NULL)
00601 
00602     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00603     Created:    7/5/96
00604     Inputs:     Intensity - 0..1 (black to white)
00605                 pColName - name to give the colour (NULL if no name)
00606     Outputs:    -
00607     Returns:    TRUE for success, FALSE if an error occured.
00608     Purpose:    Generates a Camelot greyscale colour and adds it to the imported colours list
00609 ********************************************************************************************/
00610 BOOL PaletteFilter::ProcessGreyColour(double Intensity, const StringBase* pColName)
00611 {
00612     // Ensure colour components are in range
00613     ERROR3IF(Intensity<0, "Intensity component less than 0");
00614     ERROR3IF(Intensity>1, "Intensity component greater than 1");
00615     Intensity = ClampZeroToOne(Intensity);
00616 
00617     // Make a Camelot greyscale colour
00618     ColourGreyT NewColour;
00619     NewColour.Intensity = Intensity;
00620     NewColour.Reserved1 = 0;
00621     NewColour.Reserved2 = 0;
00622     NewColour.Transparent = 0;
00623 
00624     // Name the colour
00625     String_64 NewColourName;
00626     BOOL ok = TRUE;
00627     if (pColName==NULL || pColName->IsEmpty())
00628         ok = NameGreyColour(&NewColour, &NewColourName);
00629     else
00630         NewColourName = *pColName;      
00631 
00632     if (ok)
00633     {
00634         if (ImportIntoGallery)
00635             ok = AddColourToGallery(PalettePrefix_None, &NewColourName, (ColourGeneric *)&NewColour, COLOURMODEL_GREYT);
00636         else
00637             ok = m_pNewColours->AddColour(&NewColourName, &NewColour);
00638     }
00639 
00640     return ok;
00641 }
00642  
00643 
00644 /********************************************************************************************
00645 >   BOOL PaletteFilter::NameRGBColour(ColourRGBT* pColour, StringBase* pName)
00646 
00647     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00648     Created:    3/5/96
00649     Inputs:     pColour - the Camelot colour to name
00650     Outputs:    pName holds the generated name
00651     Returns:    TRUE for success, FALSE if an error occured.
00652     Purpose:    Generates a name for this RGB colour
00653 ********************************************************************************************/
00654 BOOL PaletteFilter::NameRGBColour(ColourRGBT* pColour, StringBase* pName)
00655 {
00656     ERROR2IF(pColour==NULL || pName==NULL, FALSE, "NULL Pointer");
00657 
00658     if (UsePercentageColour())
00659     {
00660         pName->MakeMsg(_R(IDS_PALETTEIMPORT_RGBPERCENT),
00661                                 (INT32)(pColour->Red.MakeDouble()*100+0.4999),
00662                                 (INT32)(pColour->Green.MakeDouble()*100+0.4999),
00663                                 (INT32)(pColour->Blue.MakeDouble()*100+0.4999) );
00664     }
00665     else
00666     {
00667         pName->MakeMsg(_R(IDS_PALETTEIMPORT_RGBVALUE),
00668                                 (INT32)(pColour->Red.MakeDouble()*255+0.4999),
00669                                 (INT32)(pColour->Green.MakeDouble()*255+0.4999),
00670                                 (INT32)(pColour->Blue.MakeDouble()*255+0.4999) );
00671     }
00672 
00673     return TRUE;
00674 }
00675 
00676 
00677 /********************************************************************************************
00678 >   BOOL PaletteFilter::NameCMYKColour(ColourCMYK* pColour, StringBase* pName)
00679 
00680     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00681     Created:    3/5/96
00682     Inputs:     pColour - the Camelot colour to name
00683     Outputs:    pName holds the generated name
00684     Returns:    TRUE for success, FALSE if an error occured.
00685     Purpose:    Generates a name for this CMYK colour
00686 ********************************************************************************************/
00687 BOOL PaletteFilter::NameCMYKColour(ColourCMYK* pColour, StringBase* pName)
00688 {
00689     ERROR2IF(pColour==NULL || pName==NULL, FALSE, "NULL Pointer");
00690     
00691     if (UsePercentageColour())
00692     {
00693         pName->MakeMsg(_R(IDS_PALETTEIMPORT_CMYKPERCENT),
00694                                 (INT32)(pColour->Cyan.MakeDouble()*100+0.4999),
00695                                 (INT32)(pColour->Magenta.MakeDouble()*100+0.4999),
00696                                 (INT32)(pColour->Yellow.MakeDouble()*100+0.4999),
00697                                 (INT32)(pColour->Key.MakeDouble()*100+0.4999) );
00698     }
00699     else
00700     {
00701         pName->MakeMsg(_R(IDS_PALETTEIMPORT_CMYKVALUE),
00702                                 (INT32)(pColour->Cyan.MakeDouble()*255+0.4999),
00703                                 (INT32)(pColour->Magenta.MakeDouble()*255+0.4999),
00704                                 (INT32)(pColour->Yellow.MakeDouble()*255+0.4999),
00705                                 (INT32)(pColour->Key.MakeDouble()*255+0.4999) );
00706     }
00707 
00708     return TRUE;
00709 }
00710 
00711 
00712 /********************************************************************************************
00713 >   BOOL PaletteFilter::NameHSVColour(ColourHSVT* pColour, StringBase* pName)
00714 
00715     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00716     Created:    3/5/96
00717     Inputs:     pColour - the Camelot colour to name
00718     Outputs:    pName holds the generated name
00719     Returns:    TRUE for success, FALSE if an error occured.
00720     Purpose:    Generates a name for this CMYK colour
00721 ********************************************************************************************/
00722 BOOL PaletteFilter::NameHSVColour(ColourHSVT* pColour, StringBase* pName)
00723 {
00724     ERROR2IF(pColour==NULL || pName==NULL, FALSE, "NULL Pointer");
00725     
00726     if (UsePercentageColour())
00727     {
00728         pName->MakeMsg(_R(IDS_PALETTEIMPORT_HSVPERCENT),
00729                                 (INT32)(pColour->Hue.MakeDouble()*360+0.4999),
00730                                 (INT32)(pColour->Saturation.MakeDouble()*100+0.4999),
00731                                 (INT32)(pColour->Value.MakeDouble()*100+0.4999) );
00732     }
00733     else
00734     {
00735         pName->MakeMsg(_R(IDS_PALETTEIMPORT_HSVVALUE),
00736                                 (INT32)(pColour->Hue.MakeDouble()*360+0.4999),
00737                                 (INT32)(pColour->Saturation.MakeDouble()*255+0.4999),
00738                                 (INT32)(pColour->Value.MakeDouble()*255+0.4999) );
00739     }
00740 
00741     return TRUE;
00742 }
00743 
00744 
00745 /********************************************************************************************
00746 >   BOOL PaletteFilter::NameGreyColour(ColourGreyT* pColour, StringBase* pName)
00747 
00748     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00749     Created:    7/5/96
00750     Inputs:     pColour - the Camelot colour to name
00751     Outputs:    pName holds the generated name
00752     Returns:    TRUE for success, FALSE if an error occured.
00753     Purpose:    Generates a name for this greyscale colour
00754 ********************************************************************************************/
00755 BOOL PaletteFilter::NameGreyColour(ColourGreyT* pColour, StringBase* pName)
00756 {
00757     ERROR2IF(pColour==NULL || pName==NULL, FALSE, "NULL Pointer");
00758 
00759     if (pColour->Intensity.MakeDouble() <= 0.0)
00760         *pName = String_32(_R(IDS_PALETTEIMPORT_GREYBLACK));
00761     else if (pColour->Intensity.MakeDouble() >= 1.0)
00762             *pName = String_32(_R(IDS_PALETTEIMPORT_GREYWHITE));
00763         else
00764             pName->MakeMsg(_R(IDS_PALETTEIMPORT_GREYPERCENT), (INT32)(pColour->Intensity.MakeDouble()*100+0.4999));
00765 
00766     return TRUE;
00767 }
00768 
00769 
00770 /********************************************************************************************
00771 >   BOOL PaletteFilter::UsePercentageColour()
00772 
00773     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00774     Created:    29/5/96
00775     Inputs:     -
00776     Outputs:    -
00777     Returns:    TRUE if the colour editor preference is for percentages, FALSE if not
00778     Purpose:    To  see wether or not to use the precentage colour naming scheme
00779 ********************************************************************************************/
00780 BOOL PaletteFilter::UsePercentageColour()
00781 {
00782 // WEBSTER - markn 24/4/97
00783 #ifdef WEBSTER
00784     // Always use percentages for colour units in Webster
00785     return TRUE;
00786 #else
00787     #if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX)
00788         // Read what the colour editors preference is
00789         ScaleUnit* pUnit = UnitsTab::GetColourUnitPreference();
00790 
00791         return (pUnit == &StandardUnit::UnitPercent);
00792     #else
00793         return FALSE;
00794     #endif
00795 #endif // WEBSTER
00796 }
00797 
00798 
00799 /********************************************************************************************
00800 >   BOOL PaletteFilter::StartPercentage(INT32 UpTo = -1)
00801 
00802     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00803     Created:    1/5/96
00804     Inputs:     UpTo - the 100% value
00805     Outputs:    -
00806     Returns:    TRUE for success, FALSE if an error occured.
00807     Purpose:    Starts a percentage delay indicator that runs from 0 to 100.  If you don't
00808                 know how many colours you are importing pass -1 and the length of the file
00809                 is used
00810 ********************************************************************************************/
00811 BOOL PaletteFilter::StartPercentage(INT32 UpTo)
00812 {
00813 #if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX)
00814     if (UpTo == -1)
00815     {
00816         if (m_pImportFile != NULL)
00817             BeginSlowJob(m_pImportFile->Size());
00818         else
00819             BeginSlowJob();
00820     }
00821     else
00822         BeginSlowJob(UpTo);
00823 #endif
00824     return TRUE;
00825 }
00826 
00827 
00828 /********************************************************************************************
00829 >   BOOL PaletteFilter::SetPercentage(INT32 GotTo)
00830 
00831     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00832     Created:    1/5/96
00833     Inputs:     GotTo - the current position
00834     Outputs:    -
00835     Returns:    TRUE for success, FALSE if an error occured.
00836     Purpose:    Continues a percentage delay indicator.  Pass -1 to use the current import
00837                 file position as a progress indicator.
00838 ********************************************************************************************/
00839 BOOL PaletteFilter::SetPercentage(INT32 GotTo)
00840 {
00841 #if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX)
00842     if (GotTo == -1)
00843     {
00844         if (m_pImportFile != NULL)
00845             ContinueSlowJob(m_pImportFile->tell());
00846         else
00847             ContinueSlowJob();
00848     }
00849     else
00850         ContinueSlowJob(GotTo);
00851 #endif
00852     return TRUE;
00853 }
00854 
00855 
00856 
00857 /********************************************************************************************
00858 >   void PaletteFilter::ConvertXYZToRGB(const Vector3D& icol, Vector3D& ocol)
00859 
00860     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00861     Created:    13/04/96
00862     Inputs:     icon = The (Xn, Yn, Zn) coordinates of the white colour in CIE XYZ space.
00863     Outputs:    ocol  = RGB colour (0..1)
00864     Returns:    -
00865     Purpose:    To convert colours from CIE XYZ to RGB
00866 ********************************************************************************************/
00867 void PaletteFilter::ConvertXYZToRGB(const Vector3D& icol, Vector3D& ocol)
00868 {
00869     // Convert from HDTV Rec709 to RGB
00870     ocol.x = ( 3.240479*icol.x) + (-1.537150*icol.y) + (-0.498535*icol.z);
00871     ocol.y = (-0.969256*icol.x) + ( 1.875992*icol.y) + ( 0.041556*icol.z);
00872     ocol.z = ( 0.055648*icol.x) + (-0.204043*icol.y) + ( 1.057311*icol.z);
00873     
00874     ClampZeroToOne(ocol.x);
00875     ClampZeroToOne(ocol.y);
00876     ClampZeroToOne(ocol.z);
00877 }
00878 
00879 
00880 
00881 /********************************************************************************************
00882 >   void PaletteFilter::ConvertLABtoXYZ(const Vector3D& white, const Vector3D& icol, Vector3D& ocol)
00883 
00884     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00885     Created:    13/04/96
00886     Inputs:     white = The (Xn, Yn, Zn) coordinates of the white colour in CIE XYZ space.
00887                 icol  = CIE LAB colour
00888     Outputs:    ocol  = CIE XYZ colour
00889     Returns:    -
00890     Purpose:    To convert colours from CIE LUV to CIE XYZ  
00891 ********************************************************************************************/
00892 void PaletteFilter::ConvertLABtoXYZ(const Vector3D& white, const Vector3D& icol, Vector3D& ocol)
00893 {
00894     double d,e;
00895     static double third = 1.0/3.0;
00896 
00897     if (icol.x < 7.9996248) 
00898         ocol.y = icol.x * white.y / 903.3;
00899     else 
00900         ocol.y = pow((double)((icol.x + 16.0) / 116.0), (double)3.0) * white.y;
00901 
00902     e = pow((double)(ocol.y / white.y), third);
00903     d = e + (double)(icol.y / 500);
00904     
00905     ocol.x = pow(d, (double)3.0) * white.x;
00906 
00907     d = e - (double)(icol.z / 200);
00908     
00909     ocol.z = pow(d, (double)3.0) * white.z;
00910 }
00911 
00912 
00913 /********************************************************************************************
00914 >   void PaletteFilter::ConvertCIEtoXYZ(const Vector3D icol, Vector3D& ocol)
00915 
00916     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00917     Created:    13/04/96
00918     Inputs:     icol = (x,y) is the chromaticity value
00919                           YY is the corresponding luminance value
00920     Outputs:    ocol = (X,Y,Z) coordinates in the CIE XYZ space
00921                         
00922     Returns:    -
00923     Purpose:    To convert the given x, y and Y to X, Y and Z in CIE XYZ space
00924 ********************************************************************************************/
00925 void PaletteFilter::ConvertCIEtoXYZ(const Vector3D& icol, Vector3D& ocol)
00926 {
00927     double d = icol.z / icol.y;
00928 
00929     ocol.x = icol.x * d;
00930     ocol.y = icol.z;
00931     ocol.z = (1.0 - icol.x - icol.y) * d;
00932 }
00933 
00934 
00935 /********************************************************************************************
00936 >   void PaletteFilter::ConvertLABToRGB(const Vector3D& icol, Vector3D* ocol)
00937 
00938     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00939     Created:    10/5/96
00940     Inputs:     icol = (x, y, z) - Lab colour (0..100, -128..127, -128..127)
00941     Outputs:    ocol = (x, y, z) - RGB colour (0..1, 0..1, 0..1)
00942     Returns:    -
00943     Purpose:    To convert the given Lab colour to a (near) equivelent RGB colour
00944                 This uses the above conversion functions from Mike.  They are *not* accurate
00945                 but do give a reasonable approximation of the colour.
00946 ********************************************************************************************/
00947 void PaletteFilter::ConvertLABToRGB(const Vector3D& icol, Vector3D* ocol)
00948 {
00949     // First calculate a XYZ white point
00950     Vector3D CIEWhite = Vector3D(0.3127, 0.3290, 1.0 );
00951     Vector3D XYZWhite;
00952     PaletteFilter::ConvertCIEtoXYZ(CIEWhite, XYZWhite);
00953 
00954     Vector3D LabAsXYZ;
00955     PaletteFilter::ConvertLABtoXYZ(XYZWhite, icol, LabAsXYZ);
00956 
00957     // Finally convert XYZ to RGB
00958     Vector3D RGB;
00959     PaletteFilter::ConvertXYZToRGB(LabAsXYZ, RGB);
00960 
00961     ocol->x = ClampZeroToOne( pow(RGB.x, 1.0/2.5) );
00962     ocol->y = ClampZeroToOne( pow(RGB.y, 1.0/2.5) );
00963     ocol->z = ClampZeroToOne( pow(RGB.z, 1.0/2.5) );
00964 }
00965 
00966 
00967 
00968 /********************************************************************************************
00969 
00970 >   BOOL PaletteFilter::AddColourToGallery(PalettePrefix Prefix, String_64 *Name,
00971                                             ColourGeneric *Definition, ColourModel Model,
00972                                             BOOL NewlineAfter = FALSE, IsSpotColour = FALSE)
00973     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00974     Created:    8/8/96
00975     Inputs:     Prefix - Indicates a standard library prefix which should be prepended
00976                             to the name (remembering the prefix ID is much better than
00977                             storing a great long string in every colour)
00978                 Name - the name
00979                 Definition - the colour definition
00980                 Model - The colour model that Definition is given in
00981                 NewlineAfter - TRUE to hint to the colour gallery that it should divide
00982                 the colour items (by starting a new line in the display) in order to
00983                 display them more usefully.
00984 
00985     Returns:    TRUE if it succeeeds
00986 
00987     Purpose:    Sticks the given colour into the colour gallery
00988 
00989 ********************************************************************************************/
00990 
00991 BOOL PaletteFilter::AddColourToGallery(PalettePrefix Prefix, String_64 *Name,
00992                                         ColourGeneric *Definition, ColourModel Model,
00993                                         BOOL NewlineAfter, BOOL IsSpotColour)
00994 {
00995 #if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX)
00996     if (CurrentGalleryGroup == NULL)
00997         return(FALSE);
00998 
00999     // Create a new DocColour for this colour
01000     DocColour NewCol(Model, Definition);
01001     
01002     if (Prefix == PalettePrefix_Pantone || Prefix == PalettePrefix_PantoneSpot)
01003     {
01004         // Set the "PANTONE bodge" flag which rounds the colour components to the nearest half percent.
01005         // This gets around errors introduced by storing the 200 possible half-percent values in a 0-255 BYTE
01006         NewCol.ForceRounding(TRUE);
01007     }
01008 
01009     SGDisplayLibColour *NewItem = new SGDisplayLibColour(&NewCol, Name, Prefix, NewlineAfter, IsSpotColour);
01010     if (NewItem == NULL)
01011         return(FALSE);
01012 
01013     CurrentGalleryGroup->AddItem(NewItem);
01014 #endif
01015     return(TRUE);
01016 }
01017 
01018 
01019 
01020 
01021 
01022 
01023 /********************************************************************************************
01024 >   CorelPaletteFilter::CorelPaletteFilter()
01025 
01026     Author:     Ben_Summers (Xara Group Ltd) <camelotdev@xara.com>
01027     Created:    15 03 95
01028     Inputs:     As for the Filter class
01029     Returns:    As for the Filter class
01030     Purpose:    Constructor
01031     SeeAlso:    Filter
01032 ********************************************************************************************/
01033 CorelPaletteFilter::CorelPaletteFilter()
01034 {
01035     // Set up filter descriptions.
01036     FilterName.Load(_R(IDT_CORELPALETTEFILTER_FILTERNAME));
01037     FilterInfo.Load(_R(IDT_CORELPALETTEFILTER_FILTERINFO));
01038     FilterID = FILTERID_CORELPALETTEFILE;
01039 
01040 #ifndef STANDALONE
01041     Flags.CanImport = TRUE;
01042     Flags.CanExport = FALSE;
01043 #else
01044     Flags.CanImport = FALSE;
01045     Flags.CanExport = FALSE;
01046 #endif
01047 
01048 #ifndef DO_EXPORT
01049     Flags.CanExport = FALSE;
01050 #endif
01051 
01052     m_FileVersion = CPL_FVU;
01053 }
01054 
01055 
01056 /********************************************************************************************
01057 >   BOOL CorelPaletteFilter::Init(void)
01058 
01059     Author:     Ben_Summers (Xara Group Ltd) <camelotdev@xara.com>
01060     Created:    15 03 95
01061     Inputs:     As for the Filter class
01062     Returns:    As for the Filter class
01063     Purpose:    Initialisation
01064     SeeAlso:    Filter
01065 ********************************************************************************************/
01066 BOOL CorelPaletteFilter::Init(void)
01067 {
01068     // Get the OILFilter object
01069     pOILFilter = new CorelPaletteFileOILFilter(this);
01070     if (pOILFilter == NULL)
01071         return FALSE;
01072 
01073     // All ok
01074     return TRUE;
01075 }
01076 
01077 
01078 /********************************************************************************************
01079 >   INT32 CorelPaletteFilter::HowCompatible(PathName& Filename, ADDR  HeaderStart,
01080                                                             UINT32 HeaderSize, UINT32 FileSize)
01081 
01082     Author:     Ben_Summers (Xara Group Ltd) <camelotdev@xara.com>
01083     Created:    15 03 95
01084     Inputs:     As for the Filter class
01085     Returns:    As for the Filter class
01086     Purpose:    Examines a file to see how compatable it is with this filter.
01087     SeeAlso:    Filter
01088 ********************************************************************************************/
01089 INT32 CorelPaletteFilter::HowCompatible(PathName& Filename, ADDR  HeaderStart, UINT32 HeaderSize, UINT32 FileSize)
01090 {
01091 PORTNOTE("byteorder", "TODO: Check byte ordering")
01092     // Check the filetype matches
01093     if (!pOILFilter->DoesExtensionOfPathNameMatch(&Filename))
01094         return 0;
01095 
01096     m_FileVersion = CPL_FVU;
01097     
01098     // is it a .pal file (textualally based)?
01099     INT32 result = 0;
01100     if ((result = HowCompatible4(Filename, HeaderStart, HeaderSize, FileSize)) != 0)
01101         return result;
01102 
01103     // is it a .cpl file (binary)?
01104     if ((result = HowCompatible5(Filename, HeaderStart, HeaderSize, FileSize)) != 0)
01105         return result;
01106 
01107     // it's not a palette file.
01108     return 0;
01109 }
01110 
01111 
01112 /********************************************************************************************
01113 >   INT32 CorelPaletteFilter::HowCompatible4(PathName& Filename, ADDR  HeaderStart,
01114         UINT32 HeaderSize, UINT32 FileSize)
01115 
01116     Author:     Ben_Summers (Xara Group Ltd) <camelotdev@xara.com>
01117     Created:    17 03 95
01118     Inputs:     As for the Filter class
01119     Returns:    As for the Filter class
01120     Purpose:    Examines a file to see how compatable it is with this filter - checks for
01121                 version 3 and 4 .pal files (textual CMYK only)
01122     SeeAlso:    Filter
01123 ********************************************************************************************/
01124 INT32 CorelPaletteFilter::HowCompatible4(PathName& Filename, ADDR  HeaderStart,
01125         UINT32 HeaderSize, UINT32 FileSize)
01126 {
01127     char *start = (char *)HeaderStart;
01128     UINT32 l;
01129 
01130     // is it a .pal file (textualally based?)
01131     if(start[0] == '"')
01132     {
01133         l = 1;
01134         while(start[l] != '"')
01135         {
01136             if(l >= HeaderSize)
01137             {
01138                 return 0;       // if we over run the header size, it's probably not one of ours...
01139             }
01140             if(!camIsprint(start[l]))
01141             {
01142                 return 0;       // a non alphanumerical character
01143             }
01144 
01145             l++;
01146         }
01147 
01148         // find the next non-quoted character
01149         l++;
01150         while(camIsspace(start[l]) && l < HeaderSize)
01151           l++;
01152 
01153         // and the next a digit?
01154         if(isdigit(start[l]))
01155         {
01156             m_FileVersion = CPL_FV4;
01157             return 10;          // well, it's resonably likely to be...
01158         }
01159     }
01160 
01161     // it's not a palette file.
01162     return 0;
01163 }
01164 
01165 
01166 /********************************************************************************************
01167 >   INT32 CorelPaletteFilter::HowCompatible5(PathName& Filename, ADDR  HeaderStart,
01168         UINT32 HeaderSize, UINT32 FileSize)
01169 
01170     Author:     Ben_Summers (Xara Group Ltd) <camelotdev@xara.com>
01171     Created:    17 03 95
01172     Inputs:     As for the Filter class
01173     Returns:    As for the Filter class
01174     Purpose:    Examines a file to see how compatable it is with this filter - checks for
01175                 version 5 .cpl files (binary)
01176     SeeAlso:    Filter
01177 ********************************************************************************************/
01178 INT32 CorelPaletteFilter::HowCompatible5(PathName& Filename, ADDR  HeaderStart,
01179         UINT32 HeaderSize, UINT32 FileSize)
01180 {
01181     // Peter (3/5/96)
01182     // Ben used to check that the first colour was named (so it failed if first colour didn't have a name!)
01183     // Changed to check magic word at start of file (extension already checked)
01184 
01185     if (HeaderStart[0]==0xCC && HeaderStart[1]==0xDC)
01186     {
01187         m_FileVersion = CPL_FV5;
01188         return 10;
01189     }
01190     else
01191         return 0;
01192 }
01193 
01194 
01195 /********************************************************************************************
01196 >   virtual BOOL CorelPaletteFilter::PreImport()
01197 
01198     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com> - from Ben code
01199     Created:    7/5/96
01200     Inputs:     -
01201     Returns:    TRUE/FALSE for success/failure
01202     Purpose:    Called before import of a Corel palette
01203 ********************************************************************************************/
01204 BOOL CorelPaletteFilter::PreImport()
01205 {
01206     // make sure we know which flavour this palette is
01207     if (m_FileVersion!=CPL_FV4 && m_FileVersion!=CPL_FV5)
01208     {
01209         // call HowCompatable
01210         BYTE Buffer[1024];
01211 
01212         INT32 FileSize = m_pImportFile->Size();
01213         INT32 LoadSize = (FileSize<sizeof(Buffer)) ? FileSize : sizeof(Buffer);
01214 
01215         if (m_pImportFile->read(Buffer, LoadSize).bad() || m_pImportFile->seek(0).bad())
01216             return FALSE;
01217 
01218         PathName WibblePath(_R(IDS_K_COPLFILR_INVALID));
01219         
01220         if (HowCompatible(WibblePath, (ADDR)&Buffer, LoadSize, FileSize) != 10)
01221             ERROR1(FALSE, _R(IDE_CORELPALETTEFILTER_NOTCPLORPAL));
01222     }
01223 
01224     return TRUE;
01225 }
01226 
01227 
01228 /********************************************************************************************
01229 >   BOOL CorelPaletteFilter::ImportPalette()
01230 
01231     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com> - from Ben code
01232     Created:    7/5/96
01233     Inputs:     -
01234     Returns:    TRUE/FALSE for success/failure
01235     Purpose:    Called to import a Corel Palette file (.pal or .cpl)
01236 ********************************************************************************************/
01237 BOOL CorelPaletteFilter::ImportPalette()
01238 {
01239     switch(m_FileVersion)
01240     {
01241         case CPL_FV4:
01242             return DoImport4();
01243             break;
01244 
01245         case CPL_FV5:
01246             return DoImport5();
01247             break;
01248 
01249         default:
01250             ERROR2(FALSE, "Unknown FileVersion - HowCompatible gone horrible wrong or not called?");
01251             break;
01252     }
01253 }
01254 
01255 
01256 /********************************************************************************************
01257 >   BOOL CorelPaletteFilter::DoImport4()
01258 
01259     Author:     Ben_Summers (Xara Group Ltd) <camelotdev@xara.com>
01260     Created:    15 03 95
01261     Inputs:     As for the Filter class
01262     Returns:    As for the Filter class
01263     Purpose:    Does the import of a Corel .pal file
01264 ********************************************************************************************/
01265 BOOL CorelPaletteFilter::DoImport4()
01266 {
01267     StartPercentage();
01268 
01269     // init lex handling of the file
01270     if (!m_pImportFile->InitLexer())
01271         return FALSE;
01272 
01273     INT32 count = 0;            // count of colours so far
01274     while (!m_pImportFile->eof())
01275     {
01276         // check file is OK
01277         if (m_pImportFile->bad())
01278             return FALSE;
01279 
01280         // Read a token
01281         m_pImportFile->GetLineToken();
01282         const TCHAR* Line = m_pImportFile->GetTokenBuf();
01283 
01284         // is it a quoted name?
01285         if (Line[0] != '"')                 
01286             continue;
01287 
01288         // extract the string name
01289         String_32 ColName;
01290         INT32 l = 1;
01291         while (Line[l] != '"' && l < CPF_MAX_COLNAME_SIZE)
01292         {
01293             ((TCHAR*)ColName)[l - 1] = Line[l];
01294             l++;
01295         }
01296         ((TCHAR*)ColName)[l - 1] = '\0';                // terminate it nicely
01297 
01298         // find the end of the string name
01299         while(Line[l] != '"' && Line[l] != '\0')
01300           l++;
01301 
01302         l++;    // skip "
01303 
01304         // Read the CMYK colour components
01305         INT32 c, m, y, k;
01306         if (camSscanf(Line + l, "%d %d %d %d", &c, &m, &y, &k) == 4)
01307         {
01308             if (!ProcessCMYKColour(c/100.0, m/100.0, y/100.0, k/100.0, &ColName))
01309                 return FALSE;
01310 
01311             count++;
01312         }
01313 
01314         SetPercentage();
01315     }
01316 
01317     if (count == 0)     // no colour imported... oh dear, something was horrible wrong with that file
01318         ERROR1(FALSE, _R(IDE_CORELPALETTEFILTER_BADPALFILE));
01319 
01320     return TRUE;
01321 }
01322 
01323 
01324 /********************************************************************************************
01325 >   BOOL CorelPaletteFilter::DoImport5()
01326 
01327     Author:     Ben_Summers (Xara Group Ltd) <camelotdev@xara.com>
01328     Created:    15 03 95
01329     Inputs:     As for the Filter class
01330     Returns:    As for the Filter class
01331     Purpose:    Does the import of a Corel .cpl file
01332 ********************************************************************************************/
01333 
01334 #define MAX_PREFIX_LEN      16
01335 #define PREFIX_PANTONE      "PANTONE "
01336 #define PREFIX_FOCOLTONE    "FOCOLTONE "
01337 #define PREFIX_TRUMATCH     "TRUMATCH "
01338 #define PREFIX_UNIFORM      "RGB "
01339 #define FILENAME_FOCOLTONE  "FOCOLTON.CPL"
01340 #define FILENAME_TRUMATCH   "TRUMATCH.CPL"
01341 #define FILENAME_UNIFORM    "RGBSTD.CPL"
01342 #define ENTRIES_PANTONE     3006
01343 #define ENTRIES_FOCOLTONE   762
01344 #define ENTRIES_TRUMATCH    2104
01345 #define ENTRIES_UNIFORM     480
01346 
01347 BOOL CorelPaletteFilter::DoImport5()
01348 {
01349     char ColName[CPF_MAX_COLNAME_SIZE + MAX_PREFIX_LEN];
01350     cpl_header hdr;             // file header
01351     INT32 Len;                  // how many of those bytes we're going to use
01352     INT32 l;
01353     INT32 ColNameOffset;            // where to start adding the colour name - allows prefixes
01354 
01355     // Set the progress indicator, this next bit might take a while.
01356     StartPercentage();
01357 
01358     // init lex handling of the file
01359     if (!m_pImportFile->InitLexer())
01360         return FALSE;
01361 
01362     INT32 count = 0;
01363     // get the header of the file
01364     if (!m_pImportFile->read(&hdr, sizeof(hdr)))
01365         return FALSE;
01366 
01367     UINT32 Entries = hdr.Entries[0] + (hdr.Entries[1] * 256);
01368 
01369     // depending on the filename, fudge a prefix in somewhere.
01370     PathName Path;
01371     String_256 FileName;
01372     TCHAR *fn;
01373 
01374     if (m_pImportFile->IS_KIND_OF(CCDiskFile))
01375     {
01376         Path = ((CCDiskFile*) m_pImportFile)->GetPathName();
01377         FileName = Path.GetFileName();
01378         fn = FileName;
01379     }
01380     else
01381     {
01382         FileName = String_256(_R(IDS_K_COPLFILR_UNKNOWN));
01383         fn = FileName;
01384     }
01385 
01386     PalettePrefix Prefix = PalettePrefix_None;
01387 
01388     if(Entries == ENTRIES_FOCOLTONE && _tcsncicmp(fn, FILENAME_FOCOLTONE, 16) == 0)
01389         Prefix = PalettePrefix_Focoltone;
01390     else if(Entries == ENTRIES_TRUMATCH && _tcsncicmp(fn, FILENAME_TRUMATCH, 16) == 0)
01391         Prefix = PalettePrefix_Trumatch;
01392     else if(Entries == ENTRIES_UNIFORM && _tcsncicmp(fn, FILENAME_UNIFORM, 16) == 0)
01393         Prefix = PalettePrefix_RGB;
01394 
01395     ColNameOffset = 0;
01396     if (!ImportIntoGallery)
01397     {
01398         // When importing into the gallery, we save an awful lot of memory
01399         // by just recording the prefix type rather than the entire prefix string
01400         switch (Prefix)
01401         {
01402             case PalettePrefix_Pantone:
01403                 camStrcpy(ColName, PREFIX_PANTONE);
01404                 ColNameOffset = sizeof(PREFIX_PANTONE) - 1;
01405                 break;
01406 
01407             case PalettePrefix_Focoltone:
01408                 camStrcpy(ColName, PREFIX_FOCOLTONE);
01409                 ColNameOffset = sizeof(PREFIX_FOCOLTONE) - 1;
01410                 break;
01411 
01412             case PalettePrefix_Trumatch:
01413                 camStrcpy(ColName, PREFIX_TRUMATCH);
01414                 ColNameOffset = sizeof(PREFIX_TRUMATCH) - 1;
01415                 break;
01416 
01417             case PalettePrefix_RGB:
01418                 camStrcpy(ColName, PREFIX_UNIFORM);
01419                 ColNameOffset = sizeof(PREFIX_UNIFORM) - 1;
01420                 break;
01421         }
01422     }
01423 
01424     // try and import hdr.Entries colours
01425     for (UINT32 Entry = 0; Entry < Entries; Entry++)
01426     {
01427         // OK, the format of each entry is...
01428         // a cdrfColour
01429         // a byte giving the length of the name
01430         // n bytes of name. No terminator.
01431 
01432         // get the colour definition from the file
01433         cdrfColour ColIn;
01434         if (!m_pImportFile->read(&ColIn, sizeof(ColIn)))
01435             return FALSE;
01436 
01437         // convert it
01438         ImportedNewColour NewCol;
01439         CDRColour::Convert5(&ColIn, &NewCol);   // return code can be ignored
01440 
01441         // get the name
01442         BYTE NameCount;             // count of bytes of name in the file
01443         if (!m_pImportFile->read(&NameCount, sizeof(NameCount)))
01444             return FALSE;
01445 
01446         Len = __min(NameCount, CPF_MAX_COLNAME_SIZE - 1);
01447         if (!m_pImportFile->read(((char *)&ColName) + ColNameOffset, Len))
01448             return FALSE;
01449         ColName[Len + ColNameOffset] = '\0';
01450         if (Len != NameCount)               // need to skip any unread bytes?
01451             m_pImportFile->seek(m_pImportFile->tell() + (NameCount - Len));
01452 
01453         // check the name
01454         for (l = ColNameOffset; l < (Len + ColNameOffset); l++)
01455         {
01456             if (!camIsprint(ColName[l]))
01457                 ColName[l] = '\0';
01458         }
01459 
01460         // create the colour
01461         String_64 ColNameS(ColName);
01462 
01463         if (ImportIntoGallery)
01464         {
01465             BOOL NewlineAfterThisColour = FALSE;
01466 
01467             // In the pantone file, if the colour name ends in a "9" character, it's the last colour
01468             // in a pantone page, so we let it know that it should place a newline after itself.
01469             if (Prefix == PalettePrefix_Pantone)
01470             {
01471                 String_8 LastChar;
01472                 ColNameS.Right((StringBase *)&LastChar, 1);
01473                 if (LastChar == String_16(TEXT("9")))
01474                     NewlineAfterThisColour = TRUE;
01475             }
01476 
01477             AddColourToGallery(Prefix, &ColNameS, &NewCol.Colour, NewCol.Model,
01478                                 NewlineAfterThisColour);
01479         }
01480         else
01481         {
01482             if (!m_pNewColours->AddColour(&ColNameS, &NewCol))
01483                 return FALSE;
01484         }
01485 
01486         count++;
01487         SetPercentage();
01488     }
01489 
01490     if (count == 0)     // no colour imported... oh dear, something was horrible wrong with that file
01491         ERROR1(FALSE, _R(IDE_CORELPALETTEFILTER_BADCPLFILE));
01492 
01493     return TRUE;
01494 }
01495 
01496 
01497 /********************************************************************************************
01498 >   BOOL CorelPaletteFilter::PostImport(void)
01499 
01500     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com> - from Ben code
01501     Created:    7/5/96
01502     Inputs:     -
01503     Returns:    TRUE/FALSE for success/failure
01504     Purpose:    Called after import of a Corel palette file
01505 ********************************************************************************************/
01506 BOOL CorelPaletteFilter::PostImport(void)
01507 {
01508     m_FileVersion = CPL_FVU;
01509 
01510     return TRUE;
01511 }
01512 
01513 
01514 
01515 
01516 
01517 /********************************************************************************************
01518 >   MSPaletteFilter::MSPaletteFilter()
01519 
01520     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
01521     Created:    30/4/96
01522     Inputs:     -
01523     Returns:    -
01524     Purpose:    Constructor for a Microsoft Windows palette filter
01525     SeeAlso:    PaletteFilter
01526 ********************************************************************************************/
01527 MSPaletteFilter::MSPaletteFilter()
01528 {
01529     // Set up filter descriptions.
01530     FilterName.Load(_R(IDT_FILTERNAME_WINDOWSPALETTE));
01531     FilterInfo.Load(_R(IDT_FILTERINFO_WINDOWSPALETTE));
01532     FilterID = FILTERID_MSPALETTE;
01533 
01534 #ifndef STANDALONE
01535     Flags.CanImport = TRUE;
01536     Flags.CanExport = FALSE;
01537 #else
01538     Flags.CanImport = FALSE;
01539     Flags.CanExport = FALSE;
01540 #endif
01541 
01542 #ifndef DO_EXPORT
01543     Flags.CanExport = FALSE;
01544 #endif
01545 }
01546 
01547 
01548 /********************************************************************************************
01549 >   MSPaletteFilter::~MSPaletteFilter()
01550 
01551     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
01552     Created:    30/4/96
01553     Inputs:     -
01554     Returns:    -
01555     Purpose:    Destructor for a Microsoft Windows palette filter
01556     SeeAlso:    PaletteFilter
01557 ********************************************************************************************/
01558 MSPaletteFilter::~MSPaletteFilter()
01559 {
01560 }
01561 
01562 
01563 
01564 /********************************************************************************************
01565 >   virtual BOOL MSPaletteFilter::Init()
01566 
01567     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
01568     Created:    30/4/96
01569     Inputs:     -
01570     Returns:    TRUE for successful init, FALSE if error occured
01571     Purpose:    Initialise the Windows palette filter, attaches OIL filter
01572     SeeAlso:    Filter::Init
01573 ********************************************************************************************/
01574 BOOL MSPaletteFilter::Init()
01575 {
01576     // Get the OILFilter object
01577     pOILFilter = new MSPaletteOILFilter(this);
01578     
01579     return (pOILFilter != NULL);
01580 }
01581 
01582 
01583 /********************************************************************************************
01584 >   INT32 MSPaletteFilter::HowCompatible(PathName& Filename, ADDR HeaderStart, UINT32 HeaderSize, UINT32 FileSize)
01585 
01586     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
01587     Created:    30/4/96
01588     Inputs:     Filename - the file being loads (allows checks on extensions).
01589                 HeaderStart - address of some bytes from the start of the file
01590                 HeaderSize - the number of bytes at HeaderStart
01591                 FileSize - the total length of the file
01592     Returns:    Between 10 (Mine!) and 0 (Not Mine!) inclusive
01593     Purpose:    Examines a file to see how compatable it is with this filter.
01594     SeeAlso:    Filter::HowCompatible
01595 ********************************************************************************************/
01596 INT32 MSPaletteFilter::HowCompatible(PathName& Filename, ADDR HeaderStart, UINT32 HeaderSize, UINT32 FileSize)
01597 {
01598 PORTNOTE("byteorder", "TODO: Check byte ordering")
01599     // MS palette files have a well defined format.  Bytes 0-3 = "RIFF".  Bytes 8-15 = "PAL data"
01600 
01601     // Check we have enough of the file header to look at
01602     if (HeaderSize < 16)
01603     {
01604         TRACE( _T("MSPalette filter needs 16+ bytes in HowCompatible\n"));
01605         return 0;
01606     }
01607 
01608     if (    HeaderStart[0] == 0x52 &&       // R
01609             HeaderStart[1] == 0x49 &&       // I
01610             HeaderStart[2] == 0x46 &&       // F
01611             HeaderStart[3] == 0x46 &&       // F
01612             HeaderStart[8] == 0x50 &&       // P
01613             HeaderStart[9] == 0x41 &&       // A
01614             HeaderStart[10] == 0x4C &&      // L
01615             HeaderStart[11] == 0x20 &&      // <Space>
01616             HeaderStart[12] == 0x64 &&      // d
01617             HeaderStart[13] == 0x61 &&      // a
01618             HeaderStart[14] == 0x74 &&      // t
01619             HeaderStart[15] == 0x61 )       // a
01620         return 10;
01621     else
01622         return 0;
01623 }
01624 
01625 
01626 /********************************************************************************************
01627 >   BOOL MSPaletteFilter::PreImport()
01628 
01629     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
01630     Created:    1/5/96
01631     Inputs:     -
01632     Outputs:    Sets import member vars
01633     Returns:    TRUE/FALSE for success/error
01634     Purpose:    Reads the MS palette file header to see how many colours are in the file
01635 ********************************************************************************************/
01636 BOOL MSPaletteFilter::PreImport()
01637 {
01638     ERROR2IF( m_pImportFile==NULL, FALSE, "NULL pointer");
01639 
01640     // Read info out of the header.
01641     BYTE HeaderBuffer[24];
01642     m_pImportFile->read(HeaderBuffer, 24);
01643 
01644     if (m_pImportFile->good())
01645     {
01646         m_NumToImport = *((WORD*)(HeaderBuffer+22));
01647         return TRUE;
01648     }
01649     else
01650     {
01651         m_NumToImport = 0;
01652         return FALSE;
01653     }
01654 }
01655 
01656 
01657 /********************************************************************************************
01658 >   BOOL MSPaletteFilter::ImportPalette()
01659 
01660     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
01661     Created:    1/5/96
01662     Inputs:     -
01663     Outputs:    -
01664     Returns:    TRUE/FALSE for success/error
01665     Purpose:    Imports colours from a MS palette file.
01666 ********************************************************************************************/
01667 BOOL MSPaletteFilter::ImportPalette()
01668 {
01669     UINT32 ColoursToRead = m_NumToImport;
01670     BOOL ok = StartPercentage(m_NumToImport);
01671 
01672     while ( ok && (ColoursToRead > 0) && m_pImportFile->good() )
01673     {
01674         // Read the RGB values for this colour from the file
01675         BYTE ColourDef[4];
01676         m_pImportFile->read(ColourDef, 4);
01677 
01678         // Add the colour to the imported colours list
01679         if (m_pImportFile->good())
01680             ok = ProcessRGBColour(ColourDef[0]/(double)0xff, ColourDef[1]/(double)0xff, ColourDef[2]/(double)0xff);
01681 
01682         SetPercentage(m_NumToImport-ColoursToRead);
01683         ColoursToRead--;
01684     }
01685 
01686     return ok && m_pImportFile->good();
01687 }
01688 
01689 
01690 /********************************************************************************************
01691 >   BOOL MSPaletteFilter::PostImport()
01692 
01693     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
01694     Created:    1/5/96
01695     Inputs:     -
01696     Outputs:    -
01697     Returns:    TRUE/FALSE for success/error
01698     Purpose:    Called to allow post import cleanup (if required) for this filter
01699 ********************************************************************************************/
01700 BOOL MSPaletteFilter::PostImport()
01701 {
01702     // Nothing to do, no cleanup required.
01703     return TRUE;
01704 }
01705 
01706 
01707 
01708 
01709 
01710 
01711 
01712 /********************************************************************************************
01713 >   AdobeColourTableFilter::AdobeColourTableFilter()
01714 
01715     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
01716     Created:    1/5/96
01717     Inputs:     -
01718     Returns:    -
01719     Purpose:    Constructor for a Adobe Colour Table palette filter
01720     SeeAlso:    PaletteFilter
01721 ********************************************************************************************/
01722 AdobeColourTableFilter::AdobeColourTableFilter()
01723 {
01724     // Set up filter descriptions.
01725     FilterName.Load(_R(IDT_FILTERNAME_ADOBECOLOURTABLE));
01726     FilterInfo.Load(_R(IDT_FILTERINFO_ADOBECOLOURTABLE));
01727     FilterID = FILTERID_ADOBECOLOURTABLE;
01728 
01729 #ifndef STANDALONE
01730     Flags.CanImport = TRUE;
01731     Flags.CanExport = FALSE;
01732 #else
01733     Flags.CanImport = FALSE;
01734     Flags.CanExport = FALSE;
01735 #endif
01736 
01737 #ifndef DO_EXPORT
01738     Flags.CanExport = FALSE;
01739 #endif
01740 }
01741 
01742 
01743 /********************************************************************************************
01744 >   AdobeColourTableFilter::~AdobeColourTableFilter()
01745 
01746     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
01747     Created:    1/5/96
01748     Inputs:     -
01749     Returns:    -
01750     Purpose:    Destructor for a Adobe Colour Table palette filter
01751     SeeAlso:    PaletteFilter
01752 ********************************************************************************************/
01753 AdobeColourTableFilter::~AdobeColourTableFilter()
01754 {
01755 }
01756 
01757 
01758 
01759 /********************************************************************************************
01760 >   virtual BOOL AdobeColourTableFilter::Init()
01761 
01762     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
01763     Created:    1/5/96
01764     Inputs:     -
01765     Returns:    TRUE for successful init, FALSE if error occured
01766     Purpose:    Initialise the filter, attaches OIL filter
01767     SeeAlso:    Filter::Init
01768 ********************************************************************************************/
01769 BOOL AdobeColourTableFilter::Init()
01770 {
01771     // Get the OILFilter object
01772     pOILFilter = new AdobeColourTableOILFilter(this);
01773     
01774     return (pOILFilter != NULL);
01775 }
01776 
01777 
01778 /********************************************************************************************
01779 >   INT32 AdobeColourTableFilter::HowCompatible(PathName& Filename, ADDR HeaderStart, UINT32 HeaderSize, UINT32 FileSize)
01780 
01781     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
01782     Created:    1/5/96
01783     Inputs:     Filename - the file being loads (allows checks on extensions).
01784                 HeaderStart - address of some bytes from the start of the file
01785                 HeaderSize - the number of bytes at HeaderStart
01786                 FileSize - the total length of the file
01787     Returns:    Between 10 (Mine!) and 0 (Not Mine!) inclusive
01788     Purpose:    Examines a file to see how compatable it is with this filter.
01789     SeeAlso:    Filter::HowCompatible
01790 ********************************************************************************************/
01791 INT32 AdobeColourTableFilter::HowCompatible(PathName& Filename, ADDR HeaderStart, UINT32 HeaderSize, UINT32 FileSize)
01792 {
01793 PORTNOTE("byteorder", "TODO: Check byte ordering")
01794     // Adobe colour tables are just raw data.  We have to go on file extension
01795     ERROR2IF(pOILFilter==NULL, 0, "No oil filter present");
01796     return ((AdobeColourTableOILFilter*)pOILFilter)->HowCompatible(Filename);
01797 }
01798 
01799 
01800 /********************************************************************************************
01801 >   BOOL AdobeColourTableFilter::PreImport()
01802 
01803     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
01804     Created:    1/5/96
01805     Inputs:     -
01806     Outputs:    Sets import member vars
01807     Returns:    TRUE/FALSE for success/error
01808     Purpose:    Reads the MS palette file header to see how many colours are in the file
01809 ********************************************************************************************/
01810 BOOL AdobeColourTableFilter::PreImport()
01811 {
01812     // No setup required
01813     return TRUE;
01814 }
01815 
01816 
01817 /********************************************************************************************
01818 >   BOOL AdobeColourTableFilter::ImportPalette()
01819 
01820     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
01821     Created:    1/5/96
01822     Inputs:     -
01823     Outputs:    -
01824     Returns:    TRUE/FALSE for success/error
01825     Purpose:    Imports colours from an Abode Colour Table
01826 ********************************************************************************************/
01827 BOOL AdobeColourTableFilter::ImportPalette()
01828 {
01829     ERROR2IF(m_pImportFile==NULL, FALSE, "NULL pointer");
01830 
01831     BOOL ok = StartPercentage();
01832 
01833     while ( ok && m_pImportFile->good() && (m_pImportFile->tell()<m_pImportFile->Size()) )
01834     {
01835         // Read the RGB values for this colour from the file
01836         BYTE ColourDef[3];
01837         m_pImportFile->read(ColourDef, 3);
01838 
01839         // Add the colour to the imported colours list
01840         if (m_pImportFile->good())
01841             ok = ProcessRGBColour(ColourDef[0]/(double)0xff, ColourDef[1]/(double)0xff, ColourDef[2]/(double)0xff);
01842 
01843         SetPercentage();
01844     }
01845 
01846     return ok && m_pImportFile->good();
01847 }
01848 
01849 
01850 /********************************************************************************************
01851 >   BOOL AdobeColourTableFilter::PostImport()
01852 
01853     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
01854     Created:    1/5/96
01855     Inputs:     -
01856     Outputs:    -
01857     Returns:    TRUE/FALSE for success/error
01858     Purpose:    Called to allow post import cleanup (if required) for this filter
01859 ********************************************************************************************/
01860 BOOL AdobeColourTableFilter::PostImport()
01861 {
01862     // Nothing to do, no cleanup required.
01863     return TRUE;
01864 }
01865 
01866 
01867 
01868 
01869 
01870 
01871 
01872 /********************************************************************************************
01873 >   AdobeColourSwatchFilter::AdobeColourSwatchFilter()
01874 
01875     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
01876     Created:    2/5/96
01877     Inputs:     -
01878     Returns:    -
01879     Purpose:    Constructor for a Adobe Colour Swatch palette filter
01880     SeeAlso:    PaletteFilter
01881 ********************************************************************************************/
01882 AdobeColourSwatchFilter::AdobeColourSwatchFilter()
01883 {
01884     // Set up filter descriptions.
01885     FilterName.Load(_R(IDT_FILTERNAME_ADOBECOLOURSWATCH));
01886     FilterInfo.Load(_R(IDT_FILTERINFO_ADOBECOLOURSWATCH));
01887     FilterID = FILTERID_ADOBECOLOURSWATCH;
01888 
01889 #ifndef STANDALONE
01890     Flags.CanImport = TRUE;
01891     Flags.CanExport = FALSE;
01892 #else
01893     Flags.CanImport = FALSE;
01894     Flags.CanExport = FALSE;
01895 #endif
01896 
01897 #ifndef DO_EXPORT
01898     Flags.CanExport = FALSE;
01899 #endif
01900 }
01901 
01902 
01903 /********************************************************************************************
01904 >   AdobeColourSwatchFilter::~AdobeColourSwatchFilter()
01905 
01906     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
01907     Created:    2/5/96
01908     Inputs:     -
01909     Returns:    -
01910     Purpose:    Destructor for a Adobe Colour Swatch palette filter
01911     SeeAlso:    PaletteFilter
01912 ********************************************************************************************/
01913 AdobeColourSwatchFilter::~AdobeColourSwatchFilter()
01914 {
01915 }
01916 
01917 
01918 
01919 /********************************************************************************************
01920 >   virtual BOOL AdobeColourSwatchFilter::Init()
01921 
01922     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
01923     Created:    2/5/96
01924     Inputs:     -
01925     Returns:    TRUE for successful init, FALSE if error occured
01926     Purpose:    Initialise the filter, attaches OIL filter
01927     SeeAlso:    Filter::Init
01928 ********************************************************************************************/
01929 BOOL AdobeColourSwatchFilter::Init()
01930 {
01931     // Get the OILFilter object
01932     pOILFilter = new AdobeColourSwatchOILFilter(this);
01933     
01934     return (pOILFilter != NULL);
01935 }
01936 
01937 
01938 /********************************************************************************************
01939 >   INT32 AdobeColourSwatchFilter::HowCompatible(PathName& Filename, ADDR HeaderStart, UINT32 HeaderSize, UINT32 FileSize)
01940 
01941     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
01942     Created:    2/5/96
01943     Inputs:     Filename - the file being loads (allows checks on extensions).
01944                 HeaderStart - address of some bytes from the start of the file
01945                 HeaderSize - the number of bytes at HeaderStart
01946                 FileSize - the total length of the file
01947     Returns:    Between 10 (Mine!) and 0 (Not Mine!) inclusive
01948     Purpose:    Examines a file to see how compatable it is with this filter.
01949     SeeAlso:    Filter::HowCompatible
01950 ********************************************************************************************/
01951 INT32 AdobeColourSwatchFilter::HowCompatible(PathName& Filename, ADDR HeaderStart, UINT32 HeaderSize, UINT32 FileSize)
01952 {
01953 PORTNOTE("byteorder", "TODO: Check byte ordering")
01954     // Adobe colour swatchs appear to be just raw data.  We have to go on file extension
01955     ERROR2IF(pOILFilter==NULL, 0, "No oil filter present");
01956     return ((AdobeColourSwatchOILFilter*)pOILFilter)->HowCompatible(Filename);
01957 }
01958 
01959 
01960 /********************************************************************************************
01961 >   BOOL AdobeColourSwatchFilter::PreImport()
01962 
01963     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
01964     Created:    2/5/96
01965     Inputs:     -
01966     Outputs:    Sets import member vars
01967     Returns:    TRUE/FALSE for success/error
01968     Purpose:    Reads the MS palette file header to see how many colours are in the file
01969 ********************************************************************************************/
01970 BOOL AdobeColourSwatchFilter::PreImport()
01971 {
01972     ERROR2IF( m_pImportFile==NULL, FALSE, "NULL pointer");
01973     ERROR3IF( sizeof(WORD)!=2, "How come a WORD is not two bytes?");
01974 
01975     m_MetUnknownModel = FALSE;
01976 
01977     // Read info out of the header.
01978     WORD HeaderBuffer[2];
01979     m_pImportFile->read(HeaderBuffer, 4);
01980 
01981     if (m_pImportFile->good())
01982     {
01983         m_NumToImport = ReverseWord(HeaderBuffer[1]);
01984         return TRUE;
01985     }
01986     else
01987     {
01988         m_NumToImport = 0;
01989         return FALSE;
01990     }
01991 }
01992 
01993 
01994 /********************************************************************************************
01995 >   BOOL AdobeColourSwatchFilter::ImportPalette()
01996 
01997     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
01998     Created:    2/5/96
01999     Inputs:     -
02000     Outputs:    -
02001     Returns:    TRUE/FALSE for success/error
02002     Purpose:    Imports colours from an Adobe colour swatch
02003 ********************************************************************************************/
02004 
02005 BOOL AdobeColourSwatchFilter::ImportPalette()
02006 {
02007     ERROR2IF(m_pImportFile==NULL, FALSE, "NULL pointer");
02008 
02009     BOOL ok = StartPercentage(m_NumToImport);
02010     UINT32 StillToRead = m_NumToImport;
02011 
02012     while ( ok && m_pImportFile->good() && StillToRead>0 )
02013     {
02014         // Read the values for this colour from the file
02015         WORD ColourDef[5];
02016         m_pImportFile->read(ColourDef, 10);
02017 
02018         // Add the colour to the imported colours list
02019         if (m_pImportFile->good())
02020         {
02021             switch (ReverseWord(ColourDef[0]))
02022             {
02023                 case 0 :    ok = ProcessRGBColour(ReverseWord(ColourDef[1])/(double)0xFFFF,
02024                                                     ReverseWord(ColourDef[2])/(double)0xFFFF,
02025                                                     ReverseWord(ColourDef[3])/(double)0xFFFF );
02026                             break;
02027 
02028                 case 1 :    ok = ProcessHSVColour(ReverseWord(ColourDef[1])/(double)0xFFFF,
02029                                                     ReverseWord(ColourDef[2])/(double)0xFFFF,
02030                                                     ReverseWord(ColourDef[3])/(double)0xFFFF );
02031                             break;
02032 
02033                 case 2 :    ok = ProcessCMYKColour((0xFFFF-ReverseWord(ColourDef[1]))/(double)0xFFFF,
02034                                                     (0xFFFF-ReverseWord(ColourDef[2]))/(double)0xFFFF,
02035                                                     (0xFFFF-ReverseWord(ColourDef[3]))/(double)0xFFFF,
02036                                                     (0xFFFF-ReverseWord(ColourDef[4]))/(double)0xFFFF );
02037                             break;
02038 
02039                 case 7 :    ok = ProcessLabColour(ReverseWord(ColourDef[1])/100.0,
02040                                                     (signed short)(ReverseWord(ColourDef[2]))/100.0,
02041                                                     (signed short)(ReverseWord(ColourDef[3]))/100.0 );
02042                             break;
02043 
02044                 case 8 :    ok = ProcessGreyColour((0x2710-ReverseWord(ColourDef[1]))/10000.0);
02045                             break;
02046 
02047                 default :   if (!m_MetUnknownModel)
02048                             {
02049                                 InformWarning(_R(IDE_PALETTEIMPORT_ACOUNKNOWN));
02050                                 m_MetUnknownModel = TRUE;
02051                             }
02052                             break;
02053             }
02054         }
02055 
02056         SetPercentage(m_NumToImport-StillToRead);
02057         StillToRead--;
02058     }
02059 
02060     return ok && m_pImportFile->good();
02061 }
02062 
02063 
02064 /********************************************************************************************
02065 >   BOOL AdobeColourSwatchFilter::PostImport()
02066 
02067     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
02068     Created:    2/5/96
02069     Inputs:     -
02070     Outputs:    -
02071     Returns:    TRUE/FALSE for success/error
02072     Purpose:    Called to allow post import cleanup (if required) for this filter
02073 ********************************************************************************************/
02074 BOOL AdobeColourSwatchFilter::PostImport()
02075 {
02076     // Nothing to do, no cleanup required.
02077     return TRUE;
02078 }
02079 
02080 
02081 /********************************************************************************************
02082 >   WORD AdobeColourSwatchFilter::ReverseWord(WORD Orig)
02083 
02084     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
02085     Created:    3/5/96
02086     Inputs:     Orig - a word with the 'wrong' byte order
02087     Outputs:    -
02088     Returns:    A word with the two bytes switched
02089     Purpose:    WORDs in swatch files have the wrong byte order.  This function swaps the bytes.
02090 ********************************************************************************************/
02091 WORD AdobeColourSwatchFilter::ReverseWord(WORD Orig)
02092 {
02093     BYTE NewLow = (Orig & 0xFF00) >> 8;
02094     Orig = Orig << 8;
02095     
02096     return Orig | NewLow;
02097 }
02098 
02099 
02100 
02101 
02102 
02103 /********************************************************************************************
02104 >   PaintShopProPaletteFilter::PaintShopProPaletteFilter()
02105 
02106     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
02107     Created:    9/5/96
02108     Inputs:     -
02109     Returns:    -
02110     Purpose:    Constructor for a PaintShopPro palette filter
02111     SeeAlso:    PaletteFilter
02112 ********************************************************************************************/
02113 PaintShopProPaletteFilter::PaintShopProPaletteFilter()
02114 {
02115     // Set up filter descriptions.
02116     FilterName.Load(_R(IDT_FILTERNAME_PSPPALETTE));
02117     FilterInfo.Load(_R(IDT_FILTERINFO_PSPPALETTE));
02118     FilterID = FILTERID_PSPPALETTE;
02119 
02120 #ifndef STANDALONE
02121     Flags.CanImport = TRUE;
02122     Flags.CanExport = FALSE;
02123 #else
02124     Flags.CanImport = FALSE;
02125     Flags.CanExport = FALSE;
02126 #endif
02127 
02128 #ifndef DO_EXPORT
02129     Flags.CanExport = FALSE;
02130 #endif
02131 }
02132 
02133 
02134 /********************************************************************************************
02135 >   PaintShopProPaletteFilter::~PaintShopProPaletteFilter()
02136 
02137     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
02138     Created:    9/5/96
02139     Inputs:     -
02140     Returns:    -
02141     Purpose:    Destructor for a PaintShopPro palette filter
02142     SeeAlso:    PaletteFilter
02143 ********************************************************************************************/
02144 PaintShopProPaletteFilter::~PaintShopProPaletteFilter()
02145 {
02146 }
02147 
02148 
02149 
02150 /********************************************************************************************
02151 >   virtual BOOL PaintShopProPaletteFilter::Init()
02152 
02153     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
02154     Created:    9/5/96
02155     Inputs:     -
02156     Returns:    TRUE for successful init, FALSE if error occured
02157     Purpose:    Initialise the filter, attaches OIL filter
02158     SeeAlso:    Filter::Init
02159 ********************************************************************************************/
02160 BOOL PaintShopProPaletteFilter::Init()
02161 {
02162     // Get the OILFilter object
02163     pOILFilter = new PSPPaletteOILFilter(this);
02164     
02165     return (pOILFilter != NULL);
02166 }
02167 
02168 
02169 /********************************************************************************************
02170 >   INT32 PaintShopProPaletteFilter::HowCompatible(PathName& Filename, ADDR HeaderStart, UINT32 HeaderSize, UINT32 FileSize)
02171 
02172     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
02173     Created:    9/5/96
02174     Inputs:     Filename - the file being loads (allows checks on extensions).
02175                 HeaderStart - address of some bytes from the start of the file
02176                 HeaderSize - the number of bytes at HeaderStart
02177                 FileSize - the total length of the file
02178     Returns:    Between 10 (Mine!) and 0 (Not Mine!) inclusive
02179     Purpose:    Examines a file to see how compatable it is with this filter.
02180     SeeAlso:    Filter::HowCompatible
02181 ********************************************************************************************/
02182 INT32 PaintShopProPaletteFilter::HowCompatible(PathName& Filename, ADDR HeaderStart, UINT32 HeaderSize, UINT32 FileSize)
02183 {
02184 PORTNOTE("byteorder", "TODO: Check byte ordering")
02185     // Check we have enough of the file header to look at
02186     if (HeaderSize < 8)
02187     {
02188         TRACE( _T("PaintShopProPaletteFilter filter needs 8+ bytes in HowCompatible\n"));
02189         return 0;
02190     }
02191 
02192     if (    HeaderStart[0] == 0x4A &&       // J
02193             HeaderStart[1] == 0x41 &&       // A
02194             HeaderStart[2] == 0x53 &&       // S
02195             HeaderStart[3] == 0x43 &&       // C
02196             HeaderStart[4] == 0x2D &&       // -
02197             HeaderStart[5] == 0x50 &&       // P
02198             HeaderStart[6] == 0x41 &&       // A
02199             HeaderStart[7] == 0x4C )        // L
02200         return 10;
02201     else
02202         return 0;
02203 }
02204 
02205 
02206 /********************************************************************************************
02207 >   BOOL PaintShopProPaletteFilter::PreImport()
02208 
02209     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
02210     Created:    9/5/96
02211     Inputs:     -
02212     Outputs:    Sets import member vars
02213     Returns:    TRUE/FALSE for success/error
02214     Purpose:    Reads the PSP palette file header to see how many colours are in the file
02215 ********************************************************************************************/
02216 BOOL PaintShopProPaletteFilter::PreImport()
02217 {
02218     ERROR2IF( m_pImportFile==NULL, FALSE, "NULL pointer");
02219 
02220     if (!m_pImportFile->InitLexer())
02221         return FALSE;
02222 
02223     // Read the two header lines
02224     INT32 ReadLines = 0;
02225     while (ReadLines<2 && m_pImportFile->good())
02226     {
02227         m_pImportFile->GetLineToken();
02228         LexTokenType TokType = m_pImportFile->GetTokenType();
02229         if (TokType == TOKEN_LINE)
02230             ReadLines++;
02231     }
02232 
02233     // Read the number of colours line
02234     if (m_pImportFile->good())
02235         m_pImportFile->GetLineToken();
02236     if (m_pImportFile->good())
02237     {
02238         const TCHAR* Line = m_pImportFile->GetTokenBuf();
02239         // BODGE - does this work in UNICODE builds?
02240         camSscanf(Line, "%d", &m_NumToImport);
02241     }
02242 
02243     return m_pImportFile->good();
02244 }
02245 
02246 
02247 /********************************************************************************************
02248 >   BOOL PaintShopProPaletteFilter::ImportPalette()
02249 
02250     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
02251     Created:    9/5/96
02252     Inputs:     -
02253     Outputs:    -
02254     Returns:    TRUE/FALSE for success/error
02255     Purpose:    Imports colours from an Adobe colour swatch
02256 ********************************************************************************************/
02257 BOOL PaintShopProPaletteFilter::ImportPalette()
02258 {
02259     ERROR2IF(m_pImportFile==NULL, FALSE, "NULL pointer");
02260 
02261     BOOL ok = StartPercentage(m_NumToImport);
02262     UINT32 StillToRead = m_NumToImport;
02263 
02264     while ( ok && StillToRead>0 )
02265     {
02266         // Read the colour definition line
02267         ok = m_pImportFile->GetLineToken();
02268 
02269         // Add the colour to the imported colours list
02270         const TCHAR* Line = m_pImportFile->GetTokenBuf();
02271         UINT32 Red = 0;
02272         UINT32 Green = 0;
02273         UINT32 Blue = 0;
02274         INT32 result = camSscanf(Line, "%d %d %d", &Red, &Green, &Blue);
02275 
02276         if (result != 0)
02277             ok = ProcessRGBColour(Red/(double)0xFF, Green/(double)0xFF, Blue/(double)0xFF);
02278 
02279         SetPercentage(m_NumToImport-StillToRead);
02280         StillToRead--;
02281     }
02282 
02283     return ok;
02284 }
02285 
02286 
02287 
02288 /********************************************************************************************
02289 >   BOOL PaintShopProPaletteFilter::PostImport()
02290 
02291     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
02292     Created:    9/5/96
02293     Inputs:     -
02294     Outputs:    -
02295     Returns:    TRUE/FALSE for success/error
02296     Purpose:    Called to allow post import cleanup (if required) for this filter
02297 ********************************************************************************************/
02298 BOOL PaintShopProPaletteFilter::PostImport()
02299 {
02300     ERROR2IF( m_pImportFile==NULL, FALSE, "NULL pointer");
02301 
02302     m_pImportFile->DeinitLexer();
02303 
02304     return TRUE;
02305 }
02306 
02307 
02308 
02309 
02310 #if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX)
02311 
02312 
02313 
02314 /********************************************************************************************
02315 >   JCWColourFilter::JCWColourFilter()
02316 
02317     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
02318     Created:    30/8/96
02319     Inputs:     -
02320     Returns:    -
02321     Purpose:    Constructor
02322 
02323                 The JCWPalette filter loads my own personal file format, which I invented
02324                 to store PANTONE libraries in a reasonably sensible form.
02325 
02326     SeeAlso:    PaletteFilter
02327 ********************************************************************************************/
02328 JCWColourFilter::JCWColourFilter()
02329 {
02330     // Set up filter descriptions.
02331     FilterName.Load(_R(IDT_FILTERNAME_JCWPALETTE));
02332     FilterInfo.Load(_R(IDT_FILTERINFO_JCWPALETTE));
02333     FilterID = FILTERID_JCWPALETTE;
02334 
02335 #ifndef STANDALONE
02336     Flags.CanImport = TRUE;
02337 #else
02338     Flags.CanImport = FALSE;
02339 #endif
02340 
02341     // Never export, 'cos JCW is the only dude who knows the format! ;-)
02342     Flags.CanExport = FALSE;
02343 
02344     // And never show this filter in the UI
02345     Flags.ShowFilter = FALSE;
02346 
02347     m_ColoursAreSpots = FALSE;
02348     m_NumToImport = 0;
02349 }
02350 
02351 
02352 /********************************************************************************************
02353 >   JCWColourFilter::~JCWColourFilter()
02354 
02355     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
02356     Created:    30/8/96
02357     Inputs:     -
02358     Returns:    -
02359     Purpose:    Destructor
02360     SeeAlso:    PaletteFilter
02361 ********************************************************************************************/
02362 JCWColourFilter::~JCWColourFilter()
02363 {
02364 }
02365 
02366 
02367 
02368 /********************************************************************************************
02369 >   virtual BOOL JCWColourFilter::Init()
02370 
02371     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
02372     Created:    30/8/96
02373     Inputs:     -
02374     Returns:    TRUE for successful init, FALSE if error occured
02375     Purpose:    Initialise the filter, attaches OIL filter
02376     SeeAlso:    Filter::Init
02377 ********************************************************************************************/
02378 BOOL JCWColourFilter::Init()
02379 {
02380     // Get the OILFilter object
02381     pOILFilter = new JCWColourOILFilter(this);
02382     
02383     return (pOILFilter != NULL);
02384 }
02385 
02386 
02387 /********************************************************************************************
02388 >   INT32 JCWColourFilter::HowCompatible(PathName& Filename, ADDR HeaderStart, UINT32 HeaderSize, UINT32 FileSize)
02389 
02390     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
02391     Created:    30/8/96
02392     Inputs:     Filename - the file being loads (allows checks on extensions).
02393                 HeaderStart - address of some bytes from the start of the file
02394                 HeaderSize - the number of bytes at HeaderStart
02395                 FileSize - the total length of the file
02396     Returns:    Between 10 (Mine!) and 0 (Not Mine!) inclusive
02397     Purpose:    Examines a file to see how compatable it is with this filter.
02398     SeeAlso:    Filter::HowCompatible
02399 ********************************************************************************************/
02400 INT32 JCWColourFilter::HowCompatible(PathName& Filename, ADDR HeaderStart, UINT32 HeaderSize, UINT32 FileSize)
02401 {
02402 PORTNOTE("byteorder", "TODO: Check byte ordering")
02403     // Adobe colour swatchs appear to be just raw data.  We have to go on file extension
02404     ERROR2IF(pOILFilter==NULL, 0, "No oil filter present");
02405 
02406     if (HeaderSize < 4)
02407     {
02408         TRACE( _T("JCWColourFilter needs 4 or more bytes in HowCompatible\n"));
02409         return 0;
02410     }
02411 
02412     if (((JCWColourOILFilter*)pOILFilter)->HowCompatible(Filename))
02413     {
02414         BYTE *Hdr = (BYTE *)HeaderStart;
02415         if (Hdr[0] == 'J' && Hdr[1] == 'C' && Hdr[2] == 'W' && Hdr[3] > 0)
02416             return(9);
02417     }
02418 
02419     return(0);
02420 }
02421 
02422 
02423 /********************************************************************************************
02424 >   BOOL JCWColourFilter::PreImport()
02425 
02426     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
02427     Created:    30/8/96
02428     Inputs:     -
02429     Outputs:    Sets import member vars
02430     Returns:    TRUE/FALSE for success/error
02431     Purpose:    Reads the MS palette file header to see how many colours are in the file
02432 ********************************************************************************************/
02433 BOOL JCWColourFilter::PreImport()
02434 {
02435     ERROR2IF( m_pImportFile==NULL, FALSE, "NULL pointer");
02436 
02437     // Read info out of the header.
02438     BYTE HeaderBuffer[8];
02439     m_pImportFile->read(HeaderBuffer, 8);
02440 
02441     if (m_pImportFile->good() && HeaderBuffer[0] == 'J' && HeaderBuffer[1] == 'C' && HeaderBuffer[2] == 'W' && HeaderBuffer[3] == 1)
02442     {
02443         m_NumToImport = HeaderBuffer[4] + (HeaderBuffer[5] << 8);
02444         m_ColoursAreSpots = (HeaderBuffer[6] & 0x01) ? TRUE : FALSE;
02445         // HeaderBuffer[7] is currently reserved, and set to zero
02446         return TRUE;
02447     }
02448 
02449     m_NumToImport = 0;
02450     return FALSE;
02451 }
02452 
02453 
02454 /********************************************************************************************
02455 >   BOOL JCWColourFilter::ImportPalette()
02456 
02457     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
02458     Created:    30/8/96
02459     Inputs:     -
02460     Outputs:    -
02461     Returns:    TRUE/FALSE for success/error
02462     Purpose:    Imports colours from an Adobe colour swatch
02463 ********************************************************************************************/
02464 
02465 BOOL JCWColourFilter::ImportPalette()
02466 {
02467     BOOL ok = StartPercentage(m_NumToImport);
02468     UINT32 Index = 0;
02469 
02470     BYTE ColourDef[8];
02471     String_64 Name;
02472 
02473     while (ok && m_pImportFile->good() && Index < m_NumToImport)
02474     {
02475         // Read the values for this colour from the file
02476         m_pImportFile->read(ColourDef, 8);
02477         m_pImportFile->read((TCHAR *)Name, 16);
02478 
02479         // Add the colour to the imported colours list
02480         if (m_pImportFile->good())
02481         {
02482             ColourCMYK NewColour;
02483             NewColour.Cyan      = (double) ((ColourDef[0] + (ColourDef[1] << 8))) / 10000.0;
02484             NewColour.Magenta   = (double) ((ColourDef[2] + (ColourDef[3] << 8))) / 10000.0;
02485             NewColour.Yellow    = (double) ((ColourDef[4] + (ColourDef[5] << 8))) / 10000.0;
02486             NewColour.Key       = (double) ((ColourDef[6] + (ColourDef[7] << 8))) / 10000.0;
02487 
02488             if (ImportIntoGallery)
02489             {
02490                 // Add the colour to the gallery, as either a process or spot colour (as appropriate)
02491                 // Every 7th colour has a newline after it
02492                 ok = AddColourToGallery(((m_ColoursAreSpots) ? PalettePrefix_PantoneSpot : PalettePrefix_Pantone),
02493                                             &Name, (ColourGeneric *)&NewColour, COLOURMODEL_CMYK, (Index % 7 == 6),
02494                                             m_ColoursAreSpots);
02495             }
02496             else
02497                 ok = m_pNewColours->AddColour(&Name, &NewColour);
02498         }
02499 
02500         SetPercentage(Index++);
02501     }
02502 
02503     return ok && m_pImportFile->good();
02504 }
02505 
02506 
02507 /********************************************************************************************
02508 >   BOOL JCWColourFilter::PostImport()
02509 
02510     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
02511     Created:    30/8/96
02512     Inputs:     -
02513     Outputs:    -
02514     Returns:    TRUE/FALSE for success/error
02515     Purpose:    Called to allow post import cleanup (if required) for this filter
02516 ********************************************************************************************/
02517 BOOL JCWColourFilter::PostImport()
02518 {
02519     // Nothing to do, no cleanup required.
02520     return TRUE;
02521 }
02522 #endif

Generated on Sat Nov 10 03:44:54 2007 for Camelot by  doxygen 1.4.4