annotate golomb.h @ 1936:e5b0b33cf8aa libavcodec

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