PNGFilter Class Reference

Encapsulates a PNG export filter. Derives off the masked filter which provides funcitonality for doing masked bitmap export and import. More...

#include <pngfiltr.h>

Inheritance diagram for PNGFilter:

MaskedFilter BaseBitmapFilter BitmapFilter Filter ListItem CCObject SimpleCCObject PreviewFilterPNG ThumbnailFilterPNG List of all members.

Public Member Functions

 PNGFilter ()
 Constructor for an PNGFilter object. The object should be initialised before use.
BOOL Init ()
 Initialise an PNGFilter object.
virtual INT32 HowCompatible (PathName &Filename, ADDR HeaderStart, UINT32 HeaderSize, UINT32 FileSize)
 Determine if this filter can load the specified file.
virtual FilterType GetFilterType () const
virtual BOOL ReadFromFile (OILBitmap *pOilBitmap)
 Actually does the process of reading a bitmap from a file. Inherited classes override this to read in different file formats.
virtual BOOL ReadFromFile (OILBitmap *pOilBitmap, BaseCamelotFilter *pFilter, CCLexFile *pFile, BOOL IsCompressed)
 Actually does the process of reading a bitmap from a file. Inherited classes override this to read in different file formats. It is used by the web/native filters to pull out a bitmap definition from inside a bitmap definition record. IsCompressed is only used for BMP/BMPZIP type bitmaps at present. Assumes: pFile has already been opened up for reading pFilter has been set up for reading the data e.g. progress bar.
virtual BOOL WriteBitmapToFile (KernelBitmap *pKernelBitmap, BaseCamelotFilter *pFilter, CCLexFile *pFile, INT32 Compression)
virtual BOOL IsThisBppOk (UINT32 Bpp)
 Check if this Bitmap filter can cope with saving at this Bpp/Colour depth.
virtual INT32 GetPNGCompatibility ()
virtual UINT32 GetExportMsgID ()
 Used to get the message id to be used during export. Overides the baseclass form of the function so that during the two stage export process it can change the message.
virtual void PostGetExportOptions (BitmapExportOptions *pOptions)

Protected Member Functions

virtual void InvertAlpha (LPBITMAPINFO lpBitmapInfo, LPBYTE lpBits)
 Camelot uses a different transparency scheme to the rest of the world, in that 255 is clear, and 0 is opaque. Until the rest of the world catches up, it's necessary to invert the alpha channel to make exported files compatible with other programs.
virtual OutputDIBGetOutputDIB (void)
 Casts the current output DIB to be a generic OutputDIB class. This allows the same code to be re-used in the base class.
virtual BitmapExportOptionsCreateExportOptions () const
 See BaseBitmapFilter for interface details Notes: Provides a new PNGExportOptions instance.
virtual BOOL GetExportOptions (BitmapExportOptions *pOptions)
 See BaseBitmapFilter for interface details.
virtual void CleanUpAfterExport ()
 Cleans up the memory allocated at the end of Exporting or when exporting has been aborted for some reason. Does its cleaning up and then calls the baseclass version to do its stuff, - used when the import process ends, either normally or abnormally. Override if extra things are required.
virtual BOOL EndWriteToFile ()
 Cleans up after writing the bitmap data out to a file. Inherited classes override this to write in different file formats. This is slightly different to most other bitmap filters in that it is here that the data actually gets written out to file, after doing the transparency translation, if required.
virtual BOOL WriteFileHeader (void)
 To write out the file specific header data.
virtual BOOL WritePreFrame (void)
 To write out any frame specific info before the image.
virtual BOOL WritePreSecondPass (void)
 Called to do any processing required after the first and before the second pass of a two pass export.
virtual BOOL WritePostOptimisedPalette (void)
 Called after the optimised palette has been generated but before the export of the bitmap.
virtual BOOL WriteFrame (void)
 To write out the image itself This base class version actually calls the WriteToFile() function so that derived classes do not have to implement any of the multi-image stuff.
virtual BOOL WritePostFrame (void)
 To write out any frame specific info after the image.
virtual BOOL WriteFileEnd (void)
 To write out the file specific data at the end of the file This base class version calls EndWriteToFile() so that derived classes do not have to implement the multi-image stuff.
virtual BOOL WriteBitmapToFile (KernelBitmap *pKernelBitmap, double Dpi)
 Physically put the bitmap into the disk. Inherited classes override this to write in different file formats.
void AlterPaletteContents (LPLOGPALETTE pPalette)

Static Protected Member Functions

static BOOL WriteDataToFile (BOOL End, UINT32 Bpp, UINT32 Compression)
 Physically put the bitmap into the disk. NOTE - ONLY COPES WITH End=TRUE currently AtEnd is ignored now and should always be set to TRUE. Unused at present due to static problems when cretaing the 1bpp bitmap.
static BOOL WriteToFile (CCLexFile *, LPBITMAPINFO Info, LPBYTE Bits, String_64 *ProgressString=NULL)
 Write a bitmap in memory straight out as a PNG to file with no rendering or conversion between different colour depths (apart from 32 to 24) or resolution. Errors on 16-bit builds*** A progress hourglass can be shown if required. This function is used by the save bitmap button on the bitmap gallery. All other bitmap export uses the OutputDIB class instead as this copes with using a render region and converting from 32 to the destination format. (caller should close file).
static BOOL WriteToFile (CCLexFile *, LPBITMAPINFO Info, LPBYTE Bits, BOOL Interlace, INT32 TransparentColour, BaseCamelotFilter *pFilter=NULL)
 Write a bitmap in memory straight out as a PNG to file with no rendering or conversion between different colour depths (apart from 32 to 24) or resolution. Errors on 16-bit builds*** A progress hourglass can be shown if required using the BaseCamelotFilter as the controlling influence.

Protected Attributes

INT32 PNGHowCompatible
UINT32 Export2ndStageMsgID

Static Protected Attributes

static FilterType s_FilterType = PNG

Private Member Functions

 CC_DECLARE_DYNAMIC (PNGFilter)

