JPEGExportFilter Class Reference

Provides an Accusoft-free JPEG export filter. More...

#include <exjpeg.h>

Inheritance diagram for JPEGExportFilter:

BaseBitmapFilter BitmapFilter Filter ListItem CCObject SimpleCCObject PreviewFilterJPEG List of all members.

Public Member Functions

 JPEGExportFilter ()
 Default constructor for a JPEGFilter object.
 ~JPEGExportFilter ()
 Default destructor for a JPEGExportFilter object.
virtual BOOL Init ()
 Initializes the JPEGExportFilter class.
INT32 HowCompatible (PathName &Filename, ADDR HeaderStart, UINT32 HeaderSize, UINT32 FileSize)
virtual BOOL IsThisBppOk (UINT32 Bpp)
 Overriden for JPEG specifics: supports 24 & 8.
virtual BOOL WriteBitmapToFile (KernelBitmap *pKernelBitmap, double Dpi)
 To duplicate code.
virtual BOOL WriteBitmapToFile (KernelBitmap *pKernelBitmap, BaseCamelotFilter *pFilter, CCLexFile *pFile, INT32 Compression)
BOOL WriteBitmapSource (BitmapSource *Source, UINT32 Height, BaseCamelotFilter *pThisFilter, CCLexFile *pCCFile)
 Writes out the given BitmapSource to this file.
BOOL DoExportBitmapWithOptions (Operation *pOp, CCLexFile *pFile, PathName *pPath, KernelBitmap *pBitmap, BitmapExportOptions *pOptions)
 Exports the specified bitmap straight out to file with none of the rendering that DoExport does. Uses the virtual fns of the inherited class. Do not override unless really necessary. Similar to DoExportBitmap in the base class, but uses the passed options, rather then invoking a dialog to get ones.
virtual BitmapExportOptionsCreateExportOptions () const
 Overrides base class to provide JPEGExportOptions See Also: BaseBitmapFilter::CreateExportOptions().
virtual void PostGetExportOptions (BitmapExportOptions *pOptions)

Protected Member Functions

virtual BOOL SetExportHint (Document *pDoc)
 Overrides base class to set correct hint See Also: BaseBitmapFilter::SetExportHint().
virtual BOOL GetRenderBottomToTop ()
 See BaseBitmapFilter for details Notes: From IJG docs: "Image data should be written in top-to-bottom scanline order. The JPEG spec contains some weasel wording about how top and bottom are application-defined terms (a curious interpretation of the English language...) but if you want your files to be compatible with everyone else's, you WILL use top-to-bottom order.".
virtual BOOL GetExportOptions (BitmapExportOptions *pOptions)
 Overridden version provides JPEG export dialog Scope: Protected See Also: BaseBitmapFilter::GetBitmapExportOptions().
virtual BOOL PrepareForOperation ()
 Support function to do something before any actual output.
virtual BOOL PrepareToExport (Spread *pSpread, UINT32 Depth, double DPI, SelectionType Selection, UINT32 Dither)
BOOL InternalPrepareToExport ()
 Support function setting up the IJG library options and starting the compression.
BOOL EndWriteToFile (void)
 Overrides base class: does nothing See Also: BaseBitmapFilter::EndWriteToFile(void).
virtual BOOL WriteFileHeader (void)
 To write out the file specific header data: actually sets up the JPEG filter.
virtual BOOL WriteFrame (void)
 Overrides 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)
 Overrides base class to finish JPEG compression cycle of the current frame.
virtual void CleanUpAfterExport ()
 Overridden to clean up JPEG specific mess.
BOOL DoFilter (KernelBitmap *pKernelBitmap, CCLexFile *pFile)
BOOL WriteRawBitmap (const ADDR &pBitmapData, const BMP_SIZE &Width, const BMP_SIZE &Height, const BMP_DEPTH &Depth, DIBConvert *pConverter)
 Support function for writing out the bitmap scanlines Called by WriteFrame() & WriteBitmap().
BOOL InitErrorHandler ()
 Creates & initializes an error handler for this filter.
BOOL InitFileHandler ()
 Creates & initializes a source data provider for this filter.
FilterGetFilterForUpdate () const
 Allows feedback to any primary filter.
BOOL SetFilterForUpdate (Filter *const pFilterForUpdate)
 Sets the filter for any progress update on export Notes: Should be set to NULL for ordinary import.
BOOL GetPostOperation () const
void SetPostOperation (BOOL Value)

Protected Attributes

BOOL m_bOldReportErrors
BOOL m_bOldThrowExceptions
BOOL m_PostOperation
Filterm_pFilterForUpdate
libJPEG::jpeg_compress_struct m_cinfo
JPEGErrorManagerm_pErrorHandler
JPEGDataDestinationm_pDestinationHandler

Private Member Functions

 CC_DECLARE_DYNAMIC (JPEGExportFilter)

Detailed Description

Provides an Accusoft-free JPEG export filter.

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

Definition at line 196 of file exjpeg.h.


Constructor & Destructor Documentation

JPEGExportFilter::JPEGExportFilter  ) 
 

Default constructor for a JPEGFilter object.

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

Definition at line 600 of file exjpeg.cpp.

00600                                    : BaseBitmapFilter()
00601 {
00602     // Initialize members for class Filter
00603     ExportMsgID =       _R(IDS_EXPORTMSG_JPG);          // "Preparing JPEG file..."
00604     ExportingMsgID =    _R(IDS_EXPORTINGMSG_JPG);       // "Exporting JPEG file..."
00605 
00606     Flags.CanImport                 = FALSE;
00607     Flags.CanExport                 = TRUE;
00608     Flags.CanExportMultipleImages   = FALSE;
00609     Flags.ShowFilter                = TRUE;
00610 
00611     FilterID = FILTERID_EXPORT_JPEG;
00612 
00613     // Initialize our class members
00614     m_bOldReportErrors      = FALSE;
00615     m_bOldThrowExceptions   = FALSE;
00616 
00617     m_pFilterForUpdate  = NULL;
00618 
00619     m_pErrorHandler         = NULL;
00620     m_pDestinationHandler   = NULL;
00621     m_PostOperation = TRUE;
00622 }

