BitmapListComponent Class Reference

Provide a component that contains a list of kernel bitmaps in use by a document. More...

#include <bmpcomp.h>

Inheritance diagram for BitmapListComponent:

DocComponent ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 BitmapListComponent ()
 Construct a Bitmap list component. DO NOT use this constructor. It gives and ERROR3 (and sets up this in a semi-safe default state).
 BitmapListComponent (BitmapList *)
 Construct a Bitmap list component using the given Bitmap list.
virtual ~BitmapListComponent ()
 Clean up a Bitmap list component's data structures - deletes the Bitmap list.
BitmapListGetBitmapList ()
virtual BOOL EPSStartImport (EPSFilter *)
 Inform the Bitmap list document component that an EPS import is about to start.
virtual void EPSEndImport (EPSFilter *, BOOL)
 Inform the Bitmap list document component that an EPS import has just finished.
virtual BOOL WriteEPSComments (EPSFilter *)
 Writes out the Bitmap table in the form of EPS comments in the 'header' comments of the EPS file.
virtual BOOL WriteScript (EPSFilter *)
 This is called after all the Comments, Prolog etc have been output so that DocComponents get a chance to do something right at the start of the real EPS data, but before the tree starts to be exported. (The base class does nothing).
virtual ProcessEPSResult ProcessEPSComment (EPSFilter *, const char *)
 Process an EPS comment - if this is a Bitmap table comment, this component will claim it and try to decode it.
virtual void EndOfEPSComment (EPSFilter *)
 Informs the document component that the comment it has been decoding has now finished, and it should take whatever action required to act on the comment.
virtual INT32 GetSizeOfExport (Filter *)
 Find out how many nodes will be exported when this bitmap list is exported. The node can use the filter to find out how it will be exported, e.g. bitmap lists should return a value that reflects whether or not bitmap indirection is possible with this filter and so on. NB. This is virtual - the default implementation just returns 1 - only override if this is not accurate.
virtual BOOL EPSStartExport (EPSFilter *)
 Inform the Bitmap list document component that an EPS export is about to start.
virtual void EPSEndExport (EPSFilter *)
 Inform the Bitmap list document component that an EPS export has just finished.
ExportedBitmapsGetBitmapExportPool ()
ImportedBitmapsGetImportList ()
virtual BOOL StartComponentCopy ()
 This function gets called to prepare for a copy of Bitmaps into the document. It sets up the various arrays and other thangs which the Bitmap copy will need.
virtual BOOL EndComponentCopy ()
 Will commit all changes made by doing the component copy, returning TRUE.
virtual void AbortComponentCopy ()
 Will abort all changes made for component copies. This means that things such as the Bitmaps referenced by the nodes you have just copied do not exist, so you must clean up to the state the document was in before you strated copying.
virtual BOOL StartImport (BaseCamelotFilter *pFilter)
 Inform the bitmap list document component that a Native or Web import is about to start.
virtual BOOL EndImport (BaseCamelotFilter *pFilter, BOOL Success)
 Inform the bitmap list document component that a Native or Web import has just finished.
virtual BOOL StartExport (BaseCamelotFilter *pFilter)
 Inform the bitmap list document component that a Web or Native export is about to start.
virtual BOOL EndExport (BaseCamelotFilter *pFilter, BOOL Success)
 Inform the bitmap list document component that a Web or Native export has just finished.
KernelBitmapGetReadBitmapReference (INT32 BitmapRef)
 Try and convert a bitmap reference i.e. record number into a previously imported bitmap definition which should now be an kernel bitmap in the document.
INT32 GetWriteBitmapReference (KernelBitmap *pBitmap, BaseCamelotFilter *pFilter)
 Return the bitmap reference to the caller, who will then use it to write the bitmap in the record that they are preparing to save to a Web or Native file. In the process of getting the bitmap reference, the bitmap definition record for the bitmap reference will be generated and saved to the file. In the web format, the bitmap may have been reduced in resolution, colour resolution or cropped to try and reduce the size saved out. NOTE: As this does save information into the record stream, it *MUST* be called before the caller has called StartRecord() as otherwise the records will become intertwined!
INT32 SaveBitmapDefinition (KernelBitmap *pBitmap, BaseCamelotFilter *pFilter)
 This actually saves out the bitmap definition into the file and returns the bitmap reference or record number to the caller. They will then be able to use it to write the bitmap in the record that they are preparing to save to a Web or Native file.
BOOL LoadBitmapDefinition (CXaraFileRecordHandler *pXFileRecHandler, CXaraFile *pCXFile, INT32 Tag, UINT32 Size, UINT32 RecordNumber)
 Try and import a bitmap definition record into the document.
BOOL WriteBitmapPropertiesRecord (KernelBitmap *pBitmap, BaseCamelotFilter *pFilter, INT32 BmpRef)
 Helper function for SaveBitmapDefinition. Write out 'bitmap properties' record. This contains: A bitmap reference (INT32). This specifies the bitmap to which the properties apply. (This will usually be the bitmap record which immediately preceded this bmp properties record.) A single flag byte. The LSB stores the value of the 'smooth when scaled up' flag - 1 for yes, 0 for no. Other bits could be used to record other boolean bmp properties; for now these are set to 0. 7 more bytes for future use. Some of this space should be used to store GIF animation info (which is presently not saved). The remainder of the space is reserved for possible future additions to the bmp properties dialogue.

Protected Member Functions

BOOL ExportBitmapPoolItem (INT32 BitmapNum, EPSFilter *pFilter, EPSExportDC *pDC, KernelBitmap *pBitmap)
 Does the actual saving for a bitmap pool item. This uses the cbmp token to represent the Camelot BitMap Pool object.

Protected Attributes

ExportedBitmapspBitmapsToExport
ExportedBitmapspExportedBitmaps
ImportedBitmapspImportedBitmaps

Private Attributes

BitmapListpBitmaps
BaseCamelotFilterpCamFilter
BOOL WarnedBefore

Detailed Description

Provide a component that contains a list of kernel bitmaps in use by a document.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/12/94
See also:
DocComponent

Definition at line 221 of file bmpcomp.h.


Constructor & Destructor Documentation

BitmapListComponent::BitmapListComponent  ) 
 

Construct a Bitmap list component. DO NOT use this constructor. It gives and ERROR3 (and sets up this in a semi-safe default state).

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/12/94
See also:
BitmapListComponent

Definition at line 529 of file bmpcomp.cpp.

00530 {
00531     ERROR3("BitmapListComponent constructed with default constructor!?\n");
00532 }

BitmapListComponent::BitmapListComponent BitmapList pBmpList  ) 
 

Construct a Bitmap list component using the given Bitmap list.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/12/94
Parameters:
pColList - the Bitmap list to use for this Bitmap list componet. [INPUTS]
Returns:
Errors: ENSURE if pColList is NULL.
See also:
BitmapListComponent

Definition at line 549 of file bmpcomp.cpp.

00550 {
00551     ENSURE(pBmpList != NULL, "NULL Bitmap list in Bitmap list component constructor!");
00552 
00553     // Install this Bitmap list.
00554     pBitmaps = pBmpList;
00555 
00556     // Initialise Exporter bitmap list
00557     pExportedBitmaps = NULL;
00558 
00559     // Initialise Importer bitmap list
00560     pImportedBitmaps = NULL;
00561 
00562     // Our link to the BaseCamelotFilter
00563     pCamFilter = NULL;
00564     // Set our variable so that we warn about a possible replacement only once
00565     WarnedBefore = FALSE;
00566 
00567     // Initialise Exporter bitmap list (used for EPS only)
00568     pBitmapsToExport = NULL;
00569 }

BitmapListComponent::~BitmapListComponent  )  [virtual]
 

Clean up a Bitmap list component's data structures - deletes the Bitmap list.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/12/94
Returns:
Errors: -
See also:
BitmapListComponent

Definition at line 584 of file bmpcomp.cpp.

00585 {
00586     // Delete our Bitmap list.
00587     delete pBitmaps;
00588 
00589     // As we have finished with it now, destroy the list of imported bitmaps
00590     if (pImportedBitmaps)
00591     {
00592         delete pImportedBitmaps;
00593         pImportedBitmaps = NULL;
00594     }
00595 
00596     // As we have finished with it now, destroy the list of exported bitmaps
00597     if (pExportedBitmaps)
00598     {
00599         delete pExportedBitmaps;
00600         pExportedBitmaps = NULL;
00601     }
00602 
00603     if (pBitmapsToExport)
00604     {
00605         delete pBitmapsToExport;
00606         pBitmapsToExport = NULL;
00607     }
00608 }


Member Function Documentation

