Skip to content

Commit

Permalink
v4.3.1
Browse files Browse the repository at this point in the history
- **Tool - Change resolution:**
  - (Add) 12K resolution profile
  - (Improvement) Do not mark the option "Resize layers with the proposed ratio" when a machine preset results in the same pixel size / ratio of (1.0x, 1.0x)
  - (Fix) Wait time before cure suggestion for GOO and PRZ file formats, it now allows the use of the create first empty layer (#864)
- **Thumbnail sanitizer:**
  - (Add) Check if the thumbnails have the correct number of channels, if not it will throw an error
  - (Improvement) When full encode a file, strip all extra thumbnails that are not used by the file format if they are not an archive
  - (Improvement) Resize all thumbnails to the same size as the original from file format even when there are more than file format requires, this fixes a problem when converting from zip that have many thumbnails but file format selects the larger and the smallest, leading to encode the wrong size
  - (Improvement) Convert thumbnails to BGR and strip the alpha channel when required, this fixes the issue where format conversion from zip such as sl1 and vdt where corrupting the final file with invalid thumbnail rle
- (Add) Tool - Light bleed compensation: Add "Dim subject" option to select from different subjects to dim, "Bridges" was added (#868)
- (Add) Settings - Notifications: Allow to define beeps sounds to play after ran long operations (#863)
- (Improvement) CTB, FDG, PHZ: Make possible to encode a thumbnail using 1 and 4 channels, this fixes the issue where the file format could encode invalid thumbnail data
- (Improvement) Add empty layer for Goo file format when running the wait time before cure suggestion
- (Fix) Terminal: The run globals was lost from the previous version update
- (Upgrade) .NET from 6.0.28 to 6.0.29
  • Loading branch information
sn4k3 committed Apr 19, 2024
1 parent a060cf3 commit 430f376
Show file tree
Hide file tree
Showing 27 changed files with 631 additions and 143 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## 19/04/2024 - v4.3.1

- **Tool - Change resolution:**
- (Add) 12K resolution profile
- (Improvement) Do not mark the option "Resize layers with the proposed ratio" when a machine preset results in the same pixel size / ratio of (1.0x, 1.0x)
- (Fix) Wait time before cure suggestion for GOO and PRZ file formats, it now allows the use of the create first empty layer (#864)
- **Thumbnail sanitizer:**
- (Add) Check if the thumbnails have the correct number of channels, if not it will throw an error
- (Improvement) When full encode a file, strip all extra thumbnails that are not used by the file format if they are not an archive
- (Improvement) Resize all thumbnails to the same size as the original from file format even when there are more than file format requires, this fixes a problem when converting from zip that have many thumbnails but file format selects the larger and the smallest, leading to encode the wrong size
- (Improvement) Convert thumbnails to BGR and strip the alpha channel when required, this fixes the issue where format conversion from zip such as sl1 and vdt where corrupting the final file with invalid thumbnail rle
- (Add) Tool - Light bleed compensation: Add "Dim subject" option to select from different subjects to dim, "Bridges" was added (#868)
- (Add) Settings - Notifications: Allow to define beeps sounds to play after ran long operations (#863)
- (Improvement) CTB, FDG, PHZ: Make possible to encode a thumbnail using 1 and 4 channels, this fixes the issue where the file format could encode invalid thumbnail data
- (Improvement) Add empty layer for Goo file format when running the wait time before cure suggestion
- (Fix) Terminal: The run globals was lost from the previous version update
- (Upgrade) .NET from 6.0.28 to 6.0.29

## 06/04/2024 - v4.3.0

- **File formats:**
Expand Down
10 changes: 9 additions & 1 deletion CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,12 @@
- Mark Johnston
- Ivan Ivanov
- Simon Christ
- Leonardo Farenzena Felin
- Leonardo Farenzena Felin
- Sylvain Chartrand
- Sason Simpson
- Starbase3D
- Robert Blackett
- Michael Pullen
- Landry David
- Jeremy Conoley
- Brady George
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<CommonPublishDir>$(MSBuildThisFileDirectory)publish</CommonPublishDir>

<UVtoolsVersion>4.3.0</UVtoolsVersion>
<UVtoolsVersion>4.3.1</UVtoolsVersion>
<AvaloniaVersion>11.0.7</AvaloniaVersion>
</PropertyGroup>

Expand Down
38 changes: 15 additions & 23 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
- **File formats:**
- (Add) nanoDLP file format
- (Add) SL1 printer note keyword: `LAYERIMAGEFORMAT_xxx` sets the layer image format required for the converted file if the format have multiple options (For Archives with PNG's)
- (Fix) Anycubic file format: Model Min/Max(X/Y) was not properly calculated
- (Fix) Photon Mono M5s Pro incorrect display height and width (fixes #854)
- **PrusaSlicer:**
- (Add) Concepts3D Athena 8K & 12K
- (Change) Wanhao D7: Add `LAYERIMAGEFORMAT_Png32` to printer notes
- (Change) Nova3D Bene4 Mono, Bene5, Elfin2 Mono SE, Whale, Whale2: Add `LAYERIMAGEFORMAT_Png24BgrAA` to printer notes
- **UI:**
- (Add) Settings - Automations - Events: After file load, before file save and after file save. Events are fired upon an action and execute a defined script.
If the script is written with the UVtools scripting structure, it will run under an operation and within the Core context.
Otherwise, if plain C# code is used, it will run under the Terminal and in the UI context.
- (Add) Show a message of congratulations on the software birthday (Trigger only once per year)
- (Add) Menu - Help: Add "Community forums" submenu, move Facebook group into it and add GitHub, Reddit, Twitter and Youtube
- (Change) Window title: Move version near software name and add the system arch to it
- (Change) About window: Move version near software name and add "Age" label
- (Change) Benchmark tool: Add a thin border to the result panels
- (Improvement) On the status bar, hide the " @ mm/min" from lift speed label if file is not able to use lift speed parameters
- (Improvement) Re-style the new version button
- (Fix) Show print times correctly when larger than a day (#854)
- (Upgrade) .NET from 6.0.27 to 6.0.28
- (Upgrade) Wix from 4.0.4 to 5.0.0
- **Tool - Change resolution:**
- (Add) 12K resolution profile
- (Improvement) Do not mark the option "Resize layers with the proposed ratio" when a machine preset results in the same pixel size / ratio of (1.0x, 1.0x)
- (Fix) Wait time before cure suggestion for GOO and PRZ file formats, it now allows the use of the create first empty layer (#864)
- **Thumbnail sanitizer:**
- (Add) Check if the thumbnails have the correct number of channels, if not it will throw an error
- (Improvement) When full encode a file, strip all extra thumbnails that are not used by the file format if they are not an archive
- (Improvement) Resize all thumbnails to the same size as the original from file format even when there are more than file format requires, this fixes a problem when converting from zip that have many thumbnails but file format selects the larger and the smallest, leading to encode the wrong size
- (Improvement) Convert thumbnails to BGR and strip the alpha channel when required, this fixes the issue where format conversion from zip such as sl1 and vdt where corrupting the final file with invalid thumbnail rle
- (Add) Tool - Light bleed compensation: Add "Dim subject" option to select from different subjects to dim, "Bridges" was added (#868)
- (Add) Settings - Notifications: Allow to define beeps sounds to play after ran long operations (#863)
- (Improvement) CTB, FDG, PHZ: Make possible to encode a thumbnail using 1 and 4 channels, this fixes the issue where the file format could encode invalid thumbnail data
- (Improvement) Add empty layer for Goo file format when running the wait time before cure suggestion
- (Fix) Terminal: The run globals was lost from the previous version update
- (Upgrade) .NET from 6.0.28 to 6.0.29

137 changes: 109 additions & 28 deletions UVtools.Core/Extensions/EmguExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,13 @@ public static GpuMat ToGpuMat(this Mat mat)
/// <param name="mat"></param>
/// <param name="accessMode"></param>
/// <returns></returns>
public static unsafe UnmanagedMemoryStream GetUnmanagedMemoryStream(this Mat mat, FileAccess accessMode)
public static UnmanagedMemoryStream GetUnmanagedMemoryStream(this Mat mat, FileAccess accessMode)
{
var length = mat.GetLength();
return new UnmanagedMemoryStream(mat.GetBytePointer(), length, length, accessMode);
unsafe
{
return new UnmanagedMemoryStream(mat.GetBytePointer(), length, length, accessMode);
}
}

/// <summary>
Expand All @@ -200,17 +203,22 @@ public static unsafe UnmanagedMemoryStream GetUnmanagedMemoryStream(this Mat mat
/// <param name="mat"></param>
/// <returns></returns>
public static unsafe byte* GetBytePointer(this Mat mat)
=> (byte*)mat.DataPointer.ToPointer();
{
return (byte*)mat.DataPointer.ToPointer();
}

/// <summary>
/// Gets the whole data span to manipulate or read pixels, use this when possibly using ROI
/// </summary>
/// <returns></returns>
public static unsafe Span2D<T> GetDataSpan2D<T>(this Mat mat)
public static Span2D<T> GetDataSpan2D<T>(this Mat mat) where T : struct
{
var step = mat.GetRealStep();
if (mat.IsContinuous) return new(mat.DataPointer.ToPointer(), mat.Height, step, 0);
return new(mat.DataPointer.ToPointer(), mat.Height, step, mat.Step / mat.DepthToByteCount() - step);
unsafe
{
if (mat.IsContinuous) return new(mat.DataPointer.ToPointer(), mat.Height, step, 0);
return new(mat.DataPointer.ToPointer(), mat.Height, step, mat.Step / mat.DepthToByteCount() - step);
}
}

/// <summary>
Expand Down Expand Up @@ -240,9 +248,34 @@ public static unsafe Span2D<T> GetDataSpan2D<T>(this Mat mat)
/// <param name="length"></param>
/// <param name="offset"></param>
/// <returns></returns>
public static unsafe Span<T> GetDataSpan<T>(this Mat mat, int length = 0, int offset = 0)
public static Span<T> GetDataSpan<T>(this Mat mat, int length = 0, int offset = 0) where T : struct
{
if (!mat.IsContinuous)
throw new NotSupportedException("To create a Span, the Mat's memory must be continuous. This Mat does not use continuous memory. Use Span2D instead.");

if (offset < 0)
throw new ArgumentOutOfRangeException(nameof(offset), offset, "Offset must be a positive value.");

var maxLength = mat.GetLength() / Marshal.SizeOf<T>() - offset;

if (maxLength < 0)
throw new ArgumentOutOfRangeException(nameof(offset), offset, "Offset value overflow this Mat size.");

if (length <= 0)
{
length = maxLength;
}
else if (length > maxLength)
{
throw new ArgumentOutOfRangeException(nameof(length), length, $"The maximum size allowed for this Mat with an offset of {offset} is {maxLength}.");
}

unsafe
{
return new(IntPtr.Add(mat.DataPointer, offset).ToPointer(), length);
}

/*if (length <= 0)
{
if (mat.IsContinuous)
{
Expand All @@ -253,7 +286,7 @@ public static unsafe Span<T> GetDataSpan<T>(this Mat mat, int length = 0, int of
length = mat.Step / mat.DepthToByteCount() * (mat.Height - 1) + mat.GetRealStep();
}
}
return new(IntPtr.Add(mat.DataPointer, offset).ToPointer(), length);
return new(IntPtr.Add(mat.DataPointer, offset).ToPointer(), length);*/
}

/// <summary>
Expand All @@ -264,7 +297,7 @@ public static unsafe Span<T> GetDataSpan<T>(this Mat mat, int length = 0, int of
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public static Span<T> GetPixelSpan<T>(this Mat mat, int x, int y)
public static Span<T> GetPixelSpan<T>(this Mat mat, int x, int y) where T : struct
=> mat.GetDataSpan<T>(mat.NumberOfChannels, mat.GetPixelPos(x, y));

/// <summary>
Expand All @@ -274,7 +307,7 @@ public static Span<T> GetPixelSpan<T>(this Mat mat, int x, int y)
/// <param name="mat"></param>
/// <param name="pos"></param>
/// <returns></returns>
public static Span<T> GetPixelSpan<T>(this Mat mat, int pos)
public static Span<T> GetPixelSpan<T>(this Mat mat, int pos) where T : struct
=> mat.GetDataSpan<T>(mat.NumberOfChannels, pos);

/// <summary>
Expand All @@ -286,11 +319,29 @@ public static Span<T> GetPixelSpan<T>(this Mat mat, int pos)
/// <param name="length"></param>
/// <param name="offset"></param>
/// <returns></returns>
public static unsafe Span<T> GetRowSpan<T>(this Mat mat, int y, int length = 0, int offset = 0)
public static Span<T> GetRowSpan<T>(this Mat mat, int y, int length = 0, int offset = 0) where T : struct
{
var originalStep = mat.Step;
if(length <= 0) length = mat.GetRealStep();
return new(IntPtr.Add(mat.DataPointer, y * originalStep + offset).ToPointer(), length);
if (offset < 0)
throw new ArgumentOutOfRangeException(nameof(offset), offset, "Offset must be a positive value.");

var maxLength = mat.GetRealStep() / Marshal.SizeOf<T>() - offset;

if (maxLength < 0)
throw new ArgumentOutOfRangeException(nameof(offset), offset, "Offset value overflow this Mat row size.");

if (length <= 0)
{
length = maxLength;
}
else if (length > maxLength)
{
throw new ArgumentOutOfRangeException(nameof(length), length, $"The maximum size allowed for this Mat row with an offset of {offset} is {maxLength}.");
}

unsafe
{
return new(IntPtr.Add(mat.DataPointer, y * mat.Step + offset).ToPointer(), length);
}
}

/// <summary>
Expand Down Expand Up @@ -330,20 +381,32 @@ public static unsafe Span<T> GetColSpan<T>(this Mat mat, int x, int length = 0,
/// <param name="length"></param>
/// <param name="offset"></param>
/// <returns></returns>
public static unsafe ReadOnlySpan<T> GetDataReadOnlySpan<T>(this Mat mat, int length = 0, int offset = 0)
public static ReadOnlySpan<T> GetDataReadOnlySpan<T>(this Mat mat, int length = 0, int offset = 0) where T : struct
{
if (!mat.IsContinuous)
throw new NotSupportedException("To create a Span, the Mat's memory must be continuous. This Mat does not use continuous memory. Use Span2D instead.");

if (offset < 0)
throw new ArgumentOutOfRangeException(nameof(offset), offset, "Offset must be a positive value.");

int maxLength = mat.GetLength() / Marshal.SizeOf<T>() - offset;

if (maxLength < 0)
throw new ArgumentOutOfRangeException(nameof(offset), offset, "Offset value overflow this Mat size.");

if (length <= 0)
{
if (mat.IsContinuous)
{
length = mat.GetLength();
}
else
{
length = mat.Step / mat.DepthToByteCount() * (mat.Height - 1) + mat.GetRealStep();
}
length = maxLength;
}
else if (length > maxLength)
{
throw new ArgumentOutOfRangeException(nameof(length), length, $"The maximum size allowed for this Mat with an offset of {offset} is {maxLength}.");
}

unsafe
{
return new(IntPtr.Add(mat.DataPointer, offset).ToPointer(), length);
}
return new(IntPtr.Add(mat.DataPointer, offset).ToPointer(), length);
}

/// <summary>
Expand All @@ -362,11 +425,29 @@ public static unsafe ReadOnlySpan<T> GetDataReadOnlySpan<T>(this Mat mat, int le
/// <param name="length"></param>
/// <param name="offset"></param>
/// <returns></returns>
public static unsafe ReadOnlySpan<T> GetRowReadOnlySpan<T>(this Mat mat, int y, int length = 0, int offset = 0)
public static ReadOnlySpan<T> GetRowReadOnlySpan<T>(this Mat mat, int y, int length = 0, int offset = 0) where T : struct
{
var originalStep = mat.Step;
if (length <= 0) length = mat.GetRealStep();
return new(IntPtr.Add(mat.DataPointer, y * originalStep + offset).ToPointer(), length);
if (offset < 0)
throw new ArgumentOutOfRangeException(nameof(offset), offset, "Offset must be a positive value.");

var maxLength = mat.GetRealStep() / Marshal.SizeOf<T>() - offset;

if (maxLength < 0)
throw new ArgumentOutOfRangeException(nameof(offset), offset, "Offset value overflow this Mat row size.");

if (length <= 0)
{
length = maxLength;
}
else if (length > maxLength)
{
throw new ArgumentOutOfRangeException(nameof(length), length, $"The maximum size allowed for this Mat row with an offset of {offset} is {maxLength}.");
}

unsafe
{
return new(IntPtr.Add(mat.DataPointer, y * mat.Step + offset).ToPointer(), length);
}
}

/// <summary>
Expand Down
29 changes: 22 additions & 7 deletions UVtools.Core/FileFormats/CTBEncryptedFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,10 @@ public class Preview
[FieldOrder(3)] public uint ImageLength { get; set; }


public unsafe Mat Decode(byte[] rawImageData)
public Mat Decode(byte[] rawImageData)
{
var image = new Mat(new Size((int)ResolutionX, (int)ResolutionY), DepthType.Cv8U, 3);
var span = image.GetBytePointer();
var span = image.GetDataByteSpan();

int pixel = 0;
for (int n = 0; n < rawImageData.Length; n++)
Expand Down Expand Up @@ -574,14 +574,13 @@ public override string ToString()
return $"{nameof(ResolutionX)}: {ResolutionX}, {nameof(ResolutionY)}: {ResolutionY}, {nameof(ImageOffset)}: {ImageOffset}, {nameof(ImageLength)}: {ImageLength}";
}

public unsafe byte[] Encode(Mat image)
public byte[] Encode(Mat image)
{
List<byte> rawData = new();
ushort color15 = 0;
uint rep = 0;

var span = image.GetBytePointer();
var imageLength = image.GetLength();
var span = image.GetDataByteReadOnlySpan();

void RleRGB15()
{
Expand Down Expand Up @@ -611,11 +610,27 @@ void RleRGB15()
}

int pixel = 0;
while (pixel < imageLength)
while (pixel < span.Length)
{
byte b = span[pixel++];
byte g;
byte r;

if (image.NumberOfChannels == 1) // 8 bit safe-guard
{
r = g = b;
}
else
{
g = span[pixel++];
r = span[pixel++];
}

if (image.NumberOfChannels == 4) pixel++; // skip alpha

var ncolor15 =
// bgr
(span[pixel++] >> 3) | ((span[pixel++] >> 2) << 5) | ((span[pixel++] >> 3) << 11);
(b >> 3) | ((g >> 2) << 5) | ((r >> 3) << 11);

if (ncolor15 == color15)
{
Expand Down
Loading

0 comments on commit 430f376

Please sign in to comment.