JPEGExportFilter::~JPEGExportFilter  ) 
 

Default destructor for a JPEGExportFilter object.

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

Definition at line 634 of file exjpeg.cpp.

00635 {
00636     if (m_pErrorHandler != NULL)
00637         delete m_pErrorHandler;
00638 
00639     if (m_pDestinationHandler != NULL)
00640         delete m_pDestinationHandler;
00641 }


Member Function Documentation

JPEGExportFilter::CC_DECLARE_DYNAMIC JPEGExportFilter   )  [private]
 

void JPEGExportFilter::CleanUpAfterExport  )  [protected, virtual]
 

Overridden to clean up JPEG specific mess.

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

Reimplemented from BaseBitmapFilter.

Definition at line 1477 of file exjpeg.cpp.

01478 {
01479     if (GetPostOperation())
01480     {
01481         libJPEG::jpeg_destroy_compress(&m_cinfo);
01482     }
01483 
01484     if (m_pDestinationHandler != NULL)
01485     {
01486         delete m_pDestinationHandler;
01487         m_pDestinationHandler = NULL;
01488     }
01489 
01490     if (m_pErrorHandler != NULL)
01491     {
01492         delete m_pErrorHandler;
01493         m_pErrorHandler = NULL;
01494     }
01495 
01496     // Now call the baseclass version to do its stuff
01497     BaseBitmapFilter::CleanUpAfterExport();
01498 }

BitmapExportOptions * JPEGExportFilter::CreateExportOptions  )  const [virtual]
 

Overrides base class to provide JPEGExportOptions See Also: BaseBitmapFilter::CreateExportOptions().

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

Reimplemented from BaseBitmapFilter.

Definition at line 1567 of file exjpeg.cpp.

01568 {
01569     JPEGExportOptions* pExportOptions = new JPEGExportOptions(JPEG, &FilterName);
01570 
01571     return (BitmapExportOptions*)pExportOptions;
01572 }

BOOL JPEGExportFilter::DoExportBitmapWithOptions Operation pOp,
CCLexFile pFile,
PathName pPath,
KernelBitmap pBitmap,
BitmapExportOptions pOptions
[virtual]
 

Exports the specified bitmap straight out to file with none of the rendering that DoExport does. Uses the virtual fns of the inherited class. Do not override unless really necessary. Similar to DoExportBitmap in the base class, but uses the passed options, rather then invoking a dialog to get ones.

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

Reimplemented from BaseBitmapFilter.

Definition at line 1690 of file exjpeg.cpp.

01692 {
01693 #ifdef DO_EXPORT
01694     ERROR2IF(pBitmap == NULL,FALSE,"BaseBitmapFilter::DoExportBitmap null bitmap pointer specified");
01695 
01696     if (pOptions == NULL)
01697     {
01698         // Create a record of information about the export
01699         SetUpExportBitmapOptions(&pOptions, pBitmap, TRUE);
01700     }
01701 
01702     if (pOptions == NULL)
01703         return FALSE;
01704 
01705     // remember the old export options
01706 //  BitmapExportOptions *pOldOptions = GetBitmapExportOptions();
01707 //  if (pOldOptions != NULL)
01708 //      pOldOptions->RetrieveDefaults();
01709 
01710     // Added by Craig Hamilton 11/9/00.
01711     // Make a copy of the old options since the pointer to the old options gets vaped by
01712     // SetExportOptions. The copy is used to reinitialise pOldOptions later.
01713 //  BitmapExportOptions *tempOptions = pOldOptions->MakeCopy();
01714     // End added.
01715     
01716     // set the new ones
01717     SetExportOptions(pOptions);
01718     pOptions->SetAsDefaults();
01719 
01720     // Make a note of the Disk file we are to use
01721     OutputFile = pFile;
01722 
01723     // Note this pointer for later use
01724     pExportBitmap = pBitmap;
01725 
01726     // Note this ptr for use in JPEG export.
01727     JPEGExportOptions::SetKernelBitmap(pBitmap);
01728     
01729     // Get a pointer to the actual bitmap so that we can get some details from it.
01730     OILBitmap *pOilBitmap = pBitmap->ActualBitmap;
01731     ERROR2IF(pOilBitmap == NULL,FALSE,"BaseBitmapFilter::DoExportBitmap null oil bitmap pointer");
01732 
01733     // Get the details from the specified bitmap
01734     BitmapInfo BmInfo;
01735     pOilBitmap->GetInfo(&BmInfo);
01736     GetBitmapExportOptions()->SetDepth(BmInfo.PixelDepth);  // get the bitmaps bpp
01737     
01738     // Should really save the dpi when we load the file itself rather than doing
01739     // all this conversion with possible rounding errors.
01740     // Use the original size that has been calculated in the info header
01741     UINT32 PixWidth  = BmInfo.PixelWidth;
01742 //  UINT32 PixHeight = BmInfo.PixelHeight;
01743     MILLIPOINT  RecWidth = BmInfo.RecommendedWidth;
01744 //  MILLIPOINT  RecHeight = BmInfo.RecommendedHeight;
01745 //  double DPI = 0.0;
01746     if (PixWidth > 0)
01747     {
01748         //DPI = Mul32Div32( PixWidth,  72000, RecWidth );
01749         GetBitmapExportOptions()->SetDPI((PixWidth * 72000.0)/(double)RecWidth);
01750     }
01751 
01752     BOOL ok = TRUE;
01753 
01754     // Used to open the file up before starting DoExport. But this meant a cancel on the export
01755     // options dialog had filled the file, if it was already present. So now up up here if
01756     // not open already. In the PreviewBitmap case the file will already be open.
01757     if (!pFile->isOpen())
01758     {
01759         if (pFile->IsKindOf(CC_RUNTIME_CLASS(CCDiskFile)))
01760         {
01761             ok = OpenExportFile((CCDiskFile*) pFile, pPath);
01762             if (!ok) return FALSE;
01763         }
01764         else
01765         {
01766             TRACEUSER( "JustinF", _T("Tried to open non-CCDiskFile in BaseBitmapFilter::DoExportBitmap\n"));
01767             return FALSE;
01768         }
01769     }
01770 
01771     // Make a note of the Disk file we are to use
01772     OutputFile = pFile;
01773 
01774     // We do not use an export region so specify null.
01775     ExportRegion = NULL;
01776     
01777     // Actually write to the file, showing progress hourglass as we go
01778     ok = WriteBitmapToFile(pBitmap, GetBitmapExportOptions()->GetDPI());
01779 
01780     if (ok)
01781         WriteFileEnd();
01782 
01783     // All done - deallocate dynamic objects, stop the progress display/hourglass
01784     // and return success. (Also closes file).
01785     CleanUpAfterExport();
01786 
01787     // restore the old export options
01788 //  if (pOldOptions != NULL)
01789 //  {
01790         // Added by Craig Hamilton 11/9/00.
01791         // With the call to SetExportOptions the memory pointed to by pOldOptions is vaped.
01792         // Use tempOptions to reinitialise or get an access violation.
01793 //      pOldOptions = tempOptions->MakeCopy();
01794         // End added.
01795 
01796 //      SetExportOptions(pOldOptions);
01797 //      pOldOptions->SetAsDefaults();
01798 //  }
01799 
01800     // restore the file
01801     OutputFile = pFile;
01802 
01803     return ok;
01804 #else
01805     return FALSE;
01806 #endif
01807 }

