Example #1
0
        private static byte[] DecodeRGTC1Block(EndianBinaryReader reader, PixelDataFormat inputFormat, DXTxRGTCBlockLayout blockLayout, DXTxRGTCSignedness signedness)
        {
            RGTCBlock inBlock = new RGTCBlock(reader, blockLayout);

            byte[] outData = new byte[(4 * 4) * 4];

            for (int y = 0; y < 4; y++)
            {
                for (int x = 0; x < 4; x++)
                {
                    int destOffset = (((y * 4) + x) * 4);
                    outData[destOffset + 0] = DecodeRGTCValue(inBlock, x, y, signedness);
                    outData[destOffset + 1] = 0x00;
                    outData[destOffset + 2] = 0x00;
                    outData[destOffset + 3] = 0xFF;
                }
            }

            return(outData);
        }
Example #2
0
        private static byte DecodeRGTCValue(RGTCBlock inBlock, int x, int y, DXTxRGTCSignedness signedness)
        {
            int code = inBlock.Bits[(y * 4) + x];

            byte data0, data1;

            if (signedness == DXTxRGTCSignedness.Unsigned)
            {
                data0 = inBlock.Data0;
                data1 = inBlock.Data1;
            }
            else
            {
                data0 = (byte)(((sbyte)inBlock.Data0) + 128);
                data1 = (byte)(((sbyte)inBlock.Data1) + 128);
            }

            if (data0 > data1)
            {
                switch (code)
                {
                case 0x00: return(data0);

                case 0x01: return(data1);

                case 0x02: return((byte)((6 * data0 + 1 * data1) / 7));

                case 0x03: return((byte)((5 * data0 + 2 * data1) / 7));

                case 0x04: return((byte)((4 * data0 + 3 * data1) / 7));

                case 0x05: return((byte)((3 * data0 + 4 * data1) / 7));

                case 0x06: return((byte)((2 * data0 + 5 * data1) / 7));

                case 0x07: return((byte)((1 * data0 + 6 * data1) / 7));
                }
            }
            else
            {
                switch (code)
                {
                case 0x00: return(data0);

                case 0x01: return(data1);

                case 0x02: return((byte)((4 * data0 + 1 * data1) / 5));

                case 0x03: return((byte)((3 * data0 + 2 * data1) / 5));

                case 0x04: return((byte)((2 * data0 + 3 * data1) / 5));

                case 0x05: return((byte)((1 * data0 + 4 * data1) / 5));

                case 0x06: return(0x00);

                case 0x07: return(0xFF);
                }
            }

            throw new Exception("RGTC value decode exception; this shouldn't happen!");
        }