From 2ce5e442b1651e42b0dfe2af6e71208447e451bd Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Mon, 8 Aug 2016 00:45:30 -0700 Subject: [PATCH] Fix colors disappearing Thanks SciresM! --- Subforms/Save Editors/Gen5/CGearBackground.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Subforms/Save Editors/Gen5/CGearBackground.cs b/Subforms/Save Editors/Gen5/CGearBackground.cs index fffd17cd7..33f5a816d 100644 --- a/Subforms/Save Editors/Gen5/CGearBackground.cs +++ b/Subforms/Save Editors/Gen5/CGearBackground.cs @@ -51,7 +51,7 @@ public CGearBackground(byte[] data) ColorPalette = new Color[0x10]; for (int i = 0; i < 0x10; i++) - ColorPalette[i] = getRGB555(BitConverter.ToUInt16(ColorData, i * 2)); + ColorPalette[i] = getRGB555_16(BitConverter.ToUInt16(ColorData, i * 2)); Tiles = new Tile[0xFF]; for (int i = 0; i < 0xFF; i++) @@ -145,7 +145,7 @@ public void SetImage(Bitmap img) for (int i = 0; i < data.Length; i += bpp) { uint val = BitConverter.ToUInt32(data, i); - colors[i/bpp] = getRGB555(val); + colors[i/bpp] = getRGB555_32(val); } Color[] Palette = colors.Distinct().ToArray(); @@ -328,13 +328,20 @@ private static byte convert8to5(int colorval) while (colorval > Convert5To8[i]) i++; return i; } - private static Color getRGB555(uint val) + private static Color getRGB555_32(uint val) { int R = (int)(val >> 0 >> 3) & 0x1F; int G = (int)(val >> 8 >> 3) & 0x1F; int B = (int)(val >> 16 >> 3) & 0x1F; return Color.FromArgb(0xFF, Convert5To8[R], Convert5To8[G], Convert5To8[B]); } + private static Color getRGB555_16(ushort val) + { + int R = (val >> 0) & 0x1F; + int G = (val >> 5) & 0x1F; + int B = (val >> 10) & 0x1F; + return Color.FromArgb(0xFF, Convert5To8[R], Convert5To8[G], Convert5To8[B]); + } private static ushort getRGB555(Color c) { int val = 0;