BOOL JPEGExportFilter::DoFilter KernelBitmap pKernelBitmap,
CCLexFile pFile
[protected]
 

Definition at line 885 of file exjpeg.cpp.

00886 {
00887     ERROR2IF(pKernelBitmap == NULL || pFile == NULL, FALSE, "NULL Args");
00888     ERROR3IF(!pKernelBitmap->IS_KIND_OF(KernelBitmap), "pKernelBitmap isn't");
00889     ERROR3IF(!pFile->IS_KIND_OF(CCLexFile), "pFile isn't");
00890 
00891     JPEGExportOptions* pOptions = (JPEGExportOptions*)GetBitmapExportOptions();
00892 
00893     if (pOptions == NULL)
00894         return FALSE;
00895 
00896     OILBitmap* pOily = pKernelBitmap->GetActualBitmap();
00897 
00898     if (pOptions->GetJPEGPresentAndSelected())
00899     {
00900         SetPostOperation(FALSE);
00901 
00902         // Get the origianl source. 
00903         BitmapSource* pSource = NULL;
00904         BaseBitmapFilter* pDummyFilter;
00905 
00906         KernelBitmap* pBitmap = pOptions->GetKernelBitmap();
00907 
00908         if (pBitmap == NULL)
00909             return FALSE;
00910 
00911         // set our KernelBitmap pointer to NULL.
00912         pOptions->SetKernelBitmap(NULL);
00913 
00914         pBitmap->GetOriginalSource(&pSource,&pDummyFilter);
00915         OILBitmap* pOILBitmap = pBitmap->ActualBitmap;
00916 
00917         if (pOILBitmap == NULL)
00918             return FALSE;
00919 
00920         BitmapInfo Info;
00921         pOILBitmap->GetInfo(&Info);
00922         UINT32 Height = Info.PixelHeight;
00923                         
00924         // Write out the orginal JPEG image.
00925         if(WriteBitmapSource(pSource, Height, (BaseCamelotFilter*) pDummyFilter, pFile))
00926             return TRUE;
00927     }
00928     else
00929     {
00930         BOOL bOK = FALSE;
00931         bOK = PrepareForOperation();
00932         DIBConvert* pConverter = NULL;
00933 
00934         switch (pOily->GetBPP())
00935         {
00936             case 8:
00937                 if (pKernelBitmap->IsGreyscale())
00938                 {
00939                     pOptions->SetColourModel(libJPEG::JCS_GRAYSCALE);
00940                 }
00941                 else
00942                 {
00943                     pOptions->SetColourModel(libJPEG::JCS_RGB);
00944                 }
00945                 break;
00946 
00947             case 24:
00948             case 32:
00949                 pOptions->SetColourModel(libJPEG::JCS_RGB);
00950                 break;
00951     
00952             default:
00953                 ERROR3("DoFilter: invalid bpp");
00954                 bOK = FALSE;
00955                 break;
00956         }
00957         // Create a converter from bitmap depth to export depth
00958 //      pConverter = DIBConvert::Create(((WinBitmap*)pOily)->BMInfo, 
00959 //                                      (8 * pOptions->GetColourComponentCount()));
00960         pConverter = DIBConvert::Create(((CWxBitmap*)pOily)->BMInfo,
00961                                         (8 * pOptions->GetColourComponentCount()));
00962 
00963         if (bOK)
00964         {
00965             SetPixelWidth(pOily->GetWidth());
00966             SetPixelHeight(pOily->GetHeight());
00967             SetDepthToRender(pOily->GetBPP());
00968 
00969             bOK = InternalPrepareToExport();
00970         }
00971 
00972         if (bOK)
00973         {
00974             bOK = WriteRawBitmap(   pKernelBitmap->GetBitmapBits(), 
00975                                     GetPixelWidth(), GetPixelHeight(), pOily->GetBPP(),
00976                                     pConverter);
00977         }
00978     
00979         if (bOK)
00980         {
00981             bOK = WritePostFrame();
00982         }
00983 
00984 
00985         if (pConverter != NULL)
00986         {
00987             delete pConverter;
00988         }
00989         CleanUpAfterExport();
00990 
00991         // set our KernelBitmap pointer to NULL.
00992         pOptions->SetKernelBitmap(NULL);
00993         return bOK;
00994     }
00995     // set our KernelBitmap pointer to NULL.
00996     pOptions->SetKernelBitmap(NULL);
00997     return FALSE;
00998 }

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

