Exemple #1
0
        protected override void OnOpen(EndianBinaryReader reader)
        {
            Header = new SceGxtHeader(reader);

            Func <EndianBinaryReader, SceGxtTextureInfo> textureInfoGeneratorFunc;

            switch (Header.Version)
            {
            case 0x10000003: textureInfoGeneratorFunc = new Func <EndianBinaryReader, SceGxtTextureInfo>((r) => { return(new SceGxtTextureInfoV301(r)); }); break;

            case 0x10000002: textureInfoGeneratorFunc = new Func <EndianBinaryReader, SceGxtTextureInfo>((r) => { return(new SceGxtTextureInfoV201(r)); }); break;

            case 0x10000001: textureInfoGeneratorFunc = new Func <EndianBinaryReader, SceGxtTextureInfo>((r) => { return(new SceGxtTextureInfoV101(r)); }); break;

            default: throw new Exception("GXT version not implemented");
            }

            TextureInfos = new SceGxtTextureInfo[Header.NumTextures];
            for (int i = 0; i < TextureInfos.Length; i++)
            {
                TextureInfos[i] = textureInfoGeneratorFunc(reader);
            }

            // TODO: any other way to detect these?
            if (Encoding.ASCII.GetString(reader.ReadBytes(4)) == BUVChunk.ExpectedMagicNumber)
            {
                reader.BaseStream.Seek(-4, SeekOrigin.Current);
                BUVChunk = new BUVChunk(reader);
            }

            ReadAllBasePalettes(reader);
            ReadAllTextures(reader);
        }
Exemple #2
0
        public GxtBinary(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);

            Header = new SceGxtHeader(stream);

            Func <Stream, SceGxtTextureInfo> textureInfoGeneratorFunc;

            switch (Header.Version)
            {
            case 0x10000003: textureInfoGeneratorFunc = new Func <Stream, SceGxtTextureInfo>((s) => { return(new SceGxtTextureInfoV301(s)); }); break;

            case 0x10000002: textureInfoGeneratorFunc = new Func <Stream, SceGxtTextureInfo>((s) => { return(new SceGxtTextureInfoV201(s)); }); break;

            case 0x10000001: textureInfoGeneratorFunc = new Func <Stream, SceGxtTextureInfo>((s) => { return(new SceGxtTextureInfoV101(s)); }); break;

            default: throw new VersionNotImplementedException(Header.Version);
            }

            TextureInfos = new SceGxtTextureInfo[Header.NumTextures];
            for (int i = 0; i < TextureInfos.Length; i++)
            {
                TextureInfos[i] = textureInfoGeneratorFunc(stream);
            }

            // TODO: any other way to detect these?
            if (Encoding.ASCII.GetString(reader.ReadBytes(4)) == BUVChunk.ExpectedMagicNumber)
            {
                stream.Seek(-4, SeekOrigin.Current);
                BUVChunk = new BUVChunk(stream);
            }

            ReadAllBasePalettes(reader);
            ReadAllTextures(reader);

            if (BUVChunk != null)
            {
                // TODO: is it always texture 0?
                TextureBundle bundle = TextureBundles[0];

                BUVTextures = new Bitmap[BUVChunk.Entries.Length];
                for (int i = 0; i < BUVTextures.Length; i++)
                {
                    BUVEntry entry = BUVChunk.Entries[i];
                    using (Bitmap sourceImage = bundle.CreateTexture(FetchPalette(bundle.TextureFormat, entry.PaletteIndex)))
                    {
                        BUVTextures[i] = sourceImage.Clone(new Rectangle(entry.X, entry.Y, entry.Width, entry.Height), sourceImage.PixelFormat);
                    }
                }
            }
        }