| 206 | } |
| 207 | |
| 208 | int ff_ffv1_parse_header(FFV1Context *f, RangeCoder *c, uint8_t *state) |
| 209 | { |
| 210 | if (f->version < 2) { |
| 211 | int chroma_planes, chroma_h_shift, chroma_v_shift, transparency, colorspace, bits_per_raw_sample; |
| 212 | unsigned v= ff_ffv1_get_symbol(c, state, 0); |
| 213 | 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 | f->version = v; |
| 218 | f->ac = ff_ffv1_get_symbol(c, state, 0); |
| 219 | |
| 220 | 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 | ff_build_rac_states(&rc, 0.05 * (1LL << 32), 256 - 8); |
| 232 | for (int i = 1; i < 256; i++) |
| 233 | f->state_transition[i] = rc.one_state[i]; |
| 234 | } |
| 235 | |
| 236 | colorspace = ff_ffv1_get_symbol(c, state, 0); //YUV cs type |
| 237 | bits_per_raw_sample = f->version > 0 ? ff_ffv1_get_symbol(c, state, 0) : f->avctx->bits_per_raw_sample; |
| 238 | chroma_planes = get_rac(c, state); |
| 239 | chroma_h_shift = ff_ffv1_get_symbol(c, state, 0); |
| 240 | chroma_v_shift = ff_ffv1_get_symbol(c, state, 0); |
| 241 | transparency = get_rac(c, state); |
| 242 | if (colorspace == 0 && f->avctx->skip_alpha) |
| 243 | transparency = 0; |
| 244 | |
| 245 | if (f->plane_count) { |
| 246 | if (colorspace != f->colorspace || |
| 247 | bits_per_raw_sample != f->avctx->bits_per_raw_sample || |
| 248 | chroma_planes != f->chroma_planes || |
| 249 | chroma_h_shift != f->chroma_h_shift || |
| 250 | chroma_v_shift != f->chroma_v_shift || |
| 251 | 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 | 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 | f->colorspace = colorspace; |
| 264 | f->avctx->bits_per_raw_sample = bits_per_raw_sample; |
| 265 | f->chroma_planes = chroma_planes; |
no test coverage detected