Add mesh reading and conversion support

This commit is contained in:
Yukai Li 2021-03-17 03:18:15 -06:00
parent 65dc96c4d6
commit aa1277a4e1
25 changed files with 2212 additions and 9 deletions

View file

@ -10,7 +10,7 @@ namespace LibDgf.Graphics
{
public static class TxmConversion
{
public static void ConvertImageToTxm(string inPath, Stream outStream, byte level = 1, short bufferBase = 0, short paletteBufferBase = 0)
public static void ConvertImageToTxm(string inPath, Stream outStream, byte level = 1, ushort bufferBase = 0, ushort paletteBufferBase = 0)
{
using (var image = Image.Load<Rgba32>(inPath))
{
@ -161,14 +161,22 @@ namespace LibDgf.Graphics
}
public static void ConvertTxmToPng(Stream stream, string outPath)
{
using (var image = ConvertTxmToImage(stream))
{
image.SaveAsPng(outPath);
}
}
public static Image<Rgba32> ConvertTxmToImage(Stream stream)
{
BinaryReader br = new BinaryReader(stream);
TxmHeader imageHeader = new TxmHeader();
imageHeader.Read(br);
Console.WriteLine(imageHeader);
if (imageHeader.Misc != 1)
Console.WriteLine("Different level!");
//if (imageHeader.Misc != 1)
// Console.WriteLine("Different level!");
Image<Rgba32> image;
if (imageHeader.ImageSourcePixelFormat == TxmPixelFormat.PSMT8 || imageHeader.ImageSourcePixelFormat == TxmPixelFormat.PSMT4)
@ -209,8 +217,7 @@ namespace LibDgf.Graphics
throw new NotSupportedException("Unsupported pixel format");
}
image.SaveAsPng(outPath);
image.Dispose();
return image;
}
public static Image<Rgba32> ConvertTxmIndexed8bpp(BinaryReader br, int width, int height, Rgba32[] palette)