mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-14 12:26:19 +02:00
* **Core:** * Fix some improper locks for progress counter and change to Interlocked instead * Fix a bug when chaging layer count by remove or add layers it will malform the file after save and crash the program with some tools and/or clipboard * Fix when a operation fails by other reason different from cancelation it was not restoring the backup * When manually delete/fix issues it will also backup the layers * **LayerManager:** * LayerManager is now readonly and no longer used to transpose layers, each FileFormat have now a unique `LayerManager` instance which is set on the generic constructor * Implemented `List<Layer>` methods to easy modify the layers array * Changing the `Layers` instance will now recompute some properties, call the properties rebuild and forced sanitize of the structure * Better reallocation methods * **Clipboard Manager:** * Add the hability to do full backups, they will be marked with an asterisk (*) at clipboard items list * When a partial backup is made and it backups all the layers it will be converted to full backup * Clipboard can now restore a snapshot directly with `RestoreSnapshot` * Prevent restore the initial backup upon file load and when clearing the clipboard * Clip's that change the layer count will perform a full backup and also do a fail-safe backup behind if previous clip is not a full backup * **Pixel dimming:** * Allow to load an image file as a pattern (Do not use very large files or it will take much time to dump the data into the textbox) * Empty lines on patterns will be discarded and not trigger validation error
102 lines
3.1 KiB
C#
102 lines
3.1 KiB
C#
/*
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE
|
|
* Version 3, 19 November 2007
|
|
* Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
* Everyone is permitted to copy and distribute verbatim copies
|
|
* of this license document, but changing it is not allowed.
|
|
*/
|
|
|
|
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
|
|
{
|
|
[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" +
|
|
"Useful to correct LCD light uniformity for a specific printer.\n\n" +
|
|
"NOTE: This operation should be run only after repairs and other transformations. The provided" +
|
|
"input mask image must match the output resolution of the target printer.";
|
|
|
|
public override string ConfirmationText =>
|
|
$"mask layers from {LayerIndexStart} through {LayerIndexEnd}";
|
|
|
|
public override string ProgressTitle =>
|
|
$"Masking layers from {LayerIndexStart} through {LayerIndexEnd}";
|
|
|
|
public override string ProgressAction => "Masked layers";
|
|
|
|
public override bool CanHaveProfiles => false;
|
|
|
|
public override StringTag Validate(params object[] parameters)
|
|
{
|
|
var sb = new StringBuilder();
|
|
if (Mask is null)
|
|
{
|
|
sb.AppendLine("The mask can not be empty.");
|
|
}
|
|
|
|
return new StringTag(sb.ToString());
|
|
}
|
|
#endregion
|
|
|
|
#region Properties
|
|
[XmlIgnore]
|
|
public Mat Mask { get; set; }
|
|
|
|
public bool HaveMask => !(Mask is null);
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
public OperationMask() { }
|
|
|
|
public OperationMask(FileFormat slicerFile) : base(slicerFile) { }
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
public void InvertMask()
|
|
{
|
|
if (!HaveMask) return;
|
|
CvInvoke.BitwiseNot(Mask, Mask);
|
|
}
|
|
|
|
protected override bool ExecuteInternally(OperationProgress progress)
|
|
{
|
|
Parallel.For(LayerIndexStart, LayerIndexEnd + 1, layerIndex =>
|
|
{
|
|
if (progress.Token.IsCancellationRequested) return;
|
|
using var mat = SlicerFile[layerIndex].LayerMat;
|
|
Execute(mat);
|
|
SlicerFile[layerIndex].LayerMat = mat;
|
|
progress.LockAndIncrement();
|
|
});
|
|
|
|
return !progress.Token.IsCancellationRequested;
|
|
}
|
|
|
|
public override bool Execute(Mat mat, params object[] arguments)
|
|
{
|
|
var target = GetRoiOrDefault(mat);
|
|
using var mask = GetMask(mat);
|
|
if (Mask.Size != target.Size) return false;
|
|
CvInvoke.BitwiseAnd(target, Mask, target, mask);
|
|
return true;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|