예제 #1
0
        public TPL(Stream stream)
        {
            using (BigEndianReader reader = new BigEndianReader(stream))
            {
                if (reader.ReadUInt32() != _Identifier)
                {
                    throw new InvalidDataException(Strings.InvalidTPL);
                }
                ImageCount  = reader.ReadUInt32();
                TableOffset = reader.ReadUInt32();

                ITableOffsets = new uint[ImageCount];
                PTableOffsets = new uint[ImageCount];

                for (int i = 0; i < ImageCount; i++)
                {
                    ITableOffsets[i] = reader.ReadUInt32();
                    PTableOffsets[i] = reader.ReadUInt32();
                }

                ImageData   = new byte[ImageCount][];
                PaletteData = new byte[ImageCount][];
                for (int i = 0; i < ImageCount; i++)
                {
                    reader.BaseStream.Position = ITableOffsets[i];
                    Height        = reader.ReadUInt16();
                    Width         = reader.ReadUInt16();
                    ImageFormat   = reader.ReadUInt32();
                    ImageOffset   = reader.ReadUInt32();
                    WrapS         = reader.ReadUInt32();
                    WrapT         = reader.ReadUInt32();
                    MinFilter     = reader.ReadUInt32();
                    MagFilter     = reader.ReadUInt32();
                    LODBias       = reader.ReadSingle();
                    EnableEdgeLOD = reader.ReadByte();
                    MinLOD        = reader.ReadByte();
                    MaxLOD        = reader.ReadByte();
                    _Unpacked     = reader.ReadByte();
                    _Format       = ImageDataFormat.GetFormat((int)ImageFormat);
                    int ImageSize = _Format.CalculateDataSize(Width, Height);
                    ImageData[i] = reader.ReadBytes(ImageSize, (int)ImageOffset);
                }

                if (_Format.HasPalette)
                {
                    for (int i = 0; i < ImageCount; i++)
                    {
                        reader.BaseStream.Position = PTableOffsets[i];
                        EntryCount     = reader.ReadUInt16();
                        _Padding       = reader.ReadUInt16();
                        PaletteFormat  = reader.ReadUInt32();
                        PaletteOffset  = reader.ReadUInt32();
                        PaletteData[i] = reader.ReadBytes(EntryCount * 2, (int)PaletteOffset);
                    }
                }
            }
        }
예제 #2
0
        public TXGHeader(BigEndianReader reader)
        {
            ImageCount    = reader.ReadUInt32();
            ImageFormat   = reader.ReadUInt32();
            PaletteFormat = reader.ReadUInt32();
            Width         = reader.ReadUInt32();
            Height        = reader.ReadUInt32();
            SingleImage   = reader.ReadUInt32();
            _Format       = ImageDataFormat.GetFormat((int)ImageFormat);

            ImageData   = new byte[ImageCount][];
            PaletteData = new byte[ImageCount][];
            Console.WriteLine(string.Format(Strings.TXGMessage, ImageCount, ImageFormat, PaletteFormat, Width, Height, Convert.ToBoolean(SingleImage)));
            for (int i = 0; i < ImageCount; i++)
            {
                int ImageSize = _Format.CalculateDataSize((int)Width, (int)Height);
                ImageData[i] = reader.ReadBytes(ImageSize, (int)reader.ReadUInt32());
            }

            if (_Format.HasPalette)
            {
                for (int i = 0; i < ImageCount; i++)
                {
                    int palleteLength = (int)reader.ReadUInt32();
                    if (palleteLength != -1)
                    {
                        PaletteData[i] = reader.ReadBytes(0x200, palleteLength);
                    }
                    else
                    {
                        // Use previous image's palette
                        int previousPaletteLength = PaletteData[i - 1].Length;
                        PaletteData[i] = new byte[previousPaletteLength];
                        Array.Copy(PaletteData[i - 1], PaletteData[i], previousPaletteLength);
                    }
                }
            }
        }