Commit 5c323a54 authored by Bruno Jesus's avatar Bruno Jesus Committed by Alexandre Julliard

gdi32: Support negative count values in GetBitmapBits.

parent 3a14df3b
...@@ -253,7 +253,7 @@ LONG WINAPI GetBitmapBits( ...@@ -253,7 +253,7 @@ LONG WINAPI GetBitmapBits(
dst_stride = get_bitmap_stride( bmp->dib.dsBm.bmWidth, bmp->dib.dsBm.bmBitsPixel ); dst_stride = get_bitmap_stride( bmp->dib.dsBm.bmWidth, bmp->dib.dsBm.bmBitsPixel );
ret = max = dst_stride * bmp->dib.dsBm.bmHeight; ret = max = dst_stride * bmp->dib.dsBm.bmHeight;
if (!bits) goto done; if (!bits) goto done;
if (count > max) count = max; if (count < 0 || count > max) count = max;
ret = count; ret = count;
src.visrect.left = 0; src.visrect.left = 0;
......
...@@ -56,8 +56,9 @@ static void test_bitmap_info(HBITMAP hbm, INT expected_depth, const BITMAPINFOHE ...@@ -56,8 +56,9 @@ static void test_bitmap_info(HBITMAP hbm, INT expected_depth, const BITMAPINFOHE
{ {
BITMAP bm; BITMAP bm;
BITMAP bma[2]; BITMAP bma[2];
INT ret, width_bytes; INT ret, width_bytes, i;
BYTE buf[512], buf_cmp[512]; BYTE buf[512], buf_cmp[512];
INT test_size[] = {0 /*first value will be changed */, 0, -1, -1000, ~0, sizeof(buf)};
ret = GetObjectW(hbm, sizeof(bm), &bm); ret = GetObjectW(hbm, sizeof(bm), &bm);
ok(ret == sizeof(bm), "GetObject returned %d\n", ret); ok(ret == sizeof(bm), "GetObject returned %d\n", ret);
...@@ -75,17 +76,28 @@ static void test_bitmap_info(HBITMAP hbm, INT expected_depth, const BITMAPINFOHE ...@@ -75,17 +76,28 @@ static void test_bitmap_info(HBITMAP hbm, INT expected_depth, const BITMAPINFOHE
assert(sizeof(buf) == sizeof(buf_cmp)); assert(sizeof(buf) == sizeof(buf_cmp));
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
ret = GetBitmapBits(hbm, 0, NULL); test_size[0] = bm.bmWidthBytes * bm.bmHeight;
ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight); /* NULL output buffer with different count values */
for (i = 0; i < sizeof(test_size) / sizeof(test_size[0]); i++)
{
ret = GetBitmapBits(hbm, test_size[i], NULL);
ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
}
memset(buf_cmp, 0xAA, sizeof(buf_cmp)); memset(buf_cmp, 0xAA, sizeof(buf_cmp));
memset(buf_cmp, 0, bm.bmWidthBytes * bm.bmHeight); memset(buf_cmp, 0, bm.bmWidthBytes * bm.bmHeight);
memset(buf, 0xAA, sizeof(buf)); /* Correct output buffer with different count values */
ret = GetBitmapBits(hbm, sizeof(buf), buf); for (i = 0; i < sizeof(test_size) / sizeof(test_size[0]); i++)
ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight); {
ok(!memcmp(buf, buf_cmp, sizeof(buf)), int expect = i == 1 ? 0 : bm.bmWidthBytes * bm.bmHeight;
"buffers do not match, depth %d\n", bmih->biBitCount); memset(buf, 0xAA, sizeof(buf));
ret = GetBitmapBits(hbm, test_size[i], buf);
ok(ret == expect, "Test[%d]: %d != %d\n", i, ret, expect);
if (expect)
ok(!memcmp(buf, buf_cmp, sizeof(buf)),
"Test[%d]: buffers do not match, depth %d\n", i, bmih->biBitCount);
}
/* test various buffer sizes for GetObject */ /* test various buffer sizes for GetObject */
ret = GetObjectW(hbm, sizeof(*bma) * 2, bma); ret = GetObjectW(hbm, sizeof(*bma) * 2, bma);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment