From 8f4e208ef06c258e760fe55b78a6cf2ba6c1a18f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Tue, 29 Mar 2011 13:59:08 -0400 Subject: Added proper dumping function for generating cunit test case data for LineTo() --- GdiTest/BitBltDrawingArea.cs | 14 ++++---------- GdiTest/FreeRDPGDI.cs | 4 ++-- GdiTest/GDI.cs | 4 ++-- GdiTest/GdiTest.pidb | Bin 21486 -> 21842 bytes GdiTest/LineToDrawingArea.cs | 29 +++++++++++++++-------------- GdiTest/TestDrawingArea.cs | 1 - GdiTest/Win32GDI.cs | 10 +++++----- 7 files changed, 28 insertions(+), 34 deletions(-) diff --git a/GdiTest/BitBltDrawingArea.cs b/GdiTest/BitBltDrawingArea.cs index 68f90f6..5024db8 100644 --- a/GdiTest/BitBltDrawingArea.cs +++ b/GdiTest/BitBltDrawingArea.cs @@ -26,17 +26,11 @@ namespace GdiTest TestData data = new TestData(); - for (int i = 0; i < data.bmp_SRC.GetLength(0) / 2; i++) + for (int i = 0; i < data.bmp_SRC.GetLength(0); i++) { - for (int j = 0; j < data.bmp_SRC.GetLength(1); j++) + for (int j = 0; j < data.bmp_SRC.GetLength(1) / 2; j += 2) { - uint p = 0; - - if (data.bmp_SRC[i, j] == 0) - p = 0; - else - p = 0xFFFFFFFF; - + int p = 0; GDI_Win32.SetPixel(hdc, i, j, p); } } @@ -47,7 +41,7 @@ namespace GdiTest return true; } - public override String dump() + public String dump() { String text = ""; diff --git a/GdiTest/FreeRDPGDI.cs b/GdiTest/FreeRDPGDI.cs index 4877067..ab3bd4a 100644 --- a/GdiTest/FreeRDPGDI.cs +++ b/GdiTest/FreeRDPGDI.cs @@ -77,12 +77,12 @@ namespace GdiTest return false; } - public override uint GetPixel(IntPtr hdc, int X, int Y) + public override int GetPixel(IntPtr hdc, int X, int Y) { return 0; } - public override uint SetPixel(IntPtr hdc, int X, int Y, uint crColor) + public override int SetPixel(IntPtr hdc, int X, int Y, int crColor) { return 0; } diff --git a/GdiTest/GDI.cs b/GdiTest/GDI.cs index 894726e..9272bb9 100644 --- a/GdiTest/GDI.cs +++ b/GdiTest/GDI.cs @@ -33,8 +33,8 @@ namespace GdiTest public abstract int ReleaseDC(IntPtr hWnd, IntPtr hDC); public abstract IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj); public abstract bool DeleteObject(IntPtr hObject); - public abstract uint GetPixel(IntPtr hdc, int X, int Y); - public abstract uint SetPixel(IntPtr hdc, int X, int Y, uint crColor); + public abstract int GetPixel(IntPtr hdc, int X, int Y); + public abstract int SetPixel(IntPtr hdc, int X, int Y, int crColor); public abstract bool MoveToEx(IntPtr hdc, int X, int Y, IntPtr lpPoint); public abstract bool LineTo(IntPtr hdc, int nXEnd, int nYEnd); public abstract IntPtr CreatePen(int fnPenStyle, int nWidth, int crColor); diff --git a/GdiTest/GdiTest.pidb b/GdiTest/GdiTest.pidb index 98b88e0..9bd066c 100644 Binary files a/GdiTest/GdiTest.pidb and b/GdiTest/GdiTest.pidb differ diff --git a/GdiTest/LineToDrawingArea.cs b/GdiTest/LineToDrawingArea.cs index 1e78aff..0df2377 100644 --- a/GdiTest/LineToDrawingArea.cs +++ b/GdiTest/LineToDrawingArea.cs @@ -172,39 +172,40 @@ namespace GdiTest IntPtr oldPen = GDI_Win32.SelectObject(hdc, pen); GDI_Win32.MoveToEx(hdc, startp[i].X, startp[i].Y, IntPtr.Zero); GDI_Win32.LineTo(hdc, endp[i].X, endp[i].Y); + + dumpText += "unsigned char line_to_case_" + (i + 1) + "[" + areas[i].W * areas[i].H + "] = \n"; + dumpText += this.dump(hdc, areas[i].X, areas[i].Y, areas[i].W, areas[i].H) + "\n"; } } } - dumpText = this.dump(); - return true; } - public override String dump() + public String dump(IntPtr hdc, int X, int Y, int W, int H) { String text = ""; Win32GDI GDI_Win32 = Win32GDI.getInstance(); if (GDI_Win32.isAvailable()) - { - System.Drawing.Graphics wg = Gtk.DotNet.Graphics.FromDrawable(this.GdkWindow, true); - IntPtr hdc = wg.GetHdc(); - - for (int y = 0; y < 16; y++) + { + text += "{\n"; + for (int y = Y; y < Y + H; y++) { - for (int x = 0; x < 16; x++) + text += "\t\""; + for (int x = X; x < X + W; x++) { - System.Drawing.Color color = GDI_Win32.GetPixelColor(hdc, x, y); + int p = GDI_Win32.GetPixel(hdc, x, y); - if (color.R == 255) - text += "0xFF, "; + if (p == 0) + text += "\\x00"; else - text += "0x00, "; + text += "\\xFF"; } - text += "\n"; + text += "\"\n"; } + text += "};\n"; } return text; diff --git a/GdiTest/TestDrawingArea.cs b/GdiTest/TestDrawingArea.cs index ecc5d61..da388ce 100644 --- a/GdiTest/TestDrawingArea.cs +++ b/GdiTest/TestDrawingArea.cs @@ -10,7 +10,6 @@ namespace GdiTest { } - abstract public String dump(); abstract public String getDumpText(); } } diff --git a/GdiTest/Win32GDI.cs b/GdiTest/Win32GDI.cs index 1d1c722..0e788f9 100644 --- a/GdiTest/Win32GDI.cs +++ b/GdiTest/Win32GDI.cs @@ -24,10 +24,10 @@ namespace GdiTest public static extern bool DeleteObject(IntPtr hObject); [DllImport("gdi32.dll")] - public static extern uint GetPixel(IntPtr hdc, int X, int Y); + public static extern int GetPixel(IntPtr hdc, int X, int Y); [DllImport("gdi32.dll")] - public static extern uint SetPixel(IntPtr hdc, int X, int Y, uint crColor); + public static extern int SetPixel(IntPtr hdc, int X, int Y, int crColor); [DllImport("gdi32")] public static extern bool MoveToEx(IntPtr hdc, int X, int Y, IntPtr lpPoint); @@ -116,7 +116,7 @@ namespace GdiTest return false; } - public override uint GetPixel(IntPtr hdc, int X, int Y) + public override int GetPixel(IntPtr hdc, int X, int Y) { if (available) return Callbacks.GetPixel(hdc, X, Y); @@ -124,7 +124,7 @@ namespace GdiTest return 0; } - public override uint SetPixel(IntPtr hdc, int X, int Y, uint crColor) + public override int SetPixel(IntPtr hdc, int X, int Y, int crColor) { if (available) return Callbacks.SetPixel(hdc, X, Y, crColor); @@ -134,7 +134,7 @@ namespace GdiTest public System.Drawing.Color GetPixelColor(IntPtr hdc, int X, int Y) { - uint pixel = Callbacks.GetPixel(hdc, X, Y); + int pixel = Callbacks.GetPixel(hdc, X, Y); System.Drawing.Color color = System.Drawing.Color.FromArgb((int)(pixel & 0x000000FF), (int)(pixel & 0x0000FF00) >> 8, (int)(pixel & 0x00FF0000) >> 16); -- cgit v1.2.3