#include <dibutil.h>
Static Public Member Functions | |
| static UINT32 | ScanlineSize (UINT32 Width, UINT32 Depth) |
| Used in calculating bitmap memory requirements. Based on Gavin's code in GDraw_SetDIBitmap, which it had better agree with! | |
| static UINT32 | ScanlineBytes (UINT32 Width, UINT32 Depth) |
| Used in calculating offsets along scanlines. NOTE! Differs from ScanlineSize in that it DOES NOT word align the result!!! | |
| static BOOL | PlotDeepDIB (wxDC *phDC, LPBITMAPINFO lpBitmapInfo, LPBYTE lpBits, INT32, INT32, INT32, INT32, INT32, INT32, BitmapConvertHint, HPALETTE=NULL) |
| Plot a deep DIB on a device which does not understand deep DIBs. Works by converting to a 24-bit DIB in slices. The DIB must be using the 'standard' RGB arrangements. If this is called on a non-True Colour device then it will take a very very long time, as 24->8 GDI conversions are terribly slow, unless CONVHINT_SCREEN8/4 is used. | |
| static BOOL | CanReadFromFile (const BitmapInfo *pInfo) |
| To check to see if a .bmp file can be read into memory using ReadFromFile. At present, ReadFromFile only likes 8- & 24- & 32-bit BMPs and so we must tell the caller that this is the case. This is for the old OS/2 1.0 style BMPs. Scope: Static. | |
| static BOOL | CanReadFromFile (const LPBITMAPCOREHEADER pCoreHeader) |
| To check to see if a .bmp file can be read into memory using ReadFromFile. At present, ReadFromFile only likes 8- & 24- & 32-bit BMPs and so we must tell the caller that this is the case. This is for the old OS/2 1.0 style BMPs. Scope: Static. | |
| static BOOL | CanReadFromFile (const LPBITMAPINFOHEADER pInfoHeader) |
| To check to see if a .bmp file can be read into memory using ReadFromFile. At present, ReadFromFile only likes 8- & 24- & 32-bit BMPs and so we must tell the caller that this is the case. This is for the Win 3.0+ style BMPs. Scope: Static. | |
| static BOOL | ReadFromFile (CCLexFile *, LPBITMAPINFO *Info, LPBYTE *Bits, BOOL=TRUE, String_64 *ProgressString=NULL, BaseCamelotFilter *pFilter=NULL) |
| Read a .bmp file into memory. ONLY READS 8- & 24- & 32-bit BMPs currently***. Errors on 16-bit builds*** A progress hourglass can be shown if required. | |
| static BOOL | WriteToFile (CCLexFile *, LPBITMAPINFO Info, LPBYTE Bits, String_64 *ProgressString=NULL, BOOL WriteHeader=TRUE, BaseCamelotFilter *pFilter=NULL) |
| Write a bitmap in memory straight out to file with now rendering or conversion. Errors on 16-bit builds*** A progress hourglass can be shown if required. This function is used by the save bitmap button on the bitmap gallery. All other bitmap export uses the OutputDIB class instead as this copes with using a render region and converting from 32 to the destination format. (caller should close file). | |
| static BOOL | WriteToFile (CCLexFile *, LPBYTE Bits, UINT32 Width, UINT32 Height, UINT32 Depth, String_64 *ProgressString=NULL) |
| Generates a BITMAPINFO structor and then saves out the DIB. | |
| static void | Convert16to24 (INT32 PixelWidth, LPBYTE InputBits, LPBYTE OutputBits) |
| static void | Convert32to24 (INT32 PixelWidth, LPBYTE InputBits, LPBYTE OutputBits) |
| static void | Convert32to24Alpha (INT32 PixelWidth, LPBYTE InputBits, LPBYTE OutputBits, COLORREF Colour) |
| static void | Convert32to32 (INT32 PixelWidth, LPBYTE InputBits, LPBYTE OutputBits) |
| static void | Convert8to8 (INT32 PixelWidth, LPBYTE InputBits, LPBYTE OutputBits) |
| static HPALETTE | MakeIdentityPalette (PALETTEENTRY aRGB[], INT32 nColors) |
| static BitmapConvertHint | CalcConvertHint (DWORD ScreenBPP, wxDC *pTestHDC) |
| Determines RGB arrangements for 15/16-bit devices which is needed during dithering in those modes. User is responsible for preserving the state of the pixel at 0,0 if required. Returns CONVHINT_NONE if an error occurs. | |
| static DWORD | GetGavinBlitFormat (DWORD ScreenBPP, DWORD BitmapBPP, BitmapConvertHint ScreenHint) |
| Determines, from the given inputs, what number should be passed to Gavin routines SetSolidColour and SetUpBitmap (the BPP and BitmapFormat params) in order to get the best possible result (and/or to ensure no dithering occurs). Generally, this is only needed in 16bpp screen modes, but may be called at any time, as it returns safe defaults if not in 16bpp. | |
| static BOOL | MakeTransparentBitmap (LPBITMAPINFO pPseudoColourInfo, LPBYTE pPseudoColourBits, LPBITMAPINFO pMonochromeInfo, LPBYTE pMonochromeBits, const BYTE TransCol) |
| Applies the monochrome bitmap as a mask to a bitmap, setting pixels in the to the image to the TransColour if the equivelent pixel in the mask is not set. | |
| static BOOL | MakeBitmapMask (LPBITMAPINFO pPseudoColourInfo, LPBYTE pPseudoColourBits, LPBITMAPINFO pMonochromeInfo, LPBYTE pMonochromeBits, const BYTE TransCol) |
| Makes the monochrome bitmap (created with) into a mask for displaying the Pseudocolour bitmap. The mask must be 8bpp instead of the implied of 1bpp as applying it as a transparency requires this. | |
| static BOOL | MakeBitmapSmaller (UINT32 OldWidth, UINT32 OldHeight, UINT32 BaseX, UINT32 BaseY, UINT32 NewWidth, UINT32 NewHeight, UINT32 BPP, LPBYTE pBits) |
| Resizes a bitmap. | |
| static BOOL | Init () |
| Reads our prefs. | |
| static UINT32 | CalcPaletteSize (UINT32 Depth, bool bUsingBitFields, UINT32 UsedColours=0) |
| static BOOL | CopyBitmap (LPBITMAPINFO pSourceInfo, LPBYTE pSourceBits, LPBITMAPINFO *pDestInfo, LPBYTE *pDestBits) |
| static BOOL | CopyEntireBitmap (LPBITMAPINFO pSourceInfo, LPBYTE pSourceBits, LPBITMAPINFO *pDestInfo, LPBYTE *pDestBits) |
| Allocates a new DIB information header block and bits data and copies the source bitmap data across to the new bitmap. At present, just copies the actual bits data, the header will be the defaults plus width, height and colour depth. Not interested in the palette and other information stored in the bitmap info header. Same as CopyBitmap but actually copies the rest of the data as well. This includes:- Palette information Header information Bits information. | |
| static BOOL | CopyPalette (LPRGBQUAD pSourcePalette, LPRGBQUAD pDestPalette, UINT32 NumberOfColours) |
| Copy a palette from a bitmap which has been duplicated and so has the same colour depth and number of palette entries, to a destination bitmap. Assumes palettes already allocated as part of the duplication process. | |
| static KernelBitmap * | CopyKernelBitmap (KernelBitmap *pKernelBitmap, BOOL IsTemp=FALSE) |
| Allocates a new CWxBitmap and KernelBitmap pointing to it. Note these are completely new versions containing the same data as the old ones. | |
| static BOOL | CountColoursUsed (BITMAPINFO *pInfo, BYTE *pBits, UINT32 **pResultsArray) |
| Counts the usage for each palette index in the bitmap. NOTE: Caller is responsible for CCFreeing the results array. | |
| static INT32 | FindLeastUsedColour (BITMAPINFO *pInfo, UINT32 *pResultsArray) |
| Takes the results from DIBUtil::CountColoursUsed and works out which colour is the best one to use as a transparent colour by finding the least used. NOTE: Caller is responsible for CCFreeing the results array. | |
| static BOOL | CopyBitmapSection (LPBITMAPINFO pSourceInfo, LPBYTE pSourceBits, LPBITMAPINFO pDestInfo, LPBYTE pDestBits, INT32 SourceTop, INT32 SourceLeft) |
| To copy a section of the source bitmap to the destination. Note that unlike the other copy functions in this file the destination header must in not allocated so you must do it yourself. Likewise palette info. | |
| static BOOL | Optimal4bppPaletteInitialise_1stPass () |
| static BOOL | Optimal4bppPaletteInitialise_2ndPass () |
| static BOOL | GenOptimal4bppPaletteStats_1stPass (RGBQUAD *pBitmap, size_t Size) |
| static BOOL | GenOptimal4bppPaletteStats_2ndPass (RGBQUAD *pBitmap, size_t Size) |
| static BOOL | GenOptimal4bppPalette (PLOGPALETTE pPalette, const size_t MaxColours) |
| static size_t | GetOptimal8bppPaletteWorkspaceSize () |
| static BOOL | Optimal8bppPaletteInitialise (INT32 *Stats) |
| static BOOL | GenOptimal8bppPaletteStats (INT32 *Stats, RGBQUAD *pBitmap, size_t Size) |
| static BOOL | GenOptimal8bppPalette (INT32 *Stats, PLOGPALETTE pPalette, const size_t MaxColours) |
| static size_t | GetOptimalPaletteWorkspaceSize () |
| Returns size of workspace required by optimal palette routines. | |
| static BOOL | OptimalPaletteInitialise (void *Stats) |
| Initialises workspace required by optimal palette routines. Stats should have INT32 size of GetOptimalPaletteWorkspaceSize(). | |
| static BOOL | ExactPaletteInitialise (LPLOGPALETTE pExactPalette) |
| static BOOL | GenOptimalPaletteStats (void *Stats, RGBQUAD *pBitmap, size_t Size) |
| The purpose of this function is to build a table of statistics about one or more bitmaps prior to calling GenOptimalPalette. | |
| static BOOL | GenOptimalPalette (void *Stats, PLOGPALETTE pPalette, const size_t MaxColours) |
| The purpose of this function is to generate an optimal palette suitable for the bitmaps for which statistics have previously been generated. | |
| static BOOL | GenGreyscalePalette (LPRGBQUAD lpPalette, const size_t PaletteSize) |
| Generate a greyscale palette for a greyscale DIB. | |
| static BOOL | Convert24to8 (LPBITMAPINFO pSourceInfo, LPBYTE pSourceBits, LPBITMAPINFO *pDestInfo, LPBYTE *pDestBits, RGBTRIPLE *pPalette, UINT32 NumberOfPaletteEntries) |
| Generate an 8 bit form of a bitmap from a 24 bit form using the given palette. | |
| static BOOL | Convert32to8 (LPBITMAPINFO pSourceInfo, LPBYTE pSourceBits, LPBITMAPINFO *pDestInfo, LPBYTE *pDestBits, RGBTRIPLE *pPalette, UINT32 NumberOfPaletteEntries) |
| Generate an 8 bit form of a bitmap from a 32 bit form using the given palette. | |
| static BOOL | Convert8to32 (LPBITMAPINFO pSourceInfo, LPBYTE pSourceBits, RGBQUAD *pPalette, LPBITMAPINFO pDestInfo, LPBYTE pDestBits) |
| Generates a 32bit form of the input 8bit bitmap, note that the destination bitmapinfo and bitmap must be allocated prior to this function. | |
| static OILBitmap * | Create8bppGreyscaleBitmap (KernelBitmap *pSrcBitmap) |
| Designed to be used to create an 8bpp greyscale bitmap from a 24bpp, 4bpp or 1bpp bitmaps. | |
| static BOOL | ConvertTo8Greyscale (LPBITMAPINFO pSourceInfo, LPBYTE pSourceBits, LPBITMAPINFO *ppDestInfo, LPBYTE *ppDestBits) |
| Generates an 8bpp greyscale bitmap from the given 1bpp, 4bpp or 8bpp bitmap. | |
| static BOOL | GenGreyscalePaletteTriple (RGBTRIPLE *pPalette, const size_t PaletteSize) |
| Generate a packed greyscale palette for a greyscale DIB. | |
| static BOOL | GenerateDifferenceBitmap (LPBITMAPINFO pPreviousInfo, LPBYTE pPreviousBits, LPBITMAPINFO pCurrentInfo, LPBYTE pCurrentBits, LPBITMAPINFO *ppDestInfo, LPBYTE *ppDestBits, INT32 TransColour, BOOL *pFoundBadOverlay=NULL) |
| static BOOL | GenerateSubRegionBitmap (LPBITMAPINFO pSourceInfo, LPBYTE pSourceBits, LPBITMAPINFO *ppDestInfo, LPBYTE *ppDestBits, INT32 TransColour, UINT32 *pLeftOffset, UINT32 *pTopOffset) |
| static LPLOGPALETTE | AllocateLogPalette (const UINT32 PaletteSize) |
| To allocate a LOGPALETTE ready for use. The caller is responsible for cleaning up the memmory allocation. | |
| static LPLOGPALETTE | CopyBitmapPaletteIntoLogPalette (KernelBitmap *pBitmap) |
| To allocate a LOGPALETTE and then copy the palette from inside the bitmap across to the LOGPALETTE. The caller is responsible for cleaning up the memmory allocation. | |
| static BOOL | IsGreyscaleBitmap (KernelBitmap *pKB) |
| Determines whether or not a bitmap is 32bpp. | |
| static BOOL | IsGreyscaleBitmap (OILBitmap *pOilBmp) |
| Determines whether or not a bitmap is 32bpp. | |
| static BOOL | CalculateNumberOfColoursInBitmap (LPLOGPALETTE pExactPalette, RGBQUAD *pBitmap, size_t Size) |
| static void | InvertAlpha (LPBITMAPINFO lpBitmapInfo, LPBYTE lpBits) |
| Camelot uses a different transparency scheme to the rest of the world, in that 255 is clear, and 0 is opaque. Until the rest of the world catches up, it's necessary to invert the alpha channel to make exported files compatible with other programs. | |
| static void | MakeAlphaIntoGreyscale (LPBITMAPINFO lpBitmapInfo, LPBYTE lpBits) |
| Camelot uses a different transparency scheme to the rest of the world, in that 255 is clear, and 0 is opaque. Until the rest of the world catches up, it's necessary to invert the alpha channel to make exported files compatible with other programs. | |
Definition at line 164 of file dibutil.h.
|
|
To allocate a LOGPALETTE ready for use. The caller is responsible for cleaning up the memmory allocation.
Definition at line 4681 of file dibutil.cpp. 04682 { 04683 ERROR2IF(PaletteSize == 0 || PaletteSize > 256,NULL,"AllocateLogPalette Bad PaletteSize"); 04684 04685 LPLOGPALETTE pPalette = NULL; 04686 const size_t TotalPal = sizeof(LOGPALETTE) + ( sizeof(PALETTEENTRY) * PaletteSize ); 04687 pPalette = (LPLOGPALETTE)CCMalloc( TotalPal ); 04688 if (pPalette == NULL) 04689 return NULL; 04690 04691 pPalette->palNumEntries = PaletteSize; 04692 pPalette->palVersion = 0x300; 04693 return pPalette; 04694 }
|
|
||||||||||||
|
Determines RGB arrangements for 15/16-bit devices which is needed during dithering in those modes. User is responsible for preserving the state of the pixel at 0,0 if required. Returns CONVHINT_NONE if an error occurs.
Definition at line 2038 of file dibutil.cpp. 02039 { 02040 switch(ScreenBPP) 02041 { 02042 case 4: 02043 return(CONVHINT_SCREEN4); 02044 02045 case 8: 02046 return(CONVHINT_SCREEN8); 02047 02048 case 16: 02049 case 24: 02050 case 32: 02051 // Drop through to the code below to determine a proper 16/24bpp hint 02052 // (Note: Some cards say they are 24bpp when in fact they're 16bpp, so we must 02053 // do this for both values) 02054 break; 02055 02056 default: 02057 ERROR2(CONVHINT_NONE, "Unknown output screen BPP"); 02058 } 02059 02060 // Writes all 256 values to each gun, and counts the number of different values which are 02061 // returned - i.e. a 5 bit gun cannot return more than 32 values 02062 BYTE LastValue[3] = {0, 0, 0}; 02063 BYTE Count[3] = {0, 0, 0}; 02064 wxMemoryDC memdc; 02065 wxBitmap bitmap( 1, 1 ); 02066 memdc.SelectObject( bitmap ); 02067 for ( UINT32 Value=0x00; Value<0x100; Value++ ) 02068 { 02069 wxColour colour; 02070 memdc.SetPen(wxPen(wxColour(Value,Value,Value))); 02071 memdc.DrawPoint(0,0); 02072 memdc.GetPixel(0,0,&colour); 02073 if ( colour.Red()!=LastValue[0] ) 02074 { 02075 LastValue[0] = colour.Red(); 02076 Count[0]++; 02077 } 02078 if ( colour.Green()!=LastValue[1] ) 02079 { 02080 LastValue[1] = colour.Green(); 02081 Count[1]++; 02082 } 02083 if ( colour.Blue()!=LastValue[2] ) 02084 { 02085 LastValue[2] = colour.Blue(); 02086 Count[2]++; 02087 } 02088 } 02089 memdc.SelectObject( wxNullBitmap ); 02090 02091 // Now determine how many bits would be needed to store the number of values we generated 02092 // for each gun. Note that this code will return (eg) 5 bits for all values between 17-32 inclusive 02093 for (INT32 Gun = 0; Gun < 3; Gun++) 02094 { 02095 INT32 BitPos = 0; 02096 while (Count[Gun] > 0) 02097 { 02098 BitPos++; 02099 Count[Gun] /= 2; 02100 } 02101 Count[Gun] = BitPos; 02102 } 02103 02104 TRACEALL( wxT("16bpp RGB gun configuration auto-detected as %ld.%ld.%ld\n"), 02105 Count[0], Count[1], Count[2]); 02106 02107 // OK. Now determine the enum constant which represents this configuration (if any) 02108 switch(Count[0]) 02109 { 02110 case 5: 02111 if (Count[2] == 5) 02112 { 02113 if (Count[1] == 5) 02114 return(CONVHINT_FINAL555); 02115 02116 if (Count[1] == 6) 02117 return(CONVHINT_FINAL565); 02118 } 02119 break; 02120 02121 case 6: 02122 if (Count[1] == 5 && Count[2] == 5) 02123 return(CONVHINT_FINAL655); 02124 02125 if (Count[1] == 6 && Count[2] == 4) 02126 return(CONVHINT_FINAL664); 02127 break; 02128 02129 case 8: 02130 if (Count[1] == 8 && Count[2] == 8) 02131 return(CONVHINT_FINAL24); 02132 break; 02133 } 02134 02135 // Nope. It's an unknown signature. We'll just have to try 555 and hope for the best 02136 TRACEALL( wxT("Unknown 16bpp RGB gun configuration (%ld.%ld.%ld). Defaulting to CONVHINT_NONE\n"), 02137 Count[0], Count[1], Count[2]); 02138 return(CONVHINT_NONE); 02139 }
|
|
||||||||||||||||
|
Definition at line 2680 of file dibutil.cpp. 02681 { 02682 ERROR3IF((bUsingBitFields && (Depth != 16 || Depth != 32)), "Invalid use of DIBUtil::CalcPaletteSize()"); 02683 02684 // Calculate the size of the DIB data 02685 UINT32 extras = 0; 02686 switch (Depth) 02687 { 02688 case 1: 02689 if (UsedColours > 0 && UsedColours <= 2) 02690 extras = UsedColours; 02691 else 02692 extras = 2; 02693 break; 02694 case 4: 02695 if (UsedColours > 0 && UsedColours <= 16) 02696 extras = UsedColours; 02697 else 02698 extras = 16; 02699 break; 02700 case 8: 02701 if (UsedColours > 0 && UsedColours <= 256) 02702 extras = UsedColours; 02703 else 02704 extras = 256; 02705 break; 02706 case 16: 02707 case 32: 02708 if (bUsingBitFields) 02709 extras = 3; 02710 break; 02711 } 02712 ERROR3IF(extras == 0 && Depth != 16 && Depth != 24 && Depth != 32, "Unsupported DIB depth!"); 02713 02714 return(extras * sizeof(RGBQUAD)); 02715 }
|
|
||||||||||||||||
|
Definition at line 3476 of file dibutil.cpp. 03477 { 03478 ERROR3IF(pExactPalette == NULL, "NULL palette pointer passed to DIBUtil::CalculateNumberOfColoursInBitmap"); 03479 if (pExactPalette == NULL) 03480 return FALSE; 03481 03482 ERROR3IF(pBitmap == NULL, "NULL Bitmap pointer passed to DIBUtil::CalculateNumberOfColoursInBitmap"); 03483 if (pBitmap == NULL) 03484 return FALSE; 03485 03486 ERROR3IF(Size == 0, "Bad size passed to DIBUtil::CalculateNumberOfColoursInBitmap"); 03487 if (Size == 0) 03488 return FALSE; 03489 03490 // return ::CalculateNumberOfColoursInBitmap( pExactPalette, pBitmap, Size ); 03491 ASSERT(0); 03492 return FALSE; 03493 }
|
|
|
To check to see if a .bmp file can be read into memory using ReadFromFile. At present, ReadFromFile only likes 8- & 24- & 32-bit BMPs and so we must tell the caller that this is the case. This is for the Win 3.0+ style BMPs. Scope: Static.
Definition at line 1096 of file dibutil.cpp. 01097 { 01098 ERROR2IF(pInfoHeader==NULL,FALSE,"CanReadFromFile InfoHeader pointer is null"); 01099 BOOL Understand = FALSE; 01100 01101 // Check the depth in the supplied info header to see if we like it or not 01102 INT32 Depth = pInfoHeader->biBitCount; 01103 TRACEUSER( "Neville", wxT("DIBUtil::CanReadFromFile Win 3.0+ type depth = %d\n"), Depth ); 01104 if (Depth == 32) 01105 Understand = TRUE; // it is one of our 32bpp bmp so we definitely like it 01106 else 01107 Understand = FALSE; // Not sure that we can cope with this 01108 01109 return Understand; 01110 }
|
|
|
To check to see if a .bmp file can be read into memory using ReadFromFile. At present, ReadFromFile only likes 8- & 24- & 32-bit BMPs and so we must tell the caller that this is the case. This is for the old OS/2 1.0 style BMPs. Scope: Static.
Definition at line 1062 of file dibutil.cpp. 01063 { 01064 ERROR2IF(pCoreHeader==NULL,FALSE,"CanReadFromFile CoreHeader pointer is null"); 01065 BOOL Understand = FALSE; 01066 01067 // Check the depth in the supplied info header to see if we like it or not 01068 INT32 Depth = pCoreHeader->bcBitCount; 01069 TRACEUSER( "Neville", wxT("DIBUtil::CanReadFromFile OS/2 type depth = %d\n"), Depth ); 01070 if (Depth == 32) 01071 Understand = TRUE; // it is one of our 32bpp bmp so we definitely like it 01072 else 01073 Understand = FALSE; // Not sure that we can cope with this 01074 01075 return Understand; 01076 }
|
|
|
To check to see if a .bmp file can be read into memory using ReadFromFile. At present, ReadFromFile only likes 8- & 24- & 32-bit BMPs and so we must tell the caller that this is the case. This is for the old OS/2 1.0 style BMPs. Scope: Static.
Definition at line 1028 of file dibutil.cpp. 01029 { 01030 ERROR2IF(pInfo==NULL,FALSE,"CanReadFromFile BitmapInfo pointer is null"); 01031 BOOL Understand = FALSE; 01032 01033 // Check the depth in the supplied info header to see if we like it or not 01034 INT32 Depth = pInfo->PixelDepth; 01035 TRACEUSER( "Neville", wxT("DIBUtil::CanReadFromFile depth = %d\n"), Depth ); 01036 if (Depth == 32) 01037 Understand = TRUE; // it is one of our 32bpp bmp so we definitely like it 01038 else 01039 Understand = FALSE; // Not sure that we can cope with this 01040 01041 return Understand; 01042 }
|
|
||||||||||||||||
|
Definition at line 507 of file dibutil.cpp. 00508 { 00509 LPWORD Source = (LPWORD)InputBits; 00510 00511 while (PixelWidth--) 00512 { 00513 const WORD Data = *Source++; 00514 00515 // get five-bit RGB values, which we then double-up just like Quickdraw does 00516 // to get an 8-bit result 00517 const BYTE Blue = Data & 0x1F; 00518 *OutputBits++ = EXPAND(Blue); 00519 00520 const BYTE Green = (Data>>5) & 0x1F; 00521 *OutputBits++ = EXPAND(Green); 00522 00523 const BYTE Red = (Data>>10) & 0x1F; 00524 *OutputBits++ = EXPAND(Red); 00525 } 00526 }
|
|
||||||||||||||||||||||||||||
|
Generate an 8 bit form of a bitmap from a 24 bit form using the given palette.
Definition at line 3671 of file dibutil.cpp. 03674 { 03675 // In case of early set these return pointers to NULL 03676 *pDestInfo = NULL; 03677 *pDestBits = NULL; 03678 03679 ERROR2IF(pSourceInfo == NULL || pSourceBits == NULL, FALSE, "DIBUtil::Convert24to8 bad source bitmap"); 03680 ERROR2IF(pPalette == NULL || NumberOfPaletteEntries == 0, FALSE, "DIBUtil::Convert24to8 bad palette info"); 03681 03682 // Get a pointer to the useful bitmap header information for things like the size of the 03683 // bitmap and colour depth. 03684 LPBITMAPINFOHEADER pSourceInfoHeader = &(pSourceInfo->bmiHeader); 03685 03686 ERROR2IF(pSourceInfoHeader->biBitCount != 24,FALSE,"DIBUtil::Convert24to8 bad source depth"); 03687 03688 // Try and allocate the detsination bitmap to be the same size and colour depth as the source 03689 *pDestInfo = AllocDIB( pSourceInfoHeader->biWidth, pSourceInfoHeader->biHeight, 03690 8, pDestBits ); 03691 03692 // failed to allocate the bitmap so return false. 03693 if (*pDestInfo == NULL || *pDestBits == NULL ) 03694 return FALSE; 03695 03696 LPBITMAPINFOHEADER pDestInfoHeader = &((*pDestInfo)->bmiHeader); 03697 03698 // We will need the palette in LOGPALETTE for use in the conversion 03699 // We must allocate the palette to be the maximum size as otherwise people like Gavin 03700 // blow up 03701 LPLOGPALETTE pLogPalette = NULL; 03702 const UINT32 MaxColours = 256; 03703 pLogPalette = DIBUtil::AllocateLogPalette(MaxColours); 03704 if (pLogPalette == NULL) 03705 return FALSE; 03706 03707 // Now copy the RGBTRIPLE palette into this and into the destination bitmap 03708 // Get a pointer to the palette in the destination bitmap 03709 LPRGBQUAD lpPalette = NULL; 03710 lpPalette = &((*pDestInfo)->bmiColors[0]); // pointer to colours table 03711 //pLogPalette->palVersion = 0x300; 03712 pLogPalette->palNumEntries = NumberOfPaletteEntries; 03713 RGBTRIPLE *pPal = pPalette; 03714 for (UINT32 i = 0; i < NumberOfPaletteEntries; i++) 03715 { 03716 lpPalette->rgbRed = pPal->rgbtRed; 03717 pLogPalette->palPalEntry[i].peRed = pPal->rgbtRed; 03718 lpPalette->rgbGreen = pPal->rgbtGreen; 03719 pLogPalette->palPalEntry[i].peGreen = pPal->rgbtGreen; 03720 lpPalette->rgbBlue = pPal->rgbtBlue; 03721 pLogPalette->palPalEntry[i].peBlue = pPal->rgbtBlue; 03722 pLogPalette->palPalEntry[i].peFlags = 0x00; 03723 lpPalette->rgbReserved = 0x00; 03724 lpPalette++; 03725 pPal++; 03726 } 03727 // Fill in all other entries as black and do not use 03728 for (UINT32 i = NumberOfPaletteEntries; i < MaxColours; i++) 03729 { 03730 pLogPalette->palPalEntry[i].peRed = 0x00; 03731 pLogPalette->palPalEntry[i].peGreen = 0x00; 03732 pLogPalette->palPalEntry[i].peBlue = 0x00; 03733 pLogPalette->palPalEntry[i].peFlags = 0xFF; // mark as do not use 03734 lpPalette->rgbRed = 0x00; 03735 lpPalette->rgbGreen = 0x00; 03736 lpPalette->rgbBlue = 0x00; 03737 lpPalette->rgbReserved = 0xFF; // mark as do not use 03738 lpPalette++; 03739 } 03740 03741 UINT32 DitherType = XARADITHER_NONE; // request no dithering 03742 DIBConvert *pDoConvert = NULL; // the convert DIB 03743 03744 // Do some conversion using the DIBConvert class 03745 pDoConvert = DIBConvert::Create( pSourceInfoHeader->biBitCount, pDestInfoHeader->biBitCount, 03746 pSourceInfoHeader->biWidth, pLogPalette, DitherType); 03747 // If this fails then exit now 03748 if (pDoConvert == NULL) 03749 { 03750 if (pLogPalette) 03751 CCFree(pLogPalette); 03752 return FALSE; 03753 } 03754 03755 // Do the actual conversion process 03756 INT32 ChunkHeight = 16; // We will do the conversion in chunks, in case we ask for dithering 03757 INT32 Height = pSourceInfoHeader->biHeight; 03758 INT32 SourceWidth = DIBUtil::ScanlineSize( pSourceInfoHeader->biWidth, pSourceInfoHeader->biBitCount ) * ChunkHeight; 03759 INT32 DestWidth = DIBUtil::ScanlineSize( pDestInfoHeader->biWidth, pDestInfoHeader->biBitCount ) * ChunkHeight; 03760 BOOL IsFirstStrip = TRUE; // Whether we are on the first strip or not 03761 INT32 CurrentYPos = 0; // current line number 03762 LPBYTE SourceData = pSourceBits; // pointer to the source data 03763 LPBYTE DestData = *pDestBits; // pointer to the destination data 03764 while (CurrentYPos < Height) 03765 { 03766 // Work out the size of the export chunk left, normally ExportChunkHeight but 03767 // if at the end of export may be a small strip left. 03768 const UINT32 ThisBit = min( UINT32(Height - CurrentYPos), (UINT32)ChunkHeight ); 03769 if (!pDoConvert->Convert( SourceData, DestData, ThisBit, IsFirstStrip )) 03770 return FALSE; // stop if conversion failed 03771 03772 IsFirstStrip = FALSE; // Done first strip 03773 SourceData += SourceWidth; // Move on by a lines worth 03774 DestData += DestWidth; // Move on by a lines worth 03775 CurrentYPos += INT32(ThisBit); // Move down by a strips worth 03776 } 03777 03778 // Put back the recommended palette by destructing the convert function. 03779 if (pDoConvert) 03780 { 03781 delete pDoConvert; 03782 pDoConvert = NULL; 03783 } 03784 03785 if (pLogPalette) 03786 { 03787 CCFree(pLogPalette); 03788 pLogPalette = NULL; 03789 } 03790 03791 // If we got this far then more than likely we have waht we want 03792 return TRUE; 03793 }
|
|
||||||||||||||||
|
Definition at line 529 of file dibutil.cpp. 00530 { 00531 // source form is B,G,R,spare 00532 // dest is B,G,R 00533 // Note: if not little-endian, is this still true? 00534 while (PixelWidth--) 00535 { 00536 OutputBits[0] = InputBits[0]; 00537 OutputBits[1] = InputBits[1]; 00538 OutputBits[2] = InputBits[2]; 00539 OutputBits += 3; 00540 InputBits += 4; 00541 } 00542 }
|
|
||||||||||||||||||||
|
Definition at line 546 of file dibutil.cpp. 00547 { 00548 // source form is B,G,R,spare 00549 // dest is B,G,R 00550 // Note: if not little-endian, is this still true? 00551 const BYTE RedBG = (BYTE)(Colour & 0xFF); 00552 const BYTE GreenBG = (BYTE)((Colour >> 8) & 0xFF); 00553 const BYTE BlueBG = (BYTE)((Colour >> 16) & 0xFF); 00554 00555 while (PixelWidth--) 00556 { 00557 const BYTE Trans = InputBits[3]; 00558 const BYTE Alpha = 255 - Trans; 00559 OutputBits[0] = ((InputBits[0] * Alpha) + (RedBG * Trans)) / 255; 00560 OutputBits[1] = ((InputBits[1] * Alpha) + (GreenBG * Trans)) / 255; 00561 OutputBits[2] = ((InputBits[2] * Alpha) + (BlueBG * Trans)) / 255; 00562 OutputBits += 3; 00563 InputBits += 4; 00564 } 00565 }
|
|
||||||||||||||||
|
Definition at line 569 of file dibutil.cpp. 00570 { 00571 // done as DWORDs for speed 00572 LPDWORD Source = (LPDWORD)InputBits; 00573 LPDWORD Dest = (LPDWORD)OutputBits; 00574 while (PixelWidth--) 00575 { 00576 // *Dest++ = *Source++ & 0x00FFFFFF; <- MarkH What for? We can deal with 32BMP Alpha channels! 00577 *Dest++ = *Source++; 00578 } 00579 }
|
|
||||||||||||||||||||||||||||
|
Generate an 8 bit form of a bitmap from a 32 bit form using the given palette.
Definition at line 3817 of file dibutil.cpp. 03820 { 03821 // In case of early set these return pointers to NULL 03822 *pDestInfo = NULL; 03823 *pDestBits = NULL; 03824 03825 ERROR2IF(pSourceInfo == NULL || pSourceBits == NULL, FALSE, "DIBUtil::Convert32to8 bad source bitmap"); 03826 ERROR2IF(pPalette == NULL || NumberOfPaletteEntries == 0, FALSE, "DIBUtil::Convert32to8 bad palette info"); 03827 03828 // Get a pointer to the useful bitmap header information for things like the size of the 03829 // bitmap and colour depth. 03830 LPBITMAPINFOHEADER pSourceInfoHeader = &(pSourceInfo->bmiHeader); 03831 03832 ERROR2IF(pSourceInfoHeader->biBitCount != 32,FALSE,"DIBUtil::Convert32to8 bad source depth"); 03833 03834 // Try and allocate the detsination bitmap to be the same size and colour depth as the source 03835 *pDestInfo = AllocDIB( pSourceInfoHeader->biWidth, pSourceInfoHeader->biHeight, 03836 8, pDestBits ); 03837 03838 // failed to allocate the bitmap so return false. 03839 if (*pDestInfo == NULL || *pDestBits == NULL ) 03840 return FALSE; 03841 03842 LPBITMAPINFOHEADER pDestInfoHeader = &((*pDestInfo)->bmiHeader); 03843 03844 // We will need the palette in LOGPALETTE for use in the conversion 03845 // We must allocate the palette to be the maximum size as otherwise people like Gavin 03846 // blow up 03847 LPLOGPALETTE pLogPalette = NULL; 03848 const UINT32 MaxColours = 256; 03849 pLogPalette = DIBUtil::AllocateLogPalette(MaxColours); 03850 if (pLogPalette == NULL) 03851 return FALSE; 03852 03853 // Now copy the RGBTRIPLE palette into this and into the destination bitmap 03854 // Get a pointer to the palette in the destination bitmap 03855 LPRGBQUAD lpPalette = NULL; 03856 lpPalette = &((*pDestInfo)->bmiColors[0]); // pointer to colours table 03857 //pLogPalette->palVersion = 0x300; 03858 pLogPalette->palNumEntries = NumberOfPaletteEntries; 03859 RGBTRIPLE *pPal = pPalette; 03860 for (UINT32 i = 0; i < NumberOfPaletteEntries; i++) 03861 { 03862 lpPalette->rgbRed = pPal->rgbtRed; 03863 pLogPalette->palPalEntry[i].peRed = pPal->rgbtRed; 03864 lpPalette->rgbGreen = pPal->rgbtGreen; 03865 pLogPalette->palPalEntry[i].peGreen = pPal->rgbtGreen; 03866 lpPalette->rgbBlue = pPal->rgbtBlue; 03867 pLogPalette->palPalEntry[i].peBlue = pPal->rgbtBlue; 03868 pLogPalette->palPalEntry[i].peFlags = 0x00; 03869 lpPalette->rgbReserved = 0x00; 03870 lpPalette++; 03871 pPal++; 03872 } 03873 // Fill in all other entries as black and do not use 03874 for (UINT32 i = NumberOfPaletteEntries; i < MaxColours; i++) 03875 { 03876 pLogPalette->palPalEntry[i].peRed = 0x00; 03877 pLogPalette->palPalEntry[i].peGreen = 0x00; 03878 pLogPalette->palPalEntry[i].peBlue = 0x00; 03879 pLogPalette->palPalEntry[i].peFlags = 0xFF; // mark as do not use 03880 lpPalette->rgbRed = 0x00; 03881 lpPalette->rgbGreen = 0x00; 03882 lpPalette->rgbBlue = 0x00; 03883 lpPalette->rgbReserved = 0xFF; // mark as do not use 03884 lpPalette++; 03885 } 03886 03887 UINT32 DitherType = XARADITHER_NONE; // request no dithering 03888 DIBConvert *pDoConvert = NULL; // the convert DIB 03889 03890 // Do some conversion using the DIBConvert class 03891 pDoConvert = DIBConvert::Create( pSourceInfoHeader->biBitCount, pDestInfoHeader->biBitCount, 03892 pSourceInfoHeader->biWidth, pLogPalette, DitherType); 03893 // If this fails then exit now 03894 if (pDoConvert == NULL) 03895 { 03896 if (pLogPalette) 03897 CCFree(pLogPalette); 03898 return FALSE; 03899 } 03900 03901 // Do the actual conversion process 03902 INT32 ChunkHeight = 16; // We will do the conversion in chunks, in case we ask for dithering 03903 INT32 Height = pSourceInfoHeader->biHeight; 03904 INT32 SourceWidth = DIBUtil::ScanlineSize( pSourceInfoHeader->biWidth, pSourceInfoHeader->biBitCount ) * ChunkHeight; 03905 INT32 DestWidth = DIBUtil::ScanlineSize( pDestInfoHeader->biWidth, pDestInfoHeader->biBitCount ) * ChunkHeight; 03906 BOOL IsFirstStrip = TRUE; // Whether we are on the first strip or not 03907 INT32 CurrentYPos = 0; // current line number 03908 LPBYTE SourceData = pSourceBits; // pointer to the source data 03909 LPBYTE DestData = *pDestBits; // pointer to the destination data 03910 while (CurrentYPos < Height) 03911 { 03912 // Work out the size of the export chunk left, normally ExportChunkHeight but 03913 // if at the end of export may be a small strip left. 03914 const UINT32 ThisBit = min( UINT32(Height - CurrentYPos), (UINT32)ChunkHeight ); 03915 if (!pDoConvert->Convert( SourceData, DestData, ThisBit, IsFirstStrip )) 03916 return FALSE; // stop if conversion failed 03917 03918 IsFirstStrip = FALSE; // Done first strip 03919 SourceData += SourceWidth; // Move on by a lines worth 03920 DestData += DestWidth; // Move on by a lines worth 03921 CurrentYPos += INT32(ThisBit); // Move down by a strips worth 03922 } 03923 03924 // Put back the recommended palette by destructing the convert function. 03925 if (pDoConvert) 03926 { 03927 delete pDoConvert; 03928 pDoConvert = NULL; 03929 } 03930 03931 if (pLogPalette) 03932 { 03933 CCFree(pLogPalette); 03934 pLogPalette = NULL; 03935 } 03936 03937 // If we got this far then more than likely we have waht we want 03938 return TRUE; 03939 }
|
|
||||||||||||||||||||||||
|
Generates a 32bit form of the input 8bit bitmap, note that the destination bitmapinfo and bitmap must be allocated prior to this function.
Definition at line 3966 of file dibutil.cpp. 03968 { 03969 ERROR2IF(pSourceBits == NULL, FALSE, "NULL source bitmap"); 03970 ERROR2IF(pSourceInfo == NULL, FALSE, "NULL source info"); 03971 ERROR2IF(pDestInfo == NULL, FALSE, "NULL destination info"); 03972 ERROR2IF(pDestBits == NULL, FALSE, "Null destination bitmap"); 03973 03974 // most info will be the same so memcpy is the quickest way 03975 //memcpy(pSourceInfo, pDestInfo, sizeof(BITMAPINFO)); 03976 03977 // these will all be the same 03978 pDestInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 03979 pDestInfo->bmiHeader.biWidth = pSourceInfo->bmiHeader.biWidth; 03980 pDestInfo->bmiHeader.biHeight = pSourceInfo->bmiHeader.biHeight; 03981 pDestInfo->bmiHeader.biPlanes = pSourceInfo->bmiHeader.biPlanes; 03982 pDestInfo->bmiHeader.biCompression = pSourceInfo->bmiHeader.biCompression; 03983 pDestInfo->bmiHeader.biXPelsPerMeter = pSourceInfo->bmiHeader.biXPelsPerMeter; 03984 pDestInfo->bmiHeader.biYPelsPerMeter = pSourceInfo->bmiHeader.biYPelsPerMeter; 03985 pDestInfo->bmiHeader.biClrImportant = 0; 03986 03987 // get the size of the new bitmap 03988 INT32 size = pDestInfo->bmiHeader.biWidth * pDestInfo->bmiHeader.biHeight * 4; 03989 03990 //these will be different from source 03991 pDestInfo->bmiHeader.biBitCount = 32; 03992 pDestInfo->bmiHeader.biSizeImage = size; 03993 pDestInfo->bmiHeader.biClrUsed = 0; 03994 03995 03996 // convert from 8 bit to 32 bit 03997 INT32 bmpsize = pSourceInfo->bmiHeader.biWidth * pSourceInfo->bmiHeader.biHeight; 03998 INT32 padding = pSourceInfo->bmiHeader.biWidth % 4; 03999 if (padding) 04000 padding = 4 - padding; 04001 04002 LPBYTE pSource = pSourceBits; 04003 LPBYTE pDest = pDestBits; 04004 for (INT32 i = 0; i < bmpsize; i ++) 04005 { 04006 if (i && i % pSourceInfo->bmiHeader.biWidth == 0) 04007 pSource += padding; 04008 *pDest = pPalette[*pSource].rgbBlue; 04009 pDest++; 04010 *pDest = pPalette[*pSource].rgbGreen; 04011 pDest++; 04012 *pDest = pPalette[*pSource].rgbRed; 04013 pDest++; 04014 *pDest = pPalette[*pSource].rgbReserved; 04015 pDest++; 04016 pSource++; 04017 } 04018 return TRUE |