|
|
|
@ -24,6 +24,17 @@ |
|
|
|
|
#include "put_bits.h" |
|
|
|
|
#include "pnm.h" |
|
|
|
|
|
|
|
|
|
static void samplecpy(void *dst, const void *src, int n, int maxval) |
|
|
|
|
{ |
|
|
|
|
if (maxval <= 255) { |
|
|
|
|
memcpy(dst, src, n); |
|
|
|
|
} else { |
|
|
|
|
int i; |
|
|
|
|
for (i=0; i<n/2; i++) { |
|
|
|
|
((uint16_t *)dst)[i] = av_be2ne16(((uint16_t *)src)[i]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int pnm_decode_frame(AVCodecContext *avctx, void *data, |
|
|
|
|
int *got_frame, AVPacket *avpkt) |
|
|
|
@ -51,12 +62,12 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, |
|
|
|
|
switch (avctx->pix_fmt) { |
|
|
|
|
default: |
|
|
|
|
return AVERROR(EINVAL); |
|
|
|
|
case AV_PIX_FMT_RGBA64BE: |
|
|
|
|
case AV_PIX_FMT_RGBA64: |
|
|
|
|
n = avctx->width * 8; |
|
|
|
|
components=4; |
|
|
|
|
sample_len=16; |
|
|
|
|
goto do_read; |
|
|
|
|
case AV_PIX_FMT_RGB48BE: |
|
|
|
|
case AV_PIX_FMT_RGB48: |
|
|
|
|
n = avctx->width * 6; |
|
|
|
|
components=3; |
|
|
|
|
sample_len=16; |
|
|
|
@ -83,8 +94,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, |
|
|
|
|
components=2; |
|
|
|
|
sample_len=8; |
|
|
|
|
goto do_read; |
|
|
|
|
case AV_PIX_FMT_GRAY16BE: |
|
|
|
|
case AV_PIX_FMT_GRAY16LE: |
|
|
|
|
case AV_PIX_FMT_GRAY16: |
|
|
|
|
n = avctx->width * 2; |
|
|
|
|
components=1; |
|
|
|
|
sample_len=16; |
|
|
|
@ -124,15 +134,19 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, |
|
|
|
|
c = (*s->bytestream++) - '0'; |
|
|
|
|
} while (c <= 9); |
|
|
|
|
} |
|
|
|
|
put_bits(&pb, sample_len, (((1<<sample_len)-1)*v + (s->maxval>>1))/s->maxval); |
|
|
|
|
if (sample_len == 16) { |
|
|
|
|
((uint16_t*)ptr)[j] = (((1<<sample_len)-1)*v + (s->maxval>>1))/s->maxval; |
|
|
|
|
} else |
|
|
|
|
put_bits(&pb, sample_len, (((1<<sample_len)-1)*v + (s->maxval>>1))/s->maxval); |
|
|
|
|
} |
|
|
|
|
flush_put_bits(&pb); |
|
|
|
|
if (sample_len != 16) |
|
|
|
|
flush_put_bits(&pb); |
|
|
|
|
ptr+= linesize; |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
for (i = 0; i < avctx->height; i++) { |
|
|
|
|
if (!upgrade) |
|
|
|
|
memcpy(ptr, s->bytestream, n); |
|
|
|
|
samplecpy(ptr, s->bytestream, n, s->maxval); |
|
|
|
|
else if (upgrade == 1) { |
|
|
|
|
unsigned int j, f = (255 * 128 + s->maxval / 2) / s->maxval; |
|
|
|
|
for (j = 0; j < n; j++) |
|
|
|
@ -150,8 +164,8 @@ 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: |
|
|
|
|
case AV_PIX_FMT_YUV420P9: |
|
|
|
|
case AV_PIX_FMT_YUV420P10: |
|
|
|
|
{ |
|
|
|
|
unsigned char *ptr1, *ptr2; |
|
|
|
|
|
|
|
|
@ -163,7 +177,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, |
|
|
|
|
if (s->bytestream + n * avctx->height * 3 / 2 > s->bytestream_end) |
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
for (i = 0; i < avctx->height; i++) { |
|
|
|
|
memcpy(ptr, s->bytestream, n); |
|
|
|
|
samplecpy(ptr, s->bytestream, n, s->maxval); |
|
|
|
|
s->bytestream += n; |
|
|
|
|
ptr += linesize; |
|
|
|
|
} |
|
|
|
@ -172,9 +186,9 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, |
|
|
|
|
n >>= 1; |
|
|
|
|
h = avctx->height >> 1; |
|
|
|
|
for (i = 0; i < h; i++) { |
|
|
|
|
memcpy(ptr1, s->bytestream, n); |
|
|
|
|
samplecpy(ptr1, s->bytestream, n, s->maxval); |
|
|
|
|
s->bytestream += n; |
|
|
|
|
memcpy(ptr2, s->bytestream, n); |
|
|
|
|
samplecpy(ptr2, s->bytestream, n, s->maxval); |
|
|
|
|
s->bytestream += n; |
|
|
|
|
ptr1 += p->linesize[1]; |
|
|
|
|
ptr2 += p->linesize[2]; |
|
|
|
|