Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /******************************************************************** |
michael@0 | 2 | * * |
michael@0 | 3 | * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. * |
michael@0 | 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * |
michael@0 | 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * |
michael@0 | 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * |
michael@0 | 7 | * * |
michael@0 | 8 | * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 * |
michael@0 | 9 | * by the Xiph.Org Foundation and contributors http://www.xiph.org/ * |
michael@0 | 10 | * * |
michael@0 | 11 | ******************************************************************** |
michael@0 | 12 | |
michael@0 | 13 | function: |
michael@0 | 14 | last mod: $Id: dequant.c 16503 2009-08-22 18:14:02Z giles $ |
michael@0 | 15 | |
michael@0 | 16 | ********************************************************************/ |
michael@0 | 17 | |
michael@0 | 18 | #include <stdlib.h> |
michael@0 | 19 | #include <string.h> |
michael@0 | 20 | #include <ogg/ogg.h> |
michael@0 | 21 | #include "dequant.h" |
michael@0 | 22 | #include "decint.h" |
michael@0 | 23 | |
michael@0 | 24 | int oc_quant_params_unpack(oc_pack_buf *_opb,th_quant_info *_qinfo){ |
michael@0 | 25 | th_quant_base *base_mats; |
michael@0 | 26 | long val; |
michael@0 | 27 | int nbase_mats; |
michael@0 | 28 | int sizes[64]; |
michael@0 | 29 | int indices[64]; |
michael@0 | 30 | int nbits; |
michael@0 | 31 | int bmi; |
michael@0 | 32 | int ci; |
michael@0 | 33 | int qti; |
michael@0 | 34 | int pli; |
michael@0 | 35 | int qri; |
michael@0 | 36 | int qi; |
michael@0 | 37 | int i; |
michael@0 | 38 | val=oc_pack_read(_opb,3); |
michael@0 | 39 | nbits=(int)val; |
michael@0 | 40 | for(qi=0;qi<64;qi++){ |
michael@0 | 41 | val=oc_pack_read(_opb,nbits); |
michael@0 | 42 | _qinfo->loop_filter_limits[qi]=(unsigned char)val; |
michael@0 | 43 | } |
michael@0 | 44 | val=oc_pack_read(_opb,4); |
michael@0 | 45 | nbits=(int)val+1; |
michael@0 | 46 | for(qi=0;qi<64;qi++){ |
michael@0 | 47 | val=oc_pack_read(_opb,nbits); |
michael@0 | 48 | _qinfo->ac_scale[qi]=(ogg_uint16_t)val; |
michael@0 | 49 | } |
michael@0 | 50 | val=oc_pack_read(_opb,4); |
michael@0 | 51 | nbits=(int)val+1; |
michael@0 | 52 | for(qi=0;qi<64;qi++){ |
michael@0 | 53 | val=oc_pack_read(_opb,nbits); |
michael@0 | 54 | _qinfo->dc_scale[qi]=(ogg_uint16_t)val; |
michael@0 | 55 | } |
michael@0 | 56 | val=oc_pack_read(_opb,9); |
michael@0 | 57 | nbase_mats=(int)val+1; |
michael@0 | 58 | base_mats=_ogg_malloc(nbase_mats*sizeof(base_mats[0])); |
michael@0 | 59 | if(base_mats==NULL)return TH_EFAULT; |
michael@0 | 60 | for(bmi=0;bmi<nbase_mats;bmi++){ |
michael@0 | 61 | for(ci=0;ci<64;ci++){ |
michael@0 | 62 | val=oc_pack_read(_opb,8); |
michael@0 | 63 | base_mats[bmi][ci]=(unsigned char)val; |
michael@0 | 64 | } |
michael@0 | 65 | } |
michael@0 | 66 | nbits=oc_ilog(nbase_mats-1); |
michael@0 | 67 | for(i=0;i<6;i++){ |
michael@0 | 68 | th_quant_ranges *qranges; |
michael@0 | 69 | th_quant_base *qrbms; |
michael@0 | 70 | int *qrsizes; |
michael@0 | 71 | qti=i/3; |
michael@0 | 72 | pli=i%3; |
michael@0 | 73 | qranges=_qinfo->qi_ranges[qti]+pli; |
michael@0 | 74 | if(i>0){ |
michael@0 | 75 | val=oc_pack_read1(_opb); |
michael@0 | 76 | if(!val){ |
michael@0 | 77 | int qtj; |
michael@0 | 78 | int plj; |
michael@0 | 79 | if(qti>0){ |
michael@0 | 80 | val=oc_pack_read1(_opb); |
michael@0 | 81 | if(val){ |
michael@0 | 82 | qtj=qti-1; |
michael@0 | 83 | plj=pli; |
michael@0 | 84 | } |
michael@0 | 85 | else{ |
michael@0 | 86 | qtj=(i-1)/3; |
michael@0 | 87 | plj=(i-1)%3; |
michael@0 | 88 | } |
michael@0 | 89 | } |
michael@0 | 90 | else{ |
michael@0 | 91 | qtj=(i-1)/3; |
michael@0 | 92 | plj=(i-1)%3; |
michael@0 | 93 | } |
michael@0 | 94 | *qranges=*(_qinfo->qi_ranges[qtj]+plj); |
michael@0 | 95 | continue; |
michael@0 | 96 | } |
michael@0 | 97 | } |
michael@0 | 98 | val=oc_pack_read(_opb,nbits); |
michael@0 | 99 | indices[0]=(int)val; |
michael@0 | 100 | for(qi=qri=0;qi<63;){ |
michael@0 | 101 | val=oc_pack_read(_opb,oc_ilog(62-qi)); |
michael@0 | 102 | sizes[qri]=(int)val+1; |
michael@0 | 103 | qi+=(int)val+1; |
michael@0 | 104 | val=oc_pack_read(_opb,nbits); |
michael@0 | 105 | indices[++qri]=(int)val; |
michael@0 | 106 | } |
michael@0 | 107 | /*Note: The caller is responsible for cleaning up any partially |
michael@0 | 108 | constructed qinfo.*/ |
michael@0 | 109 | if(qi>63){ |
michael@0 | 110 | _ogg_free(base_mats); |
michael@0 | 111 | return TH_EBADHEADER; |
michael@0 | 112 | } |
michael@0 | 113 | qranges->nranges=qri; |
michael@0 | 114 | qranges->sizes=qrsizes=(int *)_ogg_malloc(qri*sizeof(qrsizes[0])); |
michael@0 | 115 | if(qranges->sizes==NULL){ |
michael@0 | 116 | /*Note: The caller is responsible for cleaning up any partially |
michael@0 | 117 | constructed qinfo.*/ |
michael@0 | 118 | _ogg_free(base_mats); |
michael@0 | 119 | return TH_EFAULT; |
michael@0 | 120 | } |
michael@0 | 121 | memcpy(qrsizes,sizes,qri*sizeof(qrsizes[0])); |
michael@0 | 122 | qrbms=(th_quant_base *)_ogg_malloc((qri+1)*sizeof(qrbms[0])); |
michael@0 | 123 | if(qrbms==NULL){ |
michael@0 | 124 | /*Note: The caller is responsible for cleaning up any partially |
michael@0 | 125 | constructed qinfo.*/ |
michael@0 | 126 | _ogg_free(base_mats); |
michael@0 | 127 | return TH_EFAULT; |
michael@0 | 128 | } |
michael@0 | 129 | qranges->base_matrices=(const th_quant_base *)qrbms; |
michael@0 | 130 | do{ |
michael@0 | 131 | bmi=indices[qri]; |
michael@0 | 132 | /*Note: The caller is responsible for cleaning up any partially |
michael@0 | 133 | constructed qinfo.*/ |
michael@0 | 134 | if(bmi>=nbase_mats){ |
michael@0 | 135 | _ogg_free(base_mats); |
michael@0 | 136 | return TH_EBADHEADER; |
michael@0 | 137 | } |
michael@0 | 138 | memcpy(qrbms[qri],base_mats[bmi],sizeof(qrbms[qri])); |
michael@0 | 139 | } |
michael@0 | 140 | while(qri-->0); |
michael@0 | 141 | } |
michael@0 | 142 | _ogg_free(base_mats); |
michael@0 | 143 | return 0; |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | void oc_quant_params_clear(th_quant_info *_qinfo){ |
michael@0 | 147 | int i; |
michael@0 | 148 | for(i=6;i-->0;){ |
michael@0 | 149 | int qti; |
michael@0 | 150 | int pli; |
michael@0 | 151 | qti=i/3; |
michael@0 | 152 | pli=i%3; |
michael@0 | 153 | /*Clear any duplicate pointer references.*/ |
michael@0 | 154 | if(i>0){ |
michael@0 | 155 | int qtj; |
michael@0 | 156 | int plj; |
michael@0 | 157 | qtj=(i-1)/3; |
michael@0 | 158 | plj=(i-1)%3; |
michael@0 | 159 | if(_qinfo->qi_ranges[qti][pli].sizes== |
michael@0 | 160 | _qinfo->qi_ranges[qtj][plj].sizes){ |
michael@0 | 161 | _qinfo->qi_ranges[qti][pli].sizes=NULL; |
michael@0 | 162 | } |
michael@0 | 163 | if(_qinfo->qi_ranges[qti][pli].base_matrices== |
michael@0 | 164 | _qinfo->qi_ranges[qtj][plj].base_matrices){ |
michael@0 | 165 | _qinfo->qi_ranges[qti][pli].base_matrices=NULL; |
michael@0 | 166 | } |
michael@0 | 167 | } |
michael@0 | 168 | if(qti>0){ |
michael@0 | 169 | if(_qinfo->qi_ranges[1][pli].sizes== |
michael@0 | 170 | _qinfo->qi_ranges[0][pli].sizes){ |
michael@0 | 171 | _qinfo->qi_ranges[1][pli].sizes=NULL; |
michael@0 | 172 | } |
michael@0 | 173 | if(_qinfo->qi_ranges[1][pli].base_matrices== |
michael@0 | 174 | _qinfo->qi_ranges[0][pli].base_matrices){ |
michael@0 | 175 | _qinfo->qi_ranges[1][pli].base_matrices=NULL; |
michael@0 | 176 | } |
michael@0 | 177 | } |
michael@0 | 178 | /*Now free all the non-duplicate storage.*/ |
michael@0 | 179 | _ogg_free((void *)_qinfo->qi_ranges[qti][pli].sizes); |
michael@0 | 180 | _ogg_free((void *)_qinfo->qi_ranges[qti][pli].base_matrices); |
michael@0 | 181 | } |
michael@0 | 182 | } |