Detailed Description

Encapsulates a PNG export filter. Derives off the masked filter which provides funcitonality for doing masked bitmap export and import.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/4/96

Definition at line 155 of file pngfiltr.h.


Constructor & Destructor Documentation

PNGFilter::PNGFilter  ) 
 

Constructor for an PNGFilter object. The object should be initialised before use.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/4/96
See also:
PNGFilter::Init

Definition at line 229 of file pngfiltr.cpp.

00229                      : MaskedFilter()
00230 {
00231     ImportMsgID = _R(IDS_IMPORTMSG_PNG);
00232     Flags.CanImport = TRUE;
00233     Flags.CanExport = TRUE;
00234 
00235     FilterID = PNG;
00236     ExportMsgID = _R(IDS_EXPORTMSG_PNG);            // "Preparing PNG file..."
00237     ExportingMsgID = _R(IDS_EXPORTINGMSG_PNG);      // "Exporting PNG file..."
00238 
00239     // Special Mask prepartion stage ID
00240     Export2ndStageMsgID = _R(IDN_MASKINGMSG_PNG);   // "Preparing mask for PNG file..."
00241     ExportRegion = NULL;
00242 }


Member Function Documentation

void PNGFilter::AlterPaletteContents LPLOGPALETTE  pPalette  )  [protected, virtual]
 

Reimplemented from BaseBitmapFilter.

Definition at line 1215 of file pngfiltr.cpp.

01216 {
01217     DestPNG.AlterExportPalette( pPalette );
01218 }

PNGFilter::CC_DECLARE_DYNAMIC PNGFilter   )  [private]
 

void PNGFilter::CleanUpAfterExport  )  [protected, virtual]
 

Cleans up the memory allocated at the end of Exporting or when exporting has been aborted for some reason. Does its cleaning up and then calls the baseclass version to do its stuff, - used when the import process ends, either normally or abnormally. Override if extra things are required.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/5/96
See also:
BaseBitmapFilter::PrepareToExport(); BaseBitmapFilter::CleanUpAfterExport(); Scope: Protected

Reimplemented from BaseBitmapFilter.

Definition at line 564 of file pngfiltr.cpp.

00565 {
00566     // Called right at the end of the export process or when the epxort has been aborted
00567     // Clean up any objects unique to this class.
00568     // Free up any DIBs that we might have left lying around on the export
00569     if (pDestBMInfo && pDestBMBytes)
00570     {
00571         FreeDIB( pDestBMInfo, pDestBMBytes );
00572         pDestBMInfo = NULL;
00573         pDestBMBytes = NULL;    
00574     }
00575 
00576     // the depth we ask GDraw to render is always 32-bit, so we can get transparency
00577     // we have to convert for other formats when writing the actual bytes to the file
00578     SetDepthToRender(32);
00579 
00580     // We haven't written the header yet
00581     WrittenHeader = FALSE;
00582 
00583     // We are a first pass render and not doing the mask, by default
00584     SecondPass = FALSE;
00585     DoingMask = FALSE;
00586 
00587     // Now call the baseclass version to do its stuff
00588     BaseBitmapFilter::CleanUpAfterExport();
00589 }

BitmapExportOptions * PNGFilter::CreateExportOptions  )  const [protected, virtual]
 

See BaseBitmapFilter for interface details Notes: Provides a new PNGExportOptions instance.

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

Reimplemented from BaseBitmapFilter.

Definition at line 1209 of file pngfiltr.cpp.

01210 {
01211     PNGExportOptions* pPNGOptions = new PNGExportOptions(PNG, &FilterName);
01212     return (BitmapExportOptions*)pPNGOptions;
01213 }

BOOL PNGFilter::EndWriteToFile void   )  [protected, virtual]
 

Cleans up after writing the bitmap data out to a file. Inherited classes override this to write in different file formats. This is slightly different to most other bitmap filters in that it is here that the data actually gets written out to file, after doing the transparency translation, if required.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/5/96
Parameters:
- [INPUTS]
Returns:
TRUE if worked, FALSE if failed.

Reimplemented from BaseBitmapFilter.

Definition at line 657 of file pngfiltr.cpp.

00658 {
00659     if (GeneratingOptimisedPalette())
00660         return TRUE;        // No need to output anything
00661 
00662     //  Can reset the band number now.
00663     m_BandNumber = 0;
00664 
00665     PNGExportOptions* pPNGOptions = (PNGExportOptions*)GetBitmapExportOptions();
00666     ERROR2IF(pPNGOptions == NULL, FALSE, "NULL Args");
00667     ERROR3IF(!pPNGOptions->IS_KIND_OF(PNGExportOptions), "pPNGOptions isn't");
00668 
00669     // Do the transparency translation just before we write out the data as a PNG.
00670     // This involves doing a 1 bpp export of the same area and using this to work
00671     // out which areas are transparent or not.
00672     // Only do this if the user has requested transparency and we outputting at 8bpp
00673     BOOL ok = TRUE;
00674     BOOL SaveDataOut = TRUE;
00675 
00676     if (BadExportRender)
00677     {
00678         // Delete our whitearea bitmap
00679         if (pTempBitmapMask != NULL)
00680             CCFree(pTempBitmapMask);
00681 
00682         pTempBitmapMask = NULL;
00683     }
00684 
00685     // Save the data out if required. Only if we exported ok.
00686     if (SaveDataOut && !BadExportRender)
00687     {
00688         if (ok)
00689         {
00690             // Now that we know the transparent index we can output the PNG header
00691             ok = DestPNG.OutputPNGHeader(OutputFile, NULL, pPNGOptions->WantInterlaced(),
00692                                         pPNGOptions->GetTransparencyIndex(),
00693                                         pPNGOptions->GetDepth() <= 8 ? pPNGOptions->GetLogicalPalette() : NULL);
00694         }
00695 
00696         // Actually write the destination bitmap out to the file showing an hourglass
00697         // and/or progress bar as we go. Always show the Exporting message.
00698         // Need to do in one go due to interlacing
00699         if (ok)
00700         {
00701             String_64 ProgressString(ExportingMsgID);
00702             ProgressString = GetExportProgressString(OutputFile, ExportingMsgID);
00703             BeginSlowJob(100, FALSE, &ProgressString);
00704             
00705             DestPNG.OutputPNGBits(OutputFile, DestPNG.GetDestBitmapBits());
00706             
00707             EndSlowJob();
00708         }
00709     }
00710 
00711     ASSERT(ok);
00712     
00713     return DestPNG.TidyUp();
00714 }

