2 * Unit test suite for bitmaps
4 * Copyright 2004 Huw Davies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "wine/test.h"
32 static void test_createdibitmap(void)
35 BITMAPINFOHEADER bmih;
37 HBITMAP hbm, hbm_colour, hbm_old;
41 screen_depth = GetDeviceCaps(hdc, BITSPIXEL);
42 memset(&bmih, 0, sizeof(bmih));
43 bmih.biSize = sizeof(bmih);
48 bmih.biCompression = BI_RGB;
50 /* First create an un-initialised bitmap. The depth of the bitmap
51 should match that of the hdc and not that supplied in bmih.
54 /* First try 32 bits */
55 hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
56 ok(hbm != NULL, "CreateDIBitmap failed\n");
57 ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
59 ok(bm.bmBitsPixel == screen_depth, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, screen_depth);
64 hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
65 ok(hbm != NULL, "CreateDIBitmap failed\n");
66 ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
68 ok(bm.bmBitsPixel == screen_depth, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, screen_depth);
73 hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
74 ok(hbm != NULL, "CreateDIBitmap failed\n");
75 ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
77 ok(bm.bmBitsPixel == screen_depth, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, screen_depth);
80 /* Now with a monochrome dc we expect a monochrome bitmap */
81 hdcmem = CreateCompatibleDC(hdc);
83 /* First try 32 bits */
85 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
86 ok(hbm != NULL, "CreateDIBitmap failed\n");
87 ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
89 ok(bm.bmBitsPixel == 1, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, 1);
94 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
95 ok(hbm != NULL, "CreateDIBitmap failed\n");
96 ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
98 ok(bm.bmBitsPixel == 1, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, 1);
103 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
104 ok(hbm != NULL, "CreateDIBitmap failed\n");
105 ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
107 ok(bm.bmBitsPixel == 1, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, 1);
110 /* Now select a polychrome bitmap into the dc and we expect
111 screen_depth bitmaps again */
112 hbm_colour = CreateCompatibleBitmap(hdc, 1, 1);
113 hbm_old = SelectObject(hdcmem, hbm_colour);
115 /* First try 32 bits */
116 bmih.biBitCount = 32;
117 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
118 ok(hbm != NULL, "CreateDIBitmap failed\n");
119 ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
121 ok(bm.bmBitsPixel == screen_depth, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, screen_depth);
125 bmih.biBitCount = 16;
126 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
127 ok(hbm != NULL, "CreateDIBitmap failed\n");
128 ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
130 ok(bm.bmBitsPixel == screen_depth, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, screen_depth);
135 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
136 ok(hbm != NULL, "CreateDIBitmap failed\n");
137 ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
139 ok(bm.bmBitsPixel == screen_depth, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, screen_depth);
142 SelectObject(hdcmem, hbm_old);
143 DeleteObject(hbm_colour);
146 /* If hdc == 0 then we get a 1 bpp bitmap */
147 bmih.biBitCount = 32;
148 hbm = CreateDIBitmap(0, &bmih, 0, NULL, NULL, 0);
149 ok(hbm != NULL, "CreateDIBitmap failed\n");
150 ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
152 ok(bm.bmBitsPixel == 1, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, 1);
158 static void test_dibsections(void)
160 HDC hdc, hdcmem, hdcmem2;
161 HBITMAP hdib, oldbm, hdib2, oldbm2;
162 char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
163 BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
167 char logpalbuf[sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY)];
168 LOGPALETTE *plogpal = (LOGPALETTE*)logpalbuf;
171 HPALETTE hpal, oldpal;
174 memset(pbmi, 0, sizeof(bmibuf));
175 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
176 pbmi->bmiHeader.biHeight = 16;
177 pbmi->bmiHeader.biWidth = 16;
178 pbmi->bmiHeader.biBitCount = 1;
179 pbmi->bmiHeader.biPlanes = 1;
180 pbmi->bmiHeader.biCompression = BI_RGB;
181 pbmi->bmiColors[0].rgbRed = 0xff;
182 pbmi->bmiColors[0].rgbGreen = 0;
183 pbmi->bmiColors[0].rgbBlue = 0;
184 pbmi->bmiColors[1].rgbRed = 0;
185 pbmi->bmiColors[1].rgbGreen = 0;
186 pbmi->bmiColors[1].rgbBlue = 0xff;
188 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
189 ok(hdib != NULL, "CreateDIBSection failed\n");
191 hdcmem = CreateCompatibleDC(hdc);
192 oldbm = SelectObject(hdcmem, hdib);
194 ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
195 ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
196 ok(!memcmp(rgb, pbmi->bmiColors, 2 * sizeof(RGBQUAD)),
197 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
198 rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
199 rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
201 SelectObject(hdcmem, oldbm);
204 /* Now create a palette and a palette indexed dib section */
205 memset(plogpal, 0, sizeof(logpalbuf));
206 plogpal->palVersion = 0x300;
207 plogpal->palNumEntries = 2;
208 plogpal->palPalEntry[0].peRed = 0xff;
209 plogpal->palPalEntry[0].peBlue = 0xff;
210 plogpal->palPalEntry[1].peGreen = 0xff;
212 index = (WORD*)pbmi->bmiColors;
215 hpal = CreatePalette(plogpal);
216 ok(hpal != NULL, "CreatePalette failed\n");
217 oldpal = SelectPalette(hdc, hpal, TRUE);
218 hdib = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (void**)&bits, NULL, 0);
219 ok(hdib != NULL, "CreateDIBSection failed\n");
221 /* The colour table has already been grabbed from the dc, so we select back the
224 SelectPalette(hdc, oldpal, TRUE);
225 oldbm = SelectObject(hdcmem, hdib);
227 ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
228 ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
229 ok(rgb[0].rgbRed == 0xff && rgb[0].rgbBlue == 0xff && rgb[0].rgbGreen == 0 &&
230 rgb[1].rgbRed == 0 && rgb[1].rgbBlue == 0 && rgb[1].rgbGreen == 0xff,
231 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
232 rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
233 rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
235 /* Bottom and 2nd row from top green, everything else magenta */
236 bits[0] = bits[1] = 0xff;
237 bits[13 * 4] = bits[13*4 + 1] = 0xff;
240 pbmi->bmiHeader.biBitCount = 32;
242 hdib2 = CreateDIBSection(NULL, pbmi, DIB_RGB_COLORS, (void **)&bits32, NULL, 0);
243 ok(hdib2 != NULL, "CreateDIBSection failed\n");
244 hdcmem2 = CreateCompatibleDC(hdc);
245 oldbm2 = SelectObject(hdcmem2, hdib2);
247 BitBlt(hdcmem2, 0, 0, 16,16, hdcmem, 0, 0, SRCCOPY);
249 ok(bits32[0] == 0xff00, "lower left pixel is %08lx\n", bits32[0]);
250 ok(bits32[17] == 0xff00ff, "bottom but one, left pixel is %08lx\n", bits32[17]);
252 SelectObject(hdcmem2, oldbm2);
255 SelectObject(hdcmem, oldbm);
265 test_createdibitmap();