| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of FFmpeg. | ||
| 3 | * | ||
| 4 | * FFmpeg is free software; you can redistribute it and/or | ||
| 5 | * modify it under the terms of the GNU Lesser General Public | ||
| 6 | * License as published by the Free Software Foundation; either | ||
| 7 | * version 2.1 of the License, or (at your option) any later version. | ||
| 8 | * | ||
| 9 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | * Lesser General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU Lesser General Public | ||
| 15 | * License along with FFmpeg; if not, write to the Free Software | ||
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include "libavutil/crc.h" | ||
| 20 | #include "libavutil/mem.h" | ||
| 21 | #include "libavutil/pixdesc.h" | ||
| 22 | #include "rangecoder.h" | ||
| 23 | #include "ffv1.h" | ||
| 24 | |||
| 25 | 1540 | static int read_quant_table(RangeCoder *c, int16_t *quant_table, int scale) | |
| 26 | { | ||
| 27 | int v; | ||
| 28 | 1540 | int i = 0; | |
| 29 | uint8_t state[CONTEXT_SIZE]; | ||
| 30 | |||
| 31 | 1540 | memset(state, 128, sizeof(state)); | |
| 32 | |||
| 33 |
2/2✓ Branch 0 taken 6037 times.
✓ Branch 1 taken 1540 times.
|
7577 | for (v = 0; i < 128; v++) { |
| 34 | 6037 | unsigned len = ff_ffv1_get_symbol(c, state, 0) + 1U; | |
| 35 | |||
| 36 |
2/4✓ Branch 0 taken 6037 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6037 times.
|
6037 | if (len > 128 - i || !len) |
| 37 | ✗ | return AVERROR_INVALIDDATA; | |
| 38 | |||
| 39 |
2/2✓ Branch 0 taken 197120 times.
✓ Branch 1 taken 6037 times.
|
203157 | while (len--) { |
| 40 | 197120 | quant_table[i] = scale * v; | |
| 41 | 197120 | i++; | |
| 42 | } | ||
| 43 | } | ||
| 44 | |||
| 45 |
2/2✓ Branch 0 taken 195580 times.
✓ Branch 1 taken 1540 times.
|
197120 | for (i = 1; i < 128; i++) |
| 46 | 195580 | quant_table[256 - i] = -quant_table[i]; | |
| 47 | 1540 | quant_table[128] = -quant_table[127]; | |
| 48 | |||
| 49 | 1540 | return 2 * v - 1; | |
| 50 | } | ||
| 51 | |||
| 52 | 308 | int ff_ffv1_read_quant_tables(RangeCoder *c, | |
| 53 | int16_t quant_table[MAX_CONTEXT_INPUTS][256]) | ||
| 54 | { | ||
| 55 | int i; | ||
| 56 | 308 | int context_count = 1; | |
| 57 | |||
| 58 |
2/2✓ Branch 0 taken 1540 times.
✓ Branch 1 taken 308 times.
|
1848 | for (i = 0; i < 5; i++) { |
| 59 | 1540 | int ret = read_quant_table(c, quant_table[i], context_count); | |
| 60 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1540 times.
|
1540 | if (ret < 0) |
| 61 | ✗ | return ret; | |
| 62 | 1540 | context_count *= ret; | |
| 63 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1540 times.
|
1540 | if (context_count > 32768U) { |
| 64 | ✗ | return AVERROR_INVALIDDATA; | |
| 65 | } | ||
| 66 | } | ||
| 67 | 308 | return (context_count + 1) / 2; | |
| 68 | } | ||
| 69 | |||
| 70 | 142 | int ff_ffv1_read_extra_header(FFV1Context *f) | |
| 71 | { | ||
| 72 | RangeCoder c; | ||
| 73 | uint8_t state[CONTEXT_SIZE]; | ||
| 74 | int ret; | ||
| 75 | uint8_t state2[32][CONTEXT_SIZE]; | ||
| 76 | 142 | unsigned crc = 0; | |
| 77 | |||
| 78 | 142 | memset(state2, 128, sizeof(state2)); | |
| 79 | 142 | memset(state, 128, sizeof(state)); | |
| 80 | |||
| 81 | 142 | ff_init_range_decoder(&c, f->avctx->extradata, f->avctx->extradata_size); | |
| 82 | 142 | ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8); | |
| 83 | |||
| 84 | 142 | f->version = ff_ffv1_get_symbol(&c, state, 0); | |
| 85 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 142 times.
|
142 | if (f->version < 2) { |
| 86 | ✗ | av_log(f->avctx, AV_LOG_ERROR, "Invalid version in global header\n"); | |
| 87 | ✗ | return AVERROR_INVALIDDATA; | |
| 88 | } | ||
| 89 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 142 times.
|
142 | if (f->version > 4) { |
| 90 | ✗ | av_log(f->avctx, AV_LOG_ERROR, "unsupported version %d\n", | |
| 91 | f->version); | ||
| 92 | ✗ | return AVERROR_PATCHWELCOME; | |
| 93 | } | ||
| 94 | 142 | f->combined_version = f->version << 16; | |
| 95 |
2/2✓ Branch 0 taken 130 times.
✓ Branch 1 taken 12 times.
|
142 | if (f->version > 2) { |
| 96 | 130 | c.bytestream_end -= 4; | |
| 97 | 130 | f->micro_version = ff_ffv1_get_symbol(&c, state, 0); | |
| 98 |
2/4✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 130 times.
|
130 | if (f->micro_version < 0 || f->micro_version > 65535) |
| 99 | ✗ | return AVERROR_INVALIDDATA; | |
| 100 | 130 | f->combined_version += f->micro_version; | |
| 101 | } | ||
| 102 | 142 | f->ac = ff_ffv1_get_symbol(&c, state, 0); | |
| 103 | |||
| 104 |
2/2✓ Branch 0 taken 65 times.
✓ Branch 1 taken 77 times.
|
142 | if (f->ac == AC_RANGE_CUSTOM_TAB) { |
| 105 |
2/2✓ Branch 0 taken 16575 times.
✓ Branch 1 taken 65 times.
|
16640 | for (int i = 1; i < 256; i++) |
| 106 | 16575 | f->state_transition[i] = ff_ffv1_get_symbol(&c, state, 1) + c.one_state[i]; | |
| 107 | } else { | ||
| 108 | RangeCoder rc; | ||
| 109 | 77 | ff_build_rac_states(&rc, 0.05 * (1LL << 32), 256 - 8); | |
| 110 |
2/2✓ Branch 0 taken 19635 times.
✓ Branch 1 taken 77 times.
|
19712 | for (int i = 1; i < 256; i++) |
| 111 | 19635 | f->state_transition[i] = rc.one_state[i]; | |
| 112 | } | ||
| 113 | |||
| 114 | 142 | f->colorspace = ff_ffv1_get_symbol(&c, state, 0); //YUV cs type | |
| 115 | 142 | f->avctx->bits_per_raw_sample = ff_ffv1_get_symbol(&c, state, 0); | |
| 116 | 142 | f->chroma_planes = get_rac(&c, state); | |
| 117 | 142 | f->chroma_h_shift = ff_ffv1_get_symbol(&c, state, 0); | |
| 118 | 142 | f->chroma_v_shift = ff_ffv1_get_symbol(&c, state, 0); | |
| 119 | 142 | f->transparency = get_rac(&c, state); | |
| 120 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 142 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
142 | f->plane_count = 1 + (f->chroma_planes || f->version<4) + f->transparency; |
| 121 | 142 | f->num_h_slices = 1 + ff_ffv1_get_symbol(&c, state, 0); | |
| 122 | 142 | f->num_v_slices = 1 + ff_ffv1_get_symbol(&c, state, 0); | |
| 123 | |||
| 124 |
2/4✓ Branch 0 taken 142 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 142 times.
|
142 | if (f->chroma_h_shift > 4U || f->chroma_v_shift > 4U) { |
| 125 | ✗ | av_log(f->avctx, AV_LOG_ERROR, "chroma shift parameters %d %d are invalid\n", | |
| 126 | f->chroma_h_shift, f->chroma_v_shift); | ||
| 127 | ✗ | return AVERROR_INVALIDDATA; | |
| 128 | } | ||
| 129 | |||
| 130 |
2/4✓ Branch 0 taken 142 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 142 times.
✗ Branch 3 not taken.
|
142 | if (f->num_h_slices > (unsigned)f->width || !f->num_h_slices || |
| 131 |
2/4✓ Branch 0 taken 142 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 142 times.
|
142 | f->num_v_slices > (unsigned)f->height || !f->num_v_slices |
| 132 | ) { | ||
| 133 | ✗ | av_log(f->avctx, AV_LOG_ERROR, "slice count invalid\n"); | |
| 134 | ✗ | return AVERROR_INVALIDDATA; | |
| 135 | } | ||
| 136 | |||
| 137 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 142 times.
|
142 | if (f->num_h_slices > MAX_SLICES / f->num_v_slices) { |
| 138 | ✗ | av_log(f->avctx, AV_LOG_ERROR, "slice count unsupported\n"); | |
| 139 | ✗ | return AVERROR_PATCHWELCOME; | |
| 140 | } | ||
| 141 | |||
| 142 | 142 | f->quant_table_count = ff_ffv1_get_symbol(&c, state, 0); | |
| 143 |
2/4✓ Branch 0 taken 142 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 142 times.
|
142 | if (f->quant_table_count > (unsigned)MAX_QUANT_TABLES || !f->quant_table_count) { |
| 144 | ✗ | av_log(f->avctx, AV_LOG_ERROR, "quant table count %d is invalid\n", f->quant_table_count); | |
| 145 | ✗ | f->quant_table_count = 0; | |
| 146 | ✗ | return AVERROR_INVALIDDATA; | |
| 147 | } | ||
| 148 | |||
| 149 |
2/2✓ Branch 0 taken 284 times.
✓ Branch 1 taken 142 times.
|
426 | for (int i = 0; i < f->quant_table_count; i++) { |
| 150 | 284 | f->context_count[i] = ff_ffv1_read_quant_tables(&c, f->quant_tables[i]); | |
| 151 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 284 times.
|
284 | if (f->context_count[i] < 0) { |
| 152 | ✗ | av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n"); | |
| 153 | ✗ | return AVERROR_INVALIDDATA; | |
| 154 | } | ||
| 155 | } | ||
| 156 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 142 times.
|
142 | if ((ret = ff_ffv1_allocate_initial_states(f)) < 0) |
| 157 | ✗ | return ret; | |
| 158 | |||
| 159 |
2/2✓ Branch 0 taken 284 times.
✓ Branch 1 taken 142 times.
|
426 | for (int i = 0; i < f->quant_table_count; i++) |
| 160 |
2/2✓ Branch 1 taken 24 times.
✓ Branch 2 taken 260 times.
|
284 | if (get_rac(&c, state)) { |
| 161 |
2/2✓ Branch 0 taken 151512 times.
✓ Branch 1 taken 24 times.
|
151536 | for (int j = 0; j < f->context_count[i]; j++) |
| 162 |
2/2✓ Branch 0 taken 4848384 times.
✓ Branch 1 taken 151512 times.
|
4999896 | for (int k = 0; k < CONTEXT_SIZE; k++) { |
| 163 |
2/2✓ Branch 0 taken 4847616 times.
✓ Branch 1 taken 768 times.
|
4848384 | int pred = j ? f->initial_states[i][j - 1][k] : 128; |
| 164 | 4848384 | f->initial_states[i][j][k] = | |
| 165 | 4848384 | (pred + ff_ffv1_get_symbol(&c, state2[k], 1)) & 0xFF; | |
| 166 | } | ||
| 167 | } | ||
| 168 | |||
| 169 |
2/2✓ Branch 0 taken 130 times.
✓ Branch 1 taken 12 times.
|
142 | if (f->version > 2) { |
| 170 | 130 | f->ec = ff_ffv1_get_symbol(&c, state, 0); | |
| 171 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 130 times.
|
130 | if (f->ec >= 2) |
| 172 | ✗ | f->crcref = 0x7a8c4079; | |
| 173 |
1/2✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
|
130 | if (f->combined_version >= 0x30003) |
| 174 | 130 | f->intra = ff_ffv1_get_symbol(&c, state, 0); | |
| 175 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 130 times.
|
130 | if (f->combined_version >= 0x40004) |
| 176 | ✗ | f->flt = ff_ffv1_get_symbol(&c, state, 0); | |
| 177 | } | ||
| 178 | |||
| 179 |
2/2✓ Branch 0 taken 130 times.
✓ Branch 1 taken 12 times.
|
142 | if (f->version > 2) { |
| 180 | unsigned v; | ||
| 181 | 260 | v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), f->crcref, | |
| 182 | 130 | f->avctx->extradata, f->avctx->extradata_size); | |
| 183 |
2/4✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 130 times.
|
130 | if (v != f->crcref || f->avctx->extradata_size < 4) { |
| 184 | ✗ | av_log(f->avctx, AV_LOG_ERROR, "CRC mismatch %X!\n", v); | |
| 185 | ✗ | return AVERROR_INVALIDDATA; | |
| 186 | } | ||
| 187 | 130 | crc = AV_RB32(f->avctx->extradata + f->avctx->extradata_size - 4); | |
| 188 | } | ||
| 189 | |||
| 190 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 142 times.
|
142 | if (f->avctx->debug & FF_DEBUG_PICT_INFO) |
| 191 | ✗ | av_log(f->avctx, AV_LOG_DEBUG, | |
| 192 | "global: ver:%d.%d, coder:%d, colorspace: %d bpr:%d chroma:%d(%d:%d), alpha:%d slices:%dx%d qtabs:%d ec:%d intra:%d CRC:0x%08X\n", | ||
| 193 | f->version, f->micro_version, | ||
| 194 | f->ac, | ||
| 195 | f->colorspace, | ||
| 196 | ✗ | f->avctx->bits_per_raw_sample, | |
| 197 | f->chroma_planes, f->chroma_h_shift, f->chroma_v_shift, | ||
| 198 | f->transparency, | ||
| 199 | f->num_h_slices, f->num_v_slices, | ||
| 200 | f->quant_table_count, | ||
| 201 | f->ec, | ||
| 202 | f->intra, | ||
| 203 | crc | ||
| 204 | ); | ||
| 205 | 142 | return 0; | |
| 206 | } | ||
| 207 | |||
| 208 | 478 | int ff_ffv1_parse_header(FFV1Context *f, RangeCoder *c, uint8_t *state) | |
| 209 | { | ||
| 210 |
2/2✓ Branch 0 taken 44 times.
✓ Branch 1 taken 434 times.
|
478 | if (f->version < 2) { |
| 211 | int chroma_planes, chroma_h_shift, chroma_v_shift, transparency, colorspace, bits_per_raw_sample; | ||
| 212 | 44 | unsigned v= ff_ffv1_get_symbol(c, state, 0); | |
| 213 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
|
44 | if (v >= 2) { |
| 214 | ✗ | av_log(f->avctx, AV_LOG_ERROR, "invalid version %d in ver01 header\n", v); | |
| 215 | ✗ | return AVERROR_INVALIDDATA; | |
| 216 | } | ||
| 217 | 44 | f->version = v; | |
| 218 | 44 | f->ac = ff_ffv1_get_symbol(c, state, 0); | |
| 219 | |||
| 220 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
|
44 | if (f->ac == AC_RANGE_CUSTOM_TAB) { |
| 221 | ✗ | for (int i = 1; i < 256; i++) { | |
| 222 | ✗ | int st = ff_ffv1_get_symbol(c, state, 1) + c->one_state[i]; | |
| 223 | ✗ | if (st < 1 || st > 255) { | |
| 224 | ✗ | av_log(f->avctx, AV_LOG_ERROR, "invalid state transition %d\n", st); | |
| 225 | ✗ | return AVERROR_INVALIDDATA; | |
| 226 | } | ||
| 227 | ✗ | f->state_transition[i] = st; | |
| 228 | } | ||
| 229 | } else { | ||
| 230 | RangeCoder rc; | ||
| 231 | 44 | ff_build_rac_states(&rc, 0.05 * (1LL << 32), 256 - 8); | |
| 232 |
2/2✓ Branch 0 taken 11220 times.
✓ Branch 1 taken 44 times.
|
11264 | for (int i = 1; i < 256; i++) |
| 233 | 11220 | f->state_transition[i] = rc.one_state[i]; | |
| 234 | } | ||
| 235 | |||
| 236 | 44 | colorspace = ff_ffv1_get_symbol(c, state, 0); //YUV cs type | |
| 237 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
|
44 | bits_per_raw_sample = f->version > 0 ? ff_ffv1_get_symbol(c, state, 0) : f->avctx->bits_per_raw_sample; |
| 238 | 44 | chroma_planes = get_rac(c, state); | |
| 239 | 44 | chroma_h_shift = ff_ffv1_get_symbol(c, state, 0); | |
| 240 | 44 | chroma_v_shift = ff_ffv1_get_symbol(c, state, 0); | |
| 241 | 44 | transparency = get_rac(c, state); | |
| 242 |
2/4✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 44 times.
|
44 | if (colorspace == 0 && f->avctx->skip_alpha) |
| 243 | ✗ | transparency = 0; | |
| 244 | |||
| 245 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 12 times.
|
44 | if (f->plane_count) { |
| 246 |
1/2✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
|
32 | if (colorspace != f->colorspace || |
| 247 |
1/2✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
|
32 | bits_per_raw_sample != f->avctx->bits_per_raw_sample || |
| 248 |
1/2✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
|
32 | chroma_planes != f->chroma_planes || |
| 249 |
1/2✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
|
32 | chroma_h_shift != f->chroma_h_shift || |
| 250 |
1/2✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
|
32 | chroma_v_shift != f->chroma_v_shift || |
| 251 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | transparency != f->transparency) { |
| 252 | ✗ | av_log(f->avctx, AV_LOG_ERROR, "Invalid change of global parameters\n"); | |
| 253 | ✗ | return AVERROR_INVALIDDATA; | |
| 254 | } | ||
| 255 | } | ||
| 256 | |||
| 257 |
2/4✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 44 times.
|
44 | if (chroma_h_shift > 4U || chroma_v_shift > 4U) { |
| 258 | ✗ | av_log(f->avctx, AV_LOG_ERROR, "chroma shift parameters %d %d are invalid\n", | |
| 259 | chroma_h_shift, chroma_v_shift); | ||
| 260 | ✗ | return AVERROR_INVALIDDATA; | |
| 261 | } | ||
| 262 | |||
| 263 | 44 | f->colorspace = colorspace; | |
| 264 | 44 | f->avctx->bits_per_raw_sample = bits_per_raw_sample; | |
| 265 | 44 | f->chroma_planes = chroma_planes; | |
| 266 | 44 | f->chroma_h_shift = chroma_h_shift; | |
| 267 | 44 | f->chroma_v_shift = chroma_v_shift; | |
| 268 | 44 | f->transparency = transparency; | |
| 269 | |||
| 270 | 44 | f->plane_count = 2 + f->transparency; | |
| 271 | } | ||
| 272 | |||
| 273 |
2/2✓ Branch 0 taken 390 times.
✓ Branch 1 taken 88 times.
|
478 | if (f->colorspace == 0) { |
| 274 |
2/4✓ Branch 0 taken 390 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 390 times.
|
390 | if (!f->transparency && !f->chroma_planes) { |
| 275 | ✗ | if (f->avctx->bits_per_raw_sample <= 8) | |
| 276 | ✗ | f->pix_fmt = AV_PIX_FMT_GRAY8; | |
| 277 | ✗ | else if (f->avctx->bits_per_raw_sample == 9) { | |
| 278 | ✗ | f->packed_at_lsb = 1; | |
| 279 | ✗ | f->pix_fmt = AV_PIX_FMT_GRAY9; | |
| 280 | ✗ | } else if (f->avctx->bits_per_raw_sample == 10) { | |
| 281 | ✗ | f->packed_at_lsb = 1; | |
| 282 | ✗ | f->pix_fmt = AV_PIX_FMT_GRAY10; | |
| 283 | ✗ | } else if (f->avctx->bits_per_raw_sample == 12) { | |
| 284 | ✗ | f->packed_at_lsb = 1; | |
| 285 | ✗ | f->pix_fmt = AV_PIX_FMT_GRAY12; | |
| 286 | ✗ | } else if (f->avctx->bits_per_raw_sample == 14) { | |
| 287 | ✗ | f->packed_at_lsb = 1; | |
| 288 | ✗ | f->pix_fmt = AV_PIX_FMT_GRAY14; | |
| 289 | ✗ | } else if (f->avctx->bits_per_raw_sample == 16) { | |
| 290 | ✗ | f->packed_at_lsb = 1; | |
| 291 | ✗ | if (f->flt) { | |
| 292 | ✗ | f->pix_fmt = AV_PIX_FMT_GRAYF16; | |
| 293 | } else | ||
| 294 | ✗ | f->pix_fmt = AV_PIX_FMT_GRAY16; | |
| 295 | ✗ | } else if (f->avctx->bits_per_raw_sample < 16) { | |
| 296 | ✗ | f->pix_fmt = AV_PIX_FMT_GRAY16; | |
| 297 | } else | ||
| 298 | ✗ | return AVERROR(ENOSYS); | |
| 299 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 390 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
390 | } else if (f->transparency && !f->chroma_planes) { |
| 300 | ✗ | if (f->avctx->bits_per_raw_sample <= 8 && !f->flt) { | |
| 301 | ✗ | f->pix_fmt = AV_PIX_FMT_YA8; | |
| 302 | ✗ | } else if (f->avctx->bits_per_raw_sample == 16 && f->flt) { | |
| 303 | ✗ | f->pix_fmt = AV_PIX_FMT_YAF16; | |
| 304 | } else | ||
| 305 | ✗ | return AVERROR(ENOSYS); | |
| 306 |
3/4✓ Branch 0 taken 254 times.
✓ Branch 1 taken 136 times.
✓ Branch 2 taken 254 times.
✗ Branch 3 not taken.
|
390 | } else if (f->avctx->bits_per_raw_sample<=8 && !f->transparency) { |
| 307 |
1/7✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 254 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
254 | switch(16 * f->chroma_h_shift + f->chroma_v_shift) { |
| 308 | ✗ | case 0x00: f->pix_fmt = AV_PIX_FMT_YUV444P; break; | |
| 309 | ✗ | case 0x01: f->pix_fmt = AV_PIX_FMT_YUV440P; break; | |
| 310 | ✗ | case 0x10: f->pix_fmt = AV_PIX_FMT_YUV422P; break; | |
| 311 | 254 | case 0x11: f->pix_fmt = AV_PIX_FMT_YUV420P; break; | |
| 312 | ✗ | case 0x20: f->pix_fmt = AV_PIX_FMT_YUV411P; break; | |
| 313 | ✗ | case 0x22: f->pix_fmt = AV_PIX_FMT_YUV410P; break; | |
| 314 | } | ||
| 315 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 136 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
136 | } else if (f->avctx->bits_per_raw_sample <= 8 && f->transparency) { |
| 316 | ✗ | switch(16*f->chroma_h_shift + f->chroma_v_shift) { | |
| 317 | ✗ | case 0x00: f->pix_fmt = AV_PIX_FMT_YUVA444P; break; | |
| 318 | ✗ | case 0x10: f->pix_fmt = AV_PIX_FMT_YUVA422P; break; | |
| 319 | ✗ | case 0x11: f->pix_fmt = AV_PIX_FMT_YUVA420P; break; | |
| 320 | } | ||
| 321 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 136 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
136 | } else if (f->avctx->bits_per_raw_sample == 9 && !f->transparency) { |
| 322 | ✗ | f->packed_at_lsb = 1; | |
| 323 | ✗ | switch(16 * f->chroma_h_shift + f->chroma_v_shift) { | |
| 324 | ✗ | case 0x00: f->pix_fmt = AV_PIX_FMT_YUV444P9; break; | |
| 325 | ✗ | case 0x10: f->pix_fmt = AV_PIX_FMT_YUV422P9; break; | |
| 326 | ✗ | case 0x11: f->pix_fmt = AV_PIX_FMT_YUV420P9; break; | |
| 327 | } | ||
| 328 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 136 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
136 | } else if (f->avctx->bits_per_raw_sample == 9 && f->transparency) { |
| 329 | ✗ | f->packed_at_lsb = 1; | |
| 330 | ✗ | switch(16 * f->chroma_h_shift + f->chroma_v_shift) { | |
| 331 | ✗ | case 0x00: f->pix_fmt = AV_PIX_FMT_YUVA444P9; break; | |
| 332 | ✗ | case 0x10: f->pix_fmt = AV_PIX_FMT_YUVA422P9; break; | |
| 333 | ✗ | case 0x11: f->pix_fmt = AV_PIX_FMT_YUVA420P9; break; | |
| 334 | } | ||
| 335 |
3/4✓ Branch 0 taken 92 times.
✓ Branch 1 taken 44 times.
✓ Branch 2 taken 92 times.
✗ Branch 3 not taken.
|
136 | } else if (f->avctx->bits_per_raw_sample == 10 && !f->transparency) { |
| 336 | 92 | f->packed_at_lsb = 1; | |
| 337 |
1/5✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 92 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
92 | switch(16 * f->chroma_h_shift + f->chroma_v_shift) { |
| 338 | ✗ | case 0x00: f->pix_fmt = AV_PIX_FMT_YUV444P10; break; | |
| 339 | ✗ | case 0x01: f->pix_fmt = AV_PIX_FMT_YUV440P10; break; | |
| 340 | 92 | case 0x10: f->pix_fmt = AV_PIX_FMT_YUV422P10; break; | |
| 341 | ✗ | case 0x11: f->pix_fmt = AV_PIX_FMT_YUV420P10; break; | |
| 342 | } | ||
| 343 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
44 | } else if (f->avctx->bits_per_raw_sample == 10 && f->transparency) { |
| 344 | ✗ | f->packed_at_lsb = 1; | |
| 345 | ✗ | switch(16 * f->chroma_h_shift + f->chroma_v_shift) { | |
| 346 | ✗ | case 0x00: f->pix_fmt = AV_PIX_FMT_YUVA444P10; break; | |
| 347 | ✗ | case 0x10: f->pix_fmt = AV_PIX_FMT_YUVA422P10; break; | |
| 348 | ✗ | case 0x11: f->pix_fmt = AV_PIX_FMT_YUVA420P10; break; | |
| 349 | } | ||
| 350 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
44 | } else if (f->avctx->bits_per_raw_sample == 12 && !f->transparency) { |
| 351 | ✗ | f->packed_at_lsb = 1; | |
| 352 | ✗ | switch(16 * f->chroma_h_shift + f->chroma_v_shift) { | |
| 353 | ✗ | case 0x00: f->pix_fmt = AV_PIX_FMT_YUV444P12; break; | |
| 354 | ✗ | case 0x01: f->pix_fmt = AV_PIX_FMT_YUV440P12; break; | |
| 355 | ✗ | case 0x10: f->pix_fmt = AV_PIX_FMT_YUV422P12; break; | |
| 356 | ✗ | case 0x11: f->pix_fmt = AV_PIX_FMT_YUV420P12; break; | |
| 357 | } | ||
| 358 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
44 | } else if (f->avctx->bits_per_raw_sample == 12 && f->transparency) { |
| 359 | ✗ | f->packed_at_lsb = 1; | |
| 360 | ✗ | switch(16 * f->chroma_h_shift + f->chroma_v_shift) { | |
| 361 | ✗ | case 0x00: f->pix_fmt = AV_PIX_FMT_YUVA444P12; break; | |
| 362 | ✗ | case 0x10: f->pix_fmt = AV_PIX_FMT_YUVA422P12; break; | |
| 363 | } | ||
| 364 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
44 | } else if (f->avctx->bits_per_raw_sample == 14 && !f->transparency) { |
| 365 | ✗ | f->packed_at_lsb = 1; | |
| 366 | ✗ | switch(16 * f->chroma_h_shift + f->chroma_v_shift) { | |
| 367 | ✗ | case 0x00: f->pix_fmt = AV_PIX_FMT_YUV444P14; break; | |
| 368 | ✗ | case 0x10: f->pix_fmt = AV_PIX_FMT_YUV422P14; break; | |
| 369 | ✗ | case 0x11: f->pix_fmt = AV_PIX_FMT_YUV420P14; break; | |
| 370 | } | ||
| 371 |
2/4✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 44 times.
✗ Branch 3 not taken.
|
44 | } else if (f->avctx->bits_per_raw_sample == 16 && !f->transparency){ |
| 372 | 44 | f->packed_at_lsb = 1; | |
| 373 |
1/4✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
44 | switch(16 * f->chroma_h_shift + f->chroma_v_shift) { |
| 374 | 44 | case 0x00: f->pix_fmt = AV_PIX_FMT_YUV444P16; break; | |
| 375 | ✗ | case 0x10: f->pix_fmt = AV_PIX_FMT_YUV422P16; break; | |
| 376 | ✗ | case 0x11: f->pix_fmt = AV_PIX_FMT_YUV420P16; break; | |
| 377 | } | ||
| 378 | ✗ | } else if (f->avctx->bits_per_raw_sample == 16 && f->transparency){ | |
| 379 | ✗ | f->packed_at_lsb = 1; | |
| 380 | ✗ | switch(16 * f->chroma_h_shift + f->chroma_v_shift) { | |
| 381 | ✗ | case 0x00: f->pix_fmt = AV_PIX_FMT_YUVA444P16; break; | |
| 382 | ✗ | case 0x10: f->pix_fmt = AV_PIX_FMT_YUVA422P16; break; | |
| 383 | ✗ | case 0x11: f->pix_fmt = AV_PIX_FMT_YUVA420P16; break; | |
| 384 | } | ||
| 385 | } | ||
| 386 |
1/2✓ Branch 0 taken 88 times.
✗ Branch 1 not taken.
|
88 | } else if (f->colorspace == 1) { |
| 387 |
2/4✓ Branch 0 taken 88 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 88 times.
|
88 | if (f->chroma_h_shift || f->chroma_v_shift) { |
| 388 | ✗ | av_log(f->avctx, AV_LOG_ERROR, | |
| 389 | "chroma subsampling not supported in this colorspace\n"); | ||
| 390 | ✗ | return AVERROR(ENOSYS); | |
| 391 | } | ||
| 392 |
3/4✓ Branch 0 taken 44 times.
✓ Branch 1 taken 44 times.
✓ Branch 2 taken 44 times.
✗ Branch 3 not taken.
|
88 | if ( f->avctx->bits_per_raw_sample <= 8 && !f->transparency) |
| 393 | 44 | f->pix_fmt = AV_PIX_FMT_0RGB32; | |
| 394 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
44 | else if (f->avctx->bits_per_raw_sample <= 8 && f->transparency) |
| 395 | ✗ | f->pix_fmt = AV_PIX_FMT_RGB32; | |
| 396 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
44 | else if (f->avctx->bits_per_raw_sample == 9 && !f->transparency) |
| 397 | ✗ | f->pix_fmt = AV_PIX_FMT_GBRP9; | |
| 398 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
44 | else if (f->avctx->bits_per_raw_sample == 10 && !f->transparency) |
| 399 | ✗ | f->pix_fmt = AV_PIX_FMT_GBRP10; | |
| 400 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
44 | else if (f->avctx->bits_per_raw_sample == 10 && f->transparency) |
| 401 | ✗ | f->pix_fmt = AV_PIX_FMT_GBRAP10; | |
| 402 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
44 | else if (f->avctx->bits_per_raw_sample == 12 && !f->transparency) |
| 403 | ✗ | f->pix_fmt = AV_PIX_FMT_GBRP12; | |
| 404 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
44 | else if (f->avctx->bits_per_raw_sample == 12 && f->transparency) |
| 405 | ✗ | f->pix_fmt = AV_PIX_FMT_GBRAP12; | |
| 406 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
44 | else if (f->avctx->bits_per_raw_sample == 14 && !f->transparency) |
| 407 | ✗ | f->pix_fmt = AV_PIX_FMT_GBRP14; | |
| 408 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
44 | else if (f->avctx->bits_per_raw_sample == 14 && f->transparency) |
| 409 | ✗ | f->pix_fmt = AV_PIX_FMT_GBRAP14; | |
| 410 |
2/4✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 44 times.
✗ Branch 3 not taken.
|
44 | else if (f->avctx->bits_per_raw_sample == 16 && !f->transparency) { |
| 411 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
|
44 | if (f->flt) { |
| 412 | ✗ | f->pix_fmt = AV_PIX_FMT_GBRPF16; | |
| 413 | } else | ||
| 414 | 44 | f->pix_fmt = AV_PIX_FMT_GBRP16; | |
| 415 | 44 | f->use32bit = 1; | |
| 416 | ✗ | } else if (f->avctx->bits_per_raw_sample == 16 && f->transparency) { | |
| 417 | ✗ | if (f->flt) { | |
| 418 | ✗ | f->pix_fmt = AV_PIX_FMT_GBRAPF16; | |
| 419 | } else | ||
| 420 | ✗ | f->pix_fmt = AV_PIX_FMT_GBRAP16; | |
| 421 | ✗ | f->use32bit = 1; | |
| 422 | ✗ | } else if (f->avctx->bits_per_raw_sample == 32 && !f->transparency) { | |
| 423 | ✗ | if (f->flt) { | |
| 424 | ✗ | f->pix_fmt = AV_PIX_FMT_GBRPF32; | |
| 425 | } | ||
| 426 | ✗ | f->use32bit = 1; | |
| 427 | ✗ | } else if (f->avctx->bits_per_raw_sample == 32 && f->transparency) { | |
| 428 | ✗ | if (f->flt) { | |
| 429 | ✗ | f->pix_fmt = AV_PIX_FMT_GBRAPF32; | |
| 430 | } | ||
| 431 | ✗ | f->use32bit = 1; | |
| 432 | } | ||
| 433 | } else { | ||
| 434 | ✗ | av_log(f->avctx, AV_LOG_ERROR, "colorspace not supported\n"); | |
| 435 | ✗ | return AVERROR(ENOSYS); | |
| 436 | } | ||
| 437 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 478 times.
|
478 | if (f->pix_fmt == AV_PIX_FMT_NONE) { |
| 438 | ✗ | av_log(f->avctx, AV_LOG_ERROR, "format not supported\n"); | |
| 439 | ✗ | return AVERROR(ENOSYS); | |
| 440 | } | ||
| 441 | |||
| 442 | 478 | return 0; | |
| 443 | } | ||
| 444 |