Skip to content

Commit 5a4a462

Browse files
committed
fix quant params
1 parent 57db9bb commit 5a4a462

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

inc/qdct.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#include "block.h"
66

77
// MAX QP for luma is 51, MAX QP for chroma is 39
8-
const int LUMA_QP = 28;
9-
const int CHROMA_QP = 28;
8+
const int LUMA_QP = 20;
9+
const int CHROMA_QP = 12;
1010
const int mat_MF[6][3] = {
1111
{13107, 5243, 8066},
1212
{11916, 4660, 7490},

src/qdct.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,18 @@ void forward_quantize4x4(const int mat_x[][4], int mat_z[][4], const int QP) {
124124
}
125125
}
126126

127+
void forward_DC_quantize4x4(const int mat_x[][4], int mat_z[][4], const int QP) {
128+
int qbits = 15 + floor(QP / 6);
129+
int f = (int)(pow(2.0, qbits) / 3.0);
130+
for (int i = 0; i < 4; i++) {
131+
for (int j = 0; j < 4; j++) {
132+
mat_z[i][j] = (abs(mat_x[i][j]) * mat_MF[QP % 6][0] + 2 * f) >> (qbits + 1);
133+
if (mat_x[i][j] < 0)
134+
mat_z[i][j] = -mat_z[i][j];
135+
}
136+
}
137+
}
138+
127139
/* Rescaling (inversed quantization)
128140
*
129141
* By formula:
@@ -152,32 +164,23 @@ void inverse_quantize4x4(const int mat_x[][4], int mat_z[][4], const int QP) {
152164
*/
153165
void inverse_DC_quantize4x4(const int mat_x[][4], int mat_z[][4], const int QP) {
154166
int t = floor(QP / 6);
155-
int f = (int)pow(2.0, 1-t);
156-
int k = 0;
167+
int f = (int)pow(2.0, 1 - t);
157168
for (int i = 0; i < 4; i++) {
158169
for (int j = 0; j < 4; j++) {
159170
if (QP >= 12)
160-
mat_z[i][j] = (mat_x[i][j] * mat_V[QP % 6][k]) << (t - 2);
171+
mat_z[i][j] = (mat_x[i][j] * mat_V[QP % 6][0]) << (t - 2);
161172
else
162-
mat_z[i][j] = (mat_x[i][j] * mat_V[QP % 6][k] + f) >> (2 - t);
173+
mat_z[i][j] = (mat_x[i][j] * mat_V[QP % 6][0] + f) >> (2 - t);
163174
}
164175
}
165176
}
166177

167178
void forward_quantize2x2(const int mat_x[][2], int mat_z[][2], const int QP) {
168179
int qbits = 15 + floor(QP / 6);
169180
int f = (int)(pow(2.0, qbits) / 3.0);
170-
int k;
171181
for (int i = 0; i < 2; i++) {
172182
for (int j = 0; j < 2; j++) {
173-
if (i == 0 && j == 0)
174-
k = 0;
175-
else if (i == 1 && j == 1)
176-
k = 1;
177-
else
178-
k = 2;
179-
180-
mat_z[i][j] = (abs(mat_x[i][j]) * mat_MF[QP % 6][k] + f) >> qbits;
183+
mat_z[i][j] = (abs(mat_x[i][j]) * mat_MF[QP % 6][0] + 2 * f) >> (qbits + 1);
181184
if (mat_x[i][j] < 0)
182185
mat_z[i][j] = -mat_z[i][j];
183186
}
@@ -186,13 +189,12 @@ void forward_quantize2x2(const int mat_x[][2], int mat_z[][2], const int QP) {
186189

187190
void inverse_quantize2x2(const int mat_x[][2], int mat_z[][2], const int QP) {
188191
int t = floor(QP / 6);
189-
int k = 0;
190192
for (int i = 0; i < 2; i++) {
191193
for (int j = 0; j < 2; j++) {
192194
if (QP >= 6)
193-
mat_z[i][j] = (mat_x[i][j] * mat_V[QP % 6][k]) << (t - 1);
195+
mat_z[i][j] = (mat_x[i][j] * mat_V[QP % 6][0]) << (t - 1);
194196
else
195-
mat_z[i][j] = (mat_x[i][j] * mat_V[QP % 6][k]) >> 1;
197+
mat_z[i][j] = (mat_x[i][j] * mat_V[QP % 6][0]) >> 1;
196198
}
197199
}
198200
}
@@ -349,7 +351,7 @@ inline void forward_qdct(T& block, const int BLOCK_SIZE, const int QP) {
349351
}
350352
}
351353
forward_hadamard4x4(mat16, mat_x);
352-
forward_quantize4x4(mat_x, mat16, QP);
354+
forward_DC_quantize4x4(mat_x, mat16, QP);
353355
}
354356
else { // BLOCK_SIZE = 8
355357
int mat_p[2][2];

0 commit comments

Comments
 (0)