From a2631ae1d283481c5b1509876cef202d66f41a52 Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Thu, 3 Mar 2011 14:57:19 -0600 Subject: [PATCH] gdiplus: Add tests for interpolation mode and make them pass. --- dlls/gdiplus/graphics.c | 12 ++++-- dlls/gdiplus/tests/graphics.c | 70 +++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 3 deletions(-) diff --git a/dlls/gdiplus/graphics.c b/dlls/gdiplus/graphics.c index e9412c81246..4827bb0e1dd 100644 --- a/dlls/gdiplus/graphics.c +++ b/dlls/gdiplus/graphics.c @@ -1364,7 +1364,7 @@ GpStatus WINGDIPAPI GdipCreateFromHDC2(HDC hdc, HANDLE hDevice, GpGraphics **gra (*graphics)->owndc = FALSE; (*graphics)->smoothing = SmoothingModeDefault; (*graphics)->compqual = CompositingQualityDefault; - (*graphics)->interpolation = InterpolationModeDefault; + (*graphics)->interpolation = InterpolationModeBilinear; (*graphics)->pixeloffset = PixelOffsetModeDefault; (*graphics)->compmode = CompositingModeSourceOver; (*graphics)->unit = UnitDisplay; @@ -1403,7 +1403,7 @@ GpStatus graphics_from_image(GpImage *image, GpGraphics **graphics) (*graphics)->image = image; (*graphics)->smoothing = SmoothingModeDefault; (*graphics)->compqual = CompositingQualityDefault; - (*graphics)->interpolation = InterpolationModeDefault; + (*graphics)->interpolation = InterpolationModeBilinear; (*graphics)->pixeloffset = PixelOffsetModeDefault; (*graphics)->compmode = CompositingModeSourceOver; (*graphics)->unit = UnitDisplay; @@ -4638,12 +4638,18 @@ GpStatus WINGDIPAPI GdipSetInterpolationMode(GpGraphics *graphics, { TRACE("(%p, %d)\n", graphics, mode); - if(!graphics) + if(!graphics || mode == InterpolationModeInvalid || mode > InterpolationModeHighQualityBicubic) return InvalidParameter; if(graphics->busy) return ObjectBusy; + if (mode == InterpolationModeDefault || mode == InterpolationModeLowQuality) + mode = InterpolationModeBilinear; + + if (mode == InterpolationModeHighQuality) + mode = InterpolationModeHighQualityBicubic; + graphics->interpolation = mode; return Ok; diff --git a/dlls/gdiplus/tests/graphics.c b/dlls/gdiplus/tests/graphics.c index 275c237149a..ecdbe935cb4 100644 --- a/dlls/gdiplus/tests/graphics.c +++ b/dlls/gdiplus/tests/graphics.c @@ -3012,6 +3012,75 @@ static void test_string_functions(void) ReleaseDC(hwnd, hdc); } +static void test_get_set_interpolation(void) +{ + GpGraphics *graphics; + HDC hdc = GetDC( hwnd ); + GpStatus status; + InterpolationMode mode; + + ok(hdc != NULL, "Expected HDC to be initialized\n"); + status = GdipCreateFromHDC(hdc, &graphics); + expect(Ok, status); + ok(graphics != NULL, "Expected graphics to be initialized\n"); + + status = GdipGetInterpolationMode(NULL, &mode); + expect(InvalidParameter, status); + + if (0) + { + /* Crashes on Windows XP */ + status = GdipGetInterpolationMode(graphics, NULL); + expect(InvalidParameter, status); + } + + status = GdipSetInterpolationMode(NULL, InterpolationModeNearestNeighbor); + expect(InvalidParameter, status); + + /* out of range */ + status = GdipSetInterpolationMode(graphics, InterpolationModeHighQualityBicubic+1); + expect(InvalidParameter, status); + + status = GdipSetInterpolationMode(graphics, InterpolationModeInvalid); + expect(InvalidParameter, status); + + status = GdipGetInterpolationMode(graphics, &mode); + expect(Ok, status); + expect(InterpolationModeBilinear, mode); + + status = GdipSetInterpolationMode(graphics, InterpolationModeNearestNeighbor); + expect(Ok, status); + + status = GdipGetInterpolationMode(graphics, &mode); + expect(Ok, status); + expect(InterpolationModeNearestNeighbor, mode); + + status = GdipSetInterpolationMode(graphics, InterpolationModeDefault); + expect(Ok, status); + + status = GdipGetInterpolationMode(graphics, &mode); + expect(Ok, status); + expect(InterpolationModeBilinear, mode); + + status = GdipSetInterpolationMode(graphics, InterpolationModeLowQuality); + expect(Ok, status); + + status = GdipGetInterpolationMode(graphics, &mode); + expect(Ok, status); + expect(InterpolationModeBilinear, mode); + + status = GdipSetInterpolationMode(graphics, InterpolationModeHighQuality); + expect(Ok, status); + + status = GdipGetInterpolationMode(graphics, &mode); + expect(Ok, status); + expect(InterpolationModeHighQualityBicubic, mode); + + GdipDeleteGraphics(graphics); + + ReleaseDC(hwnd, hdc); +} + START_TEST(graphics) { struct GdiplusStartupInput gdiplusStartupInput; @@ -3070,6 +3139,7 @@ START_TEST(graphics) test_textcontrast(); test_fromMemoryBitmap(); test_string_functions(); + test_get_set_interpolation(); GdiplusShutdown(gdiplusToken); DestroyWindow( hwnd );