Overrides base class: does nothing See Also: BaseBitmapFilter::EndWriteToFile(void).

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

Reimplemented from BaseBitmapFilter.

Definition at line 1461 of file exjpeg.cpp.

01462 {
01463     return TRUE;
01464 }

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

Overridden version provides JPEG export dialog Scope: Protected See Also: BaseBitmapFilter::GetBitmapExportOptions().

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

Reimplemented from BaseBitmapFilter.

Reimplemented in PreviewFilterJPEG.

Definition at line 1064 of file exjpeg.cpp.

01065 {
01066 #if !defined(EXCLUDE_FROM_RALPH)
01067     ERROR2IF(pOptions == NULL, FALSE, "NULL Args");
01068 
01069     BOOL Ok = TRUE;
01070 
01071 //  JPEGExportOptions* pJPEGOptions = (JPEGExportOptions*)pOptions;
01072 //  ERROR3IF(!pJPEGOptions->IS_KIND_OF(JPEGExportOptions), "pJPEGOptions isn't");
01073 
01074     OpDescriptor* pOpDes = OpDescriptor::FindOpDescriptor(OPTOKEN_GIFTABDLG);
01075     if (pOpDes != NULL)
01076     {
01077         // set up the data for the export options dialog
01078         OpParam Param( pOptions, this );
01079 
01080         // invoke the dialog
01081         pOpDes->Invoke(&Param);
01082 
01083         // SMFIX
01084         // we have brought the dlg up so get the options from the dlg as the graphic type may have changed
01085         pOptions = BmapPrevDlg::m_pExportOptions;
01086 
01087         // check for valid options
01088         //  This may get messed up, so have to use the second line below.
01089         Ok = BmapPrevDlg::m_bClickedOnExport;   
01090         
01091     }
01092     else
01093     {   
01094         ERROR3("Unable to find OPTOKEN_GIFTABDLG");
01095     } 
01096 
01097 /*  if (Ok)
01098     {
01099         // If Ok used then set the new defaults
01100         pJPEGOptions->SetAsDefaults();
01101     
01102         pJPEGOptions->SetDepth(24);     // Always output at 24bpp
01103 
01104         SetDepthToRender(24);
01105     }
01106 */
01107     // Return with the ok/cancel state used on the dialog box
01108     return Ok;
01109 #else
01110     return FALSE;
01111 #endif
01112 }

Filter * JPEGExportFilter::GetFilterForUpdate  )  const [protected]
 

Allows feedback to any primary filter.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/10/96
Returns:
A pointer to the filter whose member IncProgressBarCount() is called during the export for progress update or NULL if no filter is to be used for such

Definition at line 1642 of file exjpeg.cpp.

01643 {
01644     return m_pFilterForUpdate;
01645 }

BOOL JPEGExportFilter::GetPostOperation  )  const [inline, protected]
 

Definition at line 261 of file exjpeg.h.

00261 {return m_PostOperation;   }

BOOL JPEGExportFilter::GetRenderBottomToTop  )  [protected, virtual]
 

See BaseBitmapFilter for details Notes: From IJG docs: "Image data should be written in top-to-bottom scanline order. The JPEG spec contains some weasel wording about how top and bottom are application-defined terms (a curious interpretation of the English language...) but if you want your files to be compatible with everyone else's, you WILL use top-to-bottom order.".

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

Reimplemented from BaseBitmapFilter.

Definition at line 701 of file exjpeg.cpp.

00702 {
00703     return FALSE;
00704 }

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

Reimplemented from Filter.

Definition at line 208 of file exjpeg.h.

00209                                          {return 0;}    // dummy implementation

BOOL JPEGExportFilter::Init void   )  [virtual]
 

Initializes the JPEGExportFilter class.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/10/96
Returns:
TRUE if the filter was initialized ok FALSE otherwise

Reimplemented from BaseBitmapFilter.

Reimplemented in PreviewFilterJPEG.

Definition at line 655 of file exjpeg.cpp.

00656 {
00657     // Get the OILFilter object
00658     pOILFilter = new JPEGExportOILFilter(this);
00659     if (pOILFilter==NULL)
00660         return FALSE;
00661 
00662     // Load the description strings
00663     FilterName.Load(_R(IDS_JPG_IMP_FILTERNAME));
00664     FilterInfo.Load(_R(IDS_JPG_IMP_FILTERINFO));
00665 
00666     if (DeclareFilterPreferenceSection())
00667     {
00668         Camelot.DeclarePref( NULL, g_szCompression, &g_DefaultCompression, 0, 100 );
00669         Camelot.DeclarePref( NULL, g_szDCTMethod, (INT32*)&g_DefaultDCTMethod, 0, 2 );
00670         Camelot.DeclarePref( NULL, g_szProgressive, &g_bExportProgressive, 0, 1 );
00671         Camelot.DeclarePref( NULL, g_szOptimize, &g_bOptimizeCoding, 0, 1 );
00672         Camelot.DeclarePref( NULL, g_szSmoothing,  &g_Smoothing, 0, 100 );
00673 
00674 //      DeclarePreference(Compression);
00675 //      DeclarePreference(DCTMethod);
00676 //      DeclarePreference(Progressive);
00677 //      DeclarePreference(Xppm);
00678 //      DeclarePreference(Yppm);
00679     }
00680     // All ok
00681     return TRUE;
00682 }

