]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/rawdec.c
avcodec/dca: clear X96 channels if nothing was decoded
[ffmpeg] / libavcodec / rawdec.c
index b7ce2b67d55fae2dba0dba87abcd390fdb73aa1f..765e567d1fac841f017f0f73f245ecd448489fe2 100644 (file)
@@ -100,7 +100,7 @@ static av_cold int raw_init_decoder(AVCodecContext *avctx)
             avpriv_set_systematic_pal2((uint32_t*)context->palette->data, avctx->pix_fmt);
         else {
             memset(context->palette->data, 0, AVPALETTE_SIZE);
-            if (avctx->bits_per_coded_sample <= 1)
+            if (avctx->bits_per_coded_sample == 1)
                 memset(context->palette->data, 0xff, 4);
         }
     }
@@ -121,17 +121,13 @@ static av_cold int raw_init_decoder(AVCodecContext *avctx)
     if (avctx->codec_tag == MKTAG('B','1','W','0') ||
         avctx->codec_tag == MKTAG('B','0','W','1'))
         context->is_nut_mono = 1;
-    else if (avctx->codec_tag == MKTAG('P','A','L','8'))
+    else if (avctx->codec_tag == MKTAG('P','A','L',8))
         context->is_nut_pal8 = 1;
 
     if (avctx->codec_tag == AV_RL32("yuv2") &&
         avctx->pix_fmt   == AV_PIX_FMT_YUYV422)
         context->is_yuv2 = 1;
 
-    /* Temporary solution until PAL8 is implemented in nut */
-    if (context->is_pal8 && avctx->bits_per_coded_sample == 1)
-        avctx->pix_fmt = AV_PIX_FMT_NONE;
-
     return 0;
 }
 
@@ -199,26 +195,13 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame,
     else
         stride = avpkt->size / avctx->height;
 
+    av_log(avctx, AV_LOG_DEBUG, "PACKET SIZE: %d, STRIDE: %d\n", avpkt->size, stride);
+
     if (stride == 0 || avpkt->size < stride * avctx->height) {
         av_log(avctx, AV_LOG_ERROR, "Packet too small (%d)\n", avpkt->size);
         return AVERROR_INVALIDDATA;
     }
 
-    /* Temporary solution until PAL8 is implemented in nut */
-    if (avctx->pix_fmt == AV_PIX_FMT_NONE &&
-        avctx->bits_per_coded_sample == 1 &&
-        avctx->frame_number == 0 &&
-        context->palette &&
-        AV_RB64(context->palette->data) == 0xFFFFFFFF00000000
-    ) {
-        const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
-        if (!pal) {
-            avctx->pix_fmt = AV_PIX_FMT_MONOWHITE;
-            context->is_pal8 = 0;
-            context->is_mono = 1;
-        } else
-            avctx->pix_fmt = AV_PIX_FMT_PAL8;
-    }
     desc = av_pix_fmt_desc_get(avctx->pix_fmt);
 
     if ((avctx->bits_per_coded_sample == 8 || avctx->bits_per_coded_sample == 4
@@ -382,7 +365,6 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame,
     if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
         const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE,
                                                      NULL);
-
         if (pal) {
             av_buffer_unref(&context->palette);
             context->palette = av_buffer_alloc(AVPALETTE_SIZE);
@@ -392,14 +374,22 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame,
             }
             memcpy(context->palette->data, pal, AVPALETTE_SIZE);
             frame->palette_has_changed = 1;
+        } else if (context->is_nut_pal8) {
+            int vid_size = avctx->width * avctx->height;
+            if (avpkt->size - vid_size) {
+                pal = avpkt->data + vid_size;
+                memcpy(context->palette->data, pal, avpkt->size - vid_size);
+                frame->palette_has_changed = 1;
+            }
         }
     }
 
-    if ((avctx->pix_fmt==AV_PIX_FMT_BGR24    ||
-        avctx->pix_fmt==AV_PIX_FMT_GRAY8    ||
-        avctx->pix_fmt==AV_PIX_FMT_RGB555LE ||
-        avctx->pix_fmt==AV_PIX_FMT_RGB555BE ||
-        avctx->pix_fmt==AV_PIX_FMT_RGB565LE ||
+    if ((avctx->pix_fmt==AV_PIX_FMT_RGB24    ||
+        avctx->pix_fmt==AV_PIX_FMT_BGR24     ||
+        avctx->pix_fmt==AV_PIX_FMT_GRAY8     ||
+        avctx->pix_fmt==AV_PIX_FMT_RGB555LE  ||
+        avctx->pix_fmt==AV_PIX_FMT_RGB555BE  ||
+        avctx->pix_fmt==AV_PIX_FMT_RGB565LE  ||
         avctx->pix_fmt==AV_PIX_FMT_MONOWHITE ||
         avctx->pix_fmt==AV_PIX_FMT_MONOBLACK ||
         avctx->pix_fmt==AV_PIX_FMT_PAL8) &&