]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/pnm.c
whitespace cosmetics: K&R coding style, prettyprinting
[ffmpeg] / libavcodec / pnm.c
index a3b4919261e9d2dfe2c090a06745b563f61d00fe..a081f34fa831bc8f92e8e99923205ae441f182d3 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * PNM image format
- * Copyright (c) 2002, 2003 Fabrice Bellard.
+ * Copyright (c) 2002, 2003 Fabrice Bellard
  *
  * This file is part of FFmpeg.
  *
@@ -18,6 +18,7 @@
  * 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"
 
@@ -32,10 +33,10 @@ static void pnm_get(PNMContext *sc, char *str, int buf_size)
     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)) {
@@ -52,7 +53,8 @@ static void pnm_get(PNMContext *sc, char *str, int buf_size)
     *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;
 
@@ -67,12 +69,12 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s){
     } 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));
@@ -98,7 +100,7 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s){
         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)
@@ -138,8 +140,11 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s){
                 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;
             }