Skip to content

Commit

Permalink
v3.5.5
Browse files Browse the repository at this point in the history
- **File formats:**
   - (Add) `LayerImageType`: Gets the layer image data type used on this file format
   - (Improvement) jxs, rgb.cws and xml.cws: Improve the layer image read/write performance by a significant amount
   - (Fix) xml.cws: Wanhao printers need 32 bit png instead of 8 bit png (#514)
  • Loading branch information
sn4k3 committed Jul 18, 2022
1 parent 521fb58 commit 315ce3b
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 124 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 18/07/2022 - v3.5.5

- **File formats:**
- (Add) `LayerImageType`: Gets the layer image data type used on this file format
- (Improvement) jxs, rgb.cws and xml.cws: Improve the layer image read/write performance by a significant amount
- (Fix) xml.cws: Wanhao printers need 32 bit png instead of 8 bit png (#514)

## 14/07/2022 - v3.5.4

- **PCB Exposure:**
Expand Down
17 changes: 5 additions & 12 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
- **PCB Exposure:**
- (Add) Parse of deprecated commands (G70, G71, G90, G91)
- (Fix) Able to have parameterless macro apertures (#503)
- **UI:**
- (Add) Menu -> File -> Free unused RAM: Force the garbage collection of all unused objects within the program to free unused memory (RAM).
It's never required for the end user run this. The program will automatically take care of it when required.
This function is for debug purposes.
- (Improvement) Window title bar: Show elapsed minutes and seconds instead of total seconds minutes and second
- (Fix) Tool - Mask: Loaded image resolution shows as (unloaded)
- (Fix) Applying a large set of modifications in layer depth with pixel editor cause huge memory spike due layer aggregation without disposing, leading to program crash on most cases where RAM is insufficient (#506)
- (Upgrade) AvaloniaUI from 0.10.15 to 0.10.16
- (Upgrade) .NET from 6.0.6 to 6.0.7
- **File formats:**
- (Add) `LayerImageType`: Gets the layer image data type used on this file format
- (Improvement) jxs, rgb.cws and xml.cws: Improve the layer image read/write performance by a significant amount
- (Fix) xml.cws: Wanhao printers need 32 bit png instead of 8 bit png (#514)

78 changes: 11 additions & 67 deletions UVtools.Core/FileFormats/CWSFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,14 @@ public class Slice

public override FileFormatType FileType => FileFormatType.Archive;

public override FileImageType LayerImageType =>
Printer switch
{
PrinterType.BeneMono => FileImageType.Png24BgrAA,
PrinterType.Wanhao => FileImageType.Png32,
_ => FileImageType.Png8
};

public enum PrinterType : byte
{
Unknown,
Expand Down Expand Up @@ -658,49 +666,7 @@ protected override void EncodeInternally(OperationProgress progress)
}
}

if (Printer == PrinterType.BeneMono)
{
EncodeLayersInZip(outputFile, filename, LayerDigits, IndexStartNumber.Zero, progress, matGenFunc:
(_, mat) =>
{
var bgrMat = new Mat(mat.Height, mat.GetRealStep() / 3, DepthType.Cv8U, 3);
var bgrMatSpan = bgrMat.GetDataByteSpan();
var greySpan = mat.GetDataByteSpan();
for (int i = 0; i < greySpan.Length; i++)
{
bgrMatSpan[i] = greySpan[i];
}
return bgrMat;
});
/*Parallel.For(0, LayerCount, CoreSettings.GetParallelOptions(progress),
//new ParallelOptions { MaxDegreeOfParallelism = Printer == PrinterType.BeneMono ? 1 : 1 },
layerIndex =>
{
var layer = this[layerIndex];
var layerImagePath = layer.FormatFileNameWithLayerDigits(filename);
using var mat = layer.LayerMat;
using var matEncode = new Mat(mat.Height, mat.GetRealStep() / 3, DepthType.Cv8U, 3);
var span = mat.GetDataByteSpan();
var spanEncode = matEncode.GetDataByteSpan();
for (int i = 0; i < span.Length; i++)
{
spanEncode[i] = span[i];
}
var bytes = matEncode.GetPngByes();
lock (progress.Mutex)
{
outputFile.PutFileContent(layerImagePath, bytes, ZipArchiveMode.Create);
progress++;
}
});*/
}
else
{
EncodeLayersInZip(outputFile, filename, LayerDigits, IndexStartNumber.Zero, progress);
}
EncodeLayersInZip(outputFile, filename, LayerDigits, IndexStartNumber.Zero, progress);

RebuildGCode();
outputFile.PutFileContent($"{filename}.gcode", GCodeStr, ZipArchiveMode.Create);
Expand Down Expand Up @@ -861,31 +827,9 @@ protected override void DecodeInternally(OperationProgress progress)
}
}

if (Printer == PrinterType.BeneMono)
{
DecodeLayersFromZipRegex(inputFile, @"(\d+).png", IndexStartNumber.Zero, progress,
(layerIndex, pngBytes) =>
{
using Mat bgrMat = new();
CvInvoke.Imdecode(pngBytes, ImreadModes.AnyColor, bgrMat);
var greyMat = new Mat(bgrMat.Height, bgrMat.GetRealStep(), DepthType.Cv8U, 1);
var bgrSpan = bgrMat.GetDataByteSpan();
var greySpan = greyMat.GetDataByteSpan();
for (int i = 0; i < bgrSpan.Length; i++)
{
greySpan[i] = bgrSpan[i];
}
return greyMat;
});
}
else
{
DecodeLayersFromZipRegex(inputFile, @"(\d+).png", IndexStartNumber.Zero, progress);
}

GCode.ParseLayersFromGCode(this);
DecodeLayersFromZipRegex(inputFile, @"(\d+).png", IndexStartNumber.Zero, progress);

GCode.ParseLayersFromGCode(this);
}

public override void RebuildGCode()
Expand Down
98 changes: 96 additions & 2 deletions UVtools.Core/FileFormats/FileFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,26 @@ public enum FileDecodeType : byte
Partial,
}

