Mercurial > libavcodec.hg
annotate golomb.h @ 2214:de5ed621effc libavcodec
try to select w/h from tables
author | alex |
---|---|
date | Wed, 08 Sep 2004 17:57:25 +0000 |
parents | a4d3699c6636 |
children | 2a767157935e |
rev | line source |
---|---|
1168 | 1 /* |
2 * exp golomb vlc stuff | |
3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> | |
4 * | |
5 * This library is free software; you can redistribute it and/or | |
6 * modify it under the terms of the GNU Lesser General Public | |
7 * License as published by the Free Software Foundation; either | |
8 * version 2 of the License, or (at your option) any later version. | |
9 * | |
10 * This library is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Lesser General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Lesser General Public | |
16 * License along with this library; if not, write to the Free Software | |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 * | |
19 */ | |
20 | |
21 /** | |
22 * @file golomb.h | |
23 * @brief | |
24 * exp golomb vlc stuff | |
25 * @author Michael Niedermayer <michaelni@gmx.at> | |
26 */ | |
27 | |
1234 | 28 #define INVALID_VLC 0x80000000 |
29 | |
1168 | 30 extern const uint8_t ff_golomb_vlc_len[512]; |
31 extern const uint8_t ff_ue_golomb_vlc_code[512]; | |
32 extern const int8_t ff_se_golomb_vlc_code[512]; | |
33 extern const uint8_t ff_ue_golomb_len[256]; | |
34 | |
1250 | 35 extern const uint8_t ff_interleaved_golomb_vlc_len[256]; |
36 extern const uint8_t ff_interleaved_ue_golomb_vlc_code[256]; | |
37 extern const int8_t ff_interleaved_se_golomb_vlc_code[256]; | |
38 | |
1168 | 39 |
40 /** | |
41 * read unsigned exp golomb code. | |
42 */ | |
43 static inline int get_ue_golomb(GetBitContext *gb){ | |
44 unsigned int buf; | |
45 int log; | |
46 | |
47 OPEN_READER(re, gb); | |
48 UPDATE_CACHE(re, gb); | |
49 buf=GET_CACHE(re, gb); | |
50 | |
51 if(buf >= (1<<27)){ | |
52 buf >>= 32 - 9; | |
53 LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]); | |
54 CLOSE_READER(re, gb); | |
55 | |
56 return ff_ue_golomb_vlc_code[buf]; | |
57 }else{ | |
58 log= 2*av_log2(buf) - 31; | |
59 buf>>= log; | |
60 buf--; | |
61 LAST_SKIP_BITS(re, gb, 32 - log); | |
62 CLOSE_READER(re, gb); | |
63 | |
64 return buf; | |
65 } | |
66 } | |
67 | |
1234 | 68 static inline int svq3_get_ue_golomb(GetBitContext *gb){ |
1250 | 69 uint32_t buf; |
1234 | 70 int log; |
71 | |
72 OPEN_READER(re, gb); | |
73 UPDATE_CACHE(re, gb); | |
1250 | 74 buf=GET_CACHE(re, gb); |
75 | |
76 if(buf&0xAA800000){ | |
77 buf >>= 32 - 8; | |
78 LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]); | |
79 CLOSE_READER(re, gb); | |
80 | |
81 return ff_interleaved_ue_golomb_vlc_code[buf]; | |
82 }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
|
83 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
|
84 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
|
85 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
|
86 |
1250 | 87 if((buf & 0xAAAAAAAA) == 0) |
88 return INVALID_VLC; | |
1234 | 89 |
1250 | 90 for(log=31; (buf & 0x80000000) == 0; log--){ |
91 buf = (buf << 2) - ((buf << log) >> (log - 1)) + (buf >> 30); | |
92 } | |
1234 | 93 |
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
|
94 LAST_SKIP_BITS(re, gb, 63 - 2*log - 8); |
1250 | 95 CLOSE_READER(re, gb); |
1234 | 96 |
1250 | 97 return ((buf << log) >> log) - 1; |
98 } | |
1234 | 99 } |
100 | |
1168 | 101 /** |
102 * read unsigned truncated exp golomb code. | |
103 */ | |
104 static inline int get_te0_golomb(GetBitContext *gb, int range){ | |
105 assert(range >= 1); | |
106 | |
107 if(range==1) return 0; | |
1169 | 108 else if(range==2) return get_bits1(gb)^1; |
1168 | 109 else return get_ue_golomb(gb); |
110 } | |
111 | |
112 /** | |
113 * read unsigned truncated exp golomb code. | |
114 */ | |
115 static inline int get_te_golomb(GetBitContext *gb, int range){ | |
116 assert(range >= 1); | |
117 | |
1169 | 118 if(range==2) return get_bits1(gb)^1; |
1168 | 119 else return get_ue_golomb(gb); |
120 } | |
121 | |
122 | |
123 /** | |
124 * read signed exp golomb code. | |
125 */ | |
126 static inline int get_se_golomb(GetBitContext *gb){ | |
127 unsigned int buf; | |
128 int log; | |
129 | |
130 OPEN_READER(re, gb); | |
131 UPDATE_CACHE(re, gb); | |
132 buf=GET_CACHE(re, gb); | |
133 | |
134 if(buf >= (1<<27)){ | |
135 buf >>= 32 - 9; | |
136 LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]); | |
137 CLOSE_READER(re, gb); | |
138 | |
139 return ff_se_golomb_vlc_code[buf]; | |
140 }else{ | |
141 log= 2*av_log2(buf) - 31; | |
142 buf>>= log; | |
143 | |
144 LAST_SKIP_BITS(re, gb, 32 - log); | |
145 CLOSE_READER(re, gb); | |
146 | |
147 if(buf&1) buf= -(buf>>1); | |
148 else buf= (buf>>1); | |
149 | |
150 return buf; | |
151 } | |
152 } | |
153 | |
1234 | 154 static inline int svq3_get_se_golomb(GetBitContext *gb){ |
155 unsigned int buf; | |
156 int log; | |
157 | |
158 OPEN_READER(re, gb); | |
159 UPDATE_CACHE(re, gb); | |
1250 | 160 buf=GET_CACHE(re, gb); |
1234 | 161 |
1250 | 162 if(buf&0xAA800000){ |
163 buf >>= 32 - 8; | |
164 LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]); | |
165 CLOSE_READER(re, gb); | |
166 | |
167 return ff_interleaved_se_golomb_vlc_code[buf]; | |
168 }else{ | |
169 buf |=1; | |
170 if((buf & 0xAAAAAAAA) == 0) | |
171 return INVALID_VLC; | |
1234 | 172 |
1250 | 173 for(log=31; (buf & 0x80000000) == 0; log--){ |
174 buf = (buf << 2) - ((buf << log) >> (log - 1)) + (buf >> 30); | |
175 } | |
1234 | 176 |
1250 | 177 LAST_SKIP_BITS(re, gb, 63 - 2*log); |
178 CLOSE_READER(re, gb); | |
179 | |
180 return (signed) (((((buf << log) >> log) - 1) ^ -(buf & 0x1)) + 1) >> 1; | |
181 } | |
1234 | 182 } |
183 | |
1306 | 184 /** |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
185 * read unsigned golomb rice code (ffv1). |
1306 | 186 */ |
187 static inline int get_ur_golomb(GetBitContext *gb, int k, int limit, int esc_len){ | |
188 unsigned int buf; | |
189 int log; | |
190 | |
191 OPEN_READER(re, gb); | |
192 UPDATE_CACHE(re, gb); | |
193 buf=GET_CACHE(re, gb); | |
194 | |
195 log= av_log2(buf); | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
196 |
1306 | 197 if(log > 31-limit){ |
198 buf >>= log - k; | |
199 buf += (30-log)<<k; | |
200 LAST_SKIP_BITS(re, gb, 32 + k - log); | |
201 CLOSE_READER(re, gb); | |
202 | |
203 return buf; | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
204 }else{ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
205 buf >>= 32 - limit - esc_len; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
206 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
|
207 CLOSE_READER(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
208 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
209 return buf + limit - 1; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
210 } |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
211 } |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
212 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
213 /** |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
214 * read unsigned golomb rice code (jpegls). |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
215 */ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
216 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
|
217 unsigned int buf; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
218 int log; |
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 OPEN_READER(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
221 UPDATE_CACHE(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
222 buf=GET_CACHE(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
223 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
224 log= av_log2(buf); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
225 |
1362 | 226 if(log > 31-11){ |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
227 buf >>= log - k; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
228 buf += (30-log)<<k; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
229 LAST_SKIP_BITS(re, gb, 32 + k - log); |
1306 | 230 CLOSE_READER(re, gb); |
231 | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
232 return buf; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
233 }else{ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
234 int i; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
235 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
|
236 LAST_SKIP_BITS(re, gb, 1); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
237 UPDATE_CACHE(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
238 } |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
239 SKIP_BITS(re, gb, 1); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
240 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
241 if(i < limit - 1){ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
242 if(k){ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
243 buf = SHOW_UBITS(re, gb, k); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
244 LAST_SKIP_BITS(re, gb, k); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
245 }else{ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
246 buf=0; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
247 } |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
248 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
249 CLOSE_READER(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
250 return buf + (i<<k); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
251 }else if(i == limit - 1){ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
252 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
|
253 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
|
254 CLOSE_READER(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
255 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
256 return buf + 1; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
257 }else |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
258 return -1; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
259 } |
1306 | 260 } |
261 | |
1812 | 262 /** |
263 * read unsigned golomb rice code (flac). | |
264 */ | |
265 static inline int get_sr_golomb_flac(GetBitContext *gb, int k, int limit, int esc_len){ | |
266 int v= get_ur_golomb_jpegls(gb, k, limit, esc_len); | |
267 return (v>>1) ^ -(v&1); | |
268 } | |
269 | |
1168 | 270 #ifdef TRACE |
271 | |
272 static inline int get_ue(GetBitContext *s, char *file, char *func, int line){ | |
273 int show= show_bits(s, 24); | |
274 int pos= get_bits_count(s); | |
275 int i= get_ue_golomb(s); | |
276 int len= get_bits_count(s) - pos; | |
277 int bits= show>>(24-len); | |
278 | |
279 print_bin(bits, len); | |
280 | |
281 printf("%5d %2d %3d ue @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); | |
282 | |
283 return i; | |
284 } | |
285 | |
286 static inline int get_se(GetBitContext *s, char *file, char *func, int line){ | |
287 int show= show_bits(s, 24); | |
288 int pos= get_bits_count(s); | |
289 int i= get_se_golomb(s); | |
290 int len= get_bits_count(s) - pos; | |
291 int bits= show>>(24-len); | |
292 | |
293 print_bin(bits, len); | |
294 | |
295 printf("%5d %2d %3d se @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); | |
296 | |
297 return i; | |
298 } | |
299 | |
300 static inline int get_te(GetBitContext *s, int r, char *file, char *func, int line){ | |
301 int show= show_bits(s, 24); | |
302 int pos= get_bits_count(s); | |
303 int i= get_te0_golomb(s, r); | |
304 int len= get_bits_count(s) - pos; | |
305 int bits= show>>(24-len); | |
306 | |
307 print_bin(bits, len); | |
308 | |
309 printf("%5d %2d %3d te @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); | |
310 | |
311 return i; | |
312 } | |
313 | |
314 #define get_ue_golomb(a) get_ue(a, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
315 #define get_se_golomb(a) get_se(a, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
316 #define get_te_golomb(a, r) get_te(a, r, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
317 #define get_te0_golomb(a, r) get_te(a, r, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
318 | |
319 #endif | |
320 | |
321 /** | |
322 * write unsigned exp golomb code. | |
323 */ | |
324 static inline void set_ue_golomb(PutBitContext *pb, int i){ | |
325 int e; | |
326 | |
327 assert(i>=0); | |
328 | |
329 #if 0 | |
330 if(i=0){ | |
331 put_bits(pb, 1, 1); | |
332 return; | |
333 } | |
334 #endif | |
335 if(i<256) | |
336 put_bits(pb, ff_ue_golomb_len[i], i+1); | |
337 else{ | |
338 e= av_log2(i+1); | |
339 | |
340 put_bits(pb, 2*e+1, i+1); | |
341 } | |
342 } | |
343 | |
344 /** | |
345 * write truncated unsigned exp golomb code. | |
346 */ | |
347 static inline void set_te_golomb(PutBitContext *pb, int i, int range){ | |
348 assert(range >= 1); | |
349 assert(i<=range); | |
350 | |
1169 | 351 if(range==2) put_bits(pb, 1, i^1); |
1168 | 352 else set_ue_golomb(pb, i); |
353 } | |
354 | |
355 /** | |
356 * write signed exp golomb code. | |
357 */ | |
358 static inline void set_se_golomb(PutBitContext *pb, int i){ | |
359 #if 0 | |
360 if(i<=0) i= -2*i; | |
361 else i= 2*i-1; | |
362 #elif 1 | |
363 i= 2*i-1; | |
364 if(i<0) i^= -1; //FIXME check if gcc does the right thing | |
365 #else | |
366 i= 2*i-1; | |
367 i^= (i>>31); | |
368 #endif | |
369 set_ue_golomb(pb, i); | |
370 } | |
1306 | 371 |
372 /** | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
373 * write unsigned golomb rice code (ffv1). |
1306 | 374 */ |
375 static inline void set_ur_golomb(PutBitContext *pb, int i, int k, int limit, int esc_len){ | |
376 int e; | |
377 | |
378 assert(i>=0); | |
379 | |
380 e= i>>k; | |
381 if(e<limit){ | |
382 put_bits(pb, e + k + 1, (1<<k) + (i&((1<<k)-1))); | |
383 }else{ | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
384 put_bits(pb, limit + esc_len, i - limit + 1); |
1306 | 385 } |
386 } | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
387 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
388 /** |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
389 * write unsigned golomb rice code (jpegls). |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
390 */ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
391 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
|
392 int e; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
393 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
394 assert(i>=0); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
395 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
396 e= (i>>k) + 1; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
397 if(e<limit){ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
398 put_bits(pb, e, 1); |
1362 | 399 if(k) |
400 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
|
401 }else{ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
402 put_bits(pb, limit , 1); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
403 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
|
404 } |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
405 } |