This repository has been archived by the owner on Aug 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
cutils.cpp
58 lines (44 loc) · 1.43 KB
/
cutils.cpp
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
#include "cutils.h"
CUtils::CUtils()
{
}
QColor CUtils::colorDiff(const QColor &clr1, const QColor &clr2){
quint8 red = quint8(clr1.red()) - quint8(clr2.red());
quint8 green = quint8(clr1.green()) - quint8(clr2.green());
quint8 blue = quint8(clr1.blue()) - quint8(clr2.blue());
return QColor(red,green,blue);
}
QColor CUtils::colorAdd(const QColor &clr1, const QColor &clr2){
quint8 red = quint8(clr1.red()) + quint8(clr2.red());
quint8 green = quint8(clr1.green()) + quint8(clr2.green());
quint8 blue = quint8(clr1.blue()) + quint8(clr2.blue());
return QColor(red,green,blue);
}
QImage CUtils::imageDiff(const QImage& img1,const QImage& img2){
QImage tmpImage(img1);
if(img1.size() != img2.size()){
return tmpImage;
}
int width = img1.width();
int height = img1.height();
for(int y=0;y<height;y++){
for(int x=0;x<width;x++){
tmpImage.setPixelColor(x,y,colorDiff(img1.pixelColor(x,y),img2.pixelColor(x,y)));
}
}
return tmpImage;
}
QImage CUtils::imageAdd(const QImage& img1,const QImage& img2){
QImage tmpImage(img1);
if(img1.size() != img2.size()){
return tmpImage;
}
int width = img1.width();
int height = img1.height();
for(int y=0;y<height;y++){
for(int x=0;x<width;x++){
tmpImage.setPixelColor(x,y,colorAdd(img1.pixelColor(x,y),img2.pixelColor(x,y)));
}
}
return tmpImage;
}