1 /* 2 * PROJECT: ReactOS api tests 3 * LICENSE: GPL - See COPYING in the top level directory 4 * PURPOSE: Test for SetDIBits 5 * PROGRAMMERS: J�r�me Gardou 6 */ 7 8 #include "precomp.h" 9 10 void Test_SetDIBits() 11 { 12 char buffer[sizeof(BITMAPINFOHEADER)+2*sizeof(RGBQUAD)]; 13 ULONG* dibBuffer; 14 BITMAPINFO* pBMI = (BITMAPINFO*)buffer; 15 char bits1bpp[] = {0x80, 0, 0, 0}; 16 HBITMAP hbmp; 17 int ret; 18 19 ZeroMemory(buffer, sizeof(buffer)); 20 21 pBMI->bmiHeader.biSize=sizeof(BITMAPINFOHEADER); 22 pBMI->bmiHeader.biWidth=2; 23 pBMI->bmiHeader.biHeight=1; 24 pBMI->bmiHeader.biPlanes=1; 25 pBMI->bmiHeader.biBitCount=32; 26 pBMI->bmiHeader.biCompression=BI_RGB; 27 pBMI->bmiHeader.biSizeImage=0; 28 pBMI->bmiHeader.biXPelsPerMeter=0; 29 pBMI->bmiHeader.biYPelsPerMeter=0; 30 pBMI->bmiHeader.biClrUsed=0; 31 pBMI->bmiHeader.biClrImportant=0; 32 33 hbmp = CreateDIBSection(NULL, pBMI, DIB_RGB_COLORS, (PVOID*)&dibBuffer, NULL, 0); 34 ok(hbmp!=NULL, "Failed to create a DIB section\n"); 35 36 pBMI->bmiHeader.biBitCount = 1; 37 pBMI->bmiColors[0].rgbBlue = 0xFF; 38 pBMI->bmiColors[0].rgbGreen = 0; 39 pBMI->bmiColors[0].rgbRed = 0xFF; 40 41 ret = SetDIBits(NULL, hbmp, 0, 1, bits1bpp, pBMI, DIB_RGB_COLORS); 42 ok(ret == 1, "Copied %i scanlines\n", ret); 43 44 ok(dibBuffer[0] == 0, "Wrong color 0x%08x after SetDIBits\n", (unsigned int)dibBuffer[0]); 45 ok(dibBuffer[1] == 0xFF00FF, "Wrong color 0x%08x after SetDIBits\n", (unsigned int)dibBuffer[1]); 46 47 DeleteObject(hbmp); 48 } 49 50 void Test_SetDIBits_1bpp() 51 { 52 char buffer[sizeof(BITMAPINFOHEADER)+2*sizeof(RGBQUAD)]; 53 HDC hdc; 54 BITMAPINFO* pBMI = (BITMAPINFO*)buffer; 55 char bits1bpp[] = {0x80, 0, 0, 0}; 56 HBITMAP hbmp; 57 int ret; 58 COLORREF color; 59 60 hdc = CreateCompatibleDC(0); 61 if(!hdc) 62 { 63 trace("No device contexr !?\n"); 64 return; 65 } 66 67 ZeroMemory(buffer, sizeof(buffer)); 68 69 pBMI->bmiHeader.biSize=sizeof(BITMAPINFOHEADER); 70 pBMI->bmiHeader.biWidth=2; 71 pBMI->bmiHeader.biHeight=1; 72 pBMI->bmiHeader.biPlanes=1; 73 pBMI->bmiHeader.biBitCount=1; 74 pBMI->bmiHeader.biCompression=BI_RGB; 75 pBMI->bmiHeader.biSizeImage=0; 76 pBMI->bmiHeader.biXPelsPerMeter=0; 77 pBMI->bmiHeader.biYPelsPerMeter=0; 78 pBMI->bmiHeader.biClrUsed=2; 79 pBMI->bmiHeader.biClrImportant=0; 80 pBMI->bmiColors[0].rgbBlue = 0xFF; 81 pBMI->bmiColors[0].rgbGreen = 0xFF; 82 pBMI->bmiColors[0].rgbRed = 0xFF; 83 84 hbmp = CreateBitmap(2, 1, 1, 1, NULL); 85 ok(hbmp!=NULL, "Failed to create a monochrome bitmap\n"); 86 87 ret = SetDIBits(NULL, hbmp, 0, 1, bits1bpp, pBMI, DIB_RGB_COLORS); 88 ok(ret == 1, "Copied %i scanlines\n", ret); 89 90 hbmp = SelectObject(hdc, hbmp); 91 ok(hbmp != NULL, "Could not select the bitmap into the context.\n"); 92 color = GetPixel(hdc, 0,0); 93 ok(color == 0, "Wrong color at 0,0 : 0x%08x\n", (UINT)color); 94 color = GetPixel(hdc, 1,0); 95 ok(color == 0xFFFFFF, "Wrong color at 1,0 : 0x%08x\n", (UINT)color); 96 97 hbmp = SelectObject(hdc, hbmp); 98 99 /* Try something else than 0xFFFFFF */ 100 pBMI->bmiColors[0].rgbBlue = 0xFF; 101 pBMI->bmiColors[0].rgbGreen = 0; 102 pBMI->bmiColors[0].rgbRed = 0; 103 104 ret = SetDIBits(NULL, hbmp, 0, 1, bits1bpp, pBMI, DIB_RGB_COLORS); 105 ok(ret == 1, "Copied %i scanlines\n", ret); 106 107 hbmp = SelectObject(hdc, hbmp); 108 ok(hbmp != NULL, "Could not select the bitmap into the context.\n"); 109 color = GetPixel(hdc, 0,0); 110 ok(color == 0, "Wrong color at 0,0 : 0x%08x\n", (UINT)color); 111 color = GetPixel(hdc, 1,0); 112 ok(color == 0xFFFFFF, "Wrong color at 1,0 : 0x%08x\n", (UINT)color); 113 114 hbmp = SelectObject(hdc, hbmp); 115 116 /* Special : try 0 */ 117 pBMI->bmiColors[0].rgbBlue = 0; 118 pBMI->bmiColors[0].rgbGreen = 0; 119 pBMI->bmiColors[0].rgbRed = 0; 120 121 ret = SetDIBits(NULL, hbmp, 0, 1, bits1bpp, pBMI, DIB_RGB_COLORS); 122 ok(ret == 1, "Copied %i scanlines\n", ret); 123 124 hbmp = SelectObject(hdc, hbmp); 125 ok(hbmp != NULL, "Could not select the bitmap into the context.\n"); 126 color = GetPixel(hdc, 0,0); 127 ok(color == 0, "Wrong color at 0,0 : 0x%08x\n", (UINT)color); 128 color = GetPixel(hdc, 1,0); 129 ok(color == 0xFFFFFF, "Wrong color at 1,0 : 0x%08x\n", (UINT)color); 130 131 hbmp = SelectObject(hdc, hbmp); 132 DeleteObject(hbmp); 133 DeleteDC(hdc); 134 } 135 136 START_TEST(SetDIBits) 137 { 138 Test_SetDIBits(); 139 Test_SetDIBits_1bpp(); 140 } 141