UINT32 PNGFilter::GetExportMsgID  )  [virtual]
 

Used to get the message id to be used during export. Overides the baseclass form of the function so that during the two stage export process it can change the message.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
10/07/96
Returns:
The id of the message to put on the progress display whilst exporting.
See also:
DoExport; TI_GIFFilter::GetExportMsgID;

Reimplemented from BaseBitmapFilter.

Definition at line 604 of file pngfiltr.cpp.

00605 {
00606     if (GeneratingOptimisedPalette())
00607         return _R(IDS_GENOPTPALMSGID);              // "Generating optimised palette..."
00608 
00609     PNGExportOptions* pPNGOptions = (PNGExportOptions*)GetBitmapExportOptions();
00610     ERROR2IF(pPNGOptions == NULL, FALSE, "NULL Args");
00611     ERROR3IF(!pPNGOptions->IS_KIND_OF(PNGExportOptions), "pPNGOptions isn't");
00612 
00613     // If we are exporting with transparency on and on first pass use the masking message
00614     // otherwise use the exporting message.
00615     if (pPNGOptions->GetSelectionType() == SELECTION && pPNGOptions->WantTransparent())
00616     {
00617         // Special 4 stage rendering operation
00618         // - Render selected objects to white background
00619         // - Render mask 1bpp
00620         // - Render all objects
00621         // - Save data out to disk
00622         if (!SecondPass)
00623             return Export2ndStageMsgID;         // "Preparing mask for PNG file..."
00624         else
00625             return Filter::GetExportMsgID();    // "Preparing PNG file..."
00626     }
00627     else
00628     {
00629         // Special 3 stage rendering operation
00630         // - Render objects to white background
00631         // - Render mask 1bpp
00632         // - Save data out to disk
00633         if (DoingMask)
00634             return Export2ndStageMsgID;         // "Preparing mask for PNG file..."
00635         else
00636             return Filter::GetExportMsgID();    // "Preparing PNG file..."
00637     }
00638 
00639     return ExportingMsgID;
00640 }

BOOL PNGFilter::GetExportOptions BitmapExportOptions pOptions  )  [protected, virtual]
 

See BaseBitmapFilter for interface details.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/11/96

Reimplemented from BaseBitmapFilter.

Reimplemented in PreviewFilterPNG.

Definition at line 463 of file pngfiltr.cpp.

00464 {
00465     ERROR2IF(pOptions == NULL, FALSE, "NULL Args");
00466 
00467     PNGExportOptions* pPNGOptions = (PNGExportOptions*)pOptions;
00468     ERROR3IF(!pPNGOptions->IS_KIND_OF(PNGExportOptions), "pPNGOptions isn't");
00469 
00470     // the depth we ask GDraw to render is always 32-bit, so we can get transparency
00471     // we have to convert for other formats when writing the actual bytes to the file
00472     SetDepthToRender(32);
00473 
00474     // We haven't written the header yet
00475     WrittenHeader = FALSE;
00476 
00477     // We are a first pass render and not doing the mask, by default
00478     SecondPass = FALSE;
00479     DoingMask = FALSE;
00480 
00481     // Determine the filter type currently in use in Accusoft format
00482     s_FilterType = PNG;
00483     pPNGOptions->SetFilterType(PNG);
00484 
00485     BOOL Ok = FALSE;
00486 
00487     OpDescriptor* pOpDes = OpDescriptor::FindOpDescriptor(OPTOKEN_GIFTABDLG);
00488     if (pOpDes != NULL)
00489     {
00490         // set up the data for the export options dialog
00491         OpParam Param((void *)pOptions, (void *)this);
00492 
00493         // invoke the dialog
00494         pOpDes->Invoke(&Param);
00495 
00496         // SMFIX
00497         // we have brought the dlg up so get the options from the dlg as the graphic type may have changed
00498         pOptions = BmapPrevDlg::m_pExportOptions;
00499 
00500         // check for valid options
00501         //  This may get messed up, so have to use the second line below.
00502         Ok = BmapPrevDlg::m_bClickedOnExport;
00503     }
00504     else
00505     {   
00506         ERROR3("Unable to find OPTOKEN_BMAPPREVDLG");
00507     } 
00508 
00509     // Return with the ok/cancel state used on the dialog box
00510     return Ok;
00511 }

virtual FilterType PNGFilter::GetFilterType  )  const [inline, virtual]
 

Reimplemented from BaseBitmapFilter.

Definition at line 167 of file pngfiltr.h.

00167 { return PNG; }

OutputDIB * PNGFilter::GetOutputDIB void   )  [protected, virtual]
 

Casts the current output DIB to be a generic OutputDIB class. This allows the same code to be re-used in the base class.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/6/00 Returns OutputDIB* - A pointer to DestPNG.

Reimplemented from MaskedFilter.

Definition at line 1193 of file pngfiltr.cpp.

01194 {
01195     // Perform an upcast to allow the pointer to be used in a generic manner.
01196     return static_cast<OutputDIB*> ( &DestPNG );
01197 }

virtual INT32 PNGFilter::GetPNGCompatibility  )  [inline, virtual]
 

Definition at line 184 of file pngfiltr.h.

00184 { return PNGHowCompatible; }

INT32 PNGFilter::HowCompatible PathName Filename,
ADDR  HeaderStart,
UINT32  HeaderSize,
UINT32  FileSize
[virtual]
 

