diff --git a/CHANGELOG.md b/CHANGELOG.md index afff5fa1..ed49a7e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,14 @@ # Changelog +## 19/04/2024 - v4.3.2 + +- (Fix) "Index was outside the bounds of the array" when detecting issues (Fixes #869) + ## 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 @@ -14,7 +17,7 @@ - (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) Wait time before cure suggestion for GOO and PRZ file formats, it now allows the use of the create first empty layer (#864) - (Fix) Terminal: The run globals was lost from the previous version update - (Upgrade) .NET from 6.0.28 to 6.0.29 diff --git a/Directory.Build.props b/Directory.Build.props index 58f8819e..111dc789 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -31,7 +31,7 @@ $(MSBuildThisFileDirectory)publish - 4.3.1 + 4.3.2 11.0.7 diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index b6169d9a..3f42860d 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,16 +1,2 @@ -- **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 +- (Fix) "Index was outside the bounds of the array" when detecting issues (Fixes #869) diff --git a/UVtools.Core/Extensions/EmguExtensions.cs b/UVtools.Core/Extensions/EmguExtensions.cs index 144f57c0..b719744b 100644 --- a/UVtools.Core/Extensions/EmguExtensions.cs +++ b/UVtools.Core/Extensions/EmguExtensions.cs @@ -213,11 +213,31 @@ public static UnmanagedMemoryStream GetUnmanagedMemoryStream(this Mat mat, FileA /// public static Span2D GetDataSpan2D(this Mat mat) where T : struct { - var step = mat.GetRealStep(); + var step = mat.GetRealStep() / Marshal.SizeOf(); 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); + return new(mat.DataPointer.ToPointer(), mat.Height, step, mat.Step / Marshal.SizeOf() - step); + } + } + + /// + /// Gets the whole data span to read pixels, use this when possibly using ROI + /// + /// + public static ReadOnlySpan2D GetDataByteReadOnlySpan2D(this Mat mat) => mat.GetDataSpan2D(); + + /// + /// Gets the whole data span to read pixels, use this when possibly using ROI + /// + /// + public static ReadOnlySpan2D GetDataReadOnlySpan2D(this Mat mat) where T : struct + { + var step = mat.GetRealStep() / Marshal.SizeOf(); + unsafe + { + if (mat.IsContinuous) return new(mat.DataPointer.ToPointer(), mat.Height, step, 0); + return new(mat.DataPointer.ToPointer(), mat.Height, step, mat.Step / Marshal.SizeOf() - step); } } @@ -388,8 +408,8 @@ public static ReadOnlySpan GetDataReadOnlySpan(this Mat mat, int length = if (offset < 0) throw new ArgumentOutOfRangeException(nameof(offset), offset, "Offset must be a positive value."); - - int maxLength = mat.GetLength() / Marshal.SizeOf() - offset; + + var maxLength = mat.GetLength() / Marshal.SizeOf() - offset; if (maxLength < 0) throw new ArgumentOutOfRangeException(nameof(offset), offset, "Offset value overflow this Mat size."); @@ -558,24 +578,24 @@ public static byte DepthToByteCount(this Mat mat) } /// - /// Step return the original Mat step, if ROI step still from original matrix which lead to errors. + /// Return the original Mat step in bytes, if ROI step still from original matrix which lead to errors. /// Use this to get the real step size /// /// /// public static int GetRealStep(this Mat mat) { - return mat.Width * mat.NumberOfChannels; + return mat.Width * mat.NumberOfChannels * mat.DepthToByteCount(); } /// - /// Gets the total length of this + /// Gets the total length in bytes of this /// /// /// The total length of this public static int GetLength(this Mat mat) { - return mat.Total.ToInt32() * mat.NumberOfChannels; + return mat.Total.ToInt32() * mat.NumberOfChannels * mat.DepthToByteCount(); } /// @@ -1435,7 +1455,7 @@ public static List ScanLines(this Mat mat, bool vertically = false, by if (vertically) { - var span = mat.GetDataByteSpan2D(); + var span = mat.GetDataByteReadOnlySpan2D(); for (x = 0; x < matSize.Width; x++) { line.StartX = x + offset.X; @@ -1547,7 +1567,7 @@ public static List ScanLines(this Mat mat, Func greyFunc, if (vertically) { - var span = mat.GetDataByteSpan2D(); + var span = mat.GetDataByteReadOnlySpan2D(); for (x = 0; x < matSize.Width; x++) { line.StartX = x + offset.X; diff --git a/UVtools.Core/Managers/IssueManager.cs b/UVtools.Core/Managers/IssueManager.cs index 74e6c80b..6986e0b1 100644 --- a/UVtools.Core/Managers/IssueManager.cs +++ b/UVtools.Core/Managers/IssueManager.cs @@ -263,8 +263,8 @@ void GenerateAirMap(IInputArray input, IInputOutputArray output, VectorOfVectorO using (var image = layer.GetLayerMat(layerIndex == 0 ? SlicerFile.BoundingRectangle : Layer.GetBoundingRectangleUnion(SlicerFile[layerIndex - 1], layer))) { - var sourceSpan = image.SourceMat.GetDataByteSpan2D(); - var roiSpan = image.RoiMat.GetDataByteSpan2D(); + var sourceSpan = image.SourceMat.GetDataByteReadOnlySpan2D(); + var roiSpan = image.RoiMat.GetDataByteReadOnlySpan2D(); if (touchBoundConfig.Enabled) { @@ -368,7 +368,7 @@ void GenerateAirMap(IInputArray input, IInputOutputArray output, VectorOfVectorO if (layerIndex > 0 && layer.PositionZ > firstLayer!.PositionZ) // No islands nor overhangs for layer 0 or on plate { MatRoi? previousImage = null; - Span2D previousSpan = null; + ReadOnlySpan2D previousSpan = null; Mat? overhangImage = null; var previousLayer = SlicerFile[layerIndex - 1]; @@ -494,7 +494,7 @@ void GenerateAirMap(IInputArray input, IInputOutputArray output, VectorOfVectorO if (previousSpan == null) { - previousSpan = previousImage.RoiMat.GetDataByteSpan2D(); + previousSpan = previousImage.RoiMat.GetDataByteReadOnlySpan2D(); } List points = new(); @@ -559,7 +559,7 @@ void GenerateAirMap(IInputArray input, IInputOutputArray output, VectorOfVectorO using var subtractedImage = islandOverhangMat.Roi(wasNull ? Rectangle.Empty : rect, EmptyRoiBehaviour.CaptureSource); - var subtractedSpan = subtractedImage.GetDataByteSpan2D(); + var subtractedSpan = subtractedImage.GetDataByteReadOnlySpan2D(); var subtractedStep = subtractedImage.GetRealStep(); int overhangPixels = 0; diff --git a/documentation/UVtools.Core.xml b/documentation/UVtools.Core.xml index e21a3949..bb5005e2 100644 --- a/documentation/UVtools.Core.xml +++ b/documentation/UVtools.Core.xml @@ -1171,6 +1171,18 @@ + + + Gets the whole data span to read pixels, use this when possibly using ROI + + + + + + Gets the whole data span to read pixels, use this when possibly using ROI + + + Gets the whole data span to manipulate or read pixels, use this when possibly using ROI @@ -1327,7 +1339,7 @@ - Step return the original Mat step, if ROI step still from original matrix which lead to errors. + Return the original Mat step in bytes, if ROI step still from original matrix which lead to errors. Use this to get the real step size @@ -1335,7 +1347,7 @@ - Gets the total length of this + Gets the total length in bytes of this The total length of this