| 453 | } |
| 454 | |
| 455 | static int decode_frame(AVCodecContext *avctx, |
| 456 | void *data, int *data_size, |
| 457 | AVPacket *avpkt) |
| 458 | { |
| 459 | const uint8_t *buf = avpkt->data; |
| 460 | int buf_size = avpkt->size; |
| 461 | TiffContext * const s = avctx->priv_data; |
| 462 | AVFrame *picture = data; |
| 463 | AVFrame * const p= (AVFrame*)&s->picture; |
| 464 | const uint8_t *orig_buf = buf, *end_buf = buf + buf_size; |
| 465 | int id, le, off; |
| 466 | int i, j, entries; |
| 467 | int stride, soff, ssize; |
| 468 | uint8_t *dst; |
| 469 | |
| 470 | //parse image header |
| 471 | id = AV_RL16(buf); buf += 2; |
| 472 | if(id == 0x4949) le = 1; |
| 473 | else if(id == 0x4D4D) le = 0; |
| 474 | else{ |
| 475 | av_log(avctx, AV_LOG_ERROR, "TIFF header not found\n"); |
| 476 | return -1; |
| 477 | } |
| 478 | s->le = le; |
| 479 | s->invert = 0; |
| 480 | s->compr = TIFF_RAW; |
| 481 | s->fill_order = 0; |
| 482 | // As TIFF 6.0 specification puts it "An arbitrary but carefully chosen number |
| 483 | // that further identifies the file as a TIFF file" |
| 484 | if(tget_short(&buf, le) != 42){ |
| 485 | av_log(avctx, AV_LOG_ERROR, "The answer to life, universe and everything is not correct!\n"); |
| 486 | return -1; |
| 487 | } |
| 488 | /* parse image file directory */ |
| 489 | off = tget_long(&buf, le); |
| 490 | if(orig_buf + off + 14 >= end_buf){ |
| 491 | av_log(avctx, AV_LOG_ERROR, "IFD offset is greater than image size\n"); |
| 492 | return -1; |
| 493 | } |
| 494 | buf = orig_buf + off; |
| 495 | entries = tget_short(&buf, le); |
| 496 | for(i = 0; i < entries; i++){ |
| 497 | if(tiff_decode_tag(s, orig_buf, buf, end_buf) < 0) |
| 498 | return -1; |
| 499 | buf += 12; |
| 500 | } |
| 501 | if(!s->stripdata && !s->stripoff){ |
| 502 | av_log(avctx, AV_LOG_ERROR, "Image data is missing\n"); |
| 503 | return -1; |
| 504 | } |
| 505 | /* now we have the data and may start decoding */ |
| 506 | if(!p->data[0]){ |
| 507 | s->bpp = 1; |
| 508 | avctx->pix_fmt = PIX_FMT_MONOBLACK; |
| 509 | if(s->width != s->avctx->width || s->height != s->avctx->height){ |
| 510 | if(avcodec_check_dimensions(s->avctx, s->width, s->height)) |
| 511 | return -1; |
| 512 | avcodec_set_dimensions(s->avctx, s->width, s->height); |
nothing calls this directly
no test coverage detected