dibutil.h

Go to the documentation of this file.
00001 // $Id: dibutil.h 923 2006-04-29 19:13:19Z 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 #ifndef INC_DIBUTIL
00100 #define INC_DIBUTIL
00101 
00102 #include "memblk.h"
00103 #ifndef mmioFOURCC
00104 //#include <mmsystem.h>
00105 #endif
00106 
00107 class CCLexFile;
00108 class BaseCamelotFilter;
00109 
00110 LPBITMAPINFO AllocDIB( UINT32 Width, UINT32 Height, UINT32 Depth, LPBYTE *Bits, MemoryBlock *Blk=NULL, BOOL UseLimitedHeap = FALSE);
00111 void FreeDIB( LPBITMAPINFO, LPBYTE, MemoryBlock*Blk=NULL, BOOL UseLimitedHeap = FALSE);
00112 INT32 GetDIBBitsSize( LPBITMAPINFOHEADER bh );
00113 
00114 // this is our MS-approved biCompression method for transparent bitmaps
00115 #define CC_BMPTYPE  mmioFOURCC('R','G','B','T')
00116 
00117 // GDraw sometimes read or writes past the end of bitmaps. This constant is the number
00118 // of extra bytes that should be allocated in all bitmaps (always a multiple of 4)
00119 #define EXTRA_GAVIN_BYTES   4
00120 
00121 class BitmapInfo;
00122 class WxBitmap;
00123 class KernelBitmap;
00124 class OILBitmap;
00125 
00126 /********************************************************************************************
00127 
00128 >   BitmapConvertHint
00129 
00130     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00131     Created:    21/2/95
00132     Purpose:    Enum for hinting when converting bitmaps.
00133 
00134 ********************************************************************************************/
00135 
00136 enum BitmapConvertHint
00137 {
00138     CONVHINT_NONE,              // no hints
00139     CONVHINT_FINAL24,           // final output 24-bit
00140     CONVHINT_FINAL16,           // final output 16-bit RGB not known
00141     CONVHINT_FINAL555,          // final output 15-bit
00142     CONVHINT_FINAL565,
00143     CONVHINT_FINAL655,
00144     CONVHINT_FINAL664,
00145     CONVHINT_SCREEN8,           // 8-bit screen
00146     CONVHINT_SCREEN4,           // 4-bit screen
00147     CONVHINT_METAFILE,
00148     CONVHINT_PRINTER,           // printer
00149 
00150     CONVHINT_MAXVALUE = CONVHINT_PRINTER
00151 };
00152 
00153 /********************************************************************************************
00154 
00155 >   class DIBUtil
00156 
00157     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00158     Created:    9/6/94
00159     Purpose:    Contains static functions for handy DIB manipulation. Never instantiate one
00160                 of these. That would be silly.
00161 
00162 ********************************************************************************************/
00163 
00164 class DIBUtil
00165 {
00166 
00167 public:
00168 
00169 
00170     static UINT32 ScanlineSize( UINT32 Width, UINT32 Depth );
00171     static UINT32 ScanlineBytes( UINT32 Width, UINT32 Depth );
00172     static BOOL PlotDeepDIB( wxDC *phDC, LPBITMAPINFO lpBitmapInfo, LPBYTE lpBits, INT32 , INT32 , INT32 , INT32 , INT32 , INT32 , BitmapConvertHint, HPALETTE = NULL );
00173 
00174     static BOOL CanReadFromFile( const BitmapInfo *pInfo);              // Kernel style BMPs
00175     static BOOL CanReadFromFile( const LPBITMAPCOREHEADER pCoreHeader); // old OS/2 1.0 style BMPs
00176     static BOOL CanReadFromFile( const LPBITMAPINFOHEADER pInfoHeader );// Win 3.0+ style BMPs
00177 
00178     static BOOL ReadFromFile( CCLexFile *, LPBITMAPINFO *Info, LPBYTE *Bits, BOOL = TRUE,
00179                                                     String_64 *ProgressString = NULL, BaseCamelotFilter *pFilter = NULL);
00180     static BOOL WriteToFile ( CCLexFile *, LPBITMAPINFO Info, LPBYTE Bits,
00181                             String_64 *ProgressString = NULL, BOOL WriteHeader = TRUE, BaseCamelotFilter *pFilter = NULL);
00182     static BOOL WriteToFile ( CCLexFile *, LPBYTE Bits, UINT32 Width, UINT32 Height, UINT32 Depth, String_64 *ProgressString = NULL);
00183 
00184     static void Convert16to24( INT32 PixelWidth, LPBYTE InputBits, LPBYTE OutputBits );
00185     static void Convert32to24( INT32 PixelWidth, LPBYTE InputBits, LPBYTE OutputBits );
00186     static void Convert32to24Alpha( INT32 PixelWidth, LPBYTE InputBits, LPBYTE OutputBits, COLORREF Colour );
00187     static void Convert32to32( INT32 PixelWidth, LPBYTE InputBits, LPBYTE OutputBits );
00188     static void Convert8to8( INT32 PixelWidth, LPBYTE InputBits, LPBYTE OutputBits );
00189 
00190     static HPALETTE MakeIdentityPalette(PALETTEENTRY aRGB[], INT32 nColors);
00191 
00192     static BitmapConvertHint CalcConvertHint(DWORD ScreenBPP, wxDC *pTestHDC );
00193     static DWORD GetGavinBlitFormat(DWORD ScreenBPP, DWORD BitmapBPP, BitmapConvertHint ScreenHint);
00194 
00195     static BOOL MakeTransparentBitmap(LPBITMAPINFO pPseudoColourInfo, LPBYTE pPseudoColourBits,
00196                                       LPBITMAPINFO pMonochromeInfo, LPBYTE pMonochromeBits,
00197                                       const BYTE TransCol);
00198     static BOOL MakeBitmapMask(LPBITMAPINFO pPseudoColourInfo, LPBYTE pPseudoColourBits,
00199                                       LPBITMAPINFO pMonochromeInfo, LPBYTE pMonochromeBits,
00200                                       const BYTE TransCol);
00201 
00202     static BOOL MakeBitmapSmaller(UINT32 OldWidth, UINT32 OldHeight, UINT32 BaseX, UINT32 BaseY, 
00203                                   UINT32 NewWidth, UINT32 NewHeight, UINT32 BPP, LPBYTE pBits);
00204 
00205     static BOOL Init();
00206 
00207     static UINT32 CalcPaletteSize(UINT32 Depth, bool bUsingBitFields, UINT32 UsedColours = 0);
00208 
00209     static BOOL CopyBitmap(LPBITMAPINFO pSourceInfo, LPBYTE pSourceBits,
00210                            LPBITMAPINFO *pDestInfo, LPBYTE *pDestBits);
00211     static BOOL CopyEntireBitmap(LPBITMAPINFO pSourceInfo, LPBYTE pSourceBits,
00212                                  LPBITMAPINFO *pDestInfo, LPBYTE *pDestBits);
00213     static BOOL CopyPalette(LPRGBQUAD pSourcePalette, LPRGBQUAD pDestPalette, UINT32 NumberOfColours);
00214 
00215     static KernelBitmap *CopyKernelBitmap(KernelBitmap *pKernelBitmap, BOOL IsTemp = FALSE);
00216     
00217     static BOOL CountColoursUsed(BITMAPINFO* pInfo, BYTE* pBits, UINT32** pResultsArray);
00218     static INT32 FindLeastUsedColour(BITMAPINFO* pInfo, UINT32* pResultsArray);
00219 
00220     static BOOL CopyBitmapSection(LPBITMAPINFO pSourceInfo, LPBYTE pSourceBits,
00221                                   LPBITMAPINFO pDestInfo,   LPBYTE pDestBits,
00222                                   INT32 SourceTop, INT32 SourceLeft);
00223 
00224 #if !defined(EXCLUDE_FROM_RALPH)
00225     // Gavin's palette optimisation routines
00226     static BOOL Optimal4bppPaletteInitialise_1stPass() ;
00227     static BOOL Optimal4bppPaletteInitialise_2ndPass() ;
00228     static BOOL GenOptimal4bppPaletteStats_1stPass( RGBQUAD* pBitmap, size_t Size ) ;
00229     static BOOL GenOptimal4bppPaletteStats_2ndPass( RGBQUAD* pBitmap, size_t Size ) ;
00230     static BOOL GenOptimal4bppPalette( PLOGPALETTE pPalette, const size_t MaxColours ) ;
00231 
00232     static size_t GetOptimal8bppPaletteWorkspaceSize() ;
00233     static BOOL Optimal8bppPaletteInitialise( INT32* Stats ) ;
00234     static BOOL GenOptimal8bppPaletteStats( INT32* Stats, RGBQUAD* pBitmap, size_t Size ) ;
00235     static BOOL GenOptimal8bppPalette( INT32* Stats, PLOGPALETTE pPalette, const size_t MaxColours ) ;
00236 
00237     static size_t GetOptimalPaletteWorkspaceSize() ;
00238     static BOOL OptimalPaletteInitialise( void* Stats ) ;
00239     static BOOL ExactPaletteInitialise( LPLOGPALETTE pExactPalette );
00240     static BOOL GenOptimalPaletteStats( void* Stats, RGBQUAD* pBitmap, size_t Size ) ;
00241     static BOOL GenOptimalPalette( void* Stats, PLOGPALETTE pPalette, const size_t MaxColours ) ;
00242 #endif
00243 
00244     static BOOL GenGreyscalePalette(LPRGBQUAD lpPalette, const size_t PaletteSize);
00245 
00246     static BOOL Convert24to8( LPBITMAPINFO pSourceInfo, LPBYTE pSourceBits,
00247                               LPBITMAPINFO *pDestInfo, LPBYTE *pDestBits,
00248                               RGBTRIPLE *pPalette, UINT32 NumberOfPaletteEntries );
00249 
00250     static BOOL Convert32to8( LPBITMAPINFO pSourceInfo, LPBYTE pSourceBits,
00251                               LPBITMAPINFO *pDestInfo, LPBYTE *pDestBits,
00252                               RGBTRIPLE *pPalette, UINT32 NumberOfPaletteEntries );
00253 
00254     static BOOL Convert8to32( LPBITMAPINFO pSourceInfo, LPBYTE pSourceBits, RGBQUAD* pPalette,
00255                               LPBITMAPINFO pDestInfo, LPBYTE pDestBits);
00256 
00257     // WEBSTER - markn 29/1/97
00258     // Code to put contone bitmap technology into Webster, post-accusoft
00259     static OILBitmap*   Create8bppGreyscaleBitmap(KernelBitmap* pSrcBitmap);
00260     static BOOL         ConvertTo8Greyscale(LPBITMAPINFO pSourceInfo,LPBYTE pSourceBits,LPBITMAPINFO *ppDestInfo, LPBYTE *ppDestBits);
00261     static BOOL         GenGreyscalePaletteTriple(RGBTRIPLE* pPalette, const size_t PaletteSize);
00262 
00263     // Useful frame generation routines
00264     static BOOL GenerateDifferenceBitmap(LPBITMAPINFO pPreviousInfo,LPBYTE pPreviousBits,
00265                                          LPBITMAPINFO pCurrentInfo,LPBYTE pCurrentBits,
00266                                          LPBITMAPINFO *ppDestInfo, LPBYTE *ppDestBits,
00267                                          INT32 TransColour, BOOL * pFoundBadOverlay = NULL);
00268     static BOOL GenerateSubRegionBitmap(LPBITMAPINFO pSourceInfo,LPBYTE pSourceBits,
00269                                         LPBITMAPINFO *ppDestInfo, LPBYTE *ppDestBits, INT32 TransColour,
00270                                         UINT32 *pLeftOffset, UINT32 *pTopOffset);
00271 
00272     // Allocate a LOGPALETTE of the correct size
00273     static LPLOGPALETTE AllocateLogPalette(const UINT32 PaletteSize);
00274 
00275     // Allocate a LOGPALETTE and copy the palette from the specified bitmap into it 
00276     static LPLOGPALETTE CopyBitmapPaletteIntoLogPalette(KernelBitmap * pBitmap);
00277 
00278     // Transferred from bfxalu 10/11/97 Neville
00279     static BOOL IsGreyscaleBitmap(KernelBitmap * pKB);
00280     static BOOL IsGreyscaleBitmap(OILBitmap * pOilBmp);
00281 
00282     static BOOL CalculateNumberOfColoursInBitmap( LPLOGPALETTE pExactPalette, RGBQUAD* pBitmap, size_t Size );
00283 
00284     static void InvertAlpha(LPBITMAPINFO lpBitmapInfo, LPBYTE lpBits);
00285 #ifdef _DEBUG
00286     static void FillColour24(LPBITMAPINFO lpBitmapInfo, LPBYTE lpBits);
00287 #endif
00288     static void MakeAlphaIntoGreyscale(LPBITMAPINFO lpBitmapInfo, LPBYTE lpBits);
00289 };
00290 
00291 
00292 // we use pointers to functions for the different scanline conversions. This might seem
00293 // a tad un-OOPs but this way we can do assembler-versons of these as required. The following
00294 // typedef is a pointer to one of these functions
00295 typedef void (*FNPTR_SCANLINE)(INT32 PixelWidth, LPBYTE InputBits, LPBYTE OutputBits);
00296 
00297 
00298 
00299 #endif
00300 

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