예제 #1
0
        public g1tTexture(Stream stream, EndianUtils.Endianness endian)
        {
            Mipmaps = (byte)stream.ReadByte();
            byte format     = (byte)stream.ReadByte();
            byte dimensions = (byte)stream.ReadByte();
            byte unknown4   = (byte)stream.ReadByte();
            byte unknown5   = (byte)stream.ReadByte();
            byte unknown6   = (byte)stream.ReadByte();
            byte unknown7   = (byte)stream.ReadByte();
            byte unknown8   = (byte)stream.ReadByte();

            if (endian == EndianUtils.Endianness.LittleEndian)
            {
                Mipmaps    = Mipmaps.SwapEndian4Bits();
                dimensions = dimensions.SwapEndian4Bits();
                unknown4   = unknown4.SwapEndian4Bits();
                unknown5   = unknown5.SwapEndian4Bits();
                unknown6   = unknown6.SwapEndian4Bits();
                unknown7   = unknown7.SwapEndian4Bits();
                unknown8   = unknown8.SwapEndian4Bits();
            }

            if (unknown8 == 0x01)
            {
                stream.DiscardBytes(0x0C);
            }

            switch (format)
            {
            case 0x00: Format = Textures.TextureFormat.ABGR; BitPerPixel = 32; break;

            case 0x01: Format = Textures.TextureFormat.RGBA; BitPerPixel = 32; break;

            case 0x06: Format = Textures.TextureFormat.DXT1a; BitPerPixel = 4; break;

            case 0x08: Format = Textures.TextureFormat.DXT5; BitPerPixel = 8; break;

            case 0x12: Format = Textures.TextureFormat.DXT5; BitPerPixel = 8; break;                     // swizzled from vita

            case 0x5B: Format = Textures.TextureFormat.DXT5; BitPerPixel = 8; break;                     // unsure what the difference to 0x08 is

            default: throw new Exception(String.Format("g1t: Unknown Format ({0:X2})", format));
            }

            Width  = (uint)(1 << (dimensions >> 4));
            Height = (uint)(1 << (dimensions & 0x0F));

            uint highestMipmapSize = (Width * Height * BitPerPixel) / 8;
            long textureSize       = highestMipmapSize;

            for (int i = 0; i < Mipmaps - 1; ++i)
            {
                textureSize += highestMipmapSize / (4 << (i * 2));
            }

            Data = new byte[textureSize];
            stream.Read(Data, 0, Data.Length);
        }
예제 #2
0
        public g1tTexture( Stream stream, Util.Endianness endian )
        {
            Mipmaps = (byte)stream.ReadByte();
            byte format = (byte)stream.ReadByte();
            byte dimensions = (byte)stream.ReadByte();
            byte unknown4 = (byte)stream.ReadByte();
            byte unknown5 = (byte)stream.ReadByte();
            byte unknown6 = (byte)stream.ReadByte();
            byte unknown7 = (byte)stream.ReadByte();
            byte unknown8 = (byte)stream.ReadByte();

            if ( endian == Util.Endianness.LittleEndian ) {
                Mipmaps = Mipmaps.SwapEndian4Bits();
                dimensions = dimensions.SwapEndian4Bits();
                unknown4 = unknown4.SwapEndian4Bits();
                unknown5 = unknown5.SwapEndian4Bits();
                unknown6 = unknown6.SwapEndian4Bits();
                unknown7 = unknown7.SwapEndian4Bits();
                unknown8 = unknown8.SwapEndian4Bits();
            }

            if ( unknown8 == 0x01 ) {
                stream.DiscardBytes( 0x0C );
            }

            switch ( format ) {
                case 0x00: Format = Textures.TextureFormat.ABGR; BitPerPixel = 32; break;
                case 0x01: Format = Textures.TextureFormat.RGBA; BitPerPixel = 32; break;
                case 0x06: Format = Textures.TextureFormat.DXT1; BitPerPixel = 4; break;
                case 0x08: Format = Textures.TextureFormat.DXT5; BitPerPixel = 8; break;
                default: throw new Exception( String.Format( "g1t: Unknown Format ({0:X2})", format ) );
            }

            Width = (uint)( 1 << ( dimensions >> 4 ) );
            Height = (uint)( 1 << ( dimensions & 0x0F ) );

            uint highestMipmapSize = ( Width * Height * BitPerPixel ) / 8;
            long textureSize = highestMipmapSize;
            for ( int i = 0; i < Mipmaps - 1; ++i ) {
                textureSize += highestMipmapSize / ( 4 << ( i * 2 ) );
            }

            Data = new byte[textureSize];
            stream.Read( Data, 0, Data.Length );
        }