8 unsigned OC_DC_QUANT_MIN
[2]={4<<2,8<<2};
9 unsigned OC_AC_QUANT_MIN
[2]={2<<2,4<<2};
13 /*Initializes the dequantization tables from a set of quantizer info.
14 Currently the dequantizer (and elsewhere enquantizer) tables are expected to
15 be initialized as pointing to the storage reserved for them in the
16 oc_theora_state (resp. oc_enc_ctx) structure.
17 If some tables are duplicates of others, the pointers will be adjusted to
18 point to a single copy of the tables, but the storage for them will not be
20 If you're concerned about the memory footprint, the obvious thing to do is
21 to move the storage out of its fixed place in the structures and allocate
23 However, a much, much better option is to only store the quantization
24 matrices being used for the current frame, and to recalculate these as the
25 qi values change between frames (this is what VP3 did).*/
26 void oc_dequant_tables_init(oc_quant_table
*_dequant
[2][3],
27 int _pp_dc_scale
[64],const th_quant_info
*_qinfo
){
30 for(qti
=0;qti
<2;qti
++)for(pli
=0;pli
<3;pli
++){
33 /*These simple checks help us improve cache coherency later.*/
34 if(pli
>0&&memcmp(_qinfo
->qi_ranges
[qti
]+pli
-1,
35 _qinfo
->qi_ranges
[qti
]+pli
,sizeof(_qinfo
->qi_ranges
[qti
][pli
]))==0){
36 _dequant
[qti
][pli
]=_dequant
[qti
][pli
-1];
39 if(qti
>0&&memcmp(_qinfo
->qi_ranges
[qti
-1]+pli
,
40 _qinfo
->qi_ranges
[qti
]+pli
,sizeof(_qinfo
->qi_ranges
[qti
][pli
]))==0){
41 _dequant
[qti
][pli
]=_dequant
[qti
-1][pli
];
44 for(qi
=qri
=0;qri
<=_qinfo
->qi_ranges
[qti
][pli
].nranges
;qri
++){
50 memcpy(base
,_qinfo
->qi_ranges
[qti
][pli
].base_matrices
[qri
],
53 if(qri
==_qinfo
->qi_ranges
[qti
][pli
].nranges
)qi_end
=qi
+1;
54 else qi_end
=qi
+_qinfo
->qi_ranges
[qti
][pli
].sizes
[qri
];
57 /*In the original VP3.2 code, the rounding offset and the size of the
58 dead zone around 0 were controlled by a "sharpness" parameter.
59 The size of our dead zone is now controlled by the per-coefficient
60 quality thresholds returned by our HVS module.
61 We round down from a more accurate value when the quality of the
62 reconstruction does not fall below our threshold and it saves bits.
63 Hence, all of that VP3.2 code is gone from here, and the remaining
64 floating point code has been implemented as equivalent integer code
65 with exact precision.*/
66 /*Scale DC the coefficient from the proper table.*/
67 qfac
=(ogg_uint32_t
)_qinfo
->dc_scale
[qi
]*base
[0];
68 if(_pp_dc_scale
!=NULL
)_pp_dc_scale
[qi
]=(int)(qfac
/160);
70 q
=OC_CLAMPI(OC_DC_QUANT_MIN
[qti
],q
,OC_QUANT_MAX
);
71 _dequant
[qti
][pli
][qi
][0]=(ogg_uint16_t
)q
;
72 /*Now scale AC coefficients from the proper table.*/
74 q
=((ogg_uint32_t
)_qinfo
->ac_scale
[qi
]*base
[ci
]/100)<<2;
75 q
=OC_CLAMPI(OC_AC_QUANT_MIN
[qti
],q
,OC_QUANT_MAX
);
76 _dequant
[qti
][pli
][qi
][ci
]=(ogg_uint16_t
)q
;
78 if(++qi
>=qi_end
)break;
79 /*Interpolate the next base matrix.*/
81 base
[ci
]=(unsigned char)(
82 (2*((qi_end
-qi
)*_qinfo
->qi_ranges
[qti
][pli
].base_matrices
[qri
][ci
]+
83 (qi
-qi_start
)*_qinfo
->qi_ranges
[qti
][pli
].base_matrices
[qri
+1][ci
])
84 +_qinfo
->qi_ranges
[qti
][pli
].sizes
[qri
])/
85 (2*_qinfo
->qi_ranges
[qti
][pli
].sizes
[qri
]));