Determine if this filter can load the specified file.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/4/96
Parameters:
Filename - name of the file. [INPUTS] HeaderStart - Address of the first few bytes of the file. HeaderSize - the number of bytes in the header pointed to by FileStart. FileSize - the size of the whole file, in bytes.
Returns:
0 => Not a PNG file. 10 => It is a PNG file.

Reimplemented from Filter.

Definition at line 290 of file pngfiltr.cpp.

00292 {
00293 PORTNOTE("byteorder", "TODO: Check byte ordering")
00294     // We need to remember what we thought of this file in our class variable.
00295     // So, set it to a nice default value at the start.
00296     PNGHowCompatible = 0;
00297 
00298     // Check that we've got enough data to do our check
00299     if (HeaderSize < 8)
00300         return 0; // Not enough data - ignore this file.
00301 
00302     // Check the header for the "PNG" signature.
00303     // The first eight bytes of a PNG file always contain the following (decimal) values: 
00304     // 137 80 78 71 13 10 26 10 
00305     if (
00306         (HeaderStart[0] == 137) && // 0x89
00307         (HeaderStart[1] == 80) && //  0x50
00308         (HeaderStart[2] == 78) && //  0x4E
00309         (HeaderStart[3] == 71) && //  0x47
00310         (HeaderStart[4] == 13) && // Carriage return
00311         (HeaderStart[5] == 10) && // Line feed
00312         (HeaderStart[6] == 26) && // end of file (0x1a)
00313         (HeaderStart[7] == 10)    // Line feed
00314        )
00315     {
00316         // This should be a good enough check that this is a PNG file
00317         // Hence, we like this file
00318         PNGHowCompatible = 10;
00319     }
00320                 
00321     // Return the found value to the caller.
00322     return PNGHowCompatible;
00323 }

BOOL PNGFilter::Init void   )  [virtual]
 

Initialise an PNGFilter object.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/4/96
Returns:
TRUE if the filter was initialised ok, FALSE otherwise.

Errors: Will fail if not enough memory to initialise.

See also:
EPSStack

Reimplemented from MaskedFilter.

Reimplemented in PreviewFilterPNG.

Definition at line 256 of file pngfiltr.cpp.

00257 {
00258     // Get the OILFilter object
00259     pOILFilter = new PNGOILFilter(this);
00260     if (pOILFilter==NULL)
00261         return FALSE;
00262 
00263     // Load the description strings
00264     FilterName.Load(_R(IDS_PNG_FILTERNAME));
00265     FilterInfo.Load(_R(IDS_PNG_FILTERINFO));
00266 
00267     if (!PNGExportOptions::Declare())
00268         return FALSE;
00269 
00270     // All ok
00271     return TRUE;
00272 }

void PNGFilter::InvertAlpha LPBITMAPINFO  lpBitmapInfo,
LPBYTE  lpBits
[protected, virtual]
 

Camelot uses a different transparency scheme to the rest of the world, in that 255 is clear, and 0 is opaque. Until the rest of the world catches up, it's necessary to invert the alpha channel to make exported files compatible with other programs.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/6/00

Reimplemented from MaskedFilter.

Definition at line 1176 of file pngfiltr.cpp.

01178 {
01179     DIBUtil::InvertAlpha(lpBitmapInfo, lpBits);
01180 }

BOOL PNGFilter::IsThisBppOk UINT32  Bpp  )  [virtual]
 

Check if this Bitmap filter can cope with saving at this Bpp/Colour depth.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/4/96
Parameters:
Bpp or Colour depth. [INPUTS]
Returns:
TRUE if this filter can cope with this colour depth, FALSE otherwise.
See also:
OpMenuExport::DoWithParam;

Reimplemented from BaseBitmapFilter.

Definition at line 337 of file pngfiltr.cpp.

00338 {
00339     return (Bpp == 1 || Bpp == 4 || Bpp == 8 || Bpp == 24 || Bpp == 32);
00340 }

void PNGFilter::PostGetExportOptions BitmapExportOptions pOptions  )  [virtual]
 

Reimplemented from BaseBitmapFilter.

Definition at line 517 of file pngfiltr.cpp.

00518 {
00519     // should be of this type
00520     PNGExportOptions* pPNGOptions = (PNGExportOptions*)pOptions;
00521     ERROR3IF(!pPNGOptions->IS_KIND_OF(PNGExportOptions), "pPNGOptions isn't");
00522 
00523     // do the baseclass options
00524     MaskedFilter::PostGetExportOptions(pOptions);
00525 
00526     // do the specific to this class options
00527     // Filter type can be changed by the export options dialog box from say 
00528     // PNG to PNG_INTERLACED
00529     UINT32 Silliness = pPNGOptions->WantTransparent() ? 2 : 0;
00530     Silliness |= pPNGOptions->WantInterlaced() ? 1 : 0;
00531     if (Silliness >= 0 && Silliness <= 4)
00532     {
00533         Compression = Silliness;
00534         // Compression ranges from 0 .. 4 so map this onto our filter types
00535 //      s_FilterType = PNG + Silliness;
00536         switch (Silliness)
00537         {
00538         case 0: s_FilterType = PNG; break;
00539         case 1: s_FilterType = PNG_INTERLACED; break;
00540         case 2: s_FilterType = PNG_TRANSPARENT; break;
00541         case 3: s_FilterType = PNG_TRANSINTER; break;
00542         }
00543 
00544         if (pPNGOptions->WantTransparent() && pPNGOptions->GetSelectionType() == SELECTION)
00545             DoingMask = TRUE;
00546     }
00547 }

BOOL PNGFilter::ReadFromFile OILBitmap pOilBitmap,
BaseCamelotFilter pFilter,
CCLexFile pFile,
BOOL  IsCompressed
[virtual]
 

