[FFmpeg-cvslog] r17475 - in trunk: libavcodec/rawdec.c libavformat/avidec.c libavformat/riff.c

michael subversion
Sat Feb 21 16:32:56 CET 2009


Author: michael
Date: Sat Feb 21 16:32:56 2009
New Revision: 17475

Log:
Fix raw rgb/bgr vertical flip in avi based on info from http://www.fourcc.org/fccbihgt.php.
partially fixes issue862.

Modified:
   trunk/libavcodec/rawdec.c
   trunk/libavformat/avidec.c
   trunk/libavformat/riff.c

Modified: trunk/libavcodec/rawdec.c
==============================================================================
--- trunk/libavcodec/rawdec.c	Sat Feb 21 15:40:19 2009	(r17474)
+++ trunk/libavcodec/rawdec.c	Sat Feb 21 16:32:56 2009	(r17475)
@@ -30,6 +30,7 @@
 typedef struct RawVideoContext {
     unsigned char * buffer;  /* block of memory for holding one frame */
     int             length;  /* number of bytes in buffer */
+    int flip;
     AVFrame pic;             ///< AVCodecContext.coded_frame
 } RawVideoContext;
 
@@ -85,14 +86,15 @@ static av_cold int raw_init_decoder(AVCo
     if (!context->buffer)
         return -1;
 
+    if(avctx->extradata_size >= 9 && !memcmp(avctx->extradata + avctx->extradata_size - 9, "BottomUp", 9))
+        context->flip=1;
+
     return 0;
 }
 
 static void flip(AVCodecContext *avctx, AVPicture * picture){
-    if(!avctx->codec_tag && avctx->bits_per_coded_sample && picture->linesize[2]==0){
         picture->data[0] += picture->linesize[0] * (avctx->height-1);
         picture->linesize[0] *= -1;
-    }
 }
 
 static int raw_decode(AVCodecContext *avctx,
@@ -131,6 +133,7 @@ static int raw_decode(AVCodecContext *av
         avctx->palctrl->palette_changed = 0;
     }
 
+    if(context->flip)
     flip(avctx, picture);
 
     if (avctx->codec_tag == MKTAG('Y', 'V', '1', '2'))

Modified: trunk/libavformat/avidec.c
==============================================================================
--- trunk/libavformat/avidec.c	Sat Feb 21 15:40:19 2009	(r17474)
+++ trunk/libavformat/avidec.c	Sat Feb 21 16:32:56 2009	(r17475)
@@ -451,7 +451,7 @@ static int avi_read_header(AVFormatConte
                     }
                     get_le32(pb); /* size */
                     st->codec->width = get_le32(pb);
-                    st->codec->height = get_le32(pb);
+                    st->codec->height = (int32_t)get_le32(pb);
                     get_le16(pb); /* panes */
                     st->codec->bits_per_coded_sample= get_le16(pb); /* depth */
                     tag1 = get_le32(pb);
@@ -499,6 +499,15 @@ static int avi_read_header(AVFormatConte
                     st->codec->codec_tag = tag1;
                     st->codec->codec_id = codec_get_id(codec_bmp_tags, tag1);
                     st->need_parsing = AVSTREAM_PARSE_HEADERS; // This is needed to get the pict type which is necessary for generating correct pts.
+
+                    if(st->codec->codec_tag==0 && st->codec->height > 0 && st->codec->extradata_size < 1U<<30){
+                        st->codec->extradata_size+= 9;
+                        st->codec->extradata= av_realloc(st->codec->extradata, st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+                        if(st->codec->extradata)
+                            memcpy(st->codec->extradata + st->codec->extradata_size - 9, "BottomUp", 9);
+                    }
+                    st->codec->height= FFABS(st->codec->height);
+
 //                    url_fskip(pb, size - 5 * 4);
                     break;
                 case CODEC_TYPE_AUDIO:

Modified: trunk/libavformat/riff.c
==============================================================================
--- trunk/libavformat/riff.c	Sat Feb 21 15:40:19 2009	(r17474)
+++ trunk/libavformat/riff.c	Sat Feb 21 16:32:56 2009	(r17475)
@@ -368,7 +368,8 @@ void put_bmp_header(ByteIOContext *pb, A
 {
     put_le32(pb, 40 + enc->extradata_size); /* size */
     put_le32(pb, enc->width);
-    put_le32(pb, enc->height);
+    //We always store RGB TopDown
+    put_le32(pb, enc->codec_tag ? enc->height : -enc->height);
     put_le16(pb, 1); /* planes */
 
     put_le16(pb, enc->bits_per_coded_sample ? enc->bits_per_coded_sample : 24); /* depth */




More information about the ffmpeg-cvslog mailing list