From: "刘昌辉" Subject: gdiplus:GdipDrawImagePointsRect has a nosie vertical line output after resampled Message-Id: Date: Fri, 21 Nov 2014 22:32:28 +0800

From c854caca630cce9a894a1176a89538c3fd304518 Mon Sep 17 00:00:00 2001 From: Liu Changhui Date: Fri, 21 Nov 2014 22:17:58 +0800 Subject: gdiplus:GdipDrawImagePointsRect has a nosie vertical line output after resampled To: wine-patches Reply-To: wine-devel --- dlls/gdiplus/graphics.c | 9 ++--- dlls/gdiplus/tests/graphics.c | 84 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 4 deletions(-) diff --git a/dlls/gdiplus/graphics.c b/dlls/gdiplus/graphics.c index 840d866..2be9cd4 100644 --- a/dlls/gdiplus/graphics.c +++ b/dlls/gdiplus/graphics.c @@ -3038,11 +3038,12 @@ GpStatus WINGDIPAPI GdipDrawImagePointsRect(GpGraphics *graphics, GpImage *image dst_color = (ARGB*)(dst_data + dst_stride * (y - dst_area.top) + sizeof(ARGB) * (x - dst_area.left)); - if (src_pointf.X >= srcx && src_pointf.X < srcx + srcwidth && src_pointf.Y >= srcy && src_pointf.Y < srcy+srcheight) - *dst_color = resample_bitmap_pixel(&src_area, src_data, bitmap->width, bitmap->height, &src_pointf, + if ( src_pointf.X < srcx ) src_pointf.X = srcx; + if ( src_pointf.X >= srcx + srcwidth ) src_pointf.X = srcx + srcwidth - 1.0f; + if ( src_pointf.Y < srcy ) src_pointf.Y = srcy; + if ( src_pointf.Y >= srcy+srcheight ) src_pointf.Y = srcy + srcheight - 1.0f; + *dst_color = resample_bitmap_pixel(&src_area, src_data, bitmap->width, bitmap->height, &src_pointf, imageAttributes, interpolation, offset_mode); - else - *dst_color = 0; } } } diff --git a/dlls/gdiplus/tests/graphics.c b/dlls/gdiplus/tests/graphics.c index bd227dc..725f4ee 100644 --- a/dlls/gdiplus/tests/graphics.c +++ b/dlls/gdiplus/tests/graphics.c @@ -5548,6 +5548,89 @@ static void test_GdipFillRectangles(void) ReleaseDC(hwnd, hdc); } +static void test_GdipDrawImagePointsRectNeedResample (void) +{ + Rect src_rect = {6, 0, 48, 26}; + Rect dest_rect = {699, 0, 58, 23}; + int src_img_width = src_rect.X + src_rect.Width; + int src_img_height = src_rect.Height; + int dest_img_width = dest_rect.X + dest_rect.Width; + int dest_img_height = dest_rect.Height; + BYTE* src_img_data = malloc (src_img_width*src_img_height*4); + BYTE* dest_img_data = malloc (dest_img_width*dest_img_height*4); + union + { + GpBitmap *bitmap; + GpImage *image; + } src_img; + union + { + GpBitmap *bitmap; + GpImage *image; + }dest_img; + GpStatus status; + GpGraphics *graphics = NULL; + DWORD value = 0; + + ok (src_img_data != NULL, "Expected src_img_data is valid\n"); + ok (dest_img_data != NULL, "Expected dest_img_data is valid\n"); + + /*white image*/ + memset (src_img_data, 0xff, src_img_width*src_img_height*4); + /*black image*/ + memset (dest_img_data, 0, dest_img_width*dest_img_height*4); + + status = GdipCreateBitmapFromScan0 (src_img_width, src_img_height, src_img_width*4, + PixelFormat32bppRGB, src_img_data, &src_img.bitmap); + expect (Ok, status); + + status = GdipCreateBitmapFromScan0 (dest_img_width, dest_img_height, dest_img_width*4, + PixelFormat32bppRGB, dest_img_data, &dest_img.bitmap); + expect (Ok, status); + + status = GdipGetImageGraphicsContext (dest_img.image, &graphics); + expect(Ok, status); + ok(graphics != NULL, "Expected graphics to be initialized\n"); + + status = GdipDrawImageRectRectI (graphics, src_img.image, + dest_rect.X, dest_rect.Y, dest_rect.Width, dest_rect.Height, + src_rect.X, src_rect.Y, src_rect.Width, src_rect.Height, + UnitPixel, NULL, NULL, NULL ); + expect(Ok, status); + + GdipDeleteGraphics (graphics); + + /*first line*/ + value = *( (DWORD*)dest_img_data + dest_rect.X) ; + /*printf ("pixel(%d,%d) = %08x\n", dest_rect.X, 0, value );*/ + ok ( value > 0, + "dest image color should same as src image color\n"); + + /*second line*/ + value = *( (DWORD*)dest_img_data + dest_img_width + dest_rect.X) ; + /*printf ("pixel(%d,%d) = %08x\n", dest_rect.X, 1, value );*/ + ok ( value > 0, + "dest image color should same as src image color\n"); + + /*last second line*/ + value = *( (DWORD*)dest_img_data + dest_img_width*(dest_img_height-2) + dest_rect.X); + /*printf ("pixel(%d,%d) = %08x\n", dest_rect.X, dest_img_height-2, value );*/ + ok ( value > 0, + "dest image color should same as src image color\n"); + + /*last line*/ + value = *( (DWORD*)dest_img_data + dest_img_width*(dest_img_height-1) + dest_rect.X); + /*printf ("pixel(%d,%d) = %08x\n", dest_rect.X, dest_img_height-1, value );*/ + ok ( value > 0, + "dest image color should same as src image color\n"); + + GdipDisposeImage (src_img.image); + GdipDisposeImage (dest_img.image); + free (src_img_data); + free (dest_img_data); +} + + START_TEST(graphics) { struct GdiplusStartupInput gdiplusStartupInput; @@ -5619,6 +5702,7 @@ START_TEST(graphics) test_alpha_hdc(); test_bitmapfromgraphics(); test_GdipFillRectangles(); + test_GdipDrawImagePointsRectNeedResample (); GdiplusShutdown(gdiplusToken); DestroyWindow( hwnd ); -- 1.9.1