Actually does the process of reading a bitmap from a file. Inherited classes override this to read in different file formats. It is used by the web/native filters to pull out a bitmap definition from inside a bitmap definition record. IsCompressed is only used for BMP/BMPZIP type bitmaps at present. Assumes: pFile has already been opened up for reading pFilter has been set up for reading the data e.g. progress bar.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/7/96
Parameters:
pOilBitmap pointer to the oil bitmap data to be filled in [INPUTS] pFilter - the BaseCamelotFilter which provides functions like progress update pFile - the CCFile class to use to read the data from IsCompressed - Flag to say the bitmap is compressed or not.
Will have filled in BMInfo pointer to the bitmap header to fill in [OUTPUTS] BMBytes pointer to the bitmap data to fill in
Returns:
TRUE if worked, FALSE if failed.

Reimplemented from BaseBitmapFilter.

Definition at line 366 of file pngfiltr.cpp.

00368 {
00369     ERROR2IF(pOilBitmap == NULL,FALSE,"BMPFilter::ReadFromFile null OilBitmap pointer");
00370     ERROR2IF(pFilter == NULL,FALSE,"BMPFilter::ReadFromFile null pFilter pointer");
00371     ERROR2IF(pFile == NULL,FALSE,"BMPFilter::ReadFromFile null pFile pointer");
00372 
00373     // Try to import bitmap as usual binary BMP file.
00374     CWxBitmap* pWBitmap = (CWxBitmap*)pOilBitmap;
00375     
00376     LPBITMAPINFO *pInfo = &(pWBitmap->BMInfo);
00377     LPBYTE *pBytes = &(pWBitmap->BMBytes);
00378 
00379     INT32 TransColour = -1;
00380 
00381     // Read from file,using pFilter for progress bar updates
00382     if (!PNGUtil::ReadFromFile(pFile, pInfo, pBytes, &TransColour, NULL, pFilter))
00383         return FALSE;
00384 
00385     if(pWBitmap->BMInfo->bmiHeader.biBitCount == 32)
00386     {
00387         // If we`re exporting a 32Bit BMP then we need to make sure that we convert the
00388         // Alpha channel to Transparency! i.e. invert it!
00389         UINT32 BmpSize = pWBitmap->BMInfo->bmiHeader.biSizeImage;
00390         BYTE* Bits = pWBitmap->BMBytes;
00391 
00392         for(UINT32 i = 0; i < BmpSize; i+=4)
00393             Bits[i+3] = ~Bits[i+3];
00394     }
00395 
00396     // Everything went ok and we imported the bitmap ok
00397     SetTransColour(TransColour);
00398     UINT32 Bpp = pWBitmap->GetBPP();
00399     if (TransColour != -1 && Bpp <= 8)
00400         pOilBitmap->SetTransparencyIndex(TransColour);
00401 
00402     SetLastBitmap();        // can only import one bitmap at the moment
00403     return TRUE;
00404 }

BOOL PNGFilter::ReadFromFile OILBitmap pOilBitmap  )  [virtual]
 

Actually does the process of reading a bitmap from a file. Inherited classes override this to read in different file formats.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/4/96
Parameters:
pOilBitmap pointer to the oil bitmap data to be filled in [INPUTS]
Will have filled in BMInfo pointer to the bitmap header to fill in [OUTPUTS] BMBytes pointer to the bitmap data to fill in
Returns:
TRUE if worked, FALSE if failed.

Reimplemented from BaseBitmapFilter.

Definition at line 421 of file pngfiltr.cpp.

00422 {
00423     ERROR2IF(pOilBitmap == NULL,FALSE,"PNGFilter::ReadFromFile null OilBitmap pointer");
00424     
00425     // Try to import the bitmap as a PNG file.      
00426     CCLexFile *pImportFile = GetImportFile();
00427     ERROR2IF(pImportFile==NULL,FALSE,"PNGFilter::ReadFromFile - No import file");
00428 
00429     UINT32 ImportMsgId = GetImportMsgID();      
00430     String_64 ProgressString(ImportMsgId);
00431     ProgressString = GetImportProgressString(pImportFile, ImportMsgId);
00432 
00433     CWxBitmap* pWBitmap = (CWxBitmap*)pOilBitmap;
00434     
00435     LPBITMAPINFO *pInfo = &(pWBitmap->BMInfo);
00436     LPBYTE *pBytes = &(pWBitmap->BMBytes);
00437     
00438     INT32 TransColour = -1;
00439 
00440     // The PNG filter liked it very much and so use it, showing progress bar
00441     if (!PNGUtil::ReadFromFile(pImportFile, pInfo, pBytes, &TransColour, &ProgressString))
00442         return FALSE;
00443 
00444     SetTransColour(TransColour);
00445     UINT32 Bpp = pWBitmap->GetBPP();
00446     if (TransColour != -1 && Bpp <= 8)
00447         pOilBitmap->SetTransparencyIndex(TransColour);
00448 
00449     SetLastBitmap();        // can only import one bitmap at the moment
00450     
00451     return TRUE;
00452 }

BOOL PNGFilter::WriteBitmapToFile KernelBitmap pKernelBitmap,
double  Dpi
[protected, virtual]
 

Physically put the bitmap into the disk. Inherited classes override this to write in different file formats.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/4/96
Parameters:
Pointer to the bitmap to save. [INPUTS] Dpi of the bitmap to be saved
Returns:
TRUE if worked, FALSE if errored.
See also:
WriteDataToFile(); AccusoftFilters::WriteToFile; AccusoftFilters::WriteDataToFile;

Reimplemented from BaseBitmapFilter.

Definition at line 754 of file pngfiltr.cpp.

