1 /* 2 * PROJECT: ReactOS API tests 3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later) 4 * PURPOSE: Tests for the StretchBlt API 5 * COPYRIGHT: Copyright 2020 Doug Lyons (douglyons at douglyons dot com) 6 * Most Code copied and modified from Wine gdi32:bitmap test. 7 */ 8 9 #include <stdarg.h> 10 #include <assert.h> 11 #include <string.h> 12 13 #include "ntstatus.h" 14 #define WIN32_NO_STATUS 15 #include "windef.h" 16 #include "winbase.h" 17 #include "winerror.h" 18 #include "wingdi.h" 19 #include "winuser.h" 20 #include "wine/test.h" 21 22 static void test_StretchBlt(void) 23 { 24 HBITMAP bmpDst, bmpSrc; 25 HDC hdcDst, hdcSrc; 26 UINT32 *dstBuffer, *srcBuffer; 27 BITMAPINFO biDst, biSrc; 28 UINT32 expected[256]; 29 30 memset(&biDst, 0, sizeof(BITMAPINFO)); 31 32 biDst.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 33 biDst.bmiHeader.biWidth = 2; 34 biDst.bmiHeader.biHeight = 2; // Set our Height to positive so we are bottom-up 35 biDst.bmiHeader.biPlanes = 1; 36 biDst.bmiHeader.biBitCount = 32; // Set our BitCount to 32 which is Full Color 37 biDst.bmiHeader.biCompression = BI_RGB; 38 39 memcpy(&biSrc, &biDst, sizeof(BITMAPINFO)); // Put same Destination params into the Source 40 41 hdcDst = CreateCompatibleDC(0); 42 hdcSrc = CreateCompatibleDC(0); 43 44 bmpSrc = CreateDIBSection(hdcSrc, &biSrc, DIB_RGB_COLORS, (void**)&srcBuffer, NULL, 0); 45 SelectObject(hdcSrc, bmpSrc); 46 bmpDst = CreateDIBSection(hdcDst, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer, NULL, 0); 47 SelectObject(hdcDst, bmpDst); 48 49 srcBuffer[0] = 0x000000FF; // BLUE - stored beginning bottom left 50 srcBuffer[1] = 0x0000FF00; // GREEN 51 srcBuffer[2] = 0x00FF0000; // RED 52 srcBuffer[3] = 0xFF000000; // BLACK - 0xFF for alpha channel is easy to recognize when printed in hex format 53 54 /* Flip Left to Right on Source */ 55 StretchBlt(hdcDst, 0, 0, 2, 2, hdcSrc, 1, 0, -2, 2, SRCCOPY); 56 expected[0] = 0x0000FF00; 57 expected[1] = 0x000000FF; 58 expected[2] = 0xFF000000; 59 expected[3] = 0x00FF0000; 60 61 ok(expected[1] == dstBuffer[1], "StretchBlt expected { %08X } got { %08X }\n", 62 expected[1], dstBuffer[1]); 63 64 ok(expected[3] == dstBuffer[3], "StretchBlt expected { %08X } got { %08X }\n", 65 expected[3], dstBuffer[3]); 66 67 /* Flip Top to Bottom on Source */ 68 StretchBlt(hdcDst, 0, 0, 2, 2, hdcSrc, 0, 1, 2, -2, SRCCOPY); 69 expected[0] = 0x00FF0000; 70 expected[1] = 0xFF000000; 71 expected[2] = 0x000000FF; 72 expected[3] = 0x0000FF00; 73 74 ok(expected[0] == dstBuffer[0], "StretchBlt expected { %08X } got { %08X }\n", 75 expected[0], dstBuffer[0]); 76 77 ok(expected[1] == dstBuffer[1], "StretchBlt expected { %08X } got { %08X }\n", 78 expected[1], dstBuffer[1]); 79 80 /* Flip Left to Right and Top to Bottom on Source */ 81 StretchBlt(hdcDst, 0, 0, 2, 2, hdcSrc, 1, 1, -2, -2, SRCCOPY); 82 expected[0] = 0xFF000000; 83 expected[1] = 0x00FF0000; 84 expected[2] = 0x0000FF00; 85 expected[3] = 0x000000FF; 86 87 ok(expected[1] == dstBuffer[1], "StretchBlt expected { %08X } got { %08X }\n", 88 expected[1], dstBuffer[1]); 89 90 /* Flip Left to Right and Top to Bottom on both Source and Destination */ 91 StretchBlt(hdcDst, 1, 1, -2, -2, hdcSrc, 1, 1, -2, -2, SRCCOPY); 92 expected[0] = 0xFF000000; 93 expected[1] = 0x00FF0000; 94 expected[2] = 0x00FF0000; 95 expected[3] = 0x000000FF; 96 97 ok(expected[1] == dstBuffer[1], "StretchBlt expected { %08X } got { %08X }\n", 98 expected[1], dstBuffer[1]); 99 100 DeleteDC(hdcSrc); 101 DeleteDC(hdcDst); 102 } 103 104 105 START_TEST(StretchBlt) 106 { 107 test_StretchBlt(); 108 } 109