BOOL JPEGExportFilter::InitErrorHandler  )  [protected]
 

Creates & initializes an error handler for this filter.

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

Definition at line 1510 of file exjpeg.cpp.

01511 {
01512     if (m_pErrorHandler == NULL)
01513     {
01514         m_pErrorHandler = new JPEGErrorManager;
01515         if (m_pErrorHandler == NULL)
01516         {
01517             Error::SetError(_R(IDS_OUT_OF_MEMORY));
01518             return FALSE;
01519         }
01520 
01521     }
01522     m_cinfo.err = m_pErrorHandler->GetErrorMgrStruct();
01523     return TRUE;
01524 }

BOOL JPEGExportFilter::InitFileHandler  )  [protected]
 

Creates & initializes a source data provider for this filter.

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

Definition at line 1536 of file exjpeg.cpp.

01537 {
01538     SetPostOperation(TRUE);
01539 
01540     if (m_cinfo.dest == NULL)
01541     {
01542         if (m_pDestinationHandler == NULL)
01543         {
01544             m_pDestinationHandler = new JPEGDataDestination(GetExportFile());
01545             if (m_pDestinationHandler == NULL)
01546             {
01547                 Error::SetError(_R(IDS_OUT_OF_MEMORY));
01548                 return FALSE;
01549             }
01550         }
01551         m_pDestinationHandler->Init(&m_cinfo);
01552     }
01553     return TRUE;
01554 }

BOOL JPEGExportFilter::InternalPrepareToExport  )  [protected]
 

Support function setting up the IJG library options and starting the compression.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/10/96
Returns:
FALSE if failed else TRUE
See also:
PrepareToExport(), DoFilter() (callers)

Definition at line 1180 of file exjpeg.cpp.

01181 {
01182     JPEGExportOptions* pExportInfo = (JPEGExportOptions*)GetBitmapExportOptions();
01183     ERROR3IF(!pExportInfo->IS_KIND_OF(JPEGExportOptions), "pExportInfo isn't");
01184 
01185     m_cinfo.image_width     = GetPixelWidth();
01186     m_cinfo.image_height    = GetPixelHeight();
01187 
01188     m_cinfo.in_color_space      = pExportInfo->GetColourModel();
01189     m_cinfo.input_components    = pExportInfo->GetColourComponentCount();
01190 
01191     try
01192     {
01193         libJPEG::jpeg_set_defaults(&m_cinfo);
01194 
01195         if (pExportInfo->DoAsProgressive())
01196         {
01197             libJPEG::jpeg_simple_progression(&m_cinfo);
01198         }
01199 
01200         m_cinfo.density_unit    = 1;    // that's JFIF for DPI
01201         m_cinfo.X_density       = UINT16 (pExportInfo->GetDPI());
01202         m_cinfo.Y_density       = UINT16 (pExportInfo->GetDPI());
01203 
01204         libJPEG::jpeg_set_quality (&m_cinfo, pExportInfo->GetQuality(), TRUE);
01205 
01206         m_cinfo.optimize_coding     = g_bOptimizeCoding;
01207         m_cinfo.smoothing_factor    = g_Smoothing;
01208 
01209         // DCT algorithm preference
01210         m_cinfo.dct_method = pExportInfo->GetDCTMethod();
01211 
01212 
01213         libJPEG::jpeg_start_compress(&m_cinfo, TRUE);   // "TRUE" for complete JPEG interchange datastream
01214     }
01215     catch (...)
01216     {
01217         StringID errorString = m_pErrorHandler->GetStringIDForError();
01218         Error::SetError(errorString);
01219         return FALSE;
01220     }
01221 
01222     return TRUE;
01223 }

BOOL JPEGExportFilter::IsThisBppOk UINT32  Bpp  )  [virtual]
 

Overriden for JPEG specifics: supports 24 & 8.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/10/96
Parameters:
See BaseBitmapFilter for interface details [INPUTS]

Reimplemented from BaseBitmapFilter.

Definition at line 717 of file exjpeg.cpp.

00718 {
00719     return (Bpp == 24 || Bpp == 8);
00720 }

void JPEGExportFilter::PostGetExportOptions BitmapExportOptions pOptions  )  [virtual]
 

Reimplemented from BaseBitmapFilter.

Definition at line 1119 of file exjpeg.cpp.

01120 {
01121     // should be of this type
01122 
01123     // do the baseclass options
01124     BaseBitmapFilter::PostGetExportOptions(pOptions);
01125 
01126     // do the specific to this class options
01127     pOptions->SetDepth(24);     // Always output at 24bpp
01128     SetDepthToRender(24);
01129 }

BOOL JPEGExportFilter::PrepareForOperation  )  [protected, virtual]
 

Support function to do something before any actual output.

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

Definition at line 1010 of file exjpeg.cpp.

01011 {
01012     // The error handling in the following should probably be replaced by exceptions at
01013     // some time, when somebody can decide on a standard.
01014 
01015     // Set up a JPEGErrorManager
01016     if (!InitErrorHandler())
01017     {
01018         return FALSE;
01019     }
01020     
01021     // Initialize the main JPG library structure
01022     try
01023     {
01024         using namespace libJPEG;
01025         jpeg_create_compress(&m_cinfo);
01026     }
01027     catch (...)
01028     {
01029         StringID errorString = m_pErrorHandler->GetStringIDForError();
01030         Error::SetError(errorString);
01031         return FALSE;
01032     }
01033 
01034     // Setup a JPEGDataDestination
01035     if (!InitFileHandler())
01036     {
01037         return FALSE;
01038     }
01039 
01040     // Don't let the CCLexFile report errors or throw exceptions
01041     m_bOldThrowExceptions   = GetExportFile()->SetThrowExceptions(FALSE);
01042     m_bOldReportErrors      = GetExportFile()->SetReportErrors(FALSE);
01043 
01044     // Shouldn't have to do this
01045     PaletteType     = PAL_STANDARD; // don't - HATE this
01046 
01047     SetDepthToRender(24);   // immer but not necessarily what we get
01048 
01049     return TRUE;
01050 }