void BitmapListComponent::AbortComponentCopy  )  [virtual]
 

Will abort all changes made for component copies. This means that things such as the Bitmaps referenced by the nodes you have just copied do not exist, so you must clean up to the state the document was in before you strated copying.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/12/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: - Notes: May be called even if StartComponentCopy has not been called. May be called multiple times

See also:
BitmapListComponent::EndComponentCopy; BitmapListComponent::AbortComponentCopy; BitmapListComponent::CopyBitmapAcross

Reimplemented from DocComponent.

Definition at line 1094 of file bmpcomp.cpp.

01095 {
01096 }

BOOL BitmapListComponent::EndComponentCopy  )  [virtual]
 

Will commit all changes made by doing the component copy, returning TRUE.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/12/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if it succeeded

Errors: - Notes: May be called multiple times - subsequent calls will be ignored

See also:
BitmapListComponent::StartComponentCopy; BitmapListComponent::AbortComponentCopy; BitmapListComponent::CopyBitmapAcross

Reimplemented from DocComponent.

Definition at line 1066 of file bmpcomp.cpp.

01067 {
01068     return(TRUE);
01069 }

BOOL BitmapListComponent::EndExport BaseCamelotFilter pFilter,
BOOL  Success
[virtual]
 

Inform the bitmap list document component that a Web or Native export has just finished.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/6/96
Parameters:
pFilter - the BaseCamelotFilter filter that is being used to import a file. [INPUTS] Success - True if everything went swimmingly, False if just a clean up is required.
Returns:
TRUE if the component was able to end the importing; FALSE if not (e.g. out of memory)
See also:
DocComponent

Reimplemented from DocComponent.

Definition at line 1602 of file bmpcomp.cpp.

01603 {
01604 #ifdef DO_EXPORT
01605 //  ERROR2IF(pExportedBitmaps == NULL, FALSE, "BitmapListComponent::EndExport no pExportedBitmaps!");
01606     // If we error about the pExportedBitmaps then we assume that the EndImport has been called.
01607     // This may not be the case if we are in clean up mode. So just handle it!
01608 
01609 TRACEUSER( "Neville", _T("BitmapListComponent::EndExport\n") );
01610     if (pFilter == NULL)
01611     {
01612         ERROR3("BitmapListComponent::EndExport filter is null!");
01613         return TRUE;
01614     }
01615         
01616     // Check if Web or Native, if Web do nothing
01617     // If Native and we are not just in clean up mode, Save out any unsaved bitmaps
01618     //if (!pFilter->IsWebFilter() && Success)
01619     //{
01620 //TRACEUSER( "Neville", _T("BitmapListComponent::EndExport exporting unsaved bitmaps\n"));
01621 /*      // Count the number of Bitmaps
01622         INT32 TotalBitmaps = 0;
01623         KernelBitmap* pBitmap = (KernelBitmap*) pBitmaps->GetHead();
01624 
01625         while (pBitmap != NULL)
01626         {
01627             // Find the next one
01628             if (pBitmap->GetUsageCount() > 0)
01629                 TotalBitmaps++;     // Only count this bitmap if it really used
01630 
01631             pBitmap = (KernelBitmap*) pBitmaps->GetNext(pBitmap);
01632         }
01633     //}
01634 */
01635     // As we have finished with it now, destroy the list of exported bitmaps
01636     if (pExportedBitmaps)
01637     {
01638         delete pExportedBitmaps;
01639         pExportedBitmaps = NULL;
01640     }
01641     
01642 #if 0
01643     if(Success)
01644         SGLibOil::ExportWav(pFilter);
01645 #endif
01646 
01647 #endif
01648     return TRUE;
01649 }

BOOL BitmapListComponent::EndImport BaseCamelotFilter pFilter,
BOOL  Success
[virtual]
 

Inform the bitmap list document component that a Native or Web import has just finished.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/6/96
Parameters:
pFilter - the BaseCamelotFilter filter that is being used to import a file. [INPUTS] Success - TRUE => The import was successful; FALSE => The import failed - abandon any changes.
Returns:
TRUE if the component was able to end the importing; FALSE if not (e.g. out of memory)
See also:
DocComponent

Reimplemented from DocComponent.

Definition at line 1161 of file bmpcomp.cpp.

01162 {
01163 TRACEUSER( "Neville", _T("BitmapListComponent::EndImport\n") );
01164     if (pFilter == NULL)
01165     {
01166         ERROR3("BitmapListComponent::EndImport filter is null!");
01167         return TRUE;
01168     }
01169 
01170     // As we have finished with it now, destroy the list of imported bitmaps
01171     if (pImportedBitmaps)
01172     {
01173         delete pImportedBitmaps;
01174         pImportedBitmaps = NULL;
01175     }
01176 
01177     // Null our link to the BaseCamelotFilter
01178     pCamFilter = NULL;
01179     // Set our variable so that we warn about a possible replacement only once
01180     WarnedBefore = FALSE;
01181 
01182     return TRUE;
01183 }

void BitmapListComponent::EndOfEPSComment EPSFilter pFilter  )  [virtual]
 

Informs the document component that the comment it has been decoding has now finished, and it should take whatever action required to act on the comment.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/12/94
Parameters:
pFilter - the EPS filter that is being used to import a file. [INPUTS]
See also:
DocComponent::EndOfPESComment

Reimplemented from DocComponent.

Definition at line 948 of file bmpcomp.cpp.

00949 {
00950     // Do any cleanup we need to here after loading in a Bitmap table...
00951 }

void BitmapListComponent::EPSEndExport EPSFilter pFilter  )  [virtual]
 

Inform the Bitmap list document component that an EPS export has just finished.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/12/94
Parameters:
pFilter - the EPS filter that is being used to import a file. [INPUTS] Success - TRUE => The import was successful; FALSE => The import failed - abandon any changes.
See also:
DocComponent

Reimplemented from DocComponent.

Definition at line 742 of file bmpcomp.cpp.

00743 {
00744 #ifdef DO_EXPORT
00745     if (pBitmapsToExport)
00746     {
00747         delete pBitmapsToExport;
00748         pBitmapsToExport = NULL;
00749     }
00750 #endif
00751 }

void BitmapListComponent::EPSEndImport EPSFilter pFilter,
BOOL  Success
[virtual]
 

Inform the Bitmap list document component that an EPS import has just finished.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/12/94
Parameters:
pFilter - the EPS filter that is being used to import a file. [INPUTS] Success - TRUE => The import was successful; FALSE => The import failed - abandon any changes.
See also:
DocComponent

Reimplemented from DocComponent.

Definition at line 645 of file bmpcomp.cpp.

00646 {
00647 }

BOOL BitmapListComponent::EPSStartExport EPSFilter pFilter  )  [virtual]
 

Inform the Bitmap list document component that an EPS export is about to start.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/12/94
Parameters:
pFilter - the EPS filter that is being used to import a file. [INPUTS]
See also:
DocComponent

Reimplemented from DocComponent.

Definition at line 662 of file bmpcomp.cpp.

00663 {
00664 #ifdef DO_EXPORT
00665     ERROR3IF(pBitmapsToExport != NULL, "Why is there an export bitmap list already ?");
00666     
00667     // Build the list of bitmaps to export here ...
00668     pBitmapsToExport = new ExportedBitmaps();
00669 
00670     ERROR3IF(pBitmapsToExport == NULL, "Couldn't create bitmap export list !!");
00671     if (pBitmapsToExport == NULL)
00672         return FALSE;
00673 
00674     Document* ParentDoc = (Document*)pBitmaps->GetParentDocument();
00675     ERROR3IF(ParentDoc == NULL, "Bitmap list has no parent document !!");
00676     if (ParentDoc == NULL)
00677     {
00678         delete pBitmapsToExport;
00679         pBitmapsToExport = NULL;
00680         return FALSE;
00681     }
00682 
00683     UINT32 BitmapNumber = 0;
00684 
00685     // Scan the document's tree for bitmap references
00686     Node* pNode = Node::DocFindFirstDepthFirst(ParentDoc);
00687     while (pNode != NULL)
00688     {
00689         // Ignore hidden nodes
00690         if (!pNode->IsNodeHidden())
00691         {
00692             INT32 Count = 0;
00693 
00694             // Does this node have any bitmaps in it ?
00695             KernelBitmap* pBitmap = pNode->EnumerateBitmaps(Count++);
00696 
00697             while (pBitmap != NULL)
00698             {
00699                 // Check for a deleted bitmap
00700                 if (pBitmap->HasBeenDeleted())
00701                 {
00702                     ERROR2IF(pBitmap->GetParentBitmapList() == NULL, 0L, "Deleted bitmap has no parent list");
00703                     
00704                     // Use the default bitmap instead
00705                     pBitmap = pBitmap->GetParentBitmapList()->FindDefaultBitmap();
00706 
00707                     // There should always be a default bitmap at the start of the list
00708                     ERROR2IF(pBitmap == NULL, 0L, "Couldn't find the default bitmap");
00709                 }
00710 
00711                 // Found a bitmap reference, so ...
00712                 // .. if this bitmap is not in the export list, add it
00713                 if (pBitmapsToExport->GetBitmap(pBitmap) == NULL)
00714                     pBitmapsToExport->AddBitmap(pBitmap, BitmapNumber++);
00715                 
00716                 pBitmap = pNode->EnumerateBitmaps(Count++);             
00717             }
00718         }
00719 
00720         // Move onto the next node in the tree
00721         pNode = pNode->DocFindNextDepthFirst(); 
00722     }
00723 #endif
00724     return TRUE;
00725 }

