Browse code

Support 48-bit RGB PPM image.

Originally committed as revision 17511 to svn://svn.ffmpeg.org/ffmpeg/trunk

Peter Ross authored on 2009/02/22 09:56:55
Showing 2 changed files
... ...
@@ -138,8 +138,11 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s){
138 138
                 avctx->pix_fmt = PIX_FMT_GRAY16BE;
139 139
                 if (s->maxval != 65535)
140 140
                     avctx->pix_fmt = PIX_FMT_GRAY16;
141
+            } if (avctx->pix_fmt == PIX_FMT_RGB24) {
142
+                if (s->maxval > 255)
143
+                    avctx->pix_fmt = PIX_FMT_RGB48BE;
141 144
             } else {
142
-                av_log(avctx, AV_LOG_ERROR, "16-bit components are only supported for grayscale\n");
145
+                av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format\n");
143 146
                 avctx->pix_fmt = PIX_FMT_NONE;
144 147
                 return -1;
145 148
             }
... ...
@@ -63,6 +63,9 @@ static int pnm_decode_frame(AVCodecContext *avctx,
63 63
     switch(avctx->pix_fmt) {
64 64
     default:
65 65
         return -1;
66
+    case PIX_FMT_RGB48BE:
67
+        n = avctx->width * 6;
68
+        goto do_read;
66 69
     case PIX_FMT_RGB24:
67 70
         n = avctx->width * 3;
68 71
         goto do_read;
... ...
@@ -195,6 +198,10 @@ static int pnm_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, int bu
195 195
         c = '6';
196 196
         n = avctx->width * 3;
197 197
         break;
198
+    case PIX_FMT_RGB48BE:
199
+        c = '6';
200
+        n = avctx->width * 6;
201
+        break;
198 202
     case PIX_FMT_YUV420P:
199 203
         c = '5';
200 204
         n = avctx->width;
... ...
@@ -209,7 +216,7 @@ static int pnm_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, int bu
209 209
     s->bytestream += strlen(s->bytestream);
210 210
     if (avctx->pix_fmt != PIX_FMT_MONOWHITE) {
211 211
         snprintf(s->bytestream, s->bytestream_end - s->bytestream,
212
-                 "%d\n", (avctx->pix_fmt != PIX_FMT_GRAY16BE) ? 255 : 65535);
212
+                 "%d\n", (avctx->pix_fmt != PIX_FMT_GRAY16BE && avctx->pix_fmt != PIX_FMT_RGB48BE) ? 255 : 65535);
213 213
         s->bytestream += strlen(s->bytestream);
214 214
     }
215 215
 
... ...
@@ -394,7 +401,7 @@ AVCodec ppm_encoder = {
394 394
     pnm_encode_frame,
395 395
     NULL, //encode_end,
396 396
     pnm_decode_frame,
397
-    .pix_fmts= (enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_NONE},
397
+    .pix_fmts= (enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB48BE, PIX_FMT_NONE},
398 398
     .long_name= NULL_IF_CONFIG_SMALL("PPM (Portable PixelMap) image"),
399 399
 };
400 400
 #endif // CONFIG_PPM_ENCODER