00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099 #ifndef INC_DIBUTIL
00100 #define INC_DIBUTIL
00101
00102 #include "memblk.h"
00103 #ifndef mmioFOURCC
00104
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
00115 #define CC_BMPTYPE mmioFOURCC('R','G','B','T')
00116
00117
00118
00119 #define EXTRA_GAVIN_BYTES 4
00120
00121 class BitmapInfo;
00122 class WxBitmap;
00123 class KernelBitmap;
00124 class OILBitmap;
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 enum BitmapConvertHint
00137 {
00138 CONVHINT_NONE,
00139 CONVHINT_FINAL24,
00140 CONVHINT_FINAL16,
00141 CONVHINT_FINAL555,
00142 CONVHINT_FINAL565,
00143 CONVHINT_FINAL655,
00144 CONVHINT_FINAL664,
00145 CONVHINT_SCREEN8,
00146 CONVHINT_SCREEN4,
00147 CONVHINT_METAFILE,
00148 CONVHINT_PRINTER,
00149
00150 CONVHINT_MAXVALUE = CONVHINT_PRINTER
00151 };
00152
00153
00154
00155
00156
00157
00158
00159
00160
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);
00175 static BOOL CanReadFromFile( const LPBITMAPCOREHEADER pCoreHeader);
00176 static BOOL CanReadFromFile( const LPBITMAPINFOHEADER pInfoHeader );
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
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
00258
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
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
00273 static LPLOGPALETTE AllocateLogPalette(const UINT32 PaletteSize);
00274
00275
00276 static LPLOGPALETTE CopyBitmapPaletteIntoLogPalette(KernelBitmap * pBitmap);
00277
00278
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
00293
00294
00295 typedef void (*FNPTR_SCANLINE)(INT32 PixelWidth, LPBYTE InputBits, LPBYTE OutputBits);
00296
00297
00298
00299 #endif
00300