]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/bfi.c
Merge remote-tracking branch 'qatar/master'
[ffmpeg] / libavcodec / bfi.c
index 8355850183f6ffd5b456d197978eee9b292159a1..f7df68e527c7aad4dcab4bae26b771acc7b1f352 100644 (file)
@@ -2,20 +2,20 @@
  * Brute Force & Ignorance (BFI) video decoder
  * Copyright (c) 2008 Sisir Koppaka
  *
- * 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
  */
 
@@ -34,12 +34,14 @@ typedef struct BFIContext {
     AVCodecContext *avctx;
     AVFrame frame;
     uint8_t *dst;
+    uint32_t pal[256];
 } BFIContext;
 
 static av_cold int bfi_decode_init(AVCodecContext *avctx)
 {
     BFIContext *bfi = avctx->priv_data;
-    avctx->pix_fmt  = PIX_FMT_PAL8;
+    avctx->pix_fmt  = AV_PIX_FMT_PAL8;
+    avcodec_get_frame_defaults(&bfi->frame);
     bfi->dst        = av_mallocz(avctx->width * avctx->height);
     return 0;
 }
@@ -59,7 +61,7 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data,
     if (bfi->frame.data[0])
         avctx->release_buffer(avctx, &bfi->frame);
 
-    bfi->frame.reference = 1;
+    bfi->frame.reference = 3;
 
     if (avctx->get_buffer(avctx, &bfi->frame) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
@@ -80,16 +82,19 @@ static int bfi_decode_frame(AVCodecContext *avctx, void *data,
         pal = (uint32_t *)bfi->frame.data[1];
         for (i = 0; i < avctx->extradata_size / 3; i++) {
             int shift = 16;
-            *pal = 0;
+            *pal = 0xFFU << 24;
             for (j = 0; j < 3; j++, shift -= 8)
                 *pal += ((avctx->extradata[i * 3 + j] << 2) |
                          (avctx->extradata[i * 3 + j] >> 4)) << shift;
             pal++;
         }
+        memcpy(bfi->pal, bfi->frame.data[1], sizeof(bfi->pal));
         bfi->frame.palette_has_changed = 1;
     } else {
         bfi->frame.pict_type = AV_PICTURE_TYPE_P;
         bfi->frame.key_frame = 0;
+        bfi->frame.palette_has_changed = 0;
+        memcpy(bfi->frame.data[1], bfi->pal, sizeof(bfi->pal));
     }
 
     bytestream2_skip(&g, 4); // Unpacked size, not required.