BOOL BitmapListComponent::EPSStartImport EPSFilter pFilter  )  [virtual]
 

Inform the Bitmap list document component that an EPS import is about to start.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/12/94
Parameters:
pFilter - the EPS filter that is being used to import a file. [INPUTS]
See also:
DocComponent

Reimplemented from DocComponent.

Definition at line 625 of file bmpcomp.cpp.

00626 {
00627     return FALSE;
00628 }

BOOL BitmapListComponent::ExportBitmapPoolItem INT32  BitmapNum,
EPSFilter pFilter,
EPSExportDC pDC,
KernelBitmap pBitmap
[protected]
 

Does the actual saving for a bitmap pool item. This uses the cbmp token to represent the Camelot BitMap Pool object.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/1/95
Parameters:
BitmapNum - The number of the Kernel bitmap in the pool [INPUTS] pFilter - The filter that things are being saved in pDC - The DC that the saving is happening in pBitmap - The Kernel Bitmap to be saved
Returns:
TRUE if it worked, FALSE if not

Definition at line 877 of file bmpcomp.cpp.

00878 {
00879 #ifdef DO_EXPORT
00880     ERROR2IF(pBitmap->HasBeenDeleted(), FALSE, "Trying to export a deleted bitmap");
00881     
00882     if (pFilter->IS_KIND_OF(CamelotNativeEPSFilter))
00883     {
00884         // ...then the bitmap object token.
00885         pDC->OutputValue(BitmapNum);            // Output the number of the bitmap
00886         pDC->OutputValue(INT32(0));             // Bitmap pool type (ready for expansion)
00887         pDC->OutputToken(_T("cbmp"));               // Bitmap pool token
00888         pDC->OutputNewLine();
00889         
00890         // ...and then the bitmap data itself.
00891         pFilter->ExportBitmap(*pBitmap);
00892 
00893         // Tell caller we rendered ourselves ok
00894         return TRUE;
00895     }
00896 #endif
00897     return FALSE;
00898 }

ExportedBitmaps* BitmapListComponent::GetBitmapExportPool  )  [inline]
 

Definition at line 244 of file bmpcomp.h.

00244 { return pBitmapsToExport; }

BitmapList* BitmapListComponent::GetBitmapList  )  [inline]
 

Definition at line 229 of file bmpcomp.h.

00229 { return pBitmaps; }

ImportedBitmaps* BitmapListComponent::GetImportList  )  [inline]
 

Definition at line 245 of file bmpcomp.h.

00245 { return pImportedBitmaps; }

KernelBitmap * BitmapListComponent::GetReadBitmapReference INT32  BitmapRef  ) 
 

Try and convert a bitmap reference i.e. record number into a previously imported bitmap definition which should now be an kernel bitmap in the document.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/6/96
Parameters:
BitmapRef - The bitmap reference or record number that the record handler has loaded [INPUTS] from the record.
- [OUTPUTS]
Returns:
pBitmap - A pointer to return the required kernel bitmap
See also:
-

Definition at line 1201 of file bmpcomp.cpp.

01202 {
01203 TRACEUSER( "Neville", _T("GetReadBitmapReference for ref %d\n"), BitmapRef );
01204 
01205     // First check to see if the bitmap refers to any of the built in bitmaps.
01206     // These will have negative record numbers
01207     KernelBitmap* pBitmap = NULL;
01208     if (BitmapRef <= 0)
01209     {
01210         // The only one that exists at present is the default bitmap
01211         if (REF_DEFAULTBITMAP_BUILTIN)
01212         {
01213             // Its the default one so just construct a new kernel bitmap which
01214             // refers to this and return this to the caller
01215             pBitmap = KernelBitmap::MakeKernelBitmap(NULL, NULL);
01216         }
01217         else
01218         {
01219             // If we have a pFilter then ask the default warning handle to append our message
01220             if (pCamFilter)
01221             {
01222                 if (!WarnedBefore)
01223                 {
01224                     pCamFilter->AppendWarning(_R(IDS_NATIVE_BITMAPWARNING));
01225                     WarnedBefore = TRUE;
01226                 }
01227 
01228                 // We have warned the user about problems so just construct a new kernel bitmap which
01229                 // is the default one and return this to the caller
01230                 pBitmap = KernelBitmap::MakeKernelBitmap(NULL, NULL);
01231             }
01232             else
01233                 ERROR2(NULL,"BitmapListComponent::GetReadBitmapReference negative BitmapRef is unknown");
01234         }
01235     }
01236     else
01237     {
01238         // Try and find the specified record number in our colour list
01239         pBitmap = pImportedBitmaps->GetBitmap(BitmapRef);
01240         // If not found then this is a problem as a bitmap must have been defined before its being
01241         // referenced 
01242         if (pBitmap == NULL)
01243         {
01244             // If we have a pFilter then ask the default warning handle to append our message
01245             if (pCamFilter)
01246             {
01247                 if (!WarnedBefore)
01248                 {
01249                     pCamFilter->AppendWarning(_R(IDS_NATIVE_BITMAPWARNING));
01250                     WarnedBefore = TRUE;
01251                 }
01252 
01253                 // We have warned the user about problems so just construct a new kernel bitmap which
01254                 // is the default one and return this to the caller
01255                 pBitmap = KernelBitmap::MakeKernelBitmap(NULL, NULL);
01256             }
01257             else
01258                 ERROR2(NULL,"BitmapListComponent::GetReadBitmapReference BitmapRef cannot be found");
01259         }
01260     }
01261 
01262     return pBitmap;
01263 }

INT32 BitmapListComponent::GetSizeOfExport Filter pFilter  )  [virtual]
 

Find out how many nodes will be exported when this bitmap list is exported. The node can use the filter to find out how it will be exported, e.g. bitmap lists should return a value that reflects whether or not bitmap indirection is possible with this filter and so on. NB. This is virtual - the default implementation just returns 1 - only override if this is not accurate.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/01/95
Parameters:
pFilter - the export filter that will be used. [INPUTS]
Returns:
An approximation of the size of data that will be exported by this bitmap list, in terms of nodes. (see NodeRenderable::GetSizeOfExport).
See also:
Node::NeedsToExport; Node::ExportRender; NodeRenderable::GetSizeOfExport

Reimplemented from DocComponent.

Definition at line 974 of file bmpcomp.cpp.

00975 {
00976 #ifdef DO_EXPORT
00977     // Check if this filter supports bitmap pools
00978     if (pFilter->GetBitmapSupportLevel() != IndirectedBitmapSupport)
00979         // No - just return 1.
00980         return 1;
00981 
00982     ERROR3IF(pBitmapsToExport == NULL, "Why isn't there an export bitmap list (in GetSizeOfExport) ?");
00983     if (pBitmapsToExport == NULL)
00984         return 1;
00985 
00986     INT32 TotalScanlines = 0;
00987 
00988     // Find the first bitmap in the list again
00989     ExportBitmap* pExportBitmap = pBitmapsToExport->EnumerateBitmaps();
00990 
00991     while (pExportBitmap != NULL)
00992     {
00993         KernelBitmap* pBitmap = pExportBitmap->pBmp;
00994 
00995         // Get information on this bitmap.
00996         BitmapInfo Info;
00997         if (!pBitmap->ActualBitmap->GetInfo(&Info))
00998             // Failed for some reason - bodge the answer.
00999             return 1;
01000 
01001         // Add the number of scanlines to our total
01002         TotalScanlines += Info.PixelHeight;
01003 
01004         // Find the next one
01005         pExportBitmap = pBitmapsToExport->EnumerateBitmaps(pExportBitmap);
01006     }
01007     
01008     // Return size to caller.
01009     if (TotalScanlines == 0)
01010         return 1;
01011     else
01012         return TotalScanlines;
01013 #else
01014     return 0;
01015 #endif
01016 }

