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
12 FASTCALL
13 DIB_BitmapMaxBitsSize( PBITMAPINFO Info, UINT ScanLines )
14 {
15     UINT MaxBits = 0;
16 
17     if (Info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
18     {
19        PBITMAPCOREHEADER Core = (PBITMAPCOREHEADER)Info;
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 {
36     HBITMAP hBitmap;
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 
53     SetLastError(ERROR_SUCCESS);
54     ok_int(NtGdiGetDIBitsInternal(0, 0, 0, 0, NULL, NULL, 0, 0, 0), 0);
55     ok_long(GetLastError(), ERROR_SUCCESS);
56 
57     SetLastError(ERROR_SUCCESS);
58     ok_int(NtGdiGetDIBitsInternal((HDC)2345, 0, 0, 0, NULL, NULL, 0, 0, 0), 0);
59     ok_long(GetLastError(), ERROR_SUCCESS);
60 
61     SetLastError(ERROR_SUCCESS);
62     ok_int(NtGdiGetDIBitsInternal((HDC)2345, hBitmap, 0, 0, NULL, NULL, 0, 0, 0), 0);
63     ok_long(GetLastError(), ERROR_SUCCESS);
64 
65     SetLastError(ERROR_SUCCESS);
66     ok_int(NtGdiGetDIBitsInternal(hDCScreen, hBitmap, 0, 0, NULL, NULL, 0, 0, 0), 0);
67     ok_long(GetLastError(), ERROR_SUCCESS);
68 
69     SetLastError(ERROR_SUCCESS);
70     ok_int(NtGdiGetDIBitsInternal(hDCScreen, hBitmap, 0, 15, NULL, NULL, 0, 0, 0), 0);
71     ok_long(GetLastError(), ERROR_SUCCESS);
72 
73     ZeroMemory(&bmp, sizeof(bmp));
74     bmp.bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
75     FillMemory(&bmp.Colors, sizeof(bmp.Colors), 0x44);
76 
77     SetLastError(ERROR_SUCCESS);
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");
80     ok_long(GetLastError(), ERROR_SUCCESS);
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 
87     SetLastError(ERROR_SUCCESS);
88     ok(NtGdiGetDIBitsInternal((HDC)2345, hBitmap, 0, 15, NULL, &bmp.bi, 0, 0, 0) > 0,
89        "The return value was <= 0.\n");
90     ok_long(GetLastError(), ERROR_SUCCESS);
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 
97     SetLastError(ERROR_SUCCESS);
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");
100     ok_long(GetLastError(), ERROR_SUCCESS);
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 
116     SetLastError(ERROR_SUCCESS);
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");
119     ok_long(GetLastError(), ERROR_SUCCESS);
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 */
129     SetLastError(ERROR_SUCCESS);
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");
134     ok_long(GetLastError(), ERROR_SUCCESS);
135 
136 
137     ReleaseDC(NULL, hDCScreen);
138     DeleteObject(hBitmap);
139 
140 }
141