BOOL JPEGExportFilter::PrepareToExport Spread pSpread,
UINT32  Depth,
double  DPI,
SelectionType  Selection,
UINT32  Dither
[protected, virtual]
 

Reimplemented from BaseBitmapFilter.

Definition at line 1143 of file exjpeg.cpp.

01145 {
01146     if (!BaseBitmapFilter::PrepareToExport(pSpread, Depth, DPI, Selection, Dither))
01147     {
01148         return FALSE;
01149     }
01150 
01151     SetFilterForUpdate(NULL);
01152 
01153     if (!((JPEGExportOptions*)GetBitmapExportOptions())->SetColourModel(libJPEG::JCS_RGB))
01154     {
01155         ERROR2(FALSE,"Can't set colour model");
01156         return FALSE;
01157     }
01158 
01159     if (!InternalPrepareToExport())
01160     {
01161         return FALSE;
01162     }
01163 
01164     return TRUE;
01165 }

BOOL JPEGExportFilter::SetExportHint Document pDoc  )  [protected, virtual]
 

Overrides base class to set correct hint See Also: BaseBitmapFilter::SetExportHint().

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/07/97

Reimplemented from BaseBitmapFilter.

Definition at line 1586 of file exjpeg.cpp.

01587 {
01588     BOOL Ok = TRUE;
01589 
01590     if (pDoc != NULL)
01591     {
01592         ExportHint* pHint = pDoc->GetExportHint();  
01593         ERROR3IF(pHint == NULL, "NULL ExportHint");
01594         
01595         BitmapExportOptions* pBaseOptions = GetBitmapExportOptions();
01596         ERROR3IF(pBaseOptions == NULL, "NULL Options");
01597 
01598         if (pHint != NULL && pBaseOptions != NULL)
01599         {
01600             ERROR2IF(!(IS_A(pBaseOptions, JPEGExportOptions)), FALSE, "Incorrect type of options");
01601             JPEGExportOptions* pOptions = (JPEGExportOptions*) pBaseOptions;
01602             
01603             pHint->SetType(HINTTYPE_JPEG);
01604             pHint->SetWidth(GetPixelWidth());
01605             pHint->SetHeight(GetPixelHeight());
01606             pHint->SetBPP(pOptions->GetDepth());
01607 
01608             String_256 Opts;
01609 
01610             Opts._MakeMsg(_T("Q#1%ld"), pOptions->GetQuality());
01611 
01612             String_32 DPIString;
01613             Ok = Convert::DoubleToString( pOptions->GetDPI(), &DPIString, 3);
01614 
01615             Opts += _T(" D");
01616             Opts += DPIString;
01617             
01618             if (pOptions->DoAsProgressive())
01619             {
01620                 Opts += _T(" P");
01621             }
01622 
01623             pHint->SetOptionsString(Opts);
01624         }
01625     }
01626 
01627     return Ok;
01628 }

BOOL JPEGExportFilter::SetFilterForUpdate Filter *const   pFilterForUpdate  )  [protected]
 

Sets the filter for any progress update on export Notes: Should be set to NULL for ordinary import.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/10/96
Returns:
TRUE if successfully set, FALSE otherwise.

Errors: ERROR3IF invalid arg type

Definition at line 1661 of file exjpeg.cpp.

01662 {
01663     ERROR3IF(pFilterForUpdate != NULL && !pFilterForUpdate->IS_KIND_OF(Filter), 
01664             "pFilterForUpdate isn't");
01665 
01666     m_pFilterForUpdate = pFilterForUpdate;
01667 
01668     return TRUE;
01669 }

void JPEGExportFilter::SetPostOperation BOOL  Value  )  [inline, protected]
 

Definition at line 262 of file exjpeg.h.

00262 { m_PostOperation = Value; }

BOOL JPEGExportFilter::WriteBitmapSource BitmapSource Source,
UINT32  Height,
BaseCamelotFilter pThisFilter,
CCLexFile pCCFile
 

Writes out the given BitmapSource to this file.

Author:
Ranbir_Rana (Xara Group Ltd) <camelotdev@xara.com> (From Colin)
Date:
22/01/97
Parameters:
Source : the BitmapSource to write out [INPUTS] Height : the height of the bitmap in this source pThisFilter : the filter whose IncProgressBarCount we will use for the progress indicator
Returns:
TRUE if written successfully FALSE otherwise

Errors: ERROR2's if Height is zero or pThisFilter NULL See Also: CXaraFile::WriteBitmapSource

Definition at line 820 of file exjpeg.cpp.

00821 {
00822     ERROR2IF(pThisFilter == NULL, FALSE, "pThisFilter == NULL");
00823     ERROR2IF(Height == 0, FALSE, "Height == 0");
00824     
00825     CCBufferFile* pBufferFile = new CCBufferFile(pCCFile);
00826     // Now create a file that can fill it
00827     if (pBufferFile == NULL || !pBufferFile->IsInited())
00828     {
00829         return FALSE;
00830     }
00831     // Provide the filter with something to work with
00832     Source->AttachToBufferFile(pBufferFile);
00833 
00834     // Work out how much to increment the progress bar by on each loop
00835     OFFSET Size = Source->GetSize();
00836     UINT32 Increment = (Height * CCBufferFile::DEFAULT_BUFSIZ) / Size;
00837     if (Increment > Height)
00838     {
00839         Increment = Height;
00840     }
00841     else if (Increment < 1)
00842     {
00843         Increment = 1;
00844     }
00845     UINT32 UpdateEvery = Size / (Height * CCBufferFile::DEFAULT_BUFSIZ);
00846 
00847     // Write out the BitmapSource DEFAULT_BUFSIZ bytes at a time
00848     UINT32 WritesSinceUpdate = 0;
00849     while (!pBufferFile->IsAllWritten())
00850     {
00851         pBufferFile->write(NULL, CCBufferFile::DEFAULT_BUFSIZ);
00852         if (pBufferFile->bad() || pBufferFile->fail())
00853         {
00854             delete pBufferFile;
00855             return FALSE;
00856         }
00857 
00858         // We've made some progress so provide some user feedback
00859         ++WritesSinceUpdate;
00860         if (WritesSinceUpdate >= UpdateEvery)
00861         {
00862             pThisFilter->IncProgressBarCount(Increment);
00863             WritesSinceUpdate = 0;
00864         }
00865     };
00866 
00867     // Destroy our file handle
00868     delete pBufferFile;
00869 
00870     return TRUE;
00871 }

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

