ReactOS  0.4.14-dev-297-g23e575c
NtGdiGetDIBits.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS api tests
3  * LICENSE: GPL - See COPYING in the top level directory
4  * PURPOSE: Test for NtGdiGetDIBitsInternal
5  * PROGRAMMERS:
6  */
7 
8 #include <win32nt.h>
9 
10 /* taken from gdi32, bitmap.c */
11 UINT
14 {
15  UINT MaxBits = 0;
16 
17  if (Info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
18  {
20  MaxBits = Core->bcBitCount * Core->bcPlanes * Core->bcWidth;
21  }
22  else /* assume BITMAPINFOHEADER */
23  {
24  if ((Info->bmiHeader.biCompression) && (Info->bmiHeader.biCompression != BI_BITFIELDS))
25  return Info->bmiHeader.biSizeImage;
26  // Planes are over looked by Yuan. I guess assumed always 1.
27  MaxBits = Info->bmiHeader.biBitCount * Info->bmiHeader.biPlanes * Info->bmiHeader.biWidth;
28  }
29  MaxBits = ((MaxBits + 31) & ~31 ) / 8; // From Yuan, ScanLineSize = (Width * bitcount + 31)/32
30  return (MaxBits * ScanLines); // ret the full Size.
31 }
32 
33 
34 START_TEST(NtGdiGetDIBitsInternal)
35 {
37  struct
38  {
39  BITMAPINFO bi;
40  RGBQUAD Colors[20];
41  } bmp;
42 // BITMAPINFO bi;
43  INT ScreenBpp;
44  BITMAPCOREINFO bic;
45  DWORD data[20*16];
46 
47  HDC hDCScreen = GetDC(NULL);
48  ok(hDCScreen != NULL, "hDCScreen was NULL.\n");
49 
50  hBitmap = CreateCompatibleBitmap(hDCScreen, 16, 16);
51  ok(hBitmap != NULL, "hBitmap was NULL.\n");
52 
54  ok_int(NtGdiGetDIBitsInternal(0, 0, 0, 0, NULL, NULL, 0, 0, 0), 0);
56 
58  ok_int(NtGdiGetDIBitsInternal((HDC)2345, 0, 0, 0, NULL, NULL, 0, 0, 0), 0);
60 
62  ok_int(NtGdiGetDIBitsInternal((HDC)2345, hBitmap, 0, 0, NULL, NULL, 0, 0, 0), 0);
64 
66  ok_int(NtGdiGetDIBitsInternal(hDCScreen, hBitmap, 0, 0, NULL, NULL, 0, 0, 0), 0);
68 
70  ok_int(NtGdiGetDIBitsInternal(hDCScreen, hBitmap, 0, 15, NULL, NULL, 0, 0, 0), 0);
72 
73  ZeroMemory(&bmp, sizeof(bmp));
74  bmp.bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
75  FillMemory(&bmp.Colors, sizeof(bmp.Colors), 0x44);
76 
78  ok(NtGdiGetDIBitsInternal((HDC)0, hBitmap, 0, 15, NULL, &bmp.bi, 0, 0, 0) > 0,
79  "NtGdiGetDIBitsInternal((HDC)0, hBitmap, 0, 15, NULL, &bmp.bi, 0, 0, 0) <= 0.\n");
81  ok_int(bmp.Colors[0].rgbRed, 0x44);
82 
83  ZeroMemory(&bmp, sizeof(bmp));
84  bmp.bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
85  FillMemory(&bmp.Colors, sizeof(bmp.Colors), 0x44);
86 
88  ok(NtGdiGetDIBitsInternal((HDC)2345, hBitmap, 0, 15, NULL, &bmp.bi, 0, 0, 0) > 0,
89  "The return value was <= 0.\n");
91  ok_int(bmp.Colors[0].rgbRed, 0x44);
92 
93  ZeroMemory(&bmp, sizeof(bmp));
94  bmp.bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
95  FillMemory(&bmp.Colors, sizeof(bmp.Colors), 0x44);
96 
98  ok(NtGdiGetDIBitsInternal(hDCScreen, hBitmap, 0, 15, NULL, &bmp.bi, DIB_RGB_COLORS,
99  DIB_BitmapMaxBitsSize(&bmp.bi, 15), 0) > 0, "The return value was <= 0.\n");
101 
102  ScreenBpp = GetDeviceCaps(hDCScreen, BITSPIXEL);
103 
104  ok_long(bmp.bi.bmiHeader.biWidth, 16);
105  ok_long(bmp.bi.bmiHeader.biHeight, 16);
106  ok_long(bmp.bi.bmiHeader.biBitCount, ScreenBpp);
107  ok_long(bmp.bi.bmiHeader.biSizeImage, (16 * 16) * (ScreenBpp / 8));
108 
109  ok_int(bmp.Colors[0].rgbRed, 0x44);
110 
111  /* Test with pointer */
112 // ZeroMemory(&bmp.bi, sizeof(BITMAPINFO));
113  bmp.bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
114 // FillMemory(&bmp.Colors, sizeof(bmp.Colors), 0x11223344);
115 
117  ok(NtGdiGetDIBitsInternal(hDCScreen, hBitmap, 0, 15, (void*)data, &bmp.bi, DIB_RGB_COLORS,
118  DIB_BitmapMaxBitsSize(&bmp.bi, 15), 0) > 0, "The return value was <= 0.\n");
120 
121  ok_long(bmp.bi.bmiHeader.biWidth, 16);
122  ok_long(bmp.bi.bmiHeader.biHeight, 16);
123  ok_long(bmp.bi.bmiHeader.biBitCount, ScreenBpp);
124  ok_long(bmp.bi.bmiHeader.biSizeImage, (16 * 16) * (ScreenBpp / 8));
125 
126  ok(bmp.Colors[0].rgbRed != 0x44, "bmp.Colors[0].rgbRed was 0x44.\n");
127 
128  /* Test a BITMAPCOREINFO structure */
130  ZeroMemory(&bic, sizeof(BITMAPCOREINFO));
131  bic.bmciHeader.bcSize = sizeof(BITMAPCOREHEADER);
132  ok(NtGdiGetDIBitsInternal(hDCScreen, hBitmap, 0, 15, NULL, (PBITMAPINFO)&bic, DIB_RGB_COLORS,
133  DIB_BitmapMaxBitsSize((PBITMAPINFO)&bic, 15), 0) > 0, "The return value was <= 0.\n");
135 
136 
137  ReleaseDC(NULL, hDCScreen);
139 
140 }
#define BITSPIXEL
Definition: wingdi.h:719
#define ERROR_SUCCESS
Definition: deptool.c:10
HDC WINAPI GetDC(_In_opt_ HWND)
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
static HDC
Definition: imagelist.c:92
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1642
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define ok_long(expression, result)
Definition: atltest.h:133
#define FASTCALL
Definition: nt_native.h:50
int32_t INT
Definition: typedefs.h:56
#define BI_BITFIELDS
Definition: mmreg.h:507
struct TraceInfo Info
BITMAPCOREHEADER bmciHeader
Definition: wingdi.h:1448
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
smooth NULL
Definition: ftsmooth.c:416
#define ok_int(expression, result)
Definition: atltest.h:134
Colors
Definition: ansiprsr.h:4
struct tagBITMAPCOREHEADER BITMAPCOREHEADER
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FillMemory(BUF, SIZ, MASK)
Definition: strucsup.c:31
#define SetLastError(x)
Definition: compat.h:409
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
BITMAP bmp
Definition: alphablend.c:62
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
#define ok(value,...)
Definition: atltest.h:57
struct tagBITMAPCOREHEADER * PBITMAPCOREHEADER
unsigned int UINT
Definition: ndis.h:50
START_TEST(NtGdiGetDIBitsInternal)
static HBITMAP
Definition: button.c:44
#define DIB_RGB_COLORS
Definition: wingdi.h:366
static HBITMAP hBitmap
Definition: timezone.c:35
UINT FASTCALL DIB_BitmapMaxBitsSize(PBITMAPINFO Info, UINT ScanLines)