bmpfiltr.cpp

Go to the documentation of this file.
00001 // $Id: bmpfiltr.cpp 1282 2006-06-09 09:46:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 // A Windows BMP import/export filter (export only currently)
00100 
00101 
00102 #include "camtypes.h"
00103 #include "bmpfiltr.h"
00104 //#include "andy.h"
00105 //#include "oilfltrs.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00106 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00107 //#include "dibutil.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00108 #include "grndbmp.h"
00109 #include "nodebmp.h"
00110 #ifndef WEBSTER
00111 //#include "extfilts.h" // Accusoft filters class
00112 #endif //WEBSTER
00113 #include "oilbitmap.h"  // Platform specific bitmap information
00114 
00115 //#include "fixmem.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00116 
00117 //#include "accuflts.h" // instead of imglib.h for 'BMP_UNCOMPRESSED'
00118 #include "bmapprev.h"   // tab preview dialog
00119 //#include "cxfrec.h"       // for CXaraFileRecord - in camtypes.h [AUTOMATICALLY REMOVED]
00120 #include "exjpeg.h"
00121 
00122 CC_IMPLEMENT_DYNAMIC(BMPFilter, BaseBitmapFilter)
00123 CC_IMPLEMENT_DYNCREATE(BMPExportOptions, BitmapExportOptions)
00124 
00125 #define new CAM_DEBUG_NEW
00126 
00127 static double DefaultExportDPI = 96.0;
00128 static UINT32 DefaultExportDepth = 24;
00129 static UINT32 DefaultExportDither = 4;  // Webster<RanbirR> The default export dither type has been changed to No Dither.
00130 static BOOL DefaultExportCompression = FALSE;
00131 static PALETTE DefaultExportPalette = PAL_OPTIMISED;
00132 
00133 
00134 /********************************************************************************************
00135 >   BMPExportOptions::BMPExportOptions(const FilterType FilterID, const StringBase* pFilterName)
00136 
00137     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00138     Created:    29/10/96
00139     Purpose:    Default constructor
00140 ********************************************************************************************/
00141 
00142 BMPExportOptions::BMPExportOptions()
00143   : m_Dither(XARADITHER_NONE),
00144     m_Palette(DefaultExportPalette),
00145     m_Compression(BMP_RGB)
00146 {
00147     // Empty.
00148 }
00149 
00150 
00151 
00152 /********************************************************************************************
00153 >   BMPExportOptions::BMPExportOptions(const FilterType FilterID, const StringBase* pFilterName)
00154 
00155     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00156     Created:    29/10/96
00157     Purpose:    Constructor for a BMPExportOptions object to provide BMP specific
00158                 options
00159 ********************************************************************************************/
00160 
00161 BMPExportOptions::BMPExportOptions(const FilterType FilterID, const StringBase* pFilterName)
00162   : BitmapExportOptions(_R(IDD_EXPORTBMPOPTS), FilterID, pFilterName),
00163     m_Dither(XARADITHER_NONE),
00164     m_Palette(DefaultExportPalette),
00165     m_Compression(BMP_RGB)
00166 {
00167     // Empty.
00168 }
00169 
00170 
00171 
00172 /********************************************************************************************
00173 
00174 >   virtual BOOL BMPExportOptions::CopyFrom(BitmapExportOptions *pSource) 
00175 
00176     Author:     Stefan_Stoykov (Xara Group Ltd) <camelotdev@xara.com>
00177     Created:    19/05/97
00178     Inputs:     pSource - the other BitmapExportOptions object to copy the data from
00179     Purpose:    Sets the contents of this object from the passed object
00180     See Also:   BitmapExportOptions::MakeCopy()
00181 
00182 ********************************************************************************************/
00183 BOOL BMPExportOptions::CopyFrom(BitmapExportOptions *pSource) 
00184 {
00185     // copy the base class first
00186     if (!BitmapExportOptions::CopyFrom(pSource))
00187         return FALSE;
00188 
00189     // must be the same class, otherwise the base class  function above returns FALSE
00190     BMPExportOptions *pOther = (BMPExportOptions *)pSource;
00191 
00192     m_Dither        = pOther->m_Dither;
00193     m_Palette       = pOther->m_Palette;
00194     m_Compression   = pOther->m_Compression;
00195 
00196     return TRUE;
00197 };
00198 
00199 
00200 BOOL BMPExportOptions::FileTypeChangeCopyFrom(BitmapExportOptions *pSource)
00201 {
00202     ASSERT(FALSE);
00203     /*
00204     // copy the base class first
00205     if (!BitmapExportOptions::FileTypeChangeCopyFrom(pSource))
00206         return FALSE;
00207 
00208     BMPExportOptions* pOther = (BMPExportOptions*)pSource;
00209 
00210     //  Coming from a jpeg image
00211     if( pOther->IS_KIND_OF(JPEGExportOptions) )
00212     {
00213         m_Dither    = XARADITHER_NONE;
00214         m_Palette   = DefaultExportPalette;
00215     }
00216     else
00217     {
00218         //  Coming from a gif or png image.
00219         m_Dither    = pOther->m_Dither;
00220         m_Palette   = pOther->m_Palette;
00221     }
00222 
00223     m_Compression   = BMP_RGB;
00224 
00225     // Ensure that the bitmap depth is less than 32 bpp.
00226     if( GetDepth() == 32 )
00227     {
00228         SetDepth( 24 );
00229     }
00230 */
00231     return TRUE;
00232 }
00233 
00234 
00235 /********************************************************************************************
00236 
00237 >   virtual BOOL BMPExportOptions::Equal(BitmapExportOptions *pSource) 
00238 
00239     Author:     Stefan_Stoykov (Xara Group Ltd) <camelotdev@xara.com>
00240     Created:    19/05/97
00241     Inputs:     pSource - the other BitmapExportOptions object to copy the data from
00242     Purpose:    Compares the contents of this and pOther objects
00243     Returns:    TRUE, if objects are equal, FALSE otherwise
00244     See Also:   BitmapExportOptions::MakeCopy()
00245 
00246 ********************************************************************************************/
00247 /*
00248 BOOL BMPExportOptions::Equal(BitmapExportOptions *pSource) 
00249 {
00250     BOOL ok = TRUE;
00251 
00252     // compare the base classes first
00253     ok = BitmapExportOptions::Equal(pSource);
00254 
00255     // must be the same class, otherwise the base class  function above returns FALSE
00256     BMPExportOptions *pOther = (BMPExportOptions *)pSource;
00257 
00258     if (ok) ok = (m_Dither  == pOther->m_Dither);
00259     if (ok) ok = (m_Palette == pOther->m_Palette);
00260     if (ok) ok = (m_Compression == pOther->m_Compression);
00261     return ok;
00262 };
00263 */
00264 
00265 /********************************************************************************************
00266 
00267 >   virtual BOOL BMPExportOptions::RetrieveDefaults()
00268 
00269     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00270     Created:    29/10/96
00271     Purpose:    Gets GIF specific preferences
00272     Notes:      See BitmapExportOptions for interface details
00273 
00274 ********************************************************************************************/
00275 BOOL BMPExportOptions::RetrieveDefaults()
00276 {
00277     if (!BitmapExportOptions::RetrieveDefaults())
00278     {
00279         return FALSE;
00280     }
00281 
00282     SetDither((DITHER)BMPFilter::GetDefaultExportDither());
00283     SetPalette(DefaultExportPalette);
00284 
00285     BOOL Compression = DefaultExportCompression;
00286     ERROR2IF(Compression > 1, FALSE, "Invalid Compression");
00287     SetCompression((BMP_COMPRESSION)Compression);
00288 
00289     return TRUE;
00290 }
00291 
00292 
00293 /********************************************************************************************
00294 
00295 >   virtual BOOL BMPExportOptions::SetAsDefaults() const
00296 
00297     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00298     Created:    29/10/96
00299     Purpose:    Provides additional implementation to set GIF specific info as defaults
00300     See Also:   BitmapExportInfo::SetAsDefaults()
00301 
00302 ********************************************************************************************/
00303 BOOL BMPExportOptions::SetAsDefaults() const
00304 {
00305     if (!BitmapExportOptions::SetAsDefaults())
00306     {
00307         return FALSE;
00308     }
00309 
00310     BMPFilter::SetDefaultExportDither(GetDither());
00311     DefaultExportCompression    = (BOOL)GetCompression();
00312     DefaultExportPalette        = GetPalette();
00313 
00314     return TRUE;
00315 }
00316 
00317 
00318 
00319 /********************************************************************************************
00320 >   virtual BOOL BMPExportOptions::Write(CXaraFileRecord* pRec)
00321 
00322     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00323     Created:    21/2/00
00324     Inputs:     pRec    ---     record to write
00325     Returns:    TRUE if successful.
00326     Purpose:    Writes this object to the given record.
00327     SeeAlso:    BMPExportOptions::Read
00328 ********************************************************************************************/
00329 
00330 BOOL BMPExportOptions::Write(CXaraFileRecord* pRec)
00331 {
00332     return BitmapExportOptions::Write(pRec) &&
00333            pRec->WriteINT16((INT16) m_Dither) &&
00334            pRec->WriteINT16((INT16) m_Palette) &&
00335            pRec->WriteINT16((INT16) m_Compression);
00336 }
00337 
00338 
00339 
00340 /********************************************************************************************
00341 >   virtual BOOL BMPExportOptions::Read(CXaraFileRecord* pRec)
00342 
00343     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00344     Created:    21/2/00
00345     Inputs:     pRec    ---     record to read
00346     Returns:    TRUE if successful.
00347     Purpose:    Reads this object from the given record.
00348     SeeAlso:    BMPExportOptions::Write
00349 ********************************************************************************************/
00350 
00351 BOOL BMPExportOptions::Read(CXaraFileRecord* pRec)
00352 {
00353     return BitmapExportOptions::Read(pRec) &&
00354            pRec->ReadINT16((INT16*) &m_Dither) &&
00355            pRec->ReadINT16((INT16*) &m_Palette) &&
00356            pRec->ReadINT16((INT16*) &m_Compression);
00357 }
00358 
00359 
00360 
00361 /********************************************************************************************
00362 
00363 >   DITHER BMPExportOptions::GetDither() const
00364 
00365     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00366     Created:    29/10/96
00367     Returns:    The dither desired for the bitmap to export
00368     Purpose:    Support function to obtain export options
00369 
00370 ********************************************************************************************/
00371 DITHER BMPExportOptions::GetDither() const
00372 {
00373     return m_Dither;
00374 }
00375 
00376 
00377 /********************************************************************************************
00378 
00379 >   BOOL BMPExportOptions::SetDither(const DITHER& Dither)
00380 
00381     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00382     Created:    29/10/96
00383     Inputs:     Dither : The desired dither to be applied to the bitmap before being exported
00384     Returns:    TRUE if set successfully
00385                 FALSE otherwise
00386     Purpose:    Support function to set up information for the ensuing export
00387     See Also:   GetDither()
00388 
00389 ********************************************************************************************/
00390 BOOL BMPExportOptions::SetDither(const DITHER& Dither)
00391 {
00392     if (m_Dither != Dither)
00393         SetTempFileMatchesExportOptions(FALSE);
00394     m_Dither = Dither;
00395     return TRUE;
00396 }
00397 
00398 
00399 /********************************************************************************************
00400 
00401 >   PALETTE BMPExportOptions::GetPalette() const
00402 
00403     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00404     Created:    29/10/96
00405     Returns:    The palette desired to be exported with the bitmap
00406     Purpose:    Support function to obtain export options
00407 
00408 ********************************************************************************************/
00409 PALETTE BMPExportOptions::GetPalette() const
00410 {
00411     return m_Palette;
00412 }
00413 
00414 
00415 /********************************************************************************************
00416 
00417 >   BOOL BMPExportOptions::SetPalette(const PALETTE& Palette)
00418 
00419     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00420     Created:    29/10/96
00421     Inputs:     Dither : The desired dither to be applied to the bitmap before being exported
00422     Returns:    TRUE if set successfully
00423                 FALSE otherwise
00424     Purpose:    Support function to set up information for the ensuing export
00425     See Also:   GetPalette()
00426 
00427 ********************************************************************************************/
00428 BOOL BMPExportOptions::SetPalette(const PALETTE& Palette)
00429 {
00430     m_Palette = Palette;
00431     return TRUE;
00432 }
00433 
00434 
00435 
00436 /********************************************************************************************
00437 
00438 >   BMP_COMPRESSION BMPExportOptions::GetCompression() const
00439 
00440     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00441     Created:    29/10/96
00442     Returns:    The compression desired for BMP bitmap export
00443     Purpose:    Support function to obtain export options
00444 
00445 ********************************************************************************************/
00446 BMP_COMPRESSION BMPExportOptions::GetCompression() const
00447 {
00448     return m_Compression;
00449 }
00450 
00451 
00452 /********************************************************************************************
00453 
00454 >   BOOL BMPExportOptions::SetCompression(const BMP_COMPRESSION& Compression)
00455 
00456     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00457     Created:    29/10/96
00458     Inputs:     Compression : The compression to be used for the export
00459     Returns:    TRUE if set successfully
00460                 FALSE otherwise
00461     Purpose:    Support function to set up information for the ensuing export
00462     See Also:   GetCompression()
00463 
00464 ********************************************************************************************/
00465 BOOL BMPExportOptions::SetCompression(const BMP_COMPRESSION& Compression)
00466 {
00467     ERROR2IF(Compression != BMP_RLE && Compression != BMP_RGB, FALSE, "Invalid Compression");
00468 
00469     m_Compression = Compression;
00470 
00471     return TRUE;
00472 }
00473 
00474 
00475 
00476 #ifdef DO_EXPORT
00477 OutputDIB   BMPFilter::DestDIB;
00478 #endif
00479 
00480 
00481 /********************************************************************************************
00482 
00483     Preference:     DefaultExportDPI
00484     Section:        Filters
00485     Range:          1 to 3000
00486     Purpose:        Allows a default export dots per inch size to be remembered when
00487                     exporting either as a BMP or via the Accusoft loaders.
00488     SeeAlso:        -
00489 
00490 ********************************************************************************************/
00491 
00492 /********************************************************************************************
00493 
00494     Preference:     DefaultExportDepth
00495     Section:        Filters
00496     Range:          1 to 32
00497     Purpose:        Allows a default export bits per pixel amount to be remembered when 
00498                     exporting either as a BMP or via the Accusoft loaders.
00499     SeeAlso:        -
00500 
00501 ********************************************************************************************/
00502 
00503 /********************************************************************************************
00504 
00505 >   UINT32 BMPFilter::GetDefaultExportDepth()
00506 
00507     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00508     Created:    17/11/94
00509     Inputs:     None
00510     Outputs:    None
00511     Returns:    The value currently set for the DefaultExportDepth
00512     Purpose:    Allows other bitmap export filters to get at this value. Needs to be here
00513                 rather than in BaseBitmapFilter as that Init is never used.
00514     SeeAlso:    BMPFilter::Init; BMPFilter::GetDefaultExportDpi; BMPFilter::SetDefaultExportDepth; 
00515 
00516 ********************************************************************************************/
00517 
00518 UINT32 BMPFilter::GetDefaultExportDepth()
00519 {
00520     return DefaultExportDepth;
00521 }
00522 
00523 /********************************************************************************************
00524 
00525 >   double BMPFilter::GetDefaultExportDPI()
00526 
00527     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00528     Created:    17/11/94
00529     Inputs:     None
00530     Outputs:    None
00531     Returns:    The value currently set for the DefaultExportDpi
00532     Purpose:    Allows other bitmap export filters to get at this value. Needs to be here
00533                 rather than in BaseBitmapFilter as that Init is never used.
00534     SeeAlso:    BMPFilter::Init; BMPFilter::GetDefaultExportDepth; BMPFilter::SetDefaultExportDPI; 
00535 
00536 ********************************************************************************************/
00537 
00538 double BMPFilter::GetDefaultExportDPI()
00539 {
00540     return DefaultExportDPI;
00541 }
00542 
00543 /********************************************************************************************
00544 
00545 >   void BMPFilter::SetDefaultExportDepth( UINT32 Depth)
00546 
00547     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00548     Created:    17/11/94
00549     Inputs:     The new value to set for the DefaultExportDepth
00550     Outputs:    None
00551     Returns:    None  
00552     Purpose:    Allows other bitmap export filters to set this value. Needs to be here
00553                 rather than in BaseBitmapFilter as that Init is never used.
00554     SeeAlso:    BMPFilter::Init; BMPFilter::GetDefaultExportDepth; BMPFilter::GetDefaultExportDPI; 
00555 
00556 ********************************************************************************************/
00557 
00558 void BMPFilter::SetDefaultExportDepth( UINT32 Depth)
00559 {
00560     DefaultExportDepth = Depth;
00561 }
00562 
00563 /********************************************************************************************
00564 
00565 >   void BMPFilter::SetDefaultExportDPI( double DPI)
00566 
00567     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00568     Created:    17/11/94
00569     Inputs:     The new value to set for the DefaultExportDpi
00570     Outputs:    None
00571     Returns:    None  
00572     Purpose:    Allows other bitmap export filters to set this value. Needs to be here
00573                 rather than in BaseBitmapFilter as that Init is never used.
00574     SeeAlso:    BMPFilter::Init; BMPFilter::GetDefaultExportDepth; BMPFilter::GetDefaultExportDPI; 
00575 
00576 ********************************************************************************************/
00577 
00578 void BMPFilter::SetDefaultExportDPI( double DPI)
00579 {
00580     DefaultExportDPI = DPI;
00581 }
00582 
00583 UINT32 BMPFilter::GetDefaultExportDither()
00584 {
00585     return DefaultExportDither;
00586 }
00587 
00588 void BMPFilter::SetDefaultExportDither( UINT32 Dither )
00589 {
00590     DefaultExportDither = Dither;
00591 }
00592 
00593 /********************************************************************************************
00594 
00595 >   BMPFilter::BMPFilter()
00596 
00597     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00598     Created:    28/6/94
00599     Purpose:    Constructor for an BMPFilter object.  The object should be initialised
00600                 before use.
00601     SeeAlso:    BMPFilter::Init
00602 
00603 ********************************************************************************************/
00604 
00605 BMPFilter::BMPFilter() : BaseBitmapFilter()
00606 {
00607     ImportMsgID = _R(IDT_IMPORTMSG_BMP);
00608 
00609 #ifndef STANDALONE
00610     Flags.CanImport = TRUE;
00611     Flags.CanExport = TRUE;
00612 #else
00613     Flags.CanImport = TRUE;
00614     Flags.CanExport = FALSE;
00615 #endif
00616 
00617     FilterID = FILTERID_BMP;
00618 
00619     ExportRegion = NULL;
00620     ExportMsgID = _R(IDT_EXPORTMSG_BMP);
00621 
00622     ExportingMsgID = _R(IDT_EXPORTMSG_BMP);
00623 }
00624 
00625 /********************************************************************************************
00626 
00627 >   BOOL BMPFilter::Init()
00628 
00629     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00630     Created:    28/6/94
00631     Returns:    TRUE if the filter was initialised ok, FALSE otherwise.
00632     Purpose:    Initialise an BMPFilter object.
00633     Errors:     Will fail if not enough memory to initialise.
00634     SeeAlso:    EPSStack
00635 
00636 ********************************************************************************************/
00637 
00638 BOOL BMPFilter::Init()
00639 {
00640     // Get the OILFilter object
00641     pOILFilter = new BMPOILFilter(this);
00642     if (pOILFilter==NULL)
00643         return FALSE;
00644 
00645     // Load the description strings
00646     FilterName.Load(_R(IDT_BMP_FILTERNAME));
00647     FilterInfo.Load(_R(IDT_BMP_FILTERINFO));
00648 
00649     if (Camelot.DeclareSection(_T("Filters"), 10))
00650     {
00651 //      Requested that we don't store DPI for export (see bug 6757)
00652 //      Camelot.DeclarePref( NULL, "ExportBitmapDPI", &DefaultExportDPI, 1.0, 3000.0 );
00653         Camelot.DeclarePref( NULL, _T("ExportBitmapDepth"), &DefaultExportDepth, 1, 32 );
00654     }
00655 
00656     // All ok
00657     return TRUE;
00658 }
00659 
00660 /********************************************************************************************
00661 
00662 >   BOOL BMPFilter::ReadFromFile( OILBitmap* pOilBitmap, BaseCamelotFilter* pFilter,
00663                               CCLexFile* pFile, BOOL IsCompressed)
00664 
00665     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00666     Created:    20/6/96
00667     Inputs:     pOilBitmap  pointer to the oil bitmap data to be filled in
00668                 pFilter         - the BaseCamelotFilter which provides functions like progress update
00669                 pFile           - the file to read the data from
00670                 IsCompressed    - Flag to say the bitmap is compressed or not.  
00671     Outputs:    Will have filled in BMInfo  pointer to the bitmap header to fill in
00672                                     BMBytes pointer to the bitmap data to fill in
00673     Purpose:    Actually does the process of reading a bitmap from a file.
00674                 Inherited classes override this to read in different file formats.
00675                 It is used by the web/native filters to pull out a bitmap definition from
00676                 inside a bitmap definition record.
00677                 IsCompressed is only used for BMP/BMPZIP type bitmaps at present.
00678                 Assumes:
00679                     pFile has already been opened up for reading
00680                     pFilter has been set up for reading the data e.g. progress bar 
00681     Returns:    TRUE if worked, FALSE if failed.
00682 
00683 ********************************************************************************************/
00684 
00685 BOOL BMPFilter::ReadFromFile( OILBitmap* pOilBitmap, BaseCamelotFilter* pFilter,
00686                               CCLexFile* pFile, BOOL IsCompressed)
00687 {
00688     ERROR2IF(pOilBitmap == NULL,FALSE,"BMPFilter::ReadFromFile null OilBitmap pointer");
00689     ERROR2IF(pFilter == NULL,FALSE,"BMPFilter::ReadFromFile null pFilter pointer");
00690     ERROR2IF(pFile == NULL,FALSE,"BMPFilter::ReadFromFile null pFile pointer");
00691 
00692     // Try to import bitmap as usual binary BMP file.
00693     CWxBitmap* pWBitmap = (CWxBitmap*)pOilBitmap;
00694     
00695     LPBITMAPINFO *pInfo = &(pWBitmap->BMInfo);
00696     LPBYTE *pBytes = &(pWBitmap->BMBytes);
00697 
00698     if (IsCompressed)
00699     {
00700         // We want compression on so turn it on
00701         if (!pFile->SetCompression(TRUE))
00702             return FALSE;
00703     }
00704 
00705     // Read from file, no header and using pFilter for progress bar updates
00706     if (!DIBUtil::ReadFromFile(pFile, pInfo, pBytes, FALSE, NULL, pFilter))
00707         return FALSE;
00708 
00709     if (IsCompressed)
00710     {
00711         // We have finished with compression, so turn it off
00712         if (!pFile->SetCompression(FALSE))
00713             return FALSE;
00714     }
00715 
00716     // Everything went ok and we imported the bitmap ok
00717     return TRUE;
00718 }
00719 
00720 /********************************************************************************************
00721 
00722 >   BOOL BMPFilter::ReadFromFile( OILBitmap* pOilBitmap )
00723 
00724     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00725     Created:    18/8/95
00726     Inputs:     pOilBitmap  pointer to the oil bitmap data to be filled in
00727     Outputs:    Will have filled in BMInfo  pointer to the bitmap header to fill in
00728                                     BMBytes pointer to the bitmap data to fill in
00729     Purpose:    Actually does the process of reading a bitmap from a file.
00730                 Inherited classes override this to read in different file formats.
00731                 
00732     Returns:    TRUE if worked, FALSE if failed.
00733 
00734 ********************************************************************************************/
00735 
00736 BOOL BMPFilter::ReadFromFile( OILBitmap* pOilBitmap )
00737 {
00738     ERROR2IF(pOilBitmap == NULL,FALSE,"BMPFilter::ReadFromFile null OilBitmap pointer");
00739 
00740     // Try to import bitmap as usual binary BMP file.
00741     // The only problem is that if the user has chosen to use the BMP filter explicitly
00742     // then this may not be what they really want. The BMP filter may not cope with all
00743     // BMP types, whereas we may possibly have an AccusoftFilter which might cope better.
00744     // If the user has not chosen explicitly then the BMP will be directed towards the 
00745     // correct filter by the HowCompatible call.
00746     // Generally, if the filter has been chosen at this point then HowCompatible will have
00747     // been called and so we can ask the BMP filter what it found when asked this and use
00748     // this result to determine whether to load the file or not. 
00749 
00750     UINT32 ImportMsgId = GetImportMsgID();      
00751     String_64 ProgressString(ImportMsgId);
00752 
00753     CCLexFile *pImportFile = GetImportFile();
00754     ERROR2IF(pImportFile==NULL,FALSE,"BMPFilter::ReadFromFile - No import file");
00755 
00756     ProgressString = GetImportProgressString(pImportFile, ImportMsgId);
00757 
00758     CWxBitmap* pWBitmap = (CWxBitmap*)pOilBitmap;
00759     
00760     LPBITMAPINFO *pInfo = &(pWBitmap->BMInfo);
00761     LPBYTE *pBytes = &(pWBitmap->BMBytes);
00762 
00763 PORTNOTE("ExtFilt", "Removed use of external filters")
00764 #if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX)
00765 #ifndef WEBSTER
00766     if (
00767         (GetBmpCompatibility() == 10) || (AccusoftFilters::GetVersionNumber() == 0)
00768        )
00769     {       
00770         // The BMP filter liked it very much and so use it, showing progress bar
00771         if (!DIBUtil::ReadFromFile(pImportFile, pInfo, pBytes, TRUE, &ProgressString))
00772             return FALSE;
00773     }
00774     else
00775     {
00776         // The BMP filter was not totally sure about that file and so we should try and 
00777         // see if the Accusoft loader is present and if so give this an attempt at
00778         // loading that file.       
00779         // Get a cast version of a pointer to the filter
00780 PORTNOTE("ExtFilt", "Removed use of external filters")
00781 #ifndef EXCLUDE_FROM_XARALX
00782         if (!AccusoftFilters::ReadFromFile(pImportFile, pInfo, pBytes, TRUE, &ProgressString))
00783             return FALSE;
00784 #endif
00785     }
00786 #else //WEBSTER
00787     //WEBSTER-Martin-07/01/97 all we can do is try to read it
00788     if (!DIBUtil::ReadFromFile(pImportFile, pInfo, pBytes, TRUE, &ProgressString))
00789         return FALSE;
00790 #endif //WEBSTER
00791 #else //EXCLUDE_FROM_RALPH
00792     if (!DIBUtil::ReadFromFile(pImportFile, pInfo, pBytes, TRUE, &ProgressString))
00793         return FALSE;
00794 #endif //EXCLUDE_FROM_RALPH
00795     
00796     // Everything went ok and we imported the bitmap ok
00797     SetLastBitmap();        // can only import one bitmap at the moment
00798     return TRUE;
00799 }
00800 
00801 /********************************************************************************************
00802 
00803 >   BOOL BMPFilter::GetExportOptions(BitmapExportOptions* pOptions)
00804 
00805     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00806     Created:    29/10/96
00807     Purpose:    See BaseBitmapClass for interface details
00808     Notes:      Initializes BMP specific members
00809     Scope:      Protected
00810 
00811 ********************************************************************************************/
00812 BOOL BMPFilter::GetExportOptions(BitmapExportOptions* pOptions)
00813 {
00814 #ifdef DO_EXPORT
00815     ERROR2IF(pOptions == NULL, FALSE, "NULL Args");
00816 
00817     BMPExportOptions* pBMPOptions = (BMPExportOptions*)pOptions;
00818     ERROR3IF(!pBMPOptions->IS_KIND_OF(BMPExportOptions), "pBMPOptions isn't");
00819 
00820     WrittenHeader = FALSE;
00821 
00822     // Set up the variables which the export dialog box uses
00823     UINT32 BitmapDepth = 0;
00824     if (pBMPOptions->GetSelectionType() == ABITMAP)
00825     {
00826         // Exporting the bitmap itself
00827         // dpi should be set to the dpi of the bitmap itself
00828         BitmapDepth = pBMPOptions->GetDepth();
00829     }
00830 
00831     // Determine the filter type currently in use in Accusoft format
00832 //  INT32 FilterID = BMP_UNCOMPRESSED;
00833 
00834     // Sets the Accusoft filter type to the same specified value just in case
00835     // we wish to use the Accusoft DLL to do some of the BMP saving for us 
00836     //WEBSTER-Martin-07/01/97
00837 #ifndef WEBSTER
00838 PORTNOTE("ExtFilt", "Removed use of external filters")
00839 #ifndef EXCLUDE_FROM_XARALX
00840     AccusoftFilters::SetFilterType(BMP_UNCOMPRESSED);
00841 #endif
00842 #endif
00843 
00844     // When saving a bitmap directly then only use the dialog box for 8 and 4 bpp export
00845     // as these are the only forms that can request a compression type.
00846     // Otherwise, always use it.
00847     BOOL Ok = TRUE;
00848     if ( pBMPOptions->GetSelectionType() != ABITMAP )
00849     {
00850         // This is ok as we are using a modal dialog box
00851 
00852         OpDescriptor* pOpDes = OpDescriptor::FindOpDescriptor(OPTOKEN_GIFTABDLG);
00853         if (pOpDes != NULL)
00854         {
00855             // set up the data for the export options dialog
00856             OpParam Param((void *)pOptions, (void *)this);
00857 
00858             // invoke the dialog
00859             pOpDes->Invoke(&Param);
00860 
00861             // SMFIX
00862             // we have brought the dlg up so get the options from the dlg as the graphic type may have changed
00863 PORTNOTE("BmpPrevDlg", "Removed use of bitmap preview dialog")
00864 #ifndef EXCLUDE_FROM_XARALX
00865             pOptions = BmapPrevDlg::m_pExportOptions;
00866 
00867             // check for valid options
00868             //Ok = pOptions->IsValid();
00869 
00870             // This line decides if we will create a file on disk for the bmp or not
00871             Ok = BmapPrevDlg::m_bClickedOnExport;
00872 #else
00873             pOptions = NULL;
00874             Ok = FALSE;
00875 #endif
00876         }
00877         else
00878         {   
00879             ERROR3("Unable to find OPTOKEN_BMAPPREVDLG");
00880             Ok = FALSE;
00881         } 
00882     }
00883     
00884     // Return with the ok/cancel state used on the dialog box
00885     return Ok;
00886 
00887 #else
00888     return FALSE;
00889 #endif
00890 }
00891 
00892 
00893 // SMFIX sjk 5/12/00 there used to be some junk in the call to GetExportOptions that assumed the
00894 // filter type being used which could be changed by the GetExportOptions call itself
00895 // therefore all this sort of stuff should be called on the correct known filter using this
00896 // call afterwards
00897 void BMPFilter::PostGetExportOptions(BitmapExportOptions* pOptions)
00898 {
00899     // should be of this type
00900     BMPExportOptions* pBMPOptions = (BMPExportOptions*)pOptions;
00901     ERROR3IF(!pBMPOptions->IS_KIND_OF(BMPExportOptions), "pBMPOptions isn't");
00902 
00903     // do the baseclass first
00904     BaseBitmapFilter::PostGetExportOptions(pOptions);
00905 
00906     // do the filter specific stuff
00907     SetDepthToRender(pBMPOptions->GetDepth());
00908     PaletteType = pBMPOptions->GetPalette() ? 1 : 0;    // 1 for an optimised palette
00909     // Make sure that the Accusoft form of the stored dither is correctly set
00910     // as we may be calling this to do the exporting for us!
00911     //WEBSTER-Martin-07/01/97
00912 #ifndef WEBSTER
00913 PORTNOTE("ExtFilt", "Removed use of external filters")
00914 #ifndef EXCLUDE_FROM_XARALX
00915     AccusoftFilters::SetDitherToUse(pBMPOptions->GetDither());
00916 //Mark Howitt, 24/10/97. Reset the FilterType as import uses FilterType as something else!
00917     AccusoftFilters::SetFilterType(pBMPOptions->GetFilterType());
00918 #endif
00919 #endif
00920 }
00921 
00922 
00923 /********************************************************************************************
00924 
00925 >   BOOL BMPFilter::ExportViaAccusoftFilters()
00926 
00927     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00928     Created:    17/5/95
00929     Inputs:     -
00930     Outputs:    -
00931     Returns:    TRUE if going to use the Accusoft filter, FALSE if not
00932     Purpose:    Function to see if we should export via Accusoft filters or not as we cannot
00933                 cope with this format.
00934 
00935 ********************************************************************************************/
00936 
00937 BOOL BMPFilter::ExportViaAccusoftFilters()
00938 {
00939 #ifdef DO_EXPORT
00940     // Check if Accusoft filters are present
00941     // 8 and 4 as we cannot export as RLE in these formats
00942 #ifndef WEBSTER
00943 PORTNOTE("ExtFilt", "Removed use of external filters")
00944 #ifndef EXCLUDE_FROM_XARALX
00945     return  (DefaultExportDepth==8 || DefaultExportDepth==4 || DefaultExportDepth==1) &&
00946             (AccusoftFilters::GetVersionNumber() > 0);
00947 #else
00948     return FALSE;
00949 #endif
00950 #else
00951     //WEBSTER-Martin-07/01/97
00952     return  FALSE;
00953 #endif //WEBSTER
00954 #else
00955     return FALSE;
00956 #endif
00957 }   
00958 
00959 /********************************************************************************************
00960 
00961 >   virtual BOOL BMPFilter::GetRenderBottomToTop()
00962 
00963     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00964     Created:    17/5/95
00965     Inputs:     -
00966     Outputs:    -
00967     Returns:    TRUE if going to use the default of rendering bottom to top, FALSE otherwise
00968     Purpose:    Find out which way we need to render
00969 
00970 ********************************************************************************************/
00971 
00972 BOOL BMPFilter::GetRenderBottomToTop()
00973 {
00974     // We may be exporting via the Accusoft filters but when rendering BMPs they are
00975     // the correct way round already.
00976     return TRUE;
00977 }
00978 
00979 /********************************************************************************************
00980 
00981 >   virtual BOOL BMPFilter::WriteToFile( BOOL End )
00982 
00983     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00984     Created:    28/6/94
00985     Inputs:     End is TRUE if this is the last block of the file.
00986     Returns:    TRUE if worked, FALSE if errored.
00987     Purpose:    Physically put the bitmap into the disk.
00988                 NOTE - ONLY COPES WITH End=TRUE currently
00989                 Most of the work now is down by WriteDataToFile as this is a static form
00990                 and there is a similar version in the Accusoft DLL. This can therefore be
00991                 used to pass work onto the Accusoft DLL, for the cases we don't cope with. 
00992                 End is ignored now and should always be set to TRUE.
00993     SeeAlso:    WriteDataToFile(); AccusoftFilters::WriteToFile; AccusoftFilters::WriteDataToFile;
00994 
00995 ********************************************************************************************/
00996 
00997 BOOL BMPFilter::WriteToFile( BOOL End )
00998 {
00999 #ifdef DO_EXPORT
01000     // Functionality transferred to new static function so that we can share
01001     // the work between this built in BMP filter and the external Accusoft DLL.
01002     // if we are at the low depths of the bpp range then use the Accusoft DLL as on
01003     // 8 and 4 bpp the user may have chosen RLE compression and this filter cannot
01004     // cope with that.
01005     // Of course, only use the Accusoft DLL if it is present.
01006     if ( ExportViaAccusoftFilters() )
01007 #ifndef WEBSTER
01008     {
01009 PORTNOTE("ExtFilt", "Removed use of external filters")
01010 #ifndef EXCLUDE_FROM_XARALX
01011         // Graeme (26-1-00) - I've added a call to the static SetFilterType method in the
01012         // AccusoftFilters class to set up the bitmap type to be an uncompressed bitmap.
01013         // This line isn't strictly necessary - the filter contains code to catch an unset
01014         // FilterType value, and set it to BMP_UNCOMPRESSED, but there potentially could be
01015         // problems if a JPEG or GIF value is passed in. Besides, it stops Camelot from
01016         // throwing an error message in debug builds, which adds just a little polish.
01017         AccusoftFilters::SetFilterType ( BMP_UNCOMPRESSED );
01018 
01019         return AccusoftFilters::WriteDataToFile ( End, DefaultExportDepth,
01020                                                   DefaultExportCompression,
01021                                                   GetBitmapExportOptions());
01022 #else
01023         return FALSE;
01024 #endif
01025     }
01026 #else
01027         //WEBSTER-Martin-07/01/97
01028         return FALSE;
01029 #endif
01030     else    
01031         return WriteDataToFile(End, DefaultExportDepth, DefaultExportCompression);
01032 #else
01033     return FALSE;
01034 #endif
01035 }
01036 
01037 /********************************************************************************************
01038 
01039 >   virtual BOOL BMPFilter::EndWriteToFile( )
01040 
01041     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01042     Created:    12/5/95
01043     Inputs:     -
01044     Purpose:    Cleans up after writing the bitmap data out to a file. Inherited classes
01045                 override this to write in different file formats.
01046     Returns:    TRUE if worked, FALSE if failed.
01047     SeeAlso:    WriteToFile
01048 
01049 ********************************************************************************************/
01050 
01051 BOOL BMPFilter::EndWriteToFile( )
01052 {
01053 #ifdef DO_EXPORT
01054     // Must use the same check here and trasnfer the clean up process to the same filter
01055     // that we used to actually write the data to the file
01056     if  ( ExportViaAccusoftFilters() )
01057 #ifndef WEBSTER
01058 PORTNOTE("ExtFilt", "Removed use of external filters")
01059 #ifndef EXCLUDE_FROM_XARALX
01060         return AccusoftFilters::EndWriteDataToFile();
01061 #else
01062         return FALSE;
01063 #endif
01064 #else
01065         //WEBSTER-Martin-07/01/97
01066         return FALSE;
01067 #endif //WEBSTER
01068     else    
01069         return EndWriteDataToFile();
01070 #else
01071     return FALSE;
01072 #endif
01073 }
01074 
01075 
01076 /********************************************************************************************
01077 
01078 >   BOOL BMPFilter::WriteDataToFile( BOOL End, UINT32 Bpp, UINT32 Compression)
01079 
01080     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01081     Created:    16/3/95
01082     Inputs:     End - TRUE if this is the last block of the file.
01083                 Bpp - output depth in terms of bits per pixel
01084                 Compression - True if compression required, False otherwise
01085     Returns:    TRUE if worked, FALSE if errored.
01086     Purpose:    Physically put the bitmap into the disk.
01087                 NOTE - ONLY COPES WITH End=TRUE currently
01088                 End is ignored now and should always be set to TRUE.
01089     SeeAlso:    WriteToFile(); AccusoftFilters::WriteToFile; AccusoftFilters::WriteDataToFile;
01090 
01091 ********************************************************************************************/
01092 
01093 BOOL BMPFilter::WriteDataToFile( BOOL End, UINT32 Bpp, UINT32 Compression)
01094 {
01095 #ifdef DO_EXPORT
01096     if (GeneratingOptimisedPalette())
01097         return TRUE;        // No need to output anything
01098 
01099 
01100     BMPExportOptions* pBMPOptions = (BMPExportOptions*)GetBitmapExportOptions();
01101     ERROR2IF(pBMPOptions == NULL, FALSE, "NULL Args");
01102     ERROR3IF(!pBMPOptions->IS_KIND_OF(BMPExportOptions), "pBMPOptions isn't");
01103 
01104     LPBITMAPINFO lpBitmapInfo;
01105     LPBYTE lpBits;
01106 
01107     // Get the bitmap data from the Render Region
01108     ExportRegion->GetBitmapData(&lpBitmapInfo, &lpBits);
01109 
01110     ERROR3IF(lpBitmapInfo == NULL, "Bitmap has no info in BMPFilter::WriteDataToFile");
01111     if (lpBitmapInfo == NULL)
01112         return FALSE;
01113 
01114     ERROR3IF(lpBits == NULL, "Bitmap has no data in BMPFilter::WriteDataToFile");
01115     if (lpBits == NULL)
01116         return FALSE;
01117 
01118     // First time through, lets write out a suitable header.
01119     // As we write it in one big chunk (currently), its easy
01120     // If we are rendering in strips then the bitmap information in the render region will
01121     // be set for the height of the strip and not the height of the entire bitmap. 
01122     if (!WrittenHeader)
01123     {
01124         WrittenHeader = TRUE;
01125 
01126         LPBITMAPINFO lpInfo = lpBitmapInfo;
01127         LPLOGPALETTE lpPalette = NULL;
01128         ERROR2IF(lpInfo==NULL,FALSE,"BMPFilter::WriteDataToFile null export region bitmap");
01129 
01130         // Set up some useful variables giving details on the bitmap to save
01131         const UINT32 OutputDepth = Bpp;
01132         // First, get the size of the bitmap we are going to export not just the simple
01133         // lpInfo->bmiHeader.biHeight as this might just be the height of the first
01134         // strip to be exported. With the width we can use the old method.
01135 //      const UINT32 OutputWidth = lpInfo->bmiHeader.biWidth;
01136         const UINT32 OutputHeight = (INT32)ExportRegion->GetFullRegionHeight();
01137 TRACEUSER( "Neville", _T("BMPFilter::WriteDataToFile Total output height = %d\n"),OutputHeight);
01138 TRACEUSER( "Neville", _T("BMPFilter::WriteDataToFile height of 1st strip = %d\n"),lpInfo->bmiHeader.biHeight);
01139 
01140         if (OutputDepth==8 || OutputDepth==4 || OutputDepth==1 )
01141         {
01142             // SMFIX
01143             lpPalette = pBMPOptions->GetLogicalPalette();
01144 
01145             /*
01146             if (pOptimisedPalette)
01147             {
01148                 lpPalette = pOptimisedPalette;
01149                 TRACEUSER( "Will", _T("BMP filter is using an Optimised Palette\n"));
01150             }
01151             else
01152             {
01153                 GDrawContext *GDC = GRenderRegion::GetDrawContext();
01154                 // In the 4 or 1 bpp this will not necessarily be the palette that we
01155                 // should export with as it will just be the default 8bpp palette.
01156                 // Must tell it what depth (BPP) we want. The other information is superfluous
01157                 // at present as this should be called again when the info is correct.
01158                 GDC->SetupBitmap(OutputWidth, OutputHeight, OutputDepth, NULL );
01159 
01160                 // WEBSTER - markn 8/2/97
01161                 // Centralised the palette creation code for all bitmap filters
01162                 lpPalette = Create8bppPalette();
01163 
01164                 if (OutputDepth == 1)
01165                 {
01166                     // The easy one, I think black and white might be the correct choice here!
01167                     OutputDIB::FixBlackAndWhitePalette(lpPalette);
01168                 }
01169                 else if (OutputDepth == 4)
01170                 {
01171                     // Bit more tricky this one, Gavin uses a fixed 16 colour palette           
01172                     OutputDIB::Fix16ColourPalette(lpPalette);
01173                 }
01174             }
01175             */
01176         }
01177 
01178         // Set up the compression flag only if the output depth is correct
01179         UINT32 Compress = BI_RGB;
01180         if (OutputDepth==4 && Compression)
01181             Compress = BI_RLE4;
01182         if (OutputDepth==8 && Compression)
01183             Compress = BI_RLE8;
01184 
01185         if (!DestDIB.StartFile( OutputFile,
01186                                 &lpInfo->bmiHeader,             // pointer to BITMAPINFOHEADER 
01187                                 lpPalette,
01188 
01189                                 OutputDepth,                    // actual file depth
01190                                 Compress,                       // compression (BI_RGB = none)
01191                                 OutputHeight,                   // all of it
01192 
01193                                 SizeOfExport,                   // progress bar size
01194                                 FALSE,
01195                                 pBMPOptions->GetDither() )
01196             )
01197         {
01198 //          if (lpPalette != pOptimisedPalette)
01199 //              CCFree(lpPalette);
01200 
01201             return FALSE;
01202         }
01203 
01204 //      if (lpPalette != pOptimisedPalette)
01205 //          CCFree(lpPalette);
01206     }
01207 
01208 
01209     if (!End)
01210     {
01211         ENSURE(FALSE, "WriteToFile cannot do segmented writes");
01212         return FALSE;
01213     }
01214 
01215     // now lets write out our block
01216     const UINT32 StripHeight = lpBitmapInfo->bmiHeader.biHeight;
01217     if (!DestDIB.WriteBlock(    0,                      // Ypos
01218                                 StripHeight,            // height of this strip
01219                                 lpBits,                 // pointer to actual bitmap data
01220                                 32,                     // input bpp
01221                                 ProgressOffset          // value to add to progress bar updats
01222                             )
01223        )
01224         return FALSE;
01225 
01226     // Add in the height of the strip that we have just exported to the progress offset value
01227     ProgressOffset += StripHeight;
01228 
01229 #endif
01230     return TRUE;
01231 }
01232 
01233 /********************************************************************************************
01234 
01235 >   static BOOL BMPFilter::EndWriteDataToFile( )
01236 
01237     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01238     Created:    15/5/95
01239     Inputs:     -
01240     Purpose:    Actually does the job of cleaning up after writing the bitmap data out to a
01241                 file. Usually called by EndWriteToFile. 
01242     Returns:    TRUE if worked, FALSE if failed.
01243 
01244 ********************************************************************************************/
01245 
01246 BOOL BMPFilter::EndWriteDataToFile( )
01247 {
01248 #ifdef DO_EXPORT
01249     if (GeneratingOptimisedPalette())
01250         return TRUE;        // No need to output anything
01251 
01252     return DestDIB.TidyUp();
01253 #else
01254     return FALSE;
01255 #endif
01256 }
01257 
01258 /********************************************************************************************
01259 
01260 >   INT32 BMPFilter::HowCompatible(PathName& Filename, ADDR HeaderStart, UINT32 HeaderSize, 
01261                                  UINT32 FileSize)
01262 
01263     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
01264     Created:    31/08/94
01265     Inputs:     Filename - name of the file.
01266                 HeaderStart - Address of the first few bytes of the file.
01267                 HeaderSize - the number of bytes in the header pointed to by FileStart.
01268                 FileSize - the size of the whole file, in bytes.
01269     Returns:    0 => Not a BMP file.
01270                 10 => It is a BMP file.
01271     Purpose:    Determine if this filter can load the specified file.
01272 
01273 ********************************************************************************************/
01274 
01275 
01276 
01277 INT32 BMPFilter::HowCompatible(PathName& Filename, ADDR HeaderStart, UINT32 HeaderSize, 
01278                              UINT32 FileSize)
01279 {
01280     // We need to remember what we thought of this file in our class variable.
01281     // So, set it to a nice default value at the start.
01282     BMPHowCompatible = 0;
01283 
01284     // Check that we've got enough data to do our check
01285     if (HeaderSize < sizeof(BITMAPFILEHEADER))
01286         // Not enough data - ignore this file.
01287         return 0;
01288 
01289     // Check the header for the "BM" signature, and a sensible image size.
01290     LPBITMAPFILEHEADER pHeader = (LPBITMAPFILEHEADER) HeaderStart;
01291 
01292     if (pHeader->bfType != ( ('M'<<8) | 'B' ) )
01293         // No BMP signature - we don't want this file.
01294         return 0;
01295 
01296     // the other fields in the BITMAPFILEHEADER cannot be relied upon. The bfSize
01297     // field seems particularly random. We can check the size of the structure following
01298     // it though
01299 
01300     const DWORD HdrSize = *(DWORD*)(HeaderStart + sizeof(BITMAPFILEHEADER) );
01301 
01302     // If the header is of the correct size then now see what we think of this bitmap
01303     // header that we have been given. Cope with old OS/2 style headers and more up
01304     // to date ones.  
01305     // If the header was ok we used to just say 'we like it' immediately. What we want
01306     // to do now instead is only say we are really interested if it is special types of
01307     // BMP, such as 32bpp,  if it is anything else then say we are less interested in it.
01308     // This should allow the Accusoft BMP filter to take over the loading of BMPs which
01309     // we do not support. 
01310     // Pointer to the info header should be the next one after the file header 
01311     INT32 FileCompatibility = 0;    // default, didn't like this file value
01312     if (
01313         (HdrSize==sizeof( BITMAPCOREHEADER ))               // old OS/2 1.0
01314        )
01315     {
01316         LPBITMAPCOREHEADER pCoreHeader = (LPBITMAPCOREHEADER)(pHeader+1);
01317 
01318         if ( DIBUtil::CanReadFromFile(pCoreHeader) )
01319             FileCompatibility = 10;
01320         else
01321             FileCompatibility = 9;
01322     }
01323     else if
01324        (            
01325         (HdrSize==sizeof( BITMAPINFOHEADER ))               // Win 3.0+
01326        )
01327     {
01328         LPBITMAPINFOHEADER pInfoHeader = (LPBITMAPINFOHEADER)(pHeader+1);
01329 
01330         // Use the function in DIBUtil to say if we like this file or not 
01331         if ( DIBUtil::CanReadFromFile(pInfoHeader) )
01332             FileCompatibility = 10;
01333         else
01334             FileCompatibility = 9;
01335     }
01336 
01337 TRACEUSER( "Neville", _T("BMPFilter::HowCompatible FileCompatibility = %d\n"),FileCompatibility);
01338     // Remember what we thought in our class variable.
01339     BMPHowCompatible = FileCompatibility;
01340                 
01341     // Return the found value to the caller.
01342     return FileCompatibility;
01343 }
01344 
01345 /********************************************************************************************
01346 
01347 >   INT32 BMPFilter::GetBmpCompatibility()
01348 
01349     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01350     Created:    03/02/95
01351     Inputs:     -
01352     Returns:    The value we found in the HowCompatible call.
01353                 0 => Not a BMP file.
01354                 10 => It is a BMP file.
01355     Purpose:    Determine if this filter can load the specified file.
01356 
01357 ********************************************************************************************/
01358 
01359 INT32 BMPFilter::GetBmpCompatibility()
01360 {
01361     return BMPHowCompatible;
01362 }
01363 
01364 /********************************************************************************************
01365 
01366 >   virtual BOOL BMPFilter::WriteBitmapToFile(KernelBitmap* pKernelBitmap, double Dpi)
01367 
01368     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01369     Created:    25/4/95
01370     Inputs:     Pointer to the bitmap to save.
01371                 Dpi of the bitmap to be saved
01372     Returns:    TRUE if worked, FALSE if errored.
01373     Purpose:    Physically put the bitmap into the disk.
01374     SeeAlso:    WriteDataToFile(); AccusoftFilters::WriteToFile; AccusoftFilters::WriteDataToFile;
01375 
01376 ********************************************************************************************/
01377 
01378 BOOL BMPFilter::WriteBitmapToFile(KernelBitmap* pKernelBitmap, double TheDpi)
01379 {
01380 #ifdef DO_EXPORT
01381     ERROR2IF(pKernelBitmap == NULL,FALSE,"BMPFilter::WriteBitmapToFile null bitmap pointer specified");
01382 
01383     // Get a pointer to the actual bitmap so that we can get some details from it.
01384     OILBitmap *pOilBitmap = pKernelBitmap->ActualBitmap;
01385     ERROR2IF(pOilBitmap == NULL,FALSE,"BMPFilter::WriteBitmapToFile null oil bitmap pointer");
01386 
01387     // Now get the pointer to the info header and actual bits data.
01388     // Need to use the actual bitmap pointer
01389     CWxBitmap* pWBitmap = (CWxBitmap*)pOilBitmap;
01390     LPBITMAPINFO Info = pWBitmap->BMInfo;
01391     LPBYTE Bytes = pWBitmap->BMBytes;
01392 
01393     // Now, save the data out showing the correct progress string
01394     String_64 ProgressString(ExportingMsgID);
01395     BOOL ok = FALSE;
01396     // If the user has chosen a compressed BMP then we must use the Accusoft code,
01397     // if it is present as the built in one cannot do RLE compression.
01398     //WEBSTER-Martin-07/01/97
01399 #ifndef WEBSTER
01400 PORTNOTE("ExtFilt", "Removed use of external filters")
01401 #ifndef EXCLUDE_FROM_XARALX
01402     BOOL Compression = FALSE;
01403     UINT32 Bpp = pWBitmap->GetBPP();
01404     if (
01405         (DefaultExportCompression && (Bpp == 4)) ||
01406         (DefaultExportCompression && (Bpp == 8))
01407        )        
01408     
01409     {
01410         // Set Compression TRUE and force the Accusoft filter type to be compressed.
01411         Compression = TRUE;
01412         AccusoftFilters::SetFilterType(BMP_COMPRESSED);
01413         AccusoftFilters::SetExportDpi(TheDpi);  
01414     }
01415     
01416     if  ( Compression && (AccusoftFilters::GetVersionNumber() > 0) )
01417         ok = AccusoftFilters::WriteToFile(OutputFile, Info, Bytes, &ProgressString);
01418     else
01419 #endif
01420 #endif //WEBSTER
01421         ok = DIBUtil::WriteToFile(OutputFile, Info, Bytes, &ProgressString);
01422     
01423     return ok;
01424 #else
01425     return FALSE;
01426 #endif
01427 }
01428 
01429 /********************************************************************************************
01430 
01431 >   virtual BOOL BMPFilter::WriteBitmapToFile(KernelBitmap* pKernelBitmap, BaseCamelotFilter *pFilter,
01432                                               CCLexFile *pFile, INT32 Compression);
01433 
01434 
01435     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01436     Created:    20/6/96
01437     Inputs:     pKernelBitmap   - Pointer to the bitmap to be exported.
01438                 pFilter         - Pointer to the BaseCamelot filter which provides progress functions
01439                 pFile           - Pointer to the CCFile class to use for export
01440                 Compression     - used to flag how much compression of the data is required.
01441     Returns:    TRUE if worked, FALSE if errored.
01442     Purpose:    Physically put the bitmap into the disk.  Inherited classes override this to write
01443                 in different file formats.
01444                 This is used by the native/web format to output the actual bitmap data content
01445                 of a bitmap definition record. The function can assume that the CCFile is open
01446                 and ready for writing and must use the functions provided by pFilter to update
01447                 the progress system.
01448     SeeAlso:    BitmapListComponent::SaveBitmapDefinition;
01449 
01450 ********************************************************************************************/
01451 
01452 BOOL BMPFilter::WriteBitmapToFile(KernelBitmap* pKernelBitmap, BaseCamelotFilter *pFilter,
01453                                   CCLexFile *pFile, INT32 Compression)
01454 {
01455 #ifdef DO_EXPORT
01456     ERROR2IF(pKernelBitmap == NULL,FALSE, "BMPFilter::WriteBitmapToFile null pKernelBitmap");
01457     ERROR2IF(pFilter == NULL,FALSE, "BMPFilter::WriteBitmapToFile null pFilter");
01458     ERROR2IF(pFile == NULL,FALSE, "BMPFilter::WriteBitmapToFile null pFile");
01459 
01460     // Get a pointer to the actual bitmap so that we can get some details from it.
01461     OILBitmap *pOilBitmap = pKernelBitmap->ActualBitmap;
01462     ERROR2IF(pOilBitmap == NULL,FALSE,"BMPFilter::WriteBitmapToFile null oil bitmap pointer");
01463 
01464     // Now get the pointer to the info header and actual bits data.
01465     // Need to use the actual bitmap pointer
01466     CWxBitmap* pWBitmap = (CWxBitmap*)pOilBitmap;
01467     LPBITMAPINFO Info = pWBitmap->BMInfo;
01468     LPBYTE Bytes = pWBitmap->BMBytes;
01469 //  UINT32 Bpp = pWBitmap->GetBPP();
01470 
01471     // Now, save the data out showing the correct progress string
01472     BOOL ok = FALSE;
01473 
01474     // We never worry about compresion of bmps for the present moment
01475     // Just changed that so we zlib the bitmaps
01476     // Start up the compressor
01477     BOOL Ok = pFile->InitCompression();
01478     if (!Ok)
01479         return FALSE;
01480     // Now start the compression
01481     pFile->SetCompression(TRUE);
01482     
01483     // Write to file, no header and using pFilter for progress bar updates
01484     ok = DIBUtil::WriteToFile(pFile, Info, Bytes, NULL, FALSE, pFilter);
01485     
01486     // Now that we have finished, close the compressor down
01487     pFile->SetCompression(FALSE);
01488 
01489     return ok;
01490 #else
01491     return FALSE;
01492 #endif
01493 }
01494 
01495 /********************************************************************************************
01496 
01497 >   virtual BOOL BMPFilter::IsThisBppOk(UINT32 Bpp)
01498 
01499     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01500     Created:    27/4/95
01501     Inputs:     Bpp or Colour depth.
01502     Returns:    TRUE if this filter can cope with this colour depth, FALSE otherwise.
01503     Purpose:    Check if this Bitmap filter can cope with saving at this Bpp/Colour depth.
01504     SeeAlso:    OpMenuExport::DoWithParam;
01505 
01506 ********************************************************************************************/
01507 
01508 BOOL BMPFilter::IsThisBppOk(UINT32 Bpp)
01509 {
01510     return (Bpp == 1 || Bpp == 4 || Bpp == 8|| Bpp == 24 || Bpp == 32);
01511 }
01512 
01513 
01514 /********************************************************************************************
01515 
01516 >   virtual BitmapExportOptions* BMPFilter::CreateExportOptions() const
01517 
01518     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
01519     Created:    29/10/96
01520     Returns:    A pointer to a new BitmapExportInfo class
01521     Purpose:    Allows derived classes to override this function to provide their own class
01522                 derived from BitmapExportInfo containing filter specific information.
01523 
01524 ********************************************************************************************/
01525 BitmapExportOptions* BMPFilter::CreateExportOptions() const
01526 {
01527     BMPExportOptions* pExportOptions = new BMPExportOptions(BMP_UNCOMPRESSED, &FilterName);
01528 
01529     return (BitmapExportOptions*)pExportOptions;
01530 }
01531 
01532 
01533 /********************************************************************************************
01534 
01535 >   void BMPFilter::CleanUpAfterExport()
01536 
01537     Author:     Stefan_Stoykov (Xara Group Ltd) <camelotdev@xara.com>
01538     Created:    14/07/97
01539     Returns:    -
01540     Purpose:    Allows the filter to clean up any allocated resources
01541 
01542 ********************************************************************************************/
01543 
01544 void BMPFilter::CleanUpAfterExport()
01545 {
01546     // call the base filter first
01547     BaseBitmapFilter::CleanUpAfterExport();
01548 
01549     WrittenHeader = FALSE;
01550 }
01551 
01552 
01553 void BMPFilter::AlterPaletteContents( LPLOGPALETTE pPalette )
01554 {
01555     DestDIB.AlterExportPalette( pPalette );
01556 }
01557 

Generated on Sat Nov 10 03:48:07 2007 for Camelot by  doxygen 1.4.4