| 43 | } |
| 44 | |
| 45 | static int pnm_decode_frame(AVCodecContext *avctx, AVFrame *p, |
| 46 | int *got_frame, AVPacket *avpkt) |
| 47 | { |
| 48 | const uint8_t *buf = avpkt->data; |
| 49 | int buf_size = avpkt->size; |
| 50 | PNMContext * const s = avctx->priv_data; |
| 51 | int i, j, k, n, linesize, h, upgrade = 0, is_mono = 0; |
| 52 | unsigned char *ptr; |
| 53 | int components, sample_len, ret; |
| 54 | float scale; |
| 55 | |
| 56 | s->bytestream_start = |
| 57 | s->bytestream = buf; |
| 58 | s->bytestream_end = buf + buf_size; |
| 59 | |
| 60 | if ((ret = ff_pnm_decode_header(avctx, s)) < 0) |
| 61 | return ret; |
| 62 | |
| 63 | if (avctx->skip_frame >= AVDISCARD_ALL) |
| 64 | return avpkt->size; |
| 65 | |
| 66 | if (avctx->width * avctx->height / 8 > s->bytestream_end - s->bytestream) |
| 67 | return AVERROR_INVALIDDATA; |
| 68 | |
| 69 | if ((ret = ff_get_buffer(avctx, p, 0)) < 0) |
| 70 | return ret; |
| 71 | avctx->bits_per_raw_sample = av_log2(s->maxval) + 1; |
| 72 | |
| 73 | switch (avctx->pix_fmt) { |
| 74 | default: |
| 75 | return AVERROR(EINVAL); |
| 76 | case AV_PIX_FMT_RGBA64: |
| 77 | n = avctx->width * 8; |
| 78 | components=4; |
| 79 | sample_len=16; |
| 80 | if (s->maxval < 65535) |
| 81 | upgrade = 2; |
| 82 | goto do_read; |
| 83 | case AV_PIX_FMT_RGB48: |
| 84 | n = avctx->width * 6; |
| 85 | components=3; |
| 86 | sample_len=16; |
| 87 | if (s->maxval < 65535) |
| 88 | upgrade = 2; |
| 89 | goto do_read; |
| 90 | case AV_PIX_FMT_RGBA: |
| 91 | n = avctx->width * 4; |
| 92 | components=4; |
| 93 | sample_len=8; |
| 94 | goto do_read; |
| 95 | case AV_PIX_FMT_RGB24: |
| 96 | n = avctx->width * 3; |
| 97 | components=3; |
| 98 | sample_len=8; |
| 99 | if (s->maxval < 255) |
| 100 | upgrade = 1; |
| 101 | goto do_read; |
| 102 | case AV_PIX_FMT_GRAY8: |
nothing calls this directly
no test coverage detected