/// <summary> /// Decodes a texture from a stream. /// </summary> /// <param name="source">The stream to read from.</param> /// <param name="destination">The stream to write to.</param> /// <param name="length">Number of bytes to read.</param> public override void Read(Stream source, Stream destination) { // Reading GVR textures is done through VrSharp, so just pass it to that VrSharp.GvrTexture.GvrTexture texture = new VrSharp.GvrTexture.GvrTexture(source); // Check to see if this texture requires an external palette and throw an exception // if we do not have one defined if (texture.NeedsExternalPalette) { if (PaletteStream != null) { if (PaletteLength == -1) { texture.SetPalette(new GvpPalette(PaletteStream)); } else { texture.SetPalette(new GvpPalette(PaletteStream, PaletteLength)); } PaletteStream = null; PaletteLength = -1; } else { throw new TextureNeedsPaletteException(); } } texture.Save(destination); }
public bool DecodeTexture(byte[] VrData, string ClutFile, out MemoryStream BitmapData) { BitmapData = null; // Set the bitmap data to null for now // Load the Gvr texture GvrTexture GvrTexture = new GvrTexture(VrData); if (!GvrTexture.LoadSuccess()) { Console.WriteLine("ERROR: Unsupported textue format or unable to load texture."); return false; } // Set the external clut file if (GvrTexture.NeedsExternalClut()) { if (ClutFile == null || !File.Exists(ClutFile)) { Console.WriteLine("ERROR: Texture needs an external clut file."); return false; } GvpClut GvpClut = new GvpClut(ClutFile); if (!GvpClut.LoadSuccess()) { Console.WriteLine("ERROR: Unable to load clut file."); return false; } GvrTexture.SetClut(GvpClut); } // Output information to the console GvrTextureInfo TextureInfo = (GvrTextureInfo)GvrTexture.GetTextureInfo(); Console.WriteLine(); Console.WriteLine("Texture Type : Gvr"); Console.WriteLine("Dimensions : {0}x{1}", TextureInfo.TextureWidth, TextureInfo.TextureHeight); if (TextureInfo.PixelFormat != (byte)GvrPixelFormat.Unknown) 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)); if (TextureInfo.DataFlags != 0x00) Console.WriteLine("Data Flags : {0} ({1})", TextureInfo.DataFlags.ToString("X2"), GetDataFlagsAsText(TextureInfo.DataFlags)); Console.WriteLine(); // Decode the texture try { BitmapData = GvrTexture.GetTextureAsStream(); } catch { Console.WriteLine("ERROR: Unable to decode texture."); return false; } return true; }
public static void Information(string[] args) { GvrTexture texture; // Initalize the texture try { texture = new GvrTexture(args[1]); } catch (NotAValidTextureException) { Console.WriteLine("Error: This is not a valid GVR texture."); return; } Console.WriteLine("Texture Information"); Console.WriteLine("--------------------"); Console.WriteLine("Format : GVR"); if (texture.HasGlobalIndex) { Console.WriteLine("Global Index : {0}", texture.GlobalIndex); } Console.WriteLine("Dimensions : {0}x{1}", texture.TextureWidth, texture.TextureHeight); if (texture.PixelFormat != GvrPixelFormat.Unknown) { Console.WriteLine("Palette Format : {0}", PixelFormatToString(texture.PixelFormat)); } Console.WriteLine("Data Format : {0}", DataFormatToString(texture.DataFormat)); if (texture.DataFlags != GvrDataFlags.None) { Console.WriteLine("Data Flags : {0}", DataFlagsToString(texture.DataFlags)); } }
public static void Decode(string[] args) { string inPalettePath = Path.ChangeExtension(args[1], ".gvp"); string outPath = Path.ChangeExtension(args[1], ".png"); // Get arguments for (int i = 2; i < args.Length; i++) { string arg = args[i].ToLower(); // Change the output path if (arg == "-o" && args.Length > i + 1) { outPath = args[i + 1]; i++; } // Palette path if (arg == "-p" && args.Length > i + 1) { inPalettePath = args[i + 1]; i++; } } GvrTexture texture; // Initalize the texture try { texture = new GvrTexture(args[1]); } catch (NotAValidTextureException) { Console.WriteLine("Error: This is not a valid GVR texture."); return; } Console.WriteLine("Texture Information"); Console.WriteLine("--------------------"); Console.WriteLine("Format : GVR"); if (texture.HasGlobalIndex) { Console.WriteLine("Global Index : {0}", texture.GlobalIndex); } Console.WriteLine("Dimensions : {0}x{1}", texture.TextureWidth, texture.TextureHeight); if (texture.PixelFormat != GvrPixelFormat.Unknown) { Console.WriteLine("Palette Format : {0}", PixelFormatToString(texture.PixelFormat)); } Console.WriteLine("Data Format : {0}", DataFormatToString(texture.DataFormat)); if (texture.DataFlags != GvrDataFlags.None) { Console.WriteLine("Data Flags : {0}", DataFlagsToString(texture.DataFlags)); } // Decode the texture try { texture.Save(outPath); } catch (CannotDecodeTextureException) { Console.WriteLine("Error: Unable to decode this texture. The texture's palette format or data format may not be supported."); return; } Console.WriteLine("\nTexture decoded successfully."); }
/// <summary> /// Decodes a texture from a stream. /// </summary> /// <param name="source">The stream to read from.</param> /// <param name="destination">The stream to write to.</param> /// <param name="length">Number of bytes to read.</param> public override void Read(Stream source, Stream destination) { // Reading GVR textures is done through VrSharp, so just pass it to that VrSharp.GvrTexture.GvrTexture texture = new VrSharp.GvrTexture.GvrTexture(source); // Check to see if this texture requires an external palette and throw an exception // if we do not have one defined if (texture.NeedsExternalPalette) { if (PaletteStream != null) { if (PaletteLength == -1) { texture.SetPalette(new GvpPalette(PaletteStream)); } else { texture.SetPalette(new GvpPalette(PaletteStream, PaletteLength)); } PaletteStream = null; PaletteLength = -1; } else { throw new TextureNeedsPaletteException(); } } texture.Save(destination); }