-
Notifications
You must be signed in to change notification settings - Fork 1
/
matrixDsp.cpp
110 lines (97 loc) · 3.85 KB
/
matrixDsp.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
#include "matrixDsp.h"
MatrixDsp::MatrixDsp(QWidget *parent) :
QWidget(parent)
{
QHeaderView *vHeader;
QHeaderView *hHeader;
// set up quantization and compression ratio labels
whichQM = new QLabel(tr("non-uniform quantization"));
whichQM->setAlignment(Qt::AlignCenter);
cmpRate = new QLabel(tr("compression ratio: unavailable"));
cmpRate->setAlignment(Qt::AlignCenter);
qmLabel = new QLabel(tr("Quantization Table"));
qmLabel->setAlignment(Qt::AlignCenter);
oriLabel = new QLabel(tr("DCT (8x8 block)"));
oriLabel->setAlignment(Qt::AlignCenter);
qtzLabel = new QLabel(tr("Quantized 8x8 block"));
qtzLabel->setAlignment(Qt::AlignCenter);
// init a grid layout
mainLayout = new QGridLayout(this);
mainLayout->setSpacing(6);
// init matrices
QMMatrix = new QTableWidget(8, 8, this);
vHeader = QMMatrix->verticalHeader();
vHeader->sectionResizeMode(QHeaderView::Fixed);
vHeader->setDefaultSectionSize(22);
vHeader->hide();
hHeader = QMMatrix->horizontalHeader();
hHeader->sectionResizeMode(QHeaderView::Fixed);
hHeader->setDefaultSectionSize(40);
hHeader->hide();
oriMatrix = new QTableWidget(8, 8, this);
vHeader = oriMatrix->verticalHeader();
vHeader->sectionResizeMode(QHeaderView::Fixed);
vHeader->setDefaultSectionSize(22);
vHeader->hide();
hHeader = oriMatrix->horizontalHeader();
hHeader->sectionResizeMode(QHeaderView::Fixed);
hHeader->setDefaultSectionSize(40);
hHeader->hide();
qtzMatrix = new QTableWidget(8, 8, this);
vHeader = qtzMatrix->verticalHeader();
vHeader->sectionResizeMode(QHeaderView::Fixed);
vHeader->setDefaultSectionSize(22);
vHeader->hide();
hHeader = qtzMatrix->horizontalHeader();
hHeader->sectionResizeMode(QHeaderView::Fixed);
hHeader->setDefaultSectionSize(40);
hHeader->hide();
// put quantization and compression ratio labels into the grid layout
mainLayout->addWidget(whichQM, 0, 0, 1, 1);
mainLayout->addWidget(cmpRate, 1, 0, 1, 1);
mainLayout->addWidget(QMMatrix, 2, 0, 7, 1);
mainLayout->addWidget(qmLabel, 9, 0, 1, 1);
mainLayout->addWidget(oriMatrix, 10, 0, 7, 1);
mainLayout->addWidget(oriLabel, 17, 0, 1, 1);
mainLayout->addWidget(qtzMatrix, 18, 0, 7, 1);
mainLayout->addWidget(qtzLabel, 25, 0, 1, 1);
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++) {
oriMatrix->setItem(i, j, new QTableWidgetItem(""));
qtzMatrix->setItem(i, j, new QTableWidgetItem(""));
QMMatrix->setItem(i, j, new QTableWidgetItem(""));
}
}
void MatrixDsp::matrix2ChangedBySsp(int **crtBlock) {
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++)
oriMatrix->setItem(i, j, new QTableWidgetItem(QString::number(crtBlock[i][j])));
quantizationUpdate();
}
void MatrixDsp::QMUpdated(int **QM, QString QMtitle) {
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++)
QMMatrix->setItem(i, j, new QTableWidgetItem(QString::number(QM[i][j])));
delete whichQM;
whichQM = new QLabel(QMtitle);
whichQM->setAlignment(Qt::AlignCenter);
mainLayout->addWidget(whichQM, 0, 0, 1, 1);
quantizationUpdate();
}
void MatrixDsp::quantizationUpdate() {
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++) {
if (QTableWidgetItem *item = oriMatrix->item(i, j)) {
if (item->text().isEmpty())
return;
}
if (QTableWidgetItem *item = QMMatrix->item(i, j)) {
if (item->text().isEmpty())
return;
}
}
qDebug() << "reach here";
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++)
qtzMatrix->setItem(i, j, new QTableWidgetItem(QString::number(oriMatrix->item(i, j)->text().toInt() / QMMatrix->item(i, j)->text().toInt())));
}