INT32 BitmapListComponent::GetWriteBitmapReference KernelBitmap pBitmap,
BaseCamelotFilter pFilter
 

Return the bitmap reference to the caller, who will then use it to write the bitmap in the record that they are preparing to save to a Web or Native file. In the process of getting the bitmap reference, the bitmap definition record for the bitmap reference will be generated and saved to the file. In the web format, the bitmap may have been reduced in resolution, colour resolution or cropped to try and reduce the size saved out. NOTE: As this does save information into the record stream, it *MUST* be called before the caller has called StartRecord() as otherwise the records will become intertwined!

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/6/96
Parameters:
pBitmap - The document bitmap to save [INPUTS] pFilter - The filter to use for saving
- [OUTPUTS]
Returns:
The bitmap reference for the kernel bitmap ready for writing in a record. This will be zero if a problem has occurred. May return -1 if it does not need to save anything i.e if the bitmap is not in use.
See also:
DocComponent

Definition at line 1677 of file bmpcomp.cpp.

01678 {
01679 #ifdef DO_EXPORT
01680     ERROR2IF(pBitmap == NULL,0L,"BitmapListComponent::GetWriteBitmapReference null pBitmap");
01681     ERROR2IF(pFilter == NULL,0L,"BitmapListComponent::GetWriteBitmapReference null pFilter");
01682 
01683     INT32 RecordNumber = 0L;
01684 
01685     // Check for a deleted bitmap
01686     if (pBitmap->HasBeenDeleted())
01687     {
01688         ERROR2IF(pBitmap->GetParentBitmapList() == NULL, 0L, "Deleted bitmap has no parent list");
01689         
01690         // Use the default bitmap instead
01691         pBitmap = pBitmap->GetParentBitmapList()->FindDefaultBitmap();
01692 
01693         // There should always be a default bitmap in the list
01694         ERROR2IF(pBitmap == NULL, 0L, "Couldn't find the default bitmap");
01695     }
01696 
01697     // Check if the bitmap is the default one
01698     // We could save this as a unique -ve reference but this implies we have the bitmap
01699     // bound into ALL exes i.e. RALPH and the viewer. Which makes them 77k bigger. Not many
01700     // people will use the default bitmap and if they do will not assume that it is assumed.
01701     // They will want and expect the document to contain the bitmap so that it is standalone.
01702     // Also, what happens if we change the default. Then we need the old and the new default 
01703     // bound in! 
01704     //if (pBitmap->IsDefaultBitmap())
01705     //{
01706         // If so then there is no point in saving out the definition, just save out
01707         // our unique identifier for this bitmap i.e. pass this back to the caller
01708     //  return REF_DEFAULTBITMAP_BUILTIN;
01709     //}
01710 
01711     // Save out that bitmap definition into the file using the bitmap compression value
01712     // possibly requested by the user
01713     RecordNumber = SaveBitmapDefinition(pBitmap, pFilter);
01714 
01715     return RecordNumber;
01716 #else
01717     return 0;
01718 #endif
01719 }

BOOL BitmapListComponent::LoadBitmapDefinition CXaraFileRecordHandler pXFileRecHandler,
CXaraFile pCXFile,
INT32  Tag,
UINT32  Size,
UINT32  RecordNumber
 

Try and import a bitmap definition record into the document.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/6/96
Parameters:
pXFileRecHandler - The CXaraFileRecordHandler that is being used to provide read functions etc. [INPUTS] pCXFile - The CXaraFile that is being used to provide read functions etc. Tag - The tag of the record and hence the type of bitmap being imported Size - The size of this bitmap record RecordNumber - The record number for this bitmap record
Returns:
TRUE if the record was succesfully imported; FALSE if not (e.g. out of memory)
See also:
-

Definition at line 1284 of file bmpcomp.cpp.

