diff --git a/AssetRipper.TextureDecoder.ConsoleApp/DirectBitmap.cs b/AssetRipper.TextureDecoder.ConsoleApp/DirectBitmap.cs index 8913e14..b596ff0 100644 --- a/AssetRipper.TextureDecoder.ConsoleApp/DirectBitmap.cs +++ b/AssetRipper.TextureDecoder.ConsoleApp/DirectBitmap.cs @@ -43,6 +43,63 @@ public struct DirectBitmap } } + public void SaveAsBmp(string path) + { + using Stream stream = File.OpenWrite(path); + ImageWriter writer = new(); + if (typeof(TColor) == typeof(ColorRGBA32)) + { + writer.WriteBmp(Data, Width, Height, ColorComponents.RedGreenBlueAlpha, stream); + } + else if (typeof(TColor) == typeof(ColorRGB24)) + { + writer.WriteBmp(Data, Width, Height, ColorComponents.RedGreenBlue, stream); + } + else + { + RgbConverter.Convert(Bits, Width, Height, out byte[] output); + writer.WriteBmp(output, Width, Height, ColorComponents.RedGreenBlueAlpha, stream); + } + } + + public void SaveAsHdr(string path) + { + using Stream stream = File.OpenWrite(path); + ImageWriter writer = new(); + if (typeof(TColor) == typeof(ColorRGBA32)) + { + writer.WriteHdr(Data, Width, Height, ColorComponents.RedGreenBlueAlpha, stream); + } + else if (typeof(TColor) == typeof(ColorRGB24)) + { + writer.WriteHdr(Data, Width, Height, ColorComponents.RedGreenBlue, stream); + } + else + { + RgbConverter.Convert(Bits, Width, Height, out byte[] output); + writer.WriteHdr(output, Width, Height, ColorComponents.RedGreenBlueAlpha, stream); + } + } + + public void SaveAsJpg(string path) + { + using Stream stream = File.OpenWrite(path); + ImageWriter writer = new(); + if (typeof(TColor) == typeof(ColorRGBA32)) + { + writer.WriteJpg(Data, Width, Height, ColorComponents.RedGreenBlueAlpha, stream, default); + } + else if (typeof(TColor) == typeof(ColorRGB24)) + { + writer.WriteJpg(Data, Width, Height, ColorComponents.RedGreenBlue, stream, default); + } + else + { + RgbConverter.Convert(Bits, Width, Height, out byte[] output); + writer.WriteJpg(output, Width, Height, ColorComponents.RedGreenBlueAlpha, stream, default); + } + } + public void SaveAsPng(string path) { using Stream stream = File.OpenWrite(path); @@ -62,6 +119,25 @@ public struct DirectBitmap } } + public void SaveAsTga(string path) + { + using Stream stream = File.OpenWrite(path); + ImageWriter writer = new(); + if (typeof(TColor) == typeof(ColorRGBA32)) + { + writer.WriteTga(Data, Width, Height, ColorComponents.RedGreenBlueAlpha, stream); + } + else if (typeof(TColor) == typeof(ColorRGB24)) + { + writer.WriteTga(Data, Width, Height, ColorComponents.RedGreenBlue, stream); + } + else + { + RgbConverter.Convert(Bits, Width, Height, out byte[] output); + writer.WriteTga(output, Width, Height, ColorComponents.RedGreenBlueAlpha, stream); + } + } + public int Height { get; } public int Width { get; } public int ByteSize => CalculateByteSize(Width, Height);