00755 {
00756     ERROR2IF(pKernelBitmap == NULL,FALSE,"PNGFilter::WriteBitmapToFile null bitmap pointer specified");
00757 
00758     // Get a pointer to the actual bitmap so that we can get some details from it.
00759     OILBitmap *pOilBitmap = pKernelBitmap->ActualBitmap;
00760     ERROR2IF(pOilBitmap == NULL,FALSE,"PNGFilter::WriteBitmapToFile null oil bitmap pointer");
00761 
00762     // Now get the pointer to the info header and actual bits data.
00763     // Need to use the actual bitmap pointer
00764     CWxBitmap* pWBitmap = (CWxBitmap*)pOilBitmap;
00765     LPBITMAPINFO pInfo = pWBitmap->BMInfo;
00766     LPBYTE pBytes = pWBitmap->BMBytes;
00767 //  UINT32 Bpp = pWBitmap->GetBPP();
00768 
00769     // Now, save the data out showing the correct progress string
00770     String_64 ProgressString(ExportingMsgID);
00771     BOOL ok = FALSE;
00772 //  BOOL Interlace = TRUE;  // Use interlace or not
00773 //  BOOL Transparency = FALSE;  // Use transparency or not
00774 
00775     if(pInfo->bmiHeader.biBitCount == 32)
00776     {
00777         // If we`re exporting a 32Bit BMP then we need to make sure that we convert the
00778         // Alpha channel to Transparency! i.e. invert it!
00779         UINT32 BmpSize = pInfo->bmiHeader.biSizeImage;
00780 
00781         for(UINT32 i = 0; i < BmpSize; i+=4)
00782             pBytes[i+3] = ~pBytes[i+3];
00783     }
00784 
00785     ok = WriteToFile(OutputFile, pInfo, pBytes, &ProgressString);
00786 
00787     //  This function is used when saving from the bitmap gallery. If we save a 32-bit bitmap as
00788     //  a PNG, then we have to undo the alpha channel reversing that we did above.
00789     //  Failure to do this will change the bitmap displayed in the bitmap gallery.
00790     if(pInfo->bmiHeader.biBitCount == 32)
00791     {
00792         UINT32 BmpSize = pInfo->bmiHeader.biSizeImage;
00793 
00794         for(UINT32 i = 0; i < BmpSize; i+=4)
00795             pBytes[i+3] = ~pBytes[i+3];
00796     }
00797     
00798     return ok;
00799 }

BOOL PNGFilter::WriteBitmapToFile KernelBitmap pKernelBitmap,
BaseCamelotFilter pFilter,
CCLexFile pFile,
INT32  Compression
[virtual]
 

Reimplemented from BaseBitmapFilter.

Definition at line 822 of file pngfiltr.cpp.

00824 {
00825     ERROR2IF(pKernelBitmap == NULL,FALSE, "PNGFilter::WriteBitmapToFile null pKernelBitmap");
00826     ERROR2IF(pFilter == NULL,FALSE, "PNGFilter::WriteBitmapToFile null pFilter");
00827     ERROR2IF(pFile == NULL,FALSE, "PNGFilter::WriteBitmapToFile null pFile");
00828 
00829     // Get a pointer to the actual bitmap so that we can get some details from it.
00830     OILBitmap *pOilBitmap = pKernelBitmap->ActualBitmap;
00831     ERROR2IF(pOilBitmap == NULL,FALSE,"PNGFilter::WriteBitmapToFile null oil bitmap pointer");
00832 
00833     // Now get the pointer to the info header and actual bits data.
00834     // Need to use the actual bitmap pointer
00835     CWxBitmap* pWBitmap = (CWxBitmap*)pOilBitmap;
00836     LPBITMAPINFO Info = pWBitmap->BMInfo;
00837     LPBYTE Bytes = pWBitmap->BMBytes;
00838     UINT32 Bpp = pWBitmap->GetBPP();
00839 
00840     // Now, save the data out showing the correct progress string
00841     BOOL ok = FALSE;
00842     BOOL Interlace = FALSE;     // Must not use interlacing as it will screw the progress bar updates
00843 //  BOOL Transparency = FALSE;  // Use transparency or not
00844     INT32 Transparent = -1; // colour or -1 = no transparency
00845     if (Bpp <= 8)
00846         pOilBitmap->GetTransparencyIndex(&Transparent);
00847     
00848     if(Info->bmiHeader.biBitCount == 32)
00849     {
00850         // If we`re exporting a 32Bit BMP then we need to make sure that we convert the
00851         // Alpha channel to Transparency! i.e. invert it!
00852         UINT32 BmpSize = Info->bmiHeader.biSizeImage;
00853 
00854         for(UINT32 i = 0; i < BmpSize; i+=4)
00855             Bytes[i+3] = ~Bytes[i+3];
00856     }
00857     
00858     // Write to file, no header and using pFilter for progress bar updates
00859     ok = WriteToFile(pFile, Info, Bytes, Interlace, Transparent, pFilter);
00860     
00861     return ok;
00862 }

BOOL PNGFilter::WriteDataToFile BOOL  End,
UINT32  Bpp,
UINT32  Compression
[static, protected]
 

Physically put the bitmap into the disk. NOTE - ONLY COPES WITH End=TRUE currently AtEnd is ignored now and should always be set to TRUE. Unused at present due to static problems when cretaing the 1bpp bitmap.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/5/96
Parameters:
End - TRUE if this is the last block of the file. [INPUTS] Bpp - output depth in terms of bits per pixel Compression - usually True if compression required, False otherwise In the PNG case this is used to pass in the transparency and interlace state.
Returns:
TRUE if worked, FALSE if errored.
See also:
WriteToFile(); AccusoftFilters::WriteToFile; AccusoftFilters::WriteDataToFile;

Definition at line 735 of file pngfiltr.cpp.

00736 {
00737     ERROR2(FALSE,"PNGFilter::WriteDataToFile called when not implemented");
00738 }

BOOL PNGFilter::WriteFileEnd void   )  [protected, virtual]
 

To write out the file specific data at the end of the file This base class version calls EndWriteToFile() so that derived classes do not have to implement the multi-image stuff.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/7/96
Parameters:
- [INPUTS]
Returns:
FALSE if failed else TRUE
See also:
GIFFilter::WriteFileEnd(void)

Reimplemented from BaseBitmapFilter.

Definition at line 1140 of file pngfiltr.cpp.

01141 {
01142     return DestPNG.TidyUp();
01143 }

virtual BOOL PNGFilter::WriteFileHeader void   )  [inline, protected, virtual]
 