01287 {
01288     ERROR2IF(pXFileRecHandler == NULL,FALSE,"BitmapListComponent::LoadBitmapDefinition NULL pXFileRecHandler");
01289     ERROR2IF(pCXFile == NULL,FALSE,"BitmapListComponent::LoadBitmapDefinition NULL pCXFile");
01290     ERROR2IF(pImportedBitmaps == NULL,FALSE,"BitmapListComponent::LoadBitmapDefinition NULL pImportedBitmaps");
01291 
01292     BOOL ok = TRUE;
01293 
01294     // Get the underlying file stream class, CCFile, that we are using to load the file
01295     CCLexFile* pFile = pCXFile->GetCCFile();
01296     ERROR2IF(pFile == NULL,FALSE,"BitmapListComponent::LoadBitmapDefinition CCFile pointer is NULL");
01297     // Note present position in file
01298     FilePos pos = pFile->tellIn();
01299 
01300     // Get the underlying BaseCamelotFilter, which we will use to handle the progress bar updates
01301     // and other useful things
01302     CamelotRecordHandler * pCamRecHandler = (CamelotRecordHandler *)pXFileRecHandler;
01303     BaseCamelotFilter *pFilter = pCamRecHandler->GetBaseCamelotFilter();
01304 
01305     // We use this for file for the import, but we might need to change it
01306     // if we use a BitmapSource
01307     CCLexFile* pPseudoFile = pFile;
01308 
01309     // First get the name of the bitmap and other details stored in the record
01310     String_256 BitmapName;
01311     if (ok) ok = pCXFile->Read(BitmapName, BitmapName.MaxLength());
01312 
01313     // Some bitmaps might have a compressed and uncompressed format
01314     // At present, this only happens for bitmaps
01315     BOOL Compressed = FALSE;
01316     // Work out which filter is required from the tag on the record
01317     UINT32 SearchFilter = 0;
01318     // Assume we won't need a BitmapSource
01319     BitmapSource* pSource = NULL;
01320     BOOL ReadPalette = FALSE;
01321     switch (Tag)
01322     {
01323         case TAG_DEFINEBITMAP_BMP:
01324             SearchFilter = FILTERID_BMP;
01325             break;
01326         case TAG_DEFINEBITMAP_GIF:
01327             SearchFilter = FILTERID_TI_GIF;
01328             break;
01329         case TAG_DEFINEBITMAP_JPEG:
01330             SearchFilter = FILTERID_IMPORT_JPEG;
01331             break;
01332         case TAG_DEFINEBITMAP_PNG:
01333             SearchFilter = FILTERID_PNG;
01334             break;
01335         case TAG_DEFINEBITMAP_BMPZIP:
01336             SearchFilter = FILTERID_BMP;
01337             Compressed = TRUE;
01338             break;
01339         case TAG_DEFINEBITMAP_JPEG8BPP:
01340             SearchFilter = FILTERID_IMPORT_JPEG;
01341             Compressed = TRUE;
01342             ReadPalette = TRUE;
01343             break;
01344 
01345         default:
01346             // Not a known tag, so fall through below and use the default bitmap
01347             // warn the user and skip the definition
01348             //ERROR1(FALSE, _R(IDS_DONT_SUPPORT_BITMAP_TYPE));
01349             break;
01350     }
01351 
01352     // If we have a filter to search for then find it.
01353     Filter *pBmpFilter = NULL;
01354     if (SearchFilter != 0)
01355     {
01356         // Try and find the bitmap filter to use to load that bitmap in
01357         // Go get the first filter in the list
01358         pBmpFilter = Filter::GetFirst();
01359         while ((pBmpFilter != NULL) && (pBmpFilter->FilterID != SearchFilter))
01360         {
01361             // Try the next filter
01362             pBmpFilter = Filter::GetNext(pBmpFilter);
01363         }
01364     }
01365      
01366     // Check that the Filter existed
01367     KernelBitmap *pBitmap = NULL;
01368     if (pBmpFilter == NULL)
01369     {
01370         // We have no filter present to load it. In the case of RALPH and even in Camelot,
01371         // the best course of action will be to use a default bitmap instead.
01372         // In the case of Camelot, warn the user that this has happened.
01373         pBitmap = KernelBitmap::MakeKernelBitmap(NULL, NULL);
01374 
01375         // Code below will clean this up so that:-
01376         //  - we skip the bitmap definition
01377         //  - we add the record number to the loaded list so that records which access this definition
01378         //    get something rather than an error.
01379 
01380         // If we have a pFilter then ask the default warning handle to append our message
01381         if (pFilter)
01382         {
01383             if (!WarnedBefore)
01384             {
01385                 pFilter->AppendWarning(_R(IDS_NATIVE_BITMAPWARNING));
01386                 WarnedBefore = TRUE;
01387             }
01388         }
01389         else
01390         {
01391             // Shouldn't happen, as pFilter should never be null
01392             // But Warn the user about the problem, just in case it does happen
01393             InformWarning(_R(IDW_CANNOTLOADBITMAPDEF));
01394         }
01395         //ERROR1(FALSE, _R(IDT_CANT_FIND_FILTER));
01396     }
01397     else
01398     {
01399         // Load the bitmap definition in using that filter
01400         TRACEUSER( "Neville", _T("LoadBitmapDefinition Name %s RecordNumber %d\n"),(TCHAR*)BitmapName, RecordNumber);
01401 
01402         // Now use that filter to load in the bitmap
01403         //INT32 BitmapType = 0;
01404         //BitmapInfo Info;
01405         BOOL IsNew = FALSE;
01406         BaseBitmapFilter *pBitmapFilter = (BaseBitmapFilter *)pBmpFilter;
01407         UINT32 NumberOfPaletteEntries = 0;
01408         RGBTRIPLE * pPalette = NULL;
01409 
01410         if (ReadPalette)
01411         {
01412             // If we are an 8bpp JPEG then we must have saved out the palette
01413             // So load that in before anybody else gets a look in
01414             // First, read the number of entries (this is number of entries - 1)
01415             BYTE Entries = 0;
01416             if (ok) ok = pCXFile->Read(&Entries);
01417             NumberOfPaletteEntries = Entries + 1;
01418             if (ok && NumberOfPaletteEntries > 0)
01419             {
01420                 pPalette = (RGBTRIPLE*)CCMalloc(NumberOfPaletteEntries * sizeof(RGBTRIPLE));
01421                 RGBTRIPLE * pPal = pPalette;
01422                 // Now read the palette entries in
01423                 for (UINT32 i = 0; i < NumberOfPaletteEntries; i++)
01424                 {
01425                     if (ok) ok = pCXFile->Read(&pPal->rgbtRed);
01426                     if (ok) ok = pCXFile->Read(&pPal->rgbtGreen);
01427                     if (ok) ok = pCXFile->Read(&pPal->rgbtBlue);
01428                     pPal++;
01429                 }
01430             }
01431         }
01432 
01433         // WEBSTER - markn 10/2/97
01434         // New flag so that pPseudoFile only gets deleted when it should
01435         BOOL DeletePseudoFile = FALSE;
01436 
01437         // Do we need to create a BitmapSource from this import?
01438         if (pBitmapFilter->IsFormatLossy())
01439         {
01440             // Create a new bitmap source the size of the current record minus a bit
01441             OFFSET SourceSize = Size - (pFile->tellIn() - pos);
01442             pSource = pBitmapFilter->CreateBitmapSource(SourceSize);
01443             if (pSource == NULL || !pSource->IsOK())
01444             {
01445                 ok = FALSE;
01446             }
01447             // Now create a file that can fill it
01448             if (ok)
01449             {
01450                 pPseudoFile = (CCLexFile*)new CCBufferFile(pFile);
01451                 if (pPseudoFile == NULL)
01452                 {
01453                     ok = FALSE;
01454                 }
01455                 else
01456                     DeletePseudoFile = TRUE; // WEBSTER - markn 10/2/97 - New flag so that pPseudoFile only gets deleted when it should
01457             }
01458             // and provide the filter with something to work with
01459             if (ok) pSource->AttachToBufferFile((CCBufferFile*)pPseudoFile);
01460         }
01461 
01462         // Import that bitmap 
01463         // If we have a palette then we need to convert the 24bpp image into an 8bpp image
01464         // using the supplied palette
01465         if (ok) ok = KernelBitmap::ImportBitmap(pPseudoFile, pBitmapFilter, pFilter, Compressed, 
01466                                                 pPalette, NumberOfPaletteEntries,
01467                                                 &pBitmap, &IsNew);
01468         
01469         if (ok && IsNew)
01470         {
01471             // Set the name in it
01472             pBitmap->ActualBitmap->SetName(BitmapName);
01473             // Associate the new bitmap with its source...if there is one
01474             if (pSource != NULL)
01475             {
01476                 pBitmap->SetOriginalSource(pSource, pBitmapFilter);
01477                 pBitmap->SetAsLossy();
01478             }
01479         }
01480         else
01481         {
01482             // Throw away the source as we already have it or don't need it
01483             if (pSource != NULL)
01484             {
01485                 delete pSource;
01486             }
01487         }
01488         
01489         if (pPalette != NULL)
01490         {
01491             CCFree(pPalette);
01492             pPalette = NULL;
01493         }
01494 
01495         // If we have a BitmapSource we should have had a file to use it with
01496         // Delete it
01497         if (pSource != NULL)
01498         {
01499             ERROR3IF(pPseudoFile == NULL, "pPseudoFile == NULL");
01500             // WEBSTER - markn 10/2/97
01501             // New flag so that pPseudoFile only gets deleted when it should
01502             if (DeletePseudoFile && pPseudoFile != NULL) 
01503             {
01504                 delete pPseudoFile;
01505                 pPseudoFile = NULL;
01506             }
01507         }
01508     }
01509     
01510     if (!ok)
01511     {
01512         TRACEALL( _T("==============Failed to load bitmap in, try and recover situation\n") );
01513         // Try some limited error recovery
01514         // First set the flag to true so it thinks everything went ok
01515         ok = TRUE;
01516         // If it has thrown a file exception error then we will need to reset the good flag
01517         // so file access still works ok
01518         pFile->SetGoodState();
01519         // We should now fall through and skip to the end of this record/start of next
01520         // ready to read in the next bit of data.
01521         // REM Any errors will be set, we could inform error at this point but the user should get
01522         // a more friendly, a bitmap failed to load properly, using defaults.
01523     }
01524     
01525     // Only do this if everything went ok
01526     if (ok)
01527     {
01528         // Note the current position in the file
01529         FilePos newpos = pFile->tellIn(); 
01530         TRACEUSER( "Neville", _T("newpos %d, pos %d, newpos-pos %d should = Size %d\n"),newpos,pos,newpos-pos,Size);
01531         if (newpos - pos != (INT32)Size)
01532         {
01533             // The bitmap filter has been naughty and left the file
01534             // pointer sitting somewhere different to where it should.
01535             // We need to now fix this to where it should be
01536             pFile->seekIn(pos + Size);
01537         }
01538     }
01539 
01540     // If have a genuine bitmap then add it to the loaded list
01541     // If the bitmap is null then the reference will use the default instead.
01542     if (pBitmap != NULL)
01543         pImportedBitmaps->AddBitmap(pBitmap, RecordNumber);
01544 
01545     return ok;
01546 }

ProcessEPSResult BitmapListComponent::ProcessEPSComment EPSFilter pFilter,
const char *  pComment
[virtual]
 

Process an EPS comment - if this is a Bitmap table comment, this component will claim it and try to decode it.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/12/94
Parameters:
pFilter - the EPS filter that is being used to import a file. [INPUTS] pComment - pointer to the comment to process.
Returns:
EPSCommentUnknown - This EPS comment is not recognised by the document component. EPSCommentError - This EPS comment was recognised by this document component, but it contained an error. EPSCommentOK - This EPS comment was recognised as a legal comment by this document component, and was processed successfully.

Errors: Badly formed EPS comment.

See also:
DocComponent::ProcessEPSComment

Reimplemented from DocComponent.

Definition at line 924 of file bmpcomp.cpp.

00926 {
00927     // Ignore all comments
00928     return EPSCommentUnknown;
00929 }

INT32 BitmapListComponent::SaveBitmapDefinition KernelBitmap pBitmap,
BaseCamelotFilter pFilter
 

This actually saves out the bitmap definition into the file and returns the bitmap reference or record number to the caller. They will then be able to use it to write the bitmap in the record that they are preparing to save to a Web or Native file.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/6/96
Parameters:
pBitmap - The document bitmap to save [INPUTS] pFilter - The filter to use for saving
- [OUTPUTS]
Returns:
The bitmap reference for the kernel bitmap ready for writing in a record. This will be zero if a problem has occurred. May return -1 if it does not need to save anything i.e if the bitmap is not in use.
See also:
DocComponent

Definition at line 1855 of file bmpcomp.cpp.

