示例#1
0
        public DXT3Block(EndianBinaryReader reader, DXTxBlockLayout blockLayout)
        {
            switch (blockLayout)
            {
            case DXTxBlockLayout.Normal:
                Alpha = reader.ReadUInt64();
                Color = new DXT1Block(reader, blockLayout);
                break;

            case DXTxBlockLayout.PSP:
                Color = new DXT1Block(reader, blockLayout);
                Alpha = reader.ReadUInt64();
                break;

            default:
                throw new Exception("Unknown block layout");
            }
        }
示例#2
0
        public DXT5Block(EndianBinaryReader reader, DXTxBlockLayout blockLayout)
        {
            byte bits_5, bits_4, bits_3, bits_2, bits_1, bits_0;

            switch (blockLayout)
            {
            case DXTxBlockLayout.Normal:
                Alpha0 = reader.ReadByte();
                Alpha1 = reader.ReadByte();

                bits_5 = reader.ReadByte();
                bits_4 = reader.ReadByte();
                bits_3 = reader.ReadByte();
                bits_2 = reader.ReadByte();
                bits_1 = reader.ReadByte();
                bits_0 = reader.ReadByte();
                Bits   = DXTx.ExtractBits((((ulong)bits_0 << 40) | ((ulong)bits_1 << 32) | ((ulong)bits_2 << 24) | ((ulong)bits_3 << 16) | ((ulong)bits_4 << 8) | (ulong)bits_5), 3);

                Color = new DXT1Block(reader, blockLayout);
                break;

            case DXTxBlockLayout.PSP:
                Color  = new DXT1Block(reader, blockLayout);
                Alpha0 = reader.ReadByte();
                Alpha1 = reader.ReadByte();

                bits_5 = reader.ReadByte();
                bits_4 = reader.ReadByte();
                bits_3 = reader.ReadByte();
                bits_2 = reader.ReadByte();
                bits_1 = reader.ReadByte();
                bits_0 = reader.ReadByte();
                Bits   = DXTx.ExtractBits((((ulong)bits_0 << 40) | ((ulong)bits_1 << 32) | ((ulong)bits_2 << 24) | ((ulong)bits_3 << 16) | ((ulong)bits_4 << 8) | (ulong)bits_5), 3);
                break;

            default:
                throw new Exception("Unknown block layout");
            }
        }
示例#3
0
        public DXT1Block(EndianBinaryReader reader, DXTxBlockLayout blockLayout)
        {
            byte color0_hi, color0_lo, color1_hi, color1_lo, bits_3, bits_2, bits_1, bits_0;

            switch (blockLayout)
            {
            case DXTxBlockLayout.Normal:
                color0_hi = reader.ReadByte();
                color0_lo = reader.ReadByte();
                color1_hi = reader.ReadByte();
                color1_lo = reader.ReadByte();
                bits_3    = reader.ReadByte();
                bits_2    = reader.ReadByte();
                bits_1    = reader.ReadByte();
                bits_0    = reader.ReadByte();
                break;

            case DXTxBlockLayout.PSP:
                bits_3    = reader.ReadByte();
                bits_2    = reader.ReadByte();
                bits_1    = reader.ReadByte();
                bits_0    = reader.ReadByte();
                color0_hi = reader.ReadByte();
                color0_lo = reader.ReadByte();
                color1_hi = reader.ReadByte();
                color1_lo = reader.ReadByte();
                break;

            default:
                throw new Exception("Unknown block layout");
            }

            Bits   = DXTx.ExtractBits((((uint)bits_0 << 24) | ((uint)bits_1 << 16) | ((uint)bits_2 << 8) | (uint)bits_3), 2);
            Color0 = (ushort)(((ushort)color0_lo << 8) | (ushort)color0_hi);
            Color1 = (ushort)(((ushort)color1_lo << 8) | (ushort)color1_hi);
        }
示例#4
0
        private static byte[] DecodeDXT5Block(EndianBinaryReader reader, PixelDataFormat inputFormat, DXTxBlockLayout blockLayout)
        {
            DXT5Block inBlock = new DXT5Block(reader, blockLayout);

            byte[] outData = DecodeColorBlock(inBlock.Color, false, false);

            for (int y = 0; y < 4; y++)
            {
                for (int x = 0; x < 4; x++)
                {
                    byte code       = inBlock.Bits[(y * 4) + x];
                    int  destOffset = (((y * 4) + x) * 4) + 3;

                    if (inBlock.Alpha0 > inBlock.Alpha1)
                    {
                        switch (code)
                        {
                        case 0x00: outData[destOffset] = inBlock.Alpha0; break;

                        case 0x01: outData[destOffset] = inBlock.Alpha1; break;

                        case 0x02: outData[destOffset] = (byte)((6 * inBlock.Alpha0 + 1 * inBlock.Alpha1) / 7); break;

                        case 0x03: outData[destOffset] = (byte)((5 * inBlock.Alpha0 + 2 * inBlock.Alpha1) / 7); break;

                        case 0x04: outData[destOffset] = (byte)((4 * inBlock.Alpha0 + 3 * inBlock.Alpha1) / 7); break;

                        case 0x05: outData[destOffset] = (byte)((3 * inBlock.Alpha0 + 4 * inBlock.Alpha1) / 7); break;

                        case 0x06: outData[destOffset] = (byte)((2 * inBlock.Alpha0 + 5 * inBlock.Alpha1) / 7); break;

                        case 0x07: outData[destOffset] = (byte)((1 * inBlock.Alpha0 + 6 * inBlock.Alpha1) / 7); break;
                        }
                    }
                    else
                    {
                        switch (code)
                        {
                        case 0x00: outData[destOffset] = inBlock.Alpha0; break;

                        case 0x01: outData[destOffset] = inBlock.Alpha1; break;

                        case 0x02: outData[destOffset] = (byte)((4 * inBlock.Alpha0 + 1 * inBlock.Alpha1) / 5); break;

                        case 0x03: outData[destOffset] = (byte)((3 * inBlock.Alpha0 + 2 * inBlock.Alpha1) / 5); break;

                        case 0x04: outData[destOffset] = (byte)((2 * inBlock.Alpha0 + 3 * inBlock.Alpha1) / 5); break;

                        case 0x05: outData[destOffset] = (byte)((1 * inBlock.Alpha0 + 4 * inBlock.Alpha1) / 5); break;

                        case 0x06: outData[destOffset] = 0x00; break;

                        case 0x07: outData[destOffset] = 0xFF; break;
                        }
                    }
                }
            }

            return(outData);
        }
示例#5
0
        private static byte[] DecodeDXT3Block(EndianBinaryReader reader, PixelDataFormat inputFormat, DXTxBlockLayout blockLayout)
        {
            DXT3Block inBlock = new DXT3Block(reader, blockLayout);

            byte[] outData = DecodeColorBlock(inBlock.Color, false, false);

            ulong alpha = inBlock.Alpha;

            for (int i = 0; i < outData.Length; i += 4)
            {
                outData[i + 3] = (byte)(((alpha & 0xF) << 4) | (alpha & 0xF));
                alpha        >>= 4;
            }

            return(outData);
        }
示例#6
0
        private static byte[] DecodeDXT1Block(EndianBinaryReader reader, PixelDataFormat inputFormat, DXTxBlockLayout blockLayout)
        {
            DXT1Block inBlock = new DXT1Block(reader, blockLayout);

            return(DecodeColorBlock(inBlock, (inputFormat & PixelDataFormat.MaskChannels) != PixelDataFormat.ChannelsRgb, true));
        }