Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * FFV1 decoder template | ||
3 | * | ||
4 | * Copyright (c) 2003-2016 Michael Niedermayer <michaelni@gmx.at> | ||
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 | #include "ffv1_template.c" | ||
24 | |||
25 | 3621264 | static av_always_inline int RENAME(decode_line)(FFV1Context *s, int w, | |
26 | TYPE *sample[2], | ||
27 | int plane_index, int bits) | ||
28 | { | ||
29 | 3621264 | PlaneContext *const p = &s->plane[plane_index]; | |
30 | 3621264 | RangeCoder *const c = &s->c; | |
31 | int x; | ||
32 | 3621264 | int run_count = 0; | |
33 | 3621264 | int run_mode = 0; | |
34 | 3621264 | int run_index = s->run_index; | |
35 | |||
36 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1810632 times.
|
3621264 | if (is_input_end(s)) |
37 | ✗ | return AVERROR_INVALIDDATA; | |
38 | |||
39 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1810632 times.
|
3621264 | if (s->slice_coding_mode == 1) { |
40 | int i; | ||
41 | ✗ | for (x = 0; x < w; x++) { | |
42 | ✗ | int v = 0; | |
43 | ✗ | for (i=0; i<bits; i++) { | |
44 | ✗ | uint8_t state = 128; | |
45 | ✗ | v += v + get_rac(c, &state); | |
46 | } | ||
47 | ✗ | sample[1][x] = v; | |
48 | } | ||
49 | ✗ | return 0; | |
50 | } | ||
51 | |||
52 |
2/2✓ Branch 0 taken 282945407 times.
✓ Branch 1 taken 1810632 times.
|
569512078 | for (x = 0; x < w; x++) { |
53 | int diff, context, sign; | ||
54 | |||
55 |
2/2✓ Branch 0 taken 1810632 times.
✓ Branch 1 taken 281134775 times.
|
565890814 | if (!(x & 1023)) { |
56 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1810632 times.
|
3621264 | if (is_input_end(s)) |
57 | ✗ | return AVERROR_INVALIDDATA; | |
58 | } | ||
59 | |||
60 | 565890814 | context = RENAME(get_context)(p, sample[1] + x, sample[0] + x, sample[1] + x); | |
61 |
2/2✓ Branch 0 taken 121857454 times.
✓ Branch 1 taken 161087953 times.
|
565890814 | if (context < 0) { |
62 | 243714908 | context = -context; | |
63 | 243714908 | sign = 1; | |
64 | } else | ||
65 | 322175906 | sign = 0; | |
66 | |||
67 | av_assert2(context < p->context_count); | ||
68 | |||
69 |
2/2✓ Branch 0 taken 151603536 times.
✓ Branch 1 taken 131341871 times.
|
565890814 | if (s->ac != AC_GOLOMB_RICE) { |
70 | 303207072 | diff = get_symbol_inline(c, p->state[context], 1); | |
71 | } else { | ||
72 |
4/4✓ Branch 0 taken 2033133 times.
✓ Branch 1 taken 129308738 times.
✓ Branch 2 taken 1410251 times.
✓ Branch 3 taken 622882 times.
|
262683742 | if (context == 0 && run_mode == 0) |
73 | 2820502 | run_mode = 1; | |
74 | |||
75 |
2/2✓ Branch 0 taken 3184350 times.
✓ Branch 1 taken 128157521 times.
|
262683742 | if (run_mode) { |
76 |
3/4✓ Branch 0 taken 3184350 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2653980 times.
✓ Branch 3 taken 530370 times.
|
6368700 | if (run_count == 0 && run_mode == 1) { |
77 |
2/2✓ Branch 1 taken 1296943 times.
✓ Branch 2 taken 1357037 times.
|
5307960 | if (get_bits1(&s->gb)) { |
78 | 2593886 | run_count = 1 << ff_log2_run[run_index]; | |
79 |
2/2✓ Branch 0 taken 1261893 times.
✓ Branch 1 taken 35050 times.
|
2593886 | if (x + run_count <= w) |
80 | 2523786 | run_index++; | |
81 | } else { | ||
82 |
2/2✓ Branch 0 taken 1004769 times.
✓ Branch 1 taken 352268 times.
|
2714074 | if (ff_log2_run[run_index]) |
83 | 2009538 | run_count = get_bits(&s->gb, ff_log2_run[run_index]); | |
84 | else | ||
85 | 704536 | run_count = 0; | |
86 |
2/2✓ Branch 0 taken 1250932 times.
✓ Branch 1 taken 106105 times.
|
2714074 | if (run_index) |
87 | 2501864 | run_index--; | |
88 | 2714074 | run_mode = 2; | |
89 | } | ||
90 | } | ||
91 |
2/2✓ Branch 0 taken 3181851 times.
✓ Branch 1 taken 2499 times.
|
6368700 | if (sample[1][x - 1] == sample[0][x - 1]) { |
92 |
4/4✓ Branch 0 taken 1797086 times.
✓ Branch 1 taken 3146802 times.
✓ Branch 2 taken 1762037 times.
✓ Branch 3 taken 35049 times.
|
9887776 | while (run_count > 1 && w-x > 1) { |
93 | 3524074 | sample[1][x] = sample[0][x]; | |
94 | 3524074 | x++; | |
95 | 3524074 | run_count--; | |
96 | } | ||
97 | } else { | ||
98 |
4/4✓ Branch 0 taken 507 times.
✓ Branch 1 taken 2498 times.
✓ Branch 2 taken 506 times.
✓ Branch 3 taken 1 times.
|
6010 | while (run_count > 1 && w-x > 1) { |
99 | 1012 | sample[1][x] = RENAME(predict)(sample[1] + x, sample[0] + x); | |
100 | 1012 | x++; | |
101 | 1012 | run_count--; | |
102 | } | ||
103 | } | ||
104 | 6368700 | run_count--; | |
105 |
2/2✓ Branch 0 taken 1357037 times.
✓ Branch 1 taken 1827313 times.
|
6368700 | if (run_count < 0) { |
106 | 2714074 | run_mode = 0; | |
107 | 2714074 | run_count = 0; | |
108 | 2714074 | diff = get_vlc_symbol(&s->gb, &p->vlc_state[context], | |
109 | bits); | ||
110 |
2/2✓ Branch 0 taken 633176 times.
✓ Branch 1 taken 723861 times.
|
2714074 | if (diff >= 0) |
111 | 1266352 | diff++; | |
112 | } else | ||
113 | 3654626 | diff = 0; | |
114 | } else | ||
115 | 256315042 | diff = get_vlc_symbol(&s->gb, &p->vlc_state[context], bits); | |
116 | |||
117 | ff_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n", | ||
118 | run_count, run_index, run_mode, x, get_bits_count(&s->gb)); | ||
119 | } | ||
120 | |||
121 |
2/2✓ Branch 0 taken 121857454 times.
✓ Branch 1 taken 161087953 times.
|
565890814 | if (sign) |
122 | 243714908 | diff = -(unsigned)diff; | |
123 | |||
124 | 565890814 | sample[1][x] = av_mod_uintp2(RENAME(predict)(sample[1] + x, sample[0] + x) + (SUINT)diff, bits); | |
125 | } | ||
126 | 3621264 | s->run_index = run_index; | |
127 | 3621264 | return 0; | |
128 | } | ||
129 | |||
130 | 1632 | static int RENAME(decode_rgb_frame)(FFV1Context *s, uint8_t *src[4], int w, int h, int stride[4]) | |
131 | { | ||
132 | int x, y, p; | ||
133 | TYPE *sample[4][2]; | ||
134 | 1632 | int lbd = s->avctx->bits_per_raw_sample <= 8; | |
135 | 1632 | int bits = s->avctx->bits_per_raw_sample > 0 ? s->avctx->bits_per_raw_sample : 8; | |
136 | 1632 | int offset = 1 << bits; | |
137 | 1632 | int transparency = s->transparency; | |
138 | |||
139 | 8160 | for (x = 0; x < 4; x++) { | |
140 | 6528 | sample[x][0] = RENAME(s->sample_buffer) + x * 2 * (w + 6) + 3; | |
141 | 6528 | sample[x][1] = RENAME(s->sample_buffer) + (x * 2 + 1) * (w + 6) + 3; | |
142 | } | ||
143 | |||
144 | 1632 | s->run_index = 0; | |
145 | |||
146 | 1632 | memset(RENAME(s->sample_buffer), 0, 8 * (w + 6) * sizeof(*RENAME(s->sample_buffer))); | |
147 | |||
148 | 184824 | for (y = 0; y < h; y++) { | |
149 | 732768 | for (p = 0; p < 3 + transparency; p++) { | |
150 | int ret; | ||
151 | 549576 | TYPE *temp = sample[p][0]; // FIXME: try a normal buffer | |
152 | |||
153 | 549576 | sample[p][0] = sample[p][1]; | |
154 | 549576 | sample[p][1] = temp; | |
155 | |||
156 | 549576 | sample[p][1][-1]= sample[p][0][0 ]; | |
157 | 549576 | sample[p][0][ w]= sample[p][0][w-1]; | |
158 | 549576 | if (lbd && s->slice_coding_mode == 0) | |
159 | 274788 | ret = RENAME(decode_line)(s, w, sample[p], (p + 1)/2, 9); | |
160 | else | ||
161 | 274788 | ret = RENAME(decode_line)(s, w, sample[p], (p + 1)/2, bits + (s->slice_coding_mode != 1)); | |
162 | 549576 | if (ret < 0) | |
163 | ✗ | return ret; | |
164 | } | ||
165 | 31322160 | for (x = 0; x < w; x++) { | |
166 | 31138968 | int g = sample[0][1][x]; | |
167 | 31138968 | int b = sample[1][1][x]; | |
168 | 31138968 | int r = sample[2][1][x]; | |
169 | 31138968 | int a = sample[3][1][x]; | |
170 | |||
171 | 31138968 | if (s->slice_coding_mode != 1) { | |
172 | 31138968 | b -= offset; | |
173 | 31138968 | r -= offset; | |
174 | 31138968 | g -= (b * s->slice_rct_by_coef + r * s->slice_rct_ry_coef) >> 2; | |
175 | 31138968 | b += g; | |
176 | 31138968 | r += g; | |
177 | } | ||
178 | |||
179 | 31138968 | if (lbd) | |
180 | 15569484 | *((uint32_t*)(src[0] + x*4 + stride[0]*y)) = b + ((unsigned)g<<8) + ((unsigned)r<<16) + ((unsigned)a<<24); | |
181 | ✗ | else if (sizeof(TYPE) == 4 || transparency) { | |
182 | 15569484 | *((uint16_t*)(src[0] + x*2 + stride[0]*y)) = g; | |
183 | 15569484 | *((uint16_t*)(src[1] + x*2 + stride[1]*y)) = b; | |
184 | 15569484 | *((uint16_t*)(src[2] + x*2 + stride[2]*y)) = r; | |
185 | 15569484 | if (transparency) | |
186 | ✗ | *((uint16_t*)(src[3] + x*2 + stride[3]*y)) = a; | |
187 | } else { | ||
188 | ✗ | *((uint16_t*)(src[0] + x*2 + stride[0]*y)) = b; | |
189 | ✗ | *((uint16_t*)(src[1] + x*2 + stride[1]*y)) = g; | |
190 | ✗ | *((uint16_t*)(src[2] + x*2 + stride[2]*y)) = r; | |
191 | } | ||
192 | } | ||
193 | } | ||
194 | 1632 | return 0; | |
195 | } | ||
196 |