Reimplemented from BaseBitmapFilter.

Definition at line 772 of file exjpeg.cpp.

00775 {
00776     ERROR2IF(pKernelBitmap == NULL || pFilter == NULL || pFile == NULL, FALSE, "NULL Args");
00777 
00778     ERROR3IF(!pKernelBitmap->IS_KIND_OF(KernelBitmap), "pKernelBitmap isn't");
00779     ERROR3IF(!pFilter->IS_KIND_OF(BaseCamelotFilter), "pFilter isn't");
00780     ERROR3IF(!pFile->IS_KIND_OF(CCLexFile), "pFile isn't");
00781 
00782     if (!BaseBitmapFilter::WriteBitmapToFile(pKernelBitmap, pFilter, pFile, Compression))
00783     {
00784         return FALSE;
00785     }
00786 
00787     SetFilterForUpdate(pFilter);
00788 
00789     JPEGExportOptions* pOptions = (JPEGExportOptions*)GetBitmapExportOptions();
00790     pOptions->RetrieveDefaults();
00791     pOptions->SetQuality(Compression);
00792 
00793     if (!DoFilter(pKernelBitmap, pFile))
00794     {
00795         return FALSE;
00796     }
00797     return TRUE;
00798 }

BOOL JPEGExportFilter::WriteBitmapToFile KernelBitmap pKernelBitmap,
double  Dpi
[virtual]
 

To duplicate code.

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

Reimplemented from BaseBitmapFilter.

Definition at line 733 of file exjpeg.cpp.

00734 {
00735     ERROR2IF(pKernelBitmap == NULL, FALSE, "NULL Args");
00736     ERROR3IF(!pKernelBitmap->IS_KIND_OF(KernelBitmap), "pKernelBitmap isn't");
00737 
00738     BOOL bSuccess = FALSE;
00739     JPEGExportOptions* pOptions = (JPEGExportOptions*)GetBitmapExportOptions();
00740     pOptions->RetrieveDefaults();
00741     pOptions->SetDPI(Dpi);
00742 
00743     // export the jpeg just as it is (sjk 21/12/00)
00744     pOptions->m_bJPEGPresentAndSelected = TRUE;
00745 
00746     SetFilterForUpdate(NULL);
00747 
00748     // Set up the progress bar
00749     ProgressOffset = 0; // reset this Filter member!!!  so WriteBitmap() does progress correctly
00750 
00751     OILBitmap* pOILBitmap = pKernelBitmap->GetActualBitmap();
00752     String_64 ProgressString = GetExportProgressString(GetExportFile(), GetExportMsgID());
00753     BeginSlowJob(pOILBitmap->GetHeight(), FALSE, &ProgressString);
00754 
00755     bSuccess = DoFilter(pKernelBitmap, GetExportFile());
00756 
00757     EndSlowJob();
00758     return bSuccess;
00759 }

BOOL JPEGExportFilter::WriteFileHeader void   )  [protected, virtual]
 

To write out the file specific header data: actually sets up the JPEG filter.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/10/96
Returns:
FALSE if failed else TRUE
See also:
BaseBitmapFilter::WriteFileHeader()

Reimplemented from BaseBitmapFilter.

Definition at line 1238 of file exjpeg.cpp.

01239 {
01240     BOOL ok = FALSE;
01241 
01242     ok = PrepareForOperation();
01243 
01244     return ok;
01245 }

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

Overrides 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:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/10/96
Returns:
FALSE if failed else TRUE
See also:
BaseBitmapFilter::WriteFrame(void)
8. Aborting.

If you decide to abort a compression cycle before finishing, you can clean up in either of two ways:

If you don't need the JPEG object any more, just call jpeg_destroy_compress() or jpeg_destroy() to release memory. This is legitimate at any point after calling jpeg_create_compress() --- in fact, it's safe even if jpeg_create_compress() fails.

If you want to re-use the JPEG object, call jpeg_abort_compress(), or jpeg_abort() which works on both compression and decompression objects. This will return the object to an idle state, releasing any working memory. jpeg_abort() is allowed at any time after successful object creation.

Note that cleaning up the data destination, if required, is your responsibility.

Reimplemented from BaseBitmapFilter.

Definition at line 1279 of file exjpeg.cpp.

01280 {
01281     BOOL    Ok;
01282 
01283     BMP_SIZE    Width, Height;
01284     BMP_DEPTH   Depth;
01285     ADDR        pBitmapBits;
01286     
01287     Ok = GetCurrentStripInfo(&pBitmapBits, &Width, &Height, &Depth);
01288 
01289     // Create a converter from bitmap depth to export depth
01290     DIBConvert* pConverter = DIBConvert::Create( Depth, GetRenderDepth(), Width, NULL );
01291 
01292     if (Ok)
01293     {
01294         Ok = WriteRawBitmap( pBitmapBits, Width, Height, Depth, pConverter );
01295     }
01296 
01297     return Ok;
01298 }

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

