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/Operations/OperationMask.cs')
-rw-r--r--UVtools.Core/Operations/OperationMask.cs39
1 files changed, 39 insertions, 0 deletions
diff --git a/UVtools.Core/Operations/OperationMask.cs b/UVtools.Core/Operations/OperationMask.cs
index c702371..972157f 100644
--- a/UVtools.Core/Operations/OperationMask.cs
+++ b/UVtools.Core/Operations/OperationMask.cs
@@ -8,9 +8,11 @@
using System;
using System.Text;
+using System.Threading.Tasks;
using System.Xml.Serialization;
using Emgu.CV;
using Emgu.CV.CvEnum;
+using UVtools.Core.FileFormats;
using UVtools.Core.Objects;
namespace UVtools.Core.Operations
@@ -18,6 +20,7 @@ namespace UVtools.Core.Operations
[Serializable]
public class OperationMask : Operation
{
+ #region Overrides
public override string Title => "Mask";
public override string Description =>
"Mask the intensity of the LCD output using a greyscale input image.\n\n" +
@@ -45,16 +48,52 @@ namespace UVtools.Core.Operations
return new StringTag(sb.ToString());
}
+ #endregion
+ #region Properties
[XmlIgnore]
public Mat Mask { get; set; }
public bool HaveMask => !(Mask is null);
+ #endregion
+
+ #region Methods
public void InvertMask()
{
if (!HaveMask) return;
CvInvoke.BitwiseNot(Mask, Mask);
}
+
+ public override bool Execute(FileFormat slicerFile, OperationProgress progress = null)
+ {
+ progress ??= new OperationProgress();
+ progress.Reset(ProgressAction, LayerRangeCount);
+
+ Parallel.For(LayerIndexStart, LayerIndexEnd + 1, layerIndex =>
+ {
+ if (progress.Token.IsCancellationRequested) return;
+ using var mat = slicerFile[layerIndex].LayerMat;
+ Execute(mat);
+ slicerFile[layerIndex].LayerMat = mat;
+ lock (progress.Mutex)
+ {
+ progress++;
+ }
+ });
+
+ progress.Token.ThrowIfCancellationRequested();
+ return true;
+ }
+
+ public override bool Execute(Mat mat, params object[] arguments)
+ {
+ var target = GetRoiOrDefault(mat);
+ if (Mask.Size != target.Size) return false;
+ CvInvoke.BitwiseAnd(target, Mask, target);
+ return true;
+ }
+
+ #endregion
}
}