Minor fix.

Mats

--
Mats Peterson
http://matsp888.no-ip.org/~mats/
>From c8e99942495c797067be55fb115a21955e11b76b Mon Sep 17 00:00:00 2001
From: Mats Peterson <matsp...@yahoo.com>
Date: Sun, 31 Jan 2016 14:08:19 +0100
Subject: [PATCH v2] lavc/rawdec: Only use AV_PIX_FMT_PAL8 for 1 bpp video

Minor fix.

---
 libavcodec/rawdec.c               |   43 ++++++++-----------------------------
 tests/ref/vsynth/vsynth1-bpp1     |    4 ++--
 tests/ref/vsynth/vsynth2-bpp1     |    4 ++--
 tests/ref/vsynth/vsynth3-bpp1     |    4 ++--
 tests/ref/vsynth/vsynth_lena-bpp1 |    4 ++--
 5 files changed, 17 insertions(+), 42 deletions(-)

diff --git a/libavcodec/rawdec.c b/libavcodec/rawdec.c
index 93cbedf..a60e9bf 100644
--- a/libavcodec/rawdec.c
+++ b/libavcodec/rawdec.c
@@ -112,9 +112,6 @@ static av_cold int raw_init_decoder(AVCodecContext *avctx)
         avctx->pix_fmt   == AV_PIX_FMT_YUYV422)
         context->is_yuv2 = 1;
 
-    if (avctx->pix_fmt == AV_PIX_FMT_PAL8 && avctx->bits_per_coded_sample == 1)
-        avctx->pix_fmt = AV_PIX_FMT_NONE;
-
     return 0;
 }
 
@@ -155,7 +152,7 @@ MKSCALE16(scale16le, AV_RL16, AV_WL16)
 static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame,
                       AVPacket *avpkt)
 {
-    const AVPixFmtDescriptor *desc;
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
     RawVideoContext *context       = avctx->priv_data;
     const uint8_t *buf             = avpkt->data;
     int buf_size                   = avpkt->size;
@@ -176,35 +173,15 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame,
         av_log(avctx, AV_LOG_ERROR, "Packet too small (%d) height (%d)\n", avpkt->size, avctx->height);
         return AVERROR_INVALIDDATA;
     }
-    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;
-        } 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
             || avctx->bits_per_coded_sample == 2 || avctx->bits_per_coded_sample == 1) &&
