Ejemplo n.º 1
0
        private void ParseInternal(Stream s)
        {
            using (BinaryReader br = new BinaryReader(s))
            {
                Blp1ImageType compressionType = (Blp1ImageType)br.ReadInt32();
                int           mipmapCount     = br.ReadInt32();

                if (!Enum.IsDefined(typeof(Blp1ImageType), compressionType))
                {
                    throw new InvalidDataException("The file specified an unknown type of BLP1 compression.");
                }
                if (mipmapCount < 0)
                {
                    throw new InvalidDataException("The file specified a negative number of mipmaps, which is invalid.");
                }

                _compressionType = compressionType;

                int sizeX = br.ReadInt32();
                int sizeY = br.ReadInt32();

                Size fullImageSize = new Size(sizeX, sizeY);
                _mainSize = fullImageSize;

                br.ReadInt64(); // skip 'u2';

                int[] offsets = new int[MAX_BLP1_MIPMAP_COUNT];
                int[] sizes   = new int[MAX_BLP1_MIPMAP_COUNT];

                for (int i = 0; i < MAX_BLP1_MIPMAP_COUNT; i++)
                {
                    offsets[i] = br.ReadInt32();
                }

                for (int i = 0; i < MAX_BLP1_MIPMAP_COUNT; i++)
                {
                    sizes[i] = br.ReadInt32();
                }

                if (compressionType == Blp1ImageType.Palette)
                {
                    ParsePalette(br);
                }
                else
                {
                    ParseJpgHeader(s, br);
                }

                for (int i = 0; i < MAX_BLP1_MIPMAP_COUNT; i++)
                {
                    int currentOffset = offsets[i];
                    int currentSize   = sizes[i];

                    if (currentOffset == 0 || currentSize == 0)
                    {
                        break;
                    }

                    Size   mipmapSize = GetSize(fullImageSize, i);
                    byte[] data       = new byte[currentSize];
                    s.Seek(currentOffset, SeekOrigin.Begin);
                    br.Read(data, 0, currentSize);
                    Blp1MipMap mipmap = new Blp1MipMap(mipmapSize, i, data);
                    _mipmaps.Add(mipmap);
                }
            }
        }
Ejemplo n.º 2
0
        private void ParseInternal(Stream s)
        {
            using (BinaryReader br = new BinaryReader(s))
            {
                Blp1ImageType compressionType = (Blp1ImageType)br.ReadInt32();
                int mipmapCount = br.ReadInt32();

                if (!Enum.IsDefined(typeof(Blp1ImageType), compressionType))
                    throw new InvalidDataException("The file specified an unknown type of BLP1 compression.");
                if (mipmapCount < 0)
                    throw new InvalidDataException("The file specified a negative number of mipmaps, which is invalid.");

                _compressionType = compressionType;

                int sizeX = br.ReadInt32();
                int sizeY = br.ReadInt32();

                Size fullImageSize = new Size(sizeX, sizeY);
                _mainSize = fullImageSize;

                br.ReadInt64(); // skip 'u2';

                int[] offsets = new int[MAX_BLP1_MIPMAP_COUNT];
                int[] sizes = new int[MAX_BLP1_MIPMAP_COUNT];

                for (int i = 0; i < MAX_BLP1_MIPMAP_COUNT; i++)
                {
                    offsets[i] = br.ReadInt32();
                }

                for (int i = 0; i < MAX_BLP1_MIPMAP_COUNT; i++)
                {
                    sizes[i] = br.ReadInt32();
                }

                if (compressionType == Blp1ImageType.Palette)
                {
                    ParsePalette(br);
                }
                else
                {
                    ParseJpgHeader(s, br);
                }

                for (int i = 0; i < MAX_BLP1_MIPMAP_COUNT; i++)
                {
                    int currentOffset = offsets[i];
                    int currentSize = sizes[i];

                    if (currentOffset == 0 || currentSize == 0)
                        break;

                    Size mipmapSize = GetSize(fullImageSize, i);
                    byte[] data = new byte[currentSize];
                    s.Seek(currentOffset, SeekOrigin.Begin);
                    br.Read(data, 0, currentSize);
                    Blp1MipMap mipmap = new Blp1MipMap(mipmapSize, i, data);
                    _mipmaps.Add(mipmap);
                }
            }
        }