예제 #1
0
파일: IA4.cs 프로젝트: Cuyler36/GCNToolKit
        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);
        }
예제 #2
0
파일: IA8.cs 프로젝트: Cuyler36/GCNToolKit
        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);
        }
예제 #3
0
파일: I8.cs 프로젝트: Cuyler36/GCNToolKit
        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);
        }
예제 #4
0
파일: C8.cs 프로젝트: Cuyler36/GCNToolKit
        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);
        }
예제 #5
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));
        }
예제 #6
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);
        }