-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexportpicture.cpp
80 lines (65 loc) · 2.5 KB
/
exportpicture.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "exportpicture.h"
#include <QColor>
ExportPicture::ExportPicture():luminance(0,vector<int>(0,0)),chrominanceCb(0,vector<int>(0,0)),chrominanceCr(0,vector<int>(0,0)),height(0),width(0),fileName(0){
}
ExportPicture::ExportPicture(QImage &image, const QString &fileName):luminance(0,vector<int>(0,0)),chrominanceCb(0,vector<int>(0,0)),chrominanceCr(0,vector<int>(0,0)),height(image.width()),width(image.height()),fileName(fileName){
//Picture dimensions must be devidible by 8. If they are not, then we have to set them upp
if(height%8 == 0 && width%8 == 0){
luminance.resize(height);
chrominanceCb.resize(height);
chrominanceCr.resize(height);
for(int i=0;i<height;i++){
luminance[i].resize(width);
chrominanceCb[i].resize(width);
chrominanceCr[i].resize(width);
}
}
else if(height%8==0 && width%8!=0){
luminance.resize(height);
chrominanceCb.resize(height);
chrominanceCr.resize(height);
for(unsigned int i=0;i<luminance.size();i++){
luminance[i].resize(width+8-(width%8));
chrominanceCb[i].resize(width+8-(width%8));
chrominanceCr[i].resize(width+8-(width%8));
}
}
else if(height%8!=0 && width%8==0){
luminance.resize(height+8-(height%8));
chrominanceCb.resize(height+8-(height%8));
chrominanceCr.resize(height+8-(height%8));
for(unsigned int i=0;i<luminance.size();i++){
luminance[i].resize(width);
chrominanceCb[i].resize(width);
chrominanceCr[i].resize(width);
}
}
else if(height%8!=0 && width%8!=0){
luminance.resize(height+8-(height%8));
chrominanceCb.resize(height+8-(height%8));
chrominanceCr.resize(height+8-(height%8));
for(unsigned int i=0;i<luminance.size();i++){
luminance[i].resize(width+8-(width%8));
chrominanceCb[i].resize(width+8-(width%8));
chrominanceCr[i].resize(width+8-(width%8));
}
}
fillVectorsWithData(image);
}
void ExportPicture::fillVectorsWithData(QImage &image){
QRgb rgb;
for(int i=0;i<height;i++){
for(int j=0;j<width;j++){
rgb=image.pixel(j,i);
QColor c(rgb);
luminance[i][j]=c.red();
chrominanceCb[i][j]=c.green();
chrominanceCr[i][j]=c.blue();
}
}
}
void ExportPicture::deleteDataFromMatrix(){
luminance.clear();
chrominanceCb.clear();
chrominanceCr.clear();
}