From 0780f37852eb6b47c7570d65b36740e330f82cd6 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 27 Feb 2021 00:26:20 +0100 Subject: [PATCH] Added check for empty or one pixel requrests in Texture --- RGB.NET.Core/Rendering/Textures/PixelTexture.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/RGB.NET.Core/Rendering/Textures/PixelTexture.cs b/RGB.NET.Core/Rendering/Textures/PixelTexture.cs index 43a7828..0820319 100644 --- a/RGB.NET.Core/Rendering/Textures/PixelTexture.cs +++ b/RGB.NET.Core/Rendering/Textures/PixelTexture.cs @@ -29,8 +29,8 @@ namespace RGB.NET.Core { if (Data.Length == 0) return Color.Transparent; - int x = (int)Math.Round(Size.Width * point.X.Clamp(0, 1)); - int y = (int)Math.Round(Size.Height * point.Y.Clamp(0, 1)); + int x = (int)MathF.Round(Size.Width * point.X.Clamp(0, 1)); + int y = (int)MathF.Round(Size.Height * point.Y.Clamp(0, 1)); return GetColor(GetPixelData(x, y)); } } @@ -41,10 +41,13 @@ namespace RGB.NET.Core { if (Data.Length == 0) return Color.Transparent; - int x = (int)Math.Round(Size.Width * rectangle.Location.X.Clamp(0, 1)); - int y = (int)Math.Round(Size.Height * rectangle.Location.Y.Clamp(0, 1)); - int width = (int)Math.Round(Size.Width * rectangle.Size.Width.Clamp(0, 1)); - int height = (int)Math.Round(Size.Height * rectangle.Size.Height.Clamp(0, 1)); + int x = (int)MathF.Round(Size.Width * rectangle.Location.X.Clamp(0, 1)); + int y = (int)MathF.Round(Size.Height * rectangle.Location.Y.Clamp(0, 1)); + int width = (int)MathF.Round(Size.Width * rectangle.Size.Width.Clamp(0, 1)); + int height = (int)MathF.Round(Size.Height * rectangle.Size.Height.Clamp(0, 1)); + + if ((width == 0) || (height == 0)) return Color.Transparent; + if ((width == 1) && (height == 1)) return GetColor(GetPixelData(x, y)); int bufferSize = width * height * _dataPerPixel; if (bufferSize <= STACK_ALLOC_LIMIT)