Example #1
0
            public bool DecodeTexture(byte[] VrData, string ClutFile, out MemoryStream BitmapData)
            {
                BitmapData = null; // Set the bitmap data to null for now

                // Load the Pvr texture
                PvrTexture PvrTexture = new PvrTexture(VrData);
                if (!PvrTexture.LoadSuccess())
                {
                    Console.WriteLine("ERROR: Unsupported textue format or unable to load texture.");
                    return false;
                }

                // Set the external clut file
                if (PvrTexture.NeedsExternalClut())
                {
                    if (ClutFile == null || !File.Exists(ClutFile))
                    {
                        Console.WriteLine("ERROR: Texture needs an external clut file.");
                        return false;
                    }
                    PvpClut PvpClut = new PvpClut(ClutFile);
                    if (!PvpClut.LoadSuccess())
                    {
                        Console.WriteLine("ERROR: Unable to load clut file.");
                        return false;
                    }
                    PvrTexture.SetClut(PvpClut);
                }

                // Output information to the console
                PvrTextureInfo TextureInfo = (PvrTextureInfo)PvrTexture.GetTextureInfo();
                Console.WriteLine();
                Console.WriteLine("Texture Type : Pvr");
                if (TextureInfo.CompressionFormat != PvrCompressionFormat.None)
                    Console.WriteLine("Compression  : {0}",   TextureInfo.CompressionFormat);
                Console.WriteLine("Dimensions   : {0}x{1}",   TextureInfo.TextureWidth, TextureInfo.TextureHeight);
                Console.WriteLine("Pixel Format : {0} ({1})", TextureInfo.PixelFormat.ToString("X2"), GetPixelFormatAsText(TextureInfo.PixelFormat));
                Console.WriteLine("Data Format  : {0} ({1})", TextureInfo.DataFormat.ToString("X2"),  GetDataFormatAsText(TextureInfo.DataFormat));
                Console.WriteLine();

                // Decode the texture
                try { BitmapData = PvrTexture.GetTextureAsStream(); }
                catch
                {
                    Console.WriteLine("ERROR: Unable to decode texture.");
                    return false;
                }

                return true;
            }