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."); }
public bool EncodeTexture(byte[] BitmapData, string PixelFormatText, string DataFormatText, bool IncludeGI, uint GlobalIndex, out MemoryStream TextureData, out MemoryStream ClutData) { TextureData = null; // Set texture data to null ClutData = null; // Set external clut data to null // We need the width and height, so we will convert it to a bitmap Bitmap BitmapBmp = null; try { BitmapBmp = new Bitmap(new MemoryStream(BitmapData)); } catch { Console.WriteLine("ERROR: Input file is not a valid or supported image."); return false; } // Get the Pixel and Data Formats SvrPixelFormat PixelFormat = GetPixelFormat(PixelFormatText); SvrDataFormat DataFormat = GetDataFormat(DataFormatText, PixelFormat, BitmapBmp.Width, BitmapBmp.Height); if (PixelFormat == SvrPixelFormat.Unknown || DataFormat == SvrDataFormat.Unknown) { Console.WriteLine("ERROR: Unknown pixel or data format."); return false; } // Load the bitmap SvrTextureEncoder SvrTextureEncoder = new SvrTextureEncoder(BitmapBmp, (SvrPixelFormat)PixelFormat, (SvrDataFormat)DataFormat); if (!SvrTextureEncoder.LoadSuccess()) { Console.WriteLine("ERROR: Unable to load image, file is not a supported image,"); Console.WriteLine(" or image cannot be converted to the specified pixel/data formats."); return false; } SvrTextureEncoder.WriteGbix(GlobalIndex); // Output information to the console SvrTextureInfo TextureInfo = (SvrTextureInfo)SvrTextureEncoder.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(); // Encode the texture try { TextureData = SvrTextureEncoder.GetTextureAsStream(); } catch { Console.WriteLine("ERROR: Unable to encode texture."); return false; } // Encode the clut (if it has one) if (SvrTextureEncoder.NeedsExternalClut()) { try { ClutData = SvrTextureEncoder.GetClutAsStream(); } catch { Console.WriteLine("ERROR: Unable to encode clut."); return false; } } return true; }
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); }