private static byte[] EncodeI8Routine(int[] ImageData, int Width, int Height) { ImageData = BlockFormat.Encode(ImageData, Width, Height, 8, 4); byte[] I8Data = new byte[ImageData.Length]; for (int i = 0; i < I8Data.Length; i++) { I8Data[i] = (byte)((((ImageData[i] >> 16) & 0xFF) * 0.2126) + (((ImageData[i] >> 8) & 0xFF) * 0.7152) + ((ImageData[i] & 0xFF) * 0.0722)); } return(I8Data); }
private static byte[] EncodeIA8Routine(int[] ImageData, int Width, int Height) { ImageData = BlockFormat.Encode(ImageData, Width, Height, 4, 4); byte[] IA8Data = new byte[ImageData.Length * 2]; for (int i = 0; i < IA8Data.Length; i++) { int idx = i * 2; IA8Data[idx] = (byte)(ImageData[i] >> 24); IA8Data[idx + 1] = (byte)((((ImageData[i] >> 16) & 0xFF) * 0.2126) + (((ImageData[i] >> 8) & 0xFF) * 0.7152) + ((ImageData[i] & 0xFF) * 0.0722)); } return(IA8Data); }
private static byte[] EncodeIA4Routine(int[] ImageData, int Width, int Height) { ImageData = BlockFormat.Encode(ImageData, Width, Height, 8, 4); byte[] PackedIA4Data = new byte[ImageData.Length]; for (int i = 0; i < PackedIA4Data.Length; i++) { byte LeftValue = (byte)((ImageData[i] >> 24) & 0xFF); // Alpha byte RightValue = (byte)(ImageData[i] >> 16); // Only use red PackedIA4Data[i] = (byte)(((LeftValue / 16) << 4) | (RightValue / 16)); } return(PackedIA4Data); }
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)); }
private static byte[] C8ImageSubroutineEncode(int[] ImageData, ushort[] Palette, int Width, int Height) { int[] RGB8Palette = new int[Palette.Length]; for (int i = 0; i < RGB8Palette.Length; i++) { RGB8Palette[i] = (int)RGB5A3.ToARGB8(Palette[i]); } byte[] C8Data = new byte[ImageData.Length]; for (int i = 0; i < C8Data.Length; i++) { C8Data[i] = Utilities.ColorUtilities.ClosestColorRGB(ImageData[i], RGB8Palette); } return(BlockFormat.Encode(C8Data, Width, Height, 8, 4)); }
private static byte[] EncodeI4Routine(int[] ImageData, int Width, int Height) { ImageData = BlockFormat.Encode(ImageData, Width, Height, 8, 8); byte[] PackedI4Data = new byte[ImageData.Length / 2]; // We're only taking the red channel here for re-encoding. for (int i = 0; i < PackedI4Data.Length; i++) { int idx = i * 2; byte LeftValue = (byte)(ImageData[idx] >> 16); byte RightValue = (byte)(ImageData[idx + 1] >> 16); PackedI4Data[i] = (byte)(((LeftValue / 0x10) << 4) | (RightValue / 0x10)); } return(PackedI4Data); }