-        (avctx->pix_fmt == AV_PIX_FMT_PAL8 || avctx->pix_fmt == AV_PIX_FMT_MONOWHITE) &&
+        avctx->pix_fmt == AV_PIX_FMT_PAL8 &&
         (!avctx->codec_tag || avctx->codec_tag == MKTAG('r','a','w',' '))) {
         context->is_1_2_4_8_bpp = 1;
-        if (avctx->bits_per_coded_sample == 1 && avctx->pix_fmt == AV_PIX_FMT_MONOWHITE) {
-            int row_bytes = avctx->width / 8 + (avctx->width & 7 ? 1 : 0);
-            context->frame_size = av_image_get_buffer_size(avctx->pix_fmt,
-                                                           FFALIGN(row_bytes, 16) * 8,
-                                                           avctx->height, 1);
-        } else
-            context->frame_size = av_image_get_buffer_size(avctx->pix_fmt,
-                                                           FFALIGN(avctx->width, 16),
-                                                           avctx->height, 1);
+        context->frame_size = av_image_get_buffer_size(avctx->pix_fmt,
+                                                       FFALIGN(avctx->width, 16),
+                                                       avctx->height, 1);
     } else {
         context->is_lt_16bpp = av_get_bits_per_pixel(desc) == 16 && avctx->bits_per_coded_sample && avctx->bits_per_coded_sample < 16;
         context->frame_size = av_image_get_buffer_size(avctx->pix_fmt, avctx->width,
@@ -244,14 +221,12 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame,
     if (context->is_1_2_4_8_bpp) {
         int i, j, row_pix = 0;
         uint8_t *dst = frame->buf[0]->data;
-        buf_size = context->frame_size -
-                (avctx->pix_fmt == AV_PIX_FMT_PAL8 ? AVPALETTE_SIZE : 0);
-        if (avctx->bits_per_coded_sample == 8 || avctx->pix_fmt == AV_PIX_FMT_MONOWHITE) {
-            int pix_per_byte = avctx->pix_fmt == AV_PIX_FMT_MONOWHITE ? 8 : 1;
+        buf_size = context->frame_size - AVPALETTE_SIZE;
+        if (avctx->bits_per_coded_sample == 8) {
             for (i = 0, j = 0; j < buf_size && i<avpkt->size; i++, j++) {
                 dst[j] = buf[i];
-                row_pix += pix_per_byte;
-                if (row_pix >= avctx->width) {
+                row_pix++;
+                if (row_pix == avctx->width) {
                     i += avpkt_stride - (i % avpkt_stride) - 1;
                     j += 16 - (j % 16) - 1;
                     row_pix = 0;
diff --git a/tests/ref/vsynth/vsynth1-bpp1 b/tests/ref/vsynth/vsynth1-bpp1
index 32dab11..378f990 100644
--- a/tests/ref/vsynth/vsynth1-bpp1
+++ b/tests/ref/vsynth/vsynth1-bpp1
@@ -1,4 +1,4 @@
 3e5e0f4afb3a0350440e86b1ea56cec9 *tests/data/fate/vsynth1-bpp1.avi
 640452 tests/data/fate/vsynth1-bpp1.avi
-ccef5f5d5b0392f1d01c200499dac657 *tests/data/fate/vsynth1-bpp1.out.rawvideo
-stddev:   97.30 PSNR:  8.37 MAXDIFF:  237 bytes:  7603200/  7603200
+853694f3c1aa3ef3807ab1fccbeefe7b *tests/data/fate/vsynth1-bpp1.out.rawvideo
+stddev:   84.44 PSNR:  9.60 MAXDIFF:  221 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-bpp1 b/tests/ref/vsynth/vsynth2-bpp1
index d010bbd..ae8fd27 100644
--- a/tests/ref/vsynth/vsynth2-bpp1
+++ b/tests/ref/vsynth/vsynth2-bpp1
@@ -1,4 +1,4 @@
 771437c9038b44f4e2d4ff764c1c3821 *tests/data/fate/vsynth2-bpp1.avi
 640452 tests/data/fate/vsynth2-bpp1.avi
-ba70b5aebc786e625af6bd7f7ec82717 *tests/data/fate/vsynth2-bpp1.out.rawvideo
-stddev:   81.63 PSNR:  9.89 MAXDIFF:  237 bytes:  7603200/  7603200
+94261fc8aa20130cbd4361e15b742ef7 *tests/data/fate/vsynth2-bpp1.out.rawvideo
+stddev:   70.29 PSNR: 11.19 MAXDIFF:  221 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth3-bpp1 b/tests/ref/vsynth/vsynth3-bpp1
index f84808a..6f71248 100644
--- a/tests/ref/vsynth/vsynth3-bpp1
+++ b/tests/ref/vsynth/vsynth3-bpp1
@@ -1,4 +1,4 @@
 a5e6d1eff2f6fc3bba31e3bb8753b905 *tests/data/fate/vsynth3-bpp1.avi
 15352 tests/data/fate/vsynth3-bpp1.avi
-75e8ee0c0b0ada4515455d9f29377a16 *tests/data/fate/vsynth3-bpp1.out.rawvideo
-stddev:   97.70 PSNR:  8.33 MAXDIFF:  248 bytes:    86700/    86700
+79076b5fc43ee2a2284c0cde991d21f3 *tests/data/fate/vsynth3-bpp1.out.rawvideo
+stddev:   84.88 PSNR:  9.55 MAXDIFF:  232 bytes:    86700/    86700
diff --git a/tests/ref/vsynth/vsynth_lena-bpp1 b/tests/ref/vsynth/vsynth_lena-bpp1
index d4570c7..3e250a8 100644
--- a/tests/ref/vsynth/vsynth_lena-bpp1
+++ b/tests/ref/vsynth/vsynth_lena-bpp1
@@ -1,4 +1,4 @@
 d53d08c755ffde5fca744f0f941bfcb1 *tests/data/fate/vsynth_lena-bpp1.avi
 640452 tests/data/fate/vsynth_lena-bpp1.avi
-9a66df9009670b0a593d889975246c00 *tests/data/fate/vsynth_lena-bpp1.out.rawvideo
-stddev:   96.36 PSNR:  8.45 MAXDIFF:  233 bytes:  7603200/  7603200
+dce624117fcd2b16f38e0a0a62b13fa7 *tests/data/fate/vsynth_lena-bpp1.out.rawvideo
+stddev:   83.18 PSNR:  9.73 MAXDIFF:  217 bytes:  7603200/  7603200
-- 
1.7.10.4

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to