2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
13 #include "vpx_mem/vpx_mem.h"
17 #include "predictdc.h"
21 #ifdef EXACT_FASTQUANT
22 void vp8_fast_quantize_b_c(BLOCK
*b
, BLOCKD
*d
)
27 short *coeff_ptr
= b
->coeff
;
28 short *zbin_ptr
= b
->zbin
;
29 short *round_ptr
= b
->round
;
30 short *quant_ptr
= b
->quant_fast
;
31 short *quant_shift_ptr
= b
->quant_shift
;
32 short *qcoeff_ptr
= d
->qcoeff
;
33 short *dqcoeff_ptr
= d
->dqcoeff
;
34 short *dequant_ptr
= d
->dequant
;
36 vpx_memset(qcoeff_ptr
, 0, 32);
37 vpx_memset(dqcoeff_ptr
, 0, 32);
41 for (i
= 0; i
< 16; i
++)
43 rc
= vp8_default_zig_zag1d
[i
];
47 sz
= (z
>> 31); // sign of z
48 x
= (z
^ sz
) - sz
; // x = abs(z)
53 y
= (((x
* quant_ptr
[rc
]) >> 16) + x
)
54 >> quant_shift_ptr
[rc
]; // quantize (x)
55 x
= (y
^ sz
) - sz
; // get the sign back
56 qcoeff_ptr
[rc
] = x
; // write to destination
57 dqcoeff_ptr
[rc
] = x
* dequant_ptr
[rc
]; // dequantized value
61 eob
= i
; // last nonzero coeffs
70 void vp8_fast_quantize_b_c(BLOCK
*b
, BLOCKD
*d
)
74 short *coeff_ptr
= b
->coeff
;
75 short *round_ptr
= b
->round
;
76 short *quant_ptr
= b
->quant_fast
;
77 short *qcoeff_ptr
= d
->qcoeff
;
78 short *dqcoeff_ptr
= d
->dqcoeff
;
79 short *dequant_ptr
= d
->dequant
;
82 for (i
= 0; i
< 16; i
++)
84 rc
= vp8_default_zig_zag1d
[i
];
87 sz
= (z
>> 31); // sign of z
88 x
= (z
^ sz
) - sz
; // x = abs(z)
90 y
= ((x
+ round_ptr
[rc
]) * quant_ptr
[rc
]) >> 16; // quantize (x)
91 x
= (y
^ sz
) - sz
; // get the sign back
92 qcoeff_ptr
[rc
] = x
; // write to destination
93 dqcoeff_ptr
[rc
] = x
* dequant_ptr
[rc
]; // dequantized value
97 eob
= i
; // last nonzero coeffs
106 void vp8_regular_quantize_b(BLOCK
*b
, BLOCKD
*d
)
111 short *zbin_boost_ptr
= b
->zrun_zbin_boost
;
112 short *coeff_ptr
= b
->coeff
;
113 short *zbin_ptr
= b
->zbin
;
114 short *round_ptr
= b
->round
;
115 short *quant_ptr
= b
->quant
;
116 short *quant_shift_ptr
= b
->quant_shift
;
117 short *qcoeff_ptr
= d
->qcoeff
;
118 short *dqcoeff_ptr
= d
->dqcoeff
;
119 short *dequant_ptr
= d
->dequant
;
120 short zbin_oq_value
= b
->zbin_extra
;
122 vpx_memset(qcoeff_ptr
, 0, 32);
123 vpx_memset(dqcoeff_ptr
, 0, 32);
127 for (i
= 0; i
< 16; i
++)
129 rc
= vp8_default_zig_zag1d
[i
];
132 zbin
= zbin_ptr
[rc
] + *zbin_boost_ptr
+ zbin_oq_value
;
135 sz
= (z
>> 31); // sign of z
136 x
= (z
^ sz
) - sz
; // x = abs(z)
141 y
= (((x
* quant_ptr
[rc
]) >> 16) + x
)
142 >> quant_shift_ptr
[rc
]; // quantize (x)
143 x
= (y
^ sz
) - sz
; // get the sign back
144 qcoeff_ptr
[rc
] = x
; // write to destination
145 dqcoeff_ptr
[rc
] = x
* dequant_ptr
[rc
]; // dequantized value
149 eob
= i
; // last nonzero coeffs
150 zbin_boost_ptr
= b
->zrun_zbin_boost
; // reset zero runlength
158 /* Perform regular quantization, with unbiased rounding and no zero bin. */
159 void vp8_strict_quantize_b(BLOCK
*b
, BLOCKD
*d
)
170 short *quant_shift_ptr
;
175 coeff_ptr
= b
->coeff
;
176 quant_ptr
= b
->quant
;
177 quant_shift_ptr
= b
->quant_shift
;
178 qcoeff_ptr
= d
->qcoeff
;
179 dqcoeff_ptr
= d
->dqcoeff
;
180 dequant_ptr
= d
->dequant
;
182 vpx_memset(qcoeff_ptr
, 0, 32);
183 vpx_memset(dqcoeff_ptr
, 0, 32);
184 for (i
= 0; i
< 16; i
++)
189 /*TODO: These arrays should be stored in zig-zag order.*/
190 rc
= vp8_default_zig_zag1d
[i
];
192 dq
= dequant_ptr
[rc
];
201 y
= (((x
* quant_ptr
[rc
]) >> 16) + x
) >> quant_shift_ptr
[rc
];
202 /* Put the sign back. */
204 /* Save the coefficient and its dequantized value. */
206 dqcoeff_ptr
[rc
] = x
* dq
;
207 /* Remember the last non-zero coefficient. */
218 void vp8_regular_quantize_b(BLOCK
*b
, BLOCKD
*d
)
223 short *zbin_boost_ptr
= b
->zrun_zbin_boost
;
224 short *coeff_ptr
= b
->coeff
;
225 short *zbin_ptr
= b
->zbin
;
226 short *round_ptr
= b
->round
;
227 short *quant_ptr
= b
->quant
;
228 short *qcoeff_ptr
= d
->qcoeff
;
229 short *dqcoeff_ptr
= d
->dqcoeff
;
230 short *dequant_ptr
= d
->dequant
;
231 short zbin_oq_value
= b
->zbin_extra
;
233 vpx_memset(qcoeff_ptr
, 0, 32);
234 vpx_memset(dqcoeff_ptr
, 0, 32);
238 for (i
= 0; i
< 16; i
++)
240 rc
= vp8_default_zig_zag1d
[i
];
244 // zbin = zbin_ptr[rc] + *zbin_boost_ptr + zbin_oq_value/2;
246 zbin
= zbin_ptr
[rc
] + *zbin_boost_ptr
+ zbin_oq_value
;
249 sz
= (z
>> 31); // sign of z
250 x
= (z
^ sz
) - sz
; // x = abs(z)
254 y
= ((x
+ round_ptr
[rc
]) * quant_ptr
[rc
]) >> 16; // quantize (x)
255 x
= (y
^ sz
) - sz
; // get the sign back
256 qcoeff_ptr
[rc
] = x
; // write to destination
257 dqcoeff_ptr
[rc
] = x
* dequant_ptr
[rc
]; // dequantized value
261 eob
= i
; // last nonzero coeffs
262 zbin_boost_ptr
= &b
->zrun_zbin_boost
[0]; // reset zero runlength
272 void vp8_quantize_mby(MACROBLOCK
*x
)
275 int has_2nd_order
= (x
->e_mbd
.mode_info_context
->mbmi
.mode
!= B_PRED
276 && x
->e_mbd
.mode_info_context
->mbmi
.mode
!= SPLITMV
);
278 for (i
= 0; i
< 16; i
++)
279 x
->quantize_b(&x
->block
[i
], &x
->e_mbd
.block
[i
]);
282 x
->quantize_b(&x
->block
[24], &x
->e_mbd
.block
[24]);
285 void vp8_quantize_mb(MACROBLOCK
*x
)
288 int has_2nd_order
=(x
->e_mbd
.mode_info_context
->mbmi
.mode
!= B_PRED
289 && x
->e_mbd
.mode_info_context
->mbmi
.mode
!= SPLITMV
);
291 for (i
= 0; i
< 24+has_2nd_order
; i
++)
292 x
->quantize_b(&x
->block
[i
], &x
->e_mbd
.block
[i
]);
296 void vp8_quantize_mbuv(MACROBLOCK
*x
)
300 for (i
= 16; i
< 24; i
++)
301 x
->quantize_b(&x
->block
[i
], &x
->e_mbd
.block
[i
]);