2 * Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at>
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "rangecoder.h"
28 #include "mpegvideo.h"
33 static const int8_t quant3
[256]={
34 0, 0, 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,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
46 -1,-1,-1,-1,-1,-1,-1,-1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1, 1, 0, 0, 0, 0, 0,
182 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,
183 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,
184 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,
185 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,
186 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,
187 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,
188 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,
189 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,
190 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,
191 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,
192 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,
193 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,
194 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,
195 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,
196 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,
197 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,
198 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,
199 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,
200 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,
201 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,
202 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,
203 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,
204 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,
205 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,
206 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,
207 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,
208 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,
209 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,
210 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,
211 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,
214 static const uint8_t obmc16
[256]={
215 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
216 0, 1, 1, 2, 4, 5, 5, 6, 6, 5, 5, 4, 2, 1, 1, 0,
217 0, 1, 4, 6, 9,11,13,15,15,13,11, 9, 6, 4, 1, 0,
218 0, 2, 6,11,15,20,24,26,26,24,20,15,11, 6, 2, 0,
219 0, 4, 9,15,23,29,34,38,38,34,29,23,15, 9, 4, 0,
220 0, 5,11,20,29,38,45,49,49,45,38,29,20,11, 5, 0,
221 1, 5,13,24,34,45,53,57,57,53,45,34,24,13, 5, 1,
222 1, 6,15,26,38,49,57,62,62,57,49,38,26,15, 6, 1,
223 1, 6,15,26,38,49,57,62,62,57,49,38,26,15, 6, 1,
224 1, 5,13,24,34,45,53,57,57,53,45,34,24,13, 5, 1,
225 0, 5,11,20,29,38,45,49,49,45,38,29,20,11, 5, 0,
226 0, 4, 9,15,23,29,34,38,38,34,29,23,15, 9, 4, 0,
227 0, 2, 6,11,15,20,24,26,26,24,20,15,11, 6, 2, 0,
228 0, 1, 4, 6, 9,11,13,15,15,13,11, 9, 6, 4, 1, 0,
229 0, 1, 1, 2, 4, 5, 5, 6, 6, 5, 5, 4, 2, 1, 1, 0,
230 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
234 static const uint8_t obmc32
[1024]={
235 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,
236 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,
237 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,
238 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,
239 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,
240 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,
241 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,
242 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,
243 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,
244 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,
245 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,
246 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,
247 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,
248 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,
249 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,
250 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,
251 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,
252 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,
253 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,
254 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,
255 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,
256 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,
257 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,
258 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,
259 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,
260 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,
261 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,
262 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,
263 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,
264 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,
265 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,
266 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,
269 static const uint8_t obmc16
[256]={
270 0, 4, 4, 8, 8, 12, 12, 16, 16, 12, 12, 8, 8, 4, 4, 0,
271 4, 8, 16, 20, 28, 32, 40, 44, 44, 40, 32, 28, 20, 16, 8, 4,
272 4, 16, 24, 36, 44, 56, 64, 76, 76, 64, 56, 44, 36, 24, 16, 4,
273 8, 20, 36, 48, 64, 76, 92,104,104, 92, 76, 64, 48, 36, 20, 8,
274 8, 28, 44, 64, 80,100,116,136,136,116,100, 80, 64, 44, 28, 8,
275 12, 32, 56, 76,100,120,144,164,164,144,120,100, 76, 56, 32, 12,
276 12, 40, 64, 92,116,144,168,196,196,168,144,116, 92, 64, 40, 12,
277 16, 44, 76,104,136,164,196,224,224,196,164,136,104, 76, 44, 16,
278 16, 44, 76,104,136,164,196,224,224,196,164,136,104, 76, 44, 16,
279 12, 40, 64, 92,116,144,168,196,196,168,144,116, 92, 64, 40, 12,
280 12, 32, 56, 76,100,120,144,164,164,144,120,100, 76, 56, 32, 12,
281 8, 28, 44, 64, 80,100,116,136,136,116,100, 80, 64, 44, 28, 8,
282 8, 20, 36, 48, 64, 76, 92,104,104, 92, 76, 64, 48, 36, 20, 8,
283 4, 16, 24, 36, 44, 56, 64, 76, 76, 64, 56, 44, 36, 24, 16, 4,
284 4, 8, 16, 20, 28, 32, 40, 44, 44, 40, 32, 28, 20, 16, 8, 4,
285 0, 4, 4, 8, 8, 12, 12, 16, 16, 12, 12, 8, 8, 4, 4, 0,
289 static const uint8_t obmc32
[1024]={
290 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,
291 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,
292 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,
293 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,
294 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,
295 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,
296 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,
297 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,
298 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,
299 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,
300 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,
301 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,
302 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,
303 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,
304 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,
305 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,
306 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,
307 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,
308 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,
309 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,
310 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,
311 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,
312 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,
313 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,
314 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,
315 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,
316 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,
317 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,
318 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,
319 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,
320 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,
321 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,
324 static const uint8_t obmc16
[256]={
325 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
326 0, 0, 1, 2, 3, 4, 5, 5, 5, 5, 4, 3, 2, 1, 0, 0,
327 0, 1, 3, 6, 8,11,13,14,14,13,11, 8, 6, 3, 1, 0,
328 0, 2, 6,10,15,20,24,26,26,24,20,15,10, 6, 2, 0,
329 0, 3, 8,16,23,30,35,38,38,35,30,23,16, 8, 3, 0,
330 1, 4,11,20,30,39,46,49,49,46,39,30,20,11, 4, 1,
331 1, 5,13,24,35,46,54,58,58,54,46,35,24,13, 5, 1,
332 0, 5,14,26,38,49,58,63,63,58,49,38,26,14, 5, 0,
333 0, 5,14,26,38,49,58,63,63,58,49,38,26,14, 5, 0,
334 1, 5,13,24,35,46,54,58,58,54,46,35,24,13, 5, 1,
335 1, 4,11,20,30,39,46,49,49,46,39,30,20,11, 4, 1,
336 0, 3, 8,16,23,30,35,38,38,35,30,23,16, 8, 3, 0,
337 0, 2, 6,10,15,20,24,26,26,24,20,15,10, 6, 2, 0,
338 0, 1, 3, 6, 8,11,13,14,14,13,11, 8, 6, 3, 1, 0,
339 0, 0, 1, 2, 3, 4, 5, 5, 5, 5, 4, 3, 2, 1, 0, 0,
340 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
346 static const uint8_t obmc8
[64]={
347 4, 12, 20, 28, 28, 20, 12, 4,
348 12, 36, 60, 84, 84, 60, 36, 12,
349 20, 60,100,140,140,100, 60, 20,
350 28, 84,140,196,196,140, 84, 28,
351 28, 84,140,196,196,140, 84, 28,
352 20, 60,100,140,140,100, 60, 20,
353 12, 36, 60, 84, 84, 60, 36, 12,
354 4, 12, 20, 28, 28, 20, 12, 4,
359 static const uint8_t obmc4
[16]={
367 static const uint8_t *obmc_tab
[4]={
368 obmc32
, obmc16
, obmc8
, obmc4
371 static int scale_mv_ref
[MAX_REF_FRAMES
][MAX_REF_FRAMES
];
373 typedef struct BlockNode
{
379 //#define TYPE_SPLIT 1
380 #define BLOCK_INTRA 1
382 //#define TYPE_NOCOLOR 4
383 uint8_t level
; //FIXME merge into type?
386 static const BlockNode null_block
= { //FIXME add border maybe
387 .color
= {128,128,128},
395 #define LOG2_MB_SIZE 4
396 #define MB_SIZE (1<<LOG2_MB_SIZE)
398 typedef struct x_and_coeff
{
403 typedef struct SubBand
{
408 int qlog
; ///< log(qscale)/log[2^(1/6)]
412 int stride_line
; ///< Stride measured in lines, not pixels.
413 x_and_coeff
* x_coeff
;
414 struct SubBand
*parent
;
415 uint8_t state
[/*7*2*/ 7 + 512][32];
418 typedef struct Plane
{
421 SubBand band
[MAX_DECOMPOSITIONS
][4];
424 typedef struct SnowContext
{
425 // 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)
427 AVCodecContext
*avctx
;
431 AVFrame input_picture
; ///< new_picture with the internal linesizes
432 AVFrame current_picture
;
433 AVFrame last_picture
[MAX_REF_FRAMES
];
434 AVFrame mconly_picture
;
435 // uint8_t q_context[16];
436 uint8_t header_state
[32];
437 uint8_t block_state
[128 + 32*128];
441 int spatial_decomposition_type
;
442 int temporal_decomposition_type
;
443 int spatial_decomposition_count
;
444 int temporal_decomposition_count
;
447 int16_t (*ref_mvs
[MAX_REF_FRAMES
])[2];
448 uint32_t *ref_scores
[MAX_REF_FRAMES
];
449 DWTELEM
*spatial_dwt_buffer
;
453 int spatial_scalability
;
460 #define QBIAS_SHIFT 3
464 Plane plane
[MAX_PLANES
];
466 #define ME_CACHE_SIZE 1024
467 int me_cache
[ME_CACHE_SIZE
];
468 int me_cache_generation
;
471 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)
482 #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)))
483 //#define slice_buffer_get_line(slice_buf, line_num) (slice_buffer_load_line((slice_buf), (line_num)))
485 static void iterative_me(SnowContext
*s
);
487 static void slice_buffer_init(slice_buffer
* buf
, int line_count
, int max_allocated_lines
, int line_width
, DWTELEM
* base_buffer
)
491 buf
->base_buffer
= base_buffer
;
492 buf
->line_count
= line_count
;
493 buf
->line_width
= line_width
;
494 buf
->data_count
= max_allocated_lines
;
495 buf
->line
= (DWTELEM
* *) av_mallocz (sizeof(DWTELEM
*) * line_count
);
496 buf
->data_stack
= (DWTELEM
* *) av_malloc (sizeof(DWTELEM
*) * max_allocated_lines
);
498 for (i
= 0; i
< max_allocated_lines
; i
++)
500 buf
->data_stack
[i
] = (DWTELEM
*) av_malloc (sizeof(DWTELEM
) * line_width
);
503 buf
->data_stack_top
= max_allocated_lines
- 1;
506 static DWTELEM
* slice_buffer_load_line(slice_buffer
* buf
, int line
)
511 // av_log(NULL, AV_LOG_DEBUG, "Cache hit: %d\n", line);
513 assert(buf
->data_stack_top
>= 0);
514 // assert(!buf->line[line]);
516 return buf
->line
[line
];
518 offset
= buf
->line_width
* line
;
519 buffer
= buf
->data_stack
[buf
->data_stack_top
];
520 buf
->data_stack_top
--;
521 buf
->line
[line
] = buffer
;
523 // av_log(NULL, AV_LOG_DEBUG, "slice_buffer_load_line: line: %d remaining: %d\n", line, buf->data_stack_top + 1);
528 static void slice_buffer_release(slice_buffer
* buf
, int line
)
533 assert(line
>= 0 && line
< buf
->line_count
);
534 assert(buf
->line
[line
]);
536 offset
= buf
->line_width
* line
;
537 buffer
= buf
->line
[line
];
538 buf
->data_stack_top
++;
539 buf
->data_stack
[buf
->data_stack_top
] = buffer
;
540 buf
->line
[line
] = NULL
;
542 // av_log(NULL, AV_LOG_DEBUG, "slice_buffer_release: line: %d remaining: %d\n", line, buf->data_stack_top + 1);
545 static void slice_buffer_flush(slice_buffer
* buf
)
548 for (i
= 0; i
< buf
->line_count
; i
++)
552 // av_log(NULL, AV_LOG_DEBUG, "slice_buffer_flush: line: %d \n", i);
553 slice_buffer_release(buf
, i
);
558 static void slice_buffer_destroy(slice_buffer
* buf
)
561 slice_buffer_flush(buf
);
563 for (i
= buf
->data_count
- 1; i
>= 0; i
--)
565 assert(buf
->data_stack
[i
]);
566 av_freep(&buf
->data_stack
[i
]);
568 assert(buf
->data_stack
);
569 av_freep(&buf
->data_stack
);
571 av_freep(&buf
->line
);
575 // Avoid a name clash on SGI IRIX
578 #define QEXPSHIFT (7-FRAC_BITS+8) //FIXME try to change this to 0
579 static uint8_t qexp
[QROOT
];
581 static inline int mirror(int v
, int m
){
582 while((unsigned)v
> (unsigned)m
){
589 static inline void put_symbol(RangeCoder
*c
, uint8_t *state
, int v
, int is_signed
){
593 const int a
= FFABS(v
);
594 const int e
= av_log2(a
);
596 const int el
= FFMIN(e
, 10);
597 put_rac(c
, state
+0, 0);
600 put_rac(c
, state
+1+i
, 1); //1..10
603 put_rac(c
, state
+1+9, 1); //1..10
605 put_rac(c
, state
+1+FFMIN(i
,9), 0);
607 for(i
=e
-1; i
>=el
; i
--){
608 put_rac(c
, state
+22+9, (a
>>i
)&1); //22..31
611 put_rac(c
, state
+22+i
, (a
>>i
)&1); //22..31
615 put_rac(c
, state
+11 + el
, v
< 0); //11..21
618 put_rac(c
, state
+0, 0);
621 put_rac(c
, state
+1+i
, 1); //1..10
623 put_rac(c
, state
+1+i
, 0);
625 for(i
=e
-1; i
>=0; i
--){
626 put_rac(c
, state
+22+i
, (a
>>i
)&1); //22..31
630 put_rac(c
, state
+11 + e
, v
< 0); //11..21
633 put_rac(c
, state
+1+FFMIN(i
,9), 1); //1..10
635 put_rac(c
, state
+1+FFMIN(i
,9), 0);
637 for(i
=e
-1; i
>=0; i
--){
638 put_rac(c
, state
+22+FFMIN(i
,9), (a
>>i
)&1); //22..31
642 put_rac(c
, state
+11 + FFMIN(e
,10), v
< 0); //11..21
646 put_rac(c
, state
+0, 1);
650 static inline int get_symbol(RangeCoder
*c
, uint8_t *state
, int is_signed
){
651 if(get_rac(c
, state
+0))
656 while(get_rac(c
, state
+1 + FFMIN(e
,9))){ //1..10
661 for(i
=e
-1; i
>=0; i
--){
662 a
+= a
+ get_rac(c
, state
+22 + FFMIN(i
,9)); //22..31
665 if(is_signed
&& get_rac(c
, state
+11 + FFMIN(e
,10))) //11..21
672 static inline void put_symbol2(RangeCoder
*c
, uint8_t *state
, int v
, int log2
){
674 int r
= log2
>=0 ?
1<<log2
: 1;
680 put_rac(c
, state
+4+log2
, 1);
685 put_rac(c
, state
+4+log2
, 0);
687 for(i
=log2
-1; i
>=0; i
--){
688 put_rac(c
, state
+31-i
, (v
>>i
)&1);
692 static inline int get_symbol2(RangeCoder
*c
, uint8_t *state
, int log2
){
694 int r
= log2
>=0 ?
1<<log2
: 1;
699 while(get_rac(c
, state
+4+log2
)){
705 for(i
=log2
-1; i
>=0; i
--){
706 v
+= get_rac(c
, state
+31-i
)<<i
;
712 static av_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
){
713 const int mirror_left
= !highpass
;
714 const int mirror_right
= (width
&1) ^ highpass
;
715 const int w
= (width
>>1) - 1 + (highpass
& width
);
718 #define LIFT(src, ref, inv) ((src) + ((inv) ? - (ref) : + (ref)))
720 dst
[0] = LIFT(src
[0], ((mul
*2*ref
[0]+add
)>>shift
), inverse
);
726 dst
[i
*dst_step
] = LIFT(src
[i
*src_step
], ((mul
*(ref
[i
*ref_step
] + ref
[(i
+1)*ref_step
])+add
)>>shift
), inverse
);
730 dst
[w
*dst_step
] = LIFT(src
[w
*src_step
], ((mul
*2*ref
[w
*ref_step
]+add
)>>shift
), inverse
);
735 static av_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
){
736 const int mirror_left
= !highpass
;
737 const int mirror_right
= (width
&1) ^ highpass
;
738 const int w
= (width
>>1) - 1 + (highpass
& width
);
745 dst
[0] = LIFT(src
[0], ((r
+add
)>>shift
), inverse
);
751 int r
= 3*(ref
[i
*ref_step
] + ref
[(i
+1)*ref_step
]);
754 dst
[i
*dst_step
] = LIFT(src
[i
*src_step
], ((r
+add
)>>shift
), inverse
);
758 int r
= 3*2*ref
[w
*ref_step
];
761 dst
[w
*dst_step
] = LIFT(src
[w
*src_step
], ((r
+add
)>>shift
), inverse
);
767 static av_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
){
768 const int mirror_left
= !highpass
;
769 const int mirror_right
= (width
&1) ^ highpass
;
770 const int w
= (width
>>1) - 1 + (highpass
& width
);
774 #define LIFTS(src, ref, inv) ((inv) ? (src) - (((ref) - 4*(src))>>shift): (16*4*(src) + 4*(ref) + 8 + (5<<27))/(5*16) - (1<<23))
776 dst
[0] = LIFTS(src
[0], mul
*2*ref
[0]+add
, inverse
);
782 dst
[i
*dst_step
] = LIFTS(src
[i
*src_step
], mul
*(ref
[i
*ref_step
] + ref
[(i
+1)*ref_step
])+add
, inverse
);
786 dst
[w
*dst_step
] = LIFTS(src
[w
*src_step
], mul
*2*ref
[w
*ref_step
]+add
, inverse
);
792 static void inplace_lift(DWTELEM
*dst
, int width
, int *coeffs
, int n
, int shift
, int start
, int inverse
){
795 for(x
=start
; x
<width
; x
+=2){
799 int x2
= x
+ 2*i
- n
+ 1;
801 else if(x2
>=width
) x2
= 2*width
-x2
-2;
802 sum
+= coeffs
[i
]*(int64_t)dst
[x2
];
804 if(inverse
) dst
[x
] -= (sum
+ (1<<shift
)/2)>>shift
;
805 else dst
[x
] += (sum
+ (1<<shift
)/2)>>shift
;
809 static void inplace_liftV(DWTELEM
*dst
, int width
, int height
, int stride
, int *coeffs
, int n
, int shift
, int start
, int inverse
){
811 for(y
=start
; y
<height
; y
+=2){
812 for(x
=0; x
<width
; x
++){
816 int y2
= y
+ 2*i
- n
+ 1;
818 else if(y2
>=height
) y2
= 2*height
-y2
-2;
819 sum
+= coeffs
[i
]*(int64_t)dst
[x
+ y2
*stride
];
821 if(inverse
) dst
[x
+ y
*stride
] -= (sum
+ (1<<shift
)/2)>>shift
;
822 else dst
[x
+ y
*stride
] += (sum
+ (1<<shift
)/2)>>shift
;
831 #if 0 // more accurate 9/7
834 #define COEFFS1 (int[]){-25987,-25987}
837 #define COEFFS2 (int[]){-27777,-27777}
840 #define COEFFS3 (int[]){28931,28931}
843 #define COEFFS4 (int[]){14533,14533}
847 #define COEFFS1 (int[]){1,-9,-9,1}
850 #define COEFFS2 (int[]){-1,5,5,-1}
863 #define COEFFS1 (int[]){1,1}
866 #define COEFFS2 (int[]){-1,-1}
879 #define COEFFS2 (int[]){-1,-1}
882 #define COEFFS3 (int[]){-1,-1}
885 #define COEFFS4 (int[]){-5,29,29,-5}
890 #define COEFFS1 (int[]){-203,-203}
893 #define COEFFS2 (int[]){-217,-217}
896 #define COEFFS3 (int[]){113,113}
899 #define COEFFS4 (int[]){227,227}
907 #define COEFFS2 (int[]){-1,-1}
910 #define COEFFS3 (int[]){-1,-1}
913 #define COEFFS4 (int[]){3,3}
917 #define COEFFS1 (int[]){1,-9,-9,1}
920 #define COEFFS2 (int[]){1,1}
930 #define COEFFS1 (int[]){1,-9,-9,1}
933 #define COEFFS2 (int[]){-1,5,5,-1}
941 static void horizontal_decomposeX(DWTELEM
*b
, int width
){
943 const int width2
= width
>>1;
944 const int w2
= (width
+1)>>1;
947 inplace_lift(b
, width
, COEFFS1
, N1
, SHIFT1
, LX1
, 0);
948 inplace_lift(b
, width
, COEFFS2
, N2
, SHIFT2
, LX0
, 0);
949 inplace_lift(b
, width
, COEFFS3
, N3
, SHIFT3
, LX1
, 0);
950 inplace_lift(b
, width
, COEFFS4
, N4
, SHIFT4
, LX0
, 0);
952 for(x
=0; x
<width2
; x
++){
954 temp
[x
+w2
]= b
[2*x
+ 1];
958 memcpy(b
, temp
, width
*sizeof(int));
961 static void horizontal_composeX(DWTELEM
*b
, int width
){
963 const int width2
= width
>>1;
965 const int w2
= (width
+1)>>1;
967 memcpy(temp
, b
, width
*sizeof(int));
968 for(x
=0; x
<width2
; x
++){
970 b
[2*x
+ 1]= temp
[x
+w2
];
975 inplace_lift(b
, width
, COEFFS4
, N4
, SHIFT4
, LX0
, 1);
976 inplace_lift(b
, width
, COEFFS3
, N3
, SHIFT3
, LX1
, 1);
977 inplace_lift(b
, width
, COEFFS2
, N2
, SHIFT2
, LX0
, 1);
978 inplace_lift(b
, width
, COEFFS1
, N1
, SHIFT1
, LX1
, 1);
981 static void spatial_decomposeX(DWTELEM
*buffer
, int width
, int height
, int stride
){
984 for(y
=0; y
<height
; y
++){
985 for(x
=0; x
<width
; x
++){
986 buffer
[y
*stride
+ x
] *= SCALEX
;
990 for(y
=0; y
<height
; y
++){
991 horizontal_decomposeX(buffer
+ y
*stride
, width
);
994 inplace_liftV(buffer
, width
, height
, stride
, COEFFS1
, N1
, SHIFT1
, LX1
, 0);
995 inplace_liftV(buffer
, width
, height
, stride
, COEFFS2
, N2
, SHIFT2
, LX0
, 0);
996 inplace_liftV(buffer
, width
, height
, stride
, COEFFS3
, N3
, SHIFT3
, LX1
, 0);
997 inplace_liftV(buffer
, width
, height
, stride
, COEFFS4
, N4
, SHIFT4
, LX0
, 0);
1000 static void spatial_composeX(DWTELEM
*buffer
, int width
, int height
, int stride
){
1003 inplace_liftV(buffer
, width
, height
, stride
, COEFFS4
, N4
, SHIFT4
, LX0
, 1);
1004 inplace_liftV(buffer
, width
, height
, stride
, COEFFS3
, N3
, SHIFT3
, LX1
, 1);
1005 inplace_liftV(buffer
, width
, height
, stride
, COEFFS2
, N2
, SHIFT2
, LX0
, 1);
1006 inplace_liftV(buffer
, width
, height
, stride
, COEFFS1
, N1
, SHIFT1
, LX1
, 1);
1008 for(y
=0; y
<height
; y
++){
1009 horizontal_composeX(buffer
+ y
*stride
, width
);
1012 for(y
=0; y
<height
; y
++){
1013 for(x
=0; x
<width
; x
++){
1014 buffer
[y
*stride
+ x
] /= SCALEX
;
1019 static void horizontal_decompose53i(DWTELEM
*b
, int width
){
1020 DWTELEM temp
[width
];
1021 const int width2
= width
>>1;
1023 const int w2
= (width
+1)>>1;
1025 for(x
=0; x
<width2
; x
++){
1027 temp
[x
+w2
]= b
[2*x
+ 1];
1041 for(x
=1; x
+1<width2
; x
+=2){
1045 A2
+= (A1
+ A3
+ 2)>>2;
1049 A1
= temp
[x
+1+width2
];
1052 A4
+= (A1
+ A3
+ 2)>>2;
1058 A2
+= (A1
+ A3
+ 2)>>2;
1063 lift(b
+w2
, temp
+w2
, temp
, 1, 1, 1, width
, -1, 0, 1, 1, 0);
1064 lift(b
, temp
, b
+w2
, 1, 1, 1, width
, 1, 2, 2, 0, 0);
1068 static void vertical_decompose53iH0(DWTELEM
*b0
, DWTELEM
*b1
, DWTELEM
*b2
, int width
){
1071 for(i
=0; i
<width
; i
++){
1072 b1
[i
] -= (b0
[i
] + b2
[i
])>>1;
1076 static void vertical_decompose53iL0(DWTELEM
*b0
, DWTELEM
*b1
, DWTELEM
*b2
, int width
){
1079 for(i
=0; i
<width
; i
++){
1080 b1
[i
] += (b0
[i
] + b2
[i
] + 2)>>2;
1084 static void spatial_decompose53i(DWTELEM
*buffer
, int width
, int height
, int stride
){
1086 DWTELEM
*b0
= buffer
+ mirror(-2-1, height
-1)*stride
;
1087 DWTELEM
*b1
= buffer
+ mirror(-2 , height
-1)*stride
;
1089 for(y
=-2; y
<height
; y
+=2){
1090 DWTELEM
*b2
= buffer
+ mirror(y
+1, height
-1)*stride
;
1091 DWTELEM
*b3
= buffer
+ mirror(y
+2, height
-1)*stride
;
1094 if(y
+1<(unsigned)height
) horizontal_decompose53i(b2
, width
);
1095 if(y
+2<(unsigned)height
) horizontal_decompose53i(b3
, width
);
1096 STOP_TIMER("horizontal_decompose53i")}
1099 if(y
+1<(unsigned)height
) vertical_decompose53iH0(b1
, b2
, b3
, width
);
1100 if(y
+0<(unsigned)height
) vertical_decompose53iL0(b0
, b1
, b2
, width
);
1101 STOP_TIMER("vertical_decompose53i*")}
1108 static void horizontal_decompose97i(DWTELEM
*b
, int width
){
1109 DWTELEM temp
[width
];
1110 const int w2
= (width
+1)>>1;
1112 lift (temp
+w2
, b
+1, b
, 1, 2, 2, width
, -W_AM
, W_AO
, W_AS
, 1, 0);
1113 liftS(temp
, b
, temp
+w2
, 1, 2, 1, width
, -W_BM
, W_BO
, W_BS
, 0, 0);
1114 lift5(b
+w2
, temp
+w2
, temp
, 1, 1, 1, width
, W_CM
, W_CO
, W_CS
, 1, 0);
1115 lift (b
, temp
, b
+w2
, 1, 1, 1, width
, W_DM
, W_DO
, W_DS
, 0, 0);
1119 static void vertical_decompose97iH0(DWTELEM
*b0
, DWTELEM
*b1
, DWTELEM
*b2
, int width
){
1122 for(i
=0; i
<width
; i
++){
1123 b1
[i
] -= (W_AM
*(b0
[i
] + b2
[i
])+W_AO
)>>W_AS
;
1127 static void vertical_decompose97iH1(DWTELEM
*b0
, DWTELEM
*b1
, DWTELEM
*b2
, int width
){
1130 for(i
=0; i
<width
; i
++){
1132 b1
[i
] += (W_CM
*(b0
[i
] + b2
[i
])+W_CO
)>>W_CS
;
1134 int r
= 3*(b0
[i
] + b2
[i
]);
1137 b1
[i
] += (r
+W_CO
)>>W_CS
;
1142 static void vertical_decompose97iL0(DWTELEM
*b0
, DWTELEM
*b1
, DWTELEM
*b2
, int width
){
1145 for(i
=0; i
<width
; i
++){
1147 b1
[i
] -= (W_BM
*(b0
[i
] + b2
[i
])+W_BO
)>>W_BS
;
1149 b1
[i
] = (16*4*b1
[i
] - 4*(b0
[i
] + b2
[i
]) + 8*5 + (5<<27)) / (5*16) - (1<<23);
1154 static void vertical_decompose97iL1(DWTELEM
*b0
, DWTELEM
*b1
, DWTELEM
*b2
, int width
){
1157 for(i
=0; i
<width
; i
++){
1158 b1
[i
] += (W_DM
*(b0
[i
] + b2
[i
])+W_DO
)>>W_DS
;
1162 static void spatial_decompose97i(DWTELEM
*buffer
, int width
, int height
, int stride
){
1164 DWTELEM
*b0
= buffer
+ mirror(-4-1, height
-1)*stride
;
1165 DWTELEM
*b1
= buffer
+ mirror(-4 , height
-1)*stride
;
1166 DWTELEM
*b2
= buffer
+ mirror(-4+1, height
-1)*stride
;
1167 DWTELEM
*b3
= buffer
+ mirror(-4+2, height
-1)*stride
;
1169 for(y
=-4; y
<height
; y
+=2){
1170 DWTELEM
*b4
= buffer
+ mirror(y
+3, height
-1)*stride
;
1171 DWTELEM
*b5
= buffer
+ mirror(y
+4, height
-1)*stride
;
1174 if(y
+3<(unsigned)height
) horizontal_decompose97i(b4
, width
);
1175 if(y
+4<(unsigned)height
) horizontal_decompose97i(b5
, width
);
1177 STOP_TIMER("horizontal_decompose97i")
1181 if(y
+3<(unsigned)height
) vertical_decompose97iH0(b3
, b4
, b5
, width
);
1182 if(y
+2<(unsigned)height
) vertical_decompose97iL0(b2
, b3
, b4
, width
);
1183 if(y
+1<(unsigned)height
) vertical_decompose97iH1(b1
, b2
, b3
, width
);
1184 if(y
+0<(unsigned)height
) vertical_decompose97iL1(b0
, b1
, b2
, width
);
1187 STOP_TIMER("vertical_decompose97i")
1197 void ff_spatial_dwt(DWTELEM
*buffer
, int width
, int height
, int stride
, int type
, int decomposition_count
){
1200 for(level
=0; level
<decomposition_count
; level
++){
1202 case DWT_97
: spatial_decompose97i(buffer
, width
>>level
, height
>>level
, stride
<<level
); break;
1203 case DWT_53
: spatial_decompose53i(buffer
, width
>>level
, height
>>level
, stride
<<level
); break;
1204 case DWT_X
: spatial_decomposeX (buffer
, width
>>level
, height
>>level
, stride
<<level
); break;
1209 static void horizontal_compose53i(DWTELEM
*b
, int width
){
1210 DWTELEM temp
[width
];
1211 const int width2
= width
>>1;
1212 const int w2
= (width
+1)>>1;
1224 for(x
=1; x
+1<width2
; x
+=2){
1228 A2
+= (A1
+ A3
+ 2)>>2;
1232 A1
= temp
[x
+1+width2
];
1235 A4
+= (A1
+ A3
+ 2)>>2;
1241 A2
+= (A1
+ A3
+ 2)>>2;
1245 lift(temp
, b
, b
+w2
, 1, 1, 1, width
, 1, 2, 2, 0, 1);
1246 lift(temp
+w2
, b
+w2
, temp
, 1, 1, 1, width
, -1, 0, 1, 1, 1);
1248 for(x
=0; x
<width2
; x
++){
1250 b
[2*x
+ 1]= temp
[x
+w2
];
1256 static void vertical_compose53iH0(DWTELEM
*b0
, DWTELEM
*b1
, DWTELEM
*b2
, int width
){
1259 for(i
=0; i
<width
; i
++){
1260 b1
[i
] += (b0
[i
] + b2
[i
])>>1;
1264 static void vertical_compose53iL0(DWTELEM
*b0
, DWTELEM
*b1
, DWTELEM
*b2
, int width
){
1267 for(i
=0; i
<width
; i
++){
1268 b1
[i
] -= (b0
[i
] + b2
[i
] + 2)>>2;
1272 static void spatial_compose53i_buffered_init(dwt_compose_t
*cs
, slice_buffer
* sb
, int height
, int stride_line
){
1273 cs
->b0
= slice_buffer_get_line(sb
, mirror(-1-1, height
-1) * stride_line
);
1274 cs
->b1
= slice_buffer_get_line(sb
, mirror(-1 , height
-1) * stride_line
);
1278 static void spatial_compose53i_init(dwt_compose_t
*cs
, DWTELEM
*buffer
, int height
, int stride
){
1279 cs
->b0
= buffer
+ mirror(-1-1, height
-1)*stride
;
1280 cs
->b1
= buffer
+ mirror(-1 , height
-1)*stride
;
1284 static void spatial_compose53i_dy_buffered(dwt_compose_t
*cs
, slice_buffer
* sb
, int width
, int height
, int stride_line
){
1287 DWTELEM
*b0
= cs
->b0
;
1288 DWTELEM
*b1
= cs
->b1
;
1289 DWTELEM
*b2
= slice_buffer_get_line(sb
, mirror(y
+1, height
-1) * stride_line
);
1290 DWTELEM
*b3
= slice_buffer_get_line(sb
, mirror(y
+2, height
-1) * stride_line
);
1293 if(y
+1<(unsigned)height
) vertical_compose53iL0(b1
, b2
, b3
, width
);
1294 if(y
+0<(unsigned)height
) vertical_compose53iH0(b0
, b1
, b2
, width
);
1295 STOP_TIMER("vertical_compose53i*")}
1298 if(y
-1<(unsigned)height
) horizontal_compose53i(b0
, width
);
1299 if(y
+0<(unsigned)height
) horizontal_compose53i(b1
, width
);
1300 STOP_TIMER("horizontal_compose53i")}
1307 static void spatial_compose53i_dy(dwt_compose_t
*cs
, DWTELEM
*buffer
, int width
, int height
, int stride
){
1309 DWTELEM
*b0
= cs
->b0
;
1310 DWTELEM
*b1
= cs
->b1
;
1311 DWTELEM
*b2
= buffer
+ mirror(y
+1, height
-1)*stride
;
1312 DWTELEM
*b3
= buffer
+ mirror(y
+2, height
-1)*stride
;
1315 if(y
+1<(unsigned)height
) vertical_compose53iL0(b1
, b2
, b3
, width
);
1316 if(y
+0<(unsigned)height
) vertical_compose53iH0(b0
, b1
, b2
, width
);
1317 STOP_TIMER("vertical_compose53i*")}
1320 if(y
-1<(unsigned)height
) horizontal_compose53i(b0
, width
);
1321 if(y
+0<(unsigned)height
) horizontal_compose53i(b1
, width
);
1322 STOP_TIMER("horizontal_compose53i")}
1329 static void spatial_compose53i(DWTELEM
*buffer
, int width
, int height
, int stride
){
1331 spatial_compose53i_init(&cs
, buffer
, height
, stride
);
1332 while(cs
.y
<= height
)
1333 spatial_compose53i_dy(&cs
, buffer
, width
, height
, stride
);
1337 void ff_snow_horizontal_compose97i(DWTELEM
*b
, int width
){
1338 DWTELEM temp
[width
];
1339 const int w2
= (width
+1)>>1;
1341 lift (temp
, b
, b
+w2
, 1, 1, 1, width
, W_DM
, W_DO
, W_DS
, 0, 1);
1342 lift5(temp
+w2
, b
+w2
, temp
, 1, 1, 1, width
, W_CM
, W_CO
, W_CS
, 1, 1);
1343 liftS(b
, temp
, temp
+w2
, 2, 1, 1, width
, -W_BM
, W_BO
, W_BS
, 0, 1);
1344 lift (b
+1 , temp
+w2
, b
, 2, 1, 2, width
, -W_AM
, W_AO
, W_AS
, 1, 1);
1347 static void vertical_compose97iH0(DWTELEM
*b0
, DWTELEM
*b1
, DWTELEM
*b2
, int width
){
1350 for(i
=0; i
<width
; i
++){
1351 b1
[i
] += (W_AM
*(b0
[i
] + b2
[i
])+W_AO
)>>W_AS
;
1355 static void vertical_compose97iH1(DWTELEM
*b0
, DWTELEM
*b1
, DWTELEM
*b2
, int width
){
1358 for(i
=0; i
<width
; i
++){
1360 b1
[i
] -= (W_CM
*(b0
[i
] + b2
[i
])+W_CO
)>>W_CS
;
1362 int r
= 3*(b0
[i
] + b2
[i
]);
1365 b1
[i
] -= (r
+W_CO
)>>W_CS
;
1370 static void vertical_compose97iL0(DWTELEM
*b0
, DWTELEM
*b1
, DWTELEM
*b2
, int width
){
1373 for(i
=0; i
<width
; i
++){
1375 b1
[i
] += (W_BM
*(b0
[i
] + b2
[i
])+W_BO
)>>W_BS
;
1377 b1
[i
] += (W_BM
*(b0
[i
] + b2
[i
])+4*b1
[i
]+W_BO
)>>W_BS
;
1382 static void vertical_compose97iL1(DWTELEM
*b0
, DWTELEM
*b1
, DWTELEM
*b2
, int width
){
1385 for(i
=0; i
<width
; i
++){
1386 b1
[i
] -= (W_DM
*(b0
[i
] + b2
[i
])+W_DO
)>>W_DS
;
1390 void ff_snow_vertical_compose97i(DWTELEM
*b0
, DWTELEM
*b1
, DWTELEM
*b2
, DWTELEM
*b3
, DWTELEM
*b4
, DWTELEM
*b5
, int width
){
1393 for(i
=0; i
<width
; i
++){
1397 b4
[i
] -= (W_DM
*(b3
[i
] + b5
[i
])+W_DO
)>>W_DS
;
1399 b3
[i
] -= (W_CM
*(b2
[i
] + b4
[i
])+W_CO
)>>W_CS
;
1401 r
= 3*(b2
[i
] + b4
[i
]);
1404 b3
[i
] -= (r
+W_CO
)>>W_CS
;
1407 b2
[i
] += (W_BM
*(b1
[i
] + b3
[i
])+W_BO
)>>W_BS
;
1409 b2
[i
] += (W_BM
*(b1
[i
] + b3
[i
])+4*b2
[i
]+W_BO
)>>W_BS
;
1411 b1
[i
] += (W_AM
*(b0
[i
] + b2
[i
])+W_AO
)>>W_AS
;
1415 static void spatial_compose97i_buffered_init(dwt_compose_t
*cs
, slice_buffer
* sb
, int height
, int stride_line
){
1416 cs
->b0
= slice_buffer_get_line(sb
, mirror(-3-1, height
-1) * stride_line
);
1417 cs
->b1
= slice_buffer_get_line(sb
, mirror(-3 , height
-1) * stride_line
);
1418 cs
->b2
= slice_buffer_get_line(sb
, mirror(-3+1, height
-1) * stride_line
);
1419 cs
->b3
= slice_buffer_get_line(sb
, mirror(-3+2, height
-1) * stride_line
);
1423 static void spatial_compose97i_init(dwt_compose_t
*cs
, DWTELEM
*buffer
, int height
, int stride
){
1424 cs
->b0
= buffer
+ mirror(-3-1, height
-1)*stride
;
1425 cs
->b1
= buffer
+ mirror(-3 , height
-1)*stride
;
1426 cs
->b2
= buffer
+ mirror(-3+1, height
-1)*stride
;
1427 cs
->b3
= buffer
+ mirror(-3+2, height
-1)*stride
;
1431 static void spatial_compose97i_dy_buffered(DSPContext
*dsp
, dwt_compose_t
*cs
, slice_buffer
* sb
, int width
, int height
, int stride_line
){
1434 DWTELEM
*b0
= cs
->b0
;
1435 DWTELEM
*b1
= cs
->b1
;
1436 DWTELEM
*b2
= cs
->b2
;
1437 DWTELEM
*b3
= cs
->b3
;
1438 DWTELEM
*b4
= slice_buffer_get_line(sb
, mirror(y
+ 3, height
- 1) * stride_line
);
1439 DWTELEM
*b5
= slice_buffer_get_line(sb
, mirror(y
+ 4, height
- 1) * stride_line
);
1442 if(y
>0 && y
+4<height
){
1443 dsp
->vertical_compose97i(b0
, b1
, b2
, b3
, b4
, b5
, width
);
1445 if(y
+3<(unsigned)height
) vertical_compose97iL1(b3
, b4
, b5
, width
);
1446 if(y
+2<(unsigned)height
) vertical_compose97iH1(b2
, b3
, b4
, width
);
1447 if(y
+1<(unsigned)height
) vertical_compose97iL0(b1
, b2
, b3
, width
);
1448 if(y
+0<(unsigned)height
) vertical_compose97iH0(b0
, b1
, b2
, width
);
1451 STOP_TIMER("vertical_compose97i")}}
1454 if(y
-1<(unsigned)height
) dsp
->horizontal_compose97i(b0
, width
);
1455 if(y
+0<(unsigned)height
) dsp
->horizontal_compose97i(b1
, width
);
1456 if(width
>400 && y
+0<(unsigned)height
){
1457 STOP_TIMER("horizontal_compose97i")}}
1466 static void spatial_compose97i_dy(dwt_compose_t
*cs
, DWTELEM
*buffer
, int width
, int height
, int stride
){
1468 DWTELEM
*b0
= cs
->b0
;
1469 DWTELEM
*b1
= cs
->b1
;
1470 DWTELEM
*b2
= cs
->b2
;
1471 DWTELEM
*b3
= cs
->b3
;
1472 DWTELEM
*b4
= buffer
+ mirror(y
+3, height
-1)*stride
;
1473 DWTELEM
*b5
= buffer
+ mirror(y
+4, height
-1)*stride
;
1476 if(y
+3<(unsigned)height
) vertical_compose97iL1(b3
, b4
, b5
, width
);
1477 if(y
+2<(unsigned)height
) vertical_compose97iH1(b2
, b3
, b4
, width
);
1478 if(y
+1<(unsigned)height
) vertical_compose97iL0(b1
, b2
, b3
, width
);
1479 if(y
+0<(unsigned)height
) vertical_compose97iH0(b0
, b1
, b2
, width
);
1481 STOP_TIMER("vertical_compose97i")}}
1484 if(y
-1<(unsigned)height
) ff_snow_horizontal_compose97i(b0
, width
);
1485 if(y
+0<(unsigned)height
) ff_snow_horizontal_compose97i(b1
, width
);
1486 if(width
>400 && b0
<= b2
){
1487 STOP_TIMER("horizontal_compose97i")}}
1496 static void spatial_compose97i(DWTELEM
*buffer
, int width
, int height
, int stride
){
1498 spatial_compose97i_init(&cs
, buffer
, height
, stride
);
1499 while(cs
.y
<= height
)
1500 spatial_compose97i_dy(&cs
, buffer
, width
, height
, stride
);
1503 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
){
1505 for(level
=decomposition_count
-1; level
>=0; level
--){
1507 case DWT_97
: spatial_compose97i_buffered_init(cs
+level
, sb
, height
>>level
, stride_line
<<level
); break;
1508 case DWT_53
: spatial_compose53i_buffered_init(cs
+level
, sb
, height
>>level
, stride_line
<<level
); break;
1509 /* not slicified yet */
1510 case DWT_X
: /*spatial_composeX(buffer, width>>level, height>>level, stride<<level); break;*/
1511 av_log(NULL
, AV_LOG_ERROR
, "spatial_composeX neither buffered nor slicified yet.\n"); break;
1516 static void ff_spatial_idwt_init(dwt_compose_t
*cs
, DWTELEM
*buffer
, int width
, int height
, int stride
, int type
, int decomposition_count
){
1518 for(level
=decomposition_count
-1; level
>=0; level
--){
1520 case DWT_97
: spatial_compose97i_init(cs
+level
, buffer
, height
>>level
, stride
<<level
); break;
1521 case DWT_53
: spatial_compose53i_init(cs
+level
, buffer
, height
>>level
, stride
<<level
); break;
1522 /* not slicified yet */
1523 case DWT_X
: spatial_composeX(buffer
, width
>>level
, height
>>level
, stride
<<level
); break;
1528 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
){
1529 const int support
= type
==1 ?
3 : 5;
1533 for(level
=decomposition_count
-1; level
>=0; level
--){
1534 while(cs
[level
].y
<= FFMIN((y
>>level
)+support
, height
>>level
)){
1536 case DWT_97
: spatial_compose97i_dy(cs
+level
, buffer
, width
>>level
, height
>>level
, stride
<<level
);
1538 case DWT_53
: spatial_compose53i_dy(cs
+level
, buffer
, width
>>level
, height
>>level
, stride
<<level
);
1546 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
){
1547 const int support
= type
==1 ?
3 : 5;
1551 for(level
=decomposition_count
-1; level
>=0; level
--){
1552 while(cs
[level
].y
<= FFMIN((y
>>level
)+support
, height
>>level
)){
1554 case DWT_97
: spatial_compose97i_dy_buffered(dsp
, cs
+level
, slice_buf
, width
>>level
, height
>>level
, stride_line
<<level
);
1556 case DWT_53
: spatial_compose53i_dy_buffered(cs
+level
, slice_buf
, width
>>level
, height
>>level
, stride_line
<<level
);
1564 static void ff_spatial_idwt(DWTELEM
*buffer
, int width
, int height
, int stride
, int type
, int decomposition_count
){
1567 for(level
=decomposition_count
-1; level
>=0; level
--)
1568 spatial_composeX (buffer
, width
>>level
, height
>>level
, stride
<<level
);
1570 dwt_compose_t cs
[MAX_DECOMPOSITIONS
];
1572 ff_spatial_idwt_init(cs
, buffer
, width
, height
, stride
, type
, decomposition_count
);
1573 for(y
=0; y
<height
; y
+=4)
1574 ff_spatial_idwt_slice(cs
, buffer
, width
, height
, stride
, type
, decomposition_count
, y
);
1578 static int encode_subband_c0run(SnowContext
*s
, SubBand
*b
, DWTELEM
*src
, DWTELEM
*parent
, int stride
, int orientation
){
1579 const int w
= b
->width
;
1580 const int h
= b
->height
;
1592 int /*ll=0, */l
=0, lt
=0, t
=0, rt
=0;
1593 v
= src
[x
+ y
*stride
];
1596 t
= src
[x
+ (y
-1)*stride
];
1598 lt
= src
[x
- 1 + (y
-1)*stride
];
1601 rt
= src
[x
+ 1 + (y
-1)*stride
];
1605 l
= src
[x
- 1 + y
*stride
];
1607 if(orientation==1) ll= src[y + (x-2)*stride];
1608 else ll= src[x - 2 + y*stride];
1614 if(px
<b
->parent
->width
&& py
<b
->parent
->height
)
1615 p
= parent
[px
+ py
*2*stride
];
1617 if(!(/*ll|*/l
|lt
|t
|rt
|p
)){
1619 runs
[run_index
++]= run
;
1627 max_index
= run_index
;
1628 runs
[run_index
++]= run
;
1630 run
= runs
[run_index
++];
1632 put_symbol2(&s
->c
, b
->state
[30], max_index
, 0);
1633 if(run_index
<= max_index
)
1634 put_symbol2(&s
->c
, b
->state
[1], run
, 3);
1637 if(s
->c
.bytestream_end
- s
->c
.bytestream
< w
*40){
1638 av_log(s
->avctx
, AV_LOG_ERROR
, "encoded frame too large\n");
1643 int /*ll=0, */l
=0, lt
=0, t
=0, rt
=0;
1644 v
= src
[x
+ y
*stride
];
1647 t
= src
[x
+ (y
-1)*stride
];
1649 lt
= src
[x
- 1 + (y
-1)*stride
];
1652 rt
= src
[x
+ 1 + (y
-1)*stride
];
1656 l
= src
[x
- 1 + y
*stride
];
1658 if(orientation==1) ll= src[y + (x-2)*stride];
1659 else ll= src[x - 2 + y*stride];
1665 if(px
<b
->parent
->width
&& py
<b
->parent
->height
)
1666 p
= parent
[px
+ py
*2*stride
];
1668 if(/*ll|*/l
|lt
|t
|rt
|p
){
1669 int context
= av_log2(/*FFABS(ll) + */3*FFABS(l
) + FFABS(lt
) + 2*FFABS(t
) + FFABS(rt
) + FFABS(p
));
1671 put_rac(&s
->c
, &b
->state
[0][context
], !!v
);
1674 run
= runs
[run_index
++];
1676 if(run_index
<= max_index
)
1677 put_symbol2(&s
->c
, b
->state
[1], run
, 3);
1685 int context
= av_log2(/*FFABS(ll) + */3*FFABS(l
) + FFABS(lt
) + 2*FFABS(t
) + FFABS(rt
) + FFABS(p
));
1686 int l2
= 2*FFABS(l
) + (l
<0);
1687 int t2
= 2*FFABS(t
) + (t
<0);
1689 put_symbol2(&s
->c
, b
->state
[context
+ 2], FFABS(v
)-1, context
-4);
1690 put_rac(&s
->c
, &b
->state
[0][16 + 1 + 3 + quant3bA
[l2
&0xFF] + 3*quant3bA
[t2
&0xFF]], v
<0);
1698 static int encode_subband(SnowContext
*s
, SubBand
*b
, DWTELEM
*src
, DWTELEM
*parent
, int stride
, int orientation
){
1699 // encode_subband_qtree(s, b, src, parent, stride, orientation);
1700 // encode_subband_z0run(s, b, src, parent, stride, orientation);
1701 return encode_subband_c0run(s
, b
, src
, parent
, stride
, orientation
);
1702 // encode_subband_dzr(s, b, src, parent, stride, orientation);
1705 static inline void unpack_coeffs(SnowContext
*s
, SubBand
*b
, SubBand
* parent
, int orientation
){
1706 const int w
= b
->width
;
1707 const int h
= b
->height
;
1712 x_and_coeff
*xc
= b
->x_coeff
;
1713 x_and_coeff
*prev_xc
= NULL
;
1714 x_and_coeff
*prev2_xc
= xc
;
1715 x_and_coeff
*parent_xc
= parent ? parent
->x_coeff
: NULL
;
1716 x_and_coeff
*prev_parent_xc
= parent_xc
;
1718 runs
= get_symbol2(&s
->c
, b
->state
[30], 0);
1719 if(runs
-- > 0) run
= get_symbol2(&s
->c
, b
->state
[1], 3);
1724 int lt
=0, t
=0, rt
=0;
1726 if(y
&& prev_xc
->x
== 0){
1738 if(prev_xc
->x
== x
+ 1)
1744 if(x
>>1 > parent_xc
->x
){
1747 if(x
>>1 == parent_xc
->x
){
1748 p
= parent_xc
->coeff
;
1751 if(/*ll|*/l
|lt
|t
|rt
|p
){
1752 int context
= av_log2(/*FFABS(ll) + */3*(l
>>1) + (lt
>>1) + (t
&~1) + (rt
>>1) + (p
>>1));
1754 v
=get_rac(&s
->c
, &b
->state
[0][context
]);
1756 v
= 2*(get_symbol2(&s
->c
, b
->state
[context
+ 2], context
-4) + 1);
1757 v
+=get_rac(&s
->c
, &b
->state
[0][16 + 1 + 3 + quant3bA
[l
&0xFF] + 3*quant3bA
[t
&0xFF]]);
1764 if(runs
-- > 0) run
= get_symbol2(&s
->c
, b
->state
[1], 3);
1766 v
= 2*(get_symbol2(&s
->c
, b
->state
[0 + 2], 0-4) + 1);
1767 v
+=get_rac(&s
->c
, &b
->state
[0][16 + 1 + 3]);
1776 if(y
) max_run
= FFMIN(run
, prev_xc
->x
- x
- 2);
1777 else max_run
= FFMIN(run
, w
-x
-1);
1779 max_run
= FFMIN(max_run
, 2*parent_xc
->x
- x
- 1);
1785 (xc
++)->x
= w
+1; //end marker
1791 while(parent_xc
->x
!= parent
->width
+1)
1794 prev_parent_xc
= parent_xc
;
1796 parent_xc
= prev_parent_xc
;
1801 (xc
++)->x
= w
+1; //end marker
1805 static inline void decode_subband_slice_buffered(SnowContext
*s
, SubBand
*b
, slice_buffer
* sb
, int start_y
, int h
, int save_state
[1]){
1806 const int w
= b
->width
;
1808 const int qlog
= clip(s
->qlog
+ b
->qlog
, 0, QROOT
*16);
1809 int qmul
= qexp
[qlog
&(QROOT
-1)]<<(qlog
>>QSHIFT
);
1810 int qadd
= (s
->qbias
*qmul
)>>QBIAS_SHIFT
;
1815 if(b
->buf
== s
->spatial_dwt_buffer
|| s
->qlog
== LOSSLESS_QLOG
){
1820 /* If we are on the second or later slice, restore our index. */
1822 new_index
= save_state
[0];
1825 for(y
=start_y
; y
<h
; y
++){
1828 DWTELEM
* line
= slice_buffer_get_line(sb
, y
* b
->stride_line
+ b
->buf_y_offset
) + b
->buf_x_offset
;
1829 memset(line
, 0, b
->width
*sizeof(DWTELEM
));
1830 v
= b
->x_coeff
[new_index
].coeff
;
1831 x
= b
->x_coeff
[new_index
++].x
;
1834 register int t
= ( (v
>>1)*qmul
+ qadd
)>>QEXPSHIFT
;
1835 register int u
= -(v
&1);
1836 line
[x
] = (t
^u
) - u
;
1838 v
= b
->x_coeff
[new_index
].coeff
;
1839 x
= b
->x_coeff
[new_index
++].x
;
1842 if(w
> 200 && start_y
!= 0/*level+1 == s->spatial_decomposition_count*/){
1843 STOP_TIMER("decode_subband")
1846 /* Save our variables for the next slice. */
1847 save_state
[0] = new_index
;
1852 static void reset_contexts(SnowContext
*s
){
1853 int plane_index
, level
, orientation
;
1855 for(plane_index
=0; plane_index
<3; plane_index
++){
1856 for(level
=0; level
<s
->spatial_decomposition_count
; level
++){
1857 for(orientation
=level ?
1:0; orientation
<4; orientation
++){
1858 memset(s
->plane
[plane_index
].band
[level
][orientation
].state
, MID_STATE
, sizeof(s
->plane
[plane_index
].band
[level
][orientation
].state
));
1862 memset(s
->header_state
, MID_STATE
, sizeof(s
->header_state
));
1863 memset(s
->block_state
, MID_STATE
, sizeof(s
->block_state
));
1866 static int alloc_blocks(SnowContext
*s
){
1867 int w
= -((-s
->avctx
->width
)>>LOG2_MB_SIZE
);
1868 int h
= -((-s
->avctx
->height
)>>LOG2_MB_SIZE
);
1873 s
->block
= av_mallocz(w
* h
* sizeof(BlockNode
) << (s
->block_max_depth
*2));
1877 static inline void copy_rac_state(RangeCoder
*d
, RangeCoder
*s
){
1878 uint8_t *bytestream
= d
->bytestream
;
1879 uint8_t *bytestream_start
= d
->bytestream_start
;
1881 d
->bytestream
= bytestream
;
1882 d
->bytestream_start
= bytestream_start
;
1885 //near copy & paste from dsputil, FIXME
1886 static int pix_sum(uint8_t * pix
, int line_size
, int w
)
1891 for (i
= 0; i
< w
; i
++) {
1892 for (j
= 0; j
< w
; j
++) {
1896 pix
+= line_size
- w
;
1901 //near copy & paste from dsputil, FIXME
1902 static int pix_norm1(uint8_t * pix
, int line_size
, int w
)
1905 uint32_t *sq
= ff_squareTbl
+ 256;
1908 for (i
= 0; i
< w
; i
++) {
1909 for (j
= 0; j
< w
; j
++) {
1913 pix
+= line_size
- w
;
1918 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
){
1919 const int w
= s
->b_width
<< s
->block_max_depth
;
1920 const int rem_depth
= s
->block_max_depth
- level
;
1921 const int index
= (x
+ y
*w
) << rem_depth
;
1922 const int block_w
= 1<<rem_depth
;
1935 for(j
=0; j
<block_w
; j
++){
1936 for(i
=0; i
<block_w
; i
++){
1937 s
->block
[index
+ i
+ j
*w
]= block
;
1942 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
){
1943 const int offset
[3]= {
1945 ((y
*c
->uvstride
+ x
)>>1),
1946 ((y
*c
->uvstride
+ x
)>>1),
1950 c
->src
[0][i
]= src
[i
];
1951 c
->ref
[0][i
]= ref
[i
] + offset
[i
];
1956 static inline void pred_mv(SnowContext
*s
, int *mx
, int *my
, int ref
,
1957 BlockNode
*left
, BlockNode
*top
, BlockNode
*tr
){
1958 if(s
->ref_frames
== 1){
1959 *mx
= mid_pred(left
->mx
, top
->mx
, tr
->mx
);
1960 *my
= mid_pred(left
->my
, top
->my
, tr
->my
);
1962 const int *scale
= scale_mv_ref
[ref
];
1963 *mx
= mid_pred(left
->mx
* scale
[left
->ref
] + 128 >>8,
1964 top
->mx
* scale
[top
->ref
] + 128 >>8,
1965 tr
->mx
* scale
[tr
->ref
] + 128 >>8);
1966 *my
= mid_pred(left
->my
* scale
[left
->ref
] + 128 >>8,
1967 top
->my
* scale
[top
->ref
] + 128 >>8,
1968 tr
->my
* scale
[tr
->ref
] + 128 >>8);
1975 #define P_TOPRIGHT P[3]
1976 #define P_MEDIAN P[4]
1978 #define FLAG_QPEL 1 //must be 1
1980 static int encode_q_branch(SnowContext
*s
, int level
, int x
, int y
){
1981 uint8_t p_buffer
[1024];
1982 uint8_t i_buffer
[1024];
1983 uint8_t p_state
[sizeof(s
->block_state
)];
1984 uint8_t i_state
[sizeof(s
->block_state
)];
1986 uint8_t *pbbak
= s
->c
.bytestream
;
1987 uint8_t *pbbak_start
= s
->c
.bytestream_start
;
1988 int score
, score2
, iscore
, i_len
, p_len
, block_s
, sum
;
1989 const int w
= s
->b_width
<< s
->block_max_depth
;
1990 const int h
= s
->b_height
<< s
->block_max_depth
;
1991 const int rem_depth
= s
->block_max_depth
- level
;
1992 const int index
= (x
+ y
*w
) << rem_depth
;
1993 const int block_w
= 1<<(LOG2_MB_SIZE
- level
);
1994 int trx
= (x
+1)<<rem_depth
;
1995 int try= (y
+1)<<rem_depth
;
1996 BlockNode
*left
= x ?
&s
->block
[index
-1] : &null_block
;
1997 BlockNode
*top
= y ?
&s
->block
[index
-w
] : &null_block
;
1998 BlockNode
*right
= trx
<w ?
&s
->block
[index
+1] : &null_block
;
1999 BlockNode
*bottom
= try<h ?
&s
->block
[index
+w
] : &null_block
;
2000 BlockNode
*tl
= y
&& x ?
&s
->block
[index
-w
-1] : left
;
2001 BlockNode
*tr
= y
&& trx
<w
&& ((x
&1)==0 || level
==0) ?
&s
->block
[index
-w
+(1<<rem_depth
)] : tl
; //FIXME use lt
2002 int pl
= left
->color
[0];
2003 int pcb
= left
->color
[1];
2004 int pcr
= left
->color
[2];
2008 const int stride
= s
->current_picture
.linesize
[0];
2009 const int uvstride
= s
->current_picture
.linesize
[1];
2010 uint8_t *current_data
[3]= { s
->input_picture
.data
[0] + (x
+ y
* stride
)*block_w
,
2011 s
->input_picture
.data
[1] + (x
+ y
*uvstride
)*block_w
/2,
2012 s
->input_picture
.data
[2] + (x
+ y
*uvstride
)*block_w
/2};
2014 int16_t last_mv
[3][2];
2015 int qpel
= !!(s
->avctx
->flags
& CODEC_FLAG_QPEL
); //unused
2016 const int shift
= 1+qpel
;
2017 MotionEstContext
*c
= &s
->m
.me
;
2018 int ref_context
= av_log2(2*left
->ref
) + av_log2(2*top
->ref
);
2019 int mx_context
= av_log2(2*FFABS(left
->mx
- top
->mx
));
2020 int my_context
= av_log2(2*FFABS(left
->my
- top
->my
));
2021 int s_context
= 2*left
->level
+ 2*top
->level
+ tl
->level
+ tr
->level
;
2022 int ref
, best_ref
, ref_score
, ref_mx
, ref_my
;
2024 assert(sizeof(s
->block_state
) >= 256);
2026 set_blocks(s
, level
, x
, y
, pl
, pcb
, pcr
, 0, 0, 0, BLOCK_INTRA
);
2030 // clip predictors / edge ?
2032 P_LEFT
[0]= left
->mx
;
2033 P_LEFT
[1]= left
->my
;
2036 P_TOPRIGHT
[0]= tr
->mx
;
2037 P_TOPRIGHT
[1]= tr
->my
;
2039 last_mv
[0][0]= s
->block
[index
].mx
;
2040 last_mv
[0][1]= s
->block
[index
].my
;
2041 last_mv
[1][0]= right
->mx
;
2042 last_mv
[1][1]= right
->my
;
2043 last_mv
[2][0]= bottom
->mx
;
2044 last_mv
[2][1]= bottom
->my
;
2051 assert(s
->m
.me
. stride
== stride
);
2052 assert(s
->m
.me
.uvstride
== uvstride
);
2054 c
->penalty_factor
= get_penalty_factor(s
->lambda
, s
->lambda2
, c
->avctx
->me_cmp
);
2055 c
->sub_penalty_factor
= get_penalty_factor(s
->lambda
, s
->lambda2
, c
->avctx
->me_sub_cmp
);
2056 c
->mb_penalty_factor
= get_penalty_factor(s
->lambda
, s
->lambda2
, c
->avctx
->mb_cmp
);
2057 c
->current_mv_penalty
= c
->mv_penalty
[s
->m
.f_code
=1] + MAX_MV
;
2059 c
->xmin
= - x
*block_w
- 16+2;