Mercurial > libavcodec.hg
annotate golomb.h @ 4053:fb4e436780fb libavcodec
handle limit>32 for set_ur_golomb_jpegls()
| author | kostya |
|---|---|
| date | Sun, 22 Oct 2006 04:52:15 +0000 |
| parents | c8c591fe26f8 |
| children | 4394344397d8 |
| rev | line source |
|---|---|
| 1168 | 1 /* |
| 2 * exp golomb vlc stuff | |
| 3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> | |
| 2215 | 4 * Copyright (c) 2004 Alex Beregszaszi |
| 1168 | 5 * |
|
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3353
diff
changeset
|
6 * This file is part of FFmpeg. |
|
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3353
diff
changeset
|
7 * |
|
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3353
diff
changeset
|
8 * FFmpeg is free software; you can redistribute it and/or |
| 1168 | 9 * modify it under the terms of the GNU Lesser General Public |
| 10 * License as published by the Free Software Foundation; either | |
|
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3353
diff
changeset
|
11 * version 2.1 of the License, or (at your option) any later version. |
| 1168 | 12 * |
|
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3353
diff
changeset
|
13 * FFmpeg is distributed in the hope that it will be useful, |
| 1168 | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 16 * Lesser General Public License for more details. | |
| 17 * | |
| 18 * You should have received a copy of the GNU Lesser General Public | |
|
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3353
diff
changeset
|
19 * License along with FFmpeg; if not, write to the Free Software |
|
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2979
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 1168 | 21 * |
| 22 */ | |
| 2967 | 23 |
| 1168 | 24 /** |
| 25 * @file golomb.h | |
| 2967 | 26 * @brief |
| 1168 | 27 * exp golomb vlc stuff |
| 2215 | 28 * @author Michael Niedermayer <michaelni@gmx.at> and Alex Beregszaszi |
| 1168 | 29 */ |
| 30 | |
| 1234 | 31 #define INVALID_VLC 0x80000000 |
| 32 | |
| 1168 | 33 extern const uint8_t ff_golomb_vlc_len[512]; |
| 34 extern const uint8_t ff_ue_golomb_vlc_code[512]; | |
| 35 extern const int8_t ff_se_golomb_vlc_code[512]; | |
| 36 extern const uint8_t ff_ue_golomb_len[256]; | |
| 37 | |
| 1250 | 38 extern const uint8_t ff_interleaved_golomb_vlc_len[256]; |
| 39 extern const uint8_t ff_interleaved_ue_golomb_vlc_code[256]; | |
| 40 extern const int8_t ff_interleaved_se_golomb_vlc_code[256]; | |
| 41 | |
| 2967 | 42 |
| 1168 | 43 /** |
| 44 * read unsigned exp golomb code. | |
| 45 */ | |
| 46 static inline int get_ue_golomb(GetBitContext *gb){ | |
| 47 unsigned int buf; | |
| 48 int log; | |
| 2967 | 49 |
| 1168 | 50 OPEN_READER(re, gb); |
| 51 UPDATE_CACHE(re, gb); | |
| 52 buf=GET_CACHE(re, gb); | |
| 2967 | 53 |
| 1168 | 54 if(buf >= (1<<27)){ |
| 55 buf >>= 32 - 9; | |
| 56 LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]); | |
| 57 CLOSE_READER(re, gb); | |
| 2967 | 58 |
| 1168 | 59 return ff_ue_golomb_vlc_code[buf]; |
| 60 }else{ | |
| 61 log= 2*av_log2(buf) - 31; | |
| 62 buf>>= log; | |
| 63 buf--; | |
| 64 LAST_SKIP_BITS(re, gb, 32 - log); | |
| 65 CLOSE_READER(re, gb); | |
| 2967 | 66 |
| 1168 | 67 return buf; |
| 68 } | |
| 69 } | |
| 70 | |
| 1234 | 71 static inline int svq3_get_ue_golomb(GetBitContext *gb){ |
| 1250 | 72 uint32_t buf; |
| 1234 | 73 int log; |
| 74 | |
| 75 OPEN_READER(re, gb); | |
| 76 UPDATE_CACHE(re, gb); | |
| 1250 | 77 buf=GET_CACHE(re, gb); |
| 2967 | 78 |
| 1250 | 79 if(buf&0xAA800000){ |
| 80 buf >>= 32 - 8; | |
| 81 LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]); | |
| 82 CLOSE_READER(re, gb); | |
| 2967 | 83 |
| 1250 | 84 return ff_interleaved_ue_golomb_vlc_code[buf]; |
| 85 }else{ | |
|
2087
a4d3699c6636
1000l to the ffsvq3 author, our default bitstream reader is only guranteed to be able to read 25bit at a time
michael
parents:
1812
diff
changeset
|
86 LAST_SKIP_BITS(re, gb, 8); |
|
a4d3699c6636
1000l to the ffsvq3 author, our default bitstream reader is only guranteed to be able to read 25bit at a time
michael
parents:
1812
diff
changeset
|
87 UPDATE_CACHE(re, gb); |
|
a4d3699c6636
1000l to the ffsvq3 author, our default bitstream reader is only guranteed to be able to read 25bit at a time
michael
parents:
1812
diff
changeset
|
88 buf |= 1 | (GET_CACHE(re, gb) >> 8); |
|
a4d3699c6636
1000l to the ffsvq3 author, our default bitstream reader is only guranteed to be able to read 25bit at a time
michael
parents:
1812
diff
changeset
|
89 |
| 1250 | 90 if((buf & 0xAAAAAAAA) == 0) |
| 91 return INVALID_VLC; | |
| 1234 | 92 |
| 1250 | 93 for(log=31; (buf & 0x80000000) == 0; log--){ |
| 94 buf = (buf << 2) - ((buf << log) >> (log - 1)) + (buf >> 30); | |
| 95 } | |
| 1234 | 96 |
|
2087
a4d3699c6636
1000l to the ffsvq3 author, our default bitstream reader is only guranteed to be able to read 25bit at a time
michael
parents:
1812
diff
changeset
|
97 LAST_SKIP_BITS(re, gb, 63 - 2*log - 8); |
| 1250 | 98 CLOSE_READER(re, gb); |
| 1234 | 99 |
| 1250 | 100 return ((buf << log) >> log) - 1; |
| 101 } | |
| 1234 | 102 } |
| 103 | |
| 1168 | 104 /** |
| 105 * read unsigned truncated exp golomb code. | |
| 106 */ | |
| 107 static inline int get_te0_golomb(GetBitContext *gb, int range){ | |
| 108 assert(range >= 1); | |
| 2967 | 109 |
| 1168 | 110 if(range==1) return 0; |
| 1169 | 111 else if(range==2) return get_bits1(gb)^1; |
| 1168 | 112 else return get_ue_golomb(gb); |
| 113 } | |
| 114 | |
| 115 /** | |
| 116 * read unsigned truncated exp golomb code. | |
| 117 */ | |
| 118 static inline int get_te_golomb(GetBitContext *gb, int range){ | |
| 119 assert(range >= 1); | |
| 2967 | 120 |
| 1169 | 121 if(range==2) return get_bits1(gb)^1; |
| 1168 | 122 else return get_ue_golomb(gb); |
| 123 } | |
| 124 | |
| 125 | |
| 126 /** | |
| 127 * read signed exp golomb code. | |
| 128 */ | |
| 129 static inline int get_se_golomb(GetBitContext *gb){ | |
| 130 unsigned int buf; | |
| 131 int log; | |
| 2967 | 132 |
| 1168 | 133 OPEN_READER(re, gb); |
| 134 UPDATE_CACHE(re, gb); | |
| 135 buf=GET_CACHE(re, gb); | |
| 2967 | 136 |
| 1168 | 137 if(buf >= (1<<27)){ |
| 138 buf >>= 32 - 9; | |
| 139 LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]); | |
| 140 CLOSE_READER(re, gb); | |
| 2967 | 141 |
| 1168 | 142 return ff_se_golomb_vlc_code[buf]; |
| 143 }else{ | |
| 144 log= 2*av_log2(buf) - 31; | |
| 145 buf>>= log; | |
| 2967 | 146 |
| 1168 | 147 LAST_SKIP_BITS(re, gb, 32 - log); |
| 148 CLOSE_READER(re, gb); | |
| 2967 | 149 |
| 1168 | 150 if(buf&1) buf= -(buf>>1); |
| 151 else buf= (buf>>1); | |
| 152 | |
| 153 return buf; | |
| 154 } | |
| 155 } | |
| 156 | |
| 1234 | 157 static inline int svq3_get_se_golomb(GetBitContext *gb){ |
| 158 unsigned int buf; | |
| 159 int log; | |
| 160 | |
| 161 OPEN_READER(re, gb); | |
| 162 UPDATE_CACHE(re, gb); | |
| 1250 | 163 buf=GET_CACHE(re, gb); |
| 1234 | 164 |
| 1250 | 165 if(buf&0xAA800000){ |
| 166 buf >>= 32 - 8; | |
| 167 LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]); | |
| 168 CLOSE_READER(re, gb); | |
| 2967 | 169 |
| 1250 | 170 return ff_interleaved_se_golomb_vlc_code[buf]; |
| 171 }else{ | |
| 2439 | 172 LAST_SKIP_BITS(re, gb, 8); |
| 173 UPDATE_CACHE(re, gb); | |
| 174 buf |= 1 | (GET_CACHE(re, gb) >> 8); | |
| 175 | |
| 1250 | 176 if((buf & 0xAAAAAAAA) == 0) |
| 177 return INVALID_VLC; | |
| 1234 | 178 |
| 1250 | 179 for(log=31; (buf & 0x80000000) == 0; log--){ |
| 180 buf = (buf << 2) - ((buf << log) >> (log - 1)) + (buf >> 30); | |
| 181 } | |
| 1234 | 182 |
| 2439 | 183 LAST_SKIP_BITS(re, gb, 63 - 2*log - 8); |
| 1250 | 184 CLOSE_READER(re, gb); |
| 185 | |
| 186 return (signed) (((((buf << log) >> log) - 1) ^ -(buf & 0x1)) + 1) >> 1; | |
| 187 } | |
| 1234 | 188 } |
| 189 | |
| 1306 | 190 /** |
|
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
191 * read unsigned golomb rice code (ffv1). |
| 1306 | 192 */ |
| 193 static inline int get_ur_golomb(GetBitContext *gb, int k, int limit, int esc_len){ | |
| 194 unsigned int buf; | |
| 195 int log; | |
| 2967 | 196 |
| 1306 | 197 OPEN_READER(re, gb); |
| 198 UPDATE_CACHE(re, gb); | |
| 199 buf=GET_CACHE(re, gb); | |
| 200 | |
| 201 log= av_log2(buf); | |
|
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
202 |
| 1306 | 203 if(log > 31-limit){ |
| 204 buf >>= log - k; | |
| 205 buf += (30-log)<<k; | |
| 206 LAST_SKIP_BITS(re, gb, 32 + k - log); | |
| 207 CLOSE_READER(re, gb); | |
| 2967 | 208 |
| 1306 | 209 return buf; |
|
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
210 }else{ |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
211 buf >>= 32 - limit - esc_len; |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
212 LAST_SKIP_BITS(re, gb, esc_len + limit); |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
213 CLOSE_READER(re, gb); |
| 2967 | 214 |
|
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
215 return buf + limit - 1; |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
216 } |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
217 } |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
218 |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
219 /** |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
220 * read unsigned golomb rice code (jpegls). |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
221 */ |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
222 static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit, int esc_len){ |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
223 unsigned int buf; |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
224 int log; |
| 2967 | 225 |
|
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
226 OPEN_READER(re, gb); |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
227 UPDATE_CACHE(re, gb); |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
228 buf=GET_CACHE(re, gb); |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
229 |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
230 log= av_log2(buf); |
| 2967 | 231 |
| 1362 | 232 if(log > 31-11){ |
|
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
233 buf >>= log - k; |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
234 buf += (30-log)<<k; |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
235 LAST_SKIP_BITS(re, gb, 32 + k - log); |
| 1306 | 236 CLOSE_READER(re, gb); |
| 2967 | 237 |
|
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
238 return buf; |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
239 }else{ |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
240 int i; |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
241 for(i=0; SHOW_UBITS(re, gb, 1) == 0; i++){ |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
242 LAST_SKIP_BITS(re, gb, 1); |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
243 UPDATE_CACHE(re, gb); |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
244 } |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
245 SKIP_BITS(re, gb, 1); |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
246 |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
247 if(i < limit - 1){ |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
248 if(k){ |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
249 buf = SHOW_UBITS(re, gb, k); |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
250 LAST_SKIP_BITS(re, gb, k); |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
251 }else{ |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
252 buf=0; |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
253 } |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
254 |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
255 CLOSE_READER(re, gb); |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
256 return buf + (i<<k); |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
257 }else if(i == limit - 1){ |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
258 buf = SHOW_UBITS(re, gb, esc_len); |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
259 LAST_SKIP_BITS(re, gb, esc_len); |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
260 CLOSE_READER(re, gb); |
| 2967 | 261 |
|
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
262 return buf + 1; |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
263 }else |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
264 return -1; |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
265 } |
| 1306 | 266 } |
| 267 | |
| 1812 | 268 /** |
| 2215 | 269 * read signed golomb rice code (ffv1). |
| 270 */ | |
| 2220 | 271 static inline int get_sr_golomb(GetBitContext *gb, int k, int limit, int esc_len){ |
| 2215 | 272 int v= get_ur_golomb(gb, k, limit, esc_len); |
| 2967 | 273 |
| 2215 | 274 v++; |
| 275 if (v&1) return v>>1; | |
| 276 else return -(v>>1); | |
| 2967 | 277 |
| 2215 | 278 // return (v>>1) ^ -(v&1); |
| 279 } | |
| 2220 | 280 |
| 2215 | 281 /** |
| 282 * read signed golomb rice code (flac). | |
| 1812 | 283 */ |
| 284 static inline int get_sr_golomb_flac(GetBitContext *gb, int k, int limit, int esc_len){ | |
| 285 int v= get_ur_golomb_jpegls(gb, k, limit, esc_len); | |
| 286 return (v>>1) ^ -(v&1); | |
| 287 } | |
| 288 | |
|
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
289 /** |
|
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
290 * read unsigned golomb rice code (shorten). |
|
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
291 */ |
|
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
292 static inline unsigned int get_ur_golomb_shorten(GetBitContext *gb, int k){ |
| 2979 | 293 return get_ur_golomb_jpegls(gb, k, INT_MAX, 0); |
|
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
294 } |
|
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
295 |
|
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
296 /** |
|
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
297 * read signed golomb rice code (shorten). |
|
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
298 */ |
|
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
299 static inline int get_sr_golomb_shorten(GetBitContext* gb, int k) |
|
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
300 { |
|
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
301 int uvar = get_ur_golomb_jpegls(gb, k + 1, INT_MAX, 0); |
|
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
302 if (uvar & 1) |
|
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
303 return ~(uvar >> 1); |
|
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
304 else |
|
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
305 return uvar >> 1; |
|
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
306 } |
|
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
307 |
|
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
308 |
|
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
309 |
| 1168 | 310 #ifdef TRACE |
| 311 | |
|
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2220
diff
changeset
|
312 static inline int get_ue(GetBitContext *s, char *file, const char *func, int line){ |
| 1168 | 313 int show= show_bits(s, 24); |
| 314 int pos= get_bits_count(s); | |
| 315 int i= get_ue_golomb(s); | |
| 316 int len= get_bits_count(s) - pos; | |
| 317 int bits= show>>(24-len); | |
| 2967 | 318 |
| 1168 | 319 print_bin(bits, len); |
| 2967 | 320 |
| 2215 | 321 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d ue @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); |
| 2967 | 322 |
| 1168 | 323 return i; |
| 324 } | |
| 325 | |
|
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2220
diff
changeset
|
326 static inline int get_se(GetBitContext *s, char *file, const char *func, int line){ |
| 1168 | 327 int show= show_bits(s, 24); |
| 328 int pos= get_bits_count(s); | |
| 329 int i= get_se_golomb(s); | |
| 330 int len= get_bits_count(s) - pos; | |
| 331 int bits= show>>(24-len); | |
| 2967 | 332 |
| 1168 | 333 print_bin(bits, len); |
| 2967 | 334 |
| 2215 | 335 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d se @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); |
| 2967 | 336 |
| 1168 | 337 return i; |
| 338 } | |
| 339 | |
|
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2220
diff
changeset
|
340 static inline int get_te(GetBitContext *s, int r, char *file, const char *func, int line){ |
| 1168 | 341 int show= show_bits(s, 24); |
| 342 int pos= get_bits_count(s); | |
| 343 int i= get_te0_golomb(s, r); | |
| 344 int len= get_bits_count(s) - pos; | |
| 345 int bits= show>>(24-len); | |
| 2967 | 346 |
| 1168 | 347 print_bin(bits, len); |
| 2967 | 348 |
| 2215 | 349 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d te @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); |
| 2967 | 350 |
| 1168 | 351 return i; |
| 352 } | |
| 353 | |
| 354 #define get_ue_golomb(a) get_ue(a, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
| 355 #define get_se_golomb(a) get_se(a, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
| 356 #define get_te_golomb(a, r) get_te(a, r, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
| 357 #define get_te0_golomb(a, r) get_te(a, r, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
| 358 | |
| 359 #endif | |
| 360 | |
| 361 /** | |
| 362 * write unsigned exp golomb code. | |
| 363 */ | |
| 364 static inline void set_ue_golomb(PutBitContext *pb, int i){ | |
| 365 int e; | |
| 2967 | 366 |
| 1168 | 367 assert(i>=0); |
| 368 | |
| 369 #if 0 | |
| 370 if(i=0){ | |
| 371 put_bits(pb, 1, 1); | |
| 372 return; | |
| 373 } | |
| 374 #endif | |
| 375 if(i<256) | |
| 376 put_bits(pb, ff_ue_golomb_len[i], i+1); | |
| 377 else{ | |
| 378 e= av_log2(i+1); | |
| 2967 | 379 |
| 1168 | 380 put_bits(pb, 2*e+1, i+1); |
| 381 } | |
| 382 } | |
| 383 | |
| 384 /** | |
| 385 * write truncated unsigned exp golomb code. | |
| 386 */ | |
| 387 static inline void set_te_golomb(PutBitContext *pb, int i, int range){ | |
| 388 assert(range >= 1); | |
| 389 assert(i<=range); | |
| 390 | |
| 1169 | 391 if(range==2) put_bits(pb, 1, i^1); |
| 1168 | 392 else set_ue_golomb(pb, i); |
| 393 } | |
| 394 | |
| 395 /** | |
|
2905
926ea374947f
set_se_golomb can only write 16bits, add a note about this (ok, maybe it's brain dead using it with more than 16bits, but..)
alex
parents:
2525
diff
changeset
|
396 * write signed exp golomb code. 16 bits at most. |
| 1168 | 397 */ |
| 398 static inline void set_se_golomb(PutBitContext *pb, int i){ | |
|
2905
926ea374947f
set_se_golomb can only write 16bits, add a note about this (ok, maybe it's brain dead using it with more than 16bits, but..)
alex
parents:
2525
diff
changeset
|
399 // if (i>32767 || i<-32767) |
| 2979 | 400 // av_log(NULL,AV_LOG_ERROR,"value out of range %d\n", i); |
| 2967 | 401 #if 0 |
| 1168 | 402 if(i<=0) i= -2*i; |
| 403 else i= 2*i-1; | |
| 404 #elif 1 | |
| 405 i= 2*i-1; | |
| 406 if(i<0) i^= -1; //FIXME check if gcc does the right thing | |
| 407 #else | |
| 408 i= 2*i-1; | |
| 409 i^= (i>>31); | |
| 410 #endif | |
| 411 set_ue_golomb(pb, i); | |
| 412 } | |
| 1306 | 413 |
| 414 /** | |
|
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
415 * write unsigned golomb rice code (ffv1). |
| 1306 | 416 */ |
| 417 static inline void set_ur_golomb(PutBitContext *pb, int i, int k, int limit, int esc_len){ | |
| 418 int e; | |
| 2967 | 419 |
| 1306 | 420 assert(i>=0); |
| 2967 | 421 |
| 1306 | 422 e= i>>k; |
| 423 if(e<limit){ | |
| 424 put_bits(pb, e + k + 1, (1<<k) + (i&((1<<k)-1))); | |
| 425 }else{ | |
|
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
426 put_bits(pb, limit + esc_len, i - limit + 1); |
| 1306 | 427 } |
| 428 } | |
|
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
429 |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
430 /** |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
431 * write unsigned golomb rice code (jpegls). |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
432 */ |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
433 static inline void set_ur_golomb_jpegls(PutBitContext *pb, int i, int k, int limit, int esc_len){ |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
434 int e; |
| 2967 | 435 |
|
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
436 assert(i>=0); |
| 2967 | 437 |
|
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
438 e= (i>>k) + 1; |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
439 if(e<limit){ |
|
3353
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
3036
diff
changeset
|
440 while(e > 31) { |
|
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
3036
diff
changeset
|
441 put_bits(pb, 31, 0); |
|
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
3036
diff
changeset
|
442 e -= 31; |
|
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
3036
diff
changeset
|
443 } |
|
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
444 put_bits(pb, e, 1); |
| 1362 | 445 if(k) |
| 446 put_bits(pb, k, i&((1<<k)-1)); | |
|
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
447 }else{ |
| 4053 | 448 while(limit > 31) { |
| 449 put_bits(pb, 31, 0); | |
| 450 limit -= 31; | |
| 451 } | |
|
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
452 put_bits(pb, limit , 1); |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
453 put_bits(pb, esc_len, i - 1); |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
454 } |
|
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
455 } |
| 2215 | 456 |
| 457 /** | |
| 458 * write signed golomb rice code (ffv1). | |
| 459 */ | |
| 2220 | 460 static inline void set_sr_golomb(PutBitContext *pb, int i, int k, int limit, int esc_len){ |
| 2215 | 461 int v; |
| 462 | |
| 463 v = -2*i-1; | |
| 464 v ^= (v>>31); | |
| 465 | |
| 466 set_ur_golomb(pb, v, k, limit, esc_len); | |
| 467 } | |
| 468 | |
| 469 /** | |
| 470 * write signed golomb rice code (flac). | |
| 471 */ | |
| 472 static inline void set_sr_golomb_flac(PutBitContext *pb, int i, int k, int limit, int esc_len){ | |
| 473 int v; | |
| 474 | |
| 475 v = -2*i-1; | |
| 476 v ^= (v>>31); | |
| 477 | |
| 478 set_ur_golomb_jpegls(pb, v, k, limit, esc_len); | |
| 479 } |