01856 {
01857 #ifdef DO_EXPORT
01858     ERROR2IF(pBitmap == NULL,0L,"BitmapListComponent::GetWriteBitmapReference null pBitmap");
01859     ERROR2IF(pFilter == NULL,0L,"BitmapListComponent::GetWriteBitmapReference null pFilter");
01860 
01861     INT32 RecordNumber = 0L;
01862 
01863     // Check for a deleted bitmap
01864     if (pBitmap->HasBeenDeleted())
01865     {
01866         ERROR2IF(pBitmap->GetParentBitmapList() == NULL, 0L, "Deleted bitmap has no parent list");
01867         
01868         // Use the default bitmap instead
01869         pBitmap = pBitmap->GetParentBitmapList()->FindDefaultBitmap();
01870 
01871         // There should always be a default bitmap in the list
01872         ERROR2IF(pBitmap == NULL, 0L, "Couldn't find the default bitmap");
01873     }
01874 
01875     // ****
01876     // **** Saved this bitmap before?
01877     // ****
01878 
01879     // Only write this record out if we have not done so already
01880     // Check by seeing if the bitmap is already in our exported bitmap list
01881     ExportBitmap* pExportBitmap = NULL;
01882     pExportBitmap = pExportedBitmaps->GetBitmap(pBitmap);
01883     // If it is then do not save this bitmap
01884     if (pExportBitmap)
01885     {
01886         // Just return the record number as the bitmap reference to the caller
01887         return pExportBitmap->RecordNumber;
01888     }
01889 
01890 PORTNOTE("other", "Removed live effects stuff")
01891 #ifndef EXCLUDE_FROM_XARALX
01892     // Check to see whether we can save a simple placeholder, relying on the 
01893     // XPE to regenerate the bitmap from master and edits when it's reloaded.
01894     if (pFilter->GetSaveXPEBitmaps() == FALSE)
01895     {
01896         KernelBitmap* pMaster = NULL;
01897         IXMLDOMDocumentPtr pEdits = NULL;
01898         pBitmap->GetXPEInfo(pMaster, pEdits);
01899         if (pMaster != NULL && pEdits != NULL)
01900         {
01901             // Yes, we have a valid set of XPE info so we can regenerate on loading
01902             UINT32 recnum = pFilter->WriteXPEBitmapPlaceHolder(pBitmap->GetName());
01903             if (recnum!=0)
01904             {
01905                 BOOL bOK = FALSE;
01906 
01907                 // write out a bitmap properties record
01908                 bOK = WriteBitmapPropertiesRecord(pBitmap, pFilter, recnum);
01909                 if (!bOK) return 0L;
01910 
01911                 // Now add this exported bitmap definition record to our exported list for later reuse
01912                 pExportedBitmaps->AddBitmap(pBitmap, recnum);
01913 
01914                 return recnum;
01915             }
01916         }
01917     }
01918 #endif
01919 
01920     BOOL ok = TRUE;
01921     // Find out what bitmap compression was requested by the user
01922     // Could use BMPZIP which could be deemed to mean no compression
01923     // > 100 means use PNG
01924     // 0-100 use JPEG with this quality setting
01925     // Of course, only do this if we are in web mode
01926     INT32 Compression = pFilter->GetBitmapCompression(); 
01927     
01928     // Get details of the bitmap
01929     BitmapInfo Info;
01930     String_256 BitmapName;
01931     pBitmap->ActualBitmap->GetInfo(&Info);
01932     BitmapName = pBitmap->ActualBitmap->GetName();
01933 
01934 //  double Dpi = Info.PixelDepth;
01935     UINT32 Height = Info.PixelHeight;
01936     UINT32 NumberOfPaletteEntries = Info.NumPaletteEntries; // 0 for no palette
01937 
01938     UINT32 SearchFilter = 0;
01939     INT32 Tag = TAG_DEFINEBITMAP_BMP;
01940 
01941     // See if we have a BitmapSource for the bitmap we're exporting 
01942     BitmapSource* pSource = NULL;
01943     BaseBitmapFilter* pDummyFilter;
01944     BOOL bUseOriginalSource = pBitmap->GetOriginalSource(&pSource, &pDummyFilter);
01945     BOOL WritePalette = FALSE;
01946 
01947     if (!bUseOriginalSource)
01948     {
01949         // We don't already have a compressed source so pick a filter
01950 
01951         UINT32 Bpp = Info.PixelDepth;
01952         // Check if the bitmap has a transparent colour or masking colour present.
01953         // If so then we may need to change our saving strategy
01954         INT32 TransparentColour = -1;
01955         if (Bpp <= 8)
01956             pBitmap->ActualBitmap->GetTransparencyIndex(&TransparentColour);
01957 
01958         switch (Bpp)
01959         {
01960             case 1:
01961             case 4:
01962                 // Cannot use JPEG as only for 8,24bpp
01963                 // Both GIF and PNG support transparency
01964                 // So always use the PNG filter. 
01965                 Tag = TAG_DEFINEBITMAP_PNG;
01966                 SearchFilter = FILTERID_PNG;
01967                 break;
01968             case 8:
01969                 // JPEG does not support transparency, so if this is set then use PNG
01970                 if (TransparentColour == -1)
01971                 {
01972                     // If it is 8bpp and there is a no transparent colour present
01973                     // then we can JPEG the bitmap or PNG it. Using Accusoft this will save
01974                     // out the bitmap as a 24bpp JPEGd bitmap.
01975                     // If compression is between 0 and 100 then use JPEG
01976                     // otherwise use PNG
01977                     if (Compression >= 0 && Compression <= 100)
01978                     {
01979                         // Check if greyscale or not. If greyscale then legal JPEG so save as normal
01980                         // otherwise save as special 8BPP JPEG record 
01981                         if (pBitmap->IsGreyscale())
01982                         {
01983                             Tag = TAG_DEFINEBITMAP_JPEG;
01984                             SearchFilter = FILTERID_EXPORT_JPEG;
01985                         }
01986                         else
01987                         {
01988                             Tag = TAG_DEFINEBITMAP_JPEG8BPP;
01989                             SearchFilter = FILTERID_EXPORT_JPEG;
01990                             WritePalette = TRUE;
01991                         }
01992                     }
01993                     else
01994                     {
01995                         Tag = TAG_DEFINEBITMAP_PNG;
01996                         SearchFilter = FILTERID_PNG;
01997                     }
01998                 }
01999                 else
02000                 {
02001                     // If it is 8bpp and there is a transparent colour present
02002                     // then we must use PNG to save out this colour
02003                     Tag = TAG_DEFINEBITMAP_PNG;
02004                     SearchFilter = FILTERID_PNG;
02005                 }
02006                 break;
02007             case 24:
02008                 // If compression is between 0 and 100 then use JPEG
02009                 // otherwise use PNG
02010                 if (Compression >= 0 && Compression <= 100)
02011                 {
02012                     Tag = TAG_DEFINEBITMAP_JPEG;
02013                     SearchFilter = FILTERID_EXPORT_JPEG;
02014                 }
02015                 else if (Compression >= 201 && Compression <= 300)
02016                 {
02017                     // If compression is between 201 and 300 then use JPEG
02018                     // where the bitmap came from a lossy source
02019                     if (pBitmap->IsLossy())
02020                     {
02021                         Tag = TAG_DEFINEBITMAP_JPEG;
02022                         SearchFilter = FILTERID_EXPORT_JPEG;
02023                         Compression -= 200;     // Get quality in the correct range
02024                     }
02025                     else
02026                     {
02027                         Tag = TAG_DEFINEBITMAP_PNG;
02028                         SearchFilter = FILTERID_PNG;
02029                     }
02030                 }
02031                 else
02032                 {
02033                     Tag = TAG_DEFINEBITMAP_PNG;
02034                     SearchFilter = FILTERID_PNG;
02035                 }
02036                 break;
02037             case 32:
02038                 if (Compression >= 0 && Compression <= 200)
02039                 {
02040                     // Definitely use PNG is this case
02041                     Tag = TAG_DEFINEBITMAP_PNG;
02042                     SearchFilter = FILTERID_PNG;
02043                 }
02044                 else
02045                 {
02046                     // If compression indicates JPEG where possible then use 
02047                     // JPEG where the bitmap came from a lossy source and has 
02048                     // no transparency in its alpha channel
02049                     if (pBitmap->IsLossy() && !pBitmap->IsTransparent())
02050                     {
02051                         Tag = TAG_DEFINEBITMAP_JPEG;
02052                         SearchFilter = FILTERID_EXPORT_JPEG;
02053                         Compression -= 200;     // Get quality in the correct range
02054                     }
02055                     else
02056                     {
02057                         Tag = TAG_DEFINEBITMAP_PNG;
02058                         SearchFilter = FILTERID_PNG;
02059                     }
02060                 }
02061                 break;
02062             default:
02063                 ERROR2(0,"BitmapListComponent::SaveBitmapDefinition bad pixel depth");
02064         }
02065     }
02066     else
02067     {
02068         // We have a BitmapSource...
02069         // but we don't have the right filter...get rid of this hack!
02070         // FilterManager* pFilterManager = Camelot->GetFilterManager();
02071         // pFilter = pFilterManager->FindComplementaryFilter(pDummyFilter);
02072         Tag = TAG_DEFINEBITMAP_JPEG;
02073         SearchFilter = FILTERID_EXPORT_JPEG;
02074         // Now check if we have done a 24bpp to 8bpp conversion job on this
02075         // The way we can tell this is if the bitmap is 8bpp and not greyscale
02076         UINT32 Bpp = Info.PixelDepth;
02077         if (Bpp == 8 && !pBitmap->IsGreyscale())
02078         {
02079             Tag = TAG_DEFINEBITMAP_JPEG8BPP;
02080             WritePalette = TRUE;
02081         }
02082     }
02083     
02084     // Try and find the bitmap filter to use to load that bitmap in
02085     // Go get the first filter in the list
02086     Filter *pBmpFilter = Filter::GetFirst();
02087     while ((pBmpFilter != NULL) && (pBmpFilter->FilterID != SearchFilter))
02088     {
02089         // Try the next filter
02090         pBmpFilter = Filter::GetNext(pBmpFilter);
02091     }
02092 
02093     // Check that the Filter existed
02094     ERROR2IF(pBmpFilter == NULL,0,"BitmapListComponent::SaveBitmapDefinition can't find export filter!");
02095 
02096     // Start writing our record data out to file
02097     UINT32 Size = 0;
02098     // If there is a string name, then add it to this size
02099     // REMEMBER: We save out unicode strings and so we need to double the length of the returned string length
02100     // but only if we are not being compiled as Unicode
02101     Size += (BitmapName.Length() + 1) * SIZEOF_XAR_UTF16;
02102     if (WritePalette)
02103     {
02104         // If we are an 8bpp JPEG then we must save out the palette so that on loading we can
02105         // convert the 24bpp JPEG back into 8bpp using this palette
02106         Size += 1;  // For the number of palette entries
02107         Size += NumberOfPaletteEntries * sizeof(RGBTRIPLE);
02108     }
02109     
02110     RecordNumber = pFilter->StartStreamedRecord(Tag, Size);
02111     //RecordNumber = pFilter->StartRecord(Tag, Size); 
02112     // If we had a problem starting the record up then exit now
02113     if (RecordNumber <= 0)
02114         return RecordNumber;
02115 
02116     // Write out the name to disc
02117     ok = pFilter->Write(BitmapName);
02118 
02119     // Possibly write palette information into the record
02120     if (WritePalette)
02121     {
02122         TRACEUSER( "Neville", _T("8bpp JPEG write palette size %d to file\n"), NumberOfPaletteEntries );
02123         // If we are an 8bpp JPEG then we must save out the palette so that on loading we can
02124         // convert the 24bpp JPEG back into 8bpp using this palette
02125         // Saves number of palette entries followed by the palette in RGB triples
02126         pBitmap->WritePalette(pFilter);
02127     }
02128     
02129     // Write out the bitmap data to file
02130     // First get the CCFile that we are using for writing out the data
02131     CCLexFile* pFile = pFilter->GetCCFile();
02132     // The WriteBitmapToFile function is only available in bitmap filters so we need
02133     // to convert our pointer to that type of filter
02134     BaseBitmapFilter *pBitmapFilter = (BaseBitmapFilter *)pBmpFilter;
02135     // On the first pass this will be null as we are trying to work out the export size
02136     // so that we get the progress bar correct.
02137     if (pFile)
02138     {
02139         // Ensure all current data is flushed to file otherwise some filters
02140         // may screw up the file.
02141         pFile->flush();
02142 
02143         // Check to see if we haven't already got it compressed
02144         if (bUseOriginalSource)
02145         {
02146             // We have,so write out the source & don't degrade it
02147             ERROR2IF(pSource == NULL, 0L, "pSource == NULL");
02148             pFilter->WriteBitmapSource(*pSource, Height);
02149         }
02150         else
02151         {
02152             // We are on the real pass so go and export that bitmap data to file
02153             pBitmapFilter->WriteBitmapToFile(pBitmap, pFilter, pFile, Compression);
02154         }
02155     }
02156     else
02157     {
02158         if (WritePalette)
02159         {
02160             // If we are on the fake pass and saving the palette then include the number of
02161             // palette entries in the count.
02162             pFilter->IncProgressBarCount(NumberOfPaletteEntries);
02163         }
02164 
02165         // We are on the fake pass so add the height of the bitmap onto the progress bar count
02166         // as this is what we will use the update the progress bar
02167         pFilter->IncProgressBarCount(Height);
02168     }
02169 
02170     // Ask for the record to be ended and hence items like the size in the record header
02171     // to be cleaned up and hence made correct
02172     if (ok) ok = pFilter->EndStreamedRecord();
02173 
02174     // write out a bitmap properties record
02175     if (ok) ok = WriteBitmapPropertiesRecord(pBitmap, pFilter, RecordNumber);
02176 
02177     // If we have had a problem at any of the stages then return that to the caller
02178     if (!ok)
02179         return 0L;
02180 
02181     // Now add this exported bitmap definition record to our exported list for later reuse
02182     if (ok) ok = pExportedBitmaps->AddBitmap(pBitmap, RecordNumber);
02183 
02184     return RecordNumber;
02185 #else
02186     return 0;
02187 #endif
02188 }

