Skip to content

Commit 2cf889e

Browse files
committed
v4.3.2
- (Fix) "Index was outside the bounds of the array" when detecting issues (Fixes #869)
1 parent 430f376 commit 2cf889e

File tree

6 files changed

+56
-35
lines changed

6 files changed

+56
-35
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# Changelog
22

3+
## 19/04/2024 - v4.3.2
4+
5+
- (Fix) "Index was outside the bounds of the array" when detecting issues (Fixes #869)
6+
37
## 19/04/2024 - v4.3.1
48

59
- **Tool - Change resolution:**
610
- (Add) 12K resolution profile
711
- (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)
8-
- (Fix) Wait time before cure suggestion for GOO and PRZ file formats, it now allows the use of the create first empty layer (#864)
912
- **Thumbnail sanitizer:**
1013
- (Add) Check if the thumbnails have the correct number of channels, if not it will throw an error
1114
- (Improvement) When full encode a file, strip all extra thumbnails that are not used by the file format if they are not an archive
@@ -14,7 +17,7 @@
1417
- (Add) Tool - Light bleed compensation: Add "Dim subject" option to select from different subjects to dim, "Bridges" was added (#868)
1518
- (Add) Settings - Notifications: Allow to define beeps sounds to play after ran long operations (#863)
1619
- (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
17-
- (Improvement) Add empty layer for Goo file format when running the wait time before cure suggestion
20+
- (Fix) Wait time before cure suggestion for GOO and PRZ file formats, it now allows the use of the create first empty layer (#864)
1821
- (Fix) Terminal: The run globals was lost from the previous version update
1922
- (Upgrade) .NET from 6.0.28 to 6.0.29
2023

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

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

34-
<UVtoolsVersion>4.3.1</UVtoolsVersion>
34+
<UVtoolsVersion>4.3.2</UVtoolsVersion>
3535
<AvaloniaVersion>11.0.7</AvaloniaVersion>
3636
</PropertyGroup>
3737

RELEASE_NOTES.md

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,2 @@
1-
- **Tool - Change resolution:**
2-
- (Add) 12K resolution profile
3-
- (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)
4-
- (Fix) Wait time before cure suggestion for GOO and PRZ file formats, it now allows the use of the create first empty layer (#864)
5-
- **Thumbnail sanitizer:**
6-
- (Add) Check if the thumbnails have the correct number of channels, if not it will throw an error
7-
- (Improvement) When full encode a file, strip all extra thumbnails that are not used by the file format if they are not an archive
8-
- (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
9-
- (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
10-
- (Add) Tool - Light bleed compensation: Add "Dim subject" option to select from different subjects to dim, "Bridges" was added (#868)
11-
- (Add) Settings - Notifications: Allow to define beeps sounds to play after ran long operations (#863)
12-
- (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
13-
- (Improvement) Add empty layer for Goo file format when running the wait time before cure suggestion
14-
- (Fix) Terminal: The run globals was lost from the previous version update
15-
- (Upgrade) .NET from 6.0.28 to 6.0.29
1+
- (Fix) "Index was outside the bounds of the array" when detecting issues (Fixes #869)
162

UVtools.Core/Extensions/EmguExtensions.cs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,31 @@ public static UnmanagedMemoryStream GetUnmanagedMemoryStream(this Mat mat, FileA
213213
/// <returns></returns>
214214
public static Span2D<T> GetDataSpan2D<T>(this Mat mat) where T : struct
215215
{
216-
var step = mat.GetRealStep();
216+
var step = mat.GetRealStep() / Marshal.SizeOf<T>();
217217
unsafe
218218
{
219219
if (mat.IsContinuous) return new(mat.DataPointer.ToPointer(), mat.Height, step, 0);
220-
return new(mat.DataPointer.ToPointer(), mat.Height, step, mat.Step / mat.DepthToByteCount() - step);
220+
return new(mat.DataPointer.ToPointer(), mat.Height, step, mat.Step / Marshal.SizeOf<T>() - step);
221+
}
222+
}
223+
224+
/// <summary>
225+
/// Gets the whole data span to read pixels, use this when possibly using ROI
226+
/// </summary>
227+
/// <returns></returns>
228+
public static ReadOnlySpan2D<byte> GetDataByteReadOnlySpan2D(this Mat mat) => mat.GetDataSpan2D<byte>();
229+
230+
/// <summary>
231+
/// Gets the whole data span to read pixels, use this when possibly using ROI
232+
/// </summary>
233+
/// <returns></returns>
234+
public static ReadOnlySpan2D<T> GetDataReadOnlySpan2D<T>(this Mat mat) where T : struct
235+
{
236+
var step = mat.GetRealStep() / Marshal.SizeOf<T>();
237+
unsafe
238+
{
239+
if (mat.IsContinuous) return new(mat.DataPointer.ToPointer(), mat.Height, step, 0);
240+
return new(mat.DataPointer.ToPointer(), mat.Height, step, mat.Step / Marshal.SizeOf<T>() - step);
221241
}
222242
}
223243

@@ -388,8 +408,8 @@ public static ReadOnlySpan<T> GetDataReadOnlySpan<T>(this Mat mat, int length =
388408

389409
if (offset < 0)
390410
throw new ArgumentOutOfRangeException(nameof(offset), offset, "Offset must be a positive value.");
391-
392-
int maxLength = mat.GetLength() / Marshal.SizeOf<T>() - offset;
411+
412+
var maxLength = mat.GetLength() / Marshal.SizeOf<T>() - offset;
393413

394414
if (maxLength < 0)
395415
throw new ArgumentOutOfRangeException(nameof(offset), offset, "Offset value overflow this Mat size.");
@@ -558,24 +578,24 @@ public static byte DepthToByteCount(this Mat mat)
558578
}
559579

560580
/// <summary>
561-
/// Step return the original Mat step, if ROI step still from original matrix which lead to errors.
581+
/// Return the original Mat step in bytes, if ROI step still from original matrix which lead to errors.
562582
/// Use this to get the real step size
563583
/// </summary>
564584
/// <param name="mat"></param>
565585
/// <returns></returns>
566586
public static int GetRealStep(this Mat mat)
567587
{
568-
return mat.Width * mat.NumberOfChannels;
588+
return mat.Width * mat.NumberOfChannels * mat.DepthToByteCount();
569589
}
570590

571591
/// <summary>
572-
/// Gets the total length of this <see cref="Mat"/>
592+
/// Gets the total length in bytes of this <see cref="Mat"/>
573593
/// </summary>
574594
/// <param name="mat"></param>
575595
/// <returns>The total length of this <see cref="Mat"/></returns>
576596
public static int GetLength(this Mat mat)
577597
{
578-
return mat.Total.ToInt32() * mat.NumberOfChannels;
598+
return mat.Total.ToInt32() * mat.NumberOfChannels * mat.DepthToByteCount();
579599
}
580600

581601
/// <summary>
@@ -1435,7 +1455,7 @@ public static List<GreyLine> ScanLines(this Mat mat, bool vertically = false, by
14351455

14361456
if (vertically)
14371457
{
1438-
var span = mat.GetDataByteSpan2D();
1458+
var span = mat.GetDataByteReadOnlySpan2D();
14391459
for (x = 0; x < matSize.Width; x++)
14401460
{
14411461
line.StartX = x + offset.X;
@@ -1547,7 +1567,7 @@ public static List<GreyLine> ScanLines(this Mat mat, Func<byte, byte> greyFunc,
15471567

15481568
if (vertically)
15491569
{
1550-
var span = mat.GetDataByteSpan2D();
1570+
var span = mat.GetDataByteReadOnlySpan2D();
15511571
for (x = 0; x < matSize.Width; x++)
15521572
{
15531573
line.StartX = x + offset.X;

UVtools.Core/Managers/IssueManager.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ void GenerateAirMap(IInputArray input, IInputOutputArray output, VectorOfVectorO
263263

264264
using (var image = layer.GetLayerMat(layerIndex == 0 ? SlicerFile.BoundingRectangle : Layer.GetBoundingRectangleUnion(SlicerFile[layerIndex - 1], layer)))
265265
{
266-
var sourceSpan = image.SourceMat.GetDataByteSpan2D();
267-
var roiSpan = image.RoiMat.GetDataByteSpan2D();
266+
var sourceSpan = image.SourceMat.GetDataByteReadOnlySpan2D();
267+
var roiSpan = image.RoiMat.GetDataByteReadOnlySpan2D();
268268

269269
if (touchBoundConfig.Enabled)
270270
{
@@ -368,7 +368,7 @@ void GenerateAirMap(IInputArray input, IInputOutputArray output, VectorOfVectorO
368368
if (layerIndex > 0 && layer.PositionZ > firstLayer!.PositionZ) // No islands nor overhangs for layer 0 or on plate
369369
{
370370
MatRoi? previousImage = null;
371-
Span2D<byte> previousSpan = null;
371+
ReadOnlySpan2D<byte> previousSpan = null;
372372
Mat? overhangImage = null;
373373
var previousLayer = SlicerFile[layerIndex - 1];
374374

@@ -494,7 +494,7 @@ void GenerateAirMap(IInputArray input, IInputOutputArray output, VectorOfVectorO
494494

495495
if (previousSpan == null)
496496
{
497-
previousSpan = previousImage.RoiMat.GetDataByteSpan2D();
497+
previousSpan = previousImage.RoiMat.GetDataByteReadOnlySpan2D();
498498
}
499499

500500
List<Point> points = new();
@@ -559,7 +559,7 @@ void GenerateAirMap(IInputArray input, IInputOutputArray output, VectorOfVectorO
559559

560560
using var subtractedImage = islandOverhangMat.Roi(wasNull ? Rectangle.Empty : rect, EmptyRoiBehaviour.CaptureSource);
561561

562-
var subtractedSpan = subtractedImage.GetDataByteSpan2D();
562+
var subtractedSpan = subtractedImage.GetDataByteReadOnlySpan2D();
563563
var subtractedStep = subtractedImage.GetRealStep();
564564

565565
int overhangPixels = 0;

documentation/UVtools.Core.xml

Lines changed: 14 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)