ReactOS 0.4.15-dev-5669-g09dde2c
SetLayout.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Tests for SetLayout and its effects on other gdi functions
5 * such as StretchBlt, BitBlt, LPtoDP, DPtoLP
6 * PROGRAMMERS: Baruch Rutman
7 * Inspired by the StretchBlt test
8 */
9
10#include "precomp.h"
11
12static void copy(PUINT32 buffer, UINT32 value, int width, int start_x, int start_y, int end_x, int end_y)
13{
14 for (int y = start_y; y < end_y; y++)
15 {
16 for (int x = start_x; x < end_x; x++)
17 buffer[y * width + x] = value;
18 }
19}
20
21#define BLACK_PIXEL 0x000000
22#define BLUE_PIXEL 0x0000FF
23#define GREEN_PIXEL 0x00FF00
24#define RED_PIXEL 0xFF0000
25#define WHITE_PIXEL 0xFFFFFF
26
27#if 0
28#include "wincon.h"
29
30/* Draw the bitmap as colored letters on white background */
31static void
33{
36
38
39 if (title)
40 printf("%s", title);
41
42 for (int i = 0; i < width * width; i++)
43 {
44 char c;
45 WORD attributes = 0;
46 UINT32 pixel_value = buffer[i];
47
48 if (i % width == 0)
49 {
50 SetConsoleTextAttribute(hConsole, info.wAttributes);
51 putchar('\n');
52 }
53
54 switch (pixel_value)
55 {
56 case WHITE_PIXEL:
57 c = 'W';
58 break;
59 case BLUE_PIXEL:
60 c = 'B';
61 break;
62 case GREEN_PIXEL:
63 c = 'G';
64 break;
65 case RED_PIXEL:
66 c = 'R';
67 break;
68 case BLACK_PIXEL:
69 c = 'E'; /* Use 'E' for 'Empty' because 'B' is taken */
70 break;
71 default:
72 c = '?';
73 }
74
75 if (pixel_value != WHITE_PIXEL && c != '?')
76 {
77 attributes = (pixel_value & RED_PIXEL) ? FOREGROUND_RED : 0 |
78 (pixel_value & GREEN_PIXEL) ? FOREGROUND_GREEN : 0 |
79 (pixel_value & BLUE_PIXEL) ? FOREGROUND_BLUE : 0;
80 }
81
83 putchar(c);
84 }
85 SetConsoleTextAttribute(hConsole, info.wAttributes);
86 putchar('\n');
87}
88#endif
89
90static void nomirror_test(PUINT32 dstBuffer, PUINT32 srcBuffer, int width, int line)
91{
92 for (int y = 0; y < width; y++)
93 {
94 for (int x = 0; x < width; x++)
95 {
96 if (x == width - 1)
97 {
98 ok(dstBuffer[y * width + x] == BLACK_PIXEL,
99 "Expected blank (black) pixel (0x0), got (%06X), coordinates (%d, %d). line: %d\n",
100 dstBuffer[y * width + x], x, y, line);
101 }
102 else
103 {
104 ok(dstBuffer[y * width + x] == srcBuffer[y * width + x + 1],
105 "Coordinates: (%d, %d), expected (%06X), got (%06X). line: %d\n",
106 x, y, srcBuffer[y * width + x + 1], dstBuffer[y * width + x], line);
107 }
108 }
109 }
110}
111
112#define WIDTH 10
114{
115 HBITMAP bmpDst, bmpSrc, oldDst, oldSrc;
117 PUINT32 dstBuffer, srcBuffer;
118 BITMAPINFO info = { 0 };
119 size_t nBuf = WIDTH * WIDTH * sizeof(UINT32);
120
124
125 info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
126 info.bmiHeader.biWidth = WIDTH;
127 info.bmiHeader.biHeight = -WIDTH;
128 info.bmiHeader.biPlanes = 1;
129 info.bmiHeader.biBitCount = 32;
130 info.bmiHeader.biCompression = BI_RGB;
131
132 /* Create bitmaps to test with */
133 bmpSrc = CreateDIBSection(hdcSrc, &info, DIB_RGB_COLORS, (PVOID*)&srcBuffer, NULL, 0);
134 bmpDst = CreateDIBSection(hdcDst, &info, DIB_RGB_COLORS, (PVOID*)&dstBuffer, NULL, 0);
135
136 if (!bmpSrc || !bmpDst)
137 {
138 skip("Failed to create bitmaps");
139 goto cleanup;
140 }
141
142 oldSrc = SelectObject(hdcSrc, bmpSrc);
143 oldDst = SelectObject(hdcDst, bmpDst);
144
145 /* Create base "image" for use in the tests */
146 copy(srcBuffer, WHITE_PIXEL, WIDTH, 0, 0, WIDTH / 2, WIDTH / 2);
147 copy(srcBuffer, BLUE_PIXEL, WIDTH, 0, WIDTH / 2, WIDTH / 2, WIDTH);
148 copy(srcBuffer, GREEN_PIXEL, WIDTH, WIDTH / 2, 0, WIDTH, WIDTH / 2);
149 copy(srcBuffer, RED_PIXEL, WIDTH, WIDTH / 2, WIDTH / 2, WIDTH, WIDTH);
150
151 /* Mirror destination DC */
153 ok(GetLayout(hdcDst) == LAYOUT_RTL, "DC layout is not RTL\n");
154 ok(GetMapMode(hdcDst) == MM_ANISOTROPIC, "DC Map mode is not MM_ANISOTROPIC\n");
155
156 /* Test RTL transform (using LPtoDP) and the inverse transform (DPtoLP) */
157 for (int y = 0; y < WIDTH; y++)
158 {
159 for (int x = 0; x < WIDTH; x++)
160 {
161 POINT pt = { x, y };
162 POINT mirrored = { WIDTH - 1 - x, y }; /* Expected results */
163
164 LPtoDP(hdcDst, &pt, 1);
165 /* Test LPtoDP */
166 ok(pt.x == mirrored.x && pt.y == mirrored.y,
167 "Coodinates: (%d, %d), expected (%ld, %ld), got (%ld, %ld)\n",
168 x, y, mirrored.x, mirrored.y, pt.x, pt.y);
169
170 pt = mirrored;
171
172 /* Test DPtoLP */
173 DPtoLP(hdcDst, &pt, 1);
174 ok(pt.x == x && pt.y == y,
175 "Mirrored Coodinates: (%ld, %ld), expected (%d, %d), got (%ld, %ld)\n",
176 mirrored.x, mirrored.y, x, y, pt.x, pt.y);
177 }
178 }
179
180 ZeroMemory(dstBuffer, nBuf);
182 for (int y = 0; y < WIDTH; y++)
183 {
184 for (int x = 0; x < WIDTH; x++)
185 {
186 /* Test if the image is mirrored using the assumed RTL transform results */
187 ok(dstBuffer[y * WIDTH + (WIDTH - 1 - x)] == srcBuffer[y * WIDTH + x],
188 "Coordinates: (%d, %d), expected (%06X), got (%06X)\n",
189 x, y, srcBuffer[y * WIDTH + x], dstBuffer[y * WIDTH + (WIDTH - 1 - x)]);
190 }
191 }
192
193 ZeroMemory(dstBuffer, nBuf);
195 nomirror_test(dstBuffer, srcBuffer, WIDTH, __LINE__);
196
197 ZeroMemory(dstBuffer, nBuf);
198 BitBlt(hdcDst, 0, 0, WIDTH, WIDTH, hdcSrc, 0, 0, SRCCOPY);
199 for (int y = 0; y < WIDTH; y++)
200 {
201 for (int x = 0; x < WIDTH; x++)
202 {
203 /* Test if the image is mirrored using the assumed RTL transform results */
204 ok(dstBuffer[y * WIDTH + (WIDTH - 1 - x)] == srcBuffer[y * WIDTH + x],
205 "Coordinates: (%d, %d), expected (%06X), got (%06X)\n",
206 x, y, srcBuffer[y * WIDTH + x], dstBuffer[y * WIDTH + (WIDTH - 1 - x)]);
207 }
208 }
209
210 ZeroMemory(dstBuffer, nBuf);
212 nomirror_test(dstBuffer, srcBuffer, WIDTH, __LINE__);
213
215
217 "DC Layout is not LAYOUT_RTL | LAYOUT_BITMAPORIENTATIONPRESERVED\n");
218 ok(GetMapMode(hdcDst) == MM_ANISOTROPIC, "DC Map mode is not MM_ANISOTROPIC\n");
219
220 ZeroMemory(dstBuffer, nBuf);
222 nomirror_test(dstBuffer, srcBuffer, WIDTH, __LINE__);
223
224 ZeroMemory(dstBuffer, nBuf);
226 nomirror_test(dstBuffer, srcBuffer, WIDTH, __LINE__);
227
228 ZeroMemory(dstBuffer, nBuf);
229 BitBlt(hdcDst, 0, 0, WIDTH, WIDTH, hdcSrc, 0, 0, SRCCOPY);
230 nomirror_test(dstBuffer, srcBuffer, WIDTH, __LINE__);
231
232 ZeroMemory(dstBuffer, nBuf);
234 nomirror_test(dstBuffer, srcBuffer, WIDTH, __LINE__);
235
236 /* Reset DC layout to default (LTR) */
238 ok(GetLayout(hdcDst) == LAYOUT_LTR, "DC layout is not LAYOUT_LTR");
239
240 for (int y = 0; y < WIDTH; y++)
241 {
242 for (int x = 0; x < WIDTH; x++)
243 {
244 POINT pt = { x, y };
245
246 LPtoDP(hdcDst, &pt, 1);
247 /* Confirm that RTL transform is not the current one */
248 ok(pt.x == x && pt.y == y,
249 "Expected (%d, %d) got (%ld, %ld)\n", x, y, pt.x, pt.y);
250 }
251 }
252
253 ZeroMemory(dstBuffer, nBuf);
255 ok(memcmp(dstBuffer, srcBuffer, nBuf) == 0, "Bitmaps are not identical\n");
256
258 ok(GetLayout(hdcDst) == LAYOUT_BITMAPORIENTATIONPRESERVED, "DC Layout is not LAYOUT_BITMAPORIENTATIONPRESERVED");
259
260 SelectObject(hdcSrc, oldSrc);
261 SelectObject(hdcDst, oldDst);
262 DeleteObject(bmpSrc);
263 DeleteObject(bmpDst);
264cleanup:
267 DeleteDC(hdc);
268}
unsigned int UINT32
#define WHITE_PIXEL
Definition: SetLayout.c:25
#define WIDTH
Definition: SetLayout.c:112
#define BLUE_PIXEL
Definition: SetLayout.c:22
static void copy(PUINT32 buffer, UINT32 value, int width, int start_x, int start_y, int end_x, int end_y)
Definition: SetLayout.c:12
#define RED_PIXEL
Definition: SetLayout.c:24
#define BLACK_PIXEL
Definition: SetLayout.c:21
#define GREEN_PIXEL
Definition: SetLayout.c:23
static void nomirror_test(PUINT32 dstBuffer, PUINT32 srcBuffer, int width, int line)
Definition: SetLayout.c:90
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
static int start_x
Definition: maze.c:118
static int start_y
Definition: maze.c:118
static int end_x
Definition: maze.c:118
static int end_y
Definition: maze.c:118
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
BOOL WINAPI SetConsoleTextAttribute(IN HANDLE hConsoleOutput, IN WORD wAttributes)
Definition: console.c:672
BOOL WINAPI GetConsoleScreenBufferInfo(IN HANDLE hConsoleOutput, OUT PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
Definition: console.c:595
unsigned int * PUINT32
Definition: basetsd.h:127
#define BACKGROUND_GREEN
Definition: blue.h:66
#define BACKGROUND_RED
Definition: blue.h:67
#define BACKGROUND_BLUE
Definition: blue.h:65
#define FOREGROUND_GREEN
Definition: blue.h:62
#define FOREGROUND_BLUE
Definition: blue.h:61
#define FOREGROUND_RED
Definition: blue.h:63
int putchar(int c)
Definition: crtsupp.c:12
#define NULL
Definition: types.h:112
static void cleanup(void)
Definition: main.c:1335
#define pt(x, y)
Definition: drawing.c:79
static VOID NTAPI BitBlt(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Width, _In_ ULONG Height, _In_reads_bytes_(Delta *Height) PUCHAR Buffer, _In_ ULONG BitsPerPixel, _In_ ULONG Delta)
Definition: common.c:49
#define BI_RGB
Definition: precomp.h:47
unsigned short WORD
Definition: ntddk_ex.h:93
#define printf
Definition: freeldr.h:94
pKey DeleteObject()
DWORD WINAPI GetLayout(_In_ HDC hdc)
Definition: coord.c:750
DWORD WINAPI SetLayout(_In_ HDC hdc, _In_ DWORD dwLayout)
Definition: coord.c:780
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLint GLint GLsizei width
Definition: gl.h:1546
GLuint buffer
Definition: glext.h:5915
const GLubyte * c
Definition: glext.h:8905
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define c
Definition: ke_i.h:80
HDC hdc
Definition: main.c:9
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:92
#define LAYOUT_LTR
Definition: dc.c:36
static void dump(const void *ptr, unsigned len)
Definition: msc.c:95
static char title[]
Definition: ps.c:92
Definition: parser.c:49
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
Definition: pdh_main.c:94
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:199
#define ZeroMemory
Definition: winbase.h:1670
#define STD_OUTPUT_HANDLE
Definition: winbase.h:268
#define NOMIRRORBITMAP
Definition: wingdi.h:1377
#define DIB_RGB_COLORS
Definition: wingdi.h:367
BOOL WINAPI DPtoLP(_In_ HDC hdc, _Inout_updates_(c) LPPOINT lppt, _In_ int c)
BOOL WINAPI LPtoDP(_In_ HDC hdc, _Inout_updates_(c) LPPOINT lppt, _In_ int c)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
#define MM_ANISOTROPIC
Definition: wingdi.h:867
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
BOOL WINAPI StretchBlt(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_opt_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD)
#define SRCCOPY
Definition: wingdi.h:333
#define LAYOUT_RTL
Definition: wingdi.h:1371
int WINAPI GetMapMode(_In_ HDC)
Definition: coord.c:114
BOOL WINAPI DeleteDC(_In_ HDC)
#define LAYOUT_BITMAPORIENTATIONPRESERVED
Definition: wingdi.h:1375
static HDC hdcSrc
Definition: xlate.c:32
static HDC hdcDst
Definition: xlate.c:32
const char * LPCSTR
Definition: xmlstorage.h:183