bitmap.cpp

Go to the documentation of this file.
00001 // $Id: bitmap.cpp 1708 2006-08-17 17:13:38Z gerry $
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 // Kernel level parts of bitmap handler
00100 
00101 /*
00102 */
00103 
00104 #include "camtypes.h"
00105 //#include "mario.h"
00106 //#include "bitmap.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00107 #include "bitmpinf.h"
00108 //#include "list.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00109 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00110 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00111 //#include "fillval.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00112 //#include "will.h"
00113 //#include "phil.h"
00114 //#include "simon.h"
00115 //#include "resource.h"
00116 //#include "nativeps.h" // The old style EPS native filter, used in v1.1
00117 #include "clipint.h"
00118 //#include "fixmem.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00119 #include "grndrgn.h"
00120 //#include "devcolor.h"
00121 #include "gradtbl.h"
00122 #include "bmpcomp.h"    // BitmapListComponent
00123 
00124 #include "bitfilt.h"    // BaseBitmapFilter
00125 #include "camelot.h"    // BaseCamelotFilter
00126 //#include "ccfile.h"       // CCFile - in camtypes.h [AUTOMATICALLY REMOVED]
00127 #include "bmpsrc.h"     // BitmapSource
00128 
00129 //#ifndef WEBSTER       // Code now in DIBUtil 10/11/97 Neville 
00130 //#include "dibutil.h"  // put it back for DIBUtil::IsGreyscaleBitmap - in camtypes.h [AUTOMATICALLY REMOVED]
00131 //#endif //WEBSTER
00132 #include "bitmapfx.h"
00133 //#include "xpehost.h"
00134 
00135 #include "oilbitmap.h"  // for debug macros
00136 
00137 CC_IMPLEMENT_DYNAMIC( OILBitmap, ListItem )
00138 CC_IMPLEMENT_DYNAMIC( KernelBitmap, ListItem )
00139 CC_IMPLEMENT_DYNAMIC( KernelBitmapRef, CCObject )
00140 CC_IMPLEMENT_DYNAMIC( OriginalBitmapRef, CCObject )
00141 CC_IMPLEMENT_DYNAMIC( BitmapPtr, ListItem )
00142 CC_IMPLEMENT_DYNAMIC( KernelBmpListItem, ListItem )
00143 
00144 
00145 // This will get Camelot to display the filename and linenumber of any memory allocations
00146 // that are not released at program exit
00147 #define new CAM_DEBUG_NEW
00148 
00149 
00150 // Static default bitmap pointer
00151 OILBitmap *OILBitmap::Default;
00152 
00153 List* KernelBitmap::s_pTrackerList = NULL;
00154 
00155 /********************************************************************************************
00156 
00157 >   OriginalBitmapRef::OriginalBitmapRef(BitmapSource* pSource, 
00158                                          BaseBitmapFilter* pImportFilter = NULL)
00159                     
00160     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00161     Created:    8/8/96
00162 
00163     Inputs:     pSource, a pointer to a BitmapSource
00164                 pImportFilter, pointer to the filter to use to decode the bitmap
00165 
00166     Purpose:    Constructor for a reference to the original (usually compressed) bitmap
00167                 that was used to create the bitmap containing this reference.
00168     SeeAlso:    OriginalBitmapRef::GetOriginalFile
00169 
00170 ********************************************************************************************/
00171 
00172 OriginalBitmapRef::OriginalBitmapRef(BitmapSource* pSource, BaseBitmapFilter* pImportFilter)
00173 {
00174     m_pBitmapSource = pSource;
00175     m_pBitmapFilter = pImportFilter;
00176 }
00177 
00178 /********************************************************************************************
00179 
00180 >   OriginalBitmapRef::~OriginalBitmapRef()
00181                 
00182     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00183     Created:    8/8/96
00184 
00185     Purpose:    Destructor for a reference to the original bitmap.
00186                 THIS WILL FREE UP THE ORIGINAL FILE BUFFER.
00187 
00188     SeeAlso:    OriginalBitmapRef::GetOriginalFile
00189 
00190 ********************************************************************************************/
00191 
00192 OriginalBitmapRef::~OriginalBitmapRef()
00193 {
00194     if (m_pBitmapSource)
00195     {
00196         // Free up the original bitmap buffer
00197         delete m_pBitmapSource;
00198     }
00199 }
00200 
00201 /********************************************************************************************
00202 
00203 >   void OriginalBitmapRef::SetOriginalSource(BitmapSource* pSource = NULL, 
00204                                             BaseBitmapFilter* pImportFilter = NULL)
00205                 
00206     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00207     Created:    8/8/96
00208 
00209     Inputs:     pFileBuffer, a pointer to a buffer containing the original file.
00210                 pImportFilter, pointer to the filter to use to decode the bitmap
00211 
00212     Purpose:    Sets the original bitmap file associated with this reference.
00213 
00214     Notes:      The input file buffer should be CCMalloc'd, and will be CCFree'd when the
00215                 reference is destroyed, or changed to another buffer.
00216 
00217 ********************************************************************************************/
00218 
00219 void OriginalBitmapRef::SetOriginalSource(BitmapSource* pSource, BaseBitmapFilter* pImportFilter)
00220 {
00221     if (m_pBitmapSource)
00222     {
00223         // Free up the original bitmap buffer
00224         delete m_pBitmapSource;
00225     }
00226 
00227     m_pBitmapSource = pSource;
00228     m_pBitmapFilter = pImportFilter;
00229 }
00230 
00231 /********************************************************************************************
00232 
00233 >   BOOL OriginalBitmapRef::GetOriginalSource(BitmapSource** pSource = NULL,
00234                                             BaseBitmapFilter** ppImportFilter = NULL)
00235                 
00236     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00237     Created:    8/8/96
00238 
00239     Inputs:     pSource, ptr to a BitmapSource ptr to update to point at the original 
00240                 BitmapSource
00241                 ppFilterName, ptr to a BaseBitmapFilter ptr to update to point at the filter 
00242                 to use to decode the bitmap
00243                 
00244                 If both these inputs are NULL, then the function will simply return
00245                 whether an original file exists or not.
00246 
00247     Outputs:    The input pointers are set if an original file is available, otherwise they
00248                 are left unchanged.
00249 
00250     Returns:    TRUE, if an original file is available, and the pointers were set if non NULL.
00251                 FALSE, if no orginal files is available.
00252 
00253     Purpose:    Gets the original bitmap file buffer associated with this reference.
00254 
00255 ********************************************************************************************/
00256 
00257 BOOL OriginalBitmapRef::GetOriginalSource(BitmapSource** pSource, BaseBitmapFilter** ppImportFilter)
00258 {
00259     if (pSource == NULL && ppImportFilter == NULL)
00260     {
00261         // Just return whether a file is available or not, without setting the pointers
00262         return m_pBitmapSource != NULL;
00263     }
00264 
00265     if (m_pBitmapSource != NULL)
00266     {
00267         // Set the pointers
00268         *pSource        = m_pBitmapSource;
00269         *ppImportFilter = m_pBitmapFilter;
00270 
00271         return TRUE;
00272     }
00273 
00274     // No original file available
00275     return FALSE;
00276 }
00277 
00278 
00279 
00280 /********************************************************************************************
00281 
00282 >   KernelBitmap::KernelBitmap(OILBitmap *pBitmap = NULL)
00283                     
00284     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00285     Created:    ?/8/94
00286     Inputs:     Pointer to an OIL bitmap. If NULL then uses default built-in bitmap.
00287     Purpose:    Constructor for kernel bitmaps. Attaches to the OILBitmap and increases its
00288                 usage count.
00289     Errors:     -
00290     SeeAlso:    KernelBitmap::IsOK;OILBitmap::Attach
00291 
00292 ********************************************************************************************/
00293 
00294 KernelBitmap::KernelBitmap(OILBitmap *pBitmap, BOOL IsTemp)
00295 {
00296     m_pParentList = NULL;
00297     m_bDontDeleteActualBitmap = FALSE;
00298     m_bFractalAttached = FALSE;
00299     m_bUsedByBrush = FALSE;
00300     if (pBitmap == NULL)
00301         ActualBitmap = OILBitmap::Attach();
00302     else
00303         ActualBitmap = OILBitmap::Attach(pBitmap, IsTemp);
00304 
00305     if (ActualBitmap && ActualBitmap->IsAFractal())
00306         m_bFractalAttached = TRUE;
00307 }
00308 
00309 /********************************************************************************************
00310 
00311 >   KernelBitmap* KernelBitmap::MakeKernelBitmap(   OILBitmap *pBitmap = NULL, 
00312                                                     Document *pDoc = NULL,
00313                                                     BOOL bAlwaysNew = FALSE     )
00314                     
00315     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00316     Created:    14/1/95
00317     Inputs:     Pointer to an OIL bitmap. If NULL then uses default built-in bitmap.
00318                 Pointer to the Document the bitmap is use in (NULL = Current).
00319     Purpose:    Makes a KernelBitmap from an OIL bitmap.
00320                 Will use an existing one if the OILBitmap is already in use in the Doc.
00321     Errors:     -
00322     SeeAlso:    KernelBitmap::IsOK;OILBitmap::Attach
00323 
00324 ********************************************************************************************/
00325 
00326 KernelBitmap* KernelBitmap::MakeKernelBitmap(OILBitmap *pBitmap, Document *pDoc, BOOL bAlwaysNew)
00327 {
00328     KernelBitmap* NewBitmap;
00329 
00330     if (pBitmap == NULL)
00331         pBitmap = OILBitmap::Default;
00332 
00333     if (pDoc == NULL)
00334         pDoc = Document::GetCurrent();
00335 
00336     // Get the bitmap list from the document
00337     BitmapList* BmpList = NULL;
00338     if (pDoc) BmpList = pDoc->GetBitmapList();
00339 
00340     if (BmpList == NULL)
00341     {
00342         // This shouldn't really happen ...
00343         NewBitmap = new KernelBitmap(pBitmap);
00344         return NewBitmap;
00345     }
00346 
00347     KernelBitmap* Bmp = (KernelBitmap*)BmpList->GetHead();
00348     BOOL Exists = FALSE;
00349 
00350     // Scan through the Documents bitmap list to see if any of
00351     // the existing KernelBitmaps reference this OILBitmap.
00352     while (!bAlwaysNew && Bmp != NULL)
00353     {
00354         if (Bmp->ActualBitmap == pBitmap)
00355         {
00356             Exists = TRUE;
00357             break;
00358         }
00359 
00360         Bmp = (KernelBitmap*)BmpList->GetNext(Bmp);
00361     }
00362 
00363     if (Exists)
00364     {
00365         // Use the existing KernelBitmap.
00366         NewBitmap = Bmp;
00367     }
00368     else
00369     {
00370         // Make a new KernelBitmap.
00371         NewBitmap = new KernelBitmap(pBitmap);
00372     }   
00373 
00374     return NewBitmap;
00375 }
00376 
00377 
00378 /********************************************************************************************
00379 
00380 >   KernelBitmap::KernelBitmap( const KernelBitmap& other)
00381                     
00382     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00383     Created:    ?/8/94
00384     Inputs:     Another kernel bitmap.
00385     Purpose:    Copy constructor for kernel bitmaps. MAintains usage count on OILBitmap.
00386     SeeAlso:    KernelBitmap::IsOK;OILBitmap::Attach
00387 
00388 ********************************************************************************************/
00389 
00390 KernelBitmap::KernelBitmap( const KernelBitmap& other)
00391 {
00392     m_pParentList = NULL;
00393     m_bDontDeleteActualBitmap = FALSE;
00394     m_bFractalAttached = FALSE;
00395     m_bUsedByBrush = FALSE;
00396     ActualBitmap = OILBitmap::Attach( other.ActualBitmap, other.ActualBitmap->IsTemp() );
00397 
00398     if (ActualBitmap && ActualBitmap->IsAFractal())
00399         m_bFractalAttached = TRUE;
00400 }
00401 
00402 /********************************************************************************************
00403 
00404 >   KernelBitmap::KernelBitmap( UINT32 Width, UINT32 Height, UINT32 Depth, UINT32 dpi )
00405                     
00406     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00407     Created:    ?/8/94
00408     Inputs:     Bitmap pxiel width, height & depth and dpi setting.
00409     Purpose:    Constructor for kernel bitmaps which attaches it to a blank OILbitmap.
00410                 Actually, the OILBitmap isn't really blank, it is entirely uninitialised
00411                 i.e its contents will be random (including its palette if it has one).
00412     Errors:     Possible - SetError will be called, use IsOK for result.
00413     SeeAlso:    KernelBitmap::IsOK;OILBitmap::Create
00414 
00415 ********************************************************************************************/
00416 
00417 KernelBitmap::KernelBitmap( UINT32 Width, UINT32 Height, UINT32 Depth, UINT32 dpi, BOOL bTemp )
00418 {
00419     m_pParentList = NULL;
00420     m_bDontDeleteActualBitmap = FALSE;
00421     m_bFractalAttached = FALSE;
00422     m_bUsedByBrush = FALSE;
00423     OILBitmap *bm = OILBitmap::Create( Width, Height, Depth, dpi );
00424     if (bm)
00425         ActualBitmap = OILBitmap::Attach( bm, bTemp );
00426     else
00427         ActualBitmap = NULL;
00428 }
00429 
00430 /********************************************************************************************
00431 
00432 >   BOOL KernelBitmap::IsOK() const
00433                     
00434     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00435     Created:    ?/8/94
00436     Returns:    TRUE if KernelBitmap has a valid attached OILBitmap, FALSE if it doesn't
00437                 (e.g. its constructor failed).
00438     Purpose:    Tell if KernelBitmap is OK.
00439 
00440 ********************************************************************************************/
00441 
00442 BOOL KernelBitmap::IsOK() const
00443 {
00444     return ActualBitmap ? TRUE : FALSE;
00445 }
00446 
00447 /********************************************************************************************
00448 
00449 >   KernelBitmap::~KernelBitmap()
00450                     
00451     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00452     Created:    ?/8/94
00453     Purpose:    Destructor. Detaches any current OILBitmap.
00454     SeeAlso:    OILBitmap::Detach
00455 
00456 ********************************************************************************************/
00457 
00458 KernelBitmap::~KernelBitmap()
00459 {
00460     if (m_pParentList != NULL)
00461     {
00462         // If we're still in the bitmap list, then remove us
00463         m_pParentList->RemoveItem(this);
00464         m_pParentList = NULL;
00465     }
00466 
00467     if (ActualBitmap)
00468     {
00469         ERROR3IF_OILBMP_PTR_INVALID(ActualBitmap, 
00470                         "Bitmap Error.  Found a reference to a deleted bitmap.");
00471 
00472         // JustinF says: made the above check in retail builds as well, or we'll crash!
00473         if (//(INT32) ActualBitmap->m_pColourVersion != 0xFEEEFEEE &&
00474             //(INT32) ActualBitmap->m_pColourVersion != 0xCDCDCDCD &&
00475             //(INT32) ActualBitmap->m_pColourVersion != 0xDDDDDDDD &&
00476             !m_bDontDeleteActualBitmap &&
00477             !m_bFractalAttached &&
00478             ActualBitmap->IsTemp())
00479         {
00480             delete ActualBitmap;
00481         }
00482         
00483         // AndyH says: what a load of rubbish.
00484         // ActualBitmap->m_pColourVersion never evaluates to the constants
00485         // given above in the release build. In fact bug 6712 occurs because
00486         // we try to delete a KernelBitmap whose OILBitmap has already been
00487         // deleted; in turn, this function deletes ActualBitmap (an OILBitmap)
00488         // and causes an access violation.
00489 
00490         // By removing the above 'bodge', such access violations will occur in
00491         // debug mode too, as they should.
00492 
00493         ActualBitmap = NULL;
00494     }
00495 }
00496 
00497 /********************************************************************************************
00498 
00499 >   KernelBitmap& KernelBitmap::operator=(const KernelBitmap& other)
00500                     
00501     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00502     Created:    ?/8/94
00503     Inputs:     Another kernel bitmap.
00504     Purpose:    Assigns one KernelBitmap to another while maintaining usage count on OILBitmap.
00505 
00506 ********************************************************************************************/
00507 
00508 KernelBitmap& KernelBitmap::operator=(const KernelBitmap& other)
00509 {
00510     if (other.ActualBitmap == NULL)
00511         ActualBitmap = OILBitmap::Attach( NULL );
00512     else
00513         ActualBitmap = OILBitmap::Attach( other.ActualBitmap, other.ActualBitmap->IsTemp() );
00514 
00515     if (ActualBitmap && ActualBitmap->IsAFractal())
00516         m_bFractalAttached = TRUE;
00517     
00518     return *this;
00519 }
00520 
00521 /********************************************************************************************
00522 
00523 >   BOOL KernelBitmap::SetAsFractal()
00524                 
00525     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00526     Created:    10/8/96
00527     Returns:    FALSE if invalid pointer found
00528     Purpose:    Set this bitmap as a fractal bitmap
00529 
00530 ********************************************************************************************/
00531 
00532 BOOL KernelBitmap::SetAsFractal()
00533 {
00534     if (ActualBitmap == NULL)
00535         return FALSE;
00536 
00537     ERROR3IF_OILBMP_PTR_INVALID(ActualBitmap,
00538                 "Bitmap Error.  Found a reference to a deleted bitmap.");
00539 
00540     if (ActualBitmap)
00541     {
00542         m_bFractalAttached = TRUE;
00543         ActualBitmap->SetAsFractal();
00544     
00545         return TRUE;
00546     }
00547 
00548     return FALSE;
00549 }
00550 
00551 /********************************************************************************************
00552 
00553 >   BOOL KernelBitmap::SetAsGreyscale()
00554             
00555     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00556     Created:    20/2/97
00557 
00558     Returns:    FALSE if invalid pointer found
00559 
00560     Purpose:    Set this bitmap as a greyscale bitmap
00561                 This is used to inform the bitmap that it is a greyscale 8bpp bitmap.
00562                 This is because when we create a grteyscale OILBitmap and attach a KernelBitmap
00563                 to it, there is no way to indicate to the system that it's a true greyscale
00564                 bitmap, which is necessary to stop it farting around and making a new copy
00565                 of the bitmap when someone calls GetGreyscaleVersion(). This is used by
00566                 the airbrush stroke provider when it generates a greyscale bitmap for use
00567                 as a transparency mask.
00568 
00569     Notes:      ERROR3 will be given if the bitmap is not 8bpp. This may not be strictly
00570                 necessary (who can tell with this bitmap system - it's so confusing), but
00571                 for transparency masks, they must (AFAIK) be 8bpp, so it's a good safety check.
00572 
00573 ********************************************************************************************/
00574 
00575 BOOL KernelBitmap::SetAsGreyscale()
00576 {
00577     if (ActualBitmap == NULL)
00578         return FALSE;
00579 
00580     ERROR3IF_OILBMP_PTR_INVALID(ActualBitmap,
00581                 "Bitmap Error.  Found a reference to a deleted bitmap.");
00582 
00583     ERROR3IF(GetBPP() != 8, "SetAsGreyscale - this isn't an 8bpp bitmap - how can it be a greyscale?");
00584 
00585     if (ActualBitmap)
00586     {
00587         ActualBitmap->SetAsGreyscale();
00588         return TRUE;
00589     }
00590 
00591     return FALSE;
00592 }
00593 
00594 
00595 /********************************************************************************************
00596 
00597 >   BOOL KernelBitmap::SetAsLossy(BOOL bLossy = TRUE)
00598             
00599     Author:     Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
00600     Created:    20/2/97
00601 
00602     Returns:    FALSE if invalid pointer found
00603 
00604     Purpose:    Set this bitmap' lossy flag
00605 
00606 ********************************************************************************************/
00607 
00608 BOOL KernelBitmap::SetAsLossy(BOOL bLossy)
00609 {
00610     if (ActualBitmap == NULL)
00611         return FALSE;
00612 
00613     ERROR3IF_OILBMP_PTR_INVALID(ActualBitmap,
00614                 "Bitmap Error.  Found a reference to a deleted bitmap.");
00615 
00616     if (ActualBitmap)
00617     {
00618         ActualBitmap->SetAsLossy(bLossy);
00619         return TRUE;
00620     }
00621 
00622     return FALSE;
00623 }
00624 
00625 
00626 /********************************************************************************************
00627 
00628 >   BOOL KernelBitmap::IsDefaultBitmap()
00629                     
00630     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00631     Created:    1/7/96
00632     Returns:    TRUE if KernelBitmap is the default bitmap, FALSE if not.
00633     Purpose:    To find out if the bitmap is the default bitmap or not.
00634                 This is used by the native/web saving code to see if the bitmap
00635                 is the default one and if so save a reference to it.
00636     SeeAlso:    
00637 
00638 ********************************************************************************************/
00639 
00640 BOOL KernelBitmap::IsDefaultBitmap()
00641 {
00642     if (ActualBitmap == NULL)
00643         return FALSE;
00644 
00645     ERROR3IF_OILBMP_PTR_INVALID(ActualBitmap,
00646                 "Bitmap Error.  Found a reference to a deleted bitmap.");
00647 
00648     // Treat as the default bitmap, if we've been deleted
00649     if (HasBeenDeleted())
00650         return TRUE;
00651 
00652     // Check to see if its the default bitmap
00653     if (ActualBitmap == OILBitmap::Default)
00654         return TRUE;
00655 
00656     return FALSE;
00657 }
00658 
00659 /********************************************************************************************
00660 
00661 >   BOOL KernelBitmap::HasBeenDeleted ()
00662                     
00663     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00664     Created:    10/8/96
00665     Returns:    TRUE    - The bitmap has already been deleted.
00666                 FALSE   - The bitmap hasn't been deleted.
00667     Purpose:    Tests whether or not the OIL bitmap attached to the kernel bitmap class has
00668                 been deleted.
00669 
00670 ********************************************************************************************/
00671 
00672 BOOL KernelBitmap::HasBeenDeleted ()
00673 {
00674     // This test is far better done BEFORE the ERROR3!
00675     // Graeme (21/6/00) - Added a test to see whether the pointer points at 0xdddddddd, as
00676     // this is the value that the memory is (re)set to by delete.
00677     // Luke (31/10/05) - Removed these tests, since I'd rather this excepts rather than
00678     // perform a dodgy read on some memory that may be returned to OS (or used for something 
00679     // else)
00680     if( ActualBitmap == NULL )
00681     {
00682         return TRUE;
00683     }
00684     else
00685     {
00686         ERROR3IF_OILBMP_PTR_INVALID ( ActualBitmap,
00687                 "Bitmap Error. Found a reference to a deleted bitmap." );
00688 
00689         return ActualBitmap->HasBeenDeleted ();
00690     }
00691 }
00692 
00693 /********************************************************************************************
00694 
00695 >   virtual BOOL KernelBitmap::WritePalette(BaseCamelotFilter *pFilter)
00696 
00697     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00698     Created:    4/9/96
00699     Inputs:     pFilter - The filter to use to write the data with
00700     Outputs:    -
00701     Returns:    True if saved ok, False otherwise
00702     Purpose:    Exports the palette out to the file using the BaseCamelotFilter supplied. This
00703                 means that it is being written to a web or native file.
00704                 At present, used by the code when outputting an 8bpp JPEG to squirt the palette
00705                 into the record so that we can convert it back to 8bpp using the palette on
00706                 loading.
00707 
00708 ********************************************************************************************/
00709 
00710 BOOL KernelBitmap::WritePalette(BaseCamelotFilter *pFilter)
00711 {
00712     ERROR2IF(pFilter == NULL,FALSE,"KernelBitmap::WritePalette null pFilter");
00713 
00714     if (ActualBitmap == NULL)
00715         return FALSE;
00716 
00717     return ActualBitmap->WritePalette(pFilter);
00718 }
00719 
00720 /********************************************************************************************
00721 
00722 >   virtual BOOL KernelBitmap::Convert24To8(RGBTRIPLE *pPalette, UINT32 NumberOfPaletteEntries)
00723 
00724     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00725     Created:    4/9/96
00726     Inputs:     pPalette    - pointer to the palette in RGBTIPLE format to use when converting
00727                 NumberOfPaletteEntries - entries in this palette 
00728     Outputs:    -
00729     Returns:    True if worked ok, False otherwise
00730     Purpose:    Converts the OILbitmap from its present 24bpp form into an 8bpp form which
00731                 should closely match the one that was exported.
00732 
00733 ********************************************************************************************/
00734 
00735 BOOL KernelBitmap::Convert24To8(RGBTRIPLE *pPalette, UINT32 NumberOfPaletteEntries)
00736 {
00737     ERROR2IF(pPalette == NULL,FALSE,"KernelBitmap::Convert24To8 null pFilter");
00738     ERROR2IF(NumberOfPaletteEntries == 0,FALSE,"KernelBitmap::Convert24To8 NumberOfPaletteEntries = 0");
00739 
00740     if (ActualBitmap == NULL)
00741         return FALSE;
00742 
00743     // If the bitmap is already 8bpp then do nothing
00744     if (GetBPP() == 8)
00745         return TRUE;
00746 
00747     return ActualBitmap->Convert24To8(pPalette, NumberOfPaletteEntries);
00748 }
00749 
00750 /********************************************************************************************
00751 
00752 >   static BOOL KernelBitmap::ImportBitmap(CCLexFile* pFile, BaseBitmapFilter* pBitmapFilter,
00753                                            BaseCamelotFilter* pFilter, BOOL IsCompressed,
00754                                            RGBTRIPLE *pPalette, UINT32 NumberOfPaletteEntries,
00755                                            KernelBitmap** ppImportedBitmap, BOOL* IsNew)
00756                 
00757     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00758     Created:    20/6/96
00759     Inputs:     pFile           - The file to read the data from
00760                 pBitmapFilter   - The bitmap filter to use for importing the bitmap.
00761                 pFilter         - The BaseCamelotFilter which provides functions for things like progress
00762                                 bar updates.
00763                 IsCompressed    - Flag to say the bitmap is compressed or not.
00764                 pPalette        - If non-null then palette to convert the 24bpp bitmap into an 8bpp bitmap
00765                 NumberOfPaletteEntries  - Is the number of entries in the above palette  
00766     Outputs:    *ppImportedBitmap   - updated to point at new or existing bitmap.
00767                 *IsNew = TRUE       - if a new bitmap was created, or
00768                          FALSE      - if an existing one has been returned.
00769     Purpose:    Imports a bitmap, and checks to see if the bitmap already exist, returning
00770                 a pointer to the existing bitmap if possible, or creates a new one.
00771                 
00772                 This is used web/native filters to pull out a bitmap definition from inside
00773                 a bitmap definition record.  IsCompressed is only used for BMP/BMPZIP type
00774                 bitmaps, at present.
00775 
00776                 Assumes:
00777                     pFile has already been opened up for reading
00778                     pFilter has been set up for reading the data e.g. progress bar 
00779     Errors:     -
00780     SeeAlso:    OILBitmap::ImportBitmap
00781 
00782 ********************************************************************************************/
00783 
00784 BOOL KernelBitmap::ImportBitmap(CCLexFile* pFile, BaseBitmapFilter* pBitmapFilter,
00785                                 BaseCamelotFilter* pFilter, BOOL IsCompressed,
00786                                 RGBTRIPLE *pPalette, UINT32 NumberOfPaletteEntries,
00787                                 KernelBitmap** ppImportedBitmap, BOOL* IsNew)
00788 {
00789     ERROR2IF(pFile == NULL,FALSE,"KernelBitmap::ImportBitmap null pFile");
00790     ERROR2IF(pBitmapFilter == NULL,FALSE,"KernelBitmap::ImportBitmap null pBitmapFilter");
00791     ERROR2IF(pFilter == NULL,FALSE,"KernelBitmap::ImportBitmap null pFilter");
00792     ERROR2IF(ppImportedBitmap == NULL,FALSE,"KernelBitmap::ImportBitmap null ppImportedBitmap");
00793 
00794     *ppImportedBitmap = NULL;
00795     
00796     if (IsNew)
00797         *IsNew = TRUE;
00798 
00799     // Get a new bitmap object to import into
00800     OILBitmap *pOILBitmap = OILBitmap::Create();
00801     if (pOILBitmap == NULL)
00802     {
00803         return FALSE;
00804     }
00805 
00806     // Import the bitmap data
00807     if (!pOILBitmap->ImportBitmap(pFile, pBitmapFilter, pFilter, IsCompressed))
00808     {
00809         delete pOILBitmap;
00810         return FALSE;
00811     }
00812 
00813     // Check if a palette has been supplied, if so then it is a JPEG which started out
00814     // as 8bpp colour but has been converted to 24bpp so that it can be JPEGed.
00815     // If this is the case then the palette is the one from the original bitmap. So use
00816     // it to go and convert the data back into the 8bpp data.
00817     if (pPalette && NumberOfPaletteEntries > 0 && NumberOfPaletteEntries <= 256)
00818     {   
00819         // If the loaded bitmap is not 24bpp then do nothing
00820         if (pOILBitmap->GetBPP() == 24)
00821             pOILBitmap->Convert24To8(pPalette, NumberOfPaletteEntries);
00822         // If a problem has happened then we will forget the conversion and use the
00823         // 24 bpp version
00824     }
00825 
00826     // Now check to see if this bitmap already exists ....
00827     Document* ImportDoc = ((Filter*)pFilter)->GetDocument();
00828     if (ImportDoc == NULL)
00829         ImportDoc = Document::GetSelected();
00830 
00831     if (ImportDoc == NULL)
00832     {
00833         delete pOILBitmap;
00834         return FALSE;
00835     }
00836 
00837     // The bitmap system relies on the Current Doc being correct,
00838     // so we'll set it to be on the safe side
00839     ImportDoc->SetCurrent();
00840 
00841     // Is there an existing KernelBitmap already in the bitmap list ?
00842     *ppImportedBitmap = TryAndUseExistingBitmap(pOILBitmap, ImportDoc, IsNew);
00843 
00844     return (*ppImportedBitmap != NULL);
00845 }
00846 
00847 /********************************************************************************************
00848 
00849 >   BOOL KernelBitmap::ImportBitmap(Filter *pFilter, const BitmapInfo *pInfo, INT32 BitmapType,
00850                                 KernelBitmap** ppImportedBitmap, BOOL* IsNew)
00851                 
00852     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00853     Created:    11/4/95
00854     Inputs:     pFilter, The filter to use for importing the bitmap.
00855                 pInfo, Optional bitmap info to use to create the bitmap
00856                 IsNew, if NULL then no check will be made to see if the imported bitmap
00857                 already exists in the filter's associated document. A check for the OILBitmap
00858                 will always be made.
00859     Outputs:    *ppImportedBitmap, updated to point at new or existing bitmap.
00860                 *IsNew = TRUE, if a new bitmap was created, or
00861                          FALSE, if an existing one has been returned.
00862     Purpose:    Imports a bitmap, and checks to see if the bitmap already exist,
00863                 returning a pointer to the existing bitmap if possible, or
00864                 creates a new one.
00865     Errors:     -
00866     SeeAlso:    OILBitmap::ImportBitmap
00867 
00868 ********************************************************************************************/
00869 
00870 BOOL KernelBitmap::ImportBitmap(Filter *pFilter, const BitmapInfo *pInfo, INT32 BitmapType,
00871                                 KernelBitmap** ppImportedBitmap, BOOL* IsNew)
00872 {
00873     ERROR2IF(pFilter == NULL,FALSE,"KernelBitmap::ImportBitmap null pFilter");
00874     ERROR2IF(ppImportedBitmap == NULL,FALSE,"KernelBitmap::ImportBitmap null ppImportedBitmap");
00875 
00876     *ppImportedBitmap = NULL;
00877     if (IsNew)
00878         *IsNew = TRUE;
00879 
00880     // Get a new bitmap object for this node.
00881     OILBitmap *pOILBitmap = OILBitmap::Create();
00882     if (pOILBitmap == NULL)
00883     {
00884         return FALSE;
00885     }
00886 
00887     if (!pOILBitmap->ImportBitmap(pFilter, pInfo, BitmapType))
00888     {
00889         delete pOILBitmap;
00890         return FALSE;
00891     }
00892 
00893     // Now check to see if this bitmap already exists if necessary....
00894     Document* ImportDoc = ((Filter*)pFilter)->GetDocument();
00895     if (ImportDoc == NULL)
00896         ImportDoc = Document::GetSelected();
00897 
00898     if (ImportDoc == NULL)
00899     {
00900 //      delete pOILBitmap;
00901 //      return FALSE;
00902 //  }
00903         // no document, so don't try to re-use any existing bitmaps
00904         *ppImportedBitmap = TryAndUseExistingBitmap(pOILBitmap, NULL, NULL);
00905     }
00906     else
00907     {
00908         // The bitmap system relies on the Current Doc being correct,
00909         // so we'll set it to be on the safe side
00910         ImportDoc->SetCurrent();
00911 
00912         // Is there an existing KernelBitmap already in the bitmap list ?
00913         *ppImportedBitmap = TryAndUseExistingBitmap(pOILBitmap, ImportDoc, IsNew);
00914     }
00915 
00916     return (*ppImportedBitmap != NULL);
00917 }
00918 
00919 /********************************************************************************************
00920 
00921 >   KernelBitmap* KernelBitmap::TryAndUseExistingBitmap(OILBitmap* pOILBitmap, Document* pDoc, 
00922                                                         BOOL* IsNew)
00923 
00924     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00925     Created:    10/8/96
00926     Inputs:     pOILBitmap, 
00927                 pDoc,
00928                 IsNew, if NULL then no check will be made to see if the imported bitmap
00929                 already exists in the filter's associated document. A check for the OILBitmap
00930                 will always be made.
00931     Outputs:    *IsNew = TRUE, if a new bitmap was created, or
00932                          FALSE, if an existing one has been returned.
00933     Purpose:    Imports a bitmap, and checks to see if the bitmap already exist,
00934                 returning a pointer to the existing bitmap if possible, or
00935                 creates a new one.
00936     Errors:     -
00937 
00938 ********************************************************************************************/
00939 
00940 KernelBitmap* KernelBitmap::TryAndUseExistingBitmap(OILBitmap* pOILBitmap, Document* pDoc, 
00941                                                     BOOL* IsNew)
00942 {
00943     // Is IsNew is NULL, then we won't try and use an existing bitmap
00944     if (IsNew != NULL)
00945     {   
00946         // Find this documents BitmapList
00947         BitmapList* pBmpList = pDoc->GetBitmapList();
00948 
00949         // Is there an existing KernelBitmap already in the bitmap list ?
00950         KernelBitmap* pExistingKBmp = pBmpList->FindDuplicateBitmap(pOILBitmap);
00951 
00952         if (pExistingKBmp)
00953         {
00954             TRACEUSER( "Neville", _T("This bitmap already exists.  Re-using existing KernelBitmap.\n") );
00955             
00956             // We'll use the one that's there already
00957             delete pOILBitmap;
00958 
00959             *IsNew = FALSE;     // We're using an existing Bitmap
00960             return pExistingKBmp;
00961         }
00962 
00963         // There is no existing version in this document,
00964         // but there might be one in another document somewhere
00965         // so we'll have a look in the global list.
00966 
00967         OILBitmap* pExistingBmp = 
00968             GetApplication()->GetGlobalBitmapList()->FindDuplicateBitmap(pOILBitmap);
00969 
00970         if (pExistingBmp)
00971         {
00972             TRACEUSER("Neville", _T("This bitmap already exists.  Re-using existing OILBitmap.\n") );
00973 
00974             // There's already an existing OIL bitmap we can use,
00975             // so we'll make a new kernel bitmap out of it ...
00976             delete pOILBitmap;
00977 
00978             KernelBitmap* KernelBmp = new KernelBitmap(pExistingBmp);
00979             if (KernelBmp == NULL)
00980             {
00981                 return NULL;
00982             }
00983 
00984             *IsNew = FALSE;     // We're using an existing Bitmap
00985 
00986             return KernelBmp;
00987         }
00988     }
00989 
00990     TRACEUSER( "Neville", _T("This is a new bitmap\n") );
00991 
00992     BOOL Temp = FALSE;
00993     if (IsNew == NULL)
00994         Temp = TRUE; // mark it as temp
00995 
00996     // We'll make a completely new bitmap then
00997     KernelBitmap* NewKernelBmp = new KernelBitmap(pOILBitmap, Temp);
00998     if (NewKernelBmp == NULL)
00999     {
01000         delete pOILBitmap;
01001         return NULL;
01002     }
01003 
01004     if (IsNew)
01005         *IsNew = TRUE;          // This is a new Bitmap
01006 
01007     return NewKernelBmp;
01008 }
01009 
01010 
01011 /********************************************************************************************
01012 
01013 >   BOOL KernelBitmap::SetTransparencyIndex(INT32 Index)
01014                 
01015     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
01016     Created:    5/6/96
01017     Returns:    TRUE if the Index was set, FALSE if there is no transparent index
01018     Purpose:    Finds the Transparent index colour of a bitmap if one exists
01019 
01020 ********************************************************************************************/
01021 
01022 BOOL KernelBitmap::SetTransparencyIndex(INT32 Index)
01023 {
01024     if (ActualBitmap == NULL)
01025         return FALSE;
01026 
01027     ERROR3IF_OILBMP_PTR_INVALID(ActualBitmap,
01028                 "Bitmap Error.  Found a reference to a deleted bitmap.");
01029 
01030     if (ActualBitmap->GetBPP() > 8)
01031         return FALSE;
01032 
01033     return ActualBitmap->SetTransparencyIndex(Index);
01034 }
01035 
01036 /********************************************************************************************
01037 
01038 >   BOOL KernelBitmap::GetTransparencyIndex(INT32* pIndex)
01039                 
01040     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
01041     Created:    5/6/96
01042     Returns:    TRUE if the Index was set, FALSE if there is no transparent index
01043     Purpose:    Finds the Transparent index colour of a bitmap if one exists
01044 
01045 ********************************************************************************************/
01046 
01047 BOOL KernelBitmap::GetTransparencyIndex(INT32* pIndex)
01048 {
01049     if (ActualBitmap == NULL)
01050         return FALSE;
01051 
01052     ERROR3IF_OILBMP_PTR_INVALID(ActualBitmap,
01053                 "Bitmap Error.  Found a reference to a deleted bitmap.");
01054 
01055     if (ActualBitmap->GetBPP() > 8)
01056         return FALSE;
01057 
01058     return ActualBitmap->GetTransparencyIndex(pIndex);
01059 }
01060 
01061 /********************************************************************************************
01062 
01063 >   BOOL KernelBitmap::IsTransparent()
01064                 
01065     Author:     Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
01066     Created:    16/03/2004
01067     Returns:    TRUE if the bitmap has any non-opaque pixels
01068     Purpose:    Determines if a bitmap is not totally opaque
01069 
01070 ********************************************************************************************/
01071 
01072 BOOL KernelBitmap::IsTransparent()
01073 {
01074     if (ActualBitmap == NULL)
01075         return FALSE;
01076 
01077     ERROR3IF_OILBMP_PTR_INVALID(ActualBitmap,
01078                 "Bitmap Error.  Found a reference to a deleted bitmap.");
01079 
01080     return ActualBitmap->IsTransparent();
01081 }
01082 
01083 
01084 /********************************************************************************************
01085 
01086 >   INT32 KernelBitmap::GetRecommendedWidth()
01087                 
01088     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
01089     Created:    12/6/96
01090     Returns:    The current recommended width of the bitmap in Millipoints
01091     Purpose:    Finds the recommended width of the bitmap
01092 
01093 ********************************************************************************************/
01094 
01095 INT32 KernelBitmap::GetRecommendedWidth()
01096 {
01097     INT32 Width = 0;
01098 
01099     if (ActualBitmap)
01100     {
01101         Width = ActualBitmap->GetRecommendedWidth();
01102     }
01103 
01104     return Width;
01105 }
01106 
01107 /********************************************************************************************
01108 
01109 >   INT32 KernelBitmap::GetRecommendedHeight()
01110             
01111     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
01112     Created:    12/6/96
01113     Returns:    The current recommended height of the bitmap in Millipoints
01114     Purpose:    Finds the recommended height of the bitmap
01115 
01116 ********************************************************************************************/
01117 
01118 INT32 KernelBitmap::GetRecommendedHeight()
01119 {
01120     INT32 Height = 0;
01121 
01122     if (ActualBitmap)
01123     {
01124         Height = ActualBitmap->GetRecommendedHeight();
01125     }
01126 
01127     return Height;
01128 }
01129 
01130 /********************************************************************************************
01131 
01132 >   void KernelBitmap::SetRecommendedWidth(INT32 NewWidth)
01133                 
01134     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
01135     Created:    12/6/96
01136     Inputs:     NewWidth, the new width of the bitmap in Millipoints
01137     Purpose:    Sets the recommended width of the bitmap
01138 
01139 ********************************************************************************************/
01140 
01141 void KernelBitmap::SetRecommendedWidth(INT32 NewWidth)
01142 {
01143     if (ActualBitmap)
01144         ActualBitmap->SetRecommendedWidth(NewWidth);
01145 }
01146 
01147 /********************************************************************************************
01148 
01149 >   void KernelBitmap::SetRecommendedHeight(INT32 NewHeight)
01150                 
01151     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
01152     Created:    12/6/96
01153     Inputs:     NewHeight, the new height of the bitmap in Millipoints
01154     Purpose:    Sets the recommended height of the bitmap
01155 
01156 ********************************************************************************************/
01157 
01158 void KernelBitmap::SetRecommendedHeight(INT32 NewHeight)
01159 {
01160     if (ActualBitmap)
01161         ActualBitmap->SetRecommendedWidth(NewHeight);
01162 }
01163 
01164 
01165 /********************************************************************************************
01166 
01167 >   ADDR KernelBitmap::GetBitmapBits() const
01168 
01169     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
01170     Created:    02/11/96
01171     Returns:    The address of the bits of this KernelBitmap
01172                 NULL if an error occurred
01173     Purpose:    Helper function to get the actual bits (as in Bitmap)
01174     Errors:     Checks runtime class
01175 
01176 ********************************************************************************************/
01177 ADDR KernelBitmap::GetBitmapBits() const
01178 {
01179     OILBitmap* pOILy = GetActualBitmap();
01180     if (pOILy == NULL)
01181     {
01182         TRACE( _T("KernelBitmap::GetBitmapBits() - no OILBitmap") );
01183         return NULL;
01184     }
01185 
01186     ERROR3IF(!pOILy->IS_KIND_OF(OILBitmap), "pOILy isn't");
01187     
01188     return pOILy->GetBitmapBits();
01189 }
01190 
01191 
01192 /********************************************************************************************
01193 
01194 >   void KernelBitmap::Attach(BitmapList* BmpList = NULL)
01195         
01196     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
01197     Created:    12/12/94
01198     Inputs:     The bitmap list to attach this bitmap to.
01199                 if NULL then the bitmap is Re-Attached to its old list.
01200     Outputs:    -
01201     Purpose:    Adds this kernel bitmap to the specified document bitmap list.
01202     Errors:     -
01203     SeeAlso:    -
01204 
01205 ********************************************************************************************/
01206 
01207 void KernelBitmap::Attach(BitmapList* BmpList)
01208 {
01209     if (BmpList == NULL)
01210         BmpList = m_pParentList;
01211 
01212     ERROR3IF(BmpList == NULL, "Warning ... NULL BmpList in KernelBitmap::Attach");
01213     if (BmpList == NULL)    
01214         return;
01215 
01216     if (m_pParentList == NULL)
01217     {
01218         TRACEUSER( "Neville", _T("Attaching KBmp @ %x, to List at %x\n"), this, BmpList );
01219         m_pParentList = BmpList;
01220         BmpList->AddItem(this);
01221 
01222         if (KernelBitmap::s_pTrackerList)
01223         {
01224             KernelBmpListItem* pItem = new KernelBmpListItem(this);
01225             if (pItem)
01226                 KernelBitmap::s_pTrackerList->AddTail(pItem);
01227         }
01228     }
01229 
01230     ActualBitmap->RebuildXPEBitmap();
01231 }
01232 
01233 /********************************************************************************************
01234 
01235 >   void KernelBitmap::Detach()
01236         
01237     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
01238     Created:    12/12/94
01239     Inputs:     -
01240     Outputs:    -
01241     Purpose:    Removes this kernel bitmap from it's current document bitmap list.
01242     Errors:     -
01243     SeeAlso:    -
01244 
01245 ********************************************************************************************/
01246 
01247 void KernelBitmap::Detach()
01248 {
01249     // For each document
01250     // If bitmap is used in document
01251     // Go though all the documents
01252     Document* pDoc = (Document*)GetApplication()->Documents.GetHead();
01253     while (pDoc != NULL)
01254     {
01255         if (ActualBitmap->IsUsedInDocument(pDoc))
01256         return;
01257 
01258         // Move onto the next document
01259         pDoc = (Document*)GetApplication()->Documents.GetNext(pDoc);
01260     }
01261 
01262     // If we got here then the bitmap is not used in any document
01263     // so we can safely vape its data if we can later rebuild it
01264     ActualBitmap->RemoveXPEBitmap();
01265 }
01266 
01267 /********************************************************************************************
01268 
01269 >   UINT32 KernelBitmap::GetBPP()
01270                     
01271     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
01272     Created:    12/1/95
01273     Returns:    The number of Bits per pixel of this bitmap
01274     Purpose:    Finds the colour resolution of this bitmap
01275     Errors:     -
01276     SeeAlso:    -
01277 
01278 ********************************************************************************************/
01279 
01280 UINT32 KernelBitmap::GetBPP()
01281 {
01282     if (ActualBitmap == NULL)
01283         return 0;
01284 
01285     ERROR3IF_OILBMP_PTR_INVALID(ActualBitmap,"Bitmap Error.  Found a reference to a deleted bitmap.");
01286 
01287     return ActualBitmap->GetBPP();
01288 }
01289 
01290 /********************************************************************************************
01291 
01292 >   UINT32 KernelBitmap::GetWidth() const
01293                     
01294     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01295     Created:    8/7/97
01296     Returns:    The width of this bitmap
01297     Purpose:    Finds the width of this bitmap
01298 
01299 ********************************************************************************************/
01300 
01301 UINT32 KernelBitmap::GetWidth() const
01302 {
01303     if (ActualBitmap == NULL)
01304         return 0;
01305 
01306     return ActualBitmap->GetWidth();
01307 }
01308 
01309 /********************************************************************************************
01310 
01311 >   UINT32 KernelBitmap::GetHeight() const
01312                     
01313     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01314     Created:    8/7/97
01315     Returns:    The height of this bitmap
01316     Purpose:    Finds the height of this bitmap
01317 
01318 ********************************************************************************************/
01319 
01320 UINT32 KernelBitmap::GetHeight() const
01321 {
01322     if (ActualBitmap == NULL)
01323         return 0;
01324 
01325     return ActualBitmap->GetHeight();
01326 }
01327     
01328 /********************************************************************************************
01329 
01330 >   UINT32 KernelBitmap::GetNumPaletteEntries() const
01331                     
01332     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01333     Created:    8/7/97
01334     Returns:    The number of palette entries of this bitmap
01335     Purpose:    Finds the number of colours colour in this bitmap
01336 
01337 ********************************************************************************************/
01338 
01339 UINT32 KernelBitmap::GetNumPaletteEntries() const
01340 {
01341     if (ActualBitmap == NULL)
01342         return 0;
01343 
01344     return ActualBitmap->GetNumPaletteEntries();
01345 }
01346 
01347 /********************************************************************************************
01348 
01349 >   void KernelBitmap::SetOriginalSource(BitmapSource* pSource = NULL
01350                                        BaseBitmapFilter* pImportFilter = NULL)
01351                 
01352     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
01353     Created:    8/8/96
01354 
01355     Inputs:     pSource, a pointer to BitmapSource of the original file.
01356                 pImportFilter, pointer to the filter to use to decode the bitmap
01357 
01358     Purpose:    Sets the original bitmap file associated with this reference.
01359 
01360 ********************************************************************************************/
01361 
01362 void KernelBitmap::SetOriginalSource(BitmapSource* pSource, BaseBitmapFilter* pImportFilter)
01363 {
01364     if (ActualBitmap == NULL)
01365         return;
01366 
01367     ERROR3IF_OILBMP_PTR_INVALID(ActualBitmap,
01368                 "Bitmap Error.  Found a reference to a deleted bitmap.");
01369 
01370     // The OILBitmap has the reference in it
01371     ActualBitmap->SetOriginalSource(pSource, pImportFilter);
01372 }
01373 
01374 /********************************************************************************************
01375 
01376 >   BOOL KernelBitmap::GetOriginalSource(BitmapSource** pSource = NULL,
01377                                             BaseBitmapFilter** ppImportFilter = NULL)
01378                 
01379     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
01380     Created:    8/8/96
01381 
01382     Inputs:     pSource, ptr to a void ptr to update to point at the original BitmapSource
01383                 ppFilterName, ptr to a BaseBitmapFilter ptr to update to point at the filter 
01384                 to use to decode the bitmap
01385                 
01386                 If both these inputs are NULL, then the function will simply return
01387                 whether an original file exists or not.
01388 
01389     Outputs:    The input pointers are set if an original file is available, otherwise they
01390                 are left unchanged.
01391 
01392     Returns:    TRUE, if an original file is available, and the pointers were set if non NULL.
01393                 FALSE, if no orginal files is available.
01394 
01395     Purpose:    Gets the original bitmap file buffer associated with this reference.
01396 
01397 ********************************************************************************************/
01398 
01399 BOOL KernelBitmap::GetOriginalSource(BitmapSource** pSource, BaseBitmapFilter** ppImportFilter)
01400 {
01401     if (ActualBitmap == NULL)
01402         return FALSE;
01403 
01404     ERROR3IF_OILBMP_PTR_INVALID(ActualBitmap,
01405                 "Bitmap Error.  Found a reference to a deleted bitmap.");
01406 
01407     // The OILBitmap has the reference in it
01408     return ActualBitmap->GetOriginalSource(pSource, ppImportFilter);
01409 }
01410 
01411 /********************************************************************************************
01412 
01413 >   void KernelBitmap::SetXPEInfo(KernelBitmap* pMasterBitmap, IXMLDOMDocumentPtr pNewEditList)
01414                 
01415     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
01416     Created:    28/01/2004
01417 
01418     Inputs:     pNewEditList - pointer to XML edit list document to be stored with this bitmap
01419 
01420     Purpose:    Sets the XPE edit list document for this bitmap.
01421 
01422 ********************************************************************************************/
01423 
01424 PORTNOTE("other","KernelBitmap::GetXPEInfo removed")
01425 #ifndef EXCLUDE_FROM_XARALX
01426 void KernelBitmap::SetXPEInfo(KernelBitmap* pMasterBitmap, IXMLDOMDocumentPtr pNewEditList)
01427 {
01428     if (ActualBitmap)
01429     {
01430         OILBitmap* pOilMaster = NULL;
01431         if (pMasterBitmap) pOilMaster = pMasterBitmap->GetActualBitmap();
01432         ActualBitmap->SetXPEInfo(pOilMaster, pNewEditList);
01433     }
01434 }
01435 #endif
01436 
01437 /********************************************************************************************
01438 
01439 >   void KernelBitmap::GetXPEInfo(KernelBitmap*& refMasterBitmap,
01440                                   IXMLDOMDocumentPtr& refEditList,
01441                                   BOOL bEnsureList)
01442                 
01443     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
01444     Created:    28/01/2004
01445     Inputs:     -
01446     Outputs:    Updates the passed-in reference variables!!!
01447                 refMasterBitmap updated to contain pointer to the master bitmap for this bitmap
01448                 refEditList updated to contain pointer the edits list for this bitmap
01449                 NOTE:
01450                 I'd prefer to use pointers but there are problems with IXMLDOMDocument2Ptr*
01451     Returns:    Pointer to XML document containing edit list for this bitmap.
01452     Purpose:    Gets the stored XPE information for this bitmap.
01453 
01454 ********************************************************************************************/
01455 
01456 PORTNOTE("other","KernelBitmap::GetXPEInfo removed")
01457 #ifndef EXCLUDE_FROM_XARALX
01458 void KernelBitmap::GetXPEInfo(KernelBitmap*& refMasterBitmap,
01459                               IXMLDOMDocumentPtr& refEditList,
01460                               BOOL bEnsureList)
01461 {
01462     if (ActualBitmap)
01463     {
01464         OILBitmap* pMasterOil = NULL;
01465         ActualBitmap->GetXPEInfo(pMasterOil, refEditList, bEnsureList);
01466         BitmapList* pBitmapList = m_pParentList;
01467         if (pBitmapList==NULL)
01468         {
01469             Document* pDoc = Document::GetCurrent();
01470             if (pDoc)
01471                 pBitmapList = pDoc->GetBitmapList();
01472         }
01473 
01474         if (pMasterOil && pBitmapList)
01475         {
01476             KernelBitmap* pBmp = (KernelBitmap*)pBitmapList->GetHead();
01477 
01478             // Scan through the Documents bitmap list to see if any of
01479             // the existing KernelBitmaps reference this OILBitmap.
01480             while (pBmp != NULL)
01481             {
01482                 if (pBmp->ActualBitmap == pMasterOil)
01483                 {
01484                     refMasterBitmap = pBmp;
01485                     break;
01486                 }
01487 
01488                 pBmp = (KernelBitmap*)pBitmapList->GetNext(pBmp);
01489             }
01490         }
01491     }
01492 }
01493 #endif
01494 
01495 /********************************************************************************************
01496 
01497 >   BOOL KernelBitmap::IsXPEMaster()
01498                 
01499     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
01500     Created:    28/01/2004
01501     Inputs:     -
01502     Outputs:    -
01503     Returns:    TRUE if this bitmap is a used as a master by other bitmaps in the same list
01504     Purpose:    Gets the XPE master status of this bitmap by searching the bitmap list
01505 
01506 ********************************************************************************************/
01507 
01508 BOOL KernelBitmap::IsXPEMaster()
01509 {
01510     if (ActualBitmap)
01511         return ActualBitmap->IsXPEMaster();
01512     return FALSE;
01513 }
01514 
01515 
01516 /********************************************************************************************
01517 
01518 >   BOOL KernelBitmap::DestroyXPEInfo()
01519                 
01520     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
01521     Created:    30/01/2004
01522     Inputs:     -
01523     Outputs:    -
01524     Returns:    TRUE if this bitmap has no XPE info or the user agreed it could be destroyed
01525                 FALSE otherwise
01526     Purpose:    Aks the user whether he wants to destroy XPE info
01527 
01528 ********************************************************************************************/
01529 
01530 BOOL KernelBitmap::DestroyXPEInfo()
01531 {
01532     if (ActualBitmap==NULL)
01533         return TRUE;
01534 
01535     PORTNOTETRACE("other","KernelBitmap::DestroyXPEInfo - do nothing");
01536 #ifndef EXCLUDE_FROM_XARALX
01537     IXMLDOMDocumentPtr pEdits = NULL;
01538     OILBitmap* pMaster = NULL;
01539     ActualBitmap->GetXPEInfo(pMaster, pEdits);
01540 
01541     if (pEdits==NULL || pMaster==NULL)
01542         return TRUE;
01543 
01544     INT32 iButton = InformWarning(_R(IDS_XPE_DESTROY_MSG), _R(IDS_CONTINUE), _R(IDS_CANCEL));
01545     if (iButton==1)
01546     {
01547         ActualBitmap->DestroyXPEInfo();
01548     }
01549     return (iButton==1);
01550 #else
01551     return TRUE;
01552 #endif
01553 }
01554 
01555 
01556 /********************************************************************************************
01557 
01558 >   void KernelBitmap::ReplaceOILBitmap(LPBYTE pBits, LPBITMAPINFO pInfo)
01559                 
01560     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
01561     Created:    04/02/2004
01562     Inputs:     pBits - pointer to bitmap data
01563                 pInfo - pointer to bitmap info header
01564     Outputs:    -
01565     Returns:    -
01566     Purpose:    Remove the OIL bitmap from memory if it can be constructed from master and edits
01567 
01568 ********************************************************************************************/
01569 
01570 void KernelBitmap::ReplaceOILBitmap(LPBYTE pBits, LPBITMAPINFO pInfo)
01571 {
01572     if (IsDefaultBitmap())
01573     {
01574         // We can't replace the default bitmap so make a new OilBitmap and attach that
01575         CWxBitmap      *pOilBitmap = new CWxBitmap(pInfo, pBits);
01576         if (pOilBitmap && IsLossy())
01577             pOilBitmap->SetAsLossy();
01578         ActualBitmap = OILBitmap::Attach(pOilBitmap);
01579     }
01580     else
01581     {
01582         ActualBitmap->ReplaceBitmap(pBits, pInfo);
01583     }
01584 }
01585 
01586 
01587 /********************************************************************************************
01588 
01589 >   BOOL KernelBitmap::CreateGreyscaleVersion(BOOL ForceGreyBmp = FALSE)
01590 
01591     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
01592     Created:    15/8/96
01593     Purpose:    Creates a greyscale version of this bitmap
01594 
01595 ********************************************************************************************/
01596 
01597 BOOL KernelBitmap::CreateGreyscaleVersion(BOOL ForceGreyBmp)
01598 {
01599     if (ActualBitmap == NULL)
01600         return FALSE;
01601 
01602     ERROR3IF_OILBMP_PTR_INVALID(ActualBitmap,
01603                 "Bitmap Error.  Found a reference to a deleted bitmap.");
01604 
01605     if (!IsGreyscale())
01606     {
01607 //      if (GetBPP() == 8 && !ForceGreyBmp)
01608         if (!ForceGreyBmp)
01609         {
01610             // If the bitmap is already a paletted bitmap, then we don't
01611             // need to generate a greyscale version, 'cus we can use some
01612             // clever palette manipulation
01613             GenerateGreyscaleTable();
01614         }
01615         else
01616         {
01617             // Make a new grey level version of the bitmap
01618             OILBitmap* pOILBmp = DIBUtil::Create8bppGreyscaleBitmap(this);
01619             if (pOILBmp == NULL)
01620                 return FALSE;
01621 
01622             pOILBmp->m_bIsGreyscale = TRUE;
01623             ActualBitmap->SetGreyscaleVersion(pOILBmp);
01624         }
01625     }
01626 
01627     return TRUE;
01628 }
01629 
01630 /********************************************************************************************
01631 
01632 >   BOOL KernelBitmap::DestroyGreyscaleVersion()
01633 
01634     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
01635     Created:    15/8/96
01636     Purpose:    Destroys the greyscale version of this bitmap
01637 
01638 ********************************************************************************************/
01639 
01640 BOOL KernelBitmap::DestroyGreyscaleVersion()
01641 {
01642     if (ActualBitmap == NULL)
01643         return FALSE;
01644 
01645     ERROR3IF_OILBMP_PTR_INVALID(ActualBitmap,
01646                 "Bitmap Error.  Found a reference to a deleted bitmap.");
01647 
01648     return ActualBitmap->DestroyGreyscaleVersion();
01649 }
01650 
01651 /********************************************************************************************
01652 
01653 >   OILBitmap* KernelBitmap::ExtractOILBitmap()
01654 
01655     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
01656     Created:    15/8/96
01657     Purpose:    Extracts the OILBitmap from this kernel bitmap
01658                 AND DELETES THIS KERNEL BITMAP
01659 
01660 ********************************************************************************************/
01661 
01662 OILBitmap* KernelBitmap::ExtractOILBitmap()
01663 {
01664     if (ActualBitmap == NULL)
01665         return NULL;
01666 
01667     ERROR3IF_OILBMP_PTR_INVALID(ActualBitmap,
01668                 "Bitmap Error.  Found a reference to a deleted bitmap.");
01669 
01670     OILBitmap* pBmp = ActualBitmap;
01671 
01672     if (ActualBitmap->IsInGlobalList())
01673         ActualBitmap->RemoveFromGlobalList();
01674 
01675 #ifdef _DEBUG
01676     ActualBitmap->m_bIsAttached = FALSE;
01677 #endif
01678 
01679     m_bDontDeleteActualBitmap = TRUE;
01680     delete this;
01681 
01682     return pBmp;
01683 }
01684 
01685 /********************************************************************************************
01686 
01687 >   OILBitmap* KernelBitmap::GetGreyscaleVersion(BOOL ForceGreyBmp = FALSE)
01688 
01689     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
01690     Created:    15/8/96
01691     Purpose:    Gets the greyscale version of this bitmap
01692 
01693 ********************************************************************************************/
01694 
01695 OILBitmap* KernelBitmap::GetGreyscaleVersion(BOOL ForceGreyBmp)
01696 {
01697     if (ActualBitmap == NULL)
01698         return NULL;
01699 
01700     ERROR3IF_OILBMP_PTR_INVALID(ActualBitmap,
01701                 "Bitmap Error.  Found a reference to a deleted bitmap.");
01702 
01703     if (IsGreyscale())
01704         return ActualBitmap;
01705 
01706     OILBitmap* pGreyBmp = ActualBitmap->GetGreyscaleVersion();
01707     if (pGreyBmp == NULL)
01708     {
01709         // Make a greyscale bitmap
01710         CreateGreyscaleVersion(ForceGreyBmp);
01711     }
01712 
01713     return ActualBitmap->GetGreyscaleVersion();
01714 }
01715 
01716 /********************************************************************************************
01717 
01718 >   void KernelBitmap::GenerateGreyscaleTable()
01719 
01720     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
01721     Created:    15/8/96
01722     Purpose:    -
01723 
01724 ********************************************************************************************/
01725 
01726 void KernelBitmap::GenerateGreyscaleTable()
01727 {
01728 //  if (ActualBitmap == NULL || GetBPP() != 8)
01729     if (ActualBitmap == NULL || GetBPP()>8)
01730         return;
01731 
01732     ActualBitmap->GenerateGreyscaleTable();
01733 }
01734 
01735 /********************************************************************************************
01736 
01737 >   BOOL KernelBitmap::IsUsedInDocument(Document* pDoc, BOOL bIncludeHidden = FALSE)
01738 
01739     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
01740     Created:    15/8/96
01741     Purpose:    Finds if this bitmap is being used in a specified document or not
01742 
01743 ********************************************************************************************/
01744 
01745 BOOL KernelBitmap::IsUsedInDocument(Document* pDoc, BOOL bIncludeHidden)
01746 {
01747     if (ActualBitmap == NULL)
01748         return FALSE;
01749 
01750     ERROR3IF_OILBMP_PTR_INVALID(ActualBitmap,
01751                 "Bitmap Error.  Found a reference to a deleted bitmap.");
01752 
01753     if (HasBeenDeleted())
01754         return OILBitmap::Default->IsUsedInDocument(pDoc, bIncludeHidden);
01755 
01756     return ActualBitmap->IsUsedInDocument(pDoc, bIncludeHidden) || IsXPEMaster();
01757 }
01758 
01759 /********************************************************************************************
01760 
01761 >   BOOL KernelBitmap::IsGreyscale()
01762 
01763     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
01764     Created:    15/8/96
01765     Purpose:    Finds if this bitmap is greyscale or not
01766 
01767 ********************************************************************************************/
01768 
01769 BOOL KernelBitmap::IsGreyscale()
01770 {
01771     if (ActualBitmap == NULL)
01772         return FALSE;
01773 
01774     ERROR3IF_OILBMP_PTR_INVALID(ActualBitmap,
01775                 "Bitmap Error.  Found a reference to a deleted bitmap.");
01776 
01777     if (HasBeenDeleted())
01778         return OILBitmap::Default->IsGreyscale();
01779 
01780     return ActualBitmap->IsGreyscale();
01781 }
01782 
01783 
01784 /********************************************************************************************
01785 
01786 >   BOOL KernelBitmap::IsLossy()
01787 
01788     Author:     Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
01789     Created:    15/8/96
01790     Purpose:    Finds if this bitmap is lossy or not
01791 
01792 ********************************************************************************************/
01793 
01794 BOOL KernelBitmap::IsLossy()
01795 {
01796     if (ActualBitmap == NULL)
01797         return FALSE;
01798 
01799     ERROR3IF_OILBMP_PTR_INVALID(ActualBitmap,
01800                 "Bitmap Error.  Found a reference to a deleted bitmap.");
01801 
01802     if (HasBeenDeleted())
01803         return OILBitmap::Default->IsLossy();
01804 
01805     return ActualBitmap->IsLossy();
01806 }
01807 
01808 
01809 /*******************************************************************************************
01810 >   UINT32 KernelBitmap::GetDelay()
01811 
01812     Author:     Ranbir_Rana (Xara Group Ltd) <camelotdev@xara.com>
01813     Created:    05/01/96
01814     Purpose:    Returns m_AnimDelay for an OilBitmap. 
01815 
01816 ********************************************************************************************/
01817 
01818 UINT32 KernelBitmap::GetDelay()
01819 {
01820     if (ActualBitmap != NULL)
01821         return ActualBitmap->GetBitmapAnimDelay();
01822 
01823     return 0;   
01824 }
01825 
01826 
01827 /********************************************************************************************
01828 
01829 >   void KernelBitmap::SetDelay(UINT32 Delay)
01830 
01831     Author:     Ranbir_Rana (Xara Group Ltd) <camelotdev@xara.com>
01832     Created:    05/01/96
01833     Purpose:    Sets the m_AnimDelay memeber for an OilBitmap. 
01834 
01835 ********************************************************************************************/
01836 void KernelBitmap::SetDelay(UINT32 Delay)
01837 {
01838     if (ActualBitmap != NULL)
01839         ActualBitmap->SetBitmapAnimDelay(Delay);
01840 }
01841 
01842 /*******************************************************************************************
01843 >   BOOL KernelBitmap::GetInterpolation()
01844 
01845     Author:     Andy_Hills (Xara Group Ltd) <camelotdev@xara.com>
01846     Created:    06/10/00
01847     Purpose:    Returns m_bInterpolation for an OilBitmap. 
01848 
01849 ********************************************************************************************/
01850 
01851 BOOL KernelBitmap::GetInterpolation()
01852 {
01853     if (ActualBitmap != NULL)
01854         return ActualBitmap->GetInterpolation();
01855 
01856     return 0;   
01857 }
01858 
01859 
01860 /********************************************************************************************
01861 
01862 >   void KernelBitmap::SetInterpolation(BOOL Delay)
01863 
01864     Author:     Andy_Hills (Xara Group Ltd) <camelotdev@xara.com>
01865     Created:    06/10/00
01866     Purpose:    Sets the m_bInterpolation member for an OilBitmap. 
01867 
01868 ********************************************************************************************/
01869 void KernelBitmap::SetInterpolation(BOOL bInterpolation)
01870 {
01871     if (ActualBitmap != NULL)
01872         ActualBitmap->SetInterpolation(bInterpolation);
01873 }
01874 
01875 /*******************************************************************************************
01876 
01877 >   GIFDisposalMethod KernelBitmap::GetAnimationRestoreType () const
01878 
01879     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01880     Created:    14/04/97
01881     Purpose:    Returns the GIF restore type for an OilBitmap. 
01882 
01883 ********************************************************************************************/
01884 
01885 GIFDisposalMethod KernelBitmap::GetAnimationRestoreType () const
01886 {
01887     if (ActualBitmap != NULL)
01888         return ActualBitmap->GetAnimationRestoreType();
01889 
01890     return GDM_LEAVE;   
01891 }
01892 
01893 /********************************************************************************************
01894 
01895 >   void KernelBitmap::SetAnimationRestoreType(GIFDisposalMethod Type)
01896 
01897     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01898     Created:    14/04/97
01899     Inputs:     new GIF disposal method
01900     Purpose:    Sets the GIF restore type for an OilBitmap. 
01901 
01902 ********************************************************************************************/
01903 
01904 void KernelBitmap::SetAnimationRestoreType(GIFDisposalMethod Type)
01905 {
01906     if (ActualBitmap != NULL)
01907         ActualBitmap->SetAnimationRestoreType(Type);
01908 }
01909 
01910 /********************************************************************************************
01911 
01912 >   void KernelBitmap::SetLeftOffset(UINT32 LeftOffset)
01913 
01914     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01915     Created:    11/06/97
01916     Inputs:     new left offset
01917     Purpose:    Sets the left offset for an OilBitmap. 
01918 
01919 ********************************************************************************************/
01920 
01921 void KernelBitmap::SetLeftOffset(UINT32 LeftOffset)
01922 {
01923     if (ActualBitmap != NULL)
01924         ActualBitmap->SetLeftOffset(LeftOffset);
01925 }
01926 
01927 /********************************************************************************************
01928 
01929 >   UINT32 KernelBitmap::GetLeftOffset() const
01930 
01931     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01932     Created:    11/06/97
01933     Returns:    the current left offset
01934     Purpose:    Gets the left offset for an OilBitmap. 
01935 
01936 ********************************************************************************************/
01937 
01938 UINT32 KernelBitmap::GetLeftOffset() const
01939 {
01940     if (ActualBitmap != NULL)
01941         return ActualBitmap->GetLeftOffset();
01942 
01943     return 0;   
01944 }
01945 
01946 /********************************************************************************************
01947 
01948 >   void KernelBitmap::SetTopOffset(UINT32 TopOffset)
01949 
01950     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01951     Created:    11/06/97
01952     Inputs:     new top offset
01953     Purpose:    Sets the top offset for an OilBitmap. 
01954 
01955 ********************************************************************************************/
01956 
01957 void KernelBitmap::SetTopOffset(UINT32 TopOffset)
01958 {
01959     if (ActualBitmap != NULL)
01960         ActualBitmap->SetTopOffset(TopOffset);
01961 }
01962 
01963 /********************************************************************************************
01964 
01965 >   UINT32 KernelBitmap::GetTopOffset() const
01966 
01967     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01968     Created:    11/06/97
01969     Returns:    the current top offset
01970     Purpose:    Gets the top offset for an OilBitmap. 
01971 
01972 ********************************************************************************************/
01973 
01974 UINT32 KernelBitmap::GetTopOffset() const
01975 {
01976     if (ActualBitmap != NULL)
01977         return ActualBitmap->GetTopOffset();
01978 
01979     return 0;   
01980 }
01981 
01982 /********************************************************************************************
01983 
01984 >   BOOL KernelBitmap::IsBrowserPalette() const
01985 
01986     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01987     Created:    16/06/97
01988     Returns:    True if the bitmap has a browser compatible palette.
01989     Purpose:    To see if the palette attached to this bitmap is browser compatible.
01990 
01991 ********************************************************************************************/
01992 
01993 BOOL KernelBitmap::IsBrowserPalette() const
01994 {
01995     if (ActualBitmap != NULL)
01996         return ActualBitmap->IsBrowserPalette();
01997 
01998     return FALSE;   
01999 }
02000 
02001 /********************************************************************************************
02002 
02003 >   BOOL KernelBitmap::ArePalettesTheSame(const LPLOGPALETTE pLogPalette, const INT32 TransColour = -1)
02004 
02005     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02006     Created:    03/07/97
02007     Inputs:     pLogPalette     A log palette to check the palette against
02008                 TransColour     The transparent colour in the palette
02009     Returns:    True if the bitmap has the same palette as the LOG palette.
02010     Purpose:    To see if the palette attached to this bitmap is browser compatible.
02011                 It runs through the colours in a browser palette and checks to see if they
02012                 are all present. The ordering is not checked and so the palette may be
02013                 different from the one that we actually use.
02014 
02015 ********************************************************************************************/
02016 
02017 BOOL KernelBitmap::ArePalettesTheSame(const LPLOGPALETTE pLogPalette, const INT32 TransColour)
02018 {
02019     if (ActualBitmap != NULL)
02020         return ActualBitmap->ArePalettesTheSame(pLogPalette, TransColour);
02021 
02022     return FALSE;   
02023 }
02024 
02025 /********************************************************************************************
02026 
02027 >   UINT32 KernelBitmap::GetHorizontalDPI() const
02028 
02029     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02030     Created:    17/06/97
02031     Returns:    The Horizontal DPI of this bitmap
02032     Purpose:    Retrieve information on this bitmap
02033 
02034 ********************************************************************************************/
02035 
02036 UINT32 KernelBitmap::GetHorizontalDPI() const
02037 {
02038     if (ActualBitmap != NULL)
02039         return ActualBitmap->GetHorizontalDPI();
02040 
02041     return 96;  
02042 }
02043 
02044 /********************************************************************************************
02045 
02046 >   UINT32 KernelBitmap::GetVerticalDPI() const
02047 
02048     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02049     Created:    17/06/97
02050     Returns:    The Vertical DPI of this bitmap
02051     Purpose:    Retrieve information on this bitmap
02052 
02053 ********************************************************************************************/
02054 
02055 UINT32 KernelBitmap::GetVerticalDPI() const
02056 {
02057     if (ActualBitmap != NULL)
02058         return ActualBitmap->GetVerticalDPI();
02059 
02060     return 96;  
02061 }
02062 
02063 /********************************************************************************************
02064 
02065 >   void KernelBitmap::SetName(String_256& NewName)
02066 
02067     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02068     Created:    20/06/97
02069     Inputs:     The new name of this bitmap
02070     Purpose:    Set information on this bitmap
02071 
02072 ********************************************************************************************/
02073 
02074 void KernelBitmap::SetName(String_256& NewName)
02075 {
02076     if (ActualBitmap != NULL)
02077     {
02078         ActualBitmap->SetName(NewName);
02079         return;
02080     }
02081 
02082     return; 
02083 }
02084 
02085 /********************************************************************************************
02086 
02087 >   String_256& KernelBitmap::GetName()
02088 
02089     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02090     Created:    20/06/97
02091     Returns:    The name of this bitmap
02092     Purpose:    Retrieve information on this bitmap
02093 
02094 ********************************************************************************************/
02095 
02096 String_256& KernelBitmap::GetName()
02097 {
02098     if (ActualBitmap != NULL)
02099         return ActualBitmap->GetName();
02100 
02101 
02102     // In the "oh no where's the ActualBitmap" case
02103     // The old code used to be:
02104     //      return String_256("");
02105     // This static dummy object is used for returning in the error case
02106     // The original used to return a ptr to a local variable, which is a tad dangerous.
02107     // This solution is not ideal, because there's a permanent instance of an object
02108     // that will probably never be used.
02109     static String_256 Dummy("");
02110     return Dummy;
02111 }   
02112 
02113 /********************************************************************************************
02114 
02115 >   LPBITMAPINFO KernelBitmap::GetBitmapInfo()
02116 
02117     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02118     Created:    03/07/97
02119     Returns:    The BITMAPINFO for this bitmap or null.
02120     Purpose:    To get at the BITMAPINFO that this bitmap may have.
02121                 
02122                 BITMAPINFO  consists of:-
02123                         BITMAPINFOHEADER    bmiHeader;
02124                         RGBQUAD             bmiColors[1];
02125                 This is the real bitmap info header giving the overall size of the export
02126 
02127     Note:       Only use from Winoil code
02128 
02129 ********************************************************************************************/
02130 
02131 LPBITMAPINFO KernelBitmap::GetBitmapInfo()
02132 {
02133     if (ActualBitmap != NULL)
02134         return ActualBitmap->GetBitmapInfo();
02135 
02136     return NULL;
02137 }
02138 
02139 /********************************************************************************************
02140 
02141 >   LPRGBQUAD KernelBitmap::GetPaletteForBitmap()
02142 
02143     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02144     Created:    03/07/97
02145     Returns:    The palette for this bitmap or null.
02146     Purpose:    To get at the RGBQUAD palette that this bitmap may have.
02147                 
02148                 BITMAPINFO  consists of:-
02149                         BITMAPINFOHEADER    bmiHeader;
02150                         RGBQUAD             bmiColors[1];
02151                 This is the real bitmap info header giving the overall size of the export
02152 
02153     Note:       Only use from Winoil code
02154 
02155 ********************************************************************************************/
02156 
02157 LPRGBQUAD KernelBitmap::GetPaletteForBitmap()
02158 {
02159     if (ActualBitmap != NULL)
02160         return ActualBitmap->GetPaletteForBitmap();
02161 
02162     return NULL;
02163 }
02164 
02165 /********************************************************************************************
02166 
02167 >   LPBITMAPINFOHEADER KernelBitmap::GetBitmapInfoHeader()
02168 
02169     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02170     Created:    03/07/97
02171     Returns:    The bitmap header for this bitmap or null.
02172     Purpose:    To get at the BITMAPINFOHEADER that this bitmap should have.
02173                 
02174                 BITMAPINFO  consists of:-
02175                         BITMAPINFOHEADER    bmiHeader;
02176                         RGBQUAD             bmiColors[1];
02177 
02178     Note:       Only use from Winoil code
02179 
02180 ********************************************************************************************/
02181 
02182 LPBITMAPINFOHEADER KernelBitmap::GetBitmapInfoHeader()
02183 {
02184     if (ActualBitmap != NULL)
02185         return ActualBitmap->GetBitmapInfoHeader();
02186 
02187     return NULL;
02188 }
02189 
02190 
02191 
02192 #ifdef _DEBUG
02193 /********************************************************************************************
02194 
02195 >   BOOL KernelBitmap::AttachDebugCopyToCurrentDocument(String_256 strName)
02196 
02197     Author:     Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com>
02198     Created:    12/07/2000
02199 
02200     Inputs:     strName     the name you want the bitmap to have in the bitmap gallery.
02201 
02202     Outputs:    Attaches a copy of this bitmap to the bitmap gallery.
02203 
02204     Returns:    TRUE if successful,
02205                 FALSE + TRACE output otherwise.
02206 
02207     Purpose:    When debugging, it's often useful to see what sort of bitmap you have.
02208                 This method attaches a copy of this KernelBitmap to the current document,
02209                 so that it will show up in the bitmap gallery.
02210 
02211     Notes:      This is DEBUG code - DON'T change it to compile for release, as it ISN'T
02212                 TESTED and probably ISN'T STABLE or misses some initialisation somewhere.
02213                 Go figure out how to do what you want and write your own function or use
02214                 someone else's release code.
02215 
02216     Errors:     Will return FALSE and TRACE output if anything goes wrong.
02217 
02218 ********************************************************************************************/
02219 BOOL KernelBitmap::AttachDebugCopyToCurrentDocument(String_256 strName)
02220 {
02221     Document* pDoc = Document::GetCurrent();
02222     if (pDoc == NULL)
02223     {
02224         TRACEALL( _T("KernelBitmap::AttachDebugCopyToCurrentDocument; no current Doc!\n") );
02225         return FALSE;
02226     }
02227 
02228     KernelBitmap*   pCopyBitmap = DIBUtil::CopyKernelBitmap(this, FALSE);
02229     if (pCopyBitmap == NULL)
02230     {
02231         TRACEALL( _T("KernelBitmap::AttachDebugCopyToCurrentDocument; Couldn't create copy Kernel bitmap!\n") );
02232         return FALSE;
02233     }
02234 
02235     OILBitmap*      pOILCopy    = (OILBitmap*)pCopyBitmap->GetActualBitmap();
02236     if (pOILCopy == NULL)
02237     {
02238         TRACEALL( _T("KernelBitmap::AttachDebugCopyToCurrentDocument; Couldn't get OIL bmp from Kernel bmp!\n") );
02239         return FALSE;
02240     }
02241 
02242     pOILCopy->SetName(strName);
02243     pCopyBitmap->Attach(pDoc->GetBitmapList());
02244 
02245     return TRUE;
02246 }
02247 #endif
02248 
02249 
02250 
02251 /********************************************************************************************
02253 ********************************************************************************************/
02254 
02255 
02256 
02257 /********************************************************************************************
02258 
02259 >   OILBitmap::OILBitmap()
02260                     
02261     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
02262     Created:    ?/8/94
02263     Purpose:    Constructor. Sets USage count to zero.
02264 
02265 ********************************************************************************************/
02266 
02267 OILBitmap::OILBitmap()
02268 {
02269     m_bTemp = TRUE;     // Not in global list yet
02270 
02271     m_pColourVersion = NULL;
02272     m_pGreyscaleVersion = NULL;
02273     m_pContonePalette = NULL;
02274     m_pGreyscaleTable = NULL;
02275 
02276     m_bIsAFractal = FALSE;
02277     m_bIsGreyscale = FALSE;
02278     m_bIsLossy = FALSE;
02279 
02280     SetBitmapAnimDelay(10);
02281     SetAnimationRestoreType(GDM_LEAVE);
02282     SetInterpolation(TRUE);
02283 
02284     m_LeftOffset = 0;
02285     m_TopOffset = 0;
02286 
02287 PORTNOTE("other","Removed edit list")
02288 #ifndef EXCLUDE_FROM_XARALX
02289     m_pEditList = NULL;
02290 #endif
02291     m_pMasterBitmap = NULL;
02292 
02293     m_bUsedByBrush = FALSE;
02294 #if !defined(EXCLUDE_FROM_RALPH)
02295     m_BitmapName.Load(_R(IDS_BITMAPNAME));
02296 #else
02297     m_BitmapName = TEXT("Bitmap");
02298 #endif
02299     m_bNeedsXPERebuild = FALSE;
02300     m_bHidden = FALSE;
02301 
02302 #ifdef _DEBUG
02303     m_bIsAttached = FALSE;
02304 #endif
02305 }
02306 
02307 /********************************************************************************************
02308 
02309 >   OILBitmap::~OILBitmap()
02310                     
02311     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
02312     Created:    8/8/96
02313     Purpose:    Destructor.
02314 
02315 ********************************************************************************************/
02316 
02317 OILBitmap::~OILBitmap()
02318 {
02319 PORTNOTE("other","Removed edit list")
02320 #ifndef EXCLUDE_FROM_XARALX
02321     if (m_pEditList)
02322     {
02323         m_pEditList = NULL;     // This is a smart pointer so just allow it to die naturally
02324     }
02325 #endif
02326 
02327     if (m_pColourVersion)
02328     {
02329         ERROR3IF(m_pColourVersion->m_pGreyscaleVersion != this, "Bad greyscale version");
02330 
02331         // This must be a greyscale version of a colour bmp
02332         m_pColourVersion->m_pGreyscaleVersion = NULL;
02333     }
02334 
02335     // Ensure this bitmap is not in the global bitmap list
02336     RemoveFromGlobalList();
02337 
02338     if (m_pContonePalette)
02339         DestroyContonePalette();
02340 
02341     if (m_pGreyscaleVersion)
02342         DestroyGreyscaleVersion();
02343 
02344     // To do :- We could do a debug check here, to ensure that there are no references 
02345     //          to this bitmap anywhere
02346 }
02347 
02348 /********************************************************************************************
02349 
02350 >   OILBitmap *OILBitmap::Attach( OILBitmap* pTheOILBitmap, BOOL Temp )
02351                 
02352     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
02353     Created:    ?/8/94
02354     Inputs:     A pointer to an OILBitmap.
02355     Purpose:    Increases the usage count on the OILBitmap. Designed to be called from
02356                 KernelBitmap code.
02357     Returns:    The WhichOne pointer if it worked, or NULL if it failed.
02358     Errors:     A NULL return means that the WhichOne pointer was also NULL. SetError will
02359                 NOT be called.
02360     SeeAlso:    OILBitmap::Detach
02361     Scope:      Static
02362 
02363 ********************************************************************************************/
02364 
02365 OILBitmap *OILBitmap::Attach( OILBitmap* pTheOILBitmap, BOOL Temp )
02366 {
02367     if (pTheOILBitmap == NULL)
02368         return NULL;
02369 
02370 #ifdef _DEBUG
02371 
02372     ERROR3IF_OILBMP_PTR_INVALID(pTheOILBitmap,
02373                 "Bitmap Error.  Trying to attach a deleted bitmap.");
02374 
02375     // Check for illegal things ...
02376     // Trap an attempt to attach a temp bitmap to more than one KernelBitmap
02377     if (pTheOILBitmap->m_bTemp && !pTheOILBitmap->m_bIsAFractal)
02378     {
02379         //ERROR3IF(pTheOILBitmap->m_bIsAttached, "Trying to attach a temp bitmap that is already attached");
02380         // Stefans change so that if IsNew is NULL in TryAndUseExistingKernelBitmap it will set the temp
02381         // flag means that this check goes off on animated bitmaps. Downgraded to trace all.
02382         if (pTheOILBitmap->m_bIsAttached)
02383             TRACEALL( _T("Trying to attach a temp bitmap that is already attached\n") );
02384     }
02385 
02386     pTheOILBitmap->m_bIsAttached = TRUE;
02387 
02388 #endif
02389 
02390     if (!Temp && !pTheOILBitmap->IsInGlobalList())
02391     {
02392         ERROR3IF(pTheOILBitmap->IsAFractal(), "Someone's trying to attach a fractal to the global list !");
02393 
02394         if (!pTheOILBitmap->IsAFractal())
02395         {
02396             // It's not in the Global list yet, so add it now ...
02397 
02398             // First ensure the bitmap name is unique
02399             GetApplication()->GetGlobalBitmapList()->MakeNameUnique(&(pTheOILBitmap->m_BitmapName));
02400 
02401             // and the add it to the global bitmap list
02402             GetApplication()->GetGlobalBitmapList()->AddItem(pTheOILBitmap);
02403 
02404             // and flag that it's in the list
02405             pTheOILBitmap->m_bTemp = FALSE;
02406 
02407             // And set the flag if it's a greyscale bitmap
02408             // we can't tell if it is or not in WEBSTER-Martin-14/01/97
02409             // Code now in DIBUtil 10/11/97 Neville
02410 //#ifdef WEBSTER
02411 //          pTheOILBitmap->m_bIsGreyscale = FALSE;
02412 //#else
02413             pTheOILBitmap->m_bIsGreyscale = DIBUtil::IsGreyscaleBitmap(pTheOILBitmap);
02414 //#endif //WEBSTER
02415         }
02416     }
02417 
02418     return pTheOILBitmap;
02419 }
02420 
02421 /********************************************************************************************
02422 
02423 >   BOOL OILBitmap::RemoveFromGlobalList()
02424             
02425     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
02426     Created:    22/8/96
02427     Purpose:    -
02428     Returns:    -
02429     Errors:     -
02430 
02431 ********************************************************************************************/
02432 
02433 BOOL OILBitmap::RemoveFromGlobalList()
02434 {
02435     if (!IsInGlobalList())
02436         return FALSE;       // Not in the list
02437 
02438     m_bTemp = TRUE;
02439 
02440     if (GetApplication()->GetGlobalBitmapList()->RemoveItem(this) == NULL)
02441     {
02442         ERROR3("Bitmap not found in Global bitmap list");
02443         return FALSE;
02444     }
02445 
02446     return TRUE;
02447 }
02448 
02449 
02450 /********************************************************************************************
02451 
02452 >   BOOL OILBitmap::BuildContonePalette(DocColour &StartCol, DocColour &EndCol,
02453                                             EFFECTTYPE Effect, View *ScopeView)
02454 
02455     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com> or Will? (Fixed to handle colour seps, Jason)
02456     Created:    ? (8/7/96)
02457 
02458     Inputs:     StartCol - The start colour for the palette (entry 0)
02459                 EndCol - The end colour for the palette (entry 255)
02460 
02461                 Effect - The grad fill effect (Mix, Rainbow, Alt-rainbow) to use
02462 
02463                 ScopeView - The view to which this palette will be rendered. Used to
02464                 determine current colour correction/separation settings for composite
02465                 preview and separated views. Can be null, but it won't do any
02466                 of your fancy colour seperationness for you.
02467 
02468     Purpose:    Builds a contone (graduated) palette between the start and end colours
02469                 given, using the given effect (mix, rainbow, alt-rainbow), for output
02470                 through the given view. See GradTable32::BuildGraduatedPalette for details
02471                 of how the palette is built.
02472 
02473 ********************************************************************************************/
02474 
02475 BOOL OILBitmap::BuildContonePalette(DocColour &StartCol, DocColour &EndCol,
02476                                         EFFECTTYPE Effect, View *ScopeView)
02477 {
02478     UINT32 bpp = GetBPP();
02479 
02480     if (bpp > 8)
02481         // Can't do contone palette for this image
02482         return FALSE;
02483 
02484     RGBQUAD* pPalette = (RGBQUAD*)CCMalloc(256 * sizeof(RGBQUAD));
02485     if (pPalette == NULL)
02486         return FALSE;
02487 
02488     // Allocate the palette array (we always allocate enough for biggest (8bpp) palette)
02489 //  m_pContonePalette = (RGBQUAD *) CCMalloc(256 * sizeof(RGBQUAD));
02490 //  if (m_pContonePalette == NULL)
02491 //      // Out of memory.
02492 //      return FALSE;
02493 
02494     // Fill in the palette (we always use RGB space for now)
02495     INT32 NumCols = 256;
02496     switch (bpp)
02497     {
02498         case 1:
02499             NumCols = 2;
02500             break;
02501 
02502         case 2:
02503             NumCols = 4;
02504             break;
02505 
02506 //      case 4:
02507 //          // 4bpp images are expanded to 8bpp otherwise they don't work on
02508 //          // some PostScript printers.
02509 //      case 8:
02510 //      default:
02511 //          NumCols = 256;
02512 //          break;
02513     }
02514 
02515     GradTable32::BuildGraduatedPalette(StartCol, EndCol, ScopeView, Effect, NumCols, pPalette);
02516 
02517     BYTE* pGreyTable = GetGreyscaleTable();
02518     if (pGreyTable)
02519     {
02520         m_pContonePalette = (RGBQUAD *) CCMalloc(256 * sizeof(RGBQUAD));
02521         if (m_pContonePalette == NULL)
02522             return(FALSE);
02523 
02524         // Copy the entries from the contone palette into the new one,
02525         // using the Grey table as a guide
02526         for (INT32 i=0; i<256; i++)
02527         {
02528             m_pContonePalette[i] = pPalette[pGreyTable[i]];
02529         }
02530 
02531         CCFree(pPalette);
02532     }
02533     else
02534     {
02535         m_pContonePalette = pPalette;
02536     }
02537 
02538     return(TRUE);
02539 }
02540 
02541 
02542 
02543 /********************************************************************************************
02544 
02545 >   DocColour OILBitmap::GetContonePaletteEntry(UINT32 PaletteIndex)
02546                     
02547     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> ?
02548     Created:    ?/7/96
02549     Purpose:    Read an entry from the Contone Palette
02550 
02551 ********************************************************************************************/
02552 
02553 DocColour OILBitmap::GetContonePaletteEntry(UINT32 PaletteIndex)
02554 {
02555     ERROR3IF(m_pContonePalette == NULL, "No contone palette to get data from!");
02556     if (m_pContonePalette == NULL)
02557         return DocColour(COLOUR_WHITE);     // Error - return arbitrary colour
02558 
02559     // Ok, get the entry and convert it to a DocColour
02560     return DocColour((INT32) m_pContonePalette[PaletteIndex].rgbRed,
02561                      (INT32) m_pContonePalette[PaletteIndex].rgbGreen,
02562                      (INT32) m_pContonePalette[PaletteIndex].rgbBlue);
02563 }
02564 
02565 
02566 /********************************************************************************************
02567 
02568 >   BOOL OILBitmap::DestroyContonePalette()
02569                     
02570     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> ?
02571     Created:    ?/7/96
02572     Purpose:    Destroys the contone palette
02573 
02574 ********************************************************************************************/
02575 
02576 BOOL OILBitmap::DestroyContonePalette()
02577 {
02578     // (ChrisG 4/1/01) - Only delete the contone palette if we actually have one.
02579     if (m_pContonePalette != NULL)
02580     {
02581         // Free and NULL our palette array pointer.
02582         CCFree(m_pContonePalette);
02583         m_pContonePalette = NULL;
02584     }
02585     return TRUE;
02586 }
02587 
02588 
02589 /********************************************************************************************
02590 
02591 >   BOOL OILBitmap::SetGreyscaleVersion(OILBitmap* pOILBmp)
02592 
02593     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
02594     Created:    15/8/96
02595     Purpose:    Creates a greyscale version of this bitmap
02596 
02597 ********************************************************************************************/
02598 
02599 BOOL OILBitmap::SetGreyscaleVersion(OILBitmap* pOILBmp)
02600 {
02601     ERROR3IF(pOILBmp && !pOILBmp->IsGreyscale(), "SetGreyscale called with non-grey bitmap");
02602 
02603     DestroyGreyscaleVersion();
02604 
02605     m_pGreyscaleVersion = pOILBmp;
02606     m_pGreyscaleVersion->m_pColourVersion = this;
02607 
02608 //  GreyscaleBitmapList* pGreyList = 
02609 //      GetApplication()->GetGlobalBitmapList()->GetGreyscaleBitmapList();
02610     
02611 //  if (pGreyList)
02612 //      pGreyList->AddItem(m_pGreyscaleVersion);
02613 
02614     return TRUE;
02615 }
02616 
02617 /********************************************************************************************
02618 
02619 >   BOOL OILBitmap::DestroyGreyscaleVersion()
02620 
02621     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
02622     Created:    15/8/96
02623     Purpose:    Destroys the greyscale version of this bitmap
02624 
02625 ********************************************************************************************/
02626 
02627 BOOL OILBitmap::DestroyGreyscaleVersion()
02628 {
02629     if (m_pGreyscaleVersion == NULL)
02630         return TRUE;
02631 
02632     ERROR3IF(m_pGreyscaleVersion->m_pColourVersion == NULL, "Greyscale bitmap has no colour pointer");
02633 //  GreyscaleBitmapList* pGreyList = 
02634 //      GetApplication()->GetGlobalBitmapList()->GetGreyscaleBitmapList();
02635     
02636 //  if (pGreyList)
02637 //      pGreyList->RemoveItem(m_pGreyscaleVersion);
02638 
02639     delete m_pGreyscaleVersion;
02640     m_pGreyscaleVersion = NULL;
02641     return TRUE;
02642 }
02643 
02644 /********************************************************************************************
02645 
02646 >   virtual void OILBitmap::SetOriginalFile(void* pFileBuffer = NULL, 
02647                                             BaseBitmapFilter* pImportFilter = NULL)
02648                 
02649     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
02650     Created:    8/8/96
02651 
02652     Inputs:     pFileBuffer, a pointer to a buffer containing the original file.
02653                 pImportFilter, pointer to the filter to use to decode the bitmap
02654 
02655     Purpose:    Sets the original bitmap file associated with this reference.
02656 
02657     Notes:      The input file buffer should be CCMalloc'd, and will be CCFree'd when the
02658                 reference is destroyed, or changed to another buffer.
02659 
02660 ********************************************************************************************/
02661 
02662 void OILBitmap::SetOriginalSource(BitmapSource* pSource, BaseBitmapFilter* pImportFilter)
02663 {
02664     // Let the reference do the hard work ...
02665     m_OriginalBitmap.SetOriginalSource(pSource, pImportFilter);
02666 }
02667 
02668 /********************************************************************************************
02669 
02670 >   virtual BOOL OILBitmap::GetOriginalSource(BitmapSource** pSource = NULL
02671                                             BaseBitmapFilter** ppImportFilter = NULL)
02672                 
02673     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
02674     Created:    8/8/96
02675 
02676     Inputs:     pSource, ptr to a BitmapSource ptr to update to point at the BitmapSource
02677                 ppFilterName, ptr to a BaseBitmapFilter ptr to update to point at the filter 
02678                 to use to decode the bitmap
02679                 
02680                 If both these inputs are NULL, then the function will simply return
02681                 whether an original file exists or not.
02682 
02683     Outputs:    The input pointers are set if an original file is available, otherwise they
02684                 are left unchanged.
02685 
02686     Returns:    TRUE, if an original file is available, and the pointers were set if non NULL.
02687                 FALSE, if no orginal files is available.
02688 
02689     Purpose:    Gets the original bitmap file buffer associated with this reference.
02690 
02691 ********************************************************************************************/
02692 
02693 BOOL OILBitmap::GetOriginalSource(BitmapSource** pSource, BaseBitmapFilter** ppImportFilter)
02694 {
02695     // Let the reference do the hard work ...
02696     return m_OriginalBitmap.GetOriginalSource(pSource, ppImportFilter);
02697 }
02698 
02699 
02700 
02701 
02702 
02703 /****************************************************************************
02704 
02705 >   BOOL OILBitmap::IsUsedByNode(Node* pNode)
02706 
02707     Author:     Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
02708     Created:    21/07/2005
02709 
02710     Inputs:     pNode       - pointer to a Node
02711     Returns:    TRUE if ok, FALSE if bother
02712     Purpose:    Determines if this bitmap is used by the specified node
02713 
02714 ****************************************************************************/
02715 
02716 BOOL OILBitmap::IsUsedByNode(Node* pNode)
02717 {
02718     INT32 Count = 0;
02719 
02720     // Does this node have any bitmaps in it ?
02721     KernelBitmap* pBitmap = pNode->EnumerateBitmaps(Count++);
02722 
02723     while (pBitmap != NULL)
02724     {
02725         // Check for a deleted bitmap
02726         if (pBitmap->HasBeenDeleted())
02727         {
02728             // Use the default bitmap instead
02729             pBitmap = pBitmap->GetParentBitmapList()->FindDefaultBitmap();
02730 
02731             // There should always be a default bitmap at the start of the list
02732             ERROR2IF(pBitmap == NULL, 0L, "Couldn't find the default bitmap");
02733         }
02734 
02735         // Found a bitmap reference, so ...
02736         // .. is it the same as this bitmap
02737         if (pBitmap->ActualBitmap == this)
02738         {
02739             return TRUE;    // Yep, this bitmap is being used
02740         }
02741         
02742         pBitmap = pNode->EnumerateBitmaps(Count++);             
02743     }
02744 
02745     return(FALSE);
02746 }
02747 
02748 
02749 
02750 
02751 /****************************************************************************
02752 
02753 >   BOOL OILBitmap::IsUsedByChildren(Node* pNode, BOOL bIncludeHidden)
02754 
02755     Author:     Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
02756     Created:    21/07/2005
02757 
02758     Inputs:     pNode       - pointer to a Node
02759                 bIncludeHidden- 
02760     Returns:    TRUE if ok, FALSE if bother
02761     Purpose:    Determines if this bitmap is used by the children of the 
02762                 specified node (or their children etc)
02763 
02764 ****************************************************************************/
02765 
02766 BOOL OILBitmap::IsUsedByChildren(Node* pNode, BOOL bIncludeHidden)
02767 {
02768     Node* pChild = pNode->FindFirstChild();
02769 
02770     while (pChild != NULL)
02771     {
02772         if (pChild->IsNodeHidden())
02773         {
02774             if (bIncludeHidden)
02775             {
02776                 Node* pTestNode = ((NodeHidden*)pChild)->HiddenNd;
02777 
02778                 if (IsUsedByNode(pTestNode))
02779                     return(TRUE);
02780 
02781                 if (pTestNode->FindFirstChild() && IsUsedByChildren(pTestNode, bIncludeHidden))
02782                     return(TRUE);
02783             }
02784         }
02785         else
02786         {
02787             if (pChild->FindFirstChild() && IsUsedByChildren(pChild, bIncludeHidden))
02788                 return(TRUE);
02789 
02790             if (IsUsedByNode(pChild))
02791                 return(TRUE);
02792         }
02793 
02794         pChild = pChild->FindNext();
02795     }
02796 
02797     return(FALSE);
02798 }
02799 
02800 
02801 
02802 /********************************************************************************************
02803 
02804 >   BOOL OILBitmap::IsUsedInDocument(Document* pDoc, BOOL bIncludeHidden = FALSE)
02805 
02806     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
02807     Created:    15/8/96
02808     Purpose:    Finds if this bitmap is being used in a specified document or not
02809 
02810 ********************************************************************************************/
02811 
02812 BOOL OILBitmap::IsUsedInDocument(Document* pDoc, BOOL bIncludeHidden)
02813 {
02814     // Scan the document's tree for bitmap references
02815     Node* pNode = Node::DocFindFirstDepthFirst(pDoc);
02816     while (pNode != NULL)
02817     {
02818         // Handle hidden nodes
02819         if (pNode->IsNodeHidden())
02820         {
02821             if (bIncludeHidden)
02822             {
02823                 Node* pTestNode = ((NodeHidden*)pNode)->HiddenNd;
02824                 if (IsUsedByNode(pTestNode))
02825                     return(TRUE);
02826 
02827                 if (pTestNode->FindFirstChild() && IsUsedByChildren(pTestNode, bIncludeHidden))
02828                     return(TRUE);
02829             }
02830         }
02831         else
02832         {
02833             if (IsUsedByNode(pNode))
02834                 return(TRUE);
02835         }
02836 
02837         // Move onto the next node in the tree
02838         pNode = pNode->DocFindNextDepthFirst(); 
02839     }
02840 
02841     return FALSE;
02842 }
02843 
02844 /********************************************************************************************
02845 
02846 >   BOOL OILBitmap::InvalidateAllReferences(Document* pDoc)
02847 
02848     Author:     Andy_Hills (Xara Group Ltd) <camelotdev@xara.com>, adapted from IsUsedInDocument above
02849     Created:    12-10-00
02850     Purpose:    Called when the interpolation setting is changed.
02851                 Determines whether this bitmap is being used in the specified document.
02852                 All references to the bitmap (e.g. shapes with bitmap fill) are invalidated
02853                 so that they will be redrawn with the new interpolation setting.
02854 
02855 ********************************************************************************************/
02856 
02857 BOOL OILBitmap::InvalidateAllReferences(Document* pDoc)
02858 {
02859     // Scan the document's tree for bitmap references
02860     Node* pNode = Node::DocFindFirstDepthFirst(pDoc);
02861     while (pNode != NULL)
02862     {
02863         // Ignore hidden nodes
02864         if (!pNode->IsNodeHidden())
02865         {
02866             INT32 Count = 0;
02867 
02868             // Does this node have any bitmaps in it ?
02869             KernelBitmap* pBitmap = pNode->EnumerateBitmaps(Count++);
02870 
02871             while (pBitmap != NULL)
02872             {
02873                 ERROR2IF(pBitmap->GetParentBitmapList() == NULL, 0L, "Bitmap has no parent list");
02874                 ERROR2IF(pBitmap->GetParentBitmapList()->GetParentDocument() != pDoc, 0L, "Document mismatch");
02875                     
02876                 // Check for a deleted bitmap
02877                 if (pBitmap->HasBeenDeleted())
02878                 {
02879                     // Use the default bitmap instead
02880                     pBitmap = pBitmap->GetParentBitmapList()->FindDefaultBitmap();
02881 
02882                     // There should always be a default bitmap at the start of the list
02883                     ERROR2IF(pBitmap == NULL, 0L, "Couldn't find the default bitmap");
02884                 }
02885 
02886                 // Found a bitmap reference, so ...
02887                 // .. is it the same as this bitmap
02888                 if (pBitmap->ActualBitmap == this)
02889                 {
02890                     // We've found a node which refers to 'this' bitmap.
02891                     // We need to find the bounding rectangle of the object which has
02892                     // the bitmap property, so we can invalidate that area of the screen.
02893                     
02894                     // get a copy of the current node pointer
02895                     Node* pCurrentNode = pNode;
02896 
02897                     // if this is a bitmap fill or bitmap transparency...
02898                     if( pCurrentNode->IsAnAttribute() )
02899                     {
02900                         // ...then get the parent instead
02901                         pCurrentNode = pNode->FindParent();
02902                     }
02903 
02904                     // Invalidate it so that it will be redrawn.
02905                     if( pCurrentNode->IsBounded() )
02906                     {
02907                         // Now we have either a bitmap, or an object which has a bitmap
02908                         // fill/transparency attribute.
02909 
02910                         // cast the node to a NodeRenderableBounded
02911                         NodeRenderableBounded* pBoundedNode = (NodeRenderableBounded*) pCurrentNode;
02912                         
02913                         // get the spread of the node
02914                         Spread* pSpread = NULL;
02915                         pSpread = pBoundedNode->FindParentSpread();
02916                         ERROR3IF( (pSpread==NULL), "OILBitmap::InvalidateAllReferences - can't determine node's parent spread" );
02917 
02918                         // force it to be redrawn
02919                         Document::GetSelected()->ForceRedraw(pSpread, pBoundedNode->GetBoundingRect(), FALSE, pBoundedNode, FALSE);
02920                     }
02921                 }
02922                 
02923                 pBitmap = pNode->EnumerateBitmaps(Count++);             
02924             }
02925         }
02926 
02927         // Move onto the next node in the tree
02928         pNode = pNode->DocFindNextDepthFirst(); 
02929     }
02930 
02931     return FALSE;
02932 }
02933 
02934 /********************************************************************************************
02935 
02936 >   UINT32 OILBitmap::GetBitmapSize()
02937 
02938     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
02939     Created:    15/8/96
02940     Purpose:    Finds the size in bytes, of this bitmap
02941 
02942 ********************************************************************************************/
02943 
02944 UINT32 OILBitmap::GetBitmapSize()
02945 {
02946     BitmapInfo Info;
02947     Info.MemoryUsed = 0;
02948 
02949     // Get the bitmap Info
02950     GetInfo(&Info);
02951 
02952     return Info.MemoryUsed;
02953 }
02954 
02955 
02956 /********************************************************************************************
02957 
02958 >   void OILBitmap::SetXPEInfo(OILBitmap* pMasterBitmap, IXMLDOMDocumentPtr pNewEditList)
02959                 
02960     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
02961     Created:    28/01/2004
02962 
02963     Inputs:     pNewEditList - pointer to XML edit list document to be stored with this bitmap
02964 
02965     Purpose:    Sets the XPE edit list document for this bitmap.
02966 
02967 ********************************************************************************************/
02968 
02969 PORTNOTE("other","Removed OILBitmap::SetXPEInfo")
02970 #ifndef EXCLUDE_FROM_XARALX
02971 void OILBitmap::SetXPEInfo(OILBitmap* pMasterBitmap, IXMLDOMDocumentPtr pNewEditList)
02972 {
02973 //  ERROR3IF(pMasterBitmap==NULL || pNewEditList==NULL,
02974 //              "Bitmap Error. Either master pointer or edit list NULL in SetXPEInfo");
02975 
02976     m_pMasterBitmap = pMasterBitmap;
02977     m_pEditList = pNewEditList;
02978 }
02979 #endif
02980 
02981 /********************************************************************************************
02982 
02983 >   void OILBitmap::GetXPEInfo(OILBitmap*& refMasterBitmap,
02984                                   IXMLDOMDocumentPtr& refEditList,
02985                                   BOOL bEnsureList)
02986                 
02987     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
02988     Created:    28/01/2004
02989     Inputs:     -
02990     Outputs:    Updates the passed-in reference variables!!!
02991                 refMasterBitmap updated to contain pointer to the master bitmap for this bitmap
02992                 refEditList updated to contain pointer the edits list for this bitmap
02993     Returns:    Pointer to XML document containing edit list for this bitmap.
02994     Purpose:    Gets the stored XPE information for this bitmap.
02995 
02996 ********************************************************************************************/
02997 
02998 PORTNOTE("other","Removed OILBitmap::GetXPEInfo")
02999 #ifndef EXCLUDE_FROM_XARALX
03000 void OILBitmap::GetXPEInfo(OILBitmap*& refMasterBitmap,
03001                               IXMLDOMDocumentPtr& refEditList,
03002                               BOOL bEnsureList)
03003 {
03004     refMasterBitmap = m_pMasterBitmap;
03005     refEditList = m_pEditList;
03006 
03007     if (bEnsureList && refEditList==NULL)
03008     {
03009         refEditList = CXMLUtils::NewDocument();
03010     }
03011 
03012 // I'd prefer not to use references but there are problems with IXMLDOMDocument2Ptr*
03013 //  if (ppMasterBitmap) *ppMasterBitmap = m_pMasterBitmap;
03014 //  if (ppEditList)     *ppEditList = m_pEditList;
03015 }
03016 #endif
03017 
03018 /********************************************************************************************
03019 
03020 >   BOOL OILBitmap::IsXPEMaster()
03021                 
03022     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
03023     Created:    28/01/2004
03024     Inputs:     -
03025     Outputs:    -
03026     Returns:    TRUE if this bitmap is a used as a master by other bitmaps in the same list
03027     Purpose:    Gets the XPE master status of this bitmap by searching the bitmap list
03028 
03029 ********************************************************************************************/
03030 
03031 BOOL OILBitmap::IsXPEMaster()
03032 {
03033     OILBitmap* poBmp = (OILBitmap*) GetApplication()->GetGlobalBitmapList()->GetHead();
03034     while (poBmp)
03035     {
03036         if (poBmp->m_pMasterBitmap == this)
03037             return TRUE;
03038 
03039         poBmp = (OILBitmap*) GetApplication()->GetGlobalBitmapList()->GetNext(poBmp);
03040     }
03041 
03042     return FALSE;
03043 }
03044 
03045 
03046 /********************************************************************************************
03047 
03048 >   BOOL OILBitmap::DestroyXPEInfo()
03049                 
03050     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
03051     Created:    30/01/2004
03052     Inputs:     -
03053     Outputs:    -
03054     Returns:    TRUE if this bitmap has no XPE info or the user agreed it could be destroyed
03055                 FALSE otherwise
03056     Purpose:    Aks the user whether he wants to destroy XPE info
03057 
03058 ********************************************************************************************/
03059 
03060 BOOL OILBitmap::DestroyXPEInfo()
03061 {
03062     PORTNOTETRACE("other","OILBitmap::DestroyXPEInfo - do nothing");
03063 #ifndef EXCLUDE_FROM_XARALX
03064     if (m_pMasterBitmap==NULL || m_pEditList==NULL)
03065         return TRUE;
03066 
03067     m_pMasterBitmap = NULL;     // This is just a pointer to another kernel bitmap
03068     m_pEditList = NULL;         // This is a smart ptr so NULL-ing it should release the XML doc
03069 #endif
03070     return TRUE;
03071 }
03072 
03073 
03074 /********************************************************************************************
03075 
03076 >   BOOL OILBitmap::RemoveXPEBitmap()
03077                 
03078     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
03079     Created:    30/01/2004
03080     Inputs:     -
03081     Outputs:    -
03082     Returns:    TRUE if this bitmap has no XPE info or the user agreed it could be destroyed
03083                 FALSE otherwise
03084     Purpose:    Aks the user whether he wants to destroy XPE info
03085 
03086 ********************************************************************************************/
03087 
03088 BOOL OILBitmap::RemoveXPEBitmap()
03089 {
03090     PORTNOTETRACE("other","OILBitmap::RemoveXPEBitmap - do nothing");
03091 #ifndef EXCLUDE_FROM_XARALX
03092     if (m_pMasterBitmap==NULL || m_pEditList==NULL)
03093         return FALSE;
03094 
03095     if (IsDefaultBitmap())
03096         return FALSE;
03097 
03098     if (m_bNeedsXPERebuild)
03099         return TRUE;
03100 
03101     DeleteData(FALSE);
03102     m_bNeedsXPERebuild = TRUE;
03103 #endif
03104     return TRUE;
03105 }
03106 
03107 
03108 /********************************************************************************************
03109 
03110 >   BOOL OILBitmap::RebuildXPEBitmap()
03111 
03112     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
03113     Created:    03/02/2004
03114     Inputs:     -
03115     Outputs:    -
03116     Returns:    TRUE if the OIL bitmap was removed
03117                 FALSE otherwise
03118     Purpose:    Remove the OIL bitmap from memory if it can be constructed from master and edits
03119 
03120 ********************************************************************************************/
03121 
03122 BOOL OILBitmap::RebuildXPEBitmap()
03123 {
03124 PORTNOTE("other","OILBitmap::RebuildXPEBitmap - do nothing")
03125 #ifndef EXCLUDE_FROM_XARALX
03126     TRACE( _T("Warning - OILBitmap::RebuildXPEBitmap called\n") );
03127     if (!m_bNeedsXPERebuild)
03128         return TRUE;
03129 
03130     // If the XPE info is not present then we're in BIG trouble!
03131     ERROR2IF(m_pMasterBitmap==NULL || m_pEditList==NULL, FALSE, "ARGH! Can't rebuild Oil bitmap")
03132     if (m_pMasterBitmap==NULL || m_pEditList==NULL)
03133         return FALSE;
03134 
03135     // Set the flag before calling DoProcessBitmap to prevent possible infinite recursion
03136     m_bNeedsXPERebuild = FALSE;
03137 
03138     // Regenerate the OIL bitmap from the master and the edits
03139     XPEEditOp::DoProcessBitmap(this);
03140 #endif
03141     return TRUE;
03142 }
03143 
03144 
03145 /********************************************************************************************
03146 
03147 >   BOOL OILBitmap::IsHiddenInGallery()
03148 
03149     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
03150     Created:    21/06/2005
03151     Inputs:     -
03152     Outputs:    -
03153     Returns:    TRUE if the OIL bitmap should NOT be displayed in the bitmap gallery
03154                 FALSE otherwise
03155     Purpose:    Hide some bitmaps from the user to avoid confusing the user
03156 
03157 ********************************************************************************************/
03158 
03159 BOOL OILBitmap::IsHiddenInGallery()
03160 {
03161     return (HasBeenDeleted() || NeedsXPERebuild() || m_bHidden);
03162 }
03163 
03164 
03165 /********************************************************************************************
03166 
03167 >   BOOL OILBitmap::NeedsXPERebuild()
03168                 
03169     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
03170     Created:    10/02/2004
03171     Inputs:     -
03172     Outputs:    -
03173     Returns:    TRUE if this bitmap has no XPE info or the user agreed it could be destroyed
03174                 FALSE otherwise
03175     Purpose:    Ask the user whether he wants to destroy XPE info
03176 
03177 ********************************************************************************************/
03178 
03179 BOOL OILBitmap::NeedsXPERebuild()
03180 {
03181     return m_bNeedsXPERebuild;
03182 }
03183 
03184 
03185 
03186 /********************************************************************************************
03187 
03188         Kernel Bitmap Reference
03189 
03190 ********************************************************************************************/
03191 
03192 /********************************************************************************************
03193 
03194 >   KernelBitmapRef::KernelBitmapRef()
03195                 
03196     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
03197     Created:    12/12/94
03198     Inputs:     -
03199     Outputs:    -
03200     Purpose:    Constructor for kernel bitmap reference.
03201     Errors:     -
03202     SeeAlso:    -
03203 
03204 ********************************************************************************************/
03205 
03206 KernelBitmapRef::KernelBitmapRef()
03207 {
03208     m_pTheBitmap = NULL;
03209     m_bHidden = FALSE;
03210 }
03211 
03212 /********************************************************************************************
03213 
03214 >   KernelBitmapRef::~KernelBitmapRef()
03215                 
03216     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
03217     Created:    12/12/94
03218     Inputs:     -
03219     Outputs:    -
03220     Purpose:    Destructor for kernel bitmap reference.
03221     Errors:     -
03222     SeeAlso:    -
03223 
03224 ********************************************************************************************/
03225 
03226 KernelBitmapRef::~KernelBitmapRef()
03227 {
03228     Detach();
03229 }
03230 
03231 /********************************************************************************************
03232 
03233 >   KernelBitmapRef& KernelBitmapRef::operator=(KernelBitmapRef& OtherBitmap)
03234             
03235     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
03236     Created:    12/12/94
03237     Inputs:     -
03238     Outputs:    -
03239     Purpose:    Make one bitmap ref the same as the other.
03240     Errors:     -
03241     SeeAlso:    -
03242 
03243 ********************************************************************************************/
03244 
03245 KernelBitmapRef& KernelBitmapRef::operator=(KernelBitmapRef& OtherBitmap)
03246 {
03247     Attach(OtherBitmap.GetBitmap());
03248     return (*this);
03249 }
03250 
03251 /********************************************************************************************
03252 
03253 >   void KernelBitmapRef::Attach(KernelBitmap* NewBitmap, Document* BitmapDoc = NULL)
03254         
03255     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
03256     Created:    12/12/94
03257     Inputs:     NewBitmap   Source kernel bitmap
03258                 BitmapDoc   Destination document (Defaults to NULL)
03259     Outputs:    -
03260     Purpose:    Sets the bitmap that this object is referencing.
03261     Errors:     -
03262     SeeAlso:    -
03263 
03264 ********************************************************************************************/
03265 
03266 void KernelBitmapRef::Attach(KernelBitmap* NewBitmap, Document* BitmapDoc)
03267 {
03268     if (NewBitmap == NULL)
03269     {
03270         // No bitmap specified, so lets just create a default one.
03271         NewBitmap = KernelBitmap::MakeKernelBitmap();
03272     }
03273 
03274     ERROR3IF(NewBitmap == NULL, "Trying to attach NULL bitmap to bitmap ref");
03275     if (NewBitmap == NULL)
03276         return;
03277 
03278     Detach(TRUE);
03279 
03280     ERROR3IF(IsHidden(), "Attaching a bitmap to a Hidden node, in KernelBitmapRef::Attach");
03281 
03282 #if !defined(EXCLUDE_FROM_RALPH)
03283     if (InternalClipboard::CopyInProgress())
03284     {
03285         // Bit of a bodge this !!
03286         // If there is a clipboard copy op in progress, 
03287         // then we won't try and attach this to any lists.
03288 
03289         // Neville 12/8/97
03290         // Unfortunately, this leads to a memory leak for each bitmap that is copied
03291         // to the clipboard. At this point BitmapDoc is NULL and current doc is set to
03292         // the source doc. Hence, we cannot use the proper code and add it to the clipboard's
03293         // bitmap list.
03294 
03295         NewBitmap = new KernelBitmap(NewBitmap->ActualBitmap);
03296         TRACEUSER( "Neville", _T("ClipBoard Bmp at %x\n"), NewBitmap );
03297         m_pTheBitmap = NewBitmap;
03298         return;
03299     }
03300 #endif
03301 
03302     // Whenever we attach or re-attach to the document bitmap list
03303     // we need to ensure that we have valid bitmap data
03304     NewBitmap->GetActualBitmap()->RebuildXPEBitmap();
03305 
03306     if (BitmapDoc == NULL)
03307         BitmapDoc = Document::GetCurrent();
03308 
03309     if (BitmapDoc == NULL)
03310         BitmapDoc = Document::GetSelected();
03311 
03312     BitmapList* ExistingList = NewBitmap->GetParentBitmapList();
03313 
03314     if (ExistingList == NULL || ExistingList->GetParentDocument() != BitmapDoc)
03315     {
03316         // Either the bitmap is not in a list at all, or it's in a list
03317         // in another document.  So ...
03318 
03319 PORTNOTE("other","Removed IXMLDOMDocumentPtr usage")
03320 #ifndef EXCLUDE_FROM_XARALX
03321         IXMLDOMDocumentPtr pEditInfo = NULL;
03322 //      KernelBitmap* pMasterBitmap = NULL;
03323         KernelBitmap* pNewMasterBitmap = NULL;
03324 //      NewBitmap->GetXPEInfo(pMasterBitmap, pEditInfo);
03325         // Can't call KernelBitmap->GetXPEInfo because it searches for a Master bitmap in the doc list
03326         // that matches the oil master bitmap. But here we know that that will always fail
03327         OILBitmap* pMasterOil = NULL;
03328         NewBitmap->ActualBitmap->GetXPEInfo(pMasterOil, pEditInfo);
03329         if (pMasterOil!=NULL && pEditInfo!=NULL)
03330         {
03331             // Need to copy the Master into the new doc as well!
03332             // ... we'll have to make a copy to attach to this document's list
03333             pNewMasterBitmap = KernelBitmap::MakeKernelBitmap(pMasterOil, BitmapDoc);
03334 
03335             // Get the bitmap list from the document
03336             BitmapList* BmpList = NULL;
03337             if (BitmapDoc)
03338                 BmpList = BitmapDoc->GetBitmapList();
03339 
03340             // and then attach the bitmap (doesn't matter if BmpList is NULL)
03341             pNewMasterBitmap->Attach(BmpList);
03342         }
03343 #endif
03344 
03345         //------------------------------------
03346         // ... we'll have to make a copy to attach to this document's list
03347         NewBitmap = KernelBitmap::MakeKernelBitmap(NewBitmap->ActualBitmap, BitmapDoc);
03348 
03349         // Get the bitmap list from the document
03350         BitmapList* BmpList = NULL;
03351 
03352         if (BitmapDoc)
03353             BmpList = BitmapDoc->GetBitmapList();
03354 
03355         // and then attach the bitmap (doesn't matter if BmpList is NULL)
03356         NewBitmap->Attach(BmpList);
03357         //------------------------------------
03358 
03359 
03360         // Make sure the new bitmap refers to the new master...
03361 PORTNOTE("other","Removed XPEInfo usage")
03362 #ifndef EXCLUDE_FROM_XARALX
03363         if (pNewMasterBitmap)
03364         {
03365             NewBitmap->SetXPEInfo(pNewMasterBitmap, pEditInfo);
03366         }
03367 #endif
03368     }
03369 
03370     // Remember the bitmap pointer
03371     m_pTheBitmap = NewBitmap;
03372 }
03373 
03374 /********************************************************************************************
03375 
03376 >   void KernelBitmapRef::SetBitmap(KernelBitmap* NewBmp)
03377 
03378     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
03379     Created:    12/12/94
03380     Inputs:     -
03381     Outputs:    -
03382     Purpose:    Sets the reference to a bitmap.
03383     Errors:     -
03384     SeeAlso:    -
03385 
03386 ********************************************************************************************/
03387 
03388 void KernelBitmapRef::SetBitmap(KernelBitmap* NewBmp)
03389 {
03390 //  ERROR3IF(m_pTheBitmap != NULL, "Warning, overwriting bitmap ref in KernelBitmapRef::SetBitmap");
03391     
03392     // Remember the bitmap pointer
03393     m_pTheBitmap = NewBmp;
03394 }
03395 
03396 /********************************************************************************************
03397 
03398 >   void KernelBitmapRef::Detach(BOOL bTryRemoveFromDoc = FALSE)
03399     
03400     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
03401     Created:    12/12/94
03402     Inputs:     -
03403     Outputs:    -
03404     Purpose:    Removes the reference to a bitmap.
03405     Errors:     -
03406     SeeAlso:    -
03407 
03408 ********************************************************************************************/
03409 
03410 void KernelBitmapRef::Detach(BOOL bTryRemoveFromDoc)
03411 {
03412     if (bTryRemoveFromDoc)
03413     {
03414         KernelBitmap* tempBitmap = m_pTheBitmap;
03415         Document* pBitmapDoc = NULL;
03416 
03417         pBitmapDoc = Document::GetCurrent();
03418         if (pBitmapDoc == NULL)
03419             pBitmapDoc = Document::GetSelected();
03420 
03421         m_pTheBitmap = NULL;
03422 
03423         if (tempBitmap && pBitmapDoc && !tempBitmap->IsUsedInDocument(pBitmapDoc))
03424         {
03425             tempBitmap->Detach();
03426             BROADCAST_TO_ALL(BitmapListChangedMsg(tempBitmap->GetParentBitmapList(), tempBitmap));
03427         }
03428     }
03429     else
03430         m_pTheBitmap = NULL;
03431 }
03432 
03433 /********************************************************************************************
03434 
03435 >   void KernelBitmapRef::DeleteBmp()
03436     
03437     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
03438     Created:    21/01/97
03439     Inputs:     -
03440     Outputs:    -
03441     Purpose:    Deletes the bitmap we are referencing.
03442 
03443 ********************************************************************************************/
03444 
03445 void KernelBitmapRef::DeleteBmp()
03446 {
03447     if (m_pTheBitmap!=NULL)
03448     {
03449         delete m_pTheBitmap;
03450         m_pTheBitmap=NULL;
03451     }
03452 }
03453 
03454 /********************************************************************************************
03455 
03456 >   void KernelBitmapRef::RemoveFromTree()
03457 
03458     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
03459     Created:    12/12/94
03460     Inputs:     -
03461     Outputs:    -
03462     Purpose:    Called when the object containing this reference is removed from the
03463                 document tree.
03464     Errors:     -
03465     SeeAlso:    -
03466 
03467 ********************************************************************************************/
03468 
03469 void KernelBitmapRef::RemoveFromTree()
03470 {
03471     if (m_pTheBitmap == NULL)
03472         return;
03473 
03474     TRACEUSER( "Neville", _T("Removing Bitmap Ref from tree\n") );
03475     m_bHidden = TRUE;
03476 
03477     m_pTheBitmap->Detach();
03478     BROADCAST_TO_ALL(BitmapListChangedMsg(m_pTheBitmap->GetParentBitmapList(), m_pTheBitmap));
03479 }
03480 
03481 /********************************************************************************************
03482 
03483 >   void KernelBitmapRef::AddtoTree()
03484 
03485     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
03486     Created:    12/12/94
03487     Inputs:     -
03488     Outputs:    -
03489     Purpose:    Called when the object containing this reference is added to the
03490                 document tree.
03491     Errors:     -
03492     SeeAlso:    -
03493 
03494 ********************************************************************************************/
03495 
03496 void KernelBitmapRef::AddtoTree()
03497 {
03498     if (m_pTheBitmap == NULL)
03499         return;
03500 
03501     TRACEUSER( "Neville", _T("Adding Bitmap Ref to tree\n") );
03502     m_bHidden = FALSE;
03503 
03504     m_pTheBitmap->Attach();
03505     BROADCAST_TO_ALL(BitmapListChangedMsg(m_pTheBitmap->GetParentBitmapList(), m_pTheBitmap));
03506 }
03507 
03508 
03509 
03510 

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