public static void Encode(string[] args) { string outPath = Path.ChangeExtension(args[1], ".gvr"); string outPalettePath = Path.ChangeExtension(args[1], ".gvp"); GvrTextureEncoder texture = new GvrTextureEncoder(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; } // GBIX type is GCIX if (arg == "-gcix") { texture.GbixType = GvrGbixType.Gcix; } // 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++; } // Set that the texture has mipmaps if (arg == "-mipmaps") { texture.HasMipmaps = true; } // Set that the texture has an external palette if (arg == "-ep") { texture.NeedsExternalPalette = true; } } 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)); } texture.Save(outPath); if (texture.NeedsExternalPalette) { texture.PaletteEncoder.Save(outPalettePath); } Console.WriteLine("\nTexture encoded successfully."); }
public override void Write(Stream source, Stream destination) { // Writing GVR textures is done through VrSharp, so just pass it to that GvrTextureEncoder texture = new GvrTextureEncoder(source, PaletteFormat, DataFormat); if (!texture.Initalized) { throw new TextureNotInitalizedException("Unable to initalize texture."); } texture.HasGlobalIndex = HasGlobalIndex; if (texture.HasGlobalIndex) { texture.GlobalIndex = GlobalIndex; texture.GbixType = GbixType; } texture.HasMipmaps = HasMipmaps; texture.NeedsExternalPalette = needsExternalPalette; // 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); }