public override void Write(Stream source, Stream destination) { // Writing SVR textures is done through VrSharp, so just pass it to that SvrTextureEncoder texture = new SvrTextureEncoder(source, PixelFormat, DataFormat); if (!texture.Initalized) { throw new TextureNotInitalizedException("Unable to initalize texture."); } texture.HasGlobalIndex = HasGlobalIndex; if (texture.HasGlobalIndex) { texture.GlobalIndex = GlobalIndex; } // If we have an external palette file, save it if (texture.NeedsExternalPalette) { needsExternalPalette = true; PaletteStream = new MemoryStream(); texture.PaletteEncoder.Save(PaletteStream); } else { needsExternalPalette = false; } texture.Save(destination); }
public static void Encode(string[] args) { string outPath = Path.ChangeExtension(args[1], ".svr"); string outPalettePath = Path.ChangeExtension(args[1], ".svp"); SvrTextureEncoder texture = new SvrTextureEncoder(args[1], StringToPixelFormat(args[3]), StringToDataFormat(args[4])); // Was this texture initalized successfully if (!texture.Initalized) { Console.WriteLine("Error: Unable to encode using the specified texture."); return; } // Get arguments for (int i = 5; 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++; } // Change the output path for the palette if (arg == "-op" && args.Length > i + 1) { outPalettePath = args[i + 1]; i++; } // No global index if (arg == "-nogbix") { texture.HasGlobalIndex = false; } // Set global index if (arg == "-gi" && args.Length > i + 1) { uint globalIndex; if (!uint.TryParse(args[i + 1], out globalIndex)) { globalIndex = 0; } texture.GlobalIndex = globalIndex; i++; } } Console.WriteLine("Texture Information"); Console.WriteLine("--------------------"); Console.WriteLine("Format : SVR"); if (texture.HasGlobalIndex) { Console.WriteLine("Global Index : {0}", texture.GlobalIndex); } Console.WriteLine("Dimensions : {0}x{1}", texture.TextureWidth, texture.TextureHeight); Console.WriteLine("Pixel Format : {0}", PixelFormatToString(texture.PixelFormat)); Console.WriteLine("Data Format : {0}", DataFormatToString(texture.DataFormat)); texture.Save(outPath); if (texture.NeedsExternalPalette) { texture.PaletteEncoder.Save(outPalettePath); } Console.WriteLine("\nTexture encoded successfully."); }