From e1620cb930e8827fe4c325d1d1106eef0a8c6d6e Mon Sep 17 00:00:00 2001 From: Matt Thorson Date: Sun, 14 Jun 2020 17:27:50 -0700 Subject: [PATCH] Casting fixes --- src/Core/Sprite.bf | 36 ++++++++++++++++++------------------ src/Struct/Color.bf | 5 +++++ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/Core/Sprite.bf b/src/Core/Sprite.bf index 25ec536..c8f10f0 100644 --- a/src/Core/Sprite.bf +++ b/src/Core/Sprite.bf @@ -394,9 +394,9 @@ namespace Strawberry { for (int p = 0, int b = 0; p < len; p++, b += 4) { - pixels[p].R = (uint8)((int)bytes[b + 0] * (int)bytes[b + 3] / 255); - pixels[p].G = (uint8)((int)bytes[b + 1] * (int)bytes[b + 3] / 255); - pixels[p].B = (uint8)((int)bytes[b + 2] * (int)bytes[b + 3] / 255); + pixels[p].R = (uint8)((int)bytes[b + 0] * bytes[b + 3] / 255); + pixels[p].G = (uint8)((int)bytes[b + 1] * bytes[b + 3] / 255); + pixels[p].B = (uint8)((int)bytes[b + 2] * bytes[b + 3] / 255); pixels[p].A = bytes[b + 3]; } } @@ -404,7 +404,7 @@ namespace Strawberry { for (int p = 0, int b = 0; p < len; p++, b += 2) { - pixels[p].R = pixels[p].G = pixels[p].B = (uint8)((int)bytes[b + 0] * (int)bytes[b + 1] / 255); + pixels[p].R = pixels[p].G = pixels[p].B = (uint8)((int)bytes[b + 0] * bytes[b + 1] / 255); pixels[p].A = bytes[b + 1]; } } @@ -582,10 +582,10 @@ namespace Strawberry { if (src.A != 0) { - int r = dest[index + 0]; - int g = dest[index + 1]; - int b = dest[index + 2]; - int a = dest[index + 3]; + uint8 r = dest[index + 0]; + uint8 g = dest[index + 1]; + uint8 b = dest[index + 2]; + uint8 a = dest[index + 3]; if (a == 0) { @@ -599,16 +599,16 @@ namespace Strawberry int sa = MUL_UN8(src.A, opacity); int ra = a + sa - MUL_UN8(a, sa); - r = (r + (src.R - r) * sa / ra); - g = (g + (src.G - g) * sa / ra); - b = (b + (src.B - b) * sa / ra); - a = ra; + r = (uint8)((int)r + ((int)src.R - r) * sa / ra); + g = (uint8)((int)g + ((int)src.G - g) * sa / ra); + b = (uint8)((int)b + ((int)src.B - b) * sa / ra); + a = (uint8)ra; } - dest[index + 0] = (uint8)r; - dest[index + 1] = (uint8)g; - dest[index + 2] = (uint8)b; - dest[index + 3] = (uint8)a; + dest[index + 0] = r; + dest[index + 1] = g; + dest[index + 2] = b; + dest[index + 3] = a; } } }; @@ -616,8 +616,8 @@ namespace Strawberry [Inline] private static int MUL_UN8(int a, int b) { - var t = (a * b) + 0x80; - return (((t >> 8) + t) >> 8); + int t = (a * b) + 0x80; + return ((t >> 8) + t) >> 8; } } } diff --git a/src/Struct/Color.bf b/src/Struct/Color.bf index 244d986..35692ac 100644 --- a/src/Struct/Color.bf +++ b/src/Struct/Color.bf @@ -38,6 +38,11 @@ namespace Strawberry A = (uint8)(alpha * 255); } + public this() + { + R = G = B = A = 0; + } + public float Rf { [Inline]