| 183 | } |
| 184 | |
| 185 | static int decode_frame_header(ProresContext *ctx, const uint8_t *buf, |
| 186 | const int data_size, AVCodecContext *avctx) |
| 187 | { |
| 188 | int hdr_size, width, height, flags, dimensions_changed = 0; |
| 189 | int version; |
| 190 | const uint8_t *ptr; |
| 191 | enum AVPixelFormat pix_fmt; |
| 192 | int old_frame_type = ctx->frame_type; |
| 193 | |
| 194 | hdr_size = AV_RB16(buf); |
| 195 | ff_dlog(avctx, "header size %d\n", hdr_size); |
| 196 | if (hdr_size > data_size) { |
| 197 | av_log(avctx, AV_LOG_ERROR, "error, wrong header size\n"); |
| 198 | return AVERROR_INVALIDDATA; |
| 199 | } |
| 200 | |
| 201 | version = AV_RB16(buf + 2); |
| 202 | ff_dlog(avctx, "%.4s version %d\n", buf+4, version); |
| 203 | if (version > 1) { |
| 204 | av_log(avctx, AV_LOG_ERROR, "unsupported version: %d\n", version); |
| 205 | return AVERROR_PATCHWELCOME; |
| 206 | } |
| 207 | |
| 208 | width = AV_RB16(buf + 8); |
| 209 | height = AV_RB16(buf + 10); |
| 210 | |
| 211 | if (width != avctx->width || height != avctx->height) { |
| 212 | int ret; |
| 213 | |
| 214 | av_log(avctx, AV_LOG_WARNING, "picture resolution change: %dx%d -> %dx%d\n", |
| 215 | avctx->width, avctx->height, width, height); |
| 216 | if ((ret = ff_set_dimensions(avctx, width, height)) < 0) |
| 217 | return ret; |
| 218 | dimensions_changed = 1; |
| 219 | } |
| 220 | |
| 221 | ctx->frame_type = (buf[12] >> 2) & 3; |
| 222 | ctx->alpha_info = buf[17] & 0xf; |
| 223 | |
| 224 | if (ctx->alpha_info > 2) { |
| 225 | av_log(avctx, AV_LOG_ERROR, "Invalid alpha mode %d\n", ctx->alpha_info); |
| 226 | return AVERROR_INVALIDDATA; |
| 227 | } |
| 228 | if (avctx->skip_alpha) ctx->alpha_info = 0; |
| 229 | |
| 230 | ff_dlog(avctx, "frame type %d\n", ctx->frame_type); |
| 231 | |
| 232 | if (ctx->frame_type == 0) { |
| 233 | ctx->scan = ctx->progressive_scan; // permuted |
| 234 | } else { |
| 235 | ctx->scan = ctx->interlaced_scan; // permuted |
| 236 | ctx->frame->flags |= AV_FRAME_FLAG_INTERLACED; |
| 237 | if (ctx->frame_type == 1) |
| 238 | ctx->frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST; |
| 239 | } |
| 240 | |
| 241 | if (ctx->alpha_info) { |
| 242 | if (avctx->bits_per_raw_sample == 10) { |
no test coverage detected