To write out the file specific header data.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/6/96
Parameters:
- [INPUTS]
Returns:
FALSE if failed else TRUE
See also:
-

Reimplemented from BaseBitmapFilter.

Definition at line 205 of file pngfiltr.h.

00205 { return TRUE; }

BOOL PNGFilter::WriteFrame void   )  [protected, virtual]
 

To write out the image itself This base class version actually calls the WriteToFile() function so that derived classes do not have to implement any of the multi-image stuff.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/7/96
Parameters:
- [INPUTS]
Returns:
FALSE if failed else TRUE
See also:
GIFFilter::WriteFrame(void)

Reimplemented from BaseBitmapFilter.

Definition at line 1103 of file pngfiltr.cpp.

01104 {
01105     return MaskedFilter::WriteToFile(TRUE);
01106 }

BOOL PNGFilter::WritePostFrame void   )  [protected, virtual]
 

To write out any frame specific info after the image.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/7/96
Parameters:
- [INPUTS]
Returns:
FALSE if failed else TRUE
See also:
GIFFilter::WritePostFrame(void)

Reimplemented from BaseBitmapFilter.

Definition at line 1121 of file pngfiltr.cpp.

01122 {
01123     return EndWriteToFile();
01124 }

virtual BOOL PNGFilter::WritePostOptimisedPalette void   )  [inline, protected, virtual]
 

Called after the optimised palette has been generated but before the export of the bitmap.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/6/96
Parameters:
- [INPUTS]
Returns:
FALSE if failed else TRUE
See also:
-

Reimplemented from BaseBitmapFilter.

Definition at line 208 of file pngfiltr.h.

00208 { return TRUE; }

BOOL PNGFilter::WritePreFrame void   )  [protected, virtual]
 

To write out any frame specific info before the image.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/7/96
Parameters:
- [INPUTS]
Returns:
FALSE if failed else TRUE
See also:
GIFFilter::WritePreFrame(void)

Reimplemented from BaseBitmapFilter.

Definition at line 1084 of file pngfiltr.cpp.

01085 {
01086     return DestPNG.ReStartFile(NULL);
01087 }

BOOL PNGFilter::WritePreSecondPass void   )  [protected, virtual]
 

Called to do any processing required after the first and before the second pass of a two pass export.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/7/96
Parameters:
- [INPUTS]
Returns:
FALSE if failed else TRUE
See also:
GIFFilter::WritePreSecondPass(void)

Reimplemented from BaseBitmapFilter.

Definition at line 1158 of file pngfiltr.cpp.

01159 {
01160     return EndWriteToFile();
01161 }

BOOL PNGFilter::WriteToFile CCLexFile File,
LPBITMAPINFO  Info,
LPBYTE  Bits,
BOOL  Interlace,
INT32  TransparentColour,
BaseCamelotFilter pFilter = NULL
[static, protected]
 

Write a bitmap in memory straight out as a PNG to file with no rendering or conversion between different colour depths (apart from 32 to 24) or resolution. Errors on 16-bit builds*** A progress hourglass can be shown if required using the BaseCamelotFilter as the controlling influence.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
10/7/96
Parameters:
File An opened CCFile that can be written to. It should be positioned at the [INPUTS] start. Caller is responsible for closing it. The file needs to be in Binary mode. Info BITMAPINFO structure for the dib. Bits The bitmap data itself Interlace allows interlacing to be turned off or on Transparent if -1 then no transpparent colour, if not -1 then specifies the index number of the transparent colour in the palette pFilter is an alternative way of handling the progress bar, assume the progress bar has been start and just call the IncProgressBarCount in BaseCamelotFilter to do the progress bar update. Defaults to NULL i.e. no progress bar.
- [OUTPUTS]
Returns:
TRUE if worked, FALSE if failed (error will be set accordingly but not reported)
This function is used by the new native/web file format to do a straight save of the data into the file.

(caller should close file)

Returns:
Errors: Calls SetError on FALSE returns. Scope: Static
See also:
AccusoftFilters::WriteToFile; DIBUtil::WriteToFile;

Definition at line 900 of file pngfiltr.cpp.

00903 {
00904 #ifdef DO_EXPORT
00905     ERROR2IF(File==NULL,FALSE,"PNGFilter::WriteToFile File pointer is null");
00906     ERROR2IF(Info==NULL,FALSE,"PNGFilter::WriteToFile BitmapInfo pointer is null");
00907     ERROR2IF(Bits==NULL,FALSE,"PNGFilter::WriteToFile Bits pointer is null");
00908 
00909     // BITMAPINFO  consists of:-
00910     //      BITMAPINFOHEADER    bmiHeader;
00911     //      RGBQUAD             bmiColors[1];
00912     LPBITMAPINFOHEADER pInfoHeader = &Info->bmiHeader;
00913     ERROR2IF(pInfoHeader==NULL,FALSE,"PNGFilter::WriteToFile BitmapInfoHeader pointer is null");
00914         
00915     LPRGBQUAD pPalette = &(Info->bmiColors[0]);
00916     ERROR2IF(pPalette==NULL,FALSE,"PNGFilter::WriteToFile palette pointer is null");
00917 
00918     // Set up our format type flags.
00919     if(Info->bmiHeader.biBitCount == 32)
00920     {
00921         // If we`re exporting a 32Bit BMP then we need to make sure that we convert the
00922         // Alpha channel to Transparency! i.e. invert it!
00923         UINT32 BmpSize = Info->bmiHeader.biSizeImage;
00924 
00925         for(UINT32 i = 0; i < BmpSize; i+=4)
00926             Bits[i+3] = ~Bits[i+3];
00927     }
00928 
00929     // Output a PNG header for this file, using the RGBQUAD palette rather than a LOGPALETTE
00930     DestPNG.OutputPNGHeader(File, pInfoHeader, Interlace, TransparentColour, NULL, pPalette);
00931 
00932     // Now write out the bitmap data itself.
00933     DestPNG.OutputPNGBits(File, Bits, TRUE, pFilter);
00934 
00935     // The above has set the OutputFile member variable of DestPNG. We desperately need to
00936     // reset this as otherwise the next bitmap export may go wrong as it calls the tidy up
00937     // and so will refer to the deleted CCFile. Oh Er!
00938     DestPNG.TidyUp();
00939 
00940     // er, we seem to have finished OK so say so
00941     return TRUE;
00942 #else
00943     return FALSE;
00944 #endif
00945 }

