Request for feedback: gdi32/tests antialiasing patch
Glenn Wurster
gwurster at scs.carleton.ca
Wed Sep 17 09:32:13 CDT 2008
Last Thursday I submitted a patch which was silently dropped. I'd be
interested if someone could take a look at it and let me know what I'm
missing plase. I've included the original patch e-mail for reference.
The patch was tested on XP, 98, and Wine. I also ran it through
valgrind and it passed patchwatcher without any errors. I've had the
conformance test sitting around for a while and believe it's best put in
the wine source tree (especially as a conformance test for the new DIB
engine). It's a conformance test for a bug I fixed years ago in the
Wine source tree:
* http://www.winehq.org/pipermail/wine-cvs/2005-January/013584.html
* http://www.winehq.org/pipermail/wine-cvs/2005-January/013623.html
Thanks for any assistance anyone may be able to provide.
Glenn.
On Thu, Sep 11, 2008 at 02:59:46PM -0400, Glenn Wurster wrote:
>
> Changelog:
> gdi32/tests: Add font antialiasing tests
>
> Add tests to ensure that antialiasing is not used even if requested
> when we are operating in a palette drawing mode, and that antialiasing
> is used when operating in a non-palette mode.
>
> Changes since attempt 1:
> * Clear the bitmap before we write the text to it.
> * Document in this e-mail tests performed.
>
> Tested on XP (sp2), 98, and Wine, also run through Valgrind (did this on
> the initial patch as well but forgot to mention that in the e-mail).
>
> Glenn Wurster.
>
> ---
> dlls/gdi32/tests/font.c | 163 +++++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 163 insertions(+), 0 deletions(-)
> diff --git a/dlls/gdi32/tests/font.c b/dlls/gdi32/tests/font.c
> index 7d2c036..088d4e6 100644
> --- a/dlls/gdi32/tests/font.c
> +++ b/dlls/gdi32/tests/font.c
> @@ -2430,6 +2430,168 @@ static void test_orientation(void)
> DeleteDC(hdc);
> }
>
> +static void clear_bmp(HDC hdc, int width, int height, COLORREF colour)
> +{
> + HBRUSH hbrush, hbrush_old;
> + HPEN hpen, hpen_old;
> +
> + hbrush = CreateSolidBrush(colour);
> + ok(hbrush != NULL, "CreateSolidBrush failed.\n");
> +
> + hpen = CreatePen(PS_SOLID, 0, colour);
> + ok(hpen != NULL, "CreatePen failed.\n");
> +
> + hpen_old = SelectObject( hdc, hpen );
> + hbrush_old = SelectObject( hdc, hbrush );
> + ok(hpen_old != NULL, "SelectObject failed.\n");
> + ok(hbrush_old != NULL, "SelectObject failed.\n");
> +
> + ok(Rectangle(hdc, 0, 0, width, height), "Rectangle failed.\n");
> +
> + SelectObject(hdc, hbrush_old);
> + DeleteObject(hbrush);
> + SelectObject(hdc, hpen_old);
> + DeleteObject(hpen);
> +}
> +
> +static COLORREF check_bmp_colors(HDC hdc, COLORREF * colours, int colorCnt, int width, int height)
> +{
> + COLORREF pixel;
> + int x, y, z;
> + for(y = 0; y < height; y++)
> + {
> + for(x = 0; x < width; x++)
> + {
> + pixel = GetPixel(hdc, x, y);
> + for(z = 0; z < colorCnt; z++)
> + {
> + if(pixel == colours[z])
> + break;
> + }
> + if(z >= colorCnt)
> + {
> + return pixel;
> + }
> + }
> + }
> + return 0;
> +}
> +
> +static void test_antialias(void)
> +{
> + PALETTEENTRY paletteEntries[3] = {
> + { 0x00, 0x00, 0x00, PC_NOCOLLAPSE },
> + { 0xFF, 0xFF, 0xFF, PC_NOCOLLAPSE },
> + { 0x44, 0x44, 0x44, PC_NOCOLLAPSE }
> + };
> + HDC hdc;
> + HFONT hfont, old_hfont;
> + HPALETTE hpal, old_hpal;
> + LOGPALETTE * lpal;
> + HBITMAP hbmp, old_hbmp;
> + BITMAPINFO * bmi;
> + COLORREF colours[3];
> + int cntr;
> + COLORREF pixel;
> +
> + hdc = CreateCompatibleDC(0);
> +
> + /* Create an antialiased font. We don't really care what the specific font is */
> + hfont = CreateFont(32, 0, 0, 0, FW_REGULAR, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, NULL);
> + old_hfont = SelectObject(hdc, hfont);
> + ok(old_hfont != NULL, "SelectObject failed.\n");
> +
> + /* Set up a palette */
> + lpal = (LOGPALETTE *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LOGPALETTE) + 3*sizeof(PALETTEENTRY));
> + lpal->palNumEntries = 3;
> + lpal->palVersion = 0x0300;
> + lpal->palPalEntry[0] = paletteEntries[0];
> + lpal->palPalEntry[1] = paletteEntries[1];
> + lpal->palPalEntry[2] = paletteEntries[2];
> + hpal = CreatePalette(lpal);
> + HeapFree(GetProcessHeap(), 0, lpal);
> + old_hpal = SelectPalette(hdc, hpal, FALSE);
> + ok(old_hpal != NULL, "SelectPalette failed.\n");
> +
> + /* Create an 8bit bitmap to draw into */
> + bmi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFO) + 3 * sizeof(RGBQUAD));
> + bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
> + bmi->bmiHeader.biWidth = 20;
> + bmi->bmiHeader.biHeight = -20;
> + bmi->bmiHeader.biPlanes = 1;
> + bmi->bmiHeader.biBitCount = 8;
> + bmi->bmiHeader.biCompression = BI_RGB;
> + bmi->bmiHeader.biClrUsed = 3;
> + for(cntr = 0; cntr < 3; cntr++)
> + {
> + bmi->bmiColors[cntr].rgbRed = paletteEntries[cntr].peRed;
> + bmi->bmiColors[cntr].rgbGreen = paletteEntries[cntr].peGreen;
> + bmi->bmiColors[cntr].rgbBlue = paletteEntries[cntr].peBlue;
> + bmi->bmiColors[cntr].rgbReserved = 0;
> + colours[cntr] = RGB(paletteEntries[cntr].peRed, paletteEntries[cntr].peGreen, paletteEntries[cntr].peBlue);
> + }
> +
> + hbmp = CreateDIBSection(hdc, bmi, DIB_RGB_COLORS, 0, 0, 0);
> + ok(hbmp != NULL, "error=%d\n", GetLastError());
> + old_hbmp = SelectObject(hdc, hbmp);
> + ok(old_hbmp != NULL, "error=%d\n", GetLastError());
> +
> + HeapFree(GetProcessHeap(), 0, bmi);
> +
> + /* Set up the text colours */
> + SetTextColor(hdc, RGB(0xFF, 0xFF, 0xFF));
> + SetBkColor(hdc, RGB(0, 0, 0));
> + SetBkMode(hdc, OPAQUE);
> +
> + /* Draw an 'O' offset to see if antialiasing was
> + * used. Antialiasing should be restricted to colours in the
> + * palette (if it is done at all). */
> + clear_bmp(hdc, 20, 20, RGB(0, 0, 0));
> + ok(ExtTextOut(hdc, 0, -4, 0, NULL, "O", 1, NULL), "ExtTextOut failed.\n");
> + pixel = check_bmp_colors(hdc, colours, 3, 20, 20);
> + ok(pixel == 0, "Found invalid pixel: %x.\n", pixel);
> +
> + /* Cleanup the palette stuff */
> + SelectPalette(hdc, old_hpal, FALSE);
> + DeleteObject(hpal);
> + SelectObject(hdc, old_hbmp);
> + DeleteObject(hbmp);
> +
> + /* Create an RGB bitmap to draw into */
> + bmi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFO));
> + bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
> + bmi->bmiHeader.biWidth = 20;
> + bmi->bmiHeader.biHeight = -20;
> + bmi->bmiHeader.biPlanes = 1;
> + bmi->bmiHeader.biBitCount = 32;
> + bmi->bmiHeader.biCompression = BI_RGB;
> + bmi->bmiHeader.biClrUsed = 0;
> +
> + hbmp = CreateDIBSection(hdc, bmi, DIB_RGB_COLORS, 0, 0, 0);
> + ok(hbmp != NULL, "error=%d\n", GetLastError());
> + old_hbmp = SelectObject(hdc, hbmp);
> + ok(old_hbmp != NULL, "error=%d\n", GetLastError());
> +
> + HeapFree(GetProcessHeap(), 0, bmi);
> +
> + /* Draw an 'O' offset to see if antialiasing was used.
> + * Antialiasing should be used when we specify an antialiasing
> + * font and use a RGB bitmap. */
> + clear_bmp(hdc, 20, 20, RGB(0, 0, 0));
> + ok(ExtTextOut(hdc, 0, -4, 0, NULL, "O", 1, NULL), "ExtTextOut failed.\n");
> + pixel = check_bmp_colors(hdc, colours, 2, 20, 20);
> + ok(pixel != 0, "Antialiasing was not used.\n");
> +
> + /* Free the bitmap */
> + SelectObject(hdc, old_hbmp);
> + DeleteObject(hbmp);
> +
> + /* Free the rest of our memory */
> + SelectObject(hdc, old_hfont);
> + DeleteObject(hfont);
> + DeleteDC(hdc);
> +}
> +
> START_TEST(font)
> {
> init();
> @@ -2449,6 +2611,7 @@ START_TEST(font)
> test_GetFontUnicodeRanges();
> test_nonexistent_font();
> test_orientation();
> + test_antialias();
>
> /* On Windows Arial has a lot of default charset aliases such as Arial Cyr,
> * I'd like to avoid them in this test.
>
More information about the wine-devel
mailing list