2 * Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "rangecoder.h"
26 #include "mpegvideo.h"
31 static const int8_t quant3
[256]={
32 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
33 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
34 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
35 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
36 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
37 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
38 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
39 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
40 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
41 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
42 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
43 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
44 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
45 -1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, 1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0,
181 0, 0, 1, 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 7, 8, 8, 8, 8, 7, 7, 6, 6, 5, 4, 4, 3, 2, 2, 1, 1, 0, 0,
182 0, 0, 1, 2, 2, 3, 4, 6, 7, 8, 9,10,11,12,12,12,12,12,12,11,10, 9, 8, 7, 6, 4, 3, 2, 2, 1, 0, 0,
183 0, 1, 1, 2, 3, 5, 6, 8,10,11,13,14,15,16,17,18,18,17,16,15,14,13,11,10, 8, 6, 5, 3, 2, 1, 1, 0,
184 0, 1, 1, 3, 4, 6, 8,10,13,15,17,19,20,22,22,23,23,22,22,20,19,17,15,13,10, 8, 6, 4, 3, 1, 1, 0,
185 0, 1, 2, 4, 6, 8,10,13,16,19,21,23,25,27,28,29,29,28,27,25,23,21,19,16,13,10, 8, 6, 4, 2, 1, 0,
186 0, 1, 2, 4, 7,10,13,16,19,22,25,28,31,33,34,35,35,34,33,31,28,25,22,19,16,13,10, 7, 4, 2, 1, 0,
187 0, 1, 3, 5, 8,11,15,19,22,26,30,33,36,38,40,41,41,40,38,36,33,30,26,22,19,15,11, 8, 5, 3, 1, 0,
188 0, 1, 3, 6, 9,12,17,21,25,30,34,38,41,44,45,46,46,45,44,41,38,34,30,25,21,17,12, 9, 6, 3, 1, 0,
189 0, 1, 3, 6,10,14,19,23,28,33,38,42,45,48,51,52,52,51,48,45,42,38,33,28,23,19,14,10, 6, 3, 1, 0,
190 0, 1, 4, 7,11,15,20,25,31,36,41,45,49,52,55,56,56,55,52,49,45,41,36,31,25,20,15,11, 7, 4, 1, 0,
191 0, 2, 4, 7,12,16,22,27,33,38,44,48,52,56,58,60,60,58,56,52,48,44,38,33,27,22,16,12, 7, 4, 2, 0,
192 0, 1, 4, 8,12,17,22,28,34,40,45,51,55,58,61,62,62,61,58,55,51,45,40,34,28,22,17,12, 8, 4, 1, 0,
193 0, 2, 4, 8,12,18,23,29,35,41,46,52,56,60,62,64,64,62,60,56,52,46,41,35,29,23,18,12, 8, 4, 2, 0,
194 0, 2, 4, 8,12,18,23,29,35,41,46,52,56,60,62,64,64,62,60,56,52,46,41,35,29,23,18,12, 8, 4, 2, 0,
195 0, 1, 4, 8,12,17,22,28,34,40,45,51,55,58,61,62,62,61,58,55,51,45,40,34,28,22,17,12, 8, 4, 1, 0,
196 0, 2, 4, 7,12,16,22,27,33,38,44,48,52,56,58,60,60,58,56,52,48,44,38,33,27,22,16,12, 7, 4, 2, 0,
197 0, 1, 4, 7,11,15,20,25,31,36,41,45,49,52,55,56,56,55,52,49,45,41,36,31,25,20,15,11, 7, 4, 1, 0,
198 0, 1, 3, 6,10,14,19,23,28,33,38,42,45,48,51,52,52,51,48,45,42,38,33,28,23,19,14,10, 6, 3, 1, 0,
199 0, 1, 3, 6, 9,12,17,21,25,30,34,38,41,44,45,46,46,45,44,41,38,34,30,25,21,17,12, 9, 6, 3, 1, 0,
200 0, 1, 3, 5, 8,11,15,19,22,26,30,33,36,38,40,41,41,40,38,36,33,30,26,22,19,15,11, 8, 5, 3, 1, 0,
201 0, 1, 2, 4, 7,10,13,16,19,22,25,28,31,33,34,35,35,34,33,31,28,25,22,19,16,13,10, 7, 4, 2, 1, 0,
202 0, 1, 2, 4, 6, 8,10,13,16,19,21,23,25,27,28,29,29,28,27,25,23,21,19,16,13,10, 8, 6, 4, 2, 1, 0,
203 0, 1, 1, 3, 4, 6, 8,10,13,15,17,19,20,22,22,23,23,22,22,20,19,17,15,13,10, 8, 6, 4, 3, 1, 1, 0,
204 0, 1, 1, 2, 3, 5, 6, 8,10,11,13,14,15,16,17,18,18,17,16,15,14,13,11,10, 8, 6, 5, 3, 2, 1, 1, 0,
205 0, 0, 1, 2, 2, 3, 4, 6, 7, 8, 9,10,11,12,12,12,12,12,12,11,10, 9, 8, 7, 6, 4, 3, 2, 2, 1, 0, 0,
206 0, 0, 1, 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 7, 8, 8, 8, 8, 7, 7, 6, 6, 5, 4, 4, 3, 2, 2, 1, 1, 0, 0,
207 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0,
208 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
209 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
212 static const uint8_t obmc16
[256]={
213 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
214 0, 1, 1, 2, 4, 5, 5, 6, 6, 5, 5, 4, 2, 1, 1, 0,
215 0, 1, 4, 6, 9,11,13,15,15,13,11, 9, 6, 4, 1, 0,
216 0, 2, 6,11,15,20,24,26,26,24,20,15,11, 6, 2, 0,
217 0, 4, 9,15,23,29,34,38,38,34,29,23,15, 9, 4, 0,
218 0, 5,11,20,29,38,45,49,49,45,38,29,20,11, 5, 0,
219 1, 5,13,24,34,45,53,57,57,53,45,34,24,13, 5, 1,
220 1, 6,15,26,38,49,57,62,62,57,49,38,26,15, 6, 1,
221 1, 6,15,26,38,49,57,62,62,57,49,38,26,15, 6, 1,
222 1, 5,13,24,34,45,53,57,57,53,45,34,24,13, 5, 1,
223 0, 5,11,20,29,38,45,49,49,45,38,29,20,11, 5, 0,
224 0, 4, 9,15,23,29,34,38,38,34,29,23,15, 9, 4, 0,
225 0, 2, 6,11,15,20,24,26,26,24,20,15,11, 6, 2, 0,
226 0, 1, 4, 6, 9,11,13,15,15,13,11, 9, 6, 4, 1, 0,
227 0, 1, 1, 2, 4, 5, 5, 6, 6, 5, 5, 4, 2, 1, 1, 0,
228 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
232 static const uint8_t obmc32
[1024]={
233 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0,
234 0, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 16, 20, 20, 20, 24, 24, 20, 20, 20, 16, 16, 16, 12, 12, 8, 8, 8, 4, 4, 4, 0,
235 0, 4, 8, 8, 12, 12, 16, 20, 20, 24, 28, 28, 32, 32, 36, 40, 40, 36, 32, 32, 28, 28, 24, 20, 20, 16, 12, 12, 8, 8, 4, 0,
236 0, 4, 8, 12, 16, 20, 24, 28, 28, 32, 36, 40, 44, 48, 52, 56, 56, 52, 48, 44, 40, 36, 32, 28, 28, 24, 20, 16, 12, 8, 4, 0,
237 4, 8, 12, 16, 20, 24, 28, 32, 40, 44, 48, 52, 56, 60, 64, 68, 68, 64, 60, 56, 52, 48, 44, 40, 32, 28, 24, 20, 16, 12, 8, 4,
238 4, 8, 12, 20, 24, 32, 36, 40, 48, 52, 56, 64, 68, 76, 80, 84, 84, 80, 76, 68, 64, 56, 52, 48, 40, 36, 32, 24, 20, 12, 8, 4,
239 4, 8, 16, 24, 28, 36, 44, 48, 56, 60, 68, 76, 80, 88, 96,100,100, 96, 88, 80, 76, 68, 60, 56, 48, 44, 36, 28, 24, 16, 8, 4,
240 4, 12, 20, 28, 32, 40, 48, 56, 64, 72, 80, 88, 92,100,108,116,116,108,100, 92, 88, 80, 72, 64, 56, 48, 40, 32, 28, 20, 12, 4,
241 4, 12, 20, 28, 40, 48, 56, 64, 72, 80, 88, 96,108,116,124,132,132,124,116,108, 96, 88, 80, 72, 64, 56, 48, 40, 28, 20, 12, 4,
242 4, 16, 24, 32, 44, 52, 60, 72, 80, 92,100,108,120,128,136,148,148,136,128,120,108,100, 92, 80, 72, 60, 52, 44, 32, 24, 16, 4,
243 4, 16, 28, 36, 48, 56, 68, 80, 88,100,112,120,132,140,152,164,164,152,140,132,120,112,100, 88, 80, 68, 56, 48, 36, 28, 16, 4,
244 4, 16, 28, 40, 52, 64, 76, 88, 96,108,120,132,144,156,168,180,180,168,156,144,132,120,108, 96, 88, 76, 64, 52, 40, 28, 16, 4,
245 8, 20, 32, 44, 56, 68, 80, 92,108,120,132,144,156,168,180,192,192,180,168,156,144,132,120,108, 92, 80, 68, 56, 44, 32, 20, 8,
246 8, 20, 32, 48, 60, 76, 88,100,116,128,140,156,168,184,196,208,208,196,184,168,156,140,128,116,100, 88, 76, 60, 48, 32, 20, 8,
247 8, 20, 36, 52, 64, 80, 96,108,124,136,152,168,180,196,212,224,224,212,196,180,168,152,136,124,108, 96, 80, 64, 52, 36, 20, 8,
248 8, 24, 40, 56, 68, 84,100,116,132,148,164,180,192,208,224,240,240,224,208,192,180,164,148,132,116,100, 84, 68, 56, 40, 24, 8,
249 8, 24, 40, 56, 68, 84,100,116,132,148,164,180,192,208,224,240,240,224,208,192,180,164,148,132,116,100, 84, 68, 56, 40, 24, 8,
250 8, 20, 36, 52, 64, 80, 96,108,124,136,152,168,180,196,212,224,224,212,196,180,168,152,136,124,108, 96, 80, 64, 52, 36, 20, 8,
251 8, 20, 32, 48, 60, 76, 88,100,116,128,140,156,168,184,196,208,208,196,184,168,156,140,128,116,100, 88, 76, 60, 48, 32, 20, 8,
252 8, 20, 32, 44, 56, 68, 80, 92,108,120,132,144,156,168,180,192,192,180,168,156,144,132,120,108, 92, 80, 68, 56, 44, 32, 20, 8,
253 4, 16, 28, 40, 52, 64, 76, 88, 96,108,120,132,144,156,168,180,180,168,156,144,132,120,108, 96, 88, 76, 64, 52, 40, 28, 16, 4,
254 4, 16, 28, 36, 48, 56, 68, 80, 88,100,112,120,132,140,152,164,164,152,140,132,120,112,100, 88, 80, 68, 56, 48, 36, 28, 16, 4,
255 4, 16, 24, 32, 44, 52, 60, 72, 80, 92,100,108,120,128,136,148,148,136,128,120,108,100, 92, 80, 72, 60, 52, 44, 32, 24, 16, 4,
256 4, 12, 20, 28, 40, 48, 56, 64, 72, 80, 88, 96,108,116,124,132,132,124,116,108, 96, 88, 80, 72, 64, 56, 48, 40, 28, 20, 12, 4,
257 4, 12, 20, 28, 32, 40, 48, 56, 64, 72, 80, 88, 92,100,108,116,116,108,100, 92, 88, 80, 72, 64, 56, 48, 40, 32, 28, 20, 12, 4,
258 4, 8, 16, 24, 28, 36, 44, 48, 56, 60, 68, 76, 80, 88, 96,100,100, 96, 88, 80, 76, 68, 60, 56, 48, 44, 36, 28, 24, 16, 8, 4,
259 4, 8, 12, 20, 24, 32, 36, 40, 48, 52, 56, 64, 68, 76, 80, 84, 84, 80, 76, 68, 64, 56, 52, 48, 40, 36, 32, 24, 20, 12, 8, 4,
260 4, 8, 12, 16, 20, 24, 28, 32, 40, 44, 48, 52, 56, 60, 64, 68, 68, 64, 60, 56, 52, 48, 44, 40, 32, 28, 24, 20, 16, 12, 8, 4,
261 0, 4, 8, 12, 16, 20, 24, 28, 28, 32, 36, 40, 44, 48, 52, 56, 56, 52, 48, 44, 40, 36, 32, 28, 28, 24, 20, 16, 12, 8, 4, 0,
262 0, 4, 8, 8, 12, 12, 16, 20, 20, 24, 28, 28, 32, 32, 36, 40, 40, 36, 32, 32, 28, 28, 24, 20, 20, 16, 12, 12, 8, 8, 4, 0,
263 0, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 16, 20, 20, 20, 24, 24, 20, 20, 20, 16, 16, 16, 12, 12, 8, 8, 8, 4, 4, 4, 0,
264 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0,
267 static const uint8_t obmc16
[256]={
268 0, 4, 4, 8, 8, 12, 12, 16, 16, 12, 12, 8, 8, 4, 4, 0,
269 4, 8, 16, 20, 28, 32, 40, 44, 44, 40, 32, 28, 20, 16, 8, 4,
270 4, 16, 24, 36, 44, 56, 64, 76, 76, 64, 56, 44, 36, 24, 16, 4,
271 8, 20, 36, 48, 64, 76, 92,104,104, 92, 76, 64, 48, 36, 20, 8,
272 8, 28, 44, 64, 80,100,116,136,136,116,100, 80, 64, 44, 28, 8,
273 12, 32, 56, 76,100,120,144,164,164,144,120,100, 76, 56, 32, 12,
274 12, 40, 64, 92,116,144,168,196,196,168,144,116, 92, 64, 40, 12,
275 16, 44, 76,104,136,164,196,224,224,196,164,136,104, 76, 44, 16,
276 16, 44, 76,104,136,164,196,224,224,196,164,136,104, 76, 44, 16,
277 12, 40, 64, 92,116,144,168,196,196,168,144,116, 92, 64, 40, 12,
278 12, 32, 56, 76,100,120,144,164,164,144,120,100, 76, 56, 32, 12,
279 8, 28, 44, 64, 80,100,116,136,136,116,100, 80, 64, 44, 28, 8,
280 8, 20, 36, 48, 64, 76, 92,104,104, 92, 76, 64, 48, 36, 20, 8,
281 4, 16, 24, 36, 44, 56, 64, 76, 76, 64, 56, 44, 36, 24, 16, 4,
282 4, 8, 16, 20, 28, 32, 40, 44, 44, 40, 32, 28, 20, 16, 8, 4,
283 0, 4, 4, 8, 8, 12, 12, 16, 16, 12, 12, 8, 8, 4, 4, 0,
287 static const uint8_t obmc32
[1024]={
288 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
289 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
290 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0,
291 0, 0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 5, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0,
292 0, 0, 1, 1, 2, 3, 4, 5, 6, 7, 9,10,11,11,12,12,12,12,11,11,10, 9, 7, 6, 5, 4, 3, 2, 1, 1, 0, 0,
293 0, 0, 1, 2, 3, 5, 6, 8, 9,11,12,14,15,16,17,17,17,17,16,15,14,12,11, 9, 8, 6, 5, 3, 2, 1, 0, 0,
294 0, 1, 1, 2, 4, 6, 8,10,12,15,17,19,20,21,22,23,23,22,21,20,19,17,15,12,10, 8, 6, 4, 2, 1, 1, 0,
295 0, 1, 2, 3, 5, 8,10,13,16,19,21,24,26,27,28,29,29,28,27,26,24,21,19,16,13,10, 8, 5, 3, 2, 1, 0,
296 0, 1, 2, 4, 6, 9,12,16,19,23,26,29,31,33,34,35,35,34,33,31,29,26,23,19,16,12, 9, 6, 4, 2, 1, 0,
297 0, 1, 3, 5, 7,11,15,19,23,26,30,34,37,39,40,41,41,40,39,37,34,30,26,23,19,15,11, 7, 5, 3, 1, 0,
298 0, 1, 3, 5, 9,12,17,21,26,30,35,38,42,44,46,47,47,46,44,42,38,35,30,26,21,17,12, 9, 5, 3, 1, 0,
299 0, 1, 3, 6, 9,14,19,24,29,34,38,43,46,49,51,52,52,51,49,46,43,38,34,29,24,19,14, 9, 6, 3, 1, 0,
300 0, 1, 3, 6,11,15,20,26,31,37,42,46,50,53,56,57,57,56,53,50,46,42,37,31,26,20,15,11, 6, 3, 1, 0,
301 0, 1, 3, 7,11,16,21,27,33,39,44,49,53,57,59,60,60,59,57,53,49,44,39,33,27,21,16,11, 7, 3, 1, 0,
302 0, 1, 4, 7,12,17,22,28,34,40,46,51,56,59,61,63,63,61,59,56,51,46,40,34,28,22,17,12, 7, 4, 1, 0,
303 0, 1, 4, 7,12,17,23,29,35,41,47,52,57,60,63,64,64,63,60,57,52,47,41,35,29,23,17,12, 7, 4, 1, 0,
304 0, 1, 4, 7,12,17,23,29,35,41,47,52,57,60,63,64,64,63,60,57,52,47,41,35,29,23,17,12, 7, 4, 1, 0,
305 0, 1, 4, 7,12,17,22,28,34,40,46,51,56,59,61,63,63,61,59,56,51,46,40,34,28,22,17,12, 7, 4, 1, 0,
306 0, 1, 3, 7,11,16,21,27,33,39,44,49,53,57,59,60,60,59,57,53,49,44,39,33,27,21,16,11, 7, 3, 1, 0,
307 0, 1, 3, 6,11,15,20,26,31,37,42,46,50,53,56,57,57,56,53,50,46,42,37,31,26,20,15,11, 6, 3, 1, 0,
308 0, 1, 3, 6, 9,14,19,24,29,34,38,43,46,49,51,52,52,51,49,46,43,38,34,29,24,19,14, 9, 6, 3, 1, 0,
309 0, 1, 3, 5, 9,12,17,21,26,30,35,38,42,44,46,47,47,46,44,42,38,35,30,26,21,17,12, 9, 5, 3, 1, 0,
310 0, 1, 3, 5, 7,11,15,19,23,26,30,34,37,39,40,41,41,40,39,37,34,30,26,23,19,15,11, 7, 5, 3, 1, 0,
311 0, 1, 2, 4, 6, 9,12,16,19,23,26,29,31,33,34,35,35,34,33,31,29,26,23,19,16,12, 9, 6, 4, 2, 1, 0,
312 0, 1, 2, 3, 5, 8,10,13,16,19,21,24,26,27,28,29,29,28,27,26,24,21,19,16,13,10, 8, 5, 3, 2, 1, 0,
313 0, 1, 1, 2, 4, 6, 8,10,12,15,17,19,20,21,22,23,23,22,21,20,19,17,15,12,10, 8, 6, 4, 2, 1, 1, 0,
314 0, 0, 1, 2, 3, 5, 6, 8, 9,11,12,14,15,16,17,17,17,17,16,15,14,12,11, 9, 8, 6, 5, 3, 2, 1, 0, 0,
315 0, 0, 1, 1, 2, 3, 4, 5, 6, 7, 9,10,11,11,12,12,12,12,11,11,10, 9, 7, 6, 5, 4, 3, 2, 1, 1, 0, 0,
316 0, 0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 5, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0,
317 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0,
318 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
319 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
322 static const uint8_t obmc16
[256]={
323 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
324 0, 0, 1, 2, 3, 4, 5, 5, 5, 5, 4, 3, 2, 1, 0, 0,
325 0, 1, 3, 6, 8,11,13,14,14,13,11, 8, 6, 3, 1, 0,
326 0, 2, 6,10,15,20,24,26,26,24,20,15,10, 6, 2, 0,
327 0, 3, 8,16,23,30,35,38,38,35,30,23,16, 8, 3, 0,
328 1, 4,11,20,30,39,46,49,49,46,39,30,20,11, 4, 1,
329 1, 5,13,24,35,46,54,58,58,54,46,35,24,13, 5, 1,
330 0, 5,14,26,38,49,58,63,63,58,49,38,26,14, 5, 0,
331 0, 5,14,26,38,49,58,63,63,58,49,38,26,14, 5, 0,
332 1, 5,13,24,35,46,54,58,58,54,46,35,24,13, 5, 1,
333 1, 4,11,20,30,39,46,49,49,46,39,30,20,11, 4, 1,
334 0, 3, 8,16,23,30,35,38,38,35,30,23,16, 8, 3, 0,
335 0, 2, 6,10,15,20,24,26,26,24,20,15,10, 6, 2, 0,
336 0, 1, 3, 6, 8,11,13,14,14,13,11, 8, 6, 3, 1, 0,
337 0, 0, 1, 2, 3, 4, 5, 5, 5, 5, 4, 3, 2, 1, 0, 0,
338 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
344 static const uint8_t obmc8
[64]={
345 4, 12, 20, 28, 28, 20, 12, 4,
346 12, 36, 60, 84, 84, 60, 36, 12,
347 20, 60,100,140,140,100, 60, 20,
348 28, 84,140,196,196,140, 84, 28,
349 28, 84,140,196,196,140, 84, 28,
350 20, 60,100,140,140,100, 60, 20,
351 12, 36, 60, 84, 84, 60, 36, 12,
352 4, 12, 20, 28, 28, 20, 12, 4,
357 static const uint8_t obmc4
[16]={
365 static const uint8_t *obmc_tab
[4]={
366 obmc32
, obmc16
, obmc8
, obmc4
369 static int scale_mv_ref
[MAX_REF_FRAMES
][MAX_REF_FRAMES
];
371 typedef struct BlockNode
{
377 //#define TYPE_SPLIT 1
378 #define BLOCK_INTRA 1
380 //#define TYPE_NOCOLOR 4
381 uint8_t level
; //FIXME merge into type?
384 static const BlockNode null_block
= { //FIXME add border maybe
385 .color
= {128,128,128},
393 #define LOG2_MB_SIZE 4
394 #define MB_SIZE (1<<LOG2_MB_SIZE)
396 typedef struct x_and_coeff
{
401 typedef struct SubBand
{
406 int qlog
; ///< log(qscale)/log[2^(1/6)]
410 int stride_line
; ///< Stride measured in lines, not pixels.
411 x_and_coeff
* x_coeff
;
412 struct SubBand
*parent
;
413 uint8_t state
[/*7*2*/ 7 + 512][32];
416 typedef struct Plane
{
419 SubBand band
[MAX_DECOMPOSITIONS
][4];
422 typedef struct SnowContext
{
423 // MpegEncContext m; // needed for motion estimation, should not be used for anything else, the idea is to make the motion estimation eventually independant of MpegEncContext, so this will be removed then (FIXME/XXX)
425 AVCodecContext
*avctx
;
429 AVFrame input_picture
; ///< new_picture with the internal linesizes
430 AVFrame current_picture
;
431 AVFrame last_picture
[MAX_REF_FRAMES
];
432 AVFrame mconly_picture
;
433 // uint8_t q_context[16];
434 uint8_t header_state
[32];
435 uint8_t block_state
[128 + 32*128];
439 int spatial_decomposition_type
;
440 int temporal_decomposition_type
;
441 int spatial_decomposition_count
;
442 int temporal_decomposition_count
;
445 int16_t (*ref_mvs
[MAX_REF_FRAMES
])[2];
446 uint32_t *ref_scores
[MAX_REF_FRAMES
];
447 DWTELEM
*spatial_dwt_buffer
;
451 int spatial_scalability
;
458 #define QBIAS_SHIFT 3
462 Plane plane
[MAX_PLANES
];
464 #define ME_CACHE_SIZE 1024
465 int me_cache
[ME_CACHE_SIZE
];
466 int me_cache_generation
;
469 MpegEncContext m
; // needed for motion estimation, should not be used for anything else, the idea is to make the motion estimation eventually independant of MpegEncContext, so this will be removed then (FIXME/XXX)
480 #define slice_buffer_get_line(slice_buf, line_num) ((slice_buf)->line[line_num] ? (slice_buf)->line[line_num] : slice_buffer_load_line((slice_buf), (line_num)))
481 //#define slice_buffer_get_line(slice_buf, line_num) (slice_buffer_load_line((slice_buf), (line_num)))
483 static void iterative_me(SnowContext
*s
);
485 static void slice_buffer_init(slice_buffer
* buf
, int line_count
, int max_allocated_lines
, int line_width
, DWTELEM
* base_buffer
)
489 buf
->base_buffer
= base_buffer
;
490 buf
->line_count
= line_count
;
491 buf
->line_width
= line_width
;
492 buf
->data_count
= max_allocated_lines
;
493 buf
->line
= (DWTELEM
* *) av_mallocz (sizeof(DWTELEM
*) * line_count
);
494 buf
->data_stack
= (DWTELEM
* *) av_malloc (sizeof(DWTELEM
*) * max_allocated_lines
);
496 for (i
= 0; i
< max_allocated_lines
; i
++)
498 buf
->data_stack
[i
] = (DWTELEM
*) av_malloc (sizeof(DWTELEM
) * line_width
);
501 buf
->data_stack_top
= max_allocated_lines
- 1;
504 static DWTELEM
* slice_buffer_load_line(slice_buffer
* buf
, int line
)
509 // av_log(NULL, AV_LOG_DEBUG, "Cache hit: %d\n", line);
511 assert(buf
->data_stack_top
>= 0);
512 // assert(!buf->line[line]);
514 return buf
->line
[line
];
516 offset
= buf
->line_width
* line
;
517 buffer
= buf
->data_stack
[buf
->data_stack_top
];
518 buf
->data_stack_top
--;
519 buf
->line
[line
] = buffer
;
521 // av_log(NULL, AV_LOG_DEBUG, "slice_buffer_load_line: line: %d remaining: %d\n", line, buf->data_stack_top + 1);
526 static void slice_buffer_release(slice_buffer
* buf
, int line
)
531 assert(line
>= 0 && line
< buf
->line_count
);
532 assert(buf
->line
[line
]);
534 offset
= buf
->line_width
* line
;
535 buffer
= buf
->line
[line
];
536 buf
->data_stack_top
++;
537 buf
->data_stack
[buf
->data_stack_top
] = buffer
;
538 buf
->line
[line
] = NULL
;
540 // av_log(NULL, AV_LOG_DEBUG, "slice_buffer_release: line: %d remaining: %d\n", line, buf->data_stack_top + 1);
543 static void slice_buffer_flush(slice_buffer
* buf
)
546 for (i
= 0; i
< buf
->line_count
; i
++)
550 // av_log(NULL, AV_LOG_DEBUG, "slice_buffer_flush: line: %d \n", i);
551 slice_buffer_release(buf
, i
);
556 static void slice_buffer_destroy(slice_buffer
* buf
)
559 slice_buffer_flush(buf
);
561 for (i
= buf
->data_count
- 1; i
>= 0; i
--)
563 assert(buf
->data_stack
[i
]);
564 av_freep(&buf
->data_stack
[i
]);
566 assert(buf
->data_stack
);
567 av_freep(&buf
->data_stack
);
569 av_freep(&buf
->line
);
573 // Avoid a name clash on SGI IRIX
576 #define QEXPSHIFT (7-FRAC_BITS+8) //FIXME try to change this to 0
577 static uint8_t qexp
[QROOT
];
579 static inline int mirror(int v
, int m
){
580 while((unsigned)v
> (unsigned)m
){
587 static inline void put_symbol(RangeCoder
*c
, uint8_t *state
, int v
, int is_signed
){
592 const int e
= av_log2(a
);
594 const int el
= FFMIN(e
, 10);
595 put_rac(c
, state
+0, 0);
598 put_rac(c
, state
+1+i
, 1); //1..10
601 put_rac(c
, state
+1+9, 1); //1..10
603 put_rac(c
, state
+1+FFMIN(i
,9), 0);
605 for(i
=e
-1; i
>=el
; i
--){
606 put_rac(c
, state
+22+9, (a
>>i
)&1); //22..31
609 put_rac(c
, state
+22+i
, (a
>>i
)&1); //22..31
613 put_rac(c
, state
+11 + el
, v
< 0); //11..21
616 put_rac(c
, state
+0, 0);
619 put_rac(c
, state
+1+i
, 1); //1..10
621 put_rac(c
, state
+1+i
, 0);
623 for(i
=e
-1; i
>=0; i
--){
624 put_rac(c
, state
+22+i
, (a
>>i
)&1); //22..31
628 put_rac(c
, state
+11 + e
, v
< 0); //11..21
631 put_rac(c
, state
+1+FFMIN(i
,9), 1); //1..10
633 put_rac(c
, state
+1+FFMIN(i
,9), 0);
635 for(i
=e
-1; i
>=0; i
--){
636 put_rac(c
, state
+22+FFMIN(i
,9), (a
>>i
)&1); //22..31
640 put_rac(c
, state
+11 + FFMIN(e
,10), v
< 0); //11..21
644 put_rac(c
, state
+0, 1);
648 static inline int get_symbol(RangeCoder
*c
, uint8_t *state
, int is_signed
){
649 if(get_rac(c
, state
+0))
654 while(get_rac(c
, state
+1 + FFMIN(e
,9))){ //1..10
659 for(i
=e
-1; i
>=0; i
--){
660 a
+= a
+ get_rac(c
, state
+22 + FFMIN(i
,9)); //22..31
663 if(is_signed
&& get_rac(c
, state
+11 + FFMIN(e
,10))) //11..21
670 static inline void put_symbol2(RangeCoder
*c
, uint8_t *state
, int v
, int log2
){
672 int r
= log2
>=0 ?
1<<log2
: 1;
678 put_rac(c
, state
+4+log2
, 1);
683 put_rac(c
, state
+4+log2
, 0);
685 for(i
=log2
-1; i
>=0; i
--){
686 put_rac(c
, state
+31-i
, (v
>>i
)&1);
690 static inline int get_symbol2(RangeCoder
*c
, uint8_t *state
, int log2
){
692 int r
= log2
>=0 ?
1<<log2
: 1;
697 while(get_rac(c
, state
+4+log2
)){
703 for(i
=log2
-1; i
>=0; i
--){
704 v
+= get_rac(c
, state
+31-i
)<<i
;
710 static always_inline
void lift(DWTELEM
*dst
, DWTELEM
*src
, DWTELEM
*ref
, int dst_step
, int src_step
, int ref_step
, int width
, int mul
, int add
, int shift
, int highpass
, int inverse
){
711 const int mirror_left
= !highpass
;
712 const int mirror_right
= (width
&1) ^ highpass
;
713 const int w
= (width
>>1) - 1 + (highpass
& width
);
716 #define LIFT(src, ref, inv) ((src) + ((inv) ? - (ref) : + (ref)))
718 dst
[0] = LIFT(src
[0], ((mul
*2*ref
[0]+add
)>>shift
), inverse
);
724 dst
[i
*dst_step
] = LIFT(src
[i
*src_step
], ((mul
*(ref
[i
*ref_step
] + ref
[(i
+1)*ref_step
])+add
)>>shift
), inverse
);
728 dst
[w
*dst_step
] = LIFT(src
[w
*src_step
], ((mul
*2*ref
[w
*ref_step
]+add
)>>shift
), inverse
);
733 static always_inline
void lift5(DWTELEM
*dst
, DWTELEM
*src
, DWTELEM
*ref
, int dst_step
, int src_step
, int ref_step
, int width
, int mul
, int add
, int shift
, int highpass
, int inverse
){
734 const int mirror_left
= !highpass
;
735 const int mirror_right
= (width
&1) ^ highpass
;
736 const int w
= (width
>>1) - 1 + (highpass
& width
);
743 dst
[0] = LIFT(src
[0], ((r
+add
)>>shift
), inverse
);
749 int r
= 3*(ref
[i
*ref_step
] + ref
[(i
+1)*ref_step
]);
752 dst
[i
*dst_step
] = LIFT(src
[i
*src_step
], ((r
+add
)>>shift
), inverse
);
756 int r
= 3*2*ref
[w
*ref_step
];
759 dst
[w
*dst_step
] = LIFT(src
[w
*src_step
], ((r
+add
)>>shift
), inverse
);
765 static always_inline
void liftS(DWTELEM
*dst
, DWTELEM
*src
, DWTELEM
*ref
, int dst_step
, int src_step
, int ref_step
, int width
, int mul
, int add
, int shift
, int highpass
, int inverse
){
766 const int mirror_left
= !highpass
;
767 const int mirror_right
= (width
&1) ^ highpass
;
768 const int w
= (width
>>1) - 1 + (highpass
& width
);
772 #define LIFTS(src, ref, inv) ((inv) ? (src) - (((ref) - 4*(src))>>shift): (16*4*(src) + 4*(ref) + 8 + (5<<27))/(5*16) - (1<<23))
774 dst
[0] = LIFTS(src
[0], mul
*2*ref
[0]+add
, inverse
);
780 dst
[i
*dst_step
] = LIFTS(src
[i
*src_step
], mul
*(ref
[i
*ref_step
] + ref
[(i
+1)*ref_step
])+add
, inverse
);
784 dst
[w
*dst_step
] = LIFTS(src
[w
*src_step
], mul
*2*ref
[w
*ref_step
]+add
, inverse
);
790 static void inplace_lift(DWTELEM
*dst
, int width
, int *coeffs
, int n
, int shift
, int start
, int inverse
){
793 for(x
=start
; x
<width
; x
+=2){
797 int x2
= x
+ 2*i
- n
+ 1;
799 else if(x2
>=width
) x2
= 2*width
-x2
-2;
800 sum
+= coeffs
[i
]*(int64_t)dst
[x2
];
802 if(inverse
) dst
[x
] -= (sum
+ (1<<shift
)/2)>>shift
;
803 else dst
[x
] += (sum
+ (1<<shift
)/2)>>shift
;
807 static void inplace_liftV(DWTELEM
*dst
, int width
, int height
, int stride
, int *coeffs
, int n
, int shift
, int start
, int inverse
){
809 for(y
=start
; y
<height
; y
+=2){
810 for(x
=0; x
<width
; x
++){
814 int y2
= y
+ 2*i
- n
+ 1;
816 else if(y2
>=height
) y2
= 2*height
-y2
-2;
817 sum
+= coeffs
[i
]*(int64_t)dst
[x
+ y2
*stride
];
819 if(inverse
) dst
[x
+ y
*stride
] -= (sum
+ (1<<shift
)/2)>>shift
;
820 else dst
[x
+ y
*stride
] += (sum
+ (1<<shift
)/2)>>shift
;
829 #if 0 // more accurate 9/7
832 #define COEFFS1 (int[]){-25987,-25987}
835 #define COEFFS2 (int[]){-27777,-27777}
838 #define COEFFS3 (int[]){28931,28931}
841 #define COEFFS4 (int[]){14533,14533}
845 #define COEFFS1 (int[]){1,-9,-9,1}
848 #define COEFFS2 (int[]){-1,5,5,-1}
861 #define COEFFS1 (int[]){1,1}
864 #define COEFFS2 (int[]){-1,-1}
877 #define COEFFS2 (int[]){-1,-1}
880 #define COEFFS3 (int[]){-1,-1}
883 #define COEFFS4 (int[]){-5,29,29,-5}
888 #define COEFFS1 (int[]){-203,-203}
891 #define COEFFS2 (int[]){-217,-217}
894 #define COEFFS3 (int[]){113,113}
897 #define COEFFS4 (int[]){227,227}
905 #define COEFFS2 (int[]){-1,-1}
908 #define COEFFS3 (int[]){-1,-1}
911 #define COEFFS4 (int[]){3,3}
915 #define COEFFS1 (int[]){1,-9,-9,1}
918 #define COEFFS2 (int[]){1,1}
928 #define COEFFS1 (int[]){1,-9,-9,1}
931 #define COEFFS2 (int[]){-1,5,5,-1}
939 static void horizontal_decomposeX(DWTELEM
*b
, int width
){
941 const int width2
= width
>>1;
942 const int w2
= (width
+1)>>1;
945 inplace_lift(b
, width
, COEFFS1
, N1
, SHIFT1
, LX1
, 0);
946 inplace_lift(b
, width
, COEFFS2
, N2
, SHIFT2
, LX0
, 0);
947 inplace_lift(b
, width
, COEFFS3
, N3
, SHIFT3
, LX1
, 0);
948 inplace_lift(b
, width
, COEFFS4
, N4
, SHIFT4
, LX0
, 0);
950 for(x
=0; x
<width2
; x
++){
952 temp
[x
+w2
]= b
[2*x
+ 1];
956 memcpy(b
, temp
, width
*sizeof(int));
959 static void horizontal_composeX(DWTELEM
*b
, int width
){
961 const int width2
= width
>>1;
963 const int w2
= (width
+1)>>1;
965 memcpy(temp
, b
, width
*sizeof(int));
966 for(x
=0; x
<width2
; x
++){
968 b
[2*x
+ 1]= temp
[x
+w2
];
973 inplace_lift(b
, width
, COEFFS4
, N4
, SHIFT4
, LX0
, 1);
974 inplace_lift(b
, width
, COEFFS3
, N3
, SHIFT3
, LX1
, 1);
975 inplace_lift(b
, width
, COEFFS2
, N2
, SHIFT2
, LX0
, 1);
976 inplace_lift(b
, width
, COEFFS1
, N1
, SHIFT1
, LX1
, 1);
979 static void spatial_decomposeX(DWTELEM
*buffer
, int width
, int height
, int stride
){
982 for(y
=0; y
<height
; y
++){
983 for(x
=0; x
<width
; x
++){
984 buffer
[y
*stride
+ x
] *= SCALEX
;
988 for(y
=0; y
<height
; y
++){
989 horizontal_decomposeX(buffer
+ y
*stride
, width
);
992 inplace_liftV(buffer
, width
, height
, stride
, COEFFS1
, N1
, SHIFT1
, LX1
, 0);
993 inplace_liftV(buffer
, width
, height
, stride
, COEFFS2
, N2
, SHIFT2
, LX0
, 0);
994 inplace_liftV(buffer
, width
, height
, stride
, COEFFS3
, N3
, SHIFT3
, LX1
, 0);
995 inplace_liftV(buffer
, width
, height
, stride
, COEFFS4
, N4
, SHIFT4
, LX0
, 0);
998 static void spatial_composeX(DWTELEM
*buffer
, int width
, int height
, int stride
){
1001 inplace_liftV(buffer
, width
, height
, stride
, COEFFS4
, N4
, SHIFT4
, LX0
, 1);
1002 inplace_liftV(buffer
, width
, height
, stride
, COEFFS3
, N3
, SHIFT3
, LX1
, 1);
1003 inplace_liftV(buffer
, width
, height
, stride
, COEFFS2
, N2
, SHIFT2
, LX0
, 1);
1004 inplace_liftV(buffer
, width
, height
, stride
, COEFFS1
, N1
, SHIFT1
, LX1
, 1);
1006 for(y
=0; y
<height
; y
++){
1007 horizontal_composeX(buffer
+ y
*stride
, width
);
1010 for(y
=0; y
<height
; y
++){
1011 for(x
=0; x
<width
; x
++){
1012 buffer
[y
*stride
+ x
] /= SCALEX
;
1017 static void horizontal_decompose53i(DWTELEM
*b
, int width
){
1018 DWTELEM temp
[width
];
1019 const int width2
= width
>>1;
1021 const int w2
= (width
+1)>>1;
1023 for(x
=0; x
<width2
; x
++){
1025 temp
[x
+w2
]= b
[2*x
+ 1];
1039 for(x
=1; x
+1<width2
; x
+=2){
1043 A2
+= (A1
+ A3
+ 2)>>2;
1047 A1
= temp
[x
+1+width2
];
1050 A4
+= (A1
+ A3
+ 2)>>2;
1056 A2
+= (A1
+ A3
+ 2)>>2;
1061 lift(b
+w2
, temp
+w2
, temp
, 1, 1, 1, width
, -1, 0, 1, 1, 0);
1062 lift(b
, temp
, b
+w2
, 1, 1, 1, width
, 1, 2, 2, 0, 0);
1066 static void vertical_decompose53iH0(DWTELEM
*b0
, DWTELEM
*b1
, DWTELEM
*b2
, int width
){
1069 for(i
=0; i
<width
; i
++){
1070 b1
[i
] -= (b0
[i
] + b2
[i
])>>1;
1074 static void vertical_decompose53iL0(DWTELEM
*b0
, DWTELEM
*b1
, DWTELEM
*b2
, int width
){
1077 for(i
=0; i
<width
; i
++){
1078 b1
[i
] += (b0
[i
] + b2
[i
] + 2)>>2;
1082 static void spatial_decompose53i(DWTELEM
*buffer
, int width
, int height
, int stride
){
1084 DWTELEM
*b0
= buffer
+ mirror(-2-1, height
-1)*stride
;
1085 DWTELEM
*b1
= buffer
+ mirror(-2 , height
-1)*stride
;
1087 for(y
=-2; y
<height
; y
+=2){
1088 DWTELEM
*b2
= buffer
+ mirror(y
+1, height
-1)*stride
;
1089 DWTELEM
*b3
= buffer
+ mirror(y
+2, height
-1)*stride
;
1092 if(y
+1<(unsigned)height
) horizontal_decompose53i(b2
, width
);
1093 if(y
+2<(unsigned)height
) horizontal_decompose53i(b3
, width
);
1094 STOP_TIMER("horizontal_decompose53i")}
1097 if(y
+1<(unsigned)height
) vertical_decompose53iH0(b1
, b2
, b3
, width
);
1098 if(y
+0<(unsigned)height
) vertical_decompose53iL0(b0
, b1
, b2
, width
);
1099 STOP_TIMER("vertical_decompose53i*")}
1106 static void horizontal_decompose97i(DWTELEM
*b
, int width
){
1107 DWTELEM temp
[width
];
1108 const int w2
= (width
+1)>>1;
1110 lift (temp
+w2
, b
+1, b
, 1, 2, 2, width
, -W_AM
, W_AO
, W_AS
, 1, 0);
1111 liftS(temp
, b
, temp
+w2
, 1, 2, 1, width
, -W_BM
, W_BO
, W_BS
, 0, 0);
1112 lift5(b
+w2
, temp
+w2
, temp
, 1, 1, 1, width
, W_CM
, W_CO
, W_CS
, 1, 0);
1113 lift (b
, temp
, b
+w2
, 1, 1, 1, width
, W_DM
, W_DO
, W_DS
, 0, 0);
1117 static void vertical_decompose97iH0(DWTELEM
*b0
, DWTELEM
*b1
, DWTELEM
*b2
, int width
){
1120 for(i
=0; i
<width
; i
++){
1121 b1
[i
] -= (W_AM
*(b0
[i
] + b2
[i
])+W_AO
)>>W_AS
;
1125 static void vertical_decompose97iH1(DWTELEM
*b0
, DWTELEM
*b1
, DWTELEM
*b2
, int width
){
1128 for(i
=0; i
<width
; i
++){
1130 b1
[i
] += (W_CM
*(b0
[i
] + b2
[i
])+W_CO
)>>W_CS
;
1132 int r
= 3*(b0
[i
] + b2
[i
]);
1135 b1
[i
] += (r
+W_CO
)>>W_CS
;
1140 static void vertical_decompose97iL0(DWTELEM
*b0
, DWTELEM
*b1
, DWTELEM
*b2
, int width
){
1143 for(i
=0; i
<width
; i
++){
1145 b1
[i
] -= (W_BM
*(b0
[i
] + b2
[i
])+W_BO
)>>W_BS
;
1147 b1
[i
] = (16*4*b1
[i
] - 4*(b0
[i
] + b2
[i
]) + 8*5 + (5<<27)) / (5*16) - (1<<23);
1152 static void vertical_decompose97iL1(DWTELEM
*b0
, DWTELEM
*b1
, DWTELEM
*b2
, int width
){
1155 for(i
=0; i
<width
; i
++){
1156 b1
[i
] += (W_DM
*(b0
[i
] + b2
[i
])+W_DO
)>>W_DS
;
1160 static void spatial_decompose97i(DWTELEM
*buffer
, int width
, int height
, int stride
){
1162 DWTELEM
*b0
= buffer
+ mirror(-4-1, height
-1)*stride
;
1163 DWTELEM
*b1
= buffer
+ mirror(-4 , height
-1)*stride
;
1164 DWTELEM
*b2
= buffer
+ mirror(-4+1, height
-1)*stride
;
1165 DWTELEM
*b3
= buffer
+ mirror(-4+2, height
-1)*stride
;
1167 for(y
=-4; y
<height
; y
+=2){
1168 DWTELEM
*b4
= buffer
+ mirror(y
+3, height
-1)*stride
;
1169 DWTELEM
*b5
= buffer
+ mirror(y
+4, height
-1)*stride
;
1172 if(y
+3<(unsigned)height
) horizontal_decompose97i(b4
, width
);
1173 if(y
+4<(unsigned)height
) horizontal_decompose97i(b5
, width
);
1175 STOP_TIMER("horizontal_decompose97i")
1179 if(y
+3<(unsigned)height
) vertical_decompose97iH0(b3
, b4
, b5
, width
);
1180 if(y
+2<(unsigned)height
) vertical_decompose97iL0(b2
, b3
, b4
, width
);
1181 if(y
+1<(unsigned)height
) vertical_decompose97iH1(b1
, b2
, b3
, width
);
1182 if(y
+0<(unsigned)height
) vertical_decompose97iL1(b0
, b1
, b2
, width
);
1185 STOP_TIMER("vertical_decompose97i")
1195 void ff_spatial_dwt(DWTELEM
*buffer
, int width
, int height
, int stride
, int type
, int decomposition_count
){
1198 for(level
=0; level
<decomposition_count
; level
++){
1200 case DWT_97
: spatial_decompose97i(buffer
, width
>>level
, height
>>level
, stride
<<level
); break;
1201 case DWT_53
: spatial_decompose53i(buffer
, width
>>level
, height
>>level
, stride
<<level
); break;
1202 case DWT_X
: spatial_decomposeX (buffer
, width
>>level
, height
>>level
, stride
<<level
); break;
1207 static void horizontal_compose53i(DWTELEM
*b
, int width
){
1208 DWTELEM temp
[width
];
1209 const int width2
= width
>>1;
1210 const int w2
= (width
+1)>>1;
1222 for(x
=1; x
+1<width2
; x
+=2){
1226 A2
+= (A1
+ A3
+ 2)>>2;
1230 A1
= temp
[x
+1+width2
];
1233 A4
+= (A1
+ A3
+ 2)>>2;
1239 A2
+= (A1
+ A3
+ 2)>>2;
1243 lift(temp
, b
, b
+w2
, 1, 1, 1, width
, 1, 2, 2, 0, 1);
1244 lift(temp
+w2
, b
+w2
, temp
, 1, 1, 1, width
, -1, 0, 1, 1, 1);
1246 for(x
=0; x
<width2
; x
++){
1248 b
[2*x
+ 1]= temp
[x
+w2
];
1254 static void vertical_compose53iH0(DWTELEM
*b0
, DWTELEM
*b1
, DWTELEM
*b2
, int width
){
1257 for(i
=0; i
<width
; i
++){
1258 b1
[i
] += (b0
[i
] + b2
[i
])>>1;
1262 static void vertical_compose53iL0(DWTELEM
*b0
, DWTELEM
*b1
, DWTELEM
*b2
, int width
){
1265 for(i
=0; i
<width
; i
++){
1266 b1
[i
] -= (b0
[i
] + b2
[i
] + 2)>>2;
1270 static void spatial_compose53i_buffered_init(dwt_compose_t
*cs
, slice_buffer
* sb
, int height
, int stride_line
){
1271 cs
->b0
= slice_buffer_get_line(sb
, mirror(-1-1, height
-1) * stride_line
);
1272 cs
->b1
= slice_buffer_get_line(sb
, mirror(-1 , height
-1) * stride_line
);
1276 static void spatial_compose53i_init(dwt_compose_t
*cs
, DWTELEM
*buffer
, int height
, int stride
){
1277 cs
->b0
= buffer
+ mirror(-1-1, height
-1)*stride
;
1278 cs
->b1
= buffer
+ mirror(-1 , height
-1)*stride
;
1282 static void spatial_compose53i_dy_buffered(dwt_compose_t
*cs
, slice_buffer
* sb
, int width
, int height
, int stride_line
){
1285 DWTELEM
*b0
= cs
->b0
;
1286 DWTELEM
*b1
= cs
->b1
;
1287 DWTELEM
*b2
= slice_buffer_get_line(sb
, mirror(y
+1, height
-1) * stride_line
);
1288 DWTELEM
*b3
= slice_buffer_get_line(sb
, mirror(y
+2, height
-1) * stride_line
);
1291 if(y
+1<(unsigned)height
) vertical_compose53iL0(b1
, b2
, b3
, width
);
1292 if(y
+0<(unsigned)height
) vertical_compose53iH0(b0
, b1
, b2
, width
);
1293 STOP_TIMER("vertical_compose53i*")}
1296 if(y
-1<(unsigned)height
) horizontal_compose53i(b0
, width
);
1297 if(y
+0<(unsigned)height
) horizontal_compose53i(b1
, width
);
1298 STOP_TIMER("horizontal_compose53i")}
1305 static void spatial_compose53i_dy(dwt_compose_t
*cs
, DWTELEM
*buffer
, int width
, int height
, int stride
){
1307 DWTELEM
*b0
= cs
->b0
;
1308 DWTELEM
*b1
= cs
->b1
;
1309 DWTELEM
*b2
= buffer
+ mirror(y
+1, height
-1)*stride
;
1310 DWTELEM
*b3
= buffer
+ mirror(y
+2, height
-1)*stride
;
1313 if(y
+1<(unsigned)height
) vertical_compose53iL0(b1
, b2
, b3
, width
);
1314 if(y
+0<(unsigned)height
) vertical_compose53iH0(b0
, b1
, b2
, width
);
1315 STOP_TIMER("vertical_compose53i*")}
1318 if(y
-1<(unsigned)height
) horizontal_compose53i(b0
, width
);
1319 if(y
+0<(unsigned)height
) horizontal_compose53i(b1
, width
);
1320 STOP_TIMER("horizontal_compose53i")}
1327 static void spatial_compose53i(DWTELEM
*buffer
, int width
, int height
, int stride
){
1329 spatial_compose53i_init(&cs
, buffer
, height
, stride
);
1330 while(cs
.y
<= height
)
1331 spatial_compose53i_dy(&cs
, buffer
, width
, height
, stride
);
1335 void ff_snow_horizontal_compose97i(DWTELEM
*b
, int width
){
1336 DWTELEM temp
[width
];
1337 const int w2
= (width
+1)>>1;
1339 lift (temp
, b
, b
+w2
, 1, 1, 1, width
, W_DM
, W_DO
, W_DS
, 0, 1);
1340 lift5(temp
+w2
, b
+w2
, temp
, 1, 1, 1, width
, W_CM
, W_CO
, W_CS
, 1, 1);
1341 liftS(b
, temp
, temp
+w2
, 2, 1, 1, width
, -W_BM
, W_BO
, W_BS
, 0, 1);
1342 lift (b
+1 , temp
+w2
, b
, 2, 1, 2, width
, -W_AM
, W_AO
, W_AS
, 1, 1);
1345 static void vertical_compose97iH0(DWTELEM
*b0
, DWTELEM
*b1
, DWTELEM
*b2
, int width
){
1348 for(i
=0; i
<width
; i
++){
1349 b1
[i
] += (W_AM
*(b0
[i
] + b2
[i
])+W_AO
)>>W_AS
;
1353 static void vertical_compose97iH1(DWTELEM
*b0
, DWTELEM
*b1
, DWTELEM
*b2
, int width
){
1356 for(i
=0; i
<width
; i
++){
1358 b1
[i
] -= (W_CM
*(b0
[i
] + b2
[i
])+W_CO
)>>W_CS
;
1360 int r
= 3*(b0
[i
] + b2
[i
]);
1363 b1
[i
] -= (r
+W_CO
)>>W_CS
;
1368 static void vertical_compose97iL0(DWTELEM
*b0
, DWTELEM
*b1
, DWTELEM
*b2
, int width
){
1371 for(i
=0; i
<width
; i
++){
1373 b1
[i
] += (W_BM
*(b0
[i
] + b2
[i
])+W_BO
)>>W_BS
;
1375 b1
[i
] += (W_BM
*(b0
[i
] + b2
[i
])+4*b1
[i
]+W_BO
)>>W_BS
;
1380 static void vertical_compose97iL1(DWTELEM
*b0
, DWTELEM
*b1
, DWTELEM
*b2
, int width
){
1383 for(i
=0; i
<width
; i
++){
1384 b1
[i
] -= (W_DM
*(b0
[i
] + b2
[i
])+W_DO
)>>W_DS
;
1388 void ff_snow_vertical_compose97i(DWTELEM
*b0
, DWTELEM
*b1
, DWTELEM
*b2
, DWTELEM
*b3
, DWTELEM
*b4
, DWTELEM
*b5
, int width
){
1391 for(i
=0; i
<width
; i
++){
1395 b4
[i
] -= (W_DM
*(b3
[i
] + b5
[i
])+W_DO
)>>W_DS
;
1397 b3
[i
] -= (W_CM
*(b2
[i
] + b4
[i
])+W_CO
)>>W_CS
;
1399 r
= 3*(b2
[i
] + b4
[i
]);
1402 b3
[i
] -= (r
+W_CO
)>>W_CS
;
1405 b2
[i
] += (W_BM
*(b1
[i
] + b3
[i
])+W_BO
)>>W_BS
;
1407 b2
[i
] += (W_BM
*(b1
[i
] + b3
[i
])+4*b2
[i
]+W_BO
)>>W_BS
;
1409 b1
[i
] += (W_AM
*(b0
[i
] + b2
[i
])+W_AO
)>>W_AS
;
1413 static void spatial_compose97i_buffered_init(dwt_compose_t
*cs
, slice_buffer
* sb
, int height
, int stride_line
){
1414 cs
->b0
= slice_buffer_get_line(sb
, mirror(-3-1, height
-1) * stride_line
);
1415 cs
->b1
= slice_buffer_get_line(sb
, mirror(-3 , height
-1) * stride_line
);
1416 cs
->b2
= slice_buffer_get_line(sb
, mirror(-3+1, height
-1) * stride_line
);
1417 cs
->b3
= slice_buffer_get_line(sb
, mirror(-3+2, height
-1) * stride_line
);
1421 static void spatial_compose97i_init(dwt_compose_t
*cs
, DWTELEM
*buffer
, int height
, int stride
){
1422 cs
->b0
= buffer
+ mirror(-3-1, height
-1)*stride
;
1423 cs
->b1
= buffer
+ mirror(-3 , height
-1)*stride
;
1424 cs
->b2
= buffer
+ mirror(-3+1, height
-1)*stride
;
1425 cs
->b3
= buffer
+ mirror(-3+2, height
-1)*stride
;
1429 static void spatial_compose97i_dy_buffered(DSPContext
*dsp
, dwt_compose_t
*cs
, slice_buffer
* sb
, int width
, int height
, int stride_line
){
1432 DWTELEM
*b0
= cs
->b0
;
1433 DWTELEM
*b1
= cs
->b1
;
1434 DWTELEM
*b2
= cs
->b2
;
1435 DWTELEM
*b3
= cs
->b3
;
1436 DWTELEM
*b4
= slice_buffer_get_line(sb
, mirror(y
+ 3, height
- 1) * stride_line
);
1437 DWTELEM
*b5
= slice_buffer_get_line(sb
, mirror(y
+ 4, height
- 1) * stride_line
);
1440 if(y
>0 && y
+4<height
){
1441 dsp
->vertical_compose97i(b0
, b1
, b2
, b3
, b4
, b5
, width
);
1443 if(y
+3<(unsigned)height
) vertical_compose97iL1(b3
, b4
, b5
, width
);
1444 if(y
+2<(unsigned)height
) vertical_compose97iH1(b2
, b3
, b4
, width
);
1445 if(y
+1<(unsigned)height
) vertical_compose97iL0(b1
, b2
, b3
, width
);
1446 if(y
+0<(unsigned)height
) vertical_compose97iH0(b0
, b1
, b2
, width
);
1449 STOP_TIMER("vertical_compose97i")}}
1452 if(y
-1<(unsigned)height
) dsp
->horizontal_compose97i(b0
, width
);
1453 if(y
+0<(unsigned)height
) dsp
->horizontal_compose97i(b1
, width
);
1454 if(width
>400 && y
+0<(unsigned)height
){
1455 STOP_TIMER("horizontal_compose97i")}}
1464 static void spatial_compose97i_dy(dwt_compose_t
*cs
, DWTELEM
*buffer
, int width
, int height
, int stride
){
1466 DWTELEM
*b0
= cs
->b0
;
1467 DWTELEM
*b1
= cs
->b1
;
1468 DWTELEM
*b2
= cs
->b2
;
1469 DWTELEM
*b3
= cs
->b3
;
1470 DWTELEM
*b4
= buffer
+ mirror(y
+3, height
-1)*stride
;
1471 DWTELEM
*b5
= buffer
+ mirror(y
+4, height
-1)*stride
;
1474 if(y
+3<(unsigned)height
) vertical_compose97iL1(b3
, b4
, b5
, width
);
1475 if(y
+2<(unsigned)height
) vertical_compose97iH1(b2
, b3
, b4
, width
);
1476 if(y
+1<(unsigned)height
) vertical_compose97iL0(b1
, b2
, b3
, width
);
1477 if(y
+0<(unsigned)height
) vertical_compose97iH0(b0
, b1
, b2
, width
);
1479 STOP_TIMER("vertical_compose97i")}}
1482 if(y
-1<(unsigned)height
) ff_snow_horizontal_compose97i(b0
, width
);
1483 if(y
+0<(unsigned)height
) ff_snow_horizontal_compose97i(b1
, width
);
1484 if(width
>400 && b0
<= b2
){
1485 STOP_TIMER("horizontal_compose97i")}}
1494 static void spatial_compose97i(DWTELEM
*buffer
, int width
, int height
, int stride
){
1496 spatial_compose97i_init(&cs
, buffer
, height
, stride
);
1497 while(cs
.y
<= height
)
1498 spatial_compose97i_dy(&cs
, buffer
, width
, height
, stride
);
1501 static void ff_spatial_idwt_buffered_init(dwt_compose_t
*cs
, slice_buffer
* sb
, int width
, int height
, int stride_line
, int type
, int decomposition_count
){
1503 for(level
=decomposition_count
-1; level
>=0; level
--){
1505 case DWT_97
: spatial_compose97i_buffered_init(cs
+level
, sb
, height
>>level
, stride_line
<<level
); break;
1506 case DWT_53
: spatial_compose53i_buffered_init(cs
+level
, sb
, height
>>level
, stride_line
<<level
); break;
1507 /* not slicified yet */
1508 case DWT_X
: /*spatial_composeX(buffer, width>>level, height>>level, stride<<level); break;*/
1509 av_log(NULL
, AV_LOG_ERROR
, "spatial_composeX neither buffered nor slicified yet.\n"); break;
1514 static void ff_spatial_idwt_init(dwt_compose_t
*cs
, DWTELEM
*buffer
, int width
, int height
, int stride
, int type
, int decomposition_count
){
1516 for(level
=decomposition_count
-1; level
>=0; level
--){
1518 case DWT_97
: spatial_compose97i_init(cs
+level
, buffer
, height
>>level
, stride
<<level
); break;
1519 case DWT_53
: spatial_compose53i_init(cs
+level
, buffer
, height
>>level
, stride
<<level
); break;
1520 /* not slicified yet */
1521 case DWT_X
: spatial_composeX(buffer
, width
>>level
, height
>>level
, stride
<<level
); break;
1526 static void ff_spatial_idwt_slice(dwt_compose_t
*cs
, DWTELEM
*buffer
, int width
, int height
, int stride
, int type
, int decomposition_count
, int y
){
1527 const int support
= type
==1 ?
3 : 5;
1531 for(level
=decomposition_count
-1; level
>=0; level
--){
1532 while(cs
[level
].y
<= FFMIN((y
>>level
)+support
, height
>>level
)){
1534 case DWT_97
: spatial_compose97i_dy(cs
+level
, buffer
, width
>>level
, height
>>level
, stride
<<level
);
1536 case DWT_53
: spatial_compose53i_dy(cs
+level
, buffer
, width
>>level
, height
>>level
, stride
<<level
);
1544 static void ff_spatial_idwt_buffered_slice(DSPContext
*dsp
, dwt_compose_t
*cs
, slice_buffer
* slice_buf
, int width
, int height
, int stride_line
, int type
, int decomposition_count
, int y
){
1545 const int support
= type
==1 ?
3 : 5;
1549 for(level
=decomposition_count
-1; level
>=0; level
--){
1550 while(cs
[level
].y
<= FFMIN((y
>>level
)+support
, height
>>level
)){
1552 case DWT_97
: spatial_compose97i_dy_buffered(dsp
, cs
+level
, slice_buf
, width
>>level
, height
>>level
, stride_line
<<level
);
1554 case DWT_53
: spatial_compose53i_dy_buffered(cs
+level
, slice_buf
, width
>>level
, height
>>level
, stride_line
<<level
);
1562 static void ff_spatial_idwt(DWTELEM
*buffer
, int width
, int height
, int stride
, int type
, int decomposition_count
){
1565 for(level
=decomposition_count
-1; level
>=0; level
--)
1566 spatial_composeX (buffer
, width
>>level
, height
>>level
, stride
<<level
);
1568 dwt_compose_t cs
[MAX_DECOMPOSITIONS
];
1570 ff_spatial_idwt_init(cs
, buffer
, width
, height
, stride
, type
, decomposition_count
);
1571 for(y
=0; y
<height
; y
+=4)
1572 ff_spatial_idwt_slice(cs
, buffer
, width
, height
, stride
, type
, decomposition_count
, y
);
1576 static int encode_subband_c0run(SnowContext
*s
, SubBand
*b
, DWTELEM
*src
, DWTELEM
*parent
, int stride
, int orientation
){
1577 const int w
= b
->width
;
1578 const int h
= b
->height
;
1590 int /*ll=0, */l
=0, lt
=0, t
=0, rt
=0;
1591 v
= src
[x
+ y
*stride
];
1594 t
= src
[x
+ (y
-1)*stride
];
1596 lt
= src
[x
- 1 + (y
-1)*stride
];
1599 rt
= src
[x
+ 1 + (y
-1)*stride
];
1603 l
= src
[x
- 1 + y
*stride
];
1605 if(orientation==1) ll= src[y + (x-2)*stride];
1606 else ll= src[x - 2 + y*stride];
1612 if(px
<b
->parent
->width
&& py
<b
->parent
->height
)
1613 p
= parent
[px
+ py
*2*stride
];
1615 if(!(/*ll|*/l
|lt
|t
|rt
|p
)){
1617 runs
[run_index
++]= run
;
1625 max_index
= run_index
;
1626 runs
[run_index
++]= run
;
1628 run
= runs
[run_index
++];
1630 put_symbol2(&s
->c
, b
->state
[30], max_index
, 0);
1631 if(run_index
<= max_index
)
1632 put_symbol2(&s
->c
, b
->state
[1], run
, 3);
1635 if(s
->c
.bytestream_end
- s
->c
.bytestream
< w
*40){
1636 av_log(s
->avctx
, AV_LOG_ERROR
, "encoded frame too large\n");
1641 int /*ll=0, */l
=0, lt
=0, t
=0, rt
=0;
1642 v
= src
[x
+ y
*stride
];
1645 t
= src
[x
+ (y
-1)*stride
];
1647 lt
= src
[x
- 1 + (y
-1)*stride
];
1650 rt
= src
[x
+ 1 + (y
-1)*stride
];
1654 l
= src
[x
- 1 + y
*stride
];
1656 if(orientation==1) ll= src[y + (x-2)*stride];
1657 else ll= src[x - 2 + y*stride];
1663 if(px
<b
->parent
->width
&& py
<b
->parent
->height
)
1664 p
= parent
[px
+ py
*2*stride
];
1666 if(/*ll|*/l
|lt
|t
|rt
|p
){
1667 int context
= av_log2(/*ABS(ll) + */3*ABS(l
) + ABS(lt
) + 2*ABS(t
) + ABS(rt
) + ABS(p
));
1669 put_rac(&s
->c
, &b
->state
[0][context
], !!v
);
1672 run
= runs
[run_index
++];
1674 if(run_index
<= max_index
)
1675 put_symbol2(&s
->c
, b
->state
[1], run
, 3);
1683 int context
= av_log2(/*ABS(ll) + */3*ABS(l
) + ABS(lt
) + 2*ABS(t
) + ABS(rt
) + ABS(p
));
1684 int l2
= 2*ABS(l
) + (l
<0);
1685 int t2
= 2*ABS(t
) + (t
<0);
1687 put_symbol2(&s
->c
, b
->state
[context
+ 2], ABS(v
)-1, context
-4);
1688 put_rac(&s
->c
, &b
->state
[0][16 + 1 + 3 + quant3bA
[l2
&0xFF] + 3*quant3bA
[t2
&0xFF]], v
<0);
1696 static int encode_subband(SnowContext
*s
, SubBand
*b
, DWTELEM
*src
, DWTELEM
*parent
, int stride
, int orientation
){
1697 // encode_subband_qtree(s, b, src, parent, stride, orientation);
1698 // encode_subband_z0run(s, b, src, parent, stride, orientation);
1699 return encode_subband_c0run(s
, b
, src
, parent
, stride
, orientation
);
1700 // encode_subband_dzr(s, b, src, parent, stride, orientation);
1703 static inline void unpack_coeffs(SnowContext
*s
, SubBand
*b
, SubBand
* parent
, int orientation
){
1704 const int w
= b
->width
;
1705 const int h
= b
->height
;
1710 x_and_coeff
*xc
= b
->x_coeff
;
1711 x_and_coeff
*prev_xc
= NULL
;
1712 x_and_coeff
*prev2_xc
= xc
;
1713 x_and_coeff
*parent_xc
= parent ? parent
->x_coeff
: NULL
;
1714 x_and_coeff
*prev_parent_xc
= parent_xc
;
1716 runs
= get_symbol2(&s
->c
, b
->state
[30], 0);
1717 if(runs
-- > 0) run
= get_symbol2(&s
->c
, b
->state
[1], 3);
1722 int lt
=0, t
=0, rt
=0;
1724 if(y
&& prev_xc
->x
== 0){
1736 if(prev_xc
->x
== x
+ 1)
1742 if(x
>>1 > parent_xc
->x
){
1745 if(x
>>1 == parent_xc
->x
){
1746 p
= parent_xc
->coeff
;
1749 if(/*ll|*/l
|lt
|t
|rt
|p
){
1750 int context
= av_log2(/*ABS(ll) + */3*(l
>>1) + (lt
>>1) + (t
&~1) + (rt
>>1) + (p
>>1));
1752 v
=get_rac(&s
->c
, &b
->state
[0][context
]);
1754 v
= 2*(get_symbol2(&s
->c
, b
->state
[context
+ 2], context
-4) + 1);
1755 v
+=get_rac(&s
->c
, &b
->state
[0][16 + 1 + 3 + quant3bA
[l
&0xFF] + 3*quant3bA
[t
&0xFF]]);
1762 if(runs
-- > 0) run
= get_symbol2(&s
->c
, b
->state
[1], 3);
1764 v
= 2*(get_symbol2(&s
->c
, b
->state
[0 + 2], 0-4) + 1);
1765 v
+=get_rac(&s
->c
, &b
->state
[0][16 + 1 + 3]);
1774 if(y
) max_run
= FFMIN(run
, prev_xc
->x
- x
- 2);
1775 else max_run
= FFMIN(run
, w
-x
-1);
1777 max_run
= FFMIN(max_run
, 2*parent_xc
->x
- x
- 1);
1783 (xc
++)->x
= w
+1; //end marker
1789 while(parent_xc
->x
!= parent
->width
+1)
1792 prev_parent_xc
= parent_xc
;
1794 parent_xc
= prev_parent_xc
;
1799 (xc
++)->x
= w
+1; //end marker
1803 static inline void decode_subband_slice_buffered(SnowContext
*s
, SubBand
*b
, slice_buffer
* sb
, int start_y
, int h
, int save_state
[1]){
1804 const int w
= b
->width
;
1806 const int qlog
= clip(s
->qlog
+ b
->qlog
, 0, QROOT
*16);
1807 int qmul
= qexp
[qlog
&(QROOT
-1)]<<(qlog
>>QSHIFT
);
1808 int qadd
= (s
->qbias
*qmul
)>>QBIAS_SHIFT
;
1813 if(b
->buf
== s
->spatial_dwt_buffer
|| s
->qlog
== LOSSLESS_QLOG
){
1818 /* If we are on the second or later slice, restore our index. */
1820 new_index
= save_state
[0];
1823 for(y
=start_y
; y
<h
; y
++){
1826 DWTELEM
* line
= slice_buffer_get_line(sb
, y
* b
->stride_line
+ b
->buf_y_offset
) + b
->buf_x_offset
;
1827 memset(line
, 0, b
->width
*sizeof(DWTELEM
));
1828 v
= b
->x_coeff
[new_index
].coeff
;
1829 x
= b
->x_coeff
[new_index
++].x
;
1832 register int t
= ( (v
>>1)*qmul
+ qadd
)>>QEXPSHIFT
;
1833 register int u
= -(v
&1);
1834 line
[x
] = (t
^u
) - u
;
1836 v
= b
->x_coeff
[new_index
].coeff
;
1837 x
= b
->x_coeff
[new_index
++].x
;
1840 if(w
> 200 && start_y
!= 0/*level+1 == s->spatial_decomposition_count*/){
1841 STOP_TIMER("decode_subband")
1844 /* Save our variables for the next slice. */
1845 save_state
[0] = new_index
;
1850 static void reset_contexts(SnowContext
*s
){
1851 int plane_index
, level
, orientation
;
1853 for(plane_index
=0; plane_index
<3; plane_index
++){
1854 for(level
=0; level
<s
->spatial_decomposition_count
; level
++){
1855 for(orientation
=level ?
1:0; orientation
<4; orientation
++){
1856 memset(s
->plane
[plane_index
].band
[level
][orientation
].state
, MID_STATE
, sizeof(s
->plane
[plane_index
].band
[level
][orientation
].state
));
1860 memset(s
->header_state
, MID_STATE
, sizeof(s
->header_state
));
1861 memset(s
->block_state
, MID_STATE
, sizeof(s
->block_state
));
1864 static int alloc_blocks(SnowContext
*s
){
1865 int w
= -((-s
->avctx
->width
)>>LOG2_MB_SIZE
);
1866 int h
= -((-s
->avctx
->height
)>>LOG2_MB_SIZE
);
1871 s
->block
= av_mallocz(w
* h
* sizeof(BlockNode
) << (s
->block_max_depth
*2));
1875 static inline void copy_rac_state(RangeCoder
*d
, RangeCoder
*s
){
1876 uint8_t *bytestream
= d
->bytestream
;
1877 uint8_t *bytestream_start
= d
->bytestream_start
;
1879 d
->bytestream
= bytestream
;
1880 d
->bytestream_start
= bytestream_start
;
1883 //near copy & paste from dsputil, FIXME
1884 static int pix_sum(uint8_t * pix
, int line_size
, int w
)
1889 for (i
= 0; i
< w
; i
++) {
1890 for (j
= 0; j
< w
; j
++) {
1894 pix
+= line_size
- w
;
1899 //near copy & paste from dsputil, FIXME
1900 static int pix_norm1(uint8_t * pix
, int line_size
, int w
)
1903 uint32_t *sq
= squareTbl
+ 256;
1906 for (i
= 0; i
< w
; i
++) {
1907 for (j
= 0; j
< w
; j
++) {
1911 pix
+= line_size
- w
;
1916 static inline void set_blocks(SnowContext
*s
, int level
, int x
, int y
, int l
, int cb
, int cr
, int mx
, int my
, int ref
, int type
){
1917 const int w
= s
->b_width
<< s
->block_max_depth
;
1918 const int rem_depth
= s
->block_max_depth
- level
;
1919 const int index
= (x
+ y
*w
) << rem_depth
;
1920 const int block_w
= 1<<rem_depth
;
1933 for(j
=0; j
<block_w
; j
++){
1934 for(i
=0; i
<block_w
; i
++){
1935 s
->block
[index
+ i
+ j
*w
]= block
;
1940 static inline void init_ref(MotionEstContext
*c
, uint8_t *src
[3], uint8_t *ref
[3], uint8_t *ref2
[3], int x
, int y
, int ref_index
){
1941 const int offset
[3]= {
1943 ((y
*c
->uvstride
+ x
)>>1),
1944 ((y
*c
->uvstride
+ x
)>>1),
1948 c
->src
[0][i
]= src
[i
];
1949 c
->ref
[0][i
]= ref
[i
] + offset
[i
];
1954 static inline void pred_mv(SnowContext
*s
, int *mx
, int *my
, int ref
,
1955 BlockNode
*left
, BlockNode
*top
, BlockNode
*tr
){
1956 if(s
->ref_frames
== 1){
1957 *mx
= mid_pred(left
->mx
, top
->mx
, tr
->mx
);
1958 *my
= mid_pred(left
->my
, top
->my
, tr
->my
);
1960 const int *scale
= scale_mv_ref
[ref
];
1961 *mx
= mid_pred(left
->mx
* scale
[left
->ref
] + 128 >>8,
1962 top
->mx
* scale
[top
->ref
] + 128 >>8,
1963 tr
->mx
* scale
[tr
->ref
] + 128 >>8);
1964 *my
= mid_pred(left
->my
* scale
[left
->ref
] + 128 >>8,
1965 top
->my
* scale
[top
->ref
] + 128 >>8,
1966 tr
->my
* scale
[tr
->ref
] + 128 >>8);
1973 #define P_TOPRIGHT P[3]
1974 #define P_MEDIAN P[4]
1976 #define FLAG_QPEL 1 //must be 1
1978 static int encode_q_branch(SnowContext
*s
, int level
, int x
, int y
){
1979 uint8_t p_buffer
[1024];
1980 uint8_t i_buffer
[1024];
1981 uint8_t p_state
[sizeof(s
->block_state
)];
1982 uint8_t i_state
[sizeof(s
->block_state
)];
1984 uint8_t *pbbak
= s
->c
.bytestream
;
1985 uint8_t *pbbak_start
= s
->c
.bytestream_start
;
1986 int score
, score2
, iscore
, i_len
, p_len
, block_s
, sum
;
1987 const int w
= s
->b_width
<< s
->block_max_depth
;
1988 const int h
= s
->b_height
<< s
->block_max_depth
;
1989 const int rem_depth
= s
->block_max_depth
- level
;
1990 const int index
= (x
+ y
*w
) << rem_depth
;
1991 const int block_w
= 1<<(LOG2_MB_SIZE
- level
);
1992 int trx
= (x
+1)<<rem_depth
;
1993 int try= (y
+1)<<rem_depth
;
1994 BlockNode
*left
= x ?
&s
->block
[index
-1] : &null_block
;
1995 BlockNode
*top
= y ?
&s
->block
[index
-w
] : &null_block
;
1996 BlockNode
*right
= trx
<w ?
&s
->block
[index
+1] : &null_block
;
1997 BlockNode
*bottom
= try<h ?
&s
->block
[index
+w
] : &null_block
;
1998 BlockNode
*tl
= y
&& x ?
&s
->block
[index
-w
-1] : left
;
1999 BlockNode
*tr
= y
&& trx
<w
&& ((x
&1)==0 || level
==0) ?
&s
->block
[index
-w
+(1<<rem_depth
)] : tl
; //FIXME use lt
2000 int pl
= left
->color
[0];
2001 int pcb
= left
->color
[1];
2002 int pcr
= left
->color
[2];
2006 const int stride
= s
->current_picture
.linesize
[0];
2007 const int uvstride
= s
->current_picture
.linesize
[1];
2008 uint8_t *current_data
[3]= { s
->input_picture
.data
[0] + (x
+ y
* stride
)*block_w
,
2009 s
->input_picture
.data
[1] + (x
+ y
*uvstride
)*block_w
/2,
2010 s
->input_picture
.data
[2] + (x
+ y
*uvstride
)*block_w
/2};
2012 int16_t last_mv
[3][2];
2013 int qpel
= !!(s
->avctx
->flags
& CODEC_FLAG_QPEL
); //unused
2014 const int shift
= 1+qpel
;
2015 MotionEstContext
*c
= &s
->m
.me
;
2016 int ref_context
= av_log2(2*left
->ref
) + av_log2(2*top
->ref
);
2017 int mx_context
= av_log2(2*ABS(left
->mx
- top
->mx
));
2018 int my_context
= av_log2(2*ABS(left
->my
- top
->my
));
2019 int s_context
= 2*left
->level
+ 2*top
->level
+ tl
->level
+ tr
->level
;
2020 int ref
, best_ref
, ref_score
, ref_mx
, ref_my
;
2022 assert(sizeof(s
->block_state
) >= 256);
2024 set_blocks(s
, level
, x
, y
, pl
, pcb
, pcr
, 0, 0, 0, BLOCK_INTRA
);
2028 // clip predictors / edge ?
2030 P_LEFT
[0]= left
->mx
;
2031 P_LEFT
[1]= left
->my
;
2034 P_TOPRIGHT
[0]= tr
->mx
;
2035 P_TOPRIGHT
[1]= tr
->my
;
2037 last_mv
[0][0]= s
->block
[index
].mx
;
2038 last_mv
[0][1]= s
->block
[index
].my
;
2039 last_mv
[1][0]= right
->mx
;
2040 last_mv
[1][1]= right
->my
;
2041 last_mv
[2][0]= bottom
->mx
;
2042 last_mv
[2][1]= bottom
->my
;
2049 assert(s
->m
.me
. stride
== stride
);
2050 assert(s
->m
.me
.uvstride
== uvstride
);
2052 c
->penalty_factor
= get_penalty_factor(s
->lambda
, s
->lambda2
, c
->avctx
->me_cmp
);
2053 c
->sub_penalty_factor
= get_penalty_factor(s
->lambda
, s
->lambda2
, c
->avctx
->me_sub_cmp
);
2054 c
->mb_penalty_factor
= get_penalty_factor(s
->lambda
, s
->lambda2
, c
->avctx
->mb_cmp
);
2055 c
->current_mv_penalty
= c
->mv_penalty
[s
->m
.f_code
=1] + MAX_MV
;
2057 c
->xmin
= - x
*block_w
- 16+2;
2058 c
->ymin
= - y
*block_w
- 16+2;