BOOL PNGFilter::WriteToFile CCLexFile File,
LPBITMAPINFO  Info,
LPBYTE  Bits,
String_64 ProgressString = NULL
[static, protected]
 

Write a bitmap in memory straight out as a PNG to file with no rendering or conversion between different colour depths (apart from 32 to 24) or resolution. Errors on 16-bit builds*** A progress hourglass can be shown if required. This function is used by the save bitmap button on the bitmap gallery. All other bitmap export uses the OutputDIB class instead as this copes with using a render region and converting from 32 to the destination format. (caller should close file).

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/4/96
Parameters:
File An opened CCFile that can be written to. It should be positioned at the [INPUTS] start. Caller is responsible for closing it. The file needs to be in Binary mode. Info BITMAPINFO structure for the dib. Bits The bitmap data itself ProgressString allows the user to specify whether they require a progress hourglass or not. If NULL then none is shown, otherwise an progress bar is shown using the text supplied. Defaults to NULL i.e. no progress bar.
- [OUTPUTS]
Returns:
TRUE if worked, FALSE if failed (error will be set accordingly but not reported)

Errors: Calls SetError on FALSE returns. Scope: Static

See also:
AccusoftFilters::WriteToFile; DIBUtil::WriteToFile;

Definition at line 977 of file pngfiltr.cpp.

00979 {
00980 #ifdef DO_EXPORT
00981     ERROR2IF(File==NULL,FALSE,"PNGFilter::WriteToFile File pointer is null");
00982     ERROR2IF(Info==NULL,FALSE,"PNGFilter::WriteToFile BitmapInfo pointer is null");
00983     ERROR2IF(Bits==NULL,FALSE,"PNGFilter::WriteToFile Bits pointer is null");
00984 
00985     // If the caller has specified a string then assume they require a progress bar
00986     // Start it up.
00987     if (ProgressString != NULL)
00988         BeginSlowJob(100, FALSE, ProgressString);
00989 
00990     // BITMAPINFO  consists of:-
00991     //      BITMAPINFOHEADER    bmiHeader;
00992     //      RGBQUAD             bmiColors[1];
00993     LPBITMAPINFOHEADER pInfoHeader = &Info->bmiHeader;
00994     ERROR2IF(pInfoHeader==NULL,FALSE,"PNGFilter::WriteToFile BitmapInfoHeader pointer is null");
00995         
00996     LPRGBQUAD pPalette = &(Info->bmiColors[0]);
00997     ERROR2IF(pPalette==NULL,FALSE,"PNGFilter::WriteToFile palette pointer is null");
00998 
00999     // Set up our format type flags.
01000     BOOL Interlace = TRUE;  // Use interlace or not
01001     INT32 Transparent = -1; // colour or -1 = no transparency
01002     BOOL WantTransparent = FALSE;
01003 
01004     switch (s_FilterType)
01005     {
01006         default:
01007         case PNG:
01008             Interlace       = FALSE;
01009             WantTransparent = FALSE;
01010             break;
01011         case PNG_INTERLACED:
01012             Interlace       = TRUE;
01013             WantTransparent = FALSE;
01014             break;
01015         case PNG_TRANSPARENT:
01016             Interlace       = FALSE;
01017             WantTransparent = TRUE;
01018             break;
01019         case PNG_TRANSINTER:
01020             Interlace       = TRUE;
01021             WantTransparent = TRUE;
01022             break;
01023     }
01024 
01025     if (WantTransparent)
01026     {
01027         // We want to try and output the transparency if possible ...
01028 
01029         // Scan through the palette, and try and find an index with
01030         // the transparency flag set
01031 
01032         INT32 cols = Info->bmiHeader.biClrUsed;
01033         // If we have zero colours on a bitmap which is 8bpp or less then this is bad.
01034         // This should be translated as the maximum number of colours allowed
01035         if (Info->bmiHeader.biBitCount <= 8 && cols == 0)
01036             cols = 1 << Info->bmiHeader.biBitCount;
01037 
01038         for (INT32 i = 0; i < cols; i++)
01039         {
01040             if (Info->bmiColors[i].rgbReserved == 0xFF)
01041             {
01042                 Transparent = i;
01043                 TRACEUSER( "Neville", _T("PNG output with transp index of %d\n"),Transparent);
01044                 break;
01045             }       
01046         }   
01047     }
01048 
01049     // Output the PNG data
01050     BOOL ok = TRUE;
01051     // Output a PNG header for this file, using the RGBQUAD palette rather than a LOGPALETTE
01052     if (Transparent == -1)
01053         ok = DestPNG.OutputPNGHeader(File, pInfoHeader, Interlace, -1, NULL, pPalette);
01054     else
01055         ok = DestPNG.OutputPNGHeader(File, pInfoHeader, Interlace, Transparent, NULL, pPalette);
01056 
01057     // Now write out the bitmap data itself.
01058     if (ok)
01059         ok = DestPNG.OutputPNGBits(File, Bits, TRUE);
01060     
01061     // If started, then stop then progress bar
01062     if (ProgressString != NULL)
01063         EndSlowJob();
01064 
01065     // er, we seem to have finished OK so say so
01066     return TRUE;
01067 #else
01068     return FALSE;
01069 #endif
01070 }


Member Data Documentation

UINT32 PNGFilter::Export2ndStageMsgID [protected]
 

Definition at line 238 of file pngfiltr.h.

INT32 PNGFilter::PNGHowCompatible [protected]
 

Definition at line 233 of file pngfiltr.h.

FilterType PNGFilter::s_FilterType = PNG [static, protected]
 

Definition at line 235 of file pngfiltr.h.


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