summaryrefslogtreecommitdiff
path: root/libavcodec/pnm.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavcodec/pnm.c')
-rw-r--r--libavcodec/pnm.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/libavcodec/pnm.c b/libavcodec/pnm.c
index 6d72f234c1..bfb4a25b7c 100644
--- a/libavcodec/pnm.c
+++ b/libavcodec/pnm.c
@@ -2,20 +2,20 @@
* PNM image format
* Copyright (c) 2002, 2003 Fabrice Bellard
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -109,21 +109,30 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s)
avctx->width = w;
avctx->height = h;
+ s->maxval = maxval;
if (depth == 1) {
- if (maxval == 1)
- avctx->pix_fmt = PIX_FMT_MONOWHITE;
- else
+ if (maxval == 1) {
+ avctx->pix_fmt = PIX_FMT_MONOBLACK;
+ } else if (maxval == 255) {
avctx->pix_fmt = PIX_FMT_GRAY8;
+ } else {
+ avctx->pix_fmt = PIX_FMT_GRAY16BE;
+ }
+ } else if (depth == 2) {
+ if (maxval == 255)
+ avctx->pix_fmt = PIX_FMT_GRAY8A;
} else if (depth == 3) {
if (maxval < 256) {
avctx->pix_fmt = PIX_FMT_RGB24;
} else {
- av_log(avctx, AV_LOG_ERROR, "16-bit components are only supported for grayscale\n");
- avctx->pix_fmt = PIX_FMT_NONE;
- return -1;
+ avctx->pix_fmt = PIX_FMT_RGB48BE;
}
} else if (depth == 4) {
- avctx->pix_fmt = PIX_FMT_RGB32;
+ if (maxval < 256) {
+ avctx->pix_fmt = PIX_FMT_RGBA;
+ } else {
+ avctx->pix_fmt = PIX_FMT_RGBA64BE;
+ }
} else {
return -1;
}
@@ -137,9 +146,9 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s)
return -1;
pnm_get(s, buf1, sizeof(buf1));
avctx->height = atoi(buf1);
- if(av_image_check_size(avctx->width, avctx->height, 0, avctx))
+ if(avctx->height <= 0 || av_image_check_size(avctx->width, avctx->height, 0, avctx))
return -1;
- if (avctx->pix_fmt != PIX_FMT_MONOWHITE) {
+ if (avctx->pix_fmt != PIX_FMT_MONOWHITE && avctx->pix_fmt != PIX_FMT_MONOBLACK) {
pnm_get(s, buf1, sizeof(buf1));
s->maxval = atoi(buf1);
if (s->maxval <= 0) {