mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 21:45:41 +00:00
[GDI32_APITEST]
Add more helper code svn path=/trunk/; revision=66220
This commit is contained in:
parent
bd1dc3f8ca
commit
95d5773b2e
2 changed files with 102 additions and 31 deletions
|
@ -2,21 +2,18 @@
|
|||
#include <stdio.h>
|
||||
#include <windef.h>
|
||||
#include <wingdi.h>
|
||||
#include "init.h"
|
||||
|
||||
HBITMAP ghbmpDIB32;
|
||||
HDC ghdcDIB32;
|
||||
HBITMAP ghbmp1, ghbmp4, ghbmp8, ghbmp16, ghbmp24, ghbmp32;
|
||||
HDC ghdcBmp1, ghdcBmp4, ghdcBmp8, ghdcBmp16, ghdcBmp24, ghdcBmp32;
|
||||
HBITMAP ghbmpDIB1, ghbmpDIB4, ghbmpDIB8, ghbmpDIB16, ghbmpDIB24, ghbmpDIB32;
|
||||
HDC ghdcDIB1, ghdcDIB4, ghdcDIB8, ghdcDIB16, ghdcDIB24, ghdcDIB32;
|
||||
PVOID gpvDIB1, gpvDIB4, gpvDIB8, gpvDIB16, gpvDIB24, gpvDIB32;
|
||||
PULONG pulDIB32Bits;
|
||||
HBITMAP ghbmpDIB4;
|
||||
HDC ghdcDIB4;
|
||||
PULONG pulDIB4Bits;
|
||||
HPALETTE ghpal;
|
||||
|
||||
struct
|
||||
{
|
||||
WORD palVersion;
|
||||
WORD palNumEntries;
|
||||
PALETTEENTRY logpalettedata[8];
|
||||
} gpal =
|
||||
MYPAL gpal =
|
||||
{
|
||||
0x300, 8,
|
||||
{
|
||||
|
@ -31,23 +28,77 @@ struct
|
|||
}
|
||||
};
|
||||
|
||||
BOOL
|
||||
InitPerBitDepth(
|
||||
_In_ ULONG cBitsPerPixel,
|
||||
_In_ ULONG cx,
|
||||
_In_ ULONG cy,
|
||||
_Out_ HDC *phdcBmp,
|
||||
_Out_ HBITMAP *phbmp,
|
||||
_Out_ HDC *phdcDIB,
|
||||
_Out_ HBITMAP *phbmpDIB,
|
||||
_Out_ PVOID *ppvBits)
|
||||
{
|
||||
struct
|
||||
{
|
||||
BITMAPCOREHEADER bmiHeader;
|
||||
RGBQUAD bmiColors[256];
|
||||
} bmiBuffer;
|
||||
LPBITMAPINFO pbmi = (LPBITMAPINFO)&bmiBuffer;
|
||||
|
||||
/* Create a compatible DC for the bitmap */
|
||||
*phdcBmp = CreateCompatibleDC(0);
|
||||
if (*phdcBmp == NULL)
|
||||
{
|
||||
printf("CreateCompatibleDC failed for %lu bpp\n", cBitsPerPixel);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Create a bitmap */
|
||||
*phbmp = CreateBitmap(cx, cy, 1, cBitsPerPixel, NULL);
|
||||
if (*phbmp == NULL)
|
||||
{
|
||||
printf("CreateBitmap failed %lu\n", cBitsPerPixel);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
SelectObject(*phdcBmp, *phbmp);
|
||||
|
||||
/* Get info about the bitmap */
|
||||
memset(&bmiBuffer, 0, sizeof(bmiBuffer));
|
||||
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||
if (!GetDIBits(*phdcBmp, *phbmp, 0, 1, NULL, pbmi, DIB_RGB_COLORS))
|
||||
{
|
||||
printf("GetDIBits failed %lu\n", cBitsPerPixel);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Create a compatible DC for the DIB */
|
||||
*phdcDIB = CreateCompatibleDC(0);
|
||||
if (*phdcDIB == NULL)
|
||||
{
|
||||
printf("CreateCompatibleDC failed %lu\n", cBitsPerPixel);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
pbmi->bmiHeader.biCompression = BI_RGB;
|
||||
pbmi->bmiHeader.biHeight = -pbmi->bmiHeader.biHeight;
|
||||
|
||||
/* Create the DIB section with the same values */
|
||||
*phbmpDIB = CreateDIBSection(*phdcDIB, pbmi, DIB_RGB_COLORS, ppvBits, 0, 0 );
|
||||
if (*phbmpDIB == NULL)
|
||||
{
|
||||
printf("CreateDIBSection failed. %lu\n", cBitsPerPixel);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
SelectObject(*phdcDIB, *phbmpDIB);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL InitStuff(void)
|
||||
{
|
||||
BITMAPINFO bmi32 =
|
||||
{{sizeof(BITMAPINFOHEADER), 4, -4, 1, 32, BI_RGB, 0, 1, 1, 0, 0}};
|
||||
BITMAPINFO bmi4 =
|
||||
{{sizeof(BITMAPINFOHEADER), 4, -4, 1, 4, BI_RGB, 0, 1, 1, 0, 0}};
|
||||
|
||||
ghdcDIB32 = CreateCompatibleDC(0);
|
||||
ghdcDIB4 = CreateCompatibleDC(0);
|
||||
|
||||
ghbmpDIB32 = CreateDIBSection(ghdcDIB32, &bmi32, DIB_PAL_COLORS, (PVOID*)&pulDIB32Bits, 0, 0 );
|
||||
if (!ghbmpDIB32) return FALSE;
|
||||
|
||||
ghbmpDIB4 = CreateDIBSection(ghdcDIB4, &bmi4, DIB_PAL_COLORS, (PVOID*)&pulDIB4Bits, 0, 0 );
|
||||
if (!ghbmpDIB32) return FALSE;
|
||||
|
||||
SelectObject(ghdcDIB32, ghbmpDIB32);
|
||||
|
||||
/* Initialize a logical palette */
|
||||
ghpal = CreatePalette((LOGPALETTE*)&gpal);
|
||||
|
@ -57,5 +108,19 @@ BOOL InitStuff(void)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (!InitPerBitDepth(1, 9, 9, &ghdcBmp1, &ghbmp1, &ghdcDIB1, &ghbmpDIB1, &gpvDIB1) ||
|
||||
!InitPerBitDepth(4, 5, 5, &ghdcBmp4, &ghbmp4, &ghdcDIB4, &ghbmpDIB4, &gpvDIB4) ||
|
||||
!InitPerBitDepth(8, 5, 5, &ghdcBmp8, &ghbmp8, &ghdcDIB8, &ghbmpDIB8, &gpvDIB8) ||
|
||||
!InitPerBitDepth(16, 5, 5, &ghdcBmp16, &ghbmp16, &ghdcDIB16, &ghbmpDIB16, &gpvDIB16) ||
|
||||
!InitPerBitDepth(24, 5, 5, &ghdcBmp24, &ghbmp24, &ghdcDIB24, &ghbmpDIB24, &gpvDIB24) ||
|
||||
!InitPerBitDepth(32, 4, 4, &ghdcBmp32, &ghbmp32, &ghdcDIB32, &ghbmpDIB32, &gpvDIB32))
|
||||
{
|
||||
printf("failed to create objects \n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
pulDIB32Bits = gpvDIB32;
|
||||
pulDIB4Bits = gpvDIB4;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -1,16 +1,22 @@
|
|||
|
||||
extern HBITMAP ghbmp1, ghbmp4, ghbmp8, ghbmp16, ghbmp24, ghbmp32;
|
||||
extern HDC ghdcBmp1, ghdcBmp4, ghdcBmp8, ghdcBmp16, ghdcBmp24, ghdcBmp32;
|
||||
extern HBITMAP ghbmpDIB1, ghbmpDIB4, ghbmpDIB8, ghbmpDIB16, ghbmpDIB24, ghbmpDIB32;
|
||||
extern HDC ghdcDIB1, ghdcDIB4, ghdcDIB8, ghdcDIB16, ghdcDIB24, ghdcDIB32;
|
||||
extern PVOID pvBits1Bpp, pvBits4Bpp, pvBits8Bpp, pvBits16Bpp, pvBits24Bpp, pvBits32Bpp;
|
||||
|
||||
extern HBITMAP ghbmpDIB32;
|
||||
extern HDC ghdcDIB32;
|
||||
extern PULONG pulDIB32Bits;
|
||||
extern HBITMAP ghbmpDIB4;
|
||||
extern HDC ghdcDIB4;
|
||||
extern PULONG pulDIB4Bits;
|
||||
extern HPALETTE ghpal;
|
||||
extern struct
|
||||
typedef struct
|
||||
{
|
||||
LOGPALETTE logpal;
|
||||
WORD palVersion;
|
||||
WORD palNumEntries;
|
||||
PALETTEENTRY logpalettedata[8];
|
||||
} gpal;
|
||||
} MYPAL;
|
||||
|
||||
extern MYPAL gpal;
|
||||
|
||||
BOOL InitStuff(void);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue