| 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 | static av_always_inline int | ||
| 26 | 4542400 | RENAME(decode_line)(FFV1Context *f, FFV1SliceContext *sc, | |
| 27 | GetBitContext *gb, | ||
| 28 | int w, TYPE *sample[2], int plane_index, int bits, | ||
| 29 | int ac) | ||
| 30 | { | ||
| 31 | 4542400 | PlaneContext *const p = &sc->plane[plane_index]; | |
| 32 | 4542400 | RangeCoder *const c = &sc->c; | |
| 33 | 4542400 | const int16_t (*quant_table)[256] = f->quant_tables[p->quant_table_index]; | |
| 34 | int x; | ||
| 35 | 4542400 | int run_count = 0; | |
| 36 | 4542400 | int run_mode = 0; | |
| 37 | 4542400 | int run_index = sc->run_index; | |
| 38 | |||
| 39 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2271200 times.
|
4542400 | if (bits == 0) { |
| 40 | ✗ | for (x = 0; x < w; x++) | |
| 41 | ✗ | sample[1][x] = 0; | |
| 42 | ✗ | return 0; | |
| 43 | } | ||
| 44 | |||
| 45 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2271200 times.
|
4542400 | if (is_input_end(c, gb, ac)) |
| 46 | ✗ | return AVERROR_INVALIDDATA; | |
| 47 | |||
| 48 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2271200 times.
|
4542400 | if (sc->slice_coding_mode == 1) { |
| 49 | int i; | ||
| 50 | ✗ | for (x = 0; x < w; x++) { | |
| 51 | ✗ | int v = 0; | |
| 52 | ✗ | for (i=0; i<bits; i++) { | |
| 53 | ✗ | uint8_t state = 128; | |
| 54 | ✗ | v += v + get_rac(c, &state); | |
| 55 | } | ||
| 56 | ✗ | sample[1][x] = v; | |
| 57 | } | ||
| 58 | ✗ | return 0; | |
| 59 | } | ||
| 60 | |||
| 61 |
2/2✓ Branch 0 taken 341305210 times.
✓ Branch 1 taken 2271200 times.
|
687152820 | for (x = 0; x < w; x++) { |
| 62 | int diff, context, sign; | ||
| 63 | |||
| 64 |
2/2✓ Branch 0 taken 2271200 times.
✓ Branch 1 taken 339034010 times.
|
682610420 | if (!(x & 1023)) { |
| 65 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2271200 times.
|
4542400 | if (is_input_end(c, gb, ac)) |
| 66 | ✗ | return AVERROR_INVALIDDATA; | |
| 67 | } | ||
| 68 | |||
| 69 | 682610420 | context = RENAME(get_context)(quant_table, | |
| 70 | 682610420 | sample[1] + x, sample[0] + x, sample[1] + x); | |
| 71 |
2/2✓ Branch 0 taken 155690847 times.
✓ Branch 1 taken 185614363 times.
|
682610420 | if (context < 0) { |
| 72 | 311381694 | context = -context; | |
| 73 | 311381694 | sign = 1; | |
| 74 | } else | ||
| 75 | 371228726 | sign = 0; | |
| 76 | |||
| 77 | av_assert2(context < p->context_count); | ||
| 78 | |||
| 79 |
2/2✓ Branch 0 taken 175548600 times.
✓ Branch 1 taken 165756610 times.
|
682610420 | if (ac != AC_GOLOMB_RICE) { |
| 80 | 351097200 | diff = get_symbol_inline(c, p->state[context], 1); | |
| 81 | } else { | ||
| 82 |
4/4✓ Branch 0 taken 2363615 times.
✓ Branch 1 taken 163392995 times.
✓ Branch 2 taken 1633389 times.
✓ Branch 3 taken 730226 times.
|
331513220 | if (context == 0 && run_mode == 0) |
| 83 | 3266778 | run_mode = 1; | |
| 84 | |||
| 85 |
2/2✓ Branch 0 taken 3672506 times.
✓ Branch 1 taken 162084104 times.
|
331513220 | if (run_mode) { |
| 86 |
3/4✓ Branch 0 taken 3672506 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3070747 times.
✓ Branch 3 taken 601759 times.
|
7345012 | if (run_count == 0 && run_mode == 1) { |
| 87 |
2/2✓ Branch 1 taken 1494860 times.
✓ Branch 2 taken 1575887 times.
|
6141494 | if (get_bits1(gb)) { |
| 88 | 2989720 | run_count = 1 << ff_log2_run[run_index]; | |
| 89 |
2/2✓ Branch 0 taken 1457152 times.
✓ Branch 1 taken 37708 times.
|
2989720 | if (x + run_count <= w) |
| 90 | 2914304 | run_index++; | |
| 91 | } else { | ||
| 92 |
2/2✓ Branch 0 taken 1135347 times.
✓ Branch 1 taken 440540 times.
|
3151774 | if (ff_log2_run[run_index]) |
| 93 | 2270694 | run_count = get_bits(gb, ff_log2_run[run_index]); | |
| 94 | else | ||
| 95 | 881080 | run_count = 0; | |
| 96 |
2/2✓ Branch 0 taken 1439479 times.
✓ Branch 1 taken 136408 times.
|
3151774 | if (run_index) |
| 97 | 2878958 | run_index--; | |
| 98 | 3151774 | run_mode = 2; | |
| 99 | } | ||
| 100 | } | ||
| 101 |
2/2✓ Branch 0 taken 3670069 times.
✓ Branch 1 taken 2437 times.
|
7345012 | if (sample[1][x - 1] == sample[0][x - 1]) { |
| 102 |
4/4✓ Branch 0 taken 2427452 times.
✓ Branch 1 taken 3632362 times.
✓ Branch 2 taken 2389745 times.
✓ Branch 3 taken 37707 times.
|
12119628 | while (run_count > 1 && w-x > 1) { |
| 103 | 4779490 | sample[1][x] = sample[0][x]; | |
| 104 | 4779490 | x++; | |
| 105 | 4779490 | run_count--; | |
| 106 | } | ||
| 107 | } else { | ||
| 108 |
4/4✓ Branch 0 taken 346 times.
✓ Branch 1 taken 2436 times.
✓ Branch 2 taken 345 times.
✓ Branch 3 taken 1 times.
|
5564 | while (run_count > 1 && w-x > 1) { |
| 109 | 690 | sample[1][x] = RENAME(predict)(sample[1] + x, sample[0] + x); | |
| 110 | 690 | x++; | |
| 111 | 690 | run_count--; | |
| 112 | } | ||
| 113 | } | ||
| 114 | 7345012 | run_count--; | |
| 115 |
2/2✓ Branch 0 taken 1575887 times.
✓ Branch 1 taken 2096619 times.
|
7345012 | if (run_count < 0) { |
| 116 | 3151774 | run_mode = 0; | |
| 117 | 3151774 | run_count = 0; | |
| 118 | 3151774 | diff = get_vlc_symbol(gb, &p->vlc_state[context], | |
| 119 | bits); | ||
| 120 |
2/2✓ Branch 0 taken 740677 times.
✓ Branch 1 taken 835210 times.
|
3151774 | if (diff >= 0) |
| 121 | 1481354 | diff++; | |
| 122 | } else | ||
| 123 | 4193238 | diff = 0; | |
| 124 | } else | ||
| 125 | 324168208 | diff = get_vlc_symbol(gb, &p->vlc_state[context], bits); | |
| 126 | |||
| 127 | ff_dlog(f->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n", | ||
| 128 | run_count, run_index, run_mode, x, get_bits_count(gb)); | ||
| 129 | } | ||
| 130 | |||
| 131 |
2/2✓ Branch 0 taken 155690847 times.
✓ Branch 1 taken 185614363 times.
|
682610420 | if (sign) |
| 132 | 311381694 | diff = -(unsigned)diff; | |
| 133 | |||
| 134 | 682610420 | sample[1][x] = av_zero_extend(RENAME(predict)(sample[1] + x, sample[0] + x) + (SUINT)diff, bits); | |
| 135 | } | ||
| 136 | 4542400 | sc->run_index = run_index; | |
| 137 | 4542400 | return 0; | |
| 138 | } | ||
| 139 | |||
| 140 | 1600 | static int RENAME(decode_rgb_frame)(FFV1Context *f, FFV1SliceContext *sc, | |
| 141 | GetBitContext *gb, | ||
| 142 | uint8_t *src[4], int w, int h, int stride[4]) | ||
| 143 | { | ||
| 144 | int x, y, p; | ||
| 145 | TYPE *sample[4][2]; | ||
| 146 | 1600 | int lbd = f->avctx->bits_per_raw_sample <= 8; | |
| 147 | int bits[4], offset; | ||
| 148 | 1600 | int transparency = f->transparency; | |
| 149 | 1600 | int ac = f->ac; | |
| 150 | unsigned mask[4]; | ||
| 151 | |||
| 152 | 1600 | ff_ffv1_compute_bits_per_plane(f, sc, bits, &offset, mask, f->avctx->bits_per_raw_sample); | |
| 153 | |||
| 154 | 1600 | if (sc->slice_coding_mode == 1) | |
| 155 | ✗ | ac = 1; | |
| 156 | |||
| 157 | 8000 | for (x = 0; x < 4; x++) { | |
| 158 | 6400 | sample[x][0] = RENAME(sc->sample_buffer) + x * 2 * (w + 6) + 3; | |
| 159 | 6400 | sample[x][1] = RENAME(sc->sample_buffer) + (x * 2 + 1) * (w + 6) + 3; | |
| 160 | } | ||
| 161 | |||
| 162 | 1600 | sc->run_index = 0; | |
| 163 | |||
| 164 | 1600 | memset(RENAME(sc->sample_buffer), 0, 8 * (w + 6) * sizeof(*RENAME(sc->sample_buffer))); | |
| 165 | |||
| 166 | 181200 | for (y = 0; y < h; y++) { | |
| 167 | 718400 | for (p = 0; p < 3 + transparency; p++) { | |
| 168 | int ret; | ||
| 169 | 538800 | TYPE *temp = sample[p][0]; // FIXME: try a normal buffer | |
| 170 | |||
| 171 | 538800 | sample[p][0] = sample[p][1]; | |
| 172 | 538800 | sample[p][1] = temp; | |
| 173 | |||
| 174 | 538800 | sample[p][1][-1]= sample[p][0][0 ]; | |
| 175 | 538800 | sample[p][0][ w]= sample[p][0][w-1]; | |
| 176 | 538800 | if (bits[p] == 9) | |
| 177 | 269400 | ret = RENAME(decode_line)(f, sc, gb, w, sample[p], (p + 1)/2, 9, ac); | |
| 178 | else | ||
| 179 | 269400 | ret = RENAME(decode_line)(f, sc, gb, w, sample[p], (p + 1)/2, bits[p], ac); | |
| 180 | 538800 | if (ret < 0) | |
| 181 | ✗ | return ret; | |
| 182 | } | ||
| 183 | 30708000 | for (x = 0; x < w; x++) { | |
| 184 | 30528400 | int g = sample[0][1][x]; | |
| 185 | 30528400 | int b = sample[1][1][x]; | |
| 186 | 30528400 | int r = sample[2][1][x]; | |
| 187 | 30528400 | int a = sample[3][1][x]; | |
| 188 | |||
| 189 | 30528400 | if (sc->slice_coding_mode != 1) { | |
| 190 | 30528400 | b -= offset; | |
| 191 | 30528400 | r -= offset; | |
| 192 | 30528400 | g -= (b * sc->slice_rct_by_coef + r * sc->slice_rct_ry_coef) >> 2; | |
| 193 | 30528400 | b += g; | |
| 194 | 30528400 | r += g; | |
| 195 | } | ||
| 196 | 30528400 | if (sc->remap) { | |
| 197 | ✗ | if (f->avctx->bits_per_raw_sample == 32) { | |
| 198 | ✗ | g = sc->fltmap32[0][g & mask[0]]; | |
| 199 | ✗ | b = sc->fltmap32[1][b & mask[1]]; | |
| 200 | ✗ | r = sc->fltmap32[2][r & mask[2]]; | |
| 201 | ✗ | if (transparency) | |
| 202 | ✗ | a = sc->fltmap32[3][a & mask[3]]; | |
| 203 | } else { | ||
| 204 | ✗ | g = sc->fltmap[0][g & mask[0]]; | |
| 205 | ✗ | b = sc->fltmap[1][b & mask[1]]; | |
| 206 | ✗ | r = sc->fltmap[2][r & mask[2]]; | |
| 207 | ✗ | if (transparency) | |
| 208 | ✗ | a = sc->fltmap[3][a & mask[3]]; | |
| 209 | } | ||
| 210 | } | ||
| 211 | |||
| 212 | 30528400 | if (lbd) { | |
| 213 | 15264200 | *((uint32_t*)(src[0] + x*4 + stride[0]*y)) = b + ((unsigned)g<<8) + ((unsigned)r<<16) + ((unsigned)a<<24); | |
| 214 | 15264200 | } else if (f->avctx->bits_per_raw_sample == 32) { | |
| 215 | ✗ | *((uint32_t*)(src[0] + x*4 + stride[0]*y)) = g; | |
| 216 | ✗ | *((uint32_t*)(src[1] + x*4 + stride[1]*y)) = b; | |
| 217 | ✗ | *((uint32_t*)(src[2] + x*4 + stride[2]*y)) = r; | |
| 218 | ✗ | if (transparency) | |
| 219 | ✗ | *((uint32_t*)(src[3] + x*4 + stride[3]*y)) = a; | |
| 220 | ✗ | } else if (sizeof(TYPE) == 4 || transparency) { | |
| 221 | 15264200 | *((uint16_t*)(src[0] + x*2 + stride[0]*y)) = g; | |
| 222 | 15264200 | *((uint16_t*)(src[1] + x*2 + stride[1]*y)) = b; | |
| 223 | 15264200 | *((uint16_t*)(src[2] + x*2 + stride[2]*y)) = r; | |
| 224 | 15264200 | if (transparency) | |
| 225 | ✗ | *((uint16_t*)(src[3] + x*2 + stride[3]*y)) = a; | |
| 226 | } else { | ||
| 227 | ✗ | *((uint16_t*)(src[0] + x*2 + stride[0]*y)) = b; | |
| 228 | ✗ | *((uint16_t*)(src[1] + x*2 + stride[1]*y)) = g; | |
| 229 | ✗ | *((uint16_t*)(src[2] + x*2 + stride[2]*y)) = r; | |
| 230 | } | ||
| 231 | } | ||
| 232 | } | ||
| 233 | 1600 | return 0; | |
| 234 | } | ||
| 235 |