コード例 #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);
        }
コード例 #2
0
ファイル: TextureBundle.cs プロジェクト: 491467928/GXTConvert
        public TextureBundle(BinaryReader reader, SceGxtHeader header, SceGxtTextureInfo info)
        {
            reader.BaseStream.Seek(info.DataOffset, SeekOrigin.Begin);

            Width         = info.GetWidth();
            Height        = info.GetHeight();
            PaletteIndex  = info.PaletteIndex;
            RawLineSize   = (int)(info.DataSize / info.GetHeightRounded());
            TextureFormat = info.GetTextureFormat();

            RoundedWidth  = info.GetWidthRounded();
            RoundedHeight = info.GetHeightRounded();

            if (!PixelDataProviders.PixelFormatMap.ContainsKey(TextureFormat) || !PixelDataProviders.ProviderFunctions.ContainsKey(TextureFormat))
            {
                throw new FormatNotImplementedException(TextureFormat);
            }

            PixelFormat = PixelDataProviders.PixelFormatMap[TextureFormat];
            PixelData   = PixelDataProviders.ProviderFunctions[TextureFormat](reader, info);

            SceGxmTextureBaseFormat textureBaseFormat = info.GetTextureBaseFormat();

            // TODO: is this right? PVRTC/PVRTC2 doesn't need this, but everything else does?
            if (textureBaseFormat != SceGxmTextureBaseFormat.PVRT2BPP && textureBaseFormat != SceGxmTextureBaseFormat.PVRT4BPP &&
                textureBaseFormat != SceGxmTextureBaseFormat.PVRTII2BPP && textureBaseFormat != SceGxmTextureBaseFormat.PVRTII4BPP)
            {
                SceGxmTextureType textureType = info.GetTextureType();
                switch (textureType)
                {
                case SceGxmTextureType.Linear:
                    // Nothing to be done!
                    break;

                case SceGxmTextureType.Tiled:
                    // TODO: verify me!
                    PixelData = PostProcessing.UntileTexture(PixelData, info.GetWidthRounded(), info.GetHeightRounded(), PixelFormat);
                    break;

                case SceGxmTextureType.Swizzled:
                case SceGxmTextureType.Cube:
                    // TODO: is cube really the same as swizzled? seems that way from CS' *env* files...
                    PixelData = PostProcessing.UnswizzleTexture(PixelData, info.GetWidthRounded(), info.GetHeightRounded(), PixelFormat);
                    break;

                case (SceGxmTextureType)0xA0000000:
                    // TODO: mehhhhh
                    PixelData = PostProcessing.UnswizzleTexture(PixelData, info.GetWidthRounded(), info.GetHeightRounded(), PixelFormat);
                    break;

                default:
                    throw new TypeNotImplementedException(textureType);
                }
            }
        }