Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Copyright (C) 2007 Marco Gerards <marco@gnu.org> | ||
3 | * Copyright (C) 2009 David Conrad | ||
4 | * Copyright (C) 2011 Jordi Ortiz | ||
5 | * | ||
6 | * This file is part of FFmpeg. | ||
7 | * | ||
8 | * FFmpeg is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU Lesser General Public | ||
10 | * License as published by the Free Software Foundation; either | ||
11 | * version 2.1 of the License, or (at your option) any later version. | ||
12 | * | ||
13 | * FFmpeg is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * Lesser General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU Lesser General Public | ||
19 | * License along with FFmpeg; if not, write to the Free Software | ||
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
21 | */ | ||
22 | |||
23 | /** | ||
24 | * @file | ||
25 | * Dirac Decoder | ||
26 | * @author Marco Gerards <marco@gnu.org>, David Conrad, Jordi Ortiz <nenjordi@gmail.com> | ||
27 | */ | ||
28 | |||
29 | #include "libavutil/mem_internal.h" | ||
30 | #include "libavutil/pixdesc.h" | ||
31 | #include "libavutil/thread.h" | ||
32 | #include "avcodec.h" | ||
33 | #include "get_bits.h" | ||
34 | #include "codec_internal.h" | ||
35 | #include "decode.h" | ||
36 | #include "golomb.h" | ||
37 | #include "dirac_arith.h" | ||
38 | #include "dirac_vlc.h" | ||
39 | #include "mpegpicture.h" | ||
40 | #include "mpegvideoencdsp.h" | ||
41 | #include "dirac_dwt.h" | ||
42 | #include "dirac.h" | ||
43 | #include "diractab.h" | ||
44 | #include "diracdsp.h" | ||
45 | #include "videodsp.h" | ||
46 | |||
47 | /** | ||
48 | * The spec limits this to 3 for frame coding, but in practice can be as high as 6 | ||
49 | */ | ||
50 | #define MAX_REFERENCE_FRAMES 8 | ||
51 | #define MAX_DELAY 5 /* limit for main profile for frame coding (TODO: field coding) */ | ||
52 | #define MAX_FRAMES (MAX_REFERENCE_FRAMES + MAX_DELAY + 1) | ||
53 | #define MAX_QUANT 255 /* max quant for VC-2 */ | ||
54 | #define MAX_BLOCKSIZE 32 /* maximum xblen/yblen we support */ | ||
55 | |||
56 | /** | ||
57 | * DiracBlock->ref flags, if set then the block does MC from the given ref | ||
58 | */ | ||
59 | #define DIRAC_REF_MASK_REF1 1 | ||
60 | #define DIRAC_REF_MASK_REF2 2 | ||
61 | #define DIRAC_REF_MASK_GLOBAL 4 | ||
62 | |||
63 | /** | ||
64 | * Value of Picture.reference when Picture is not a reference picture, but | ||
65 | * is held for delayed output. | ||
66 | */ | ||
67 | #define DELAYED_PIC_REF 4 | ||
68 | |||
69 | #define CALC_PADDING(size, depth) \ | ||
70 | (((size + (1 << depth) - 1) >> depth) << depth) | ||
71 | |||
72 | #define DIVRNDUP(a, b) (((a) + (b) - 1) / (b)) | ||
73 | |||
74 | typedef struct { | ||
75 | AVFrame *avframe; | ||
76 | int interpolated[3]; /* 1 if hpel[] is valid */ | ||
77 | uint8_t *hpel[3][4]; | ||
78 | uint8_t *hpel_base[3][4]; | ||
79 | int reference; | ||
80 | unsigned picture_number; | ||
81 | } DiracFrame; | ||
82 | |||
83 | typedef struct { | ||
84 | union { | ||
85 | int16_t mv[2][2]; | ||
86 | int16_t dc[3]; | ||
87 | } u; /* anonymous unions aren't in C99 :( */ | ||
88 | uint8_t ref; | ||
89 | } DiracBlock; | ||
90 | |||
91 | typedef struct SubBand { | ||
92 | int level; | ||
93 | int orientation; | ||
94 | int stride; /* in bytes */ | ||
95 | int width; | ||
96 | int height; | ||
97 | int pshift; | ||
98 | int quant; | ||
99 | uint8_t *ibuf; | ||
100 | struct SubBand *parent; | ||
101 | |||
102 | /* for low delay */ | ||
103 | unsigned length; | ||
104 | const uint8_t *coeff_data; | ||
105 | } SubBand; | ||
106 | |||
107 | typedef struct Plane { | ||
108 | DWTPlane idwt; | ||
109 | |||
110 | int width; | ||
111 | int height; | ||
112 | ptrdiff_t stride; | ||
113 | |||
114 | /* block length */ | ||
115 | uint8_t xblen; | ||
116 | uint8_t yblen; | ||
117 | /* block separation (block n+1 starts after this many pixels in block n) */ | ||
118 | uint8_t xbsep; | ||
119 | uint8_t ybsep; | ||
120 | /* amount of overspill on each edge (half of the overlap between blocks) */ | ||
121 | uint8_t xoffset; | ||
122 | uint8_t yoffset; | ||
123 | |||
124 | SubBand band[MAX_DWT_LEVELS][4]; | ||
125 | } Plane; | ||
126 | |||
127 | /* Used by Low Delay and High Quality profiles */ | ||
128 | typedef struct DiracSlice { | ||
129 | GetBitContext gb; | ||
130 | int slice_x; | ||
131 | int slice_y; | ||
132 | int bytes; | ||
133 | } DiracSlice; | ||
134 | |||
135 | typedef struct DiracContext { | ||
136 | AVCodecContext *avctx; | ||
137 | MpegvideoEncDSPContext mpvencdsp; | ||
138 | VideoDSPContext vdsp; | ||
139 | DiracDSPContext diracdsp; | ||
140 | DiracVersionInfo version; | ||
141 | GetBitContext gb; | ||
142 | AVDiracSeqHeader seq; | ||
143 | int seen_sequence_header; | ||
144 | int64_t frame_number; /* number of the next frame to display */ | ||
145 | Plane plane[3]; | ||
146 | int chroma_x_shift; | ||
147 | int chroma_y_shift; | ||
148 | |||
149 | int bit_depth; /* bit depth */ | ||
150 | int pshift; /* pixel shift = bit_depth > 8 */ | ||
151 | |||
152 | int zero_res; /* zero residue flag */ | ||
153 | int is_arith; /* whether coeffs use arith or golomb coding */ | ||
154 | int core_syntax; /* use core syntax only */ | ||
155 | int low_delay; /* use the low delay syntax */ | ||
156 | int hq_picture; /* high quality picture, enables low_delay */ | ||
157 | int ld_picture; /* use low delay picture, turns on low_delay */ | ||
158 | int dc_prediction; /* has dc prediction */ | ||
159 | int globalmc_flag; /* use global motion compensation */ | ||
160 | int num_refs; /* number of reference pictures */ | ||
161 | |||
162 | /* wavelet decoding */ | ||
163 | unsigned wavelet_depth; /* depth of the IDWT */ | ||
164 | unsigned wavelet_idx; | ||
165 | |||
166 | /** | ||
167 | * schroedinger older than 1.0.8 doesn't store | ||
168 | * quant delta if only one codebook exists in a band | ||
169 | */ | ||
170 | unsigned old_delta_quant; | ||
171 | unsigned codeblock_mode; | ||
172 | |||
173 | unsigned num_x; /* number of horizontal slices */ | ||
174 | unsigned num_y; /* number of vertical slices */ | ||
175 | |||
176 | uint8_t *thread_buf; /* Per-thread buffer for coefficient storage */ | ||
177 | int threads_num_buf; /* Current # of buffers allocated */ | ||
178 | int thread_buf_size; /* Each thread has a buffer this size */ | ||
179 | |||
180 | DiracSlice *slice_params_buf; | ||
181 | int slice_params_num_buf; | ||
182 | |||
183 | struct { | ||
184 | unsigned width; | ||
185 | unsigned height; | ||
186 | } codeblock[MAX_DWT_LEVELS+1]; | ||
187 | |||
188 | struct { | ||
189 | AVRational bytes; /* average bytes per slice */ | ||
190 | uint8_t quant[MAX_DWT_LEVELS][4]; /* [DIRAC_STD] E.1 */ | ||
191 | } lowdelay; | ||
192 | |||
193 | struct { | ||
194 | unsigned prefix_bytes; | ||
195 | uint64_t size_scaler; | ||
196 | } highquality; | ||
197 | |||
198 | struct { | ||
199 | int pan_tilt[2]; /* pan/tilt vector */ | ||
200 | int zrs[2][2]; /* zoom/rotate/shear matrix */ | ||
201 | int perspective[2]; /* perspective vector */ | ||
202 | unsigned zrs_exp; | ||
203 | unsigned perspective_exp; | ||
204 | } globalmc[2]; | ||
205 | |||
206 | /* motion compensation */ | ||
207 | uint8_t mv_precision; /* [DIRAC_STD] REFS_WT_PRECISION */ | ||
208 | int16_t weight[2]; /* [DIRAC_STD] REF1_WT and REF2_WT */ | ||
209 | unsigned weight_log2denom; /* [DIRAC_STD] REFS_WT_PRECISION */ | ||
210 | |||
211 | int blwidth; /* number of blocks (horizontally) */ | ||
212 | int blheight; /* number of blocks (vertically) */ | ||
213 | int sbwidth; /* number of superblocks (horizontally) */ | ||
214 | int sbheight; /* number of superblocks (vertically) */ | ||
215 | |||
216 | uint8_t *sbsplit; | ||
217 | DiracBlock *blmotion; | ||
218 | |||
219 | uint8_t *edge_emu_buffer[4]; | ||
220 | uint8_t *edge_emu_buffer_base; | ||
221 | |||
222 | uint16_t *mctmp; /* buffer holding the MC data multiplied by OBMC weights */ | ||
223 | uint8_t *mcscratch; | ||
224 | int buffer_stride; | ||
225 | |||
226 | DECLARE_ALIGNED(16, uint8_t, obmc_weight)[3][MAX_BLOCKSIZE*MAX_BLOCKSIZE]; | ||
227 | |||
228 | void (*put_pixels_tab[4])(uint8_t *dst, const uint8_t *src[5], int stride, int h); | ||
229 | void (*avg_pixels_tab[4])(uint8_t *dst, const uint8_t *src[5], int stride, int h); | ||
230 | void (*add_obmc)(uint16_t *dst, const uint8_t *src, int stride, const uint8_t *obmc_weight, int yblen); | ||
231 | dirac_weight_func weight_func; | ||
232 | dirac_biweight_func biweight_func; | ||
233 | |||
234 | DiracFrame *current_picture; | ||
235 | DiracFrame *ref_pics[2]; | ||
236 | |||
237 | DiracFrame *ref_frames[MAX_REFERENCE_FRAMES+1]; | ||
238 | DiracFrame *delay_frames[MAX_DELAY+1]; | ||
239 | DiracFrame all_frames[MAX_FRAMES]; | ||
240 | } DiracContext; | ||
241 | |||
242 | enum dirac_subband { | ||
243 | subband_ll = 0, | ||
244 | subband_hl = 1, | ||
245 | subband_lh = 2, | ||
246 | subband_hh = 3, | ||
247 | subband_nb, | ||
248 | }; | ||
249 | |||
250 | /* magic number division by 3 from schroedinger */ | ||
251 | 55371 | static inline int divide3(int x) | |
252 | { | ||
253 | 55371 | return (int)((x+1U)*21845 + 10922) >> 16; | |
254 | } | ||
255 | |||
256 | 14 | static DiracFrame *remove_frame(DiracFrame *framelist[], unsigned picnum) | |
257 | { | ||
258 | 14 | DiracFrame *remove_pic = NULL; | |
259 | 14 | int i, remove_idx = -1; | |
260 | |||
261 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 14 times.
|
39 | for (i = 0; framelist[i]; i++) |
262 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 12 times.
|
25 | if (framelist[i]->picture_number == picnum) { |
263 | 13 | remove_pic = framelist[i]; | |
264 | 13 | remove_idx = i; | |
265 | } | ||
266 | |||
267 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 1 times.
|
14 | if (remove_pic) |
268 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 13 times.
|
32 | for (i = remove_idx; framelist[i]; i++) |
269 | 19 | framelist[i] = framelist[i+1]; | |
270 | |||
271 | 14 | return remove_pic; | |
272 | } | ||
273 | |||
274 | 18 | static int add_frame(DiracFrame *framelist[], int maxframes, DiracFrame *frame) | |
275 | { | ||
276 | int i; | ||
277 |
1/2✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
|
33 | for (i = 0; i < maxframes; i++) |
278 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 15 times.
|
33 | if (!framelist[i]) { |
279 | 18 | framelist[i] = frame; | |
280 | 18 | return 0; | |
281 | } | ||
282 | ✗ | return -1; | |
283 | } | ||
284 | |||
285 | 70 | static int alloc_sequence_buffers(DiracContext *s) | |
286 | { | ||
287 | 70 | int sbwidth = DIVRNDUP(s->seq.width, 4); | |
288 | 70 | int sbheight = DIVRNDUP(s->seq.height, 4); | |
289 | int i, w, h, top_padding; | ||
290 | |||
291 | /* todo: think more about this / use or set Plane here */ | ||
292 |
2/2✓ Branch 0 taken 210 times.
✓ Branch 1 taken 70 times.
|
280 | for (i = 0; i < 3; i++) { |
293 |
2/2✓ Branch 0 taken 140 times.
✓ Branch 1 taken 70 times.
|
210 | int max_xblen = MAX_BLOCKSIZE >> (i ? s->chroma_x_shift : 0); |
294 |
2/2✓ Branch 0 taken 140 times.
✓ Branch 1 taken 70 times.
|
210 | int max_yblen = MAX_BLOCKSIZE >> (i ? s->chroma_y_shift : 0); |
295 |
2/2✓ Branch 0 taken 140 times.
✓ Branch 1 taken 70 times.
|
210 | w = s->seq.width >> (i ? s->chroma_x_shift : 0); |
296 |
2/2✓ Branch 0 taken 140 times.
✓ Branch 1 taken 70 times.
|
210 | h = s->seq.height >> (i ? s->chroma_y_shift : 0); |
297 | |||
298 | /* we allocate the max we support here since num decompositions can | ||
299 | * change from frame to frame. Stride is aligned to 16 for SIMD, and | ||
300 | * 1<<MAX_DWT_LEVELS top padding to avoid if(y>0) in arith decoding | ||
301 | * MAX_BLOCKSIZE padding for MC: blocks can spill up to half of that | ||
302 | * on each side */ | ||
303 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 210 times.
|
210 | top_padding = FFMAX(1<<MAX_DWT_LEVELS, max_yblen/2); |
304 | 210 | w = FFALIGN(CALC_PADDING(w, MAX_DWT_LEVELS), 8); /* FIXME: Should this be 16 for SSE??? */ | |
305 | 210 | h = top_padding + CALC_PADDING(h, MAX_DWT_LEVELS) + max_yblen/2; | |
306 | |||
307 | 210 | s->plane[i].idwt.buf_base = av_calloc(w + max_xblen, h * (2 << s->pshift)); | |
308 | 210 | s->plane[i].idwt.tmp = av_malloc_array((w+16), 2 << s->pshift); | |
309 | 210 | s->plane[i].idwt.buf = s->plane[i].idwt.buf_base + (top_padding*w)*(2 << s->pshift); | |
310 |
2/4✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 210 times.
|
210 | if (!s->plane[i].idwt.buf_base || !s->plane[i].idwt.tmp) |
311 | ✗ | return AVERROR(ENOMEM); | |
312 | } | ||
313 | |||
314 | /* fixme: allocate using real stride here */ | ||
315 | 70 | s->sbsplit = av_malloc_array(sbwidth, sbheight); | |
316 | 70 | s->blmotion = av_malloc_array(sbwidth, sbheight * 16 * sizeof(*s->blmotion)); | |
317 | |||
318 |
2/4✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 70 times.
|
70 | if (!s->sbsplit || !s->blmotion) |
319 | ✗ | return AVERROR(ENOMEM); | |
320 | 70 | return 0; | |
321 | } | ||
322 | |||
323 | 260 | static int alloc_buffers(DiracContext *s, int stride) | |
324 | { | ||
325 | 260 | int w = s->seq.width; | |
326 | 260 | int h = s->seq.height; | |
327 | |||
328 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 260 times.
|
260 | av_assert0(stride >= w); |
329 | 260 | stride += 64; | |
330 | |||
331 |
2/2✓ Branch 0 taken 190 times.
✓ Branch 1 taken 70 times.
|
260 | if (s->buffer_stride >= stride) |
332 | 190 | return 0; | |
333 | 70 | s->buffer_stride = 0; | |
334 | |||
335 | 70 | av_freep(&s->edge_emu_buffer_base); | |
336 | 70 | memset(s->edge_emu_buffer, 0, sizeof(s->edge_emu_buffer)); | |
337 | 70 | av_freep(&s->mctmp); | |
338 | 70 | av_freep(&s->mcscratch); | |
339 | |||
340 | 70 | s->edge_emu_buffer_base = av_malloc_array(stride, MAX_BLOCKSIZE); | |
341 | |||
342 | 70 | s->mctmp = av_malloc_array((stride+MAX_BLOCKSIZE), (h+MAX_BLOCKSIZE) * sizeof(*s->mctmp)); | |
343 | 70 | s->mcscratch = av_malloc_array(stride, MAX_BLOCKSIZE); | |
344 | |||
345 |
3/6✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 70 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 70 times.
|
70 | if (!s->edge_emu_buffer_base || !s->mctmp || !s->mcscratch) |
346 | ✗ | return AVERROR(ENOMEM); | |
347 | |||
348 | 70 | s->buffer_stride = stride; | |
349 | 70 | return 0; | |
350 | } | ||
351 | |||
352 | 70 | static void free_sequence_buffers(DiracContext *s) | |
353 | { | ||
354 | int i, j, k; | ||
355 | |||
356 |
2/2✓ Branch 0 taken 980 times.
✓ Branch 1 taken 70 times.
|
1050 | for (i = 0; i < MAX_FRAMES; i++) { |
357 |
2/2✓ Branch 0 taken 38 times.
✓ Branch 1 taken 942 times.
|
980 | if (s->all_frames[i].avframe->data[0]) { |
358 | 38 | av_frame_unref(s->all_frames[i].avframe); | |
359 | 38 | memset(s->all_frames[i].interpolated, 0, sizeof(s->all_frames[i].interpolated)); | |
360 | } | ||
361 | |||
362 |
2/2✓ Branch 0 taken 2940 times.
✓ Branch 1 taken 980 times.
|
3920 | for (j = 0; j < 3; j++) |
363 |
2/2✓ Branch 0 taken 8820 times.
✓ Branch 1 taken 2940 times.
|
11760 | for (k = 1; k < 4; k++) |
364 | 8820 | av_freep(&s->all_frames[i].hpel_base[j][k]); | |
365 | } | ||
366 | |||
367 | 70 | memset(s->ref_frames, 0, sizeof(s->ref_frames)); | |
368 | 70 | memset(s->delay_frames, 0, sizeof(s->delay_frames)); | |
369 | |||
370 |
2/2✓ Branch 0 taken 210 times.
✓ Branch 1 taken 70 times.
|
280 | for (i = 0; i < 3; i++) { |
371 | 210 | av_freep(&s->plane[i].idwt.buf_base); | |
372 | 210 | av_freep(&s->plane[i].idwt.tmp); | |
373 | } | ||
374 | |||
375 | 70 | s->buffer_stride = 0; | |
376 | 70 | av_freep(&s->sbsplit); | |
377 | 70 | av_freep(&s->blmotion); | |
378 | 70 | av_freep(&s->edge_emu_buffer_base); | |
379 | |||
380 | 70 | av_freep(&s->mctmp); | |
381 | 70 | av_freep(&s->mcscratch); | |
382 | 70 | } | |
383 | |||
384 | static AVOnce dirac_arith_init = AV_ONCE_INIT; | ||
385 | |||
386 | 70 | static av_cold int dirac_decode_init(AVCodecContext *avctx) | |
387 | { | ||
388 | 70 | DiracContext *s = avctx->priv_data; | |
389 | int i, ret; | ||
390 | |||
391 | 70 | s->avctx = avctx; | |
392 | 70 | s->frame_number = -1; | |
393 | |||
394 | 70 | s->thread_buf = NULL; | |
395 | 70 | s->threads_num_buf = -1; | |
396 | 70 | s->thread_buf_size = -1; | |
397 | |||
398 | 70 | ff_diracdsp_init(&s->diracdsp); | |
399 | 70 | ff_mpegvideoencdsp_init(&s->mpvencdsp, avctx); | |
400 | 70 | ff_videodsp_init(&s->vdsp, 8); | |
401 | |||
402 |
2/2✓ Branch 0 taken 980 times.
✓ Branch 1 taken 70 times.
|
1050 | for (i = 0; i < MAX_FRAMES; i++) { |
403 | 980 | s->all_frames[i].avframe = av_frame_alloc(); | |
404 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 980 times.
|
980 | if (!s->all_frames[i].avframe) { |
405 | ✗ | while (i > 0) | |
406 | ✗ | av_frame_free(&s->all_frames[--i].avframe); | |
407 | ✗ | return AVERROR(ENOMEM); | |
408 | } | ||
409 | } | ||
410 | 70 | ret = ff_thread_once(&dirac_arith_init, ff_dirac_init_arith_tables); | |
411 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
|
70 | if (ret != 0) |
412 | ✗ | return AVERROR_UNKNOWN; | |
413 | |||
414 | 70 | return 0; | |
415 | } | ||
416 | |||
417 | 70 | static void dirac_decode_flush(AVCodecContext *avctx) | |
418 | { | ||
419 | 70 | DiracContext *s = avctx->priv_data; | |
420 | 70 | free_sequence_buffers(s); | |
421 | 70 | s->seen_sequence_header = 0; | |
422 | 70 | s->frame_number = -1; | |
423 | 70 | } | |
424 | |||
425 | 70 | static av_cold int dirac_decode_end(AVCodecContext *avctx) | |
426 | { | ||
427 | 70 | DiracContext *s = avctx->priv_data; | |
428 | int i; | ||
429 | |||
430 | 70 | dirac_decode_flush(avctx); | |
431 |
2/2✓ Branch 0 taken 980 times.
✓ Branch 1 taken 70 times.
|
1050 | for (i = 0; i < MAX_FRAMES; i++) |
432 | 980 | av_frame_free(&s->all_frames[i].avframe); | |
433 | |||
434 | 70 | av_freep(&s->thread_buf); | |
435 | 70 | av_freep(&s->slice_params_buf); | |
436 | |||
437 | 70 | return 0; | |
438 | } | ||
439 | |||
440 | 1949239 | static inline int coeff_unpack_golomb(GetBitContext *gb, int qfactor, int qoffset) | |
441 | { | ||
442 | 1949239 | int coeff = dirac_get_se_golomb(gb); | |
443 |
2/2✓ Branch 0 taken 170271 times.
✓ Branch 1 taken 1778968 times.
|
1949239 | const unsigned sign = FFSIGN(coeff); |
444 |
2/2✓ Branch 0 taken 336797 times.
✓ Branch 1 taken 1612442 times.
|
1949239 | if (coeff) |
445 | 336797 | coeff = sign*((sign * coeff * qfactor + qoffset) >> 2); | |
446 | 1949239 | return coeff; | |
447 | } | ||
448 | |||
449 | #define SIGN_CTX(x) (CTX_SIGN_ZERO + ((x) > 0) - ((x) < 0)) | ||
450 | |||
451 | #define UNPACK_ARITH(n, type) \ | ||
452 | static inline void coeff_unpack_arith_##n(DiracArith *c, int qfactor, int qoffset, \ | ||
453 | SubBand *b, type *buf, int x, int y) \ | ||
454 | { \ | ||
455 | int sign, sign_pred = 0, pred_ctx = CTX_ZPZN_F1; \ | ||
456 | unsigned coeff; \ | ||
457 | const int mstride = -(b->stride >> (1+b->pshift)); \ | ||
458 | if (b->parent) { \ | ||
459 | const type *pbuf = (type *)b->parent->ibuf; \ | ||
460 | const int stride = b->parent->stride >> (1+b->parent->pshift); \ | ||
461 | pred_ctx += !!pbuf[stride * (y>>1) + (x>>1)] << 1; \ | ||
462 | } \ | ||
463 | if (b->orientation == subband_hl) \ | ||
464 | sign_pred = buf[mstride]; \ | ||
465 | if (x) { \ | ||
466 | pred_ctx += !(buf[-1] | buf[mstride] | buf[-1 + mstride]); \ | ||
467 | if (b->orientation == subband_lh) \ | ||
468 | sign_pred = buf[-1]; \ | ||
469 | } else { \ | ||
470 | pred_ctx += !buf[mstride]; \ | ||
471 | } \ | ||
472 | coeff = dirac_get_arith_uint(c, pred_ctx, CTX_COEFF_DATA); \ | ||
473 | if (coeff) { \ | ||
474 | coeff = (coeff * qfactor + qoffset) >> 2; \ | ||
475 | sign = dirac_get_arith_bit(c, SIGN_CTX(sign_pred)); \ | ||
476 | coeff = (coeff ^ -sign) + sign; \ | ||
477 | } \ | ||
478 | *buf = coeff; \ | ||
479 | } \ | ||
480 | |||
481 |
14/14✓ Branch 0 taken 259740 times.
✓ Branch 1 taken 77360 times.
✓ Branch 2 taken 149532 times.
✓ Branch 3 taken 110208 times.
✓ Branch 4 taken 104524 times.
✓ Branch 5 taken 232576 times.
✓ Branch 6 taken 335110 times.
✓ Branch 7 taken 1990 times.
✓ Branch 8 taken 92635 times.
✓ Branch 9 taken 242475 times.
✓ Branch 11 taken 136865 times.
✓ Branch 12 taken 200235 times.
✓ Branch 13 taken 32492 times.
✓ Branch 14 taken 104373 times.
|
337100 | UNPACK_ARITH(8, int16_t) |
482 | ✗ | UNPACK_ARITH(10, int32_t) | |
483 | |||
484 | /** | ||
485 | * Decode the coeffs in the rectangle defined by left, right, top, bottom | ||
486 | * [DIRAC_STD] 13.4.3.2 Codeblock unpacking loop. codeblock() | ||
487 | */ | ||
488 | 82699 | static inline int codeblock(const DiracContext *s, SubBand *b, | |
489 | GetBitContext *gb, DiracArith *c, | ||
490 | int left, int right, int top, int bottom, | ||
491 | int blockcnt_one, int is_arith) | ||
492 | { | ||
493 | int x, y, zero_block; | ||
494 | int qoffset, qfactor; | ||
495 | uint8_t *buf; | ||
496 | |||
497 | /* check for any coded coefficients in this codeblock */ | ||
498 |
2/2✓ Branch 0 taken 82635 times.
✓ Branch 1 taken 64 times.
|
82699 | if (!blockcnt_one) { |
499 |
1/2✓ Branch 0 taken 82635 times.
✗ Branch 1 not taken.
|
82635 | if (is_arith) |
500 | 82635 | zero_block = dirac_get_arith_bit(c, CTX_ZERO_BLOCK); | |
501 | else | ||
502 | ✗ | zero_block = get_bits1(gb); | |
503 | |||
504 |
2/2✓ Branch 0 taken 77258 times.
✓ Branch 1 taken 5377 times.
|
82635 | if (zero_block) |
505 | 77258 | return 0; | |
506 | } | ||
507 | |||
508 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 5441 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
5441 | if (s->codeblock_mode && !(s->old_delta_quant && blockcnt_one)) { |
509 | int quant; | ||
510 | ✗ | if (is_arith) | |
511 | ✗ | quant = dirac_get_arith_int(c, CTX_DELTA_Q_F, CTX_DELTA_Q_DATA); | |
512 | else | ||
513 | ✗ | quant = dirac_get_se_golomb(gb); | |
514 | ✗ | if (quant > INT_MAX - b->quant || b->quant + quant < 0) { | |
515 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Invalid quant\n"); | |
516 | ✗ | return AVERROR_INVALIDDATA; | |
517 | } | ||
518 | ✗ | b->quant += quant; | |
519 | } | ||
520 | |||
521 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5441 times.
|
5441 | if (b->quant > (DIRAC_MAX_QUANT_INDEX - 1)) { |
522 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Unsupported quant %d\n", b->quant); | |
523 | ✗ | b->quant = 0; | |
524 | ✗ | return AVERROR_INVALIDDATA; | |
525 | } | ||
526 | |||
527 | 5441 | qfactor = ff_dirac_qscale_tab[b->quant]; | |
528 | /* TODO: context pointer? */ | ||
529 |
2/2✓ Branch 0 taken 1700 times.
✓ Branch 1 taken 3741 times.
|
5441 | if (!s->num_refs) |
530 | 1700 | qoffset = ff_dirac_qoffset_intra_tab[b->quant] + 2; | |
531 | else | ||
532 | 3741 | qoffset = ff_dirac_qoffset_inter_tab[b->quant] + 2; | |
533 | |||
534 | 5441 | buf = b->ibuf + top * b->stride; | |
535 |
1/2✓ Branch 0 taken 5441 times.
✗ Branch 1 not taken.
|
5441 | if (is_arith) { |
536 |
2/2✓ Branch 0 taken 40614 times.
✓ Branch 1 taken 5441 times.
|
46055 | for (y = top; y < bottom; y++) { |
537 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 40614 times.
|
40614 | if (c->error) |
538 | ✗ | return c->error; | |
539 |
2/2✓ Branch 0 taken 337100 times.
✓ Branch 1 taken 40614 times.
|
377714 | for (x = left; x < right; x++) { |
540 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 337100 times.
|
337100 | if (b->pshift) { |
541 | ✗ | coeff_unpack_arith_10(c, qfactor, qoffset, b, (int32_t*)(buf)+x, x, y); | |
542 | } else { | ||
543 | 337100 | coeff_unpack_arith_8(c, qfactor, qoffset, b, (int16_t*)(buf)+x, x, y); | |
544 | } | ||
545 | } | ||
546 | 40614 | buf += b->stride; | |
547 | } | ||
548 | } else { | ||
549 | ✗ | for (y = top; y < bottom; y++) { | |
550 | ✗ | if (get_bits_left(gb) < 1) | |
551 | ✗ | return AVERROR_INVALIDDATA; | |
552 | ✗ | for (x = left; x < right; x++) { | |
553 | ✗ | int val = coeff_unpack_golomb(gb, qfactor, qoffset); | |
554 | ✗ | if (b->pshift) { | |
555 | ✗ | AV_WN32(&buf[4*x], val); | |
556 | } else { | ||
557 | ✗ | AV_WN16(&buf[2*x], val); | |
558 | } | ||
559 | } | ||
560 | ✗ | buf += b->stride; | |
561 | } | ||
562 | } | ||
563 | 5441 | return 0; | |
564 | } | ||
565 | |||
566 | /** | ||
567 | * Dirac Specification -> | ||
568 | * 13.3 intra_dc_prediction(band) | ||
569 | */ | ||
570 | #define INTRA_DC_PRED(n, type) \ | ||
571 | static inline void intra_dc_prediction_##n(SubBand *b) \ | ||
572 | { \ | ||
573 | type *buf = (type*)b->ibuf; \ | ||
574 | int x, y; \ | ||
575 | \ | ||
576 | for (x = 1; x < b->width; x++) \ | ||
577 | buf[x] += buf[x-1]; \ | ||
578 | buf += (b->stride >> (1+b->pshift)); \ | ||
579 | \ | ||
580 | for (y = 1; y < b->height; y++) { \ | ||
581 | buf[0] += buf[-(b->stride >> (1+b->pshift))]; \ | ||
582 | \ | ||
583 | for (x = 1; x < b->width; x++) { \ | ||
584 | int pred = buf[x - 1] + buf[x - (b->stride >> (1+b->pshift))] + buf[x - (b->stride >> (1+b->pshift))-1]; \ | ||
585 | buf[x] += divide3(pred); \ | ||
586 | } \ | ||
587 | buf += (b->stride >> (1+b->pshift)); \ | ||
588 | } \ | ||
589 | } \ | ||
590 | |||
591 |
6/6✓ Branch 0 taken 2541 times.
✓ Branch 1 taken 99 times.
✓ Branch 3 taken 54879 times.
✓ Branch 4 taken 1881 times.
✓ Branch 5 taken 1881 times.
✓ Branch 6 taken 99 times.
|
59400 | INTRA_DC_PRED(8, int16_t) |
592 | ✗ | INTRA_DC_PRED(10, uint32_t) | |
593 | |||
594 | /** | ||
595 | * Dirac Specification -> | ||
596 | * 13.4.2 Non-skipped subbands. subband_coeffs() | ||
597 | */ | ||
598 | 930 | static av_always_inline int decode_subband_internal(const DiracContext *s, | |
599 | SubBand *b, int is_arith) | ||
600 | { | ||
601 | int cb_x, cb_y, left, right, top, bottom; | ||
602 | DiracArith c; | ||
603 | GetBitContext gb; | ||
604 | 930 | int cb_width = s->codeblock[b->level + (b->orientation != subband_ll)].width; | |
605 | 930 | int cb_height = s->codeblock[b->level + (b->orientation != subband_ll)].height; | |
606 | 930 | int blockcnt_one = (cb_width + cb_height) == 2; | |
607 | int ret; | ||
608 | |||
609 |
2/2✓ Branch 0 taken 263 times.
✓ Branch 1 taken 667 times.
|
930 | if (!b->length) |
610 | 263 | return 0; | |
611 | |||
612 | 667 | init_get_bits8(&gb, b->coeff_data, b->length); | |
613 | |||
614 |
1/2✓ Branch 0 taken 667 times.
✗ Branch 1 not taken.
|
667 | if (is_arith) |
615 | 667 | ff_dirac_init_arith_decoder(&c, &gb, b->length); | |
616 | |||
617 | 667 | top = 0; | |
618 |
2/2✓ Branch 0 taken 5305 times.
✓ Branch 1 taken 667 times.
|
5972 | for (cb_y = 0; cb_y < cb_height; cb_y++) { |
619 | 5305 | bottom = (b->height * (cb_y+1LL)) / cb_height; | |
620 | 5305 | left = 0; | |
621 |
2/2✓ Branch 0 taken 82699 times.
✓ Branch 1 taken 5305 times.
|
88004 | for (cb_x = 0; cb_x < cb_width; cb_x++) { |
622 | 82699 | right = (b->width * (cb_x+1LL)) / cb_width; | |
623 | 82699 | ret = codeblock(s, b, &gb, &c, left, right, top, bottom, blockcnt_one, is_arith); | |
624 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 82699 times.
|
82699 | if (ret < 0) |
625 | ✗ | return ret; | |
626 | 82699 | left = right; | |
627 | } | ||
628 | 5305 | top = bottom; | |
629 | } | ||
630 | |||
631 |
4/4✓ Branch 0 taken 64 times.
✓ Branch 1 taken 603 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 58 times.
|
667 | if (b->orientation == subband_ll && s->num_refs == 0) { |
632 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (s->pshift) { |
633 | ✗ | intra_dc_prediction_10(b); | |
634 | } else { | ||
635 | 6 | intra_dc_prediction_8(b); | |
636 | } | ||
637 | } | ||
638 | 667 | return 0; | |
639 | } | ||
640 | |||
641 | 930 | static int decode_subband_arith(AVCodecContext *avctx, void *b) | |
642 | { | ||
643 | 930 | const DiracContext *s = avctx->priv_data; | |
644 | 930 | return decode_subband_internal(s, b, 1); | |
645 | } | ||
646 | |||
647 | ✗ | static int decode_subband_golomb(AVCodecContext *avctx, void *arg) | |
648 | { | ||
649 | ✗ | const DiracContext *s = avctx->priv_data; | |
650 | ✗ | SubBand **b = arg; | |
651 | ✗ | return decode_subband_internal(s, *b, 0); | |
652 | } | ||
653 | |||
654 | /** | ||
655 | * Dirac Specification -> | ||
656 | * [DIRAC_STD] 13.4.1 core_transform_data() | ||
657 | */ | ||
658 | 93 | static int decode_component(DiracContext *s, int comp) | |
659 | { | ||
660 | 93 | AVCodecContext *avctx = s->avctx; | |
661 | SubBand *bands[3*MAX_DWT_LEVELS+1]; | ||
662 | enum dirac_subband orientation; | ||
663 | 93 | int level, num_bands = 0; | |
664 | int ret[3*MAX_DWT_LEVELS+1]; | ||
665 | int i; | ||
666 | 93 | int damaged_count = 0; | |
667 | |||
668 | /* Unpack all subbands at all levels. */ | ||
669 |
2/2✓ Branch 0 taken 279 times.
✓ Branch 1 taken 93 times.
|
372 | for (level = 0; level < s->wavelet_depth; level++) { |
670 |
2/2✓ Branch 0 taken 930 times.
✓ Branch 1 taken 279 times.
|
1209 | for (orientation = !!level; orientation < 4; orientation++) { |
671 | 930 | SubBand *b = &s->plane[comp].band[level][orientation]; | |
672 | 930 | bands[num_bands++] = b; | |
673 | |||
674 | 930 | align_get_bits(&s->gb); | |
675 | /* [DIRAC_STD] 13.4.2 subband() */ | ||
676 | 930 | b->length = get_interleaved_ue_golomb(&s->gb); | |
677 |
2/2✓ Branch 0 taken 667 times.
✓ Branch 1 taken 263 times.
|
930 | if (b->length) { |
678 | 667 | b->quant = get_interleaved_ue_golomb(&s->gb); | |
679 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 667 times.
|
667 | if (b->quant > (DIRAC_MAX_QUANT_INDEX - 1)) { |
680 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Unsupported quant %d\n", b->quant); | |
681 | ✗ | b->quant = 0; | |
682 | ✗ | return AVERROR_INVALIDDATA; | |
683 | } | ||
684 | 667 | align_get_bits(&s->gb); | |
685 | 667 | b->coeff_data = s->gb.buffer + get_bits_count(&s->gb)/8; | |
686 |
2/4✓ Branch 1 taken 667 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 667 times.
|
667 | if (b->length > FFMAX(get_bits_left(&s->gb)/8, 0)) { |
687 | ✗ | b->length = FFMAX(get_bits_left(&s->gb)/8, 0); | |
688 | ✗ | damaged_count ++; | |
689 | } | ||
690 | 667 | skip_bits_long(&s->gb, b->length*8); | |
691 | } | ||
692 | } | ||
693 | /* arithmetic coding has inter-level dependencies, so we can only execute one level at a time */ | ||
694 |
1/2✓ Branch 0 taken 279 times.
✗ Branch 1 not taken.
|
279 | if (s->is_arith) |
695 |
2/2✓ Branch 0 taken 186 times.
✓ Branch 1 taken 93 times.
|
279 | avctx->execute(avctx, decode_subband_arith, &s->plane[comp].band[level][!!level], |
696 |
2/2✓ Branch 0 taken 186 times.
✓ Branch 1 taken 93 times.
|
279 | ret + 3*level + !!level, 4-!!level, sizeof(SubBand)); |
697 | } | ||
698 | /* golomb coding has no inter-level dependencies, so we can execute all subbands in parallel */ | ||
699 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 93 times.
|
93 | if (!s->is_arith) |
700 | ✗ | avctx->execute(avctx, decode_subband_golomb, bands, ret, num_bands, sizeof(SubBand*)); | |
701 | |||
702 |
2/2✓ Branch 0 taken 930 times.
✓ Branch 1 taken 93 times.
|
1023 | for (i = 0; i < s->wavelet_depth * 3 + 1; i++) { |
703 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 930 times.
|
930 | if (ret[i] < 0) |
704 | ✗ | damaged_count++; | |
705 | } | ||
706 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 93 times.
|
93 | if (damaged_count > (s->wavelet_depth * 3 + 1) /2) |
707 | ✗ | return AVERROR_INVALIDDATA; | |
708 | |||
709 | 93 | return 0; | |
710 | } | ||
711 | |||
712 | #define PARSE_VALUES(type, x, gb, ebits, buf1, buf2) \ | ||
713 | type *buf = (type *)buf1; \ | ||
714 | buf[x] = coeff_unpack_golomb(gb, qfactor, qoffset); \ | ||
715 | if (get_bits_count(gb) >= ebits) \ | ||
716 | return; \ | ||
717 | if (buf2) { \ | ||
718 | buf = (type *)buf2; \ | ||
719 | buf[x] = coeff_unpack_golomb(gb, qfactor, qoffset); \ | ||
720 | if (get_bits_count(gb) >= ebits) \ | ||
721 | return; \ | ||
722 | } \ | ||
723 | |||
724 | 186000 | static void decode_subband(const DiracContext *s, GetBitContext *gb, int quant, | |
725 | int slice_x, int slice_y, int bits_end, | ||
726 | const SubBand *b1, const SubBand *b2) | ||
727 | { | ||
728 | 186000 | int left = b1->width * slice_x / s->num_x; | |
729 | 186000 | int right = b1->width *(slice_x+1) / s->num_x; | |
730 | 186000 | int top = b1->height * slice_y / s->num_y; | |
731 | 186000 | int bottom = b1->height *(slice_y+1) / s->num_y; | |
732 | |||
733 | int qfactor, qoffset; | ||
734 | |||
735 | 186000 | uint8_t *buf1 = b1->ibuf + top * b1->stride; | |
736 |
2/2✓ Branch 0 taken 93000 times.
✓ Branch 1 taken 93000 times.
|
186000 | uint8_t *buf2 = b2 ? b2->ibuf + top * b2->stride: NULL; |
737 | int x, y; | ||
738 | |||
739 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 186000 times.
|
186000 | if (quant > (DIRAC_MAX_QUANT_INDEX - 1)) { |
740 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Unsupported quant %d\n", quant); | |
741 | ✗ | return; | |
742 | } | ||
743 | 186000 | qfactor = ff_dirac_qscale_tab[quant]; | |
744 | 186000 | qoffset = ff_dirac_qoffset_intra_tab[quant] + 2; | |
745 | /* we have to constantly check for overread since the spec explicitly | ||
746 | requires this, with the meaning that all remaining coeffs are set to 0 */ | ||
747 |
2/2✓ Branch 1 taken 38746 times.
✓ Branch 2 taken 147254 times.
|
186000 | if (get_bits_count(gb) >= bits_end) |
748 | 38746 | return; | |
749 | |||
750 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 147254 times.
|
147254 | if (s->pshift) { |
751 | ✗ | for (y = top; y < bottom; y++) { | |
752 | ✗ | for (x = left; x < right; x++) { | |
753 | ✗ | PARSE_VALUES(int32_t, x, gb, bits_end, buf1, buf2); | |
754 | } | ||
755 | ✗ | buf1 += b1->stride; | |
756 | ✗ | if (buf2) | |
757 | ✗ | buf2 += b2->stride; | |
758 | } | ||
759 | } | ||
760 | else { | ||
761 |
2/2✓ Branch 0 taken 385191 times.
✓ Branch 1 taken 133708 times.
|
518899 | for (y = top; y < bottom; y++) { |
762 |
2/2✓ Branch 0 taken 1464362 times.
✓ Branch 1 taken 371645 times.
|
1836007 | for (x = left; x < right; x++) { |
763 |
6/6✓ Branch 2 taken 11052 times.
✓ Branch 3 taken 1453310 times.
✓ Branch 4 taken 484877 times.
✓ Branch 5 taken 968433 times.
✓ Branch 8 taken 2494 times.
✓ Branch 9 taken 482383 times.
|
1464362 | PARSE_VALUES(int16_t, x, gb, bits_end, buf1, buf2); |
764 | } | ||
765 | 371645 | buf1 += b1->stride; | |
766 |
2/2✓ Branch 0 taken 173605 times.
✓ Branch 1 taken 198040 times.
|
371645 | if (buf2) |
767 | 173605 | buf2 += b2->stride; | |
768 | } | ||
769 | } | ||
770 | } | ||
771 | |||
772 | /** | ||
773 | * Dirac Specification -> | ||
774 | * 13.5.2 Slices. slice(sx,sy) | ||
775 | */ | ||
776 | 9300 | static int decode_lowdelay_slice(AVCodecContext *avctx, void *arg) | |
777 | { | ||
778 | 9300 | const DiracContext *s = avctx->priv_data; | |
779 | 9300 | DiracSlice *slice = arg; | |
780 | 9300 | GetBitContext *gb = &slice->gb; | |
781 | enum dirac_subband orientation; | ||
782 | int level, quant, chroma_bits, chroma_end; | ||
783 | |||
784 | 9300 | int quant_base = get_bits(gb, 7); /*[DIRAC_STD] qindex */ | |
785 | 9300 | int length_bits = av_log2(8 * slice->bytes)+1; | |
786 | 9300 | int luma_bits = get_bits_long(gb, length_bits); | |
787 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 9300 times.
|
9300 | int luma_end = get_bits_count(gb) + FFMIN(luma_bits, get_bits_left(gb)); |
788 | |||
789 | /* [DIRAC_STD] 13.5.5.2 luma_slice_band */ | ||
790 |
2/2✓ Branch 0 taken 27900 times.
✓ Branch 1 taken 9300 times.
|
37200 | for (level = 0; level < s->wavelet_depth; level++) |
791 |
2/2✓ Branch 0 taken 93000 times.
✓ Branch 1 taken 27900 times.
|
120900 | for (orientation = !!level; orientation < 4; orientation++) { |
792 | 93000 | quant = FFMAX(quant_base - s->lowdelay.quant[level][orientation], 0); | |
793 | 93000 | decode_subband(s, gb, quant, slice->slice_x, slice->slice_y, luma_end, | |
794 | &s->plane[0].band[level][orientation], NULL); | ||
795 | } | ||
796 | |||
797 | /* consume any unused bits from luma */ | ||
798 | 9300 | skip_bits_long(gb, get_bits_count(gb) - luma_end); | |
799 | |||
800 | 9300 | chroma_bits = 8*slice->bytes - 7 - length_bits - luma_bits; | |
801 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 9300 times.
|
9300 | chroma_end = get_bits_count(gb) + FFMIN(chroma_bits, get_bits_left(gb)); |
802 | /* [DIRAC_STD] 13.5.5.3 chroma_slice_band */ | ||
803 |
2/2✓ Branch 0 taken 27900 times.
✓ Branch 1 taken 9300 times.
|
37200 | for (level = 0; level < s->wavelet_depth; level++) |
804 |
2/2✓ Branch 0 taken 93000 times.
✓ Branch 1 taken 27900 times.
|
120900 | for (orientation = !!level; orientation < 4; orientation++) { |
805 | 93000 | quant = FFMAX(quant_base - s->lowdelay.quant[level][orientation], 0); | |
806 | 93000 | decode_subband(s, gb, quant, slice->slice_x, slice->slice_y, chroma_end, | |
807 | &s->plane[1].band[level][orientation], | ||
808 | &s->plane[2].band[level][orientation]); | ||
809 | } | ||
810 | |||
811 | 9300 | return 0; | |
812 | } | ||
813 | |||
814 | typedef struct SliceCoeffs { | ||
815 | int left; | ||
816 | int top; | ||
817 | int tot_h; | ||
818 | int tot_v; | ||
819 | int tot; | ||
820 | } SliceCoeffs; | ||
821 | |||
822 | 117841 | static int subband_coeffs(const DiracContext *s, int x, int y, int p, | |
823 | SliceCoeffs c[MAX_DWT_LEVELS]) | ||
824 | { | ||
825 | 117841 | int level, coef = 0; | |
826 |
2/2✓ Branch 0 taken 471333 times.
✓ Branch 1 taken 117841 times.
|
589174 | for (level = 0; level < s->wavelet_depth; level++) { |
827 | 471333 | SliceCoeffs *o = &c[level]; | |
828 | 471333 | const SubBand *b = &s->plane[p].band[level][3]; /* orientation doens't matter */ | |
829 | 471333 | o->top = b->height * y / s->num_y; | |
830 | 471333 | o->left = b->width * x / s->num_x; | |
831 | 471333 | o->tot_h = ((b->width * (x + 1)) / s->num_x) - o->left; | |
832 | 471333 | o->tot_v = ((b->height * (y + 1)) / s->num_y) - o->top; | |
833 | 471333 | o->tot = o->tot_h*o->tot_v; | |
834 |
2/2✓ Branch 0 taken 353492 times.
✓ Branch 1 taken 117841 times.
|
471333 | coef += o->tot * (4 - !!level); |
835 | } | ||
836 | 117841 | return coef; | |
837 | } | ||
838 | |||
839 | /** | ||
840 | * VC-2 Specification -> | ||
841 | * 13.5.3 hq_slice(sx,sy) | ||
842 | */ | ||
843 | 39204 | static int decode_hq_slice(const DiracContext *s, DiracSlice *slice, uint8_t *tmp_buf) | |
844 | { | ||
845 | int i, level, orientation, quant_idx; | ||
846 | int qfactor[MAX_DWT_LEVELS][4], qoffset[MAX_DWT_LEVELS][4]; | ||
847 | 39204 | GetBitContext *gb = &slice->gb; | |
848 | SliceCoeffs coeffs_num[MAX_DWT_LEVELS]; | ||
849 | |||
850 | 39204 | skip_bits_long(gb, 8*s->highquality.prefix_bytes); | |
851 | 39204 | quant_idx = get_bits(gb, 8); | |
852 | |||
853 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 39204 times.
|
39204 | if (quant_idx > DIRAC_MAX_QUANT_INDEX - 1) { |
854 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Invalid quantization index - %i\n", quant_idx); | |
855 | ✗ | return AVERROR_INVALIDDATA; | |
856 | } | ||
857 | |||
858 | /* Slice quantization (slice_quantizers() in the specs) */ | ||
859 |
2/2✓ Branch 0 taken 156816 times.
✓ Branch 1 taken 39204 times.
|
196020 | for (level = 0; level < s->wavelet_depth; level++) { |
860 |
2/2✓ Branch 0 taken 509652 times.
✓ Branch 1 taken 156816 times.
|
666468 | for (orientation = !!level; orientation < 4; orientation++) { |
861 | 509652 | const int quant = FFMAX(quant_idx - s->lowdelay.quant[level][orientation], 0); | |
862 | 509652 | qfactor[level][orientation] = ff_dirac_qscale_tab[quant]; | |
863 | 509652 | qoffset[level][orientation] = ff_dirac_qoffset_intra_tab[quant] + 2; | |
864 | } | ||
865 | } | ||
866 | |||
867 | /* Luma + 2 Chroma planes */ | ||
868 |
2/2✓ Branch 0 taken 117612 times.
✓ Branch 1 taken 39204 times.
|
156816 | for (i = 0; i < 3; i++) { |
869 | 117612 | int coef_num, coef_par, off = 0; | |
870 | 117612 | int64_t length = s->highquality.size_scaler*get_bits(gb, 8); | |
871 | 117612 | int64_t bits_end = get_bits_count(gb) + 8*length; | |
872 | 117612 | const uint8_t *addr = align_get_bits(gb); | |
873 | |||
874 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 117612 times.
|
117612 | if (length*8 > get_bits_left(gb)) { |
875 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "end too far away\n"); | |
876 | ✗ | return AVERROR_INVALIDDATA; | |
877 | } | ||
878 | |||
879 | 117612 | coef_num = subband_coeffs(s, slice->slice_x, slice->slice_y, i, coeffs_num); | |
880 | |||
881 |
2/2✓ Branch 0 taken 85536 times.
✓ Branch 1 taken 32076 times.
|
117612 | if (s->pshift) |
882 | 85536 | coef_par = ff_dirac_golomb_read_32bit(addr, length, | |
883 | tmp_buf, coef_num); | ||
884 | else | ||
885 | 32076 | coef_par = ff_dirac_golomb_read_16bit(addr, length, | |
886 | tmp_buf, coef_num); | ||
887 | |||
888 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 117612 times.
|
117612 | if (coef_num > coef_par) { |
889 | ✗ | const int start_b = coef_par * (1 << (s->pshift + 1)); | |
890 | ✗ | const int end_b = coef_num * (1 << (s->pshift + 1)); | |
891 | ✗ | memset(&tmp_buf[start_b], 0, end_b - start_b); | |
892 | } | ||
893 | |||
894 |
2/2✓ Branch 0 taken 470448 times.
✓ Branch 1 taken 117612 times.
|
588060 | for (level = 0; level < s->wavelet_depth; level++) { |
895 | 470448 | const SliceCoeffs *c = &coeffs_num[level]; | |
896 |
2/2✓ Branch 0 taken 1528956 times.
✓ Branch 1 taken 470448 times.
|
1999404 | for (orientation = !!level; orientation < 4; orientation++) { |
897 | 1528956 | const SubBand *b1 = &s->plane[i].band[level][orientation]; | |
898 | 1528956 | uint8_t *buf = b1->ibuf + c->top * b1->stride + (c->left << (s->pshift + 1)); | |
899 | |||
900 | /* Change to c->tot_h <= 4 for AVX2 dequantization */ | ||
901 |
2/2✓ Branch 0 taken 641520 times.
✓ Branch 1 taken 887436 times.
|
1528956 | const int qfunc = s->pshift + 2*(c->tot_h <= 2); |
902 | 1528956 | s->diracdsp.dequant_subband[qfunc](&tmp_buf[off], buf, b1->stride, | |
903 | qfactor[level][orientation], | ||
904 | qoffset[level][orientation], | ||
905 | 1528956 | c->tot_v, c->tot_h); | |
906 | |||
907 | 1528956 | off += c->tot << (s->pshift + 1); | |
908 | } | ||
909 | } | ||
910 | |||
911 | 117612 | skip_bits_long(gb, bits_end - get_bits_count(gb)); | |
912 | } | ||
913 | |||
914 | 39204 | return 0; | |
915 | } | ||
916 | |||
917 | 3564 | static int decode_hq_slice_row(AVCodecContext *avctx, void *arg, int jobnr, int threadnr) | |
918 | { | ||
919 | int i; | ||
920 | 3564 | const DiracContext *s = avctx->priv_data; | |
921 | 3564 | DiracSlice *slices = ((DiracSlice *)arg) + s->num_x*jobnr; | |
922 | 3564 | uint8_t *thread_buf = &s->thread_buf[s->thread_buf_size*threadnr]; | |
923 |
2/2✓ Branch 0 taken 39204 times.
✓ Branch 1 taken 3564 times.
|
42768 | for (i = 0; i < s->num_x; i++) |
924 | 39204 | decode_hq_slice(s, &slices[i], thread_buf); | |
925 | 3564 | return 0; | |
926 | } | ||
927 | |||
928 | /** | ||
929 | * Dirac Specification -> | ||
930 | * 13.5.1 low_delay_transform_data() | ||
931 | */ | ||
932 | 229 | static int decode_lowdelay(DiracContext *s) | |
933 | { | ||
934 | 229 | AVCodecContext *avctx = s->avctx; | |
935 | int slice_x, slice_y, bufsize; | ||
936 | 229 | int64_t coef_buf_size, bytes = 0; | |
937 | const uint8_t *buf; | ||
938 | DiracSlice *slices; | ||
939 | SliceCoeffs tmp[MAX_DWT_LEVELS]; | ||
940 | 229 | int slice_num = 0; | |
941 | |||
942 |
2/2✓ Branch 0 taken 68 times.
✓ Branch 1 taken 161 times.
|
229 | if (s->slice_params_num_buf != (s->num_x * s->num_y)) { |
943 | 68 | s->slice_params_buf = av_realloc_f(s->slice_params_buf, s->num_x * s->num_y, sizeof(DiracSlice)); | |
944 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 68 times.
|
68 | if (!s->slice_params_buf) { |
945 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "slice params buffer allocation failure\n"); | |
946 | ✗ | s->slice_params_num_buf = 0; | |
947 | ✗ | return AVERROR(ENOMEM); | |
948 | } | ||
949 | 68 | s->slice_params_num_buf = s->num_x * s->num_y; | |
950 | } | ||
951 | 229 | slices = s->slice_params_buf; | |
952 | |||
953 | /* 8 becacuse that's how much the golomb reader could overread junk data | ||
954 | * from another plane/slice at most, and 512 because SIMD */ | ||
955 | 229 | coef_buf_size = subband_coeffs(s, s->num_x - 1, s->num_y - 1, 0, tmp) + 8; | |
956 | 229 | coef_buf_size = (coef_buf_size << (1 + s->pshift)) + 512; | |
957 | |||
958 |
2/2✓ Branch 0 taken 161 times.
✓ Branch 1 taken 68 times.
|
229 | if (s->threads_num_buf != avctx->thread_count || |
959 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 161 times.
|
161 | s->thread_buf_size != coef_buf_size) { |
960 | 68 | s->threads_num_buf = avctx->thread_count; | |
961 | 68 | s->thread_buf_size = coef_buf_size; | |
962 | 68 | s->thread_buf = av_realloc_f(s->thread_buf, avctx->thread_count, s->thread_buf_size); | |
963 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 68 times.
|
68 | if (!s->thread_buf) { |
964 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "thread buffer allocation failure\n"); | |
965 | ✗ | return AVERROR(ENOMEM); | |
966 | } | ||
967 | } | ||
968 | |||
969 | 229 | align_get_bits(&s->gb); | |
970 | /*[DIRAC_STD] 13.5.2 Slices. slice(sx,sy) */ | ||
971 | 229 | buf = s->gb.buffer + get_bits_count(&s->gb)/8; | |
972 | 229 | bufsize = get_bits_left(&s->gb); | |
973 | |||
974 |
2/2✓ Branch 0 taken 198 times.
✓ Branch 1 taken 31 times.
|
229 | if (s->hq_picture) { |
975 | int i; | ||
976 | |||
977 |
3/4✓ Branch 0 taken 3564 times.
✓ Branch 1 taken 198 times.
✓ Branch 2 taken 3564 times.
✗ Branch 3 not taken.
|
3762 | for (slice_y = 0; bufsize > 0 && slice_y < s->num_y; slice_y++) { |
978 |
4/4✓ Branch 0 taken 42570 times.
✓ Branch 1 taken 198 times.
✓ Branch 2 taken 39204 times.
✓ Branch 3 taken 3366 times.
|
42768 | for (slice_x = 0; bufsize > 0 && slice_x < s->num_x; slice_x++) { |
979 | 39204 | bytes = s->highquality.prefix_bytes + 1; | |
980 |
2/2✓ Branch 0 taken 117612 times.
✓ Branch 1 taken 39204 times.
|
156816 | for (i = 0; i < 3; i++) { |
981 |
1/2✓ Branch 0 taken 117612 times.
✗ Branch 1 not taken.
|
117612 | if (bytes <= bufsize/8) |
982 | 117612 | bytes += buf[bytes] * s->highquality.size_scaler + 1; | |
983 | } | ||
984 |
2/4✓ Branch 0 taken 39204 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 39204 times.
|
39204 | if (bytes >= INT_MAX || bytes*8 > bufsize) { |
985 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "too many bytes\n"); | |
986 | ✗ | return AVERROR_INVALIDDATA; | |
987 | } | ||
988 | |||
989 | 39204 | slices[slice_num].bytes = bytes; | |
990 | 39204 | slices[slice_num].slice_x = slice_x; | |
991 | 39204 | slices[slice_num].slice_y = slice_y; | |
992 | 39204 | init_get_bits(&slices[slice_num].gb, buf, bufsize); | |
993 | 39204 | slice_num++; | |
994 | |||
995 | 39204 | buf += bytes; | |
996 |
1/2✓ Branch 0 taken 39204 times.
✗ Branch 1 not taken.
|
39204 | if (bufsize/8 >= bytes) |
997 | 39204 | bufsize -= bytes*8; | |
998 | else | ||
999 | ✗ | bufsize = 0; | |
1000 | } | ||
1001 | } | ||
1002 | |||
1003 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
|
198 | if (s->num_x*s->num_y != slice_num) { |
1004 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "too few slices\n"); | |
1005 | ✗ | return AVERROR_INVALIDDATA; | |
1006 | } | ||
1007 | |||
1008 | 198 | avctx->execute2(avctx, decode_hq_slice_row, slices, NULL, s->num_y); | |
1009 | } else { | ||
1010 |
3/4✓ Branch 0 taken 465 times.
✓ Branch 1 taken 31 times.
✓ Branch 2 taken 465 times.
✗ Branch 3 not taken.
|
496 | for (slice_y = 0; bufsize > 0 && slice_y < s->num_y; slice_y++) { |
1011 |
4/4✓ Branch 0 taken 9734 times.
✓ Branch 1 taken 31 times.
✓ Branch 2 taken 9300 times.
✓ Branch 3 taken 434 times.
|
9765 | for (slice_x = 0; bufsize > 0 && slice_x < s->num_x; slice_x++) { |
1012 | 9300 | bytes = (slice_num+1) * (int64_t)s->lowdelay.bytes.num / s->lowdelay.bytes.den | |
1013 | 9300 | - slice_num * (int64_t)s->lowdelay.bytes.num / s->lowdelay.bytes.den; | |
1014 |
2/4✓ Branch 0 taken 9300 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9300 times.
|
9300 | if (bytes >= INT_MAX || bytes*8 > bufsize) { |
1015 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "too many bytes\n"); | |
1016 | ✗ | return AVERROR_INVALIDDATA; | |
1017 | } | ||
1018 | 9300 | slices[slice_num].bytes = bytes; | |
1019 | 9300 | slices[slice_num].slice_x = slice_x; | |
1020 | 9300 | slices[slice_num].slice_y = slice_y; | |
1021 | 9300 | init_get_bits(&slices[slice_num].gb, buf, bufsize); | |
1022 | 9300 | slice_num++; | |
1023 | |||
1024 | 9300 | buf += bytes; | |
1025 |
1/2✓ Branch 0 taken 9300 times.
✗ Branch 1 not taken.
|
9300 | if (bufsize/8 >= bytes) |
1026 | 9300 | bufsize -= bytes*8; | |
1027 | else | ||
1028 | ✗ | bufsize = 0; | |
1029 | } | ||
1030 | } | ||
1031 | 31 | avctx->execute(avctx, decode_lowdelay_slice, slices, NULL, slice_num, | |
1032 | sizeof(DiracSlice)); /* [DIRAC_STD] 13.5.2 Slices */ | ||
1033 | } | ||
1034 | |||
1035 |
2/2✓ Branch 0 taken 31 times.
✓ Branch 1 taken 198 times.
|
229 | if (s->dc_prediction) { |
1036 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | if (s->pshift) { |
1037 | ✗ | intra_dc_prediction_10(&s->plane[0].band[0][0]); /* [DIRAC_STD] 13.3 intra_dc_prediction() */ | |
1038 | ✗ | intra_dc_prediction_10(&s->plane[1].band[0][0]); /* [DIRAC_STD] 13.3 intra_dc_prediction() */ | |
1039 | ✗ | intra_dc_prediction_10(&s->plane[2].band[0][0]); /* [DIRAC_STD] 13.3 intra_dc_prediction() */ | |
1040 | } else { | ||
1041 | 31 | intra_dc_prediction_8(&s->plane[0].band[0][0]); | |
1042 | 31 | intra_dc_prediction_8(&s->plane[1].band[0][0]); | |
1043 | 31 | intra_dc_prediction_8(&s->plane[2].band[0][0]); | |
1044 | } | ||
1045 | } | ||
1046 | |||
1047 | 229 | return 0; | |
1048 | } | ||
1049 | |||
1050 | 260 | static void init_planes(DiracContext *s) | |
1051 | { | ||
1052 | int i, w, h, level, orientation; | ||
1053 | |||
1054 |
2/2✓ Branch 0 taken 780 times.
✓ Branch 1 taken 260 times.
|
1040 | for (i = 0; i < 3; i++) { |
1055 | 780 | Plane *p = &s->plane[i]; | |
1056 | |||
1057 |
2/2✓ Branch 0 taken 520 times.
✓ Branch 1 taken 260 times.
|
780 | p->width = s->seq.width >> (i ? s->chroma_x_shift : 0); |
1058 |
2/2✓ Branch 0 taken 520 times.
✓ Branch 1 taken 260 times.
|
780 | p->height = s->seq.height >> (i ? s->chroma_y_shift : 0); |
1059 | 780 | p->idwt.width = w = CALC_PADDING(p->width , s->wavelet_depth); | |
1060 | 780 | p->idwt.height = h = CALC_PADDING(p->height, s->wavelet_depth); | |
1061 | 780 | p->idwt.stride = FFALIGN(p->idwt.width, 8) << (1 + s->pshift); | |
1062 | |||
1063 |
2/2✓ Branch 0 taken 2934 times.
✓ Branch 1 taken 780 times.
|
3714 | for (level = s->wavelet_depth-1; level >= 0; level--) { |
1064 | 2934 | w = w>>1; | |
1065 | 2934 | h = h>>1; | |
1066 |
2/2✓ Branch 0 taken 9582 times.
✓ Branch 1 taken 2934 times.
|
12516 | for (orientation = !!level; orientation < 4; orientation++) { |
1067 | 9582 | SubBand *b = &p->band[level][orientation]; | |
1068 | |||
1069 | 9582 | b->pshift = s->pshift; | |
1070 | 9582 | b->ibuf = p->idwt.buf; | |
1071 | 9582 | b->level = level; | |
1072 | 9582 | b->stride = p->idwt.stride << (s->wavelet_depth - level); | |
1073 | 9582 | b->width = w; | |
1074 | 9582 | b->height = h; | |
1075 | 9582 | b->orientation = orientation; | |
1076 | |||
1077 |
2/2✓ Branch 0 taken 5868 times.
✓ Branch 1 taken 3714 times.
|
9582 | if (orientation & 1) |
1078 | 5868 | b->ibuf += w << (1+b->pshift); | |
1079 |
2/2✓ Branch 0 taken 5868 times.
✓ Branch 1 taken 3714 times.
|
9582 | if (orientation > 1) |
1080 | 5868 | b->ibuf += (b->stride>>1); | |
1081 | |||
1082 |
2/2✓ Branch 0 taken 6462 times.
✓ Branch 1 taken 3120 times.
|
9582 | if (level) |
1083 | 6462 | b->parent = &p->band[level-1][orientation]; | |
1084 | } | ||
1085 | } | ||
1086 | |||
1087 |
2/2✓ Branch 0 taken 520 times.
✓ Branch 1 taken 260 times.
|
780 | if (i > 0) { |
1088 | 520 | p->xblen = s->plane[0].xblen >> s->chroma_x_shift; | |
1089 | 520 | p->yblen = s->plane[0].yblen >> s->chroma_y_shift; | |
1090 | 520 | p->xbsep = s->plane[0].xbsep >> s->chroma_x_shift; | |
1091 | 520 | p->ybsep = s->plane[0].ybsep >> s->chroma_y_shift; | |
1092 | } | ||
1093 | |||
1094 | 780 | p->xoffset = (p->xblen - p->xbsep)/2; | |
1095 | 780 | p->yoffset = (p->yblen - p->ybsep)/2; | |
1096 | } | ||
1097 | 260 | } | |
1098 | |||
1099 | /** | ||
1100 | * Unpack the motion compensation parameters | ||
1101 | * Dirac Specification -> | ||
1102 | * 11.2 Picture prediction data. picture_prediction() | ||
1103 | */ | ||
1104 | 29 | static int dirac_unpack_prediction_parameters(DiracContext *s) | |
1105 | { | ||
1106 | static const uint8_t default_blen[] = { 4, 12, 16, 24 }; | ||
1107 | |||
1108 | 29 | GetBitContext *gb = &s->gb; | |
1109 | unsigned idx, ref; | ||
1110 | |||
1111 | 29 | align_get_bits(gb); | |
1112 | /* [DIRAC_STD] 11.2.2 Block parameters. block_parameters() */ | ||
1113 | /* Luma and Chroma are equal. 11.2.3 */ | ||
1114 | 29 | idx = get_interleaved_ue_golomb(gb); /* [DIRAC_STD] index */ | |
1115 | |||
1116 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 29 times.
|
29 | if (idx > 4) { |
1117 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Block prediction index too high\n"); | |
1118 | ✗ | return AVERROR_INVALIDDATA; | |
1119 | } | ||
1120 | |||
1121 |
1/2✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
|
29 | if (idx == 0) { |
1122 | 29 | s->plane[0].xblen = get_interleaved_ue_golomb(gb); | |
1123 | 29 | s->plane[0].yblen = get_interleaved_ue_golomb(gb); | |
1124 | 29 | s->plane[0].xbsep = get_interleaved_ue_golomb(gb); | |
1125 | 29 | s->plane[0].ybsep = get_interleaved_ue_golomb(gb); | |
1126 | } else { | ||
1127 | /*[DIRAC_STD] preset_block_params(index). Table 11.1 */ | ||
1128 | ✗ | s->plane[0].xblen = default_blen[idx-1]; | |
1129 | ✗ | s->plane[0].yblen = default_blen[idx-1]; | |
1130 | ✗ | s->plane[0].xbsep = 4 * idx; | |
1131 | ✗ | s->plane[0].ybsep = 4 * idx; | |
1132 | } | ||
1133 | /*[DIRAC_STD] 11.2.4 motion_data_dimensions() | ||
1134 | Calculated in function dirac_unpack_block_motion_data */ | ||
1135 | |||
1136 |
1/2✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
|
29 | if (s->plane[0].xblen % (1 << s->chroma_x_shift) != 0 || |
1137 |
1/2✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
|
29 | s->plane[0].yblen % (1 << s->chroma_y_shift) != 0 || |
1138 |
2/4✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 29 times.
|
29 | !s->plane[0].xblen || !s->plane[0].yblen) { |
1139 | ✗ | av_log(s->avctx, AV_LOG_ERROR, | |
1140 | "invalid x/y block length (%d/%d) for x/y chroma shift (%d/%d)\n", | ||
1141 | ✗ | s->plane[0].xblen, s->plane[0].yblen, s->chroma_x_shift, s->chroma_y_shift); | |
1142 | ✗ | return AVERROR_INVALIDDATA; | |
1143 | } | ||
1144 |
4/8✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 29 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 29 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 29 times.
|
29 | if (!s->plane[0].xbsep || !s->plane[0].ybsep || s->plane[0].xbsep < s->plane[0].xblen/2 || s->plane[0].ybsep < s->plane[0].yblen/2) { |
1145 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Block separation too small\n"); | |
1146 | ✗ | return AVERROR_INVALIDDATA; | |
1147 | } | ||
1148 |
2/4✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 29 times.
|
29 | if (s->plane[0].xbsep > s->plane[0].xblen || s->plane[0].ybsep > s->plane[0].yblen) { |
1149 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Block separation greater than size\n"); | |
1150 | ✗ | return AVERROR_INVALIDDATA; | |
1151 | } | ||
1152 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 29 times.
|
29 | if (FFMAX(s->plane[0].xblen, s->plane[0].yblen) > MAX_BLOCKSIZE) { |
1153 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Unsupported large block size\n"); | |
1154 | ✗ | return AVERROR_PATCHWELCOME; | |
1155 | } | ||
1156 | |||
1157 | /*[DIRAC_STD] 11.2.5 Motion vector precision. motion_vector_precision() | ||
1158 | Read motion vector precision */ | ||
1159 | 29 | s->mv_precision = get_interleaved_ue_golomb(gb); | |
1160 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 29 times.
|
29 | if (s->mv_precision > 3) { |
1161 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "MV precision finer than eighth-pel\n"); | |
1162 | ✗ | return AVERROR_INVALIDDATA; | |
1163 | } | ||
1164 | |||
1165 | /*[DIRAC_STD] 11.2.6 Global motion. global_motion() | ||
1166 | Read the global motion compensation parameters */ | ||
1167 | 29 | s->globalmc_flag = get_bits1(gb); | |
1168 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 29 times.
|
29 | if (s->globalmc_flag) { |
1169 | ✗ | memset(s->globalmc, 0, sizeof(s->globalmc)); | |
1170 | /* [DIRAC_STD] pan_tilt(gparams) */ | ||
1171 | ✗ | for (ref = 0; ref < s->num_refs; ref++) { | |
1172 | ✗ | if (get_bits1(gb)) { | |
1173 | ✗ | s->globalmc[ref].pan_tilt[0] = dirac_get_se_golomb(gb); | |
1174 | ✗ | s->globalmc[ref].pan_tilt[1] = dirac_get_se_golomb(gb); | |
1175 | } | ||
1176 | /* [DIRAC_STD] zoom_rotate_shear(gparams) | ||
1177 | zoom/rotation/shear parameters */ | ||
1178 | ✗ | if (get_bits1(gb)) { | |
1179 | ✗ | s->globalmc[ref].zrs_exp = get_interleaved_ue_golomb(gb); | |
1180 | ✗ | s->globalmc[ref].zrs[0][0] = dirac_get_se_golomb(gb); | |
1181 | ✗ | s->globalmc[ref].zrs[0][1] = dirac_get_se_golomb(gb); | |
1182 | ✗ | s->globalmc[ref].zrs[1][0] = dirac_get_se_golomb(gb); | |
1183 | ✗ | s->globalmc[ref].zrs[1][1] = dirac_get_se_golomb(gb); | |
1184 | } else { | ||
1185 | ✗ | s->globalmc[ref].zrs[0][0] = 1; | |
1186 | ✗ | s->globalmc[ref].zrs[1][1] = 1; | |
1187 | } | ||
1188 | /* [DIRAC_STD] perspective(gparams) */ | ||
1189 | ✗ | if (get_bits1(gb)) { | |
1190 | ✗ | s->globalmc[ref].perspective_exp = get_interleaved_ue_golomb(gb); | |
1191 | ✗ | s->globalmc[ref].perspective[0] = dirac_get_se_golomb(gb); | |
1192 | ✗ | s->globalmc[ref].perspective[1] = dirac_get_se_golomb(gb); | |
1193 | } | ||
1194 | ✗ | if (s->globalmc[ref].perspective_exp + (uint64_t)s->globalmc[ref].zrs_exp > 30) { | |
1195 | ✗ | return AVERROR_INVALIDDATA; | |
1196 | } | ||
1197 | |||
1198 | } | ||
1199 | } | ||
1200 | |||
1201 | /*[DIRAC_STD] 11.2.7 Picture prediction mode. prediction_mode() | ||
1202 | Picture prediction mode, not currently used. */ | ||
1203 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 29 times.
|
29 | if (get_interleaved_ue_golomb(gb)) { |
1204 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Unknown picture prediction mode\n"); | |
1205 | ✗ | return AVERROR_INVALIDDATA; | |
1206 | } | ||
1207 | |||
1208 | /* [DIRAC_STD] 11.2.8 Reference picture weight. reference_picture_weights() | ||
1209 | just data read, weight calculation will be done later on. */ | ||
1210 | 29 | s->weight_log2denom = 1; | |
1211 | 29 | s->weight[0] = 1; | |
1212 | 29 | s->weight[1] = 1; | |
1213 | |||
1214 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 29 times.
|
29 | if (get_bits1(gb)) { |
1215 | ✗ | s->weight_log2denom = get_interleaved_ue_golomb(gb); | |
1216 | ✗ | if (s->weight_log2denom < 1 || s->weight_log2denom > 8) { | |
1217 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "weight_log2denom unsupported or invalid\n"); | |
1218 | ✗ | s->weight_log2denom = 1; | |
1219 | ✗ | return AVERROR_INVALIDDATA; | |
1220 | } | ||
1221 | ✗ | s->weight[0] = dirac_get_se_golomb(gb); | |
1222 | ✗ | if (s->num_refs == 2) | |
1223 | ✗ | s->weight[1] = dirac_get_se_golomb(gb); | |
1224 | } | ||
1225 | 29 | return 0; | |
1226 | } | ||
1227 | |||
1228 | /** | ||
1229 | * Dirac Specification -> | ||
1230 | * 11.3 Wavelet transform data. wavelet_transform() | ||
1231 | */ | ||
1232 | 260 | static int dirac_unpack_idwt_params(DiracContext *s) | |
1233 | { | ||
1234 | 260 | GetBitContext *gb = &s->gb; | |
1235 | int i, level; | ||
1236 | unsigned tmp; | ||
1237 | |||
1238 | #define CHECKEDREAD(dst, cond, errmsg) \ | ||
1239 | tmp = get_interleaved_ue_golomb(gb); \ | ||
1240 | if (cond) { \ | ||
1241 | av_log(s->avctx, AV_LOG_ERROR, errmsg); \ | ||
1242 | return AVERROR_INVALIDDATA; \ | ||
1243 | }\ | ||
1244 | dst = tmp; | ||
1245 | |||
1246 | 260 | align_get_bits(gb); | |
1247 | |||
1248 |
2/2✓ Branch 0 taken 29 times.
✓ Branch 1 taken 231 times.
|
260 | s->zero_res = s->num_refs ? get_bits1(gb) : 0; |
1249 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 260 times.
|
260 | if (s->zero_res) |
1250 | ✗ | return 0; | |
1251 | |||
1252 | /*[DIRAC_STD] 11.3.1 Transform parameters. transform_parameters() */ | ||
1253 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 260 times.
|
260 | CHECKEDREAD(s->wavelet_idx, tmp > 6, "wavelet_idx is too big\n") |
1254 | |||
1255 |
2/4✓ Branch 1 taken 260 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 260 times.
|
260 | CHECKEDREAD(s->wavelet_depth, tmp > MAX_DWT_LEVELS || tmp < 1, "invalid number of DWT decompositions\n") |
1256 | |||
1257 |
2/2✓ Branch 0 taken 31 times.
✓ Branch 1 taken 229 times.
|
260 | if (!s->low_delay) { |
1258 | /* Codeblock parameters (core syntax only) */ | ||
1259 |
1/2✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
|
31 | if (get_bits1(gb)) { |
1260 |
2/2✓ Branch 0 taken 124 times.
✓ Branch 1 taken 31 times.
|
155 | for (i = 0; i <= s->wavelet_depth; i++) { |
1261 |
2/4✓ Branch 1 taken 124 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 124 times.
|
124 | CHECKEDREAD(s->codeblock[i].width , tmp < 1 || tmp > (s->avctx->width >>s->wavelet_depth-i), "codeblock width invalid\n") |
1262 |
2/4✓ Branch 1 taken 124 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 124 times.
|
124 | CHECKEDREAD(s->codeblock[i].height, tmp < 1 || tmp > (s->avctx->height>>s->wavelet_depth-i), "codeblock height invalid\n") |
1263 | } | ||
1264 | |||
1265 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 31 times.
|
31 | CHECKEDREAD(s->codeblock_mode, tmp > 1, "unknown codeblock mode\n") |
1266 | } | ||
1267 | else { | ||
1268 | ✗ | for (i = 0; i <= s->wavelet_depth; i++) | |
1269 | ✗ | s->codeblock[i].width = s->codeblock[i].height = 1; | |
1270 | } | ||
1271 | } | ||
1272 | else { | ||
1273 | 229 | s->num_x = get_interleaved_ue_golomb(gb); | |
1274 | 229 | s->num_y = get_interleaved_ue_golomb(gb); | |
1275 |
2/4✓ Branch 0 taken 229 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 229 times.
✗ Branch 3 not taken.
|
229 | if (s->num_x * s->num_y == 0 || s->num_x * (uint64_t)s->num_y > INT_MAX || |
1276 |
1/2✓ Branch 0 taken 229 times.
✗ Branch 1 not taken.
|
229 | s->num_x * (uint64_t)s->avctx->width > INT_MAX || |
1277 |
1/2✓ Branch 0 taken 229 times.
✗ Branch 1 not taken.
|
229 | s->num_y * (uint64_t)s->avctx->height > INT_MAX || |
1278 |
1/2✓ Branch 0 taken 229 times.
✗ Branch 1 not taken.
|
229 | s->num_x > s->avctx->width || |
1279 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 229 times.
|
229 | s->num_y > s->avctx->height |
1280 | ) { | ||
1281 | ✗ | av_log(s->avctx,AV_LOG_ERROR,"Invalid numx/y\n"); | |
1282 | ✗ | s->num_x = s->num_y = 0; | |
1283 | ✗ | return AVERROR_INVALIDDATA; | |
1284 | } | ||
1285 |
2/2✓ Branch 0 taken 31 times.
✓ Branch 1 taken 198 times.
|
229 | if (s->ld_picture) { |
1286 | 31 | s->lowdelay.bytes.num = get_interleaved_ue_golomb(gb); | |
1287 | 31 | s->lowdelay.bytes.den = get_interleaved_ue_golomb(gb); | |
1288 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | if (s->lowdelay.bytes.den <= 0) { |
1289 | ✗ | av_log(s->avctx,AV_LOG_ERROR,"Invalid lowdelay.bytes.den\n"); | |
1290 | ✗ | return AVERROR_INVALIDDATA; | |
1291 | } | ||
1292 |
1/2✓ Branch 0 taken 198 times.
✗ Branch 1 not taken.
|
198 | } else if (s->hq_picture) { |
1293 | 198 | s->highquality.prefix_bytes = get_interleaved_ue_golomb(gb); | |
1294 | 198 | s->highquality.size_scaler = get_interleaved_ue_golomb(gb); | |
1295 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 198 times.
|
198 | if (s->highquality.prefix_bytes >= INT_MAX / 8) { |
1296 | ✗ | av_log(s->avctx,AV_LOG_ERROR,"too many prefix bytes\n"); | |
1297 | ✗ | return AVERROR_INVALIDDATA; | |
1298 | } | ||
1299 | } | ||
1300 | |||
1301 | /* [DIRAC_STD] 11.3.5 Quantisation matrices (low-delay syntax). quant_matrix() */ | ||
1302 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 229 times.
|
229 | if (get_bits1(gb)) { |
1303 | ✗ | av_log(s->avctx,AV_LOG_DEBUG,"Low Delay: Has Custom Quantization Matrix!\n"); | |
1304 | /* custom quantization matrix */ | ||
1305 | ✗ | for (level = 0; level < s->wavelet_depth; level++) { | |
1306 | ✗ | for (i = !!level; i < 4; i++) { | |
1307 | ✗ | s->lowdelay.quant[level][i] = get_interleaved_ue_golomb(gb); | |
1308 | } | ||
1309 | } | ||
1310 | } else { | ||
1311 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 229 times.
|
229 | if (s->wavelet_depth > 4) { |
1312 | ✗ | av_log(s->avctx,AV_LOG_ERROR,"Mandatory custom low delay matrix missing for depth %d\n", s->wavelet_depth); | |
1313 | ✗ | return AVERROR_INVALIDDATA; | |
1314 | } | ||
1315 | /* default quantization matrix */ | ||
1316 |
2/2✓ Branch 0 taken 885 times.
✓ Branch 1 taken 229 times.
|
1114 | for (level = 0; level < s->wavelet_depth; level++) |
1317 |
2/2✓ Branch 0 taken 3540 times.
✓ Branch 1 taken 885 times.
|
4425 | for (i = 0; i < 4; i++) { |
1318 | 3540 | s->lowdelay.quant[level][i] = ff_dirac_default_qmat[s->wavelet_idx][level][i]; | |
1319 | /* haar with no shift differs for different depths */ | ||
1320 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3540 times.
|
3540 | if (s->wavelet_idx == 3) |
1321 | ✗ | s->lowdelay.quant[level][i] += 4*(s->wavelet_depth-1 - level); | |
1322 | } | ||
1323 | } | ||
1324 | } | ||
1325 | 260 | return 0; | |
1326 | } | ||
1327 | |||
1328 | 2320 | static inline int pred_sbsplit(uint8_t *sbsplit, int stride, int x, int y) | |
1329 | { | ||
1330 | static const uint8_t avgsplit[7] = { 0, 0, 1, 1, 1, 2, 2 }; | ||
1331 | |||
1332 |
2/2✓ Branch 0 taken 29 times.
✓ Branch 1 taken 2291 times.
|
2320 | if (!(x|y)) |
1333 | 29 | return 0; | |
1334 |
2/2✓ Branch 0 taken 261 times.
✓ Branch 1 taken 2030 times.
|
2291 | else if (!y) |
1335 | 261 | return sbsplit[-1]; | |
1336 |
2/2✓ Branch 0 taken 203 times.
✓ Branch 1 taken 1827 times.
|
2030 | else if (!x) |
1337 | 203 | return sbsplit[-stride]; | |
1338 | |||
1339 | 1827 | return avgsplit[sbsplit[-1] + sbsplit[-stride] + sbsplit[-stride-1]]; | |
1340 | } | ||
1341 | |||
1342 | 8493 | static inline int pred_block_mode(DiracBlock *block, int stride, int x, int y, int refmask) | |
1343 | { | ||
1344 | int pred; | ||
1345 | |||
1346 |
2/2✓ Branch 0 taken 57 times.
✓ Branch 1 taken 8436 times.
|
8493 | if (!(x|y)) |
1347 | 57 | return 0; | |
1348 |
2/2✓ Branch 0 taken 545 times.
✓ Branch 1 taken 7891 times.
|
8436 | else if (!y) |
1349 | 545 | return block[-1].ref & refmask; | |
1350 |
2/2✓ Branch 0 taken 399 times.
✓ Branch 1 taken 7492 times.
|
7891 | else if (!x) |
1351 | 399 | return block[-stride].ref & refmask; | |
1352 | |||
1353 | /* return the majority */ | ||
1354 | 7492 | pred = (block[-1].ref & refmask) + (block[-stride].ref & refmask) + (block[-stride-1].ref & refmask); | |
1355 | 7492 | return (pred >> 1) & refmask; | |
1356 | } | ||
1357 | |||
1358 | 754 | static inline void pred_block_dc(DiracBlock *block, int stride, int x, int y) | |
1359 | { | ||
1360 | 754 | int i, n = 0; | |
1361 | |||
1362 | 754 | memset(block->u.dc, 0, sizeof(block->u.dc)); | |
1363 | |||
1364 |
3/4✓ Branch 0 taken 754 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 438 times.
✓ Branch 3 taken 316 times.
|
754 | if (x && !(block[-1].ref & 3)) { |
1365 |
2/2✓ Branch 0 taken 1314 times.
✓ Branch 1 taken 438 times.
|
1752 | for (i = 0; i < 3; i++) |
1366 | 1314 | block->u.dc[i] += block[-1].u.dc[i]; | |
1367 | 438 | n++; | |
1368 | } | ||
1369 | |||
1370 |
3/4✓ Branch 0 taken 754 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 404 times.
✓ Branch 3 taken 350 times.
|
754 | if (y && !(block[-stride].ref & 3)) { |
1371 |
2/2✓ Branch 0 taken 1212 times.
✓ Branch 1 taken 404 times.
|
1616 | for (i = 0; i < 3; i++) |
1372 | 1212 | block->u.dc[i] += block[-stride].u.dc[i]; | |
1373 | 404 | n++; | |
1374 | } | ||
1375 | |||
1376 |
4/6✓ Branch 0 taken 754 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 754 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 343 times.
✓ Branch 5 taken 411 times.
|
754 | if (x && y && !(block[-1-stride].ref & 3)) { |
1377 |
2/2✓ Branch 0 taken 1029 times.
✓ Branch 1 taken 343 times.
|
1372 | for (i = 0; i < 3; i++) |
1378 | 1029 | block->u.dc[i] += block[-1-stride].u.dc[i]; | |
1379 | 343 | n++; | |
1380 | } | ||
1381 | |||
1382 |
2/2✓ Branch 0 taken 220 times.
✓ Branch 1 taken 534 times.
|
754 | if (n == 2) { |
1383 |
2/2✓ Branch 0 taken 660 times.
✓ Branch 1 taken 220 times.
|
880 | for (i = 0; i < 3; i++) |
1384 | 660 | block->u.dc[i] = (block->u.dc[i]+1)>>1; | |
1385 |
2/2✓ Branch 0 taken 164 times.
✓ Branch 1 taken 370 times.
|
534 | } else if (n == 3) { |
1386 |
2/2✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
|
656 | for (i = 0; i < 3; i++) |
1387 | 492 | block->u.dc[i] = divide3(block->u.dc[i]); | |
1388 | } | ||
1389 | 754 | } | |
1390 | |||
1391 | 5951 | static inline void pred_mv(DiracBlock *block, int stride, int x, int y, int ref) | |
1392 | { | ||
1393 | int16_t *pred[3]; | ||
1394 | 5951 | int refmask = ref+1; | |
1395 | 5951 | int mask = refmask | DIRAC_REF_MASK_GLOBAL; /* exclude gmc blocks */ | |
1396 | 5951 | int n = 0; | |
1397 | |||
1398 |
4/4✓ Branch 0 taken 5495 times.
✓ Branch 1 taken 456 times.
✓ Branch 2 taken 4890 times.
✓ Branch 3 taken 605 times.
|
5951 | if (x && (block[-1].ref & mask) == refmask) |
1399 | 4890 | pred[n++] = block[-1].u.mv[ref]; | |
1400 | |||
1401 |
4/4✓ Branch 0 taken 5407 times.
✓ Branch 1 taken 544 times.
✓ Branch 2 taken 4719 times.
✓ Branch 3 taken 688 times.
|
5951 | if (y && (block[-stride].ref & mask) == refmask) |
1402 | 4719 | pred[n++] = block[-stride].u.mv[ref]; | |
1403 | |||
1404 |
6/6✓ Branch 0 taken 5495 times.
✓ Branch 1 taken 456 times.
✓ Branch 2 taken 5008 times.
✓ Branch 3 taken 487 times.
✓ Branch 4 taken 4313 times.
✓ Branch 5 taken 695 times.
|
5951 | if (x && y && (block[-stride-1].ref & mask) == refmask) |
1405 | 4313 | pred[n++] = block[-stride-1].u.mv[ref]; | |
1406 | |||
1407 |
4/5✓ Branch 0 taken 304 times.
✓ Branch 1 taken 1266 times.
✓ Branch 2 taken 487 times.
✓ Branch 3 taken 3894 times.
✗ Branch 4 not taken.
|
5951 | switch (n) { |
1408 | 304 | case 0: | |
1409 | 304 | block->u.mv[ref][0] = 0; | |
1410 | 304 | block->u.mv[ref][1] = 0; | |
1411 | 304 | break; | |
1412 | 1266 | case 1: | |
1413 | 1266 | block->u.mv[ref][0] = pred[0][0]; | |
1414 | 1266 | block->u.mv[ref][1] = pred[0][1]; | |
1415 | 1266 | break; | |
1416 | 487 | case 2: | |
1417 | 487 | block->u.mv[ref][0] = (pred[0][0] + pred[1][0] + 1) >> 1; | |
1418 | 487 | block->u.mv[ref][1] = (pred[0][1] + pred[1][1] + 1) >> 1; | |
1419 | 487 | break; | |
1420 | 3894 | case 3: | |
1421 | 3894 | block->u.mv[ref][0] = mid_pred(pred[0][0], pred[1][0], pred[2][0]); | |
1422 | 3894 | block->u.mv[ref][1] = mid_pred(pred[0][1], pred[1][1], pred[2][1]); | |
1423 | 3894 | break; | |
1424 | } | ||
1425 | 5951 | } | |
1426 | |||
1427 | ✗ | static void global_mv(DiracContext *s, DiracBlock *block, int x, int y, int ref) | |
1428 | { | ||
1429 | ✗ | int ez = s->globalmc[ref].zrs_exp; | |
1430 | ✗ | int ep = s->globalmc[ref].perspective_exp; | |
1431 | ✗ | int (*A)[2] = s->globalmc[ref].zrs; | |
1432 | ✗ | int *b = s->globalmc[ref].pan_tilt; | |
1433 | ✗ | int *c = s->globalmc[ref].perspective; | |
1434 | |||
1435 | ✗ | int64_t m = (1<<ep) - (c[0]*(int64_t)x + c[1]*(int64_t)y); | |
1436 | ✗ | int64_t mx = m * (uint64_t)((A[0][0] * (int64_t)x + A[0][1]*(int64_t)y) + (1LL<<ez) * b[0]); | |
1437 | ✗ | int64_t my = m * (uint64_t)((A[1][0] * (int64_t)x + A[1][1]*(int64_t)y) + (1LL<<ez) * b[1]); | |
1438 | |||
1439 | ✗ | block->u.mv[ref][0] = (mx + (1<<(ez+ep))) >> (ez+ep); | |
1440 | ✗ | block->u.mv[ref][1] = (my + (1<<(ez+ep))) >> (ez+ep); | |
1441 | ✗ | } | |
1442 | |||
1443 | 4348 | static void decode_block_params(DiracContext *s, DiracArith arith[8], DiracBlock *block, | |
1444 | int stride, int x, int y) | ||
1445 | { | ||
1446 | int i; | ||
1447 | |||
1448 | 4348 | block->ref = pred_block_mode(block, stride, x, y, DIRAC_REF_MASK_REF1); | |
1449 | 4348 | block->ref ^= dirac_get_arith_bit(arith, CTX_PMODE_REF1); | |
1450 | |||
1451 |
2/2✓ Branch 0 taken 4145 times.
✓ Branch 1 taken 203 times.
|
4348 | if (s->num_refs == 2) { |
1452 | 4145 | block->ref |= pred_block_mode(block, stride, x, y, DIRAC_REF_MASK_REF2); | |
1453 | 4145 | block->ref ^= dirac_get_arith_bit(arith, CTX_PMODE_REF2) << 1; | |
1454 | } | ||
1455 | |||
1456 |
2/2✓ Branch 0 taken 754 times.
✓ Branch 1 taken 3594 times.
|
4348 | if (!block->ref) { |
1457 | 754 | pred_block_dc(block, stride, x, y); | |
1458 |
2/2✓ Branch 0 taken 2262 times.
✓ Branch 1 taken 754 times.
|
3016 | for (i = 0; i < 3; i++) |
1459 | 2262 | block->u.dc[i] += (unsigned)dirac_get_arith_int(arith+1+i, CTX_DC_F1, CTX_DC_DATA); | |
1460 | 754 | return; | |
1461 | } | ||
1462 | |||
1463 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3594 times.
|
3594 | if (s->globalmc_flag) { |
1464 | ✗ | block->ref |= pred_block_mode(block, stride, x, y, DIRAC_REF_MASK_GLOBAL); | |
1465 | ✗ | block->ref ^= dirac_get_arith_bit(arith, CTX_GLOBAL_BLOCK) << 2; | |
1466 | } | ||
1467 | |||
1468 |
2/2✓ Branch 0 taken 7042 times.
✓ Branch 1 taken 3594 times.
|
10636 | for (i = 0; i < s->num_refs; i++) |
1469 |
2/2✓ Branch 0 taken 5951 times.
✓ Branch 1 taken 1091 times.
|
7042 | if (block->ref & (i+1)) { |
1470 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5951 times.
|
5951 | if (block->ref & DIRAC_REF_MASK_GLOBAL) { |
1471 | ✗ | global_mv(s, block, x, y, i); | |
1472 | } else { | ||
1473 | 5951 | pred_mv(block, stride, x, y, i); | |
1474 | 5951 | block->u.mv[i][0] += (unsigned)dirac_get_arith_int(arith + 4 + 2 * i, CTX_MV_F1, CTX_MV_DATA); | |
1475 | 5951 | block->u.mv[i][1] += (unsigned)dirac_get_arith_int(arith + 5 + 2 * i, CTX_MV_F1, CTX_MV_DATA); | |
1476 | } | ||
1477 | } | ||
1478 | } | ||
1479 | |||
1480 | /** | ||
1481 | * Copies the current block to the other blocks covered by the current superblock split mode | ||
1482 | */ | ||
1483 | 4348 | static void propagate_block_data(DiracBlock *block, int stride, int size) | |
1484 | { | ||
1485 | int x, y; | ||
1486 | 4348 | DiracBlock *dst = block; | |
1487 | |||
1488 |
2/2✓ Branch 0 taken 6764 times.
✓ Branch 1 taken 4348 times.
|
11112 | for (x = 1; x < size; x++) |
1489 | 6764 | dst[x] = *block; | |
1490 | |||
1491 |
2/2✓ Branch 0 taken 6764 times.
✓ Branch 1 taken 4348 times.
|
11112 | for (y = 1; y < size; y++) { |
1492 | 6764 | dst += stride; | |
1493 |
2/2✓ Branch 0 taken 26008 times.
✓ Branch 1 taken 6764 times.
|
32772 | for (x = 0; x < size; x++) |
1494 | 26008 | dst[x] = *block; | |
1495 | } | ||
1496 | 4348 | } | |
1497 | |||
1498 | /** | ||
1499 | * Dirac Specification -> | ||
1500 | * 12. Block motion data syntax | ||
1501 | */ | ||
1502 | 29 | static int dirac_unpack_block_motion_data(DiracContext *s) | |
1503 | { | ||
1504 | 29 | GetBitContext *gb = &s->gb; | |
1505 | 29 | uint8_t *sbsplit = s->sbsplit; | |
1506 | int i, x, y, q, p; | ||
1507 | DiracArith arith[8]; | ||
1508 | |||
1509 | 29 | align_get_bits(gb); | |
1510 | |||
1511 | /* [DIRAC_STD] 11.2.4 and 12.2.1 Number of blocks and superblocks */ | ||
1512 | 29 | s->sbwidth = DIVRNDUP(s->seq.width, 4*s->plane[0].xbsep); | |
1513 | 29 | s->sbheight = DIVRNDUP(s->seq.height, 4*s->plane[0].ybsep); | |
1514 | 29 | s->blwidth = 4 * s->sbwidth; | |
1515 | 29 | s->blheight = 4 * s->sbheight; | |
1516 | |||
1517 | /* [DIRAC_STD] 12.3.1 Superblock splitting modes. superblock_split_modes() | ||
1518 | decode superblock split modes */ | ||
1519 | 29 | ff_dirac_init_arith_decoder(arith, gb, get_interleaved_ue_golomb(gb)); /* get_interleaved_ue_golomb(gb) is the length */ | |
1520 |
2/2✓ Branch 0 taken 232 times.
✓ Branch 1 taken 29 times.
|
261 | for (y = 0; y < s->sbheight; y++) { |
1521 |
2/2✓ Branch 0 taken 2320 times.
✓ Branch 1 taken 232 times.
|
2552 | for (x = 0; x < s->sbwidth; x++) { |
1522 | 2320 | unsigned int split = dirac_get_arith_uint(arith, CTX_SB_F1, CTX_SB_DATA); | |
1523 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2320 times.
|
2320 | if (split > 2) |
1524 | ✗ | return AVERROR_INVALIDDATA; | |
1525 | 2320 | sbsplit[x] = (split + pred_sbsplit(sbsplit+x, s->sbwidth, x, y)) % 3; | |
1526 | } | ||
1527 | 232 | sbsplit += s->sbwidth; | |
1528 | } | ||
1529 | |||
1530 | /* setup arith decoding */ | ||
1531 | 29 | ff_dirac_init_arith_decoder(arith, gb, get_interleaved_ue_golomb(gb)); | |
1532 |
2/2✓ Branch 0 taken 57 times.
✓ Branch 1 taken 29 times.
|
86 | for (i = 0; i < s->num_refs; i++) { |
1533 | 57 | ff_dirac_init_arith_decoder(arith + 4 + 2 * i, gb, get_interleaved_ue_golomb(gb)); | |
1534 | 57 | ff_dirac_init_arith_decoder(arith + 5 + 2 * i, gb, get_interleaved_ue_golomb(gb)); | |
1535 | } | ||
1536 |
2/2✓ Branch 0 taken 87 times.
✓ Branch 1 taken 29 times.
|
116 | for (i = 0; i < 3; i++) |
1537 | 87 | ff_dirac_init_arith_decoder(arith+1+i, gb, get_interleaved_ue_golomb(gb)); | |
1538 | |||
1539 |
2/2✓ Branch 0 taken 232 times.
✓ Branch 1 taken 29 times.
|
261 | for (y = 0; y < s->sbheight; y++) |
1540 |
2/2✓ Branch 0 taken 2320 times.
✓ Branch 1 taken 232 times.
|
2552 | for (x = 0; x < s->sbwidth; x++) { |
1541 | 2320 | int blkcnt = 1 << s->sbsplit[y * s->sbwidth + x]; | |
1542 | 2320 | int step = 4 >> s->sbsplit[y * s->sbwidth + x]; | |
1543 | |||
1544 |
2/2✓ Branch 0 taken 2778 times.
✓ Branch 1 taken 2320 times.
|
5098 | for (q = 0; q < blkcnt; q++) |
1545 |
2/2✓ Branch 0 taken 4348 times.
✓ Branch 1 taken 2778 times.
|
7126 | for (p = 0; p < blkcnt; p++) { |
1546 | 4348 | int bx = 4 * x + p*step; | |
1547 | 4348 | int by = 4 * y + q*step; | |
1548 | 4348 | DiracBlock *block = &s->blmotion[by*s->blwidth + bx]; | |
1549 | 4348 | decode_block_params(s, arith, block, s->blwidth, bx, by); | |
1550 | 4348 | propagate_block_data(block, s->blwidth, step); | |
1551 | } | ||
1552 | } | ||
1553 | |||
1554 |
2/2✓ Branch 0 taken 230 times.
✓ Branch 1 taken 29 times.
|
259 | for (i = 0; i < 4 + 2*s->num_refs; i++) { |
1555 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 230 times.
|
230 | if (arith[i].error) |
1556 | ✗ | return arith[i].error; | |
1557 | } | ||
1558 | |||
1559 | 29 | return 0; | |
1560 | } | ||
1561 | |||
1562 | 72384 | static int weight(int i, int blen, int offset) | |
1563 | { | ||
1564 | #define ROLLOFF(i) offset == 1 ? ((i) ? 5 : 3) : \ | ||
1565 | (1 + (6*(i) + offset - 1) / (2*offset - 1)) | ||
1566 | |||
1567 |
2/2✓ Branch 0 taken 36192 times.
✓ Branch 1 taken 36192 times.
|
72384 | if (i < 2*offset) |
1568 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 36192 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
36192 | return ROLLOFF(i); |
1569 |
1/2✓ Branch 0 taken 36192 times.
✗ Branch 1 not taken.
|
36192 | else if (i > blen-1 - 2*offset) |
1570 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 36192 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
36192 | return ROLLOFF(blen-1 - i); |
1571 | ✗ | return 8; | |
1572 | } | ||
1573 | |||
1574 | 8352 | static void init_obmc_weight_row(Plane *p, uint8_t *obmc_weight, int stride, | |
1575 | int left, int right, int wy) | ||
1576 | { | ||
1577 | int x; | ||
1578 |
4/4✓ Branch 0 taken 19488 times.
✓ Branch 1 taken 5568 times.
✓ Branch 2 taken 16704 times.
✓ Branch 3 taken 2784 times.
|
25056 | for (x = 0; left && x < p->xblen >> 1; x++) |
1579 | 16704 | obmc_weight[x] = wy*8; | |
1580 |
2/2✓ Branch 0 taken 66816 times.
✓ Branch 1 taken 8352 times.
|
75168 | for (; x < p->xblen >> right; x++) |
1581 | 66816 | obmc_weight[x] = wy*weight(x, p->xblen, p->xoffset); | |
1582 |
2/2✓ Branch 0 taken 16704 times.
✓ Branch 1 taken 8352 times.
|
25056 | for (; x < p->xblen; x++) |
1583 | 16704 | obmc_weight[x] = wy*8; | |
1584 |
2/2✓ Branch 0 taken 167040 times.
✓ Branch 1 taken 8352 times.
|
175392 | for (; x < stride; x++) |
1585 | 167040 | obmc_weight[x] = 0; | |
1586 | 8352 | } | |
1587 | |||
1588 | 783 | static void init_obmc_weight(Plane *p, uint8_t *obmc_weight, int stride, | |
1589 | int left, int right, int top, int bottom) | ||
1590 | { | ||
1591 | int y; | ||
1592 |
4/4✓ Branch 0 taken 1653 times.
✓ Branch 1 taken 522 times.
✓ Branch 2 taken 1392 times.
✓ Branch 3 taken 261 times.
|
2175 | for (y = 0; top && y < p->yblen >> 1; y++) { |
1593 | 1392 | init_obmc_weight_row(p, obmc_weight, stride, left, right, 8); | |
1594 | 1392 | obmc_weight += stride; | |
1595 | } | ||
1596 |
2/2✓ Branch 0 taken 5568 times.
✓ Branch 1 taken 783 times.
|
6351 | for (; y < p->yblen >> bottom; y++) { |
1597 | 5568 | int wy = weight(y, p->yblen, p->yoffset); | |
1598 | 5568 | init_obmc_weight_row(p, obmc_weight, stride, left, right, wy); | |
1599 | 5568 | obmc_weight += stride; | |
1600 | } | ||
1601 |
2/2✓ Branch 0 taken 1392 times.
✓ Branch 1 taken 783 times.
|
2175 | for (; y < p->yblen; y++) { |
1602 | 1392 | init_obmc_weight_row(p, obmc_weight, stride, left, right, 8); | |
1603 | 1392 | obmc_weight += stride; | |
1604 | } | ||
1605 | 783 | } | |
1606 | |||
1607 | 2784 | static void init_obmc_weights(DiracContext *s, Plane *p, int by) | |
1608 | { | ||
1609 | 2784 | int top = !by; | |
1610 | 2784 | int bottom = by == s->blheight-1; | |
1611 | |||
1612 | /* don't bother re-initing for rows 2 to blheight-2, the weights don't change */ | ||
1613 |
6/6✓ Branch 0 taken 2697 times.
✓ Branch 1 taken 87 times.
✓ Branch 2 taken 2610 times.
✓ Branch 3 taken 87 times.
✓ Branch 4 taken 87 times.
✓ Branch 5 taken 2523 times.
|
2784 | if (top || bottom || by == 1) { |
1614 | 261 | init_obmc_weight(p, s->obmc_weight[0], MAX_BLOCKSIZE, 1, 0, top, bottom); | |
1615 | 261 | init_obmc_weight(p, s->obmc_weight[1], MAX_BLOCKSIZE, 0, 0, top, bottom); | |
1616 | 261 | init_obmc_weight(p, s->obmc_weight[2], MAX_BLOCKSIZE, 0, 1, top, bottom); | |
1617 | } | ||
1618 | 2784 | } | |
1619 | |||
1620 | static const uint8_t epel_weights[4][4][4] = { | ||
1621 | {{ 16, 0, 0, 0 }, | ||
1622 | { 12, 4, 0, 0 }, | ||
1623 | { 8, 8, 0, 0 }, | ||
1624 | { 4, 12, 0, 0 }}, | ||
1625 | {{ 12, 0, 4, 0 }, | ||
1626 | { 9, 3, 3, 1 }, | ||
1627 | { 6, 6, 2, 2 }, | ||
1628 | { 3, 9, 1, 3 }}, | ||
1629 | {{ 8, 0, 8, 0 }, | ||
1630 | { 6, 2, 6, 2 }, | ||
1631 | { 4, 4, 4, 4 }, | ||
1632 | { 2, 6, 2, 6 }}, | ||
1633 | {{ 4, 0, 12, 0 }, | ||
1634 | { 3, 1, 9, 3 }, | ||
1635 | { 2, 2, 6, 6 }, | ||
1636 | { 1, 3, 3, 9 }} | ||
1637 | }; | ||
1638 | |||
1639 | /** | ||
1640 | * For block x,y, determine which of the hpel planes to do bilinear | ||
1641 | * interpolation from and set src[] to the location in each hpel plane | ||
1642 | * to MC from. | ||
1643 | * | ||
1644 | * @return the index of the put_dirac_pixels_tab function to use | ||
1645 | * 0 for 1 plane (fpel,hpel), 1 for 2 planes (qpel), 2 for 4 planes (qpel), and 3 for epel | ||
1646 | */ | ||
1647 | 199452 | static int mc_subpel(DiracContext *s, DiracBlock *block, const uint8_t *src[5], | |
1648 | int x, int y, int ref, int plane) | ||
1649 | { | ||
1650 | 199452 | Plane *p = &s->plane[plane]; | |
1651 | 199452 | uint8_t **ref_hpel = s->ref_pics[ref]->hpel[plane]; | |
1652 | 199452 | int motion_x = block->u.mv[ref][0]; | |
1653 | 199452 | int motion_y = block->u.mv[ref][1]; | |
1654 | 199452 | int mx, my, i, epel, nplanes = 0; | |
1655 | |||
1656 |
2/2✓ Branch 0 taken 132968 times.
✓ Branch 1 taken 66484 times.
|
199452 | if (plane) { |
1657 | 132968 | motion_x >>= s->chroma_x_shift; | |
1658 | 132968 | motion_y >>= s->chroma_y_shift; | |
1659 | } | ||
1660 | |||
1661 | 199452 | mx = motion_x & ~(-1U << s->mv_precision); | |
1662 | 199452 | my = motion_y & ~(-1U << s->mv_precision); | |
1663 | 199452 | motion_x >>= s->mv_precision; | |
1664 | 199452 | motion_y >>= s->mv_precision; | |
1665 | /* normalize subpel coordinates to epel */ | ||
1666 | /* TODO: template this function? */ | ||
1667 | 199452 | mx <<= 3 - s->mv_precision; | |
1668 | 199452 | my <<= 3 - s->mv_precision; | |
1669 | |||
1670 | 199452 | x += motion_x; | |
1671 | 199452 | y += motion_y; | |
1672 | 199452 | epel = (mx|my)&1; | |
1673 | |||
1674 | /* hpel position */ | ||
1675 |
1/2✓ Branch 0 taken 199452 times.
✗ Branch 1 not taken.
|
199452 | if (!((mx|my)&3)) { |
1676 | 199452 | nplanes = 1; | |
1677 | 199452 | src[0] = ref_hpel[(my>>1)+(mx>>2)] + y*p->stride + x; | |
1678 | } else { | ||
1679 | /* qpel or epel */ | ||
1680 | ✗ | nplanes = 4; | |
1681 | ✗ | for (i = 0; i < 4; i++) | |
1682 | ✗ | src[i] = ref_hpel[i] + y*p->stride + x; | |
1683 | |||
1684 | /* if we're interpolating in the right/bottom halves, adjust the planes as needed | ||
1685 | we increment x/y because the edge changes for half of the pixels */ | ||
1686 | ✗ | if (mx > 4) { | |
1687 | ✗ | src[0] += 1; | |
1688 | ✗ | src[2] += 1; | |
1689 | ✗ | x++; | |
1690 | } | ||
1691 | ✗ | if (my > 4) { | |
1692 | ✗ | src[0] += p->stride; | |
1693 | ✗ | src[1] += p->stride; | |
1694 | ✗ | y++; | |
1695 | } | ||
1696 | |||
1697 | /* hpel planes are: | ||
1698 | [0]: F [1]: H | ||
1699 | [2]: V [3]: C */ | ||
1700 | ✗ | if (!epel) { | |
1701 | /* check if we really only need 2 planes since either mx or my is | ||
1702 | a hpel position. (epel weights of 0 handle this there) */ | ||
1703 | ✗ | if (!(mx&3)) { | |
1704 | /* mx == 0: average [0] and [2] | ||
1705 | mx == 4: average [1] and [3] */ | ||
1706 | ✗ | src[!mx] = src[2 + !!mx]; | |
1707 | ✗ | nplanes = 2; | |
1708 | ✗ | } else if (!(my&3)) { | |
1709 | ✗ | src[0] = src[(my>>1) ]; | |
1710 | ✗ | src[1] = src[(my>>1)+1]; | |
1711 | ✗ | nplanes = 2; | |
1712 | } | ||
1713 | } else { | ||
1714 | /* adjust the ordering if needed so the weights work */ | ||
1715 | ✗ | if (mx > 4) { | |
1716 | ✗ | FFSWAP(const uint8_t *, src[0], src[1]); | |
1717 | ✗ | FFSWAP(const uint8_t *, src[2], src[3]); | |
1718 | } | ||
1719 | ✗ | if (my > 4) { | |
1720 | ✗ | FFSWAP(const uint8_t *, src[0], src[2]); | |
1721 | ✗ | FFSWAP(const uint8_t *, src[1], src[3]); | |
1722 | } | ||
1723 | ✗ | src[4] = epel_weights[my&3][mx&3]; | |
1724 | } | ||
1725 | } | ||
1726 | |||
1727 | /* fixme: v/h _edge_pos */ | ||
1728 |
2/2✓ Branch 0 taken 199293 times.
✓ Branch 1 taken 159 times.
|
199452 | if (x + p->xblen > p->width +EDGE_WIDTH/2 || |
1729 |
4/4✓ Branch 0 taken 196946 times.
✓ Branch 1 taken 2347 times.
✓ Branch 2 taken 191702 times.
✓ Branch 3 taken 5244 times.
|
199293 | y + p->yblen > p->height+EDGE_WIDTH/2 || |
1730 |
2/2✓ Branch 0 taken 6165 times.
✓ Branch 1 taken 185537 times.
|
191702 | x < 0 || y < 0) { |
1731 |
2/2✓ Branch 0 taken 13915 times.
✓ Branch 1 taken 13915 times.
|
27830 | for (i = 0; i < nplanes; i++) { |
1732 | 13915 | s->vdsp.emulated_edge_mc(s->edge_emu_buffer[i], src[i], | |
1733 | p->stride, p->stride, | ||
1734 | 13915 | p->xblen, p->yblen, x, y, | |
1735 | 13915 | p->width+EDGE_WIDTH/2, p->height+EDGE_WIDTH/2); | |
1736 | 13915 | src[i] = s->edge_emu_buffer[i]; | |
1737 | } | ||
1738 | } | ||
1739 | 199452 | return (nplanes>>1) + epel; | |
1740 | } | ||
1741 | |||
1742 | 2262 | static void add_dc(uint16_t *dst, int dc, int stride, | |
1743 | uint8_t *obmc_weight, int xblen, int yblen) | ||
1744 | { | ||
1745 | int x, y; | ||
1746 | 2262 | dc += 128; | |
1747 | |||
1748 |
2/2✓ Branch 0 taken 24128 times.
✓ Branch 1 taken 2262 times.
|
26390 | for (y = 0; y < yblen; y++) { |
1749 |
2/2✓ Branch 0 taken 144768 times.
✓ Branch 1 taken 24128 times.
|
168896 | for (x = 0; x < xblen; x += 2) { |
1750 | 144768 | dst[x ] += dc * obmc_weight[x ]; | |
1751 | 144768 | dst[x+1] += dc * obmc_weight[x+1]; | |
1752 | } | ||
1753 | 24128 | dst += stride; | |
1754 | 24128 | obmc_weight += MAX_BLOCKSIZE; | |
1755 | } | ||
1756 | 2262 | } | |
1757 | |||
1758 | 107880 | static void block_mc(DiracContext *s, DiracBlock *block, | |
1759 | uint16_t *mctmp, uint8_t *obmc_weight, | ||
1760 | int plane, int dstx, int dsty) | ||
1761 | { | ||
1762 | 107880 | Plane *p = &s->plane[plane]; | |
1763 | const uint8_t *src[5]; | ||
1764 | int idx; | ||
1765 | |||
1766 |
3/4✓ Branch 0 taken 2262 times.
✓ Branch 1 taken 11784 times.
✓ Branch 2 taken 93834 times.
✗ Branch 3 not taken.
|
107880 | switch (block->ref&3) { |
1767 | 2262 | case 0: /* DC */ | |
1768 | 2262 | add_dc(mctmp, block->u.dc[plane], p->stride, obmc_weight, p->xblen, p->yblen); | |
1769 | 2262 | return; | |
1770 | 11784 | case 1: | |
1771 | case 2: | ||
1772 | 11784 | idx = mc_subpel(s, block, src, dstx, dsty, (block->ref&3)-1, plane); | |
1773 | 11784 | s->put_pixels_tab[idx](s->mcscratch, src, p->stride, p->yblen); | |
1774 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11784 times.
|
11784 | if (s->weight_func) |
1775 | ✗ | s->weight_func(s->mcscratch, p->stride, s->weight_log2denom, | |
1776 | ✗ | s->weight[0] + s->weight[1], p->yblen); | |
1777 | 11784 | break; | |
1778 | 93834 | case 3: | |
1779 | 93834 | idx = mc_subpel(s, block, src, dstx, dsty, 0, plane); | |
1780 | 93834 | s->put_pixels_tab[idx](s->mcscratch, src, p->stride, p->yblen); | |
1781 | 93834 | idx = mc_subpel(s, block, src, dstx, dsty, 1, plane); | |
1782 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 93834 times.
|
93834 | if (s->biweight_func) { |
1783 | /* fixme: +32 is a quick hack */ | ||
1784 | ✗ | s->put_pixels_tab[idx](s->mcscratch + 32, src, p->stride, p->yblen); | |
1785 | ✗ | s->biweight_func(s->mcscratch, s->mcscratch+32, p->stride, s->weight_log2denom, | |
1786 | ✗ | s->weight[0], s->weight[1], p->yblen); | |
1787 | } else | ||
1788 | 93834 | s->avg_pixels_tab[idx](s->mcscratch, src, p->stride, p->yblen); | |
1789 | 93834 | break; | |
1790 | } | ||
1791 | 105618 | s->add_obmc(mctmp, s->mcscratch, p->stride, obmc_weight, p->yblen); | |
1792 | } | ||
1793 | |||
1794 | 2697 | static void mc_row(DiracContext *s, DiracBlock *block, uint16_t *mctmp, int plane, int dsty) | |
1795 | { | ||
1796 | 2697 | Plane *p = &s->plane[plane]; | |
1797 | 2697 | int x, dstx = p->xbsep - p->xoffset; | |
1798 | |||
1799 | 2697 | block_mc(s, block, mctmp, s->obmc_weight[0], plane, -p->xoffset, dsty); | |
1800 | 2697 | mctmp += p->xbsep; | |
1801 | |||
1802 |
2/2✓ Branch 0 taken 102486 times.
✓ Branch 1 taken 2697 times.
|
105183 | for (x = 1; x < s->blwidth-1; x++) { |
1803 | 102486 | block_mc(s, block+x, mctmp, s->obmc_weight[1], plane, dstx, dsty); | |
1804 | 102486 | dstx += p->xbsep; | |
1805 | 102486 | mctmp += p->xbsep; | |
1806 | } | ||
1807 | 2697 | block_mc(s, block+x, mctmp, s->obmc_weight[2], plane, dstx, dsty); | |
1808 | 2697 | } | |
1809 | |||
1810 | 87 | static void select_dsp_funcs(DiracContext *s, int width, int height, int xblen, int yblen) | |
1811 | { | ||
1812 | 87 | int idx = 0; | |
1813 |
2/2✓ Branch 0 taken 29 times.
✓ Branch 1 taken 58 times.
|
87 | if (xblen > 8) |
1814 | 29 | idx = 1; | |
1815 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 87 times.
|
87 | if (xblen > 16) |
1816 | ✗ | idx = 2; | |
1817 | |||
1818 | 87 | memcpy(s->put_pixels_tab, s->diracdsp.put_dirac_pixels_tab[idx], sizeof(s->put_pixels_tab)); | |
1819 | 87 | memcpy(s->avg_pixels_tab, s->diracdsp.avg_dirac_pixels_tab[idx], sizeof(s->avg_pixels_tab)); | |
1820 | 87 | s->add_obmc = s->diracdsp.add_dirac_obmc[idx]; | |
1821 |
3/6✓ Branch 0 taken 87 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 87 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 87 times.
|
87 | if (s->weight_log2denom > 1 || s->weight[0] != 1 || s->weight[1] != 1) { |
1822 | ✗ | s->weight_func = s->diracdsp.weight_dirac_pixels_tab[idx]; | |
1823 | ✗ | s->biweight_func = s->diracdsp.biweight_dirac_pixels_tab[idx]; | |
1824 | } else { | ||
1825 | 87 | s->weight_func = NULL; | |
1826 | 87 | s->biweight_func = NULL; | |
1827 | } | ||
1828 | 87 | } | |
1829 | |||
1830 | 171 | static int interpolate_refplane(DiracContext *s, DiracFrame *ref, int plane, int width, int height) | |
1831 | { | ||
1832 | /* chroma allocates an edge of 8 when subsampled | ||
1833 | which for 4:2:2 means an h edge of 16 and v edge of 8 | ||
1834 | just use 8 for everything for the moment */ | ||
1835 | 171 | int i, edge = EDGE_WIDTH/2; | |
1836 | |||
1837 | 171 | ref->hpel[plane][0] = ref->avframe->data[plane]; | |
1838 | 171 | s->mpvencdsp.draw_edges(ref->hpel[plane][0], ref->avframe->linesize[plane], width, height, edge, edge, EDGE_TOP | EDGE_BOTTOM); /* EDGE_TOP | EDGE_BOTTOM values just copied to make it build, this needs to be ensured */ | |
1839 | |||
1840 | /* no need for hpel if we only have fpel vectors */ | ||
1841 |
1/2✓ Branch 0 taken 171 times.
✗ Branch 1 not taken.
|
171 | if (!s->mv_precision) |
1842 | 171 | return 0; | |
1843 | |||
1844 | ✗ | for (i = 1; i < 4; i++) { | |
1845 | ✗ | if (!ref->hpel_base[plane][i]) | |
1846 | ✗ | ref->hpel_base[plane][i] = av_malloc((height+2*edge) * ref->avframe->linesize[plane] + 32); | |
1847 | ✗ | if (!ref->hpel_base[plane][i]) { | |
1848 | ✗ | return AVERROR(ENOMEM); | |
1849 | } | ||
1850 | /* we need to be 16-byte aligned even for chroma */ | ||
1851 | ✗ | ref->hpel[plane][i] = ref->hpel_base[plane][i] + edge*ref->avframe->linesize[plane] + 16; | |
1852 | } | ||
1853 | |||
1854 | ✗ | if (!ref->interpolated[plane]) { | |
1855 | ✗ | s->diracdsp.dirac_hpel_filter(ref->hpel[plane][1], ref->hpel[plane][2], | |
1856 | ✗ | ref->hpel[plane][3], ref->hpel[plane][0], | |
1857 | ✗ | ref->avframe->linesize[plane], width, height); | |
1858 | ✗ | s->mpvencdsp.draw_edges(ref->hpel[plane][1], ref->avframe->linesize[plane], width, height, edge, edge, EDGE_TOP | EDGE_BOTTOM); | |
1859 | ✗ | s->mpvencdsp.draw_edges(ref->hpel[plane][2], ref->avframe->linesize[plane], width, height, edge, edge, EDGE_TOP | EDGE_BOTTOM); | |
1860 | ✗ | s->mpvencdsp.draw_edges(ref->hpel[plane][3], ref->avframe->linesize[plane], width, height, edge, edge, EDGE_TOP | EDGE_BOTTOM); | |
1861 | } | ||
1862 | ✗ | ref->interpolated[plane] = 1; | |
1863 | |||
1864 | ✗ | return 0; | |
1865 | } | ||
1866 | |||
1867 | /** | ||
1868 | * Dirac Specification -> | ||
1869 | * 13.0 Transform data syntax. transform_data() | ||
1870 | */ | ||
1871 | 260 | static int dirac_decode_frame_internal(DiracContext *s) | |
1872 | { | ||
1873 | DWTContext d; | ||
1874 | int y, i, comp, dsty; | ||
1875 | int ret; | ||
1876 | |||
1877 |
2/2✓ Branch 0 taken 229 times.
✓ Branch 1 taken 31 times.
|
260 | if (s->low_delay) { |
1878 | /* [DIRAC_STD] 13.5.1 low_delay_transform_data() */ | ||
1879 |
2/2✓ Branch 0 taken 31 times.
✓ Branch 1 taken 198 times.
|
229 | if (!s->hq_picture) { |
1880 |
2/2✓ Branch 0 taken 93 times.
✓ Branch 1 taken 31 times.
|
124 | for (comp = 0; comp < 3; comp++) { |
1881 | 93 | Plane *p = &s->plane[comp]; | |
1882 | 93 | memset(p->idwt.buf, 0, p->idwt.stride * p->idwt.height); | |
1883 | } | ||
1884 | } | ||
1885 |
1/2✓ Branch 0 taken 229 times.
✗ Branch 1 not taken.
|
229 | if (!s->zero_res) { |
1886 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 229 times.
|
229 | if ((ret = decode_lowdelay(s)) < 0) |
1887 | ✗ | return ret; | |
1888 | } | ||
1889 | } | ||
1890 | |||
1891 |
2/2✓ Branch 0 taken 780 times.
✓ Branch 1 taken 260 times.
|
1040 | for (comp = 0; comp < 3; comp++) { |
1892 | 780 | Plane *p = &s->plane[comp]; | |
1893 | 780 | uint8_t *frame = s->current_picture->avframe->data[comp]; | |
1894 | |||
1895 | /* FIXME: small resolutions */ | ||
1896 |
2/2✓ Branch 0 taken 3120 times.
✓ Branch 1 taken 780 times.
|
3900 | for (i = 0; i < 4; i++) |
1897 | 3120 | s->edge_emu_buffer[i] = s->edge_emu_buffer_base + i*FFALIGN(p->width, 16); | |
1898 | |||
1899 |
3/4✓ Branch 0 taken 780 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 93 times.
✓ Branch 3 taken 687 times.
|
780 | if (!s->zero_res && !s->low_delay) |
1900 | { | ||
1901 | 93 | memset(p->idwt.buf, 0, p->idwt.stride * p->idwt.height); | |
1902 | 93 | ret = decode_component(s, comp); /* [DIRAC_STD] 13.4.1 core_transform_data() */ | |
1903 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 93 times.
|
93 | if (ret < 0) |
1904 | ✗ | return ret; | |
1905 | } | ||
1906 | 780 | ret = ff_spatial_idwt_init(&d, &p->idwt, s->wavelet_idx+2, | |
1907 | 780 | s->wavelet_depth, s->bit_depth); | |
1908 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 780 times.
|
780 | if (ret < 0) |
1909 | ✗ | return ret; | |
1910 | |||
1911 |
2/2✓ Branch 0 taken 693 times.
✓ Branch 1 taken 87 times.
|
780 | if (!s->num_refs) { /* intra */ |
1912 |
2/2✓ Branch 0 taken 10743 times.
✓ Branch 1 taken 693 times.
|
11436 | for (y = 0; y < p->height; y += 16) { |
1913 | 10743 | int idx = (s->bit_depth - 8) >> 1; | |
1914 | 10743 | ff_spatial_idwt_slice2(&d, y+16); /* decode */ | |
1915 | 10743 | s->diracdsp.put_signed_rect_clamped[idx](frame + y*p->stride, | |
1916 | 10743 | p->stride, | |
1917 | 10743 | p->idwt.buf + y*p->idwt.stride, | |
1918 | p->idwt.stride, p->width, 16); | ||
1919 | } | ||
1920 | } else { /* inter */ | ||
1921 | 87 | int rowheight = p->ybsep*p->stride; | |
1922 | |||
1923 | 87 | select_dsp_funcs(s, p->width, p->height, p->xblen, p->yblen); | |
1924 | |||
1925 |
2/2✓ Branch 0 taken 171 times.
✓ Branch 1 taken 87 times.
|
258 | for (i = 0; i < s->num_refs; i++) { |
1926 | 171 | int ret = interpolate_refplane(s, s->ref_pics[i], comp, p->width, p->height); | |
1927 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 171 times.
|
171 | if (ret < 0) |
1928 | ✗ | return ret; | |
1929 | } | ||
1930 | |||
1931 | 87 | memset(s->mctmp, 0, 4*p->yoffset*p->stride); | |
1932 | |||
1933 | 87 | dsty = -p->yoffset; | |
1934 |
1/2✓ Branch 0 taken 2784 times.
✗ Branch 1 not taken.
|
2784 | for (y = 0; y < s->blheight; y++) { |
1935 | 2784 | int h = 0, | |
1936 | 2784 | start = FFMAX(dsty, 0); | |
1937 | 2784 | uint16_t *mctmp = s->mctmp + y*rowheight; | |
1938 | 2784 | DiracBlock *blocks = s->blmotion + y*s->blwidth; | |
1939 | |||
1940 | 2784 | init_obmc_weights(s, p, y); | |
1941 | |||
1942 |
4/4✓ Branch 0 taken 2697 times.
✓ Branch 1 taken 87 times.
✓ Branch 2 taken 87 times.
✓ Branch 3 taken 2610 times.
|
2784 | if (y == s->blheight-1 || start+p->ybsep > p->height) |
1943 | 174 | h = p->height - start; | |
1944 | else | ||
1945 | 2610 | h = p->ybsep - (start - dsty); | |
1946 |
2/2✓ Branch 0 taken 87 times.
✓ Branch 1 taken 2697 times.
|
2784 | if (h < 0) |
1947 | 87 | break; | |
1948 | |||
1949 | 2697 | memset(mctmp+2*p->yoffset*p->stride, 0, 2*rowheight); | |
1950 | 2697 | mc_row(s, blocks, mctmp, comp, dsty); | |
1951 | |||
1952 | 2697 | mctmp += (start - dsty)*p->stride + p->xoffset; | |
1953 | 2697 | ff_spatial_idwt_slice2(&d, start + h); /* decode */ | |
1954 | /* NOTE: add_rect_clamped hasn't been templated hence the shifts. | ||
1955 | * idwt.stride is passed as pixels, not in bytes as in the rest of the decoder */ | ||
1956 | 2697 | s->diracdsp.add_rect_clamped(frame + start*p->stride, mctmp, p->stride, | |
1957 | 2697 | (int16_t*)(p->idwt.buf) + start*(p->idwt.stride >> 1), (p->idwt.stride >> 1), p->width, h); | |
1958 | |||
1959 | 2697 | dsty += p->ybsep; | |
1960 | } | ||
1961 | } | ||
1962 | } | ||
1963 | |||
1964 | |||
1965 | 260 | return 0; | |
1966 | } | ||
1967 | |||
1968 | 260 | static int get_buffer_with_edge(AVCodecContext *avctx, AVFrame *f, int flags) | |
1969 | { | ||
1970 | int ret, i; | ||
1971 | int chroma_x_shift, chroma_y_shift; | ||
1972 | 260 | ret = av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &chroma_x_shift, | |
1973 | &chroma_y_shift); | ||
1974 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 260 times.
|
260 | if (ret < 0) |
1975 | ✗ | return ret; | |
1976 | |||
1977 | 260 | f->width = avctx->width + 2 * EDGE_WIDTH; | |
1978 | 260 | f->height = avctx->height + 2 * EDGE_WIDTH + 2; | |
1979 | 260 | ret = ff_get_buffer(avctx, f, flags); | |
1980 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 260 times.
|
260 | if (ret < 0) |
1981 | ✗ | return ret; | |
1982 | |||
1983 |
2/2✓ Branch 0 taken 780 times.
✓ Branch 1 taken 260 times.
|
1040 | for (i = 0; f->data[i]; i++) { |
1984 |
3/4✓ Branch 0 taken 520 times.
✓ Branch 1 taken 260 times.
✓ Branch 2 taken 520 times.
✗ Branch 3 not taken.
|
780 | int offset = (EDGE_WIDTH >> (i && i<3 ? chroma_y_shift : 0)) * |
1985 | 780 | f->linesize[i] + 32; | |
1986 | 780 | f->data[i] += offset; | |
1987 | } | ||
1988 | 260 | f->width = avctx->width; | |
1989 | 260 | f->height = avctx->height; | |
1990 | |||
1991 | 260 | return 0; | |
1992 | } | ||
1993 | |||
1994 | /** | ||
1995 | * Dirac Specification -> | ||
1996 | * 11.1.1 Picture Header. picture_header() | ||
1997 | */ | ||
1998 | 260 | static int dirac_decode_picture_header(DiracContext *s) | |
1999 | { | ||
2000 | unsigned retire, picnum; | ||
2001 | int i, j, ret; | ||
2002 | int64_t refdist, refnum; | ||
2003 | 260 | GetBitContext *gb = &s->gb; | |
2004 | |||
2005 | /* [DIRAC_STD] 11.1.1 Picture Header. picture_header() PICTURE_NUM */ | ||
2006 | 260 | picnum = s->current_picture->picture_number = get_bits_long(gb, 32); | |
2007 | |||
2008 | |||
2009 | 260 | av_log(s->avctx,AV_LOG_DEBUG,"PICTURE_NUM: %d\n",picnum); | |
2010 | |||
2011 | /* if this is the first keyframe after a sequence header, start our | ||
2012 | reordering from here */ | ||
2013 |
2/2✓ Branch 0 taken 70 times.
✓ Branch 1 taken 190 times.
|
260 |