aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/pnm.c
diff options
context:
space:
mode:
authorKostya Shishkov <kostya.shishkov@gmail.com>2006-10-24 05:00:14 +0000
committerKostya Shishkov <kostya.shishkov@gmail.com>2006-10-24 05:00:14 +0000
commit22eafdf24f65697cc2ae12dfc54fead2318fdacd (patch)
treeed33c70db89cc72ab67a37091cabc7c225951469 /libavcodec/pnm.c
parentae912c5b622df55a229502e8b2742a0625373f21 (diff)
downloadffmpeg-22eafdf24f65697cc2ae12dfc54fead2318fdacd.tar.gz
PGM 16-bit gray support
Originally committed as revision 6780 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/pnm.c')
-rw-r--r--libavcodec/pnm.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/libavcodec/pnm.c b/libavcodec/pnm.c
index b729c4c529..c4c4e2954d 100644
--- a/libavcodec/pnm.c
+++ b/libavcodec/pnm.c
@@ -70,7 +70,7 @@ static int common_init(AVCodecContext *avctx){
static int pnm_decode_header(AVCodecContext *avctx, PNMContext * const s){
char buf1[32], tuple_type[32];
- int h, w, depth, maxval;;
+ int h, w, depth, maxval;
pnm_get(s, buf1, sizeof(buf1));
if (!strcmp(buf1, "P4")) {
@@ -142,8 +142,9 @@ static int pnm_decode_header(AVCodecContext *avctx, PNMContext * const s){
return -1;
if (avctx->pix_fmt != PIX_FMT_MONOWHITE) {
pnm_get(s, buf1, sizeof(buf1));
+ if(atoi(buf1) == 65535 && avctx->pix_fmt == PIX_FMT_GRAY8)
+ avctx->pix_fmt = PIX_FMT_GRAY16BE;
}
-
/* more check if YUV420 */
if (avctx->pix_fmt == PIX_FMT_YUV420P) {
if ((avctx->width & 1) != 0)
@@ -194,6 +195,9 @@ static int pnm_decode_frame(AVCodecContext *avctx,
case PIX_FMT_GRAY8:
n = avctx->width;
goto do_read;
+ case PIX_FMT_GRAY16BE:
+ n = avctx->width * 2;
+ goto do_read;
case PIX_FMT_MONOWHITE:
case PIX_FMT_MONOBLACK:
n = (avctx->width + 7) >> 3;
@@ -292,6 +296,10 @@ static int pnm_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, int bu
c = '5';
n = avctx->width;
break;
+ case PIX_FMT_GRAY16BE:
+ c = '5';
+ n = avctx->width * 2;
+ break;
case PIX_FMT_RGB24:
c = '6';
n = avctx->width * 3;
@@ -310,7 +318,7 @@ static int pnm_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, int bu
s->bytestream += strlen(s->bytestream);
if (avctx->pix_fmt != PIX_FMT_MONOWHITE) {
snprintf(s->bytestream, s->bytestream_end - s->bytestream,
- "%d\n", 255);
+ "%d\n", (avctx->pix_fmt != PIX_FMT_GRAY16BE) ? 255 : 65535);
s->bytestream += strlen(s->bytestream);
}
@@ -537,7 +545,7 @@ AVCodec pgm_encoder = {
pnm_encode_frame,
NULL, //encode_end,
pnm_decode_frame,
- .pix_fmts= (enum PixelFormat[]){PIX_FMT_GRAY8, -1},
+ .pix_fmts= (enum PixelFormat[]){PIX_FMT_GRAY8, PIX_FMT_GRAY16BE, -1},
};
#endif // CONFIG_PGM_ENCODER