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 void vp8_fast_quantize_b_c(BLOCK
*b
, BLOCKD
*d
)
26 short *coeff_ptr
= b
->coeff
;
27 short *zbin_ptr
= b
->zbin
;
28 short *round_ptr
= b
->round
;
29 short *quant_ptr
= b
->quant
;
30 short *quant_shift_ptr
= b
->quant_shift
;
31 short *qcoeff_ptr
= d
->qcoeff
;
32 short *dqcoeff_ptr
= d
->dqcoeff
;
33 short *dequant_ptr
= d
->dequant
;
35 vpx_memset(qcoeff_ptr
, 0, 32);
36 vpx_memset(dqcoeff_ptr
, 0, 32);
40 for (i
= 0; i
< 16; i
++)
42 rc
= vp8_default_zig_zag1d
[i
];
46 sz
= (z
>> 31); // sign of z
47 x
= (z
^ sz
) - sz
; // x = abs(z)
52 y
= (((x
* quant_ptr
[rc
]) >> 16) + x
)
53 >> quant_shift_ptr
[rc
]; // quantize (x)
54 x
= (y
^ sz
) - sz
; // get the sign back
55 qcoeff_ptr
[rc
] = x
; // write to destination
56 dqcoeff_ptr
[rc
] = x
* dequant_ptr
[rc
]; // dequantized value
60 eob
= i
; // last nonzero coeffs
67 void vp8_regular_quantize_b(BLOCK
*b
, BLOCKD
*d
)
72 short *zbin_boost_ptr
= b
->zrun_zbin_boost
;
73 short *coeff_ptr
= b
->coeff
;
74 short *zbin_ptr
= b
->zbin
;
75 short *round_ptr
= b
->round
;
76 short *quant_ptr
= b
->quant
;
77 short *quant_shift_ptr
= b
->quant_shift
;
78 short *qcoeff_ptr
= d
->qcoeff
;
79 short *dqcoeff_ptr
= d
->dqcoeff
;
80 short *dequant_ptr
= d
->dequant
;
81 short zbin_oq_value
= b
->zbin_extra
;
83 vpx_memset(qcoeff_ptr
, 0, 32);
84 vpx_memset(dqcoeff_ptr
, 0, 32);
88 for (i
= 0; i
< 16; i
++)
90 rc
= vp8_default_zig_zag1d
[i
];
94 // zbin = zbin_ptr[rc] + *zbin_boost_ptr + zbin_oq_value/2;
96 zbin
= zbin_ptr
[rc
] + *zbin_boost_ptr
+ zbin_oq_value
;
99 sz
= (z
>> 31); // sign of z
100 x
= (z
^ sz
) - sz
; // x = abs(z)
105 y
= (((x
* quant_ptr
[rc
]) >> 16) + x
)
106 >> quant_shift_ptr
[rc
]; // quantize (x)
107 x
= (y
^ sz
) - sz
; // get the sign back
108 qcoeff_ptr
[rc
] = x
; // write to destination
109 dqcoeff_ptr
[rc
] = x
* dequant_ptr
[rc
]; // dequantized value
113 eob
= i
; // last nonzero coeffs
114 zbin_boost_ptr
= &b
->zrun_zbin_boost
[0]; // reset zero runlength
122 /* Perform regular quantization, with unbiased rounding and no zero bin. */
123 void vp8_strict_quantize_b(BLOCK
*b
, BLOCKD
*d
)
134 short *quant_shift_ptr
;
139 coeff_ptr
= b
->coeff
;
140 quant_ptr
= b
->quant
;
141 quant_shift_ptr
= b
->quant_shift
;
142 qcoeff_ptr
= d
->qcoeff
;
143 dqcoeff_ptr
= d
->dqcoeff
;
144 dequant_ptr
= d
->dequant
;
146 vpx_memset(qcoeff_ptr
, 0, 32);
147 vpx_memset(dqcoeff_ptr
, 0, 32);
148 for (i
= 0; i
< 16; i
++)
153 /*TODO: These arrays should be stored in zig-zag order.*/
154 rc
= vp8_default_zig_zag1d
[i
];
156 dq
= dequant_ptr
[rc
];
165 y
= (((x
* quant_ptr
[rc
]) >> 16) + x
) >> quant_shift_ptr
[rc
];
166 /* Put the sign back. */
168 /* Save the coefficient and its dequantized value. */
170 dqcoeff_ptr
[rc
] = x
* dq
;
171 /* Remember the last non-zero coefficient. */
181 void vp8_fast_quantize_b_c(BLOCK
*b
, BLOCKD
*d
)
186 short *coeff_ptr
= b
->coeff
;
187 short *round_ptr
= b
->round
;
188 short *quant_ptr
= b
->quant
;
189 short *qcoeff_ptr
= d
->qcoeff
;
190 short *dqcoeff_ptr
= d
->dqcoeff
;
191 short *dequant_ptr
= d
->dequant
;
194 for (i
= 0; i
< 16; i
++)
196 rc
= vp8_default_zig_zag1d
[i
];
199 sz
= (z
>> 31); // sign of z
200 x
= (z
^ sz
) - sz
; // x = abs(z)
202 y
= ((x
+ round_ptr
[rc
]) * quant_ptr
[rc
]) >> 16; // quantize (x)
203 x
= (y
^ sz
) - sz
; // get the sign back
204 qcoeff_ptr
[rc
] = x
; // write to destination
205 dqcoeff_ptr
[rc
] = x
* dequant_ptr
[rc
]; // dequantized value
209 eob
= i
; // last nonzero coeffs
215 void vp8_regular_quantize_b(BLOCK
*b
, BLOCKD
*d
)
220 short *zbin_boost_ptr
= b
->zrun_zbin_boost
;
221 short *coeff_ptr
= b
->coeff
;
222 short *zbin_ptr
= b
->zbin
;
223 short *round_ptr
= b
->round
;
224 short *quant_ptr
= b
->quant
;
225 short *qcoeff_ptr
= d
->qcoeff
;
226 short *dqcoeff_ptr
= d
->dqcoeff
;
227 short *dequant_ptr
= d
->dequant
;
228 short zbin_oq_value
= b
->zbin_extra
;
230 vpx_memset(qcoeff_ptr
, 0, 32);
231 vpx_memset(dqcoeff_ptr
, 0, 32);
235 for (i
= 0; i
< 16; i
++)
237 rc
= vp8_default_zig_zag1d
[i
];
241 // zbin = zbin_ptr[rc] + *zbin_boost_ptr + zbin_oq_value/2;
243 zbin
= zbin_ptr
[rc
] + *zbin_boost_ptr
+ zbin_oq_value
;
246 sz
= (z
>> 31); // sign of z
247 x
= (z
^ sz
) - sz
; // x = abs(z)
251 y
= ((x
+ round_ptr
[rc
]) * quant_ptr
[rc
]) >> 16; // quantize (x)
252 x
= (y
^ sz
) - sz
; // get the sign back
253 qcoeff_ptr
[rc
] = x
; // write to destination
254 dqcoeff_ptr
[rc
] = x
* dequant_ptr
[rc
]; // dequantized value
258 eob
= i
; // last nonzero coeffs
259 zbin_boost_ptr
= &b
->zrun_zbin_boost
[0]; // reset zero runlength
269 void vp8_quantize_mby(MACROBLOCK
*x
)
272 int has_2nd_order
= (x
->e_mbd
.mode_info_context
->mbmi
.mode
!= B_PRED
273 && x
->e_mbd
.mode_info_context
->mbmi
.mode
!= SPLITMV
);
275 for (i
= 0; i
< 16; i
++)
276 x
->quantize_b(&x
->block
[i
], &x
->e_mbd
.block
[i
]);
279 x
->quantize_b(&x
->block
[24], &x
->e_mbd
.block
[24]);
282 void vp8_quantize_mb(MACROBLOCK
*x
)
285 int has_2nd_order
=(x
->e_mbd
.mode_info_context
->mbmi
.mode
!= B_PRED
286 && x
->e_mbd
.mode_info_context
->mbmi
.mode
!= SPLITMV
);
288 for (i
= 0; i
< 24+has_2nd_order
; i
++)
289 x
->quantize_b(&x
->block
[i
], &x
->e_mbd
.block
[i
]);
293 void vp8_quantize_mbuv(MACROBLOCK
*x
)
297 for (i
= 16; i
< 24; i
++)
298 x
->quantize_b(&x
->block
[i
], &x
->e_mbd
.block
[i
]);