MauiKit Image Tools

colorcommands.cpp
1#include "colorcommands.h"
2#include <preprocessimage.hpp>
3#include <convertimage.hpp>
4#include <cvmatandqimage.h>
5
6using namespace ColorCommands;
7
8Brightness::Brightness(QImage image, int value, const std::function<void ()> &f)
9 : m_image(image)
10 , m_value(value)
11// ,m_cb(f)
12{
13 m_cb = f;
14 qDebug() << "create brightness <<" << m_value;
15}
16
17void Brightness::setArea(const QRectF &area)
18{
19 m_area = area;
20}
21
22QImage Brightness::undo(QImage image)
23{
24 Q_UNUSED(image)
25
26 if(m_cb != nullptr)
27 {
28 m_cb();
29 }
30
31 qDebug() << "back to birghtness" << m_value;
32 return m_image;
33}
34
35QImage Brightness::redo(QImage image)
36{
37 // m_image = image;
38
39 if(m_value > 255)
40 m_value = 255;
41
42 else if(m_value < -255)
43 m_value = -255;
44
45 auto m_imgMat = QtOcv::image2Mat(image);
46 auto newMat = PreprocessImage::adjustBrightness(m_imgMat, m_value, cv::Rect(m_area.x(), m_area.y(), m_area.width(), m_area.height()));
47 // qDebug() << "IS PROCESSED IMAGE VALIUD" << img.isNull() << img.format();
48
49 auto img = QtOcv::mat2Image(newMat); //remember to delete
50
51 qDebug() << "testing saturation" << image.format() << img.format()<< img.isDetached()<<newMat.rows << newMat.cols << newMat.step << newMat.empty();
52
53 return img;
54}
55
56Contrast::Contrast(QImage image, double value, const std::function<void ()> &f)
57 : m_image(image)
58 , m_value(value)
59{
60 m_cb = f;
61}
62
63QImage Contrast::redo(QImage image)
64{
65 if(m_value > 255)
66 m_value = 255;
67 else if(m_value < -255)
68 m_value = -255;
69
70 auto m_imgMat = QtOcv::image2Mat(image);
71 auto newMat = PreprocessImage::adjustContrast(m_imgMat, m_value);
72 auto img = QtOcv::mat2Image(newMat); //remember to delete
73 // qDebug() << "IS PROCESSED IMAGE VALIUD" << img.isNull() << img.format();
74
75 qDebug() << m_imgMat.rows << m_imgMat.cols << m_imgMat.step << m_imgMat.empty();
76
77 return img;
78}
79
80QImage Contrast::undo(QImage image)
81{
82 Q_UNUSED(image)
83
84 if(m_cb != nullptr)
85 {
86 m_cb();
87 }
88
89 qDebug() << "back to birghtness" << m_value;
90 return m_image;
91}
92
93Saturation::Saturation(QImage image, int value, const std::function<void ()> &f)
94 : m_image(image)
95 , m_value(value)
96{
97 m_cb = f;
98}
99
100QImage Saturation::redo(QImage image)
101{
102 // m_image = image;
103
104 if(m_value > 100)
105 m_value = 100;
106
107 if(m_value < -100)
108 m_value = -100;
109
110 auto m_imgMat = QtOcv::image2Mat(image);
111 auto newMat = PreprocessImage::adjustSaturation(m_imgMat, m_value);
112 // qDebug() << "IS PROCESSED IMAGE VALIUD" << img.isNull() << img.format();
113
114 auto img = QtOcv::mat2Image(newMat); //remember to delete
115
116 qDebug() << "testing saturation" << image.format() << img.format()<< img.isDetached()<<newMat.rows << newMat.cols << newMat.step << newMat.empty();
117
118 return img;
119}
120
121QImage Saturation::undo(QImage image)
122{
123 Q_UNUSED(image)
124
125 if(m_cb != nullptr)
126 {
127 m_cb();
128 }
129
130 qDebug() << "back to birghtness" << m_value;
131 return m_image;
132}
133
134Hue::Hue(QImage image, int value, const std::function<void ()> &f)
135 : m_image(image)
136 , m_value(value)
137{
138 qDebug() << "Creating HUE COMMAND" << m_value << value;
139 m_cb = f;
140}
141
142QImage Hue::redo(QImage image)
143{
144 // if(m_value > 180)
145 // m_value = 180;
146 // else if(m_value < 0)
147 // m_value = 0;
148 qDebug() << "Creating command for hue" << m_value;
149
150 auto m_imgMat = QtOcv::image2Mat(image);
151 auto newMat = PreprocessImage::hue(m_imgMat, m_value);
152 auto img = QtOcv::mat2Image(newMat); //remember to delete
153 // qDebug() << "IS PROCESSED IMAGE VALIUD" << img.isNull() << img.format();
154
155 qDebug() << m_imgMat.rows << m_imgMat.cols << m_imgMat.step << m_imgMat.empty();
156
157 return img;
158}
159
160QImage Hue::undo(QImage image)
161{
162 Q_UNUSED(image)
163
164 if(m_cb != nullptr)
165 {
166 m_cb();
167 }
168
169 return m_image;
170}
Format format() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Apr 11 2025 11:57:09 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.