BOOL BitmapListComponent::StartComponentCopy  )  [virtual]
 

This function gets called to prepare for a copy of Bitmaps into the document. It sets up the various arrays and other thangs which the Bitmap copy will need.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/12/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if it succeeded. FALSE if the copy must be aborted

Errors: ENSURE failure if called when a component copy is already under way. Errors will be reported if memory is unavailable

See also:
BitmapListComponent::EndComponentCopy; BitmapListComponent::AbortComponentCopy; BitmapListComponent::CopyBitmapAcross

Reimplemented from DocComponent.

Definition at line 1040 of file bmpcomp.cpp.

01041 {
01042     return(TRUE);
01043 }

BOOL BitmapListComponent::StartExport BaseCamelotFilter pFilter  )  [virtual]
 

Inform the bitmap list document component that a Web or Native export is about to start.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/6/96
Returns:
TRUE if the component was able to prepare for exporting; FALSE if not (e.g. out of memory)
Parameters:
pFilter - the BaseCamelotFilter filter that is being used to export a file. [INPUTS]
See also:
DocComponent

Reimplemented from DocComponent.

Definition at line 1567 of file bmpcomp.cpp.

01568 {
01569 #ifdef DO_EXPORT
01570     TRACEUSER( "Neville", _T("BitmapListComponent::StartExport\n") );
01571     // Mark all bitmaps as unsaved 
01572     if (pFilter == NULL)
01573     {
01574         ERROR3("BitmapListComponent::StartExport filter is null!");
01575         return TRUE;
01576     }
01577 
01578     // Set up and start the exported bitmap list
01579     pExportedBitmaps = new ExportedBitmaps();
01580     if (pExportedBitmaps == NULL)
01581         return FALSE;
01582 #endif
01583     return TRUE;
01584 }

BOOL BitmapListComponent::StartImport BaseCamelotFilter pFilter  )  [virtual]
 

Inform the bitmap list document component that a Native or Web import is about to start.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/6/96
Parameters:
pFilter - the BaseCamelotFilter filter that is being used to import a file. [INPUTS]
Returns:
TRUE if the component was able to prepare for importing; FALSE if not (e.g. out of memory)
See also:
DocComponent

Reimplemented from DocComponent.

Definition at line 1122 of file bmpcomp.cpp.

01123 {
01124 TRACEUSER( "Neville", _T("BitmapListComponent::StartImport\n") );
01125     if (pFilter == NULL)
01126     {
01127         ERROR3("BitmapListComponent::StartExport filter is null!");
01128         return TRUE;
01129     }
01130 
01131     // Save this in our link to the BaseCamelotFilter
01132     pCamFilter = pFilter;
01133     // Set our variable so that we warn about a possible replacement only once
01134     WarnedBefore = FALSE;
01135 
01136     // Set up and start the imported bitmap list
01137     pImportedBitmaps = new ImportedBitmaps();
01138     if (pImportedBitmaps == NULL)
01139         return FALSE;
01140 
01141     return TRUE;
01142 }

BOOL BitmapListComponent::WriteBitmapPropertiesRecord KernelBitmap pBitmap,
BaseCamelotFilter pFilter,
INT32  BmpRef
 

