Skip to content

Commit 4746b1b

Browse files
committed
[GDITOOLS] Don't create duplicate DDBs
1 parent b84fa49 commit 4746b1b

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

‎modules/rostests/apitests/gditools/gditools.c‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,13 @@ GdiGetHandleUserData(
108108
#define FL_INVERT_COLORS 0x01
109109
#define FL_RED_BLUE 0x02
110110

111+
static
111112
BOOL
112113
InitPerBitDepth(
113114
_In_ ULONG cBitsPerPixel,
114115
_In_ ULONG cx,
115116
_In_ ULONG cy,
116-
_Out_ HBITMAP *phbmp,
117+
_Out_opt_ HBITMAP *phbmpDDB,
117118
_Out_ HDC *phdcDIB,
118119
_Out_ HBITMAP *phbmpDIB,
119120
_Out_ PVOID *ppvBits,
@@ -126,12 +127,15 @@ InitPerBitDepth(
126127
} bmiBuffer;
127128
LPBITMAPINFO pbmi = (LPBITMAPINFO)&bmiBuffer;
128129

129-
/* Create a bitmap */
130-
*phbmp = CreateBitmap(cx, cy, 1, cBitsPerPixel, NULL);
131-
if (*phbmp == NULL)
130+
if (phbmpDDB != NULL)
132131
{
133-
printf("CreateBitmap failed %lu\n", cBitsPerPixel);
134-
return FALSE;
132+
/* Create a bitmap */
133+
*phbmpDDB = CreateBitmap(cx, cy, 1, cBitsPerPixel, NULL);
134+
if (*phbmpDDB == NULL)
135+
{
136+
printf("CreateBitmap failed %lu\n", cBitsPerPixel);
137+
return FALSE;
138+
}
135139
}
136140

137141
/* Setup bitmap info */
@@ -184,14 +188,17 @@ InitPerBitDepth(
184188
return FALSE;
185189
}
186190

187-
SelectObject(*phdcDIB, *phbmpDIB);
191+
if (SelectObject(*phdcDIB, *phbmpDIB) == NULL)
192+
{
193+
printf("SelectObject failed for %lu bpp DIB\n", cBitsPerPixel);
194+
return FALSE;
195+
}
188196

189197
return TRUE;
190198
}
191199

192200
BOOL GdiToolsInit(void)
193201
{
194-
195202
/* Initialize a logical palette */
196203
ghpal = CreatePalette((LOGPALETTE*)&gpal);
197204
if (!ghpal)
@@ -201,8 +208,8 @@ BOOL GdiToolsInit(void)
201208
}
202209

203210
if (!InitPerBitDepth(1, 9, 9, &ghbmp1, &ghdcDIB1, &ghbmpDIB1, &gpvDIB1, 0) ||
204-
!InitPerBitDepth(1, 9, 9, &ghbmp1_InvCol, &ghdcDIB1_InvCol, &ghbmpDIB1_InvCol, &gpvDIB1_InvCol, FL_INVERT_COLORS) ||
205-
!InitPerBitDepth(1, 9, 9, &ghbmp1_RB, &ghdcDIB1_RB, &ghbmpDIB1_RB, &gpvDIB1_RB, FL_RED_BLUE) ||
211+
!InitPerBitDepth(1, 9, 9, NULL, &ghdcDIB1_InvCol, &ghbmpDIB1_InvCol, &gpvDIB1_InvCol, FL_INVERT_COLORS) ||
212+
!InitPerBitDepth(1, 9, 9, NULL, &ghdcDIB1_RB, &ghbmpDIB1_RB, &gpvDIB1_RB, FL_RED_BLUE) ||
206213
!InitPerBitDepth(4, 5, 5, &ghbmp4, &ghdcDIB4, &ghbmpDIB4, &gpvDIB4, 0) ||
207214
!InitPerBitDepth(8, 5, 5, &ghbmp8, &ghdcDIB8, &ghbmpDIB8, &gpvDIB8, 0) ||
208215
!InitPerBitDepth(16, 8, 8, &ghbmp16, &ghdcDIB16, &ghbmpDIB16, &gpvDIB16, 0) ||

0 commit comments

Comments
 (0)