[1/4] gdiplus: Add a test for GdipDrawImage scaling.
Dmitry Timoshkov
dmitry at baikal.ru
Tue Aug 7 22:36:52 CDT 2012
---
dlls/gdiplus/tests/image.c | 129 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 129 insertions(+)
diff --git a/dlls/gdiplus/tests/image.c b/dlls/gdiplus/tests/image.c
index 0595cc2..fbcb969 100644
--- a/dlls/gdiplus/tests/image.c
+++ b/dlls/gdiplus/tests/image.c
@@ -2,6 +2,7 @@
* Unit test suite for images
*
* Copyright (C) 2007 Google (Evan Stade)
+ * Copyright (C) 2012 Dmitry Timoshkov
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -3607,6 +3608,132 @@ static void test_bitmapbits(void)
}
}
+static void test_DrawImage(void)
+{
+ BYTE black_1x1[4] = { 0,0,0,0 };
+ BYTE white_2x2[16] = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff };
+ BYTE black_2x2[16] = { 0,0,0,0,0,0,0xff,0xff,
+ 0,0,0,0,0,0,0xff,0xff };
+ GpStatus status;
+ union
+ {
+ GpBitmap *bitmap;
+ GpImage *image;
+ } u1, u2;
+ GpGraphics *graphics;
+ BitmapData data;
+ int match;
+
+ status = GdipCreateBitmapFromScan0(1, 1, 4, PixelFormat24bppRGB, black_1x1, &u1.bitmap);
+ expect(Ok, status);
+ status = GdipBitmapSetResolution(u1.bitmap, 100.0, 100.0);
+ expect(Ok, status);
+
+ status = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat24bppRGB, white_2x2, &u2.bitmap);
+ expect(Ok, status);
+ status = GdipBitmapSetResolution(u2.bitmap, 300.0, 300.0);
+ expect(Ok, status);
+ status = GdipGetImageGraphicsContext(u2.image, &graphics);
+ expect(Ok, status);
+ status = GdipSetInterpolationMode(graphics, InterpolationModeNearestNeighbor);
+ expect(Ok, status);
+
+ status = GdipDrawImageI(graphics, u1.image, 0, 0);
+ expect(Ok, status);
+
+ memset(&data, 0xfe, sizeof(data));
+ status = GdipBitmapLockBits(u2.bitmap, NULL, ImageLockModeRead, PixelFormat24bppRGB, &data);
+ expect(Ok, status);
+ expect(2, data.Width);
+ expect(2, data.Height);
+ expect(8, data.Stride);
+ expect(PixelFormat24bppRGB, data.PixelFormat);
+ match = memcmp(data.Scan0, black_2x2, sizeof(black_2x2)) == 0;
+todo_wine
+ ok(match, "data should match\n");
+ if (!match)
+ {
+ UINT i, size = data.Height * data.Stride;
+ BYTE *bits = data.Scan0;
+ for (i = 0; i < size; i++)
+ printf(" %02x", bits[i]);
+ printf("\n");
+ }
+ status = GdipBitmapUnlockBits(u2.bitmap, &data);
+ expect(Ok, status);
+
+ status = GdipDeleteGraphics(graphics);
+ expect(Ok, status);
+ status = GdipDisposeImage(u1.image);
+ expect(Ok, status);
+ status = GdipDisposeImage(u2.image);
+ expect(Ok, status);
+}
+
+static void test_GdipDrawImagePointRect(void)
+{
+ BYTE black_1x1[4] = { 0,0,0,0 };
+ BYTE white_2x2[16] = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff };
+ BYTE black_2x2[16] = { 0,0,0,0,0,0,0xff,0xff,
+ 0,0,0,0,0,0,0xff,0xff };
+ GpStatus status;
+ union
+ {
+ GpBitmap *bitmap;
+ GpImage *image;
+ } u1, u2;
+ GpGraphics *graphics;
+ BitmapData data;
+ int match;
+
+ status = GdipCreateBitmapFromScan0(1, 1, 4, PixelFormat24bppRGB, black_1x1, &u1.bitmap);
+ expect(Ok, status);
+ status = GdipBitmapSetResolution(u1.bitmap, 100.0, 100.0);
+ expect(Ok, status);
+
+ status = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat24bppRGB, white_2x2, &u2.bitmap);
+ expect(Ok, status);
+ status = GdipBitmapSetResolution(u2.bitmap, 300.0, 300.0);
+ expect(Ok, status);
+ status = GdipGetImageGraphicsContext(u2.image, &graphics);
+ expect(Ok, status);
+ status = GdipSetInterpolationMode(graphics, InterpolationModeNearestNeighbor);
+ expect(Ok, status);
+
+ status = GdipDrawImagePointRectI(graphics, u1.image, 0, 0, 0, 0, 1, 1, UnitPixel);
+ expect(Ok, status);
+
+ memset(&data, 0xfe, sizeof(data));
+ status = GdipBitmapLockBits(u2.bitmap, NULL, ImageLockModeRead, PixelFormat24bppRGB, &data);
+ expect(Ok, status);
+ expect(2, data.Width);
+ expect(2, data.Height);
+ expect(8, data.Stride);
+ expect(PixelFormat24bppRGB, data.PixelFormat);
+ match = memcmp(data.Scan0, black_2x2, sizeof(black_2x2)) == 0;
+todo_wine
+ ok(match, "data should match\n");
+ if (!match)
+ {
+ UINT i, size = data.Height * data.Stride;
+ BYTE *bits = data.Scan0;
+ for (i = 0; i < size; i++)
+ printf(" %02x", bits[i]);
+ printf("\n");
+ }
+ status = GdipBitmapUnlockBits(u2.bitmap, &data);
+ expect(Ok, status);
+
+ status = GdipDeleteGraphics(graphics);
+ expect(Ok, status);
+ status = GdipDisposeImage(u1.image);
+ expect(Ok, status);
+ status = GdipDisposeImage(u2.image);
+ expect(Ok, status);
+}
+
START_TEST(image)
{
struct GdiplusStartupInput gdiplusStartupInput;
@@ -3619,6 +3746,8 @@ START_TEST(image)
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
+ test_DrawImage();
+ test_GdipDrawImagePointRect();
test_bitmapbits();
test_tiff_palette();
test_GdipGetAllPropertyItems();
--
1.7.11.4
More information about the wine-patches
mailing list