Skip to content

Commit

Permalink
(Fix) Benchmark tool: Allow to show percentages larger than 100% and …
Browse files Browse the repository at this point in the history
…increase progress height
  • Loading branch information
sn4k3 committed Jan 19, 2024
1 parent d5f7a49 commit 5236242
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- (Add) Title bar: Display the loaded file size and re-arrange the last operation run time to the right
- (Improvement) Re-arrange some items on `File` and `Help` menu
- (Improvement) Use icons instead UTF-8 character for buttons with drop-down menus
- (Fix) Benchmark tool: Allow to show percentages larger than 100% and increase progress height
- **Tools:**
- (Fix) Layer actions - Import layer(s): Unable to process image files (#815)
- (Fix) PCB Exposure: Draw circles using ellipses in order to use non-square pixels (#822)
Expand Down
21 changes: 11 additions & 10 deletions UVtools.Core/Extensions/CompressionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static int GetGzipUncompressedLength(Stream stream)
return BitConverter.ToInt32(uncompressedLength);
}

public static MemoryStream GZipCompress(Stream inputStream, CompressionLevel compressionLevel, bool leaveStreamOpen = false)
public static Stream GZipCompress(Stream inputStream, CompressionLevel compressionLevel, bool leaveStreamOpen = false)
{
if (inputStream.Position == inputStream.Length) inputStream.Seek(0, SeekOrigin.Begin);

Expand All @@ -41,19 +41,20 @@ public static MemoryStream GZipCompress(Stream inputStream, CompressionLevel com
{
inputStream.CopyTo(gzipStream);
}
if (!leaveStreamOpen) { inputStream.Close(); }
if (!leaveStreamOpen) inputStream.Close();

compressedStream.Seek(0, SeekOrigin.Begin);

return compressedStream;
}

public static MemoryStream GZipCompress(byte[] inputStream, CompressionLevel compressionLevel) =>
public static Stream GZipCompress(byte[] inputStream, CompressionLevel compressionLevel) =>
GZipCompress(new ReadOnlyMemory<byte>(inputStream).AsStream(), compressionLevel);

public static byte[] GZipCompressToBytes(Stream inputStream, CompressionLevel compressionLevel)
{
using var ms = GZipCompress(inputStream, compressionLevel);
return ms.ToArray();
using var stream = GZipCompress(inputStream, compressionLevel);
return stream.ToArray();
}

public static byte[] GZipCompressToBytes(byte[] inputStream, CompressionLevel compressionLevel)
Expand All @@ -63,7 +64,7 @@ public static byte[] GZipCompressToBytes(byte[] inputStream, CompressionLevel co
}


public static MemoryStream GZipDecompress(Stream compressedStream, bool leaveStreamOpen = false)
public static Stream GZipDecompress(Stream compressedStream, bool leaveStreamOpen = false)
{
if (compressedStream.Position == compressedStream.Length) { compressedStream.Seek(0, SeekOrigin.Begin); }

Expand All @@ -87,7 +88,7 @@ public static ArraySegment<byte> GZipDecompress(ReadOnlyMemory<byte> compressedD
: uncompressedStream.ToArray();
}

public static MemoryStream DeflateCompress(Stream inputStream, CompressionLevel compressionLevel, bool leaveStreamOpen = false)
public static Stream DeflateCompress(Stream inputStream, CompressionLevel compressionLevel, bool leaveStreamOpen = false)
{
if (inputStream.Position == inputStream.Length) { inputStream.Seek(0, SeekOrigin.Begin); }

Expand All @@ -96,13 +97,13 @@ public static MemoryStream DeflateCompress(Stream inputStream, CompressionLevel
{
inputStream.CopyTo(gzipStream);
}
if (!leaveStreamOpen) { inputStream.Close(); }
if (!leaveStreamOpen) inputStream.Close();

compressedStream.Seek(0, SeekOrigin.Begin);
return compressedStream;
}

public static MemoryStream DeflateCompress(byte[] inputStream, CompressionLevel compressionLevel) =>
public static Stream DeflateCompress(byte[] inputStream, CompressionLevel compressionLevel) =>
DeflateCompress(new ReadOnlyMemory<byte>(inputStream).AsStream(), compressionLevel);

public static byte[] DeflateCompressToBytes(Stream inputStream, CompressionLevel compressionLevel)
Expand All @@ -117,7 +118,7 @@ public static byte[] DeflateCompressToBytes(byte[] inputStream, CompressionLevel
return ms.ToArray();
}

public static MemoryStream DeflateDecompress(Stream compressedStream, bool leaveStreamOpen = false)
public static Stream DeflateDecompress(Stream compressedStream, bool leaveStreamOpen = false)
{
if (compressedStream.Position == compressedStream.Length) { compressedStream.Seek(0, SeekOrigin.Begin); }

Expand Down
2 changes: 1 addition & 1 deletion UVtools.Core/FileFormats/FileFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6035,7 +6035,7 @@ public Mat CreateMatWithDummyPixel(Point dummyPixelLocation, byte dummyPixelBrig
public Mat CreateMatWithDummyPixel() => CreateMatWithDummyPixel(SupportGCode ? (byte)1 : (byte)128);

/// <summary>
/// Creates a empty mat of file <see cref="Resolution"/> size
/// Creates an empty mat of file <see cref="Resolution"/> size
/// </summary>
/// <param name="initMat">True to black out the mat</param>
/// <returns></returns>
Expand Down
20 changes: 14 additions & 6 deletions UVtools.Core/Layers/Layer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -928,12 +928,12 @@ public Mat LayerMat
CvInvoke.Imdecode(_compressedBytes, ImreadModes.Grayscale, mat);
break;
case LayerCompressionCodec.Lz4:
mat = CreateMat();
mat = CreateMat(false);
LZ4Codec.Decode(_compressedBytes.AsSpan(), mat.GetDataByteSpan());
break;
case LayerCompressionCodec.GZip:
{
mat = CreateMat();
mat = CreateMat(false);
unsafe
{
fixed (byte* pBuffer = _compressedBytes)
Expand All @@ -949,7 +949,7 @@ public Mat LayerMat
}
case LayerCompressionCodec.Deflate:
{
mat = CreateMat();
mat = CreateMat(false);
unsafe
{
fixed (byte* pBuffer = _compressedBytes)
Expand Down Expand Up @@ -1312,12 +1312,15 @@ public override string ToString()
#region Methods

/// <summary>
/// Creates an <see cref="Mat"/> using this layer information
/// Creates an empty <see cref="Mat"/> of file <see cref="Resolution"/> size
/// </summary>
/// <param name="initMat">True to black out the mat</param>
/// <returns></returns>
public Mat CreateMat()
public Mat CreateMat(bool initMat = true)
{
return new Mat(Resolution, DepthType.Cv8U, 1);
return initMat
? EmguExtensions.InitMat(Resolution)
: new Mat(Resolution, DepthType.Cv8U, 1);
}

/// <summary>
Expand Down Expand Up @@ -2007,6 +2010,11 @@ public static byte[] CompressMat(Mat mat, LayerCompressionCodec codec)

ArrayPool<byte>.Shared.Return(rent);
return target;

/*var span = mat.GetDataByteSpan();
using var buffer = new PooledBufferWriter<byte>();
LZ4Frame.Encode(span, buffer, LZ4Level.L00_FAST);
return buffer.WrittenMemory.ToArray();*/
}
case LayerCompressionCodec.GZip:
return CompressionExtensions.GZipCompressToBytes(mat.GetUnmanagedMemoryStream(FileAccess.Read), CompressionLevel.Fastest);
Expand Down
1 change: 0 additions & 1 deletion UVtools.UI/MainWindow.Suggestions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* of this license document, but changing it is not allowed.
*/

using Avalonia.Controls;
using Avalonia.Threading;
using System;
using System.Collections.Generic;
Expand Down
2 changes: 1 addition & 1 deletion UVtools.UI/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@ private void UpdateTitle()

if (IsFileLoaded)
{
_titleStringBuilder.Append($"File: {SlicerFile!.Filename} Size: {_loadedFileSizeRepresentation}");
_titleStringBuilder.Append($"File: {SlicerFile!.Filename} ({_loadedFileSizeRepresentation})");
}

_titleStringBuilder.Append($" Version: {About.VersionStr} RAM: {SizeExtensions.SizeSuffix(Environment.WorkingSet)}");
Expand Down
11 changes: 9 additions & 2 deletions UVtools.UI/Windows/BenchmarkWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Icon="/Assets/Icons/UVtools.ico"
SizeToContent="WidthAndHeight"
WindowStartupLocation="CenterOwner"
MinWidth="560"
CanResize="False"
x:Class="UVtools.UI.Windows.BenchmarkWindow"
x:DataType="windows:BenchmarkWindow">
Expand Down Expand Up @@ -81,17 +82,23 @@

<ProgressBar Grid.Row="4" Grid.Column="0"
Name="SingleThreadDiffProgressBar"
FontWeight="Bold"
MinHeight="30"
Value="{Binding SingleThreadDiffValue}"
Maximum="{Binding SingleThreadDiffMaxValue}"
Foreground="{Binding SingleThreadDiffForeground}"
ShowProgressText="True"/>
ShowProgressText="True"
ProgressTextFormat="{Binding #SingleThreadDiffProgressBar.Value, StringFormat='{}{0:0}%'}"/>

<ProgressBar Grid.Row="4" Grid.Column="2"
Name="MultiThreadDiffProgressBar"
FontWeight="Bold"
MinHeight="30"
Value="{Binding MultiThreadDiffValue}"
Maximum="{Binding MultiThreadDiffMaxValue}"
Foreground="{Binding MultiThreadDiffForeground}"
ShowProgressText="True"/>
ShowProgressText="True"
ProgressTextFormat="{Binding #MultiThreadDiffProgressBar.Value, StringFormat='{}{0:0}%'}"/>

<TextBlock Grid.Row="6" Grid.Column="0"
FontWeight="Bold" Text="Developer results:"/>
Expand Down
6 changes: 3 additions & 3 deletions UVtools.UI/Windows/BenchmarkWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public enum BenchmarkResolution
/*GZip 8K Compress*/ new BenchmarkTestResult(63.29f, 1020.41f),
/*Deflate 4K Compress*/ new BenchmarkTestResult(246.91f, 4000.00f),
/*Deflate 8K Compress*/ new BenchmarkTestResult(64.10f, 1033.06f),
/*LZ4 4K Compress*/ new BenchmarkTestResult(1052.63f, 6666.67f),
/*LZ4 8K Compress*/ new BenchmarkTestResult(281.69f, 2155.17f),
/*LZ4 4K Compress*/ new BenchmarkTestResult(1111.11f, 20833.33f),
/*LZ4 8K Compress*/ new BenchmarkTestResult(312.5f, 6097.56f),
/*Stress CPU test*/ new BenchmarkTestResult(0f, 0f),
}),
new BenchmarkMachine("Intel® Core™ i9-9900K @ 5.0 GHz", "G.Skill Trident Z 32GB DDR4-3200MHz CL14", new []
Expand Down Expand Up @@ -198,7 +198,7 @@ public double MultiThreadDiffMaxValue
get => _multiThreadDiffMaxValue;
set => RaiseAndSetIfChanged(ref _multiThreadDiffMaxValue, value);
}

public IBrush SingleThreadDiffForeground
{
get => _singleThreadDiffForeground;
Expand Down
7 changes: 4 additions & 3 deletions documentation/UVtools.Core.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified wiki/UVtools_Compression.xlsx
Binary file not shown.

0 comments on commit 5236242

Please sign in to comment.