ReactOS 0.4.15-dev-8093-g3285f69
/srv/doxygen/reactos/win32ss/gdi/gdi32/objects/utils.c

PBITMAPINFO NewBitmapInfo; UINT NewBitmapInfoSize;

NewBitmapInfo = ConvertBitmapInfo(OldBitmapInfo, DIB_RGB_COLORS, &NewBitmapInfoSize, FALSE); if (NewBitmapInfo) { <do something with the bitmap info> if (NewBitmapInfo != OldBitmapInfo) RtlFreeHeap(RtlGetProcessHeap(), 0, NewBitmapInfo); }

#include <precomp.h>
/* LoadLPK global variables */
CONST BITMAPINFOHEADER *BitmapInfoHeader,
UINT *ColorSpec,
UINT *ColorTableSize)
{
WORD BitCount;
DWORD ClrUsed;
DWORD Compression;
/*
* At first get some basic parameters from the passed BitmapInfoHeader
* structure. It can have one of the following formats:
* - BITMAPCOREHEADER (the oldest one with totally different layout
* from the others)
* - BITMAPINFOHEADER (the standard and most common header)
* - BITMAPV4HEADER (extension of BITMAPINFOHEADER)
* - BITMAPV5HEADER (extension of BITMAPV4HEADER)
*/
if (BitmapInfoHeader->biSize == sizeof(BITMAPCOREHEADER))
{
BitCount = ((LPBITMAPCOREHEADER)BitmapInfoHeader)->bcBitCount;
ClrUsed = 0;
Compression = BI_RGB;
}
else
{
BitCount = BitmapInfoHeader->biBitCount;
ClrUsed = BitmapInfoHeader->biClrUsed;
Compression = BitmapInfoHeader->biCompression;
}
switch (Compression)
{
if (*ColorSpec == DIB_PAL_COLORS)
*ColorSpec = DIB_RGB_COLORS;
if (BitCount != 16 && BitCount != 32)
return FALSE;
/*
* For BITMAPV4HEADER/BITMAPV5HEADER the masks are included in
* the structure itself (bV4RedMask, bV4GreenMask, and bV4BlueMask).
* For BITMAPINFOHEADER the color masks are stored in the palette.
*/
if (BitmapInfoHeader->biSize > sizeof(BITMAPINFOHEADER))
*ColorTableSize = 0;
else
*ColorTableSize = 3;
return TRUE;
case BI_RGB:
switch (BitCount)
{
case 1:
*ColorTableSize = ClrUsed ? min(ClrUsed, 2) : 2;
return TRUE;
case 4:
*ColorTableSize = ClrUsed ? min(ClrUsed, 16) : 16;
return TRUE;
case 8:
*ColorTableSize = ClrUsed ? min(ClrUsed, 256) : 256;
return TRUE;
default:
if (*ColorSpec == DIB_PAL_COLORS)
*ColorSpec = DIB_RGB_COLORS;
if (BitCount != 16 && BitCount != 24 && BitCount != 32)
return FALSE;
*ColorTableSize = ClrUsed;
return TRUE;
}
case BI_RLE4:
if (BitCount == 4)
{
*ColorTableSize = ClrUsed ? min(ClrUsed, 16) : 16;
return TRUE;
}
return FALSE;
case BI_RLE8:
if (BitCount == 8)
{
*ColorTableSize = ClrUsed ? min(ClrUsed, 256) : 256;
return TRUE;
}
return FALSE;
case BI_JPEG:
case BI_PNG:
*ColorTableSize = ClrUsed;
return TRUE;
default:
return FALSE;
}
}
CONST BITMAPINFO *BitmapInfo,
UINT ColorSpec,
UINT *BitmapInfoSize,
BOOL FollowedByData)
{
LPBITMAPINFO NewBitmapInfo = (LPBITMAPINFO)BitmapInfo;
LPBITMAPCOREINFO CoreBitmapInfo = (LPBITMAPCOREINFO)BitmapInfo;
DWORD Size = 0;
UINT PaletteEntryCount = 0;
/*
* At first check if the passed BitmapInfo structure has valid size. It
* can have one of these headers: BITMAPCOREHEADER, BITMAPINFOHEADER,
* BITMAPV4HEADER or BITMAPV5HEADER (see CalculateColorTableSize for
* description).
*/
if ( !BitmapInfo ||
(BitmapInfo->bmiHeader.biSize != sizeof(BITMAPCOREHEADER) &&
(BitmapInfo->bmiHeader.biSize < sizeof(BITMAPINFOHEADER) ||
BitmapInfo->bmiHeader.biSize > sizeof(BITMAPV5HEADER))))
{
return NULL;
}
/*
* Now calculate the color table size. Also if the bitmap info contains
* invalid color information it's rejected here.
*/
if (!CalculateColorTableSize(&BitmapInfo->bmiHeader, &ColorSpec,
&PaletteEntryCount))
{
return NULL;
}
/*
* Calculate the size of image data if applicable. We must be careful
* to do proper aligning on line ends.
*/
if (FollowedByData)
{
}
/*
* If BitmapInfo was originally BITMAPCOREINFO then we need to convert
* it to the standard BITMAPINFO layout.
*/
if (BitmapInfo->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
{
if (ColorSpec == DIB_RGB_COLORS)
Size += PaletteEntryCount * sizeof(RGBQUAD);
else
Size += PaletteEntryCount * sizeof(USHORT);
NewBitmapInfo = RtlAllocateHeap(RtlGetProcessHeap(), 0, Size);
if (NewBitmapInfo == NULL)
{
return NULL;
}
NewBitmapInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
NewBitmapInfo->bmiHeader.biWidth = CoreBitmapInfo->bmciHeader.bcWidth;
NewBitmapInfo->bmiHeader.biHeight = CoreBitmapInfo->bmciHeader.bcHeight;
NewBitmapInfo->bmiHeader.biPlanes = CoreBitmapInfo->bmciHeader.bcPlanes;
NewBitmapInfo->bmiHeader.biBitCount = CoreBitmapInfo->bmciHeader.bcBitCount;
NewBitmapInfo->bmiHeader.biCompression = BI_RGB;
NewBitmapInfo->bmiHeader.biSizeImage = 0;
NewBitmapInfo->bmiHeader.biXPelsPerMeter = 0;
NewBitmapInfo->bmiHeader.biYPelsPerMeter = 0;
NewBitmapInfo->bmiHeader.biClrUsed = 0;
NewBitmapInfo->bmiHeader.biClrImportant = 0;
if (PaletteEntryCount != 0)
{
if (ColorSpec == DIB_RGB_COLORS)
{
for (Index = 0; Index < PaletteEntryCount; Index++)
{
NewBitmapInfo->bmiColors[Index].rgbRed =
CoreBitmapInfo->bmciColors[Index].rgbtRed;
NewBitmapInfo->bmiColors[Index].rgbGreen =
CoreBitmapInfo->bmciColors[Index].rgbtGreen;
NewBitmapInfo->bmiColors[Index].rgbBlue =
CoreBitmapInfo->bmciColors[Index].rgbtBlue;
NewBitmapInfo->bmiColors[Index].rgbReserved = 0;
}
}
else
{
RtlCopyMemory(NewBitmapInfo->bmiColors,
CoreBitmapInfo->bmciColors,
PaletteEntryCount * sizeof(USHORT));
}
}
if (FollowedByData)
{
ULONG_PTR NewDataPtr, OldDataPtr;
if (ColorSpec == DIB_RGB_COLORS)
{
NewDataPtr = (ULONG_PTR)(NewBitmapInfo->bmiColors +
PaletteEntryCount);
OldDataPtr = (ULONG_PTR)(CoreBitmapInfo->bmciColors +
PaletteEntryCount);
}
else
{
NewDataPtr = (ULONG_PTR)(NewBitmapInfo->bmiColors) +
PaletteEntryCount * sizeof(USHORT);
OldDataPtr = (ULONG_PTR)(CoreBitmapInfo->bmciColors) +
PaletteEntryCount * sizeof(USHORT);
}
RtlCopyMemory((PVOID)NewDataPtr, (PVOID)OldDataPtr, DataSize);
}
}
else
{
/* Verify some data validity */
switch (BitmapInfo->bmiHeader.biCompression)
{
case BI_RLE8:
if (BitmapInfo->bmiHeader.biBitCount != 8)
return NULL;
if (BitmapInfo->bmiHeader.biHeight < 0)
return NULL;
break;
case BI_RLE4:
if (BitmapInfo->bmiHeader.biBitCount != 4)
return NULL;
if (BitmapInfo->bmiHeader.biHeight < 0)
return NULL;
break;
default:
break;
}
/* Non "standard" formats must have a valid size set */
if ((BitmapInfo->bmiHeader.biCompression != BI_RGB) &&
(BitmapInfo->bmiHeader.biCompression != BI_BITFIELDS))
{
if (BitmapInfo->bmiHeader.biSizeImage == 0)
return NULL;
}
}
Size = NewBitmapInfo->bmiHeader.biSize;
if (ColorSpec == DIB_RGB_COLORS)
Size += PaletteEntryCount * sizeof(RGBQUAD);
else
Size += PaletteEntryCount * sizeof(USHORT);
*BitmapInfoSize = Size;
return NewBitmapInfo;
}
{
#define COPYS(f,len) MultiByteToWideChar ( CP_THREAD_ACP, 0, pA->f, len, pW->f, len )
#define COPYN(f) pW->f = pA->f
COPYN(lfHeight);
COPYN(lfWidth);
COPYN(lfEscapement);
COPYN(lfOrientation);
COPYN(lfWeight);
COPYN(lfItalic);
COPYN(lfUnderline);
COPYN(lfStrikeOut);
COPYN(lfCharSet);
COPYN(lfOutPrecision);
COPYN(lfClipPrecision);
COPYN(lfQuality);
COPYN(lfPitchAndFamily);
COPYS(lfFaceName,LF_FACESIZE);
pW->lfFaceName[LF_FACESIZE - 1] = '\0';
#undef COPYN
#undef COPYS
}
{
#define COPYS(f,len) WideCharToMultiByte ( CP_THREAD_ACP, 0, pW->f, len, pA->f, len, NULL, NULL )
#define COPYN(f) pA->f = pW->f
COPYN(lfHeight);
COPYN(lfWidth);
COPYN(lfEscapement);
COPYN(lfOrientation);
COPYN(lfWeight);
COPYN(lfItalic);
COPYN(lfUnderline);
COPYN(lfStrikeOut);
COPYN(lfCharSet);
COPYN(lfOutPrecision);
COPYN(lfClipPrecision);
COPYN(lfQuality);
COPYN(lfPitchAndFamily);
COPYS(lfFaceName,LF_FACESIZE);
pA->lfFaceName[LF_FACESIZE - 1] = '\0';
#undef COPYN
#undef COPYS
}
{
WideCharToMultiByte( CP_THREAD_ACP, 0, fontW->elfFullName, -1,
(LPSTR) fontA->elfFullName, LF_FULLFACESIZE, NULL, NULL );
fontA->elfFullName[LF_FULLFACESIZE-1] = '\0';
(LPSTR) fontA->elfStyle, LF_FACESIZE, NULL, NULL );
fontA->elfStyle[LF_FACESIZE-1] = '\0';
(LPSTR) fontA->elfScript, LF_FACESIZE, NULL, NULL );
fontA->elfScript[LF_FACESIZE-1] = '\0';
}
/*
* LPK.DLL loader function
*
* Returns TRUE if a valid parameter was passed and loading was successful,
* returns FALSE otherwise.
*/
BOOL WINAPI LoadLPK(INT LpkFunctionID)
{
if(!hLpk) // Check if the DLL is already loaded
hLpk = LoadLibraryW(L"lpk.dll");
if (hLpk)
{
switch (LpkFunctionID)
{
case LPK_INIT:
return TRUE;
case LPK_ETO:
if (!LpkExtTextOut) // Check if the function is already loaded
LpkExtTextOut = (LPKETO) GetProcAddress(hLpk, "LpkExtTextOut");
{
return FALSE;
}
return TRUE;
case LPK_GCP:
if (!LpkGetCharacterPlacement) // Check if the function is already loaded
LpkGetCharacterPlacement = (LPKGCP) GetProcAddress(hLpk, "LpkGetCharacterPlacement");
{
return FALSE;
}
return TRUE;
case LPK_GTEP:
if (!LpkGetTextExtentExPoint) // Check if the function is already loaded
LpkGetTextExtentExPoint = (LPKGTEP) GetProcAddress(hLpk, "LpkGetTextExtentExPoint");
{
return FALSE;
}
return TRUE;
default:
return FALSE;
}
}
else
return FALSE;
}
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
#define LF_FACESIZE
Definition: dimm.idl:39
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
#define WideCharToMultiByte
Definition: compat.h:111
#define LoadLibraryW(x)
Definition: compat.h:747
static const WCHAR fontW[]
Definition: editor.c:78
#define BI_RLE4
Definition: precomp.h:57
#define BI_RGB
Definition: precomp.h:56
ULONG RGBQUAD
Definition: precomp.h:59
#define ULONG_PTR
Definition: config.h:101
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
VOID WINAPI EnumLogFontExW2A(LPENUMLOGFONTEXA fontA, CONST ENUMLOGFONTEXW *fontW)
Definition: utils.c:402
BOOL WINAPI CalculateColorTableSize(CONST BITMAPINFOHEADER *BitmapInfoHeader, UINT *ColorSpec, UINT *ColorTableSize)
Definition: utils.c:32
VOID NTAPI LogFontA2W(LPLOGFONTW pW, CONST LOGFONTA *pA)
Definition: utils.c:348
BOOL(WINAPI * LPKETO)(HDC hdc, int x, int y, UINT fuOptions, const RECT *lprc, LPCWSTR lpString, UINT uCount, const INT *lpDx, INT unknown)
Definition: gdi32p.h:31
HINSTANCE hLpk
Definition: utils.c:4
LPKGCP LpkGetCharacterPlacement
Definition: utils.c:6
VOID NTAPI LogFontW2A(LPLOGFONTA pA, CONST LOGFONTW *pW)
Definition: utils.c:375
#define LPK_ETO
Definition: gdi32p.h:82
#define LPK_INIT
Definition: gdi32p.h:81
#define LPK_GCP
Definition: gdi32p.h:83
int WINAPI GdiGetBitmapBitsSize(BITMAPINFO *lpbmi)
Definition: bitmap.c:209
BOOL WINAPI LoadLPK(INT LpkFunctionID)
Definition: utils.c:423
LPKETO LpkExtTextOut
Definition: utils.c:5
LPBITMAPINFO WINAPI ConvertBitmapInfo(CONST BITMAPINFO *BitmapInfo, UINT ColorSpec, UINT *BitmapInfoSize, BOOL FollowedByData)
Definition: utils.c:178
BOOL(WINAPI * LPKGTEP)(HDC hdc, LPCWSTR lpString, INT cString, INT nMaxExtent, LPINT lpnFit, LPINT lpnDx, LPSIZE lpSize, DWORD dwUnused, int unknown)
Definition: gdi32p.h:55
#define LPK_GTEP
Definition: gdi32p.h:84
DWORD(WINAPI * LPKGCP)(HDC hdc, LPCWSTR lpString, INT uCount, INT nMaxExtent, LPGCP_RESULTSW lpResults, DWORD dwFlags, DWORD dwUnused)
Definition: gdi32p.h:44
LPKGTEP LpkGetTextExtentExPoint
Definition: utils.c:7
#define BI_BITFIELDS
Definition: mmreg.h:507
#define min(a, b)
Definition: monoChain.cc:55
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4755
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#define CONST
Definition: pedump.c:81
unsigned short USHORT
Definition: pedump.c:61
BITMAPCOREHEADER bmciHeader
Definition: wingdi.h:1453
RGBTRIPLE bmciColors[1]
Definition: wingdi.h:1454
ULONG biClrImportant
Definition: precomp.h:52
USHORT biBitCount
Definition: precomp.h:46
LONG biYPelsPerMeter
Definition: precomp.h:50
ULONG biCompression
Definition: precomp.h:47
LONG biXPelsPerMeter
Definition: precomp.h:49
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1476
RGBQUAD bmiColors[1]
Definition: wingdi.h:1477
CHAR lfFaceName[LF_FACESIZE]
Definition: wingdi.h:1894
WCHAR lfFaceName[LF_FACESIZE]
Definition: wingdi.h:1910
UCHAR rgbReserved
Definition: bootanim.c:106
UCHAR rgbBlue
Definition: bootanim.c:103
UCHAR rgbRed
Definition: bootanim.c:105
UCHAR rgbGreen
Definition: bootanim.c:104
BYTE rgbtGreen
Definition: wingdi.h:1439
BYTE rgbtBlue
Definition: wingdi.h:1438
BYTE rgbtRed
Definition: wingdi.h:1440
int32_t INT
Definition: typedefs.h:58
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
#define COPYN(f)
#define COPYS(f, len)
#define WINAPI
Definition: msvc.h:6
#define DIB_RGB_COLORS
Definition: wingdi.h:367
struct _BITMAPCOREINFO * LPBITMAPCOREINFO
struct tagBITMAPINFO * LPBITMAPINFO
struct tagBITMAPCOREHEADER * LPBITMAPCOREHEADER
#define DIB_PAL_COLORS
Definition: wingdi.h:366
#define BI_JPEG
Definition: wingdi.h:38
#define BI_PNG
Definition: wingdi.h:39
#define BI_RLE8
Definition: wingdi.h:35
#define LF_FULLFACESIZE
Definition: wingdi.h:41
#define CP_THREAD_ACP
Definition: winnls.h:233
char * LPSTR
Definition: xmlstorage.h:182