Skip to content

Commit

Permalink
Actually fix preview and save functions as tga files
Browse files Browse the repository at this point in the history
  • Loading branch information
zzm634 committed Oct 30, 2021
1 parent 152b989 commit 244b123
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
17 changes: 16 additions & 1 deletion UVTextureReverser/ISBitmap.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Tga;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors;
Expand Down Expand Up @@ -109,7 +110,21 @@ public ISBitmap(int width, int height, Color fill)

public void toFile(String path)
{
this.bitmap.Save(path);
if (path.ToLower().EndsWith("tga"))
{
TgaEncoder enc = new TgaEncoder();
enc.BitsPerPixel = TgaBitsPerPixel.Pixel32;
enc.Compression = TgaCompression.None;
using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
{
fs.SetLength(0); // discard contents of file
enc.Encode(this.bitmap, fs);
}
}
else
{
this.bitmap.Save(path);
}
}

public static ISBitmap fromFile(String path)
Expand Down
6 changes: 6 additions & 0 deletions UVTextureReverser/ISTextureScan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,12 @@ public ISBitmap getProjectionMap() {

var map = (new ISBitmap(this.blackScan.width, this.blackScan.height, Color.Transparent)).getRawImage();

// draw the base black image over top at 50% opacity. so that it may more easily be used as a reference
map.Mutate(x =>
{
x.DrawImage(this.blackScan.getRawImage(), 0.5f);
});

/*
map.Mutate(x => {
x.Opacity(254.0f / 255.0f)
Expand Down
3 changes: 2 additions & 1 deletion UVTextureReverser/ProjectionWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ private void ButtonSave_Click(object sender, RoutedEventArgs e) {
int outputResolution = (1 << Int32.Parse((String)this.TextureResolutionCombo.SelectedValue));
try
{
this.texture.scale(outputResolution, outputResolution).toFile(sfd.FileName);
this.texture.scale(outputResolution, outputResolution).toFile(sfd.FileName);


}
catch (Exception ex)
Expand Down

0 comments on commit 244b123

Please sign in to comment.