1 /********************************************************************
3 * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
5 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2007 *
9 * by the Xiph.Org Foundation http://www.xiph.org/ *
11 ********************************************************************
14 last mod: $Id: dequant.c 14369 2008-01-05 23:15:32Z tterribe $
16 ********************************************************************/
24 int oc_quant_params_unpack(oggpack_buffer
*_opb
,
25 th_quant_info
*_qinfo
){
26 th_quant_base
*base_mats
;
39 theorapackB_read(_opb
,3,&val
);
42 theorapackB_read(_opb
,nbits
,&val
);
43 _qinfo
->loop_filter_limits
[qi
]=(unsigned char)val
;
45 theorapackB_read(_opb
,4,&val
);
48 theorapackB_read(_opb
,nbits
,&val
);
49 _qinfo
->ac_scale
[qi
]=(ogg_uint16_t
)val
;
51 theorapackB_read(_opb
,4,&val
);
54 theorapackB_read(_opb
,nbits
,&val
);
55 _qinfo
->dc_scale
[qi
]=(ogg_uint16_t
)val
;
57 theorapackB_read(_opb
,9,&val
);
58 nbase_mats
=(int)val
+1;
59 base_mats
=_ogg_malloc(nbase_mats
*sizeof(base_mats
[0]));
60 for(bmi
=0;bmi
<nbase_mats
;bmi
++){
62 theorapackB_read(_opb
,8,&val
);
63 base_mats
[bmi
][ci
]=(unsigned char)val
;
66 nbits
=oc_ilog(nbase_mats
-1);
68 th_quant_ranges
*qranges
;
73 qranges
=_qinfo
->qi_ranges
[qti
]+pli
;
75 theorapackB_read1(_opb
,&val
);
80 theorapackB_read1(_opb
,&val
);
94 *qranges
=*(_qinfo
->qi_ranges
[qtj
]+plj
);
98 theorapackB_read(_opb
,nbits
,&val
);
100 for(qi
=qri
=0;qi
<63;){
101 theorapackB_read(_opb
,oc_ilog(62-qi
),&val
);
102 sizes
[qri
]=(int)val
+1;
104 theorapackB_read(_opb
,nbits
,&val
);
105 indices
[++qri
]=(int)val
;
107 /*Note: The caller is responsible for cleaning up any partially
110 _ogg_free(base_mats
);
111 return TH_EBADHEADER
;
113 qranges
->nranges
=qri
;
114 qranges
->sizes
=qrsizes
=(int *)_ogg_malloc(qri
*sizeof(qrsizes
[0]));
115 memcpy(qrsizes
,sizes
,qri
*sizeof(qrsizes
[0]));
116 qrbms
=(th_quant_base
*)_ogg_malloc((qri
+1)*sizeof(qrbms
[0]));
117 qranges
->base_matrices
=(const th_quant_base
*)qrbms
;
120 /*Note: The caller is responsible for cleaning up any partially
123 _ogg_free(base_mats
);
124 return TH_EBADHEADER
;
126 memcpy(qrbms
[qri
],base_mats
[bmi
],sizeof(qrbms
[qri
]));
132 /* dump the tables */
135 TH_DEBUG("loop filter limits = {");
138 for(j
=0;j
<16;i
++,j
++)
139 TH_DEBUG("%3d ",_qinfo
->loop_filter_limits
[i
]);
143 TH_DEBUG("ac scale = {");
146 for(j
=0;j
<16;i
++,j
++)
147 TH_DEBUG("%3d ",_qinfo
->ac_scale
[i
]);
151 TH_DEBUG("dc scale = {");
154 for(j
=0;j
<16;i
++,j
++)
155 TH_DEBUG("%3d ",_qinfo
->dc_scale
[i
]);
162 {"intra Y bases","intra U bases", "intra V bases"},
163 {"inter Y bases","inter U bases", "inter V bases"}
166 th_quant_ranges
*r
= &_qinfo
->qi_ranges
[k
][l
];
167 TH_DEBUG("%s = {\n",name
[k
][l
]);
168 TH_DEBUG(" ranges = %d\n",r
->nranges
);
169 TH_DEBUG(" intervals = { ");
170 for(i
=0;i
<r
->nranges
;i
++)
171 TH_DEBUG("%3d ",r
->sizes
[i
]);
173 TH_DEBUG("\n matricies = { ");
174 for(m
=0;m
<r
->nranges
+1;m
++){
179 TH_DEBUG("%3d ",r
->base_matrices
[m
][i
]);
189 _ogg_free(base_mats
);
193 void oc_quant_params_clear(th_quant_info
*_qinfo
){
200 /*Clear any duplicate pointer references.*/
206 if(_qinfo
->qi_ranges
[qti
][pli
].sizes
==
207 _qinfo
->qi_ranges
[qtj
][plj
].sizes
){
208 _qinfo
->qi_ranges
[qti
][pli
].sizes
=NULL
;
210 if(_qinfo
->qi_ranges
[qti
][pli
].base_matrices
==
211 _qinfo
->qi_ranges
[qtj
][plj
].base_matrices
){
212 _qinfo
->qi_ranges
[qti
][pli
].base_matrices
=NULL
;
216 if(_qinfo
->qi_ranges
[1][pli
].sizes
==
217 _qinfo
->qi_ranges
[0][pli
].sizes
){
218 _qinfo
->qi_ranges
[1][pli
].sizes
=NULL
;
220 if(_qinfo
->qi_ranges
[1][pli
].base_matrices
==
221 _qinfo
->qi_ranges
[0][pli
].base_matrices
){
222 _qinfo
->qi_ranges
[1][pli
].base_matrices
=NULL
;
225 /*Now free all the non-duplicate storage.*/
226 _ogg_free((void *)_qinfo
->qi_ranges
[qti
][pli
].sizes
);
227 _ogg_free((void *)_qinfo
->qi_ranges
[qti
][pli
].base_matrices
);