[4/5] gdiplus: Add drawing tests for GdipFillRegion with gdi transform.

Vincent Povirk vincent at codeweavers.com
Wed Aug 30 12:32:16 CDT 2017


From: Changhui Liu <liuchanghui at linuxdeepin.com>

Signed-off-by: Vincent Povirk <vincent at codeweavers.com>
---
 dlls/gdiplus/tests/graphics.c | 245 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 245 insertions(+)

diff --git a/dlls/gdiplus/tests/graphics.c b/dlls/gdiplus/tests/graphics.c
index 540fdfd..5f45cc2 100644
--- a/dlls/gdiplus/tests/graphics.c
+++ b/dlls/gdiplus/tests/graphics.c
@@ -6287,6 +6287,248 @@ static void test_GdipFillRectanglesOnMemoryDCSolidBrush(void)
     ReleaseDC(hwnd, dc);
 }
 
+static void test_GdipFillRectanglesOnMemoryDCTextureBrush(void)
+{
+    ARGB color[6] = {0,0,0,0,0,0};
+    POINT pt = {0,0};
+    RECT rect = {100, 100, 180, 180};
+    UINT width = rect.right - rect.left;
+    UINT height = rect.bottom - rect.top;
+    GpStatus status = 0;
+    union
+    {
+        GpBitmap *bitmap;
+        GpImage *image;
+    } src_img;
+    GpTexture *brush = NULL;
+    GpGraphics *graphics = NULL;
+    HDC dc = GetDC( hwnd);
+    HDC hdc = CreateCompatibleDC(dc);
+    HBITMAP bmp = CreateCompatibleBitmap(dc, width, height);
+    HGDIOBJ old = SelectObject(hdc, bmp);
+
+    UINT x = 0;
+    UINT y = 0;
+    UINT src_img_width = width/2;
+    UINT src_img_height = height/2;
+    BYTE *src_img_data = GdipAlloc(src_img_width*src_img_height*4);
+    DWORD *pixel = (DWORD *)src_img_data;
+    ok(pixel != NULL, "Expected src_img_data is valid\n");
+
+    /*Change the window origin is the key test point*/
+    SetWindowOrgEx(hdc, rect.left, rect.top, &pt);
+
+    /*build a blue solid image!*/
+    for(y = 0; y < src_img_height; ++y)
+    {
+        for(x = 0; x < src_img_width; ++x)
+        {
+            pixel[x] = BLUE_COLOR;
+        }
+
+        pixel += src_img_width;
+    }
+
+    status = GdipCreateBitmapFromScan0(src_img_width, src_img_height, src_img_width*4,
+            PixelFormat32bppARGB, src_img_data, &src_img.bitmap);
+    expect(Ok, status);
+
+    status = GdipCreateTexture(src_img.image, 0, &brush);
+    expect(Ok, status);
+
+    status = GdipCreateFromHDC(hdc, &graphics);
+    expect(Ok, status);
+
+    status = GdipSetClipRectI(graphics, rect.left+width/2, rect.top+height/2,
+            width, height, CombineModeReplace);
+    expect(Ok, status);
+
+    status = GdipFillRectangleI(graphics, (GpBrush*)brush, 0, 0, rect.right, rect.bottom);
+    expect(Ok, status);
+
+    GdipDisposeImage(src_img.image);
+    GdipDeleteBrush((GpBrush*)brush);
+    GdipDeleteGraphics(graphics);
+    GdipFree(src_img_data);
+
+    pixel = GetBitmapPixelBuffer(hdc, bmp, width, height);
+    if (pixel)
+    {
+       color[0] = get_bitmap_pixel(width/2, height/2);
+       color[1] = get_bitmap_pixel(width/2+1, height/2);
+       color[2] = get_bitmap_pixel(width/2, height/2+1);
+       color[3] = get_bitmap_pixel(width/2-1, height/2-1);
+       color[4] = get_bitmap_pixel(width/2-1, height-1);
+       color[5] = get_bitmap_pixel(width-1, height/2-1);
+    }
+    todo_wine ok(is_blue_color(color[0]) && is_blue_color(color[1]) && is_blue_color(color[2]) &&
+       color[3] == 0 && color[4] == 0 && color[5] == 0,
+      "Expected GdipFillRectangleI take effect!\n" );
+    ReleaseBitmapPixelBuffer(pixel);
+
+    SelectObject(hdc, old);
+    DeleteObject(bmp);
+    DeleteDC(hdc);
+    ReleaseDC(hwnd, dc);
+}
+
+static void test_GdipFillRectanglesOnBitmapTextureBrush(void)
+{
+    ARGB color[6] = {0,0,0,0,0,0};
+    UINT x = 0;
+    UINT y = 0;
+    RECT rect = {100, 100, 180, 180};
+    UINT width = rect.right - rect.left;
+    UINT height = rect.bottom - rect.top;
+    UINT src_img_width = width/2;
+    UINT src_img_height = height/2;
+
+    GpStatus status = 0;
+    union
+    {
+        GpBitmap *bitmap;
+        GpImage *image;
+    } src_img;
+    union
+    {
+        GpBitmap *bitmap;
+        GpImage *image;
+    } dst_img;
+
+    GpTexture *brush = NULL;
+    GpGraphics *graphics = NULL;
+    BYTE *src_img_data = GdipAlloc(src_img_width*src_img_height*4);
+    DWORD *pixel = (DWORD *)src_img_data;
+    ok(pixel != NULL, "Expected src_img_data is valid\n");
+
+    status = GdipCreateBitmapFromScan0(width, height, width*4,
+            PixelFormat32bppARGB, NULL, &dst_img.bitmap);
+    expect(Ok, status);
+
+    /*build a blue solid image!*/
+    for(y = 0; y < src_img_height; ++y)
+    {
+        for(x = 0; x < src_img_width; ++x)
+        {
+            pixel[x] = BLUE_COLOR;
+        }
+
+        pixel += src_img_width;
+    }
+
+    status = GdipCreateBitmapFromScan0(src_img_width, src_img_height, src_img_width*4,
+            PixelFormat32bppARGB, src_img_data, &src_img.bitmap);
+    expect(Ok, status);
+
+    status = GdipCreateTexture(src_img.image, 0, &brush);
+    expect(Ok, status);
+
+    status = GdipGetImageGraphicsContext(dst_img.image, &graphics);
+    expect(Ok, status);
+
+    status = GdipSetClipRectI(graphics, 0, 0, width, height, CombineModeReplace);
+    expect(Ok, status);
+
+    status = GdipFillRectangleI(graphics, (GpBrush*)brush, 0, 0, width/2, height/2);
+    expect(Ok, status);
+
+    GdipDeleteBrush((GpBrush*)brush);
+    GdipDeleteGraphics(graphics);
+
+    GdipBitmapGetPixel(dst_img.bitmap, 0, 0, &color[0]);
+    GdipBitmapGetPixel(dst_img.bitmap, 0, 1, &color[1]);
+    GdipBitmapGetPixel(dst_img.bitmap, 1, 0, &color[2]);
+    GdipBitmapGetPixel(dst_img.bitmap, width/2, 0, &color[3]);
+    GdipBitmapGetPixel(dst_img.bitmap, width/2, height/2, &color[4]);
+    GdipBitmapGetPixel(dst_img.bitmap, 0, height/2, &color[5]);
+
+    ok(is_blue_color(color[0]) && is_blue_color(color[1]) && is_blue_color(color[2]) &&
+       color[3] == 0 && color[4] == 0 && color[5] == 0,
+       "Expected GdipFillRectangleI take effect!\n" );
+
+    GdipDisposeImage(src_img.image);
+    GdipDisposeImage(dst_img.image);
+    GdipFree(src_img_data);
+}
+
+static void test_GdipDrawImagePointsRectOnMemoryDC(void)
+{
+    ARGB color[6] = {0,0,0,0,0,0};
+    POINT pt = {0,0};
+    RECT rect = {100, 100, 180, 180};
+    UINT width = rect.right - rect.left;
+    UINT height = rect.bottom - rect.top;
+    GpStatus status = 0;
+    union
+    {
+        GpBitmap *bitmap;
+        GpImage *image;
+    } src_img;
+    GpGraphics *graphics = NULL;
+    HDC dc = GetDC( hwnd);
+    HDC hdc = CreateCompatibleDC(dc);
+    HBITMAP bmp = CreateCompatibleBitmap(dc, width, height);
+    HGDIOBJ old = SelectObject(hdc, bmp);
+
+    UINT x = 0;
+    UINT y = 0;
+    UINT src_img_width = width/2;
+    UINT src_img_height = height/2;
+    BYTE *src_img_data = GdipAlloc(src_img_width*src_img_height*4);
+    DWORD *pixel = (DWORD *)src_img_data;
+    ok(pixel != NULL, "Expected src_img_data is valid\n");
+
+    /*Change the window origin is the key test point*/
+    SetWindowOrgEx(hdc, rect.left, rect.top, &pt);
+
+    /*build a blue solid image!*/
+    for(y = 0; y < src_img_height; ++y)
+    {
+        for(x = 0; x < src_img_width; ++x)
+        {
+            pixel[x] = BLUE_COLOR;
+        }
+
+        pixel += src_img_width;
+    }
+
+    status = GdipCreateBitmapFromScan0(src_img_width, src_img_height, src_img_width*4,
+            PixelFormat32bppARGB, src_img_data, &src_img.bitmap);
+    expect(Ok, status);
+
+    status = GdipCreateFromHDC(hdc, &graphics);
+    expect(Ok, status);
+
+    status = GdipDrawImageRectRectI(graphics, src_img.image,
+            rect.left+width/2, rect.top+height/2, width/2, height/2,
+            0, 0, src_img_width, src_img_height, UnitPixel, NULL, NULL, NULL);
+    expect(Ok, status);
+
+    GdipDisposeImage(src_img.image);
+    GdipDeleteGraphics(graphics);
+    GdipFree(src_img_data);
+
+    pixel = GetBitmapPixelBuffer(hdc, bmp, width, height);
+    if (pixel)
+    {
+       color[0] = get_bitmap_pixel(width/2, height/2);
+       color[1] = get_bitmap_pixel(width/2+1, height/2);
+       color[2] = get_bitmap_pixel(width/2, height/2+1);
+       color[3] = get_bitmap_pixel(width/2-1, height/2-1);
+       color[4] = get_bitmap_pixel(width/2-1, height-1);
+       color[5] = get_bitmap_pixel(width-1, height/2-1);
+    }
+    ok(is_blue_color(color[0]) && is_blue_color(color[1]) && is_blue_color(color[2]) &&
+       color[3] == 0 && color[4] == 0 && color[5] == 0,
+       "Expected GdipDrawImageRectRectI take effect!\n" );
+    ReleaseBitmapPixelBuffer(pixel);
+
+    SelectObject(hdc, old);
+    DeleteObject(bmp);
+    DeleteDC(hdc);
+    ReleaseDC(hwnd, dc);
+}
+
 START_TEST(graphics)
 {
     struct GdiplusStartupInput gdiplusStartupInput;
@@ -6371,6 +6613,9 @@ START_TEST(graphics)
     test_GdipFillRectangles();
     test_GdipGetVisibleClipBounds_memoryDC();
     test_GdipFillRectanglesOnMemoryDCSolidBrush();
+    test_GdipFillRectanglesOnMemoryDCTextureBrush();
+    test_GdipFillRectanglesOnBitmapTextureBrush();
+    test_GdipDrawImagePointsRectOnMemoryDC();
     test_container_rects();
     test_GdipGraphicsSetAbort();
 
-- 
2.7.4




More information about the wine-patches mailing list