/// <summary>
/// Image data type
/// </summary>
public enum FileImageType : byte
{
Custom,
Png8,
Png24,
Png32,
/// <summary>
/// eg: Nova Bene4
/// </summary>
Png24BgrAA,
/// <summary>
/// eg: Uniformation GKone
/// </summary>
Png24RgbAA,

}

#endregion

#region Sub Classes
Expand Down Expand Up @@ -1022,6 +1042,11 @@ public static int MutateGetIterationChamfer(uint layerIndex, uint startLayerInde
/// </summary>
public abstract FileFormatType FileType { get; }

/// <summary>
/// Gets the layer image data type used on this file format
/// </summary>
public virtual FileImageType LayerImageType => FileType == FileFormatType.Archive ? FileImageType.Png8 : FileImageType.Custom;

/// <summary>
/// Gets the valid file extensions for this <see cref="FileFormat"/>
/// </summary>
Expand Down Expand Up @@ -3416,13 +3441,54 @@ public void EncodeLayersInZip(ZipArchive zipArchive, string prepend, byte padDig
progress.Reset(OperationProgress.StatusEncodeLayers, LayerCount);
var batches = BatchLayersIndexes();
var pngLayerBytes = new byte[LayerCount][];

var layerImageType = LayerImageType;

foreach (var batch in batches)
{
Parallel.ForEach(batch, CoreSettings.GetParallelOptions(progress), layerIndex =>
{
if (matGenFunc is null)
{
pngLayerBytes[layerIndex] = this[layerIndex].CompressedPngBytes!;
switch (layerImageType)
{
case FileImageType.Png24:
{
using var mat = this[layerIndex].LayerMat;
CvInvoke.CvtColor(mat, mat, ColorConversion.Gray2Bgr);
pngLayerBytes[layerIndex] = mat.GetPngByes();
break;
}
case FileImageType.Png32:
{
using var mat = this[layerIndex].LayerMat;
CvInvoke.CvtColor(mat, mat, ColorConversion.Gray2Bgra);
pngLayerBytes[layerIndex] = mat.GetPngByes();
break;
}
case FileImageType.Png24BgrAA:
{
using var mat = this[layerIndex].LayerMat;
using var outputMat = mat.Reshape(3);
pngLayerBytes[layerIndex] = outputMat.GetPngByes();
break;
}
case FileImageType.Png24RgbAA:
{
using var mat = this[layerIndex].LayerMat;
using var outputMat = mat.Reshape(3);
CvInvoke.CvtColor(outputMat, outputMat, ColorConversion.Bgr2Rgb);
pngLayerBytes[layerIndex] = outputMat.GetPngByes();
break;
}
default:
pngLayerBytes[layerIndex] = this[layerIndex].CompressedPngBytes!;
break;
}
}
else
{
Expand Down Expand Up @@ -3461,6 +3527,8 @@ public void DecodeLayersFromZip(ZipArchiveEntry[] layerEntries, OperationProgres
progress ??= new OperationProgress();
progress.Reset(OperationProgress.StatusDecodeLayers, LayerCount);

var layerImageType = LayerImageType;

Parallel.For(0, LayerCount, CoreSettings.GetParallelOptions(progress), layerIndex =>
{
byte[] pngBytes;
Expand All @@ -3472,7 +3540,33 @@ public void DecodeLayersFromZip(ZipArchiveEntry[] layerEntries, OperationProgres
if (matGenFunc is null)
{
_layers[layerIndex] = new Layer((uint)layerIndex, pngBytes, this);
switch (layerImageType)
{
case FileImageType.Png24BgrAA:
{
using var bgrMat = new Mat();
CvInvoke.Imdecode(pngBytes, ImreadModes.Color, bgrMat);
using var greyMat = bgrMat.Reshape(1);
_layers[layerIndex] = new Layer((uint) layerIndex, greyMat, this);
break;
}
case FileImageType.Png24RgbAA:
{
using Mat rgbMat = new();
CvInvoke.Imdecode(pngBytes, ImreadModes.Color, rgbMat);
CvInvoke.CvtColor(rgbMat, rgbMat, ColorConversion.Bgr2Rgb);
using var greyMat = rgbMat.Reshape(1);
_layers[layerIndex] = new Layer((uint)layerIndex, greyMat, this);
break;
}
default:
_layers[layerIndex] = new Layer((uint)layerIndex, pngBytes, this);
break;
}
}
else
{
Expand Down
43 changes: 4 additions & 39 deletions UVtools.Core/FileFormats/JXSFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public sealed class JXSControl

public override FileFormatType FileType => FileFormatType.Archive;

public override FileImageType LayerImageType => FileImageType.Png24RgbAA;

public override FileExtension[] FileExtensions { get; } = {
new(typeof(JXSFile), "jxs", "Uniformation GKone (JXS)")
};
Expand Down Expand Up @@ -510,27 +512,8 @@ protected override void DecodeInternally(OperationProgress progress)
}

Init(ConfigFile.LayerCount, DecodeType == FileDecodeType.Partial);
sbyte[] bgrToRgbTable = {
2,
0,
-2
};
DecodeLayersFromZip(inputFile, IndexStartNumber.Zero, progress,
(layerIndex, pngBytes) =>
{
using Mat rgbMat = new();
CvInvoke.Imdecode(pngBytes, ImreadModes.AnyColor, rgbMat);
var greyMat = new Mat(rgbMat.Height, rgbMat.GetRealStep(), DepthType.Cv8U, 1);
var rgbSpan = rgbMat.GetDataByteSpan();
var greySpan = greyMat.GetDataByteSpan();

for (var i = 0; i < rgbSpan.Length; i++)
{
greySpan[i] = rgbSpan[i + bgrToRgbTable[i%3]];
}
return greyMat;
});
DecodeLayersFromZip(inputFile, IndexStartNumber.Zero, progress);

GCode!.Clear();

Expand Down Expand Up @@ -587,25 +570,7 @@ protected override void EncodeInternally(OperationProgress progress)
{
using var outputFile = ZipFile.Open(TemporaryOutputFileFullPath, ZipArchiveMode.Create);

sbyte[] bgrToRgbTable = {
2,
0,
-2
};
EncodeLayersInZip(outputFile, 5, IndexStartNumber.Zero, progress, matGenFunc:
(_, mat) =>
{
var rgbMat = new Mat(mat.Height, mat.GetRealStep() / 3, DepthType.Cv8U, 3);
var rgbMatSpan = rgbMat.GetDataByteSpan();
var greySpan = mat.GetDataByteSpan();
for (int i = 0; i < greySpan.Length; i++)
{
rgbMatSpan[i + bgrToRgbTable[i % 3]] = greySpan[i];
}
return rgbMat;
});

EncodeLayersInZip(outputFile, 5, IndexStartNumber.Zero, progress);

RebuildFileProperties();

Expand Down
2 changes: 1 addition & 1 deletion UVtools.Core/UVtools.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<RepositoryUrl>https://github.com/sn4k3/UVtools</RepositoryUrl>
<PackageProjectUrl>https://github.com/sn4k3/UVtools</PackageProjectUrl>
<Description>MSLA/DLP, file analysis, calibration, repair, conversion and manipulation</Description>
<Version>3.5.4</Version>
<Version>3.5.5</Version>
<Copyright>Copyright © 2020 PTRTECH</Copyright>
<PackageIcon>UVtools.png</PackageIcon>
<Platforms>AnyCPU;x64</Platforms>
Expand Down
2 changes: 1 addition & 1 deletion UVtools.InstallerMM/UVtools.InstallerMM.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<?define ComponentRules="OneToOne"?>
<!-- SourceDir instructs IsWiX the location of the directory that contains files for this merge module -->
<?define SourceDir="..\publish\UVtools_win-x64_v3.5.4"?>
<?define SourceDir="..\publish\UVtools_win-x64_v3.5.5"?>
<Module Id="UVtools" Language="1033" Version="1.0.0.0">
<Package Id="12aaa1cf-ff06-4a02-abd5-2ac01ac4f83b" Manufacturer="PTRTECH" InstallerVersion="200" Keywords="MSLA, DLP" Description="MSLA/DLP, file analysis, repair, conversion and manipulation" InstallScope="perMachine" Platform="x64" />
<Directory Id="TARGETDIR" Name="SourceDir">
Expand Down
4 changes: 2 additions & 2 deletions UVtools.WPF/UVtools.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<RepositoryUrl>https://github.com/sn4k3/UVtools</RepositoryUrl>
<RepositoryType>Git</RepositoryType>
<Version>3.5.4</Version>
<Version>3.5.5</Version>
<Platforms>AnyCPU;x64</Platforms>
<PackageIcon>UVtools.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down Expand Up @@ -43,7 +43,7 @@
<PackageReference Include="Avalonia.Controls.DataGrid" Version="0.10.16" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.16" />
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.16" />
<PackageReference Include="MessageBox.Avalonia" Version="2.0.1" />
<PackageReference Include="MessageBox.Avalonia" Version="2.0.2" />
<PackageReference Include="Projektanker.Icons.Avalonia" Version="5.1.0" />
<PackageReference Include="Projektanker.Icons.Avalonia.FontAwesome" Version="5.1.0" />
<PackageReference Include="Projektanker.Icons.Avalonia.MaterialDesign" Version="5.1.0" />
Expand Down

0 comments on commit 315ce3b

Please sign in to comment.