Beispiel #1
0
        private static int[] DecodeI8Routine(byte[] I8Data, int Width, int Height, bool Unswizzle = true)
        {
            int[] GrayscaleData = new int[I8Data.Length];
            for (int i = 0; i < GrayscaleData.Length; i++)
            {
                GrayscaleData[i] = (I8Data[i] << 24) | (I8Data[i] << 16) | (I8Data[i] << 8) | I8Data[i];
            }

            return(Unswizzle ? SwizzleUtil.Unswizzle(GrayscaleData, Width, Height, 8, 4) : GrayscaleData);
        }
Beispiel #2
0
        private static int[] DecodeIA8Routine(byte[] IA8Data, int Width, int Height, bool Unswizzle = true)
        {
            int[] GrayscaleData = new int[IA8Data.Length / 2];
            for (int i = 0; i < GrayscaleData.Length; i++)
            {
                int idx = i * 2;
                GrayscaleData[i] = (IA8Data[idx] << 24) | (IA8Data[idx + 1] << 16) | (IA8Data[idx + 1] << 8) | IA8Data[idx + 1];
            }

            return(Unswizzle ? SwizzleUtil.Unswizzle(GrayscaleData, Width, Height, 4, 4) : GrayscaleData);
        }
Beispiel #3
0
        private static byte[] EncodeIA4Routine(int[] ImageData, int Width, int Height)
        {
            ImageData = SwizzleUtil.Swizzle(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);
        }
Beispiel #4
0
        private static int[] DecodeI4Routine(byte[] I4Data, int Width, int Height, bool Unswizzle = true)
        {
            int[] GrayscaleData = new int[I4Data.Length * 2];
            for (int i = 0; i < I4Data.Length; i++)
            {
                byte LeftPixelValue  = (byte)((I4Data[i] & 0xF0) | (I4Data[i] >> 4));
                byte RightPixelValue = (byte)((I4Data[i] << 4) | (I4Data[i] & 0x0F));

                int idx = i * 2;
                GrayscaleData[idx]     = (0xFF << 24) | (LeftPixelValue << 16) | (LeftPixelValue << 8) | LeftPixelValue;
                GrayscaleData[idx + 1] = (0xFF << 24) | (RightPixelValue << 16) | (RightPixelValue << 8) | RightPixelValue;
            }

            return(Unswizzle ? SwizzleUtil.Unswizzle(GrayscaleData, Width, Height, 8, 8) : GrayscaleData);
        }
Beispiel #5
0
        private static byte[] EncodeIA8Routine(int[] ImageData, int Width, int Height, bool Swizzle = true)
        {
            ImageData = Swizzle ? SwizzleUtil.Swizzle(ImageData, Width, Height, 4, 4) : ImageData;
            byte[] IA8Data = new byte[ImageData.Length * 2];

            for (int i = 0; i < ImageData.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);
        }
Beispiel #6
0
        private static int[] C4ImageSubroutineDecode(byte[] C4ImageData, ushort[] Palette, int Width, int Height, ColorFormat PixelFormat,
                                                     bool Unswizzle = true)
        {
            C4ImageData = Utilities.Utilities.SeparateNibbles(C4ImageData);
            int[] RGB8Palette = PaletteManager.GetRGBA8Palette(Palette, PixelFormat);

            byte[] UnscrambledData = Unswizzle ? SwizzleUtil.Unswizzle(C4ImageData, Width, Height, 8, 8) : C4ImageData;
            int[]  ImageData       = new int[UnscrambledData.Length];

            for (int i = 0; i < ImageData.Length; i++)
            {
                ImageData[i] = RGB8Palette[UnscrambledData[i]];
            }

            return(ImageData);
        }
Beispiel #7
0
        private static byte[] EncodeI8Routine(int[] ImageData, int Width, int Height, bool Swizzle = true)
        {
            if (Swizzle)
            {
                ImageData = SwizzleUtil.Swizzle(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);
        }
Beispiel #8
0
        private static byte[] C8ImageSubroutineEncode(int[] ImageData, ushort[] Palette, int Width, int Height, bool Swizzle)
        {
            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(Swizzle ? SwizzleUtil.Swizzle(C8Data, Width, Height, 8, 4) : C8Data);
        }
Beispiel #9
0
        private static byte[] C4ImageSubroutineEncode(int[] ImageData, ushort[] Palette, int Width, int Height, ColorFormat PixelFormat,
                                                      bool Swizzle = 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(Swizzle ? SwizzleUtil.Swizzle(C4Data, Width, Height, 8, 8) : C4Data));
        }
Beispiel #10
0
        public static int[] Decode(ushort[] rgba16Data, int width, int height)
        {
            var dataOut  = new int[width * height];
            var position = 0;

            rgba16Data = SwizzleUtil.Unswizzle(rgba16Data, width, height, 4, 4);

            for (var y = 0; y < height; y++)
            {
                for (var x = 0; x < width; x++)
                {
                    dataOut[position] = (int)RGB5A3.ToARGB8(rgba16Data[position]);
                    position++;
                }
            }

            return(dataOut);
        }
Beispiel #11
0
        private static int[] DecodeIA4Routine(byte[] IA4Data, int Width, int Height, Color Color, bool Unswizzle = true)
        {
            int[] GrayscaleData = new int[IA4Data.Length];
            for (int i = 0; i < GrayscaleData.Length; i++)
            {
                byte LeftPixelValue  = (byte)(((IA4Data[i] & 0xF0) | (IA4Data[i] >> 4)) & 0xFF); // Alpha
                byte RightPixelValue = (byte)(((IA4Data[i] << 4) | (IA4Data[i] & 0x0F)) & 0xFF);

                GrayscaleData[i] = (LeftPixelValue << 24) | (RightPixelValue << 16) | (RightPixelValue << 8) | RightPixelValue;
            }

            // Apply color to decoded pixel data.
            for (var i = 0; i < GrayscaleData.Length; i++)
            {
            }

            return(Unswizzle ? SwizzleUtil.Unswizzle(GrayscaleData, Width, Height, 8, 4) : GrayscaleData);
        }
Beispiel #12
0
        private static int[] C8ImageSubroutineDecode(byte[] C8ImageData, ushort[] Palette, int Width, int Height, bool Unswizzle)
        {
            int[] RGB8Palette = new int[Palette.Length];
            for (int i = 0; i < RGB8Palette.Length; i++)
            {
                RGB8Palette[i] = (int)RGB5A3.ToARGB8(Palette[i]);
            }

            byte[] UnscrambledData = Unswizzle ? SwizzleUtil.Unswizzle(C8ImageData, Width, Height, 8, 4) : C8ImageData;
            int[]  ImageData       = new int[UnscrambledData.Length];

            for (int i = 0; i < ImageData.Length; i++)
            {
                ImageData[i] = RGB8Palette[UnscrambledData[i]];
            }

            return(ImageData);
        }
Beispiel #13
0
        private static byte[] EncodeI4Routine(int[] ImageData, int Width, int Height, bool Swizzle = true)
        {
            if (Swizzle)
            {
                ImageData = SwizzleUtil.Swizzle(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);
        }