/*
* PNM image format
- * Copyright (c) 2002, 2003 Fabrice Bellard.
+ * Copyright (c) 2002, 2003 Fabrice Bellard
*
* This file is part of FFmpeg.
*
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+
#include "avcodec.h"
#include "pnm.h"
int c;
/* skip spaces and comments */
- for(;;) {
+ for (;;) {
c = *sc->bytestream++;
if (c == '#') {
- do {
+ do {
c = *sc->bytestream++;
} while (c != '\n' && sc->bytestream < sc->bytestream_end);
} else if (!pnm_space(c)) {
*s = '\0';
}
-int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s){
+int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s)
+{
char buf1[32], tuple_type[32];
int h, w, depth, maxval;
} else if (!strcmp(buf1, "P6")) {
avctx->pix_fmt = PIX_FMT_RGB24;
} else if (!strcmp(buf1, "P7")) {
- w = -1;
- h = -1;
+ w = -1;
+ h = -1;
maxval = -1;
- depth = -1;
+ depth = -1;
tuple_type[0] = '\0';
- for(;;) {
+ for (;;) {
pnm_get(s, buf1, sizeof(buf1));
if (!strcmp(buf1, "WIDTH")) {
pnm_get(s, buf1, sizeof(buf1));
if (w <= 0 || h <= 0 || maxval <= 0 || depth <= 0 || tuple_type[0] == '\0' || avcodec_check_dimensions(avctx, w, h))
return -1;
- avctx->width = w;
+ avctx->width = w;
avctx->height = h;
if (depth == 1) {
if (maxval == 1)
avctx->pix_fmt = PIX_FMT_GRAY16BE;
if (s->maxval != 65535)
avctx->pix_fmt = PIX_FMT_GRAY16;
+ } else if (avctx->pix_fmt == PIX_FMT_RGB24) {
+ if (s->maxval > 255)
+ avctx->pix_fmt = PIX_FMT_RGB48BE;
} else {
- av_log(avctx, AV_LOG_ERROR, "16-bit components are only supported for grayscale\n");
+ av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format\n");
avctx->pix_fmt = PIX_FMT_NONE;
return -1;
}