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

OperationPixelDimming.cs « Operations « UVtools.Core - github.com/sn4k3/UVtools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 22941d6ded7ffae4553b9c1bc184e4ec7fdfb41b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 *                     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.Text;
using Emgu.CV;
using UVtools.Core.Objects;

namespace UVtools.Core.Operations
{
    public class OperationPixelDimming : Operation
    {
        private uint _borderSize = 5;
        private bool _bordersOnly;
        private Matrix<byte> _evenPattern;
        private Matrix<byte> _oddPattern;

        #region Overrides
        public override string Title => "Pixel dimming";
        public override string Description =>
            "Dim white pixels in a chosen pattern applied over the print area.\n\n" +
            "The selected pattern will tiled over the image.  Benefits are:\n" +
            "1) Reduced layer expansion for large layer objects\n" +
            "2) Reduced cross layer exposure\n" +
            "3) Extended pixel life of the LCD\n\n" +
            "NOTE: Run this tool only after repairs and all other transformations.";

        public override string ConfirmationText =>
            $"dim pixels from layers {LayerIndexStart} through {LayerIndexEnd}";

        public override string ProgressTitle =>
            $"Dimming from layers {LayerIndexStart} through {LayerIndexEnd}";

        public override string ProgressAction => "Dimmed layers";

        public override StringTag Validate(params object[] parameters)
        {
            var sb = new StringBuilder();
            if (BorderSize == 0 && BordersOnly)
            {
                sb.AppendLine("Border size must be positive in order to use \"Dim only borders\" function.");
            }

            if (EvenPattern is null && OddPattern is null)
            {
                sb.AppendLine("Either even or odd pattern must contain a valid matrix.");
            }

            return new StringTag(sb.ToString());
        }
        #endregion

        #region Properties

        public uint BorderSize
        {
            get => _borderSize;
            set => RaiseAndSetIfChanged(ref _borderSize, value);
        }

        public bool BordersOnly
        {
            get => _bordersOnly;
            set => RaiseAndSetIfChanged(ref _bordersOnly, value);
        }

        public Matrix<byte> EvenPattern
        {
            get => _evenPattern;
            set => RaiseAndSetIfChanged(ref _evenPattern, value);
        }

        public Matrix<byte> OddPattern
        {
            get => _oddPattern;
            set => RaiseAndSetIfChanged(ref _oddPattern, value);
        }

        #endregion
    }
}