-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdctDsp.cpp
186 lines (155 loc) · 6.31 KB
/
dctDsp.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#include "dctDsp.h"
#include <math.h>
#include <QDebug>
DctDsp::DctDsp(QString widgetName, QWidget *parent) :
YuvImgDsp(widgetName, parent)
{
dctData = NULL;
crtBlock = new int*[8];
for (int i = 0; i < 8; i++)
crtBlock[i] = new int[8];
}
DctDsp::~DctDsp() {}
void DctDsp::dctChangedBySsp(RawImg &sspData)
{
// delete former QImage and data
delete imgY;
delete imgU;
delete imgV;
if (dataY != NULL)
delete dataY;
if (dataU != NULL)
delete dataU;
if (dataV != NULL)
delete dataV;
// update width and height
crtWidth = sspData.width;
crtHeight = sspData.height;
// init dctData
if (dctData != NULL)
delete dctData;
dctData = new RawImg(sspData);
// dct
for(int i = 0; i<sspData.width; i += 8)
{
for(int j = 0; j<sspData.height; j += 8)
{
int w = 8, h = 8;
if( i+7 >= sspData.width)
w = sspData.width - i;
if( j+7 >= sspData.height)
h = sspData.height - j;
double **f;
f = new double*[8];
for(int u = 0; u < 8; u++)
f[u] = new double[8];
for(int inc = 0; inc<3; inc++)
{
for(int u = 0; u<w; u++)
for(int v = 0; v<h; v++)
f[u][v] = dctData->data[((j+v)*sspData.width+(i+u))*3+inc] - 128;
// fill in the rest
for(int u=w; u<8; u++)
for(int v = 0; v<h; v++)
f[u][v] = f[w-1][v];
for(int v=h; v<8; v++)
for(int u = 0; u<h; u++)
f[u][v] = f[u][h-1];
for(int u=w; u<8; u++)
for(int v=h; v<8; v++)
f[u][v] = f[w-1][h-1];
dct(f);
for(int u = 0; u<w; u++)
for(int v = 0; v<h; v++)
dctData->data[((j+v)*sspData.width+(i+u))*3+inc] = (int)f[u][v];
}
for(int u = 0; u < 8; u++ )
delete[]f[u];
delete []f;
}
}
dataY = new unsigned char[sspData.width * sspData.height * 4];
dataU = new unsigned char[sspData.width * sspData.height * 4];
dataV = new unsigned char[sspData.width * sspData.height * 4];
// fill in data
for (int i = 0, j = 0; i < sspData.width * sspData.height; ++i, j += 4)
{
dataY[j] = dataY[j + 1] = dataY[j + 2] = dctData->data[i*3];
dataU[j] = dataU[j + 1] = dataU[j + 2] = dctData->data[i*3+1];
dataV[j] = dataV[j + 1] = dataV[j + 2] = dctData->data[i*3+2];
dataY[j + 3] = dataU[j + 3] = dataV[j + 3] = ~0; // Alpha
}
// display YUV images
imgY = new QImage(dataY, sspData.width, sspData.height, QImage::Format_ARGB32);
imgShowY = new QLabel(this);
imgShowY->setPixmap(QPixmap::fromImage(imgY->scaled(300, 300, Qt::KeepAspectRatio, Qt::SmoothTransformation)));
imgShowY->show();
mainLayout->addWidget(imgShowY, 0, 0, 10, 2);
imgU = new QImage(dataU, sspData.width, sspData.height, QImage::Format_ARGB32);
imgShowU = new QLabel(this);
imgShowU->setPixmap(QPixmap::fromImage(imgU->scaled(150, 150, Qt::KeepAspectRatio, Qt::SmoothTransformation)));
imgShowU->show();
mainLayout->addWidget(imgShowU, 0, 2, 5, 1);
imgV = new QImage(dataV, sspData.width, sspData.height, QImage::Format_ARGB32);
imgShowV = new QLabel(this);
imgShowV->setPixmap(QPixmap::fromImage(imgV->scaled(150, 150, Qt::KeepAspectRatio, Qt::SmoothTransformation)));
imgShowV->show();
mainLayout->addWidget(imgShowV, 5, 2, 5, 1);
emit dctChangingDct(*dctData);
}
void DctDsp::dctChangedByDct(RawImg &preDctData)
{
// init dctData_backup
if (dctDataBackup != NULL)
delete dctDataBackup;
dctDataBackup = new RawImg(preDctData);
if (dataY != NULL)
delete dataY;
if (dataU != NULL)
delete dataU;
if (dataV != NULL)
delete dataV;
dataY = new unsigned char[preDctData.width * preDctData.height * 4];
dataU = new unsigned char[preDctData.width * preDctData.height * 4];
dataV = new unsigned char[preDctData.width * preDctData.height * 4];
dctQuantizationAndUpdate();
}
void DctDsp::dctQuantizationAndUpdate() {
if (dctData != NULL)
delete dctData;
dctData = new RawImg(*dctDataBackup);
// fill in data
for (int i = 0, j = 0; i < dctData->width * dctData->height; ++i, j += 4) {
dataY[j] = dataY[j + 1] = dataY[j + 2] = dctData->data[i*3] = dctData->data[i*3] / (QM[crtQM][(i / dctData->width) % 8][(i % dctData->width) % 8]);
dataU[j] = dataU[j + 1] = dataU[j + 2] = dctData->data[i*3+1] = dctData->data[i*3+1] / (QM[crtQM][(i / dctData->width) % 8][(i % dctData->width) % 8]);
dataV[j] = dataV[j + 1] = dataV[j + 2] = dctData->data[i*3+2] = dctData->data[i*3+2] / (QM[crtQM][(i / dctData->width) % 8][(i % dctData->width) % 8]);
dataY[j + 3] = dataU[j+3] = dataV[j+3] = ~0; // Alpha
}
// delete former QImage and data
delete imgY;
delete imgU;
delete imgV;
// display YUV images
imgY = new QImage(dataY, dctData->width, dctData->height, QImage::Format_ARGB32);
imgShowY = new QLabel(this);
imgShowY->setPixmap(QPixmap::fromImage(imgY->scaled(300, 300, Qt::KeepAspectRatio, Qt::SmoothTransformation)));
imgShowY->show();
mainLayout->addWidget(imgShowY, 0, 0, 10, 2);
imgU = new QImage(dataU, dctData->width, dctData->height, QImage::Format_ARGB32);
imgShowU = new QLabel(this);
imgShowU->setPixmap(QPixmap::fromImage(imgU->scaled(150, 150, Qt::KeepAspectRatio, Qt::SmoothTransformation)));
imgShowU->show();
mainLayout->addWidget(imgShowU, 0, 2, 5, 1);
imgV = new QImage(dataV, dctData->width, dctData->height, QImage::Format_ARGB32);
imgShowV = new QLabel(this);
imgShowV->setPixmap(QPixmap::fromImage(imgV->scaled(150, 150, Qt::KeepAspectRatio, Qt::SmoothTransformation)));
imgShowV->show();
mainLayout->addWidget(imgShowV, 5, 2, 5, 1);
emit dctChangingSsp(*dctData);
}
void DctDsp::helpSspChangingMatrix2(int bX, int bY, int offset) {
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++)
crtBlock[i][j] = dctData->data[((bY * 8 + i) * crtWidth + bX * 8 + j) * 3 + offset];
emit dctChangingMatrix2(crtBlock);
}