private static void Import(BinaryFormat input, string pngPath, string output, ColorFormat format) { MmTex texture; if (format == ColorFormat.Indexed_A5I3) { texture = input.ConvertWith <Binary2MmTex, BinaryFormat, MmTex>(); } else { texture = input.ConvertWith <Binary2MmTexA3, BinaryFormat, MmTex>(); } input.Dispose(); // Import the new PNG file Bitmap newImage = (Bitmap)Image.FromFile(pngPath); var quantization = new FixedPaletteQuantization(texture.Palette.GetPalette(0)); Texim.Media.Image.ImageConverter importer = new Texim.Media.Image.ImageConverter { Format = format, PixelEncoding = PixelEncoding.Lineal, Quantization = quantization }; (Palette _, PixelArray pixelInfo) = importer.Convert(newImage); texture.Pixels = pixelInfo; // Save the texture texture.ConvertWith <Binary2MmTex, MmTex, BinaryFormat>() .Stream.WriteTo(output); }
/// <summary> /// Creates a Node from a file. /// </summary> /// <returns>The node.</returns> /// <param name="filePath">File path.</param> /// <param name="nodeName">Node name.</param> public static Node FromFile(string filePath, string nodeName) { // We need to catch if the node creation fails // for instance for null names, to dispose the stream. var format = new BinaryFormat(filePath); Node node; try { node = new Node(nodeName, format); } catch { format.Dispose(); throw; } return(node); }
private static void Export(BinaryFormat input, string output, ColorFormat format) { MmTex mmtex; if (format == ColorFormat.Indexed_A5I3) { mmtex = input.ConvertWith <Binary2MmTex, BinaryFormat, MmTex>(); } else { mmtex = input.ConvertWith <Binary2MmTexA3, BinaryFormat, MmTex>(); } input.Dispose(); // To export the image: mmtex.Pixels.CreateBitmap(mmtex.Palette, 0).Save(output); }
public static Node FromFile(string filePath, string nodeName) { // We need to catch if the node creation fails // for instance for null names, to dispose the stream. FileOpenMode mode = FileOpenMode.ReadWrite; var format = new BinaryFormat(DataStreamFactory.FromFile(filePath, mode)); Node node; try { node = new Node(nodeName, format) { Tags = { ["FileInfo"] = new FileInfo(filePath) }, }; } catch { format.Dispose(); throw; } return(node); }
static void ImportEvtChildrenFromXml(Node node, XDocument xml) { JavaClassBinaryConverter javaConverter = new JavaClassBinaryConverter(); foreach (XElement xmlClass in xml.Root.Elements()) { string path = xmlClass.Attribute("class").Value; path = node.Path + NodeSystem.PathSeparator + path; Node child = Navigator.SearchFile(node, path); if (child == null) { throw new Exception(); } // We need to convert from Binary to Binary (skip XML conversion) BinaryFormat originalFormat = child.GetFormatAs <BinaryFormat>(); DataStream originalStream = originalFormat.Stream; javaConverter.OriginalStream = originalStream; child.Format = javaConverter.Convert(xmlClass); originalFormat.Dispose(); } }