private static byte[] C4ImageSubroutineEncode(int[] ImageData, ushort[] Palette, int Width, int Height, bool UsesBlocks = true) { int[] RGB8Palette = new int[Palette.Length]; for (int i = 0; i < RGB8Palette.Length; i++) { RGB8Palette[i] = (int)RGB5A3.ToARGB8(Palette[i]); } byte[] C4Data = new byte[ImageData.Length]; for (int i = 0; i < C4Data.Length; i++) { C4Data[i] = ColorUtilities.ClosestColorRGB(ImageData[i], RGB8Palette); } return(Utilities.Utilities.CondenseNibbles(UsesBlocks ? BlockFormat.Encode(C4Data, Width, Height, 8, 8) : C4Data)); }