mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-11 19:12:31 +02:00
5cfd62d36e
* (Add) Tools can now run inside a ROI (#49) * (Add) Layer preview: Hold-Shift + Left-drag to select an ROI (Region of interest) on image, that region will be used instead of whole image when running some tools * (Add) Layer preview: Hold-Shift + Hold-Alt + Left-drag to select and auto adjust the ROI to the contained objects, that region will be used instead of whole image when running some tools * (Add) Layer preview: Hold-Shift + Right-click on a object to select its bounding area, that region will be used instead of whole image when running some tools * (Add) Layer preview: ESC key to clear ROI * (Add) Layer preview: Overlay text with hints for current action * (Add) Tool - Move: Now possible to do a copy move instead of a cut move * (Add) Arrow wait cursor to progress loadings * (Change) Layer preview: Hold-Shift key to select issues and pick pixel position/brightness changed to Hold-Control key * (Change) Layer preview: Shift+click combination to zoom-in changed to Alt+click * (Fix) CTB v3: Bad file when re-encoding
136 lines
4.9 KiB
C#
136 lines
4.9 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.Drawing;
|
|
using System.Windows.Forms;
|
|
using Emgu.CV;
|
|
using Emgu.CV.CvEnum;
|
|
using Emgu.CV.Structure;
|
|
using UVtools.Core.Extensions;
|
|
using UVtools.Core.Operations;
|
|
using UVtools.GUI.Extensions;
|
|
|
|
namespace UVtools.GUI.Controls.Tools
|
|
{
|
|
public partial class CtrlToolMask : CtrlToolWindowContent
|
|
{
|
|
public OperationMask Operation { get; }
|
|
|
|
public CtrlToolMask()
|
|
{
|
|
InitializeComponent();
|
|
Operation = new OperationMask();
|
|
SetOperation(Operation);
|
|
lbPrinterResolution.Text = $"Printer Resolution: {Program.FrmMain.ActualLayerImage.Size}";
|
|
}
|
|
|
|
public override void ExtraActionCall(object sender)
|
|
{
|
|
if (ReferenceEquals(sender, ParentToolWindow.btnClearRoi))
|
|
{
|
|
Operation.Mask = null;
|
|
pbMask.Image = null;
|
|
lbMaskResolution.Text = "Mask resolution: (Unloaded)";
|
|
ButtonOkEnabled = false;
|
|
return;
|
|
}
|
|
}
|
|
|
|
private void EventClick(object sender, EventArgs e)
|
|
{
|
|
if (ReferenceEquals(sender, btnImportImageMask))
|
|
{
|
|
using (var fileOpen = new OpenFileDialog
|
|
{
|
|
CheckFileExists = true,
|
|
Filter = "Image Files(*.PNG;*.BMP;*.JPEG;*.JPG;*.GIF)|*.PNG;*.BMP;*.JPEG;*.JPG;*.GIF"
|
|
})
|
|
{
|
|
if (fileOpen.ShowDialog() != DialogResult.OK) return;
|
|
|
|
Operation.Mask = CvInvoke.Imread(fileOpen.FileName, ImreadModes.Grayscale);
|
|
|
|
var roi = Program.FrmMain.ROI;
|
|
if (roi.IsEmpty)
|
|
{
|
|
if (Operation.Mask.Size != Program.FrmMain.ActualLayerImage.Size)
|
|
{
|
|
CvInvoke.Resize(Operation.Mask, Operation.Mask, Program.FrmMain.ActualLayerImage.Size);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (Operation.Mask.Size != roi.Size)
|
|
{
|
|
CvInvoke.Resize(Operation.Mask, Operation.Mask, roi.Size);
|
|
}
|
|
}
|
|
|
|
if (cbInvertMask.Checked)
|
|
{
|
|
CvInvoke.BitwiseNot(Operation.Mask, Operation.Mask);
|
|
}
|
|
|
|
lbMaskResolution.Text = $"Mask Resolution: {Operation.Mask.Size}";
|
|
|
|
pbMask.Image = Operation.Mask.ToBitmap();
|
|
cbInvertMask.Enabled =
|
|
ButtonOkEnabled = true;
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (ReferenceEquals(sender, cbInvertMask))
|
|
{
|
|
CvInvoke.BitwiseNot(Operation.Mask, Operation.Mask);
|
|
pbMask.Image = Operation.Mask.ToBitmap();
|
|
return;
|
|
}
|
|
|
|
if (ReferenceEquals(sender, btnMaskGenerate))
|
|
{
|
|
var roi = Program.FrmMain.ROI;
|
|
Operation.Mask = roi.IsEmpty ? Program.FrmMain.ActualLayerImage.CloneBlank() : new Mat(roi.Size, DepthType.Cv8U, 1);
|
|
|
|
lbMaskResolution.Text = $"Mask Resolution: {Operation.Mask.Size}";
|
|
|
|
int radius = (int)nmGeneratorDiameter.Value;
|
|
if (radius == 0)
|
|
{
|
|
radius = Math.Min(Operation.Mask.Width, Operation.Mask.Height) / 2;
|
|
}
|
|
else
|
|
{
|
|
radius = radius.Clamp(2, Math.Min(Operation.Mask.Width, Operation.Mask.Height)) / 2;
|
|
}
|
|
|
|
var maxScalar = new MCvScalar((double)nmGeneratorMaxBrightness.Value);
|
|
Operation.Mask.SetTo(maxScalar);
|
|
|
|
var center = new Point(Operation.Mask.Width / 2, Operation.Mask.Height / 2);
|
|
var colorDifference = nmGeneratorMinBrightness.Value - nmGeneratorMaxBrightness.Value;
|
|
//CvInvoke.Circle(Mask, center, radius, minScalar, -1);
|
|
|
|
for (decimal i = 1; i < radius; i++)
|
|
{
|
|
int color = (int)(nmGeneratorMinBrightness.Value - i / radius * colorDifference); //or some another color calculation
|
|
CvInvoke.Circle(Operation.Mask, center, (int)i, new MCvScalar(color), 2);
|
|
}
|
|
|
|
if (cbInvertMask.Checked)
|
|
CvInvoke.BitwiseNot(Operation.Mask, Operation.Mask);
|
|
pbMask.Image = Operation.Mask.ToBitmap();
|
|
cbInvertMask.Enabled =
|
|
ButtonOkEnabled = true;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|