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 ASSERT(hDCScreen != NULL); 49 50 hBitmap = CreateCompatibleBitmap(hDCScreen, 16, 16); 51 ASSERT(hBitmap != NULL); 52 53 SetLastError(ERROR_SUCCESS); 54 RTEST(NtGdiGetDIBitsInternal(0, 0, 0, 0, NULL, NULL, 0, 0, 0) == 0); 55 RTEST(GetLastError() == ERROR_SUCCESS); 56 57 SetLastError(ERROR_SUCCESS); 58 RTEST(NtGdiGetDIBitsInternal((HDC)2345, 0, 0, 0, NULL, NULL, 0, 0, 0) == 0); 59 RTEST(GetLastError() == ERROR_SUCCESS); 60 61 SetLastError(ERROR_SUCCESS); 62 RTEST(NtGdiGetDIBitsInternal((HDC)2345, hBitmap, 0, 0, NULL, NULL, 0, 0, 0) == 0); 63 RTEST(GetLastError() == ERROR_SUCCESS); 64 65 SetLastError(ERROR_SUCCESS); 66 RTEST(NtGdiGetDIBitsInternal(hDCScreen, hBitmap, 0, 0, NULL, NULL, 0, 0, 0) == 0); 67 RTEST(GetLastError() == ERROR_SUCCESS); 68 69 SetLastError(ERROR_SUCCESS); 70 RTEST(NtGdiGetDIBitsInternal(hDCScreen, hBitmap, 0, 15, NULL, NULL, 0, 0, 0) == 0); 71 RTEST(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 RTEST(NtGdiGetDIBitsInternal((HDC)0, hBitmap, 0, 15, NULL, &bmp.bi, 0, 0, 0) > 0); 79 RTEST(GetLastError() == ERROR_SUCCESS); 80 TEST(bmp.Colors[0].rgbRed == 0x44); 81 82 ZeroMemory(&bmp, sizeof(bmp)); 83 bmp.bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 84 FillMemory(&bmp.Colors, sizeof(bmp.Colors), 0x44); 85 86 SetLastError(ERROR_SUCCESS); 87 RTEST(NtGdiGetDIBitsInternal((HDC)2345, hBitmap, 0, 15, NULL, &bmp.bi, 0, 0, 0) > 0); 88 RTEST(GetLastError() == ERROR_SUCCESS); 89 TEST(bmp.Colors[0].rgbRed == 0x44); 90 91 ZeroMemory(&bmp, sizeof(bmp)); 92 bmp.bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 93 FillMemory(&bmp.Colors, sizeof(bmp.Colors), 0x44); 94 95 SetLastError(ERROR_SUCCESS); 96 RTEST(NtGdiGetDIBitsInternal(hDCScreen, hBitmap, 0, 15, NULL, &bmp.bi, DIB_RGB_COLORS, 97 DIB_BitmapMaxBitsSize(&bmp.bi, 15), 0) > 0); 98 RTEST(GetLastError() == ERROR_SUCCESS); 99 100 ScreenBpp = GetDeviceCaps(hDCScreen, BITSPIXEL); 101 102 RTEST(bmp.bi.bmiHeader.biWidth == 16); 103 RTEST(bmp.bi.bmiHeader.biHeight == 16); 104 RTEST(bmp.bi.bmiHeader.biBitCount == ScreenBpp); 105 RTEST(bmp.bi.bmiHeader.biSizeImage == (16 * 16) * (ScreenBpp / 8)); 106 107 TEST(bmp.Colors[0].rgbRed == 0x44); 108 109 /* Test with pointer */ 110 // ZeroMemory(&bmp.bi, sizeof(BITMAPINFO)); 111 bmp.bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 112 // FillMemory(&bmp.Colors, sizeof(bmp.Colors), 0x11223344); 113 114 SetLastError(ERROR_SUCCESS); 115 TEST(NtGdiGetDIBitsInternal(hDCScreen, hBitmap, 0, 15, (void*)data, &bmp.bi, DIB_RGB_COLORS, 116 DIB_BitmapMaxBitsSize(&bmp.bi, 15), 0) > 0); 117 RTEST(GetLastError() == ERROR_SUCCESS); 118 119 RTEST(bmp.bi.bmiHeader.biWidth == 16); 120 RTEST(bmp.bi.bmiHeader.biHeight == 16); 121 RTEST(bmp.bi.bmiHeader.biBitCount == ScreenBpp); 122 RTEST(bmp.bi.bmiHeader.biSizeImage == (16 * 16) * (ScreenBpp / 8)); 123 124 TEST(bmp.Colors[0].rgbRed != 0x44); 125 126 /* Test a BITMAPCOREINFO structure */ 127 SetLastError(ERROR_SUCCESS); 128 ZeroMemory(&bic, sizeof(BITMAPCOREINFO)); 129 bic.bmciHeader.bcSize = sizeof(BITMAPCOREHEADER); 130 TEST(NtGdiGetDIBitsInternal(hDCScreen, hBitmap, 0, 15, NULL, (PBITMAPINFO)&bic, DIB_RGB_COLORS, 131 DIB_BitmapMaxBitsSize((PBITMAPINFO)&bic, 15), 0) > 0); 132 RTEST(GetLastError() == ERROR_SUCCESS); 133 134 135 ReleaseDC(NULL, hDCScreen); 136 DeleteObject(hBitmap); 137 138 } 139