Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sn4k3/UVtools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'UVtools.Core/Extensions/EmguExtensions.cs')
-rw-r--r--UVtools.Core/Extensions/EmguExtensions.cs19
1 files changed, 18 insertions, 1 deletions
diff --git a/UVtools.Core/Extensions/EmguExtensions.cs b/UVtools.Core/Extensions/EmguExtensions.cs
index 64b2dc5..b5ed369 100644
--- a/UVtools.Core/Extensions/EmguExtensions.cs
+++ b/UVtools.Core/Extensions/EmguExtensions.cs
@@ -63,10 +63,27 @@ namespace UVtools.Core.Extensions
public static unsafe Span<T> GetPixelRowSpan<T>(this Mat mat, int y, int length = 0, int offset = 0)
{
- return new Span<T>(IntPtr.Add(mat.DataPointer, y * mat.Step + offset).ToPointer(), length == 0 ? mat.Step : length);
+ return new(IntPtr.Add(mat.DataPointer, y * mat.Step + offset).ToPointer(), length == 0 ? mat.Step : length);
//return mat.GetPixelSpan<T>().Slice(offset, mat.Step);
}
+ /// <summary>
+ /// Gets if a <see cref="Mat"/> is all zeroed
+ /// </summary>
+ /// <param name="mat"></param>
+ /// <param name="threshold">Pixel brightness threshold</param>
+ /// <returns></returns>
+ public static unsafe bool IsZeroed(this Mat mat, byte threshold = 0)
+ {
+ var ptr = mat.GetBytePointer();
+ for (int i = 0; i < mat.GetLength(); i++)
+ {
+ if (ptr[i] > threshold) return false;
+ }
+ return true;
+ }
+
+
public static void Transform(this Mat src, double xScale, double yScale, double xTrans = 0, double yTrans = 0, Size dstSize = default, Inter interpolation = Inter.Linear)
{
//var dst = new Mat(src.Size, src.Depth, src.NumberOfChannels);