@@ -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 */
153165void 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
167178void 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
187190void 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