| 1521 | } |
| 1522 | |
| 1523 | static int decode_frame(AVCodecContext *avctx, AVFrame *frame, |
| 1524 | int *got_frame, AVPacket *avpkt) |
| 1525 | { |
| 1526 | IffContext *s = avctx->priv_data; |
| 1527 | const uint8_t *buf = avpkt->data; |
| 1528 | int buf_size = avpkt->size; |
| 1529 | const uint8_t *buf_end = buf + buf_size; |
| 1530 | int y, plane, res; |
| 1531 | GetByteContext gb0, *const gb = &gb0; |
| 1532 | const AVPixFmtDescriptor *desc; |
| 1533 | |
| 1534 | bytestream2_init(gb, avpkt->data, avpkt->size); |
| 1535 | |
| 1536 | if ((res = parse_packet_header(avctx, gb)) < 0) |
| 1537 | return res; |
| 1538 | |
| 1539 | if ((res = ff_get_buffer(avctx, frame, 0)) < 0) |
| 1540 | return res; |
| 1541 | |
| 1542 | buf += bytestream2_tell(gb); |
| 1543 | buf_size -= bytestream2_tell(gb); |
| 1544 | desc = av_pix_fmt_desc_get(avctx->pix_fmt); |
| 1545 | |
| 1546 | if (!s->init && avctx->bits_per_coded_sample <= 8 - (s->masking == MASK_HAS_MASK) && |
| 1547 | avctx->pix_fmt == AV_PIX_FMT_PAL8) { |
| 1548 | if ((res = cmap_read_palette(avctx, (uint32_t *)frame->data[1])) < 0) |
| 1549 | return res; |
| 1550 | } else if (!s->init && avctx->bits_per_coded_sample <= 8 && |
| 1551 | avctx->pix_fmt == AV_PIX_FMT_RGB32) { |
| 1552 | if ((res = cmap_read_palette(avctx, s->mask_palbuf)) < 0) |
| 1553 | return res; |
| 1554 | } |
| 1555 | s->init = 1; |
| 1556 | |
| 1557 | if (s->compression <= 0xff && (avctx->codec_tag == MKTAG('A', 'N', 'I', 'M'))) { |
| 1558 | if (avctx->pix_fmt == AV_PIX_FMT_PAL8) |
| 1559 | memcpy(s->pal, frame->data[1], 256 * 4); |
| 1560 | } |
| 1561 | |
| 1562 | switch (s->compression) { |
| 1563 | case 0x0: |
| 1564 | if (avctx->codec_tag == MKTAG('A', 'C', 'B', 'M')) { |
| 1565 | if (avctx->pix_fmt == AV_PIX_FMT_PAL8 || avctx->pix_fmt == AV_PIX_FMT_GRAY8) { |
| 1566 | memset(frame->data[0], 0, avctx->height * frame->linesize[0]); |
| 1567 | for (plane = 0; plane < s->bpp; plane++) { |
| 1568 | for (y = 0; y < avctx->height && buf < buf_end; y++) { |
| 1569 | uint8_t *row = &frame->data[0][y * frame->linesize[0]]; |
| 1570 | decodeplane8(row, buf, FFMIN(s->planesize, buf_end - buf), plane); |
| 1571 | buf += s->planesize; |
| 1572 | } |
| 1573 | } |
| 1574 | } else if (s->ham) { // HAM to AV_PIX_FMT_BGR32 |
| 1575 | memset(frame->data[0], 0, avctx->height * frame->linesize[0]); |
| 1576 | for (y = 0; y < avctx->height; y++) { |
| 1577 | uint8_t *row = &frame->data[0][y * frame->linesize[0]]; |
| 1578 | memset(s->ham_buf, 0, s->planesize * 8); |
| 1579 | for (plane = 0; plane < s->bpp; plane++) { |
| 1580 | const uint8_t * start = buf + (plane * avctx->height + y) * s->planesize; |
nothing calls this directly
no test coverage detected