Overrides base class to finish JPEG compression cycle of the current frame.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/10/96
Returns:
FALSE if failed else TRUE
See also:
BaseBitmapFilter

Reimplemented from BaseBitmapFilter.

Definition at line 1432 of file exjpeg.cpp.

01433 {
01434     try
01435     {
01436         libJPEG::jpeg_finish_compress(&m_cinfo);
01437     }
01438     catch (...)
01439     {
01440         StringID errorString = m_pErrorHandler->GetStringIDForError();
01441         Error::SetError(errorString);
01442 
01443         return FALSE;
01444     }
01445 
01446     return TRUE;
01447 }

BOOL JPEGExportFilter::WriteRawBitmap const ADDR pBitmapData,
const BMP_SIZE Width,
const BMP_SIZE Height,
const BMP_DEPTH Bpp,
DIBConvert pConverter
[protected]
 

Support function for writing out the bitmap scanlines Called by WriteFrame() & WriteBitmap().

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/10/96
Parameters:
pBitmapData : The bits, as in "bitmap" [INPUTS] Width: The bitmap width in pixels Height: The bitmap height in pixels Depth: The bitmap depth in bits per pixel pConverter: A pointer to a DIBConvert to convert the actual bitmap given to 32bpp data
Returns:
FALSE if failed else TRUE

Definition at line 1322 of file exjpeg.cpp.

01326 {
01327 //  ERROR2IF(pConverter == NULL && Bpp != (BMP_DEPTH)GetRenderDepth(), FALSE, "Parameters incorrect");
01328 
01329     const UINT32 ScanlineSize = DIBUtil::ScanlineSize( Width, Bpp );
01330     const UINT32 ExportlineSize = DIBUtil::ScanlineSize( Width, 32 );
01331     Filter* const pFilterForUpdate = GetFilterForUpdate();
01332 
01333     ADDR pExportBuffer = NULL;
01334     ADDR pBitmapLine = pBitmapData;
01335     ADDR pExportLine = NULL;
01336 
01337 
01338     if (pConverter != NULL)
01339     {
01340         pExportBuffer = new BYTE[ExportlineSize];
01341         pExportLine = pExportBuffer;
01342     }
01343 
01344     try
01345     {
01346         UINT32 ScanlinesRemaining = Height;
01347         pBitmapLine += (ScanlinesRemaining - 1) * ScanlineSize;
01348 
01349         RGBTRIPLE*  pTempLine = (RGBTRIPLE*)alloca( ExportlineSize );
01350 
01351         // Do it one line at a time like it or not
01352         while (ScanlinesRemaining > 0)
01353         {
01354             // Convert the bitmap to 32bpp if necessary
01355             if (pConverter == NULL)
01356             {
01357                 pExportLine = pBitmapLine;
01358             }
01359             else
01360             {
01361                 pConverter->Convert(pBitmapLine, pExportBuffer, 1, FALSE);
01362             }
01363 
01364 #if !defined(__WXMSW__) && defined(BIG_ENDIAN)
01365             // Component swapping must be done out-of-line, to stop original
01366             // being blatted
01367             RGBTRIPLE* pExportRGB = (RGBTRIPLE*)pExportLine;
01368             if( pExportLine == pBitmapLine )
01369             {
01370                 pExportRGB = pTempLine;
01371                 memcpy( pExportRGB, pExportLine, ExportlineSize );
01372                 pExportLine = PBYTE(pExportRGB);
01373             }
01374             for( unsigned ord = 0; ord < Width; ++ord, ++ pExportRGB )
01375                 std::swap( pExportRGB->rgbtBlue, pExportRGB->rgbtRed );
01376 #endif
01377 
01378             libJPEG::jpeg_write_scanlines(&m_cinfo, &pExportLine, 1);
01379 
01380             if (pFilterForUpdate != NULL)
01381             {
01382                 // Ask the pFilter to update the progress bar for us
01383                 pFilterForUpdate->IncProgressBarCount(1);
01384             }
01385             else
01386             {
01387                 ContinueSlowJob(ProgressOffset + (Height - ScanlinesRemaining));
01388             }
01389 
01390             pBitmapLine -= ScanlineSize;
01391             --ScanlinesRemaining;
01392         }
01393     }
01394     catch (...)
01395     {
01396         if (pExportBuffer != NULL)
01397         {
01398             delete pExportBuffer;
01399         }
01400         StringID errorString = m_pErrorHandler->GetStringIDForError();
01401         Error::SetError(errorString);
01402 
01403         return FALSE;
01404     }
01405 
01406     if (pExportBuffer != NULL)
01407     {
01408         delete pExportBuffer;
01409     }
01410 
01411     if (pFilterForUpdate == NULL)
01412     {
01413         // Add in the height of the strip that we have just exported to the progress offset value
01414         ProgressOffset += Height;
01415     }
01416 
01417     return TRUE;
01418 }


Member Data Documentation

BOOL JPEGExportFilter::m_bOldReportErrors [protected]
 

Definition at line 268 of file exjpeg.h.

BOOL JPEGExportFilter::m_bOldThrowExceptions [protected]
 

Definition at line 269 of file exjpeg.h.

struct libJPEG::jpeg_compress_struct JPEGExportFilter::m_cinfo [protected]
 

Definition at line 275 of file exjpeg.h.

JPEGDataDestination* JPEGExportFilter::m_pDestinationHandler [protected]
 

Definition at line 278 of file exjpeg.h.

JPEGErrorManager* JPEGExportFilter::m_pErrorHandler [protected]
 

Definition at line 277 of file exjpeg.h.

Filter* JPEGExportFilter::m_pFilterForUpdate [protected]
 

Definition at line 272 of file exjpeg.h.

BOOL JPEGExportFilter::m_PostOperation [protected]
 

Definition at line 270 of file exjpeg.h.


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