Helper function for SaveBitmapDefinition. Write out 'bitmap properties' record. This contains: A bitmap reference (INT32). This specifies the bitmap to which the properties apply. (This will usually be the bitmap record which immediately preceded this bmp properties record.) A single flag byte. The LSB stores the value of the 'smooth when scaled up' flag - 1 for yes, 0 for no. Other bits could be used to record other boolean bmp properties; for now these are set to 0. 7 more bytes for future use. Some of this space should be used to store GIF animation info (which is presently not saved). The remainder of the space is reserved for possible future additions to the bmp properties dialogue.

Author:
Andy_Hills (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/10/00
Parameters:
pBitmap - The document bitmap to save [INPUTS] pFilter - The filter to use for saving BmpRef - The bitmap reference
- [OUTPUTS]
Returns:
TRUE on success.
See also:
SaveBitmapDefinition

Definition at line 1750 of file bmpcomp.cpp.

01751 {
01752     BOOL ok = TRUE;
01753 
01754     // populate the record
01755     BYTE Flags = 0x00;
01756     if (pBitmap->GetInterpolation()) Flags |= 0x01;
01757 
01758     // Find out whether we need to make an XPE record or not...
01759 PORTNOTE("other","KernelBitmap::GetXPEInfo removed")
01760 #ifndef EXCLUDE_FROM_XARALX
01761     if (pFilter->GetSaveXPEBitmaps() == FALSE)
01762     {
01763         KernelBitmap* pMaster = NULL;
01764         IXMLDOMDocumentPtr pEditList = NULL;
01765         pBitmap->GetXPEInfo(pMaster, pEditList);
01766         if (pMaster!=NULL && pEditList!=NULL)
01767         {
01768             // Get master bitmap reference number (writing out the bitmap if necessary)
01769             INT32 MasterRecord = 0;
01770             MasterRecord = GetWriteBitmapReference(pMaster, pFilter);
01771     
01772             // Only write out new record style if we really have to...
01773             // (Helps forward compatibility)
01774             if (MasterRecord!=0)
01775             {
01776                 // Create a new style XPE bitmap properties record
01777                 CXaraFileRecord Rec(TAG_XPE_BITMAP_PROPERTIES);
01778     
01779                 BSTR bstrValue;
01780                 HRESULT hr;
01781                 hr = pEditList->get_xml(&bstrValue);
01782                 if (SUCCEEDED(hr))
01783                 {
01784                     ok = Rec.Init();
01785                     if (ok) ok = Rec.WriteReference(BmpRef);        // bitmap reference
01786                     if (ok) ok = Rec.WriteBYTE(Flags);              // flags
01787                     
01788                     // TODO: write GIF animation properties here
01789     
01790                     // reserved bytes
01791                     for( INT32 i=0; i<7; i++ )
01792                     {
01793                         if (ok) ok = Rec.WriteBYTE(0);
01794                     }
01795     
01796                     // Now write out XPE stuff
01797                     if (ok) ok = Rec.WriteReference(MasterRecord);      // Master bitmap record number
01798                     if (ok) ok = Rec.WriteUnicode(pBitmap->GetName());  // Oil Bitmap name
01799                     if (ok) ok = Rec.WriteBSTR(bstrValue);              // UNICODE xml string edits list
01800     
01801                     // Write the record
01802                     if (ok) ok = pFilter->Write(&Rec);
01803     
01804                     return ok;
01805                 }
01806             }
01807         }
01808     }
01809 #endif
01810 
01811     // Fallback to the original BITMAP PROPERTIES record style
01812     // Create an old style properties record
01813     CXaraFileRecord Rec(TAG_BITMAP_PROPERTIES,TAG_BITMAP_PROPERTIES_SIZE);
01814 
01815     ok = Rec.Init();
01816     if (ok) ok = Rec.WriteReference(BmpRef);    // bitmap reference
01817     if (ok) ok = Rec.WriteBYTE(Flags);          // flags
01818     
01819     // TODO: write GIF animation properties here
01820 
01821     // reserved bytes
01822     for( INT32 i=0; i<7; i++ )
01823     {
01824         if (ok) ok = Rec.WriteBYTE(0);
01825     }
01826 
01827     // Write the record
01828     if (ok) ok = pFilter->Write(&Rec);
01829 
01830     return ok;
01831 }

BOOL BitmapListComponent::WriteEPSComments EPSFilter pFilter  )  [virtual]
 

Writes out the Bitmap table in the form of EPS comments in the 'header' comments of the EPS file.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/12/94
Parameters:
pFilter - the filter being used to import the EPS file. [INPUTS]
Returns:
TRUE if the Bitmap table was written successfully; FALSE if not.

Errors: Out of disk space, and similar disk errors.

See also:
DocComponent::WriteEPSComments; DocComponent

Reimplemented from DocComponent.

Definition at line 770 of file bmpcomp.cpp.

00771 {
00772     return TRUE;
00773 }

BOOL BitmapListComponent::WriteScript EPSFilter pFilter  )  [virtual]
 

This is called after all the Comments, Prolog etc have been output so that DocComponents get a chance to do something right at the start of the real EPS data, but before the tree starts to be exported. (The base class does nothing).

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/1/95
Parameters:
pFilter - the EPS filter that is being used to export a file. [INPUTS]
Returns:
TRUE if the Script for this component was written out successfully; FALSE if not (e.g. out of disk space etc)
See also:
DocComponent::WriteEPSSetup; DocComponent::WriteEPSProlog; DocComponent::ProcessEPSComment; DocComponent; EPSFIlter

Reimplemented from DocComponent.

Definition at line 797 of file bmpcomp.cpp.

00798 {
00799 #ifdef DO_EXPORT
00800     // This only happens in Native EPS
00801     if (pFilter->IS_KIND_OF(CamelotNativeEPSFilter))
00802     {
00803         // Find out the context to save to
00804         EPSExportDC *pDC = pFilter->GetExportDC();
00805 
00806         // Make sure that there's a bitmap list to export.
00807         if (pBitmapsToExport == NULL)
00808         {
00809             ERROR3 ( "Why isn't there an export bitmap list (in WriteScript) ?" );
00810             return FALSE;
00811         }
00812 
00813         // Something to mark the start of the bitmap pool
00814         pDC->OutputToken(_T("%%BeginCamelotBitmapPool"));
00815         pDC->OutputNewLine();
00816 
00817         // Tell the filter we are starting to save the bitmap pool
00818         ((CamelotNativeEPSFilter*)pFilter)->IsSavingBitmapPool = TRUE;
00819 
00820         // Find the number of Bitmaps
00821         INT32 TotalBitmaps = pBitmapsToExport->GetCount();
00822 
00823         // Output a comment saying how many bitmaps we have
00824         pDC->OutputToken(_T("%%BitmapPoolCount"));
00825         pDC->OutputValue(TotalBitmaps);
00826         pDC->OutputNewLine();
00827 
00828         INT32 BitmapNum = 0;
00829 
00830         // Find the first bitmap in the list again
00831         ExportBitmap* pExportBitmap = pBitmapsToExport->EnumerateBitmaps();
00832 
00833         while (pExportBitmap != NULL)
00834         {
00835             ERROR3IF(pExportBitmap->RecordNumber != BitmapNum, "Bad bitmap number found when saving bitmap pool");
00836                 
00837             // Save the bitmap out
00838             ExportBitmapPoolItem(BitmapNum, pFilter, pDC, pExportBitmap->pBmp);
00839 
00840             BitmapNum++;
00841 
00842             // Find the next one
00843             pExportBitmap = pBitmapsToExport->EnumerateBitmaps(pExportBitmap);
00844         }
00845 
00846         // Tell the filter we are starting to save the bitmap pool
00847         ((CamelotNativeEPSFilter*)pFilter)->IsSavingBitmapPool = FALSE;
00848 
00849         // Something to mark the start of the bitmap pool
00850         pDC->OutputToken(_T("%%EndCamelotBitmapPool"));
00851         pDC->OutputNewLine();
00852     }
00853 
00854 #endif
00855     return TRUE;
00856 }


Member Data Documentation

BitmapList* BitmapListComponent::pBitmaps [private]
 

Definition at line 256 of file bmpcomp.h.

ExportedBitmaps* BitmapListComponent::pBitmapsToExport [protected]
 

Definition at line 253 of file bmpcomp.h.

BaseCamelotFilter* BitmapListComponent::pCamFilter [private]
 

Definition at line 289 of file bmpcomp.h.

ExportedBitmaps* BitmapListComponent::pExportedBitmaps [protected]
 

Definition at line 283 of file bmpcomp.h.

ImportedBitmaps* BitmapListComponent::pImportedBitmaps [protected]
 

Definition at line 286 of file bmpcomp.h.

BOOL BitmapListComponent::WarnedBefore [private]
 

Definition at line 292 of file bmpcomp.h.


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