Example #1
0
        // Convert the texture to a bitmap
        public override Bitmap Unpack(ref Stream data)
        {
            try
            {
                PvrTexture TextureInput = new PvrTexture(data.Copy());
                if (TextureInput.NeedsExternalClut())
                {
                    if (PaletteData != null)
                        TextureInput.SetClut(new PvpClut(PaletteData.Copy())); // Texture has an external clut; set it
                    else
                        throw new GraphicFormatNeedsPalette(); // Texture needs an external clut; throw an exception
                }

                return TextureInput.GetTextureAsBitmap();
            }
            catch (GraphicFormatNeedsPalette)
            {
                throw new GraphicFormatNeedsPalette(); // Throw it again
            }
            //catch   { return null; }
            finally { PaletteData = null; }
        }
Example #2
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;
            }