From 101340a6ed95fdeabd234349a1cde6343345829b Mon Sep 17 00:00:00 2001 From: KM198912 <55886806+KM198912@users.noreply.github.com> Date: Tue, 20 Oct 2020 15:54:01 +0200 Subject: [PATCH 1/4] Implement Bitmap Scaling Implement Bitmap Scaling by Desired Height and Width --- source/Cosmos.System2/Graphics/Canvas.cs | 43 +++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/source/Cosmos.System2/Graphics/Canvas.cs b/source/Cosmos.System2/Graphics/Canvas.cs index 427f1d084b..223f6c44e1 100644 --- a/source/Cosmos.System2/Graphics/Canvas.cs +++ b/source/Cosmos.System2/Graphics/Canvas.cs @@ -855,7 +855,48 @@ public virtual void DrawImage(Image image, int x, int y) } } } - + + /// + /// Draw a Scaled Bitmap. + /// + /// Image to Scale. + /// X coordinate. + /// Y coordinate. + /// Desired Width. + /// Desired Height. + private int[] scaleImage(Image image, int newWidth, int newHeight) + { + int[] pixels = image.rawData; + int w1 = (int)image.Width; + int h1 = (int)image.Height; + int[] temp = new int[newWidth * newHeight]; + int x_ratio = (int)((w1 << 16) / newWidth) + 1; + int y_ratio = (int)((h1 << 16) / newHeight) + 1; + int x2, y2; + for (int i = 0; i < newHeight; i++) + { + for (int j = 0; j < newWidth; j++) + { + x2 = ((j * x_ratio) >> 16); + y2 = ((i * y_ratio) >> 16); + temp[(i * newWidth) + j] = pixels[(y2 * w1) + x2]; + } + } + return temp; + } + public virtual void DrawScaledImage(Image image, int x, int y,int w,int h) + { + int[] pixels = scaleImage(image, w, h); + for (int _x = 0; _x < w; _x++) + { + for (int _y = 0; _y < h; _y++) + { + Global.mDebugger.SendInternal(pixels[_x + _y * w]); + DrawPoint(new Pen(Color.FromArgb(pixels[_x + _y * w])), x + _x, y + _y); + } + } + } + /// /// Draw image with alpha channel. /// From b797255548a1f500863a4bff571c7aeb973f637b Mon Sep 17 00:00:00 2001 From: KM198912 <55886806+KM198912@users.noreply.github.com> Date: Tue, 20 Oct 2020 15:56:53 +0200 Subject: [PATCH 2/4] Add Scaling Test --- Tests/Kernels/GraphicTest/Kernel.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Tests/Kernels/GraphicTest/Kernel.cs b/Tests/Kernels/GraphicTest/Kernel.cs index d6a6a43516..61951432cb 100644 --- a/Tests/Kernels/GraphicTest/Kernel.cs +++ b/Tests/Kernels/GraphicTest/Kernel.cs @@ -117,7 +117,9 @@ private void DoTest(Canvas aCanvas) aCanvas.DrawImage(bitmap, new Point(0, 0)); aCanvas.DrawImage(bitmap2, new Point(200, 0)); - + //Scale Bitmap + aCanvas.DrawScaledImage(bitmap,0,0,50,50); + aCanvas.DrawImageAlpha(bitmap3, new Point(0, 300)); /* Drawing ellipses */ From 7cf12663e48358101c770aab3ecd4df06d6bd90f Mon Sep 17 00:00:00 2001 From: KM198912 <55886806+KM198912@users.noreply.github.com> Date: Tue, 20 Oct 2020 16:33:07 +0200 Subject: [PATCH 3/4] Update Canvas.cs Make Requested Changes --- source/Cosmos.System2/Graphics/Canvas.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/source/Cosmos.System2/Graphics/Canvas.cs b/source/Cosmos.System2/Graphics/Canvas.cs index 223f6c44e1..bd5d6efca7 100644 --- a/source/Cosmos.System2/Graphics/Canvas.cs +++ b/source/Cosmos.System2/Graphics/Canvas.cs @@ -856,14 +856,6 @@ public virtual void DrawImage(Image image, int x, int y) } } - /// - /// Draw a Scaled Bitmap. - /// - /// Image to Scale. - /// X coordinate. - /// Y coordinate. - /// Desired Width. - /// Desired Height. private int[] scaleImage(Image image, int newWidth, int newHeight) { int[] pixels = image.rawData; @@ -884,7 +876,15 @@ private int[] scaleImage(Image image, int newWidth, int newHeight) } return temp; } - public virtual void DrawScaledImage(Image image, int x, int y,int w,int h) + /// + /// Draw a Scaled Bitmap. + /// + /// Image to Scale. + /// X coordinate. + /// Y coordinate. + /// Desired Width. + /// Desired Height. + public virtual void DrawImage(Image image, int x, int y,int w,int h) { int[] pixels = scaleImage(image, w, h); for (int _x = 0; _x < w; _x++) From 9435168e13db7cd20cbeaa9e68dcfe008f3bd092 Mon Sep 17 00:00:00 2001 From: KM198912 <55886806+KM198912@users.noreply.github.com> Date: Tue, 20 Oct 2020 16:46:05 +0200 Subject: [PATCH 4/4] Update Kernel.cs Forgot that --- Tests/Kernels/GraphicTest/Kernel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Kernels/GraphicTest/Kernel.cs b/Tests/Kernels/GraphicTest/Kernel.cs index 61951432cb..ab9d54f599 100644 --- a/Tests/Kernels/GraphicTest/Kernel.cs +++ b/Tests/Kernels/GraphicTest/Kernel.cs @@ -118,7 +118,7 @@ private void DoTest(Canvas aCanvas) aCanvas.DrawImage(bitmap, new Point(0, 0)); aCanvas.DrawImage(bitmap2, new Point(200, 0)); //Scale Bitmap - aCanvas.DrawScaledImage(bitmap,0,0,50,50); + aCanvas.DrawImage(bitmap,0,0,50,50); aCanvas.DrawImageAlpha(bitmap3, new Point(0, 300));