mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
pnmdec: always output native pixel format
This simplifies the code Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
parent
b7ed18b9bd
commit
62738157dd
@ -118,10 +118,8 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s)
|
||||
avctx->pix_fmt = AV_PIX_FMT_MONOBLACK;
|
||||
} else if (maxval < 256) {
|
||||
avctx->pix_fmt = AV_PIX_FMT_GRAY8;
|
||||
} else if (maxval < 65535) {
|
||||
avctx->pix_fmt = AV_PIX_FMT_GRAY16;
|
||||
} else {
|
||||
avctx->pix_fmt = AV_PIX_FMT_GRAY16BE;
|
||||
avctx->pix_fmt = AV_PIX_FMT_GRAY16;
|
||||
}
|
||||
} else if (depth == 2) {
|
||||
if (maxval == 255)
|
||||
@ -130,13 +128,13 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s)
|
||||
if (maxval < 256) {
|
||||
avctx->pix_fmt = AV_PIX_FMT_RGB24;
|
||||
} else {
|
||||
avctx->pix_fmt = AV_PIX_FMT_RGB48BE;
|
||||
avctx->pix_fmt = AV_PIX_FMT_RGB48;
|
||||
}
|
||||
} else if (depth == 4) {
|
||||
if (maxval < 256) {
|
||||
avctx->pix_fmt = AV_PIX_FMT_RGBA;
|
||||
} else {
|
||||
avctx->pix_fmt = AV_PIX_FMT_RGBA64BE;
|
||||
avctx->pix_fmt = AV_PIX_FMT_RGBA64;
|
||||
}
|
||||
} else {
|
||||
return AVERROR_INVALIDDATA;
|
||||
@ -164,16 +162,14 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s)
|
||||
}
|
||||
if (s->maxval >= 256) {
|
||||
if (avctx->pix_fmt == AV_PIX_FMT_GRAY8) {
|
||||
avctx->pix_fmt = AV_PIX_FMT_GRAY16BE;
|
||||
if (s->maxval != 65535)
|
||||
avctx->pix_fmt = AV_PIX_FMT_GRAY16;
|
||||
} else if (avctx->pix_fmt == AV_PIX_FMT_RGB24) {
|
||||
avctx->pix_fmt = AV_PIX_FMT_RGB48BE;
|
||||
avctx->pix_fmt = AV_PIX_FMT_RGB48;
|
||||
} else if (avctx->pix_fmt == AV_PIX_FMT_YUV420P && s->maxval < 65536) {
|
||||
if (s->maxval < 512)
|
||||
avctx->pix_fmt = AV_PIX_FMT_YUV420P9BE;
|
||||
avctx->pix_fmt = AV_PIX_FMT_YUV420P9;
|
||||
else if (s->maxval < 1024)
|
||||
avctx->pix_fmt = AV_PIX_FMT_YUV420P10BE;
|
||||
avctx->pix_fmt = AV_PIX_FMT_YUV420P10;
|
||||
else
|
||||
avctx->pix_fmt = AV_PIX_FMT_YUV420P16;
|
||||
} else {
|
||||
|
@ -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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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];
|
||||
|
@ -235,8 +235,8 @@ if [ -n "$do_pam" ] ; then
|
||||
do_image_formats pam
|
||||
do_image_formats pam "-pix_fmt rgba"
|
||||
do_image_formats pam "-pix_fmt gray"
|
||||
do_image_formats pam "-pix_fmt gray16be"
|
||||
do_image_formats pam "-pix_fmt rgb48be"
|
||||
do_image_formats pam "-pix_fmt gray16be" "-pix_fmt gray16be"
|
||||
do_image_formats pam "-pix_fmt rgb48be" "-pix_fmt rgb48be"
|
||||
do_image_formats pam "-pix_fmt monob"
|
||||
fi
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user