From 6665fab8d9143d3e0b7d40ee2bbaaecb7f086ec0 Mon Sep 17 00:00:00 2001 From: Jeremy Pritts Date: Sat, 5 Feb 2022 23:48:53 -0500 Subject: [PATCH] fix overflow in RGBAHalfToBGRA32 --- TextureDecoder/Rgb/RgbConverter.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/TextureDecoder/Rgb/RgbConverter.cs b/TextureDecoder/Rgb/RgbConverter.cs index 20986c0..52fd1dd 100644 --- a/TextureDecoder/Rgb/RgbConverter.cs +++ b/TextureDecoder/Rgb/RgbConverter.cs @@ -511,10 +511,10 @@ public static void RGBAHalfToBGRA32(byte[] input, int width, int height, byte[] { for (int j = 0; j < height; j++) { - byte r = Convert.ToByte(Math.Round(ToHalf(input, io + 0) * 255f)); - byte g = Convert.ToByte(Math.Round(ToHalf(input, io + 2) * 255f)); - byte b = Convert.ToByte(Math.Round(ToHalf(input, io + 4) * 255f)); - byte a = Convert.ToByte(Math.Round(ToHalf(input, io + 6) * 255f)); + byte r = ClampByte(ToHalf(input, io + 0) * 255f); + byte g = ClampByte(ToHalf(input, io + 2) * 255f); + byte b = ClampByte(ToHalf(input, io + 4) * 255f); + byte a = ClampByte(ToHalf(input, io + 6) * 255f); output[oo + 0] = b; // b output[oo + 1] = g; // g output[oo + 2] = r; // r