diff options
author | Kostya Shishkov <kostya.shishkov@gmail.com> | 2013-02-22 11:57:59 +0100 |
---|---|---|
committer | Kostya Shishkov <kostya.shishkov@gmail.com> | 2013-02-23 16:49:22 +0100 |
commit | b5f536d24b5ae360503935c34d5d59fa5181b94d (patch) | |
tree | 3f4700246c9c1194ffff6cd779c7aa57d7fc06ef /libavcodec/pnmdec.c | |
parent | 2f325a6fd4421c4dd4e26d7065e5d4bf26ed52f2 (diff) | |
download | ffmpeg-b5f536d24b5ae360503935c34d5d59fa5181b94d.tar.gz |
pnm: add high-bitdepth PGMYUV support for both encoder and decoder
Diffstat (limited to 'libavcodec/pnmdec.c')
-rw-r--r-- | libavcodec/pnmdec.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/libavcodec/pnmdec.c b/libavcodec/pnmdec.c index b9897b9c1a..c9b873d468 100644 --- a/libavcodec/pnmdec.c +++ b/libavcodec/pnmdec.c @@ -135,12 +135,16 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, } break; case AV_PIX_FMT_YUV420P: + case AV_PIX_FMT_YUV420P9BE: + case AV_PIX_FMT_YUV420P10BE: { unsigned char *ptr1, *ptr2; n = avctx->width; ptr = p->data[0]; linesize = p->linesize[0]; + if (s->maxval >= 256) + n *= 2; if (s->bytestream + n * avctx->height * 3 / 2 > s->bytestream_end) return AVERROR_INVALIDDATA; for (i = 0; i < avctx->height; i++) { @@ -162,6 +166,47 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, } } break; + case AV_PIX_FMT_YUV420P16: + { + uint16_t *ptr1, *ptr2; + const int f = (65535 * 32768 + s->maxval / 2) / s->maxval; + unsigned int j, v; + + n = avctx->width * 2; + ptr = p->data[0]; + linesize = p->linesize[0]; + if (s->bytestream + n * avctx->height * 3 / 2 > s->bytestream_end) + return AVERROR_INVALIDDATA; + for (i = 0; i < avctx->height; i++) { + for (j = 0; j < n / 2; j++) { + v = av_be2ne16(((uint16_t *)s->bytestream)[j]); + ((uint16_t *)ptr)[j] = (v * f + 16384) >> 15; + } + s->bytestream += n; + ptr += linesize; + } + ptr1 = (uint16_t*)p->data[1]; + ptr2 = (uint16_t*)p->data[2]; + n >>= 1; + h = avctx->height >> 1; + for (i = 0; i < h; i++) { + for (j = 0; j < n / 2; j++) { + v = av_be2ne16(((uint16_t *)s->bytestream)[j]); + ptr1[j] = (v * f + 16384) >> 15; + } + s->bytestream += n; + + for (j = 0; j < n / 2; j++) { + v = av_be2ne16(((uint16_t *)s->bytestream)[j]); + ptr2[j] = (v * f + 16384) >> 15; + } + s->bytestream += n; + + ptr1 += p->linesize[1] / 2; + ptr2 += p->linesize[2] / 2; + } + } + break; case AV_PIX_FMT_RGB32: ptr = p->data[0]; linesize = p->linesize[0]; |