Exemple #1
0
        public static byte[] DecodeBC4(NsGpuTexture Tex, int Offset)
        {
            int W = (Tex.Width + 3) / 4;
            int H = (Tex.Height + 3) / 4;

            byte[] Output = new byte[W * H * 64];

            SwizzleAddr Swizzle = new SwizzleAddr(W, H, 8);

            for (int Y = 0; Y < H; Y++)
            {
                for (int X = 0; X < W; X++)
                {
                    int IOffs = Swizzle.GetSwizzledAddress64(X, Y) * 8;

                    byte[] Red = new byte[8];

                    Red[0] = Tex.Data[IOffs + 0];
                    Red[1] = Tex.Data[IOffs + 1];

                    CalculateBC3Alpha(Red);

                    int RedLow  = Get32(Tex.Data, IOffs + 2);
                    int RedHigh = Get16(Tex.Data, IOffs + 6);

                    ulong RedCh = (uint)RedLow | (ulong)RedHigh << 32;

                    int TOffset = 0;

                    for (int TY = 0; TY < 4; TY++)
                    {
                        for (int TX = 0; TX < 4; TX++)
                        {
                            int OOffset = (X * 4 + TX + (Y * 4 + TY) * W * 4) * 4;

                            byte RedPx = Red[(RedCh >> (TY * 12 + TX * 3)) & 7];

                            Output[OOffset + 0] = RedPx;
                            Output[OOffset + 1] = RedPx;
                            Output[OOffset + 2] = RedPx;
                            Output[OOffset + 3] = 0xff;

                            TOffset += 4;
                        }
                    }
                }
            }

            return(Output);
        }
Exemple #2
0
        public static byte[] DecodeBC1(NsGpuTexture Tex, int Offset)
        {
            int W = (Tex.Width + 3) / 4;
            int H = (Tex.Height + 3) / 4;

            byte[] Output = new byte[W * H * 64];

            SwizzleAddr Swizzle = new SwizzleAddr(W, H, 8);

            for (int Y = 0; Y < H; Y++)
            {
                for (int X = 0; X < W; X++)
                {
                    int IOffs = Offset + Swizzle.GetSwizzledAddress64(X, Y) * 8;

                    byte[] Tile = BCnDecodeTile(Tex.Data, IOffs, true);

                    int TOffset = 0;

                    for (int TY = 0; TY < 4; TY++)
                    {
                        for (int TX = 0; TX < 4; TX++)
                        {
                            int OOffset = (X * 4 + TX + (Y * 4 + TY) * W * 4) * 4;

                            Output[OOffset + 0] = Tile[TOffset + 0];
                            Output[OOffset + 1] = Tile[TOffset + 1];
                            Output[OOffset + 2] = Tile[TOffset + 2];
                            Output[OOffset + 3] = Tile[TOffset + 3];

                            TOffset += 4;
                        }
                    }
                }
            }

            return(Output);
        }