示例#1
0
        public Bitmap GenerateBitmap()
        {
            Reader.BaseStream.Position = DataOffset;

            switch (Format)
            {
            case VTexFormat.RGBA8888:
                for (ushort i = 0; i < Depth && i < 0xFF; ++i)
                {
                    // Horribly skip all mipmaps
                    // TODO: Either this needs to be optimized, or allow saving each individual mipmap
                    for (var j = NumMipLevels; j > 0; j--)
                    {
                        if (j == 1)
                        {
                            break;
                        }

                        for (var k = 0; k < Height / Math.Pow(2.0, j - 1); ++k)
                        {
                            Reader.BaseStream.Position += (int)((4 * Width) / Math.Pow(2.0f, j - 1));
                        }
                    }

                    return(ReadRGBA8888(Reader, Width, Height));
                }

                break;

            case VTexFormat.RGBA16161616F:
                return(ReadRGBA16161616F(Reader, Width, Height));

            case VTexFormat.DXT1:
                for (ushort i = 0; i < Depth && i < 0xFF; ++i)
                {
                    // Horribly skip all mipmaps
                    // TODO: Either this needs to be optimized, or allow saving each individual mipmap
                    for (var j = NumMipLevels; j > 0; j--)
                    {
                        if (j == 1)
                        {
                            break;
                        }

                        for (var k = 0; k < Height / Math.Pow(2.0, j + 1); ++k)
                        {
                            for (var l = 0; l < Width / Math.Pow(2.0, j + 1); ++l)
                            {
                                Reader.BaseStream.Position += 8;
                            }
                        }
                    }

                    return(DDSImage.UncompressDXT1(Reader, Width, Height));
                }

                break;

            case VTexFormat.DXT5:
                var yCoCg = false;

                if (Resource.EditInfo.Structs.ContainsKey(ResourceEditInfo.REDIStruct.SpecialDependencies))
                {
                    var specialDeps = (SpecialDependencies)Resource.EditInfo.Structs[ResourceEditInfo.REDIStruct.SpecialDependencies];

                    foreach (var dependancy in specialDeps.List)
                    {
                        if (dependancy.CompilerIdentifier == "CompileTexture" && dependancy.String == "Texture Compiler Version Image YCoCg Conversion")
                        {
                            yCoCg = true;

                            break;
                        }
                    }
                }

                for (ushort i = 0; i < Depth && i < 0xFF; ++i)
                {
                    // Horribly skip all mipmaps
                    // TODO: Either this needs to be optimized, or allow saving each individual mipmap
                    for (var j = NumMipLevels; j > 0; j--)
                    {
                        if (j == 1)
                        {
                            break;
                        }

                        for (var k = 0; k < Height / Math.Pow(2.0, j + 1); ++k)
                        {
                            for (var l = 0; l < Width / Math.Pow(2.0, j + 1); ++l)
                            {
                                Reader.BaseStream.Position += 16;
                            }
                        }
                    }

                    return(DDSImage.UncompressDXT5(Reader, Width, Height, yCoCg));
                }

                break;

            case (VTexFormat)17:
            case (VTexFormat)18:
            case VTexFormat.PNG:
                return(ReadPNG());
            }

            throw new NotImplementedException(string.Format("Unhandled image type: {0}", Format));
        }