mirror of
https://github.com/AssetRipper/AssetRipper.TextureDecoder.git
synced 2026-11-13 04:26:30 -10:00
Add methods to DirectBitmap
This commit is contained in:
1 parent
d6ad4d5a6f
commit
2085dbcce4
1 file changed
+76
@@ -43,6 +43,63 @@ public struct DirectBitmap<TColor, TColorArg>
|
||||
}
|
||||
}
|
||||
|
||||
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<TColor, TColorArg, ColorRGBA32, byte>(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<TColor, TColorArg, ColorRGBA32, byte>(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<TColor, TColorArg, ColorRGBA32, byte>(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<TColor, TColorArg>
|
||||
}
|
||||
}
|
||||
|
||||
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<TColor, TColorArg, ColorRGBA32, byte>(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);
|
||||
|
||||
Reference in new issue
Block a user