예제 #1
0
파일: svr.cs 프로젝트: memerdot/puyotools
        // Convert the texture to a bitmap
        public override Bitmap Unpack(ref Stream data)
        {
            try
            {
                SvrTexture TextureInput = new SvrTexture(data.Copy());
                if (TextureInput.NeedsExternalClut())
                {
                    if (PaletteData != null)
                        TextureInput.SetClut(new SvpClut(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; }
        }
예제 #2
0
            public bool DecodeTexture(byte[] VrData, string ClutFile, out MemoryStream BitmapData)
            {
                BitmapData = null; // Set the bitmap data to null for now

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

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

                // Output information to the console
                SvrTextureInfo TextureInfo = (SvrTextureInfo)SvrTexture.GetTextureInfo();
                Console.WriteLine();
                Console.WriteLine("Texture Type : Svr");
                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 = SvrTexture.GetTextureAsStream(); }
                catch
                {
                    Console.WriteLine("ERROR: Unable to decode texture.");
                    return false;
                }

                return true;
            }