private void ReadAllTextures(BinaryReader reader) { TextureBundles = new TextureBundle[TextureInfos.Length]; Textures = new Bitmap[TextureBundles.Length]; for (int i = 0; i < TextureInfos.Length; i++) { TextureBundle bundle = (TextureBundles[i] = new TextureBundle(reader, Header, TextureInfos[i])); Textures[i] = bundle.CreateTexture(FetchPalette(bundle.TextureFormat, bundle.PaletteIndex)); } }
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); } } } }