From b5f536d24b5ae360503935c34d5d59fa5181b94d Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Fri, 22 Feb 2013 11:57:59 +0100 Subject: pnm: add high-bitdepth PGMYUV support for both encoder and decoder --- libavcodec/pnmdec.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'libavcodec/pnmdec.c') 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]; -- cgit v1.2.3