Browse code

huffyuvenc: write last odd sample

If width is odd, last sample wouldn't be written.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Christophe Gisquet authored on 2014/08/26 05:24:29
Showing 3 changed files
... ...
@@ -488,15 +488,31 @@ static int encode_422_bitstream(HYuvContext *s, int offset, int count)
488 488
     return 0;
489 489
 }
490 490
 
491
-static int encode_plane_bitstream(HYuvContext *s, int count, int plane)
491
+static int encode_plane_bitstream(HYuvContext *s, int width, int plane)
492 492
 {
493
-    int i;
493
+    int i, count = width/2;
494 494
 
495 495
     if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) < count * s->bps / 2) {
496 496
         av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
497 497
         return -1;
498 498
     }
499 499
 
500
+#define LOADEND\
501
+            int y0 = s->temp[0][width-1];
502
+#define LOADEND_14\
503
+            int y0 = s->temp16[0][width-1] & mask;
504
+#define LOADEND_16\
505
+            int y0 = s->temp16[0][width-1];
506
+#define STATEND\
507
+            s->stats[plane][y0]++;
508
+#define STATEND_16\
509
+            s->stats[plane][y0>>2]++;
510
+#define WRITEEND\
511
+            put_bits(&s->pb, s->len[plane][y0], s->bits[plane][y0]);
512
+#define WRITEEND_16\
513
+            put_bits(&s->pb, s->len[plane][y0>>2], s->bits[plane][y0>>2]);\
514
+            put_bits(&s->pb, 2, y0&3);
515
+
500 516
 #define LOAD2\
501 517
             int y0 = s->temp[0][2 * i];\
502 518
             int y1 = s->temp[0][2 * i + 1];
... ...
@@ -521,14 +537,16 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane)
521 521
             put_bits(&s->pb, s->len[plane][y1>>2], s->bits[plane][y1>>2]);\
522 522
             put_bits(&s->pb, 2, y1&3);
523 523
 
524
-    count /= 2;
525
-
526 524
     if (s->bps <= 8) {
527 525
     if (s->flags & CODEC_FLAG_PASS1) {
528 526
         for (i = 0; i < count; i++) {
529 527
             LOAD2;
530 528
             STAT2;
531 529
         }
530
+        if (width&1) {
531
+            LOADEND;
532
+            STATEND;
533
+        }
532 534
     }
533 535
     if (s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT)
534 536
         return 0;
... ...
@@ -539,11 +557,20 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane)
539 539
             STAT2;
540 540
             WRITE2;
541 541
         }
542
+        if (width&1) {
543
+            LOADEND;
544
+            STATEND;
545
+            WRITEEND;
546
+        }
542 547
     } else {
543 548
         for (i = 0; i < count; i++) {
544 549
             LOAD2;
545 550
             WRITE2;
546 551
         }
552
+        if (width&1) {
553
+            LOADEND;
554
+            WRITEEND;
555
+        }
547 556
     }
548 557
     } else if (s->bps <= 14) {
549 558
         int mask = s->n - 1;
... ...
@@ -552,6 +579,10 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane)
552 552
                 LOAD2_14;
553 553
                 STAT2;
554 554
             }
555
+            if (width&1) {
556
+                LOADEND_14;
557
+                STATEND;
558
+            }
555 559
         }
556 560
         if (s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT)
557 561
             return 0;
... ...
@@ -562,11 +593,20 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane)
562 562
                 STAT2;
563 563
                 WRITE2;
564 564
             }
565
+            if (width&1) {
566
+                LOADEND_14;
567
+                STATEND;
568
+                WRITEEND;
569
+            }
565 570
         } else {
566 571
             for (i = 0; i < count; i++) {
567 572
                 LOAD2_14;
568 573
                 WRITE2;
569 574
             }
575
+            if (width&1) {
576
+                LOADEND_14;
577
+                WRITEEND;
578
+            }
570 579
         }
571 580
     } else {
572 581
         if (s->flags & CODEC_FLAG_PASS1) {
... ...
@@ -574,6 +614,10 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane)
574 574
                 LOAD2_16;
575 575
                 STAT2_16;
576 576
             }
577
+            if (width&1) {
578
+                LOADEND_16;
579
+                STATEND_16;
580
+            }
577 581
         }
578 582
         if (s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT)
579 583
             return 0;
... ...
@@ -584,11 +628,20 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane)
584 584
                 STAT2_16;
585 585
                 WRITE2_16;
586 586
             }
587
+            if (width&1) {
588
+                LOADEND_16;
589
+                STATEND_16;
590
+                WRITEEND_16;
591
+            }
587 592
         } else {
588 593
             for (i = 0; i < count; i++) {
589 594
                 LOAD2_16;
590 595
                 WRITE2_16;
591 596
             }
597
+            if (width&1) {
598
+                LOADEND_16;
599
+                WRITEEND_16;
600
+            }
592 601
         }
593 602
     }
594 603
 #undef LOAD2
... ...
@@ -1,4 +1,4 @@
1
-a6164daa3036ae92eb0b3f0831268165 *tests/data/fate/vsynth3-ffvhuff420p12.avi
2
-172132 tests/data/fate/vsynth3-ffvhuff420p12.avi
3
-eb1a8ff2c33ba5145b5a89727ee5dcb8 *tests/data/fate/vsynth3-ffvhuff420p12.out.rawvideo
4
-stddev:   46.89 PSNR: 14.71 MAXDIFF:  239 bytes:    86700/    86700
1
+9b3e44ccdd28614f588804a0682db312 *tests/data/fate/vsynth3-ffvhuff420p12.avi
2
+175256 tests/data/fate/vsynth3-ffvhuff420p12.avi
3
+faf8b5ec29b12ac41b1bd1a6ebd8a757 *tests/data/fate/vsynth3-ffvhuff420p12.out.rawvideo
4
+stddev:   47.95 PSNR: 14.51 MAXDIFF:  237 bytes:    86700/    86700
... ...
@@ -1,4 +1,4 @@
1
-2459272ee10f3b503940324ba5dcc1e5 *tests/data/fate/vsynth3-ffvhuff422p10left.avi
2
-168836 tests/data/fate/vsynth3-ffvhuff422p10left.avi
3
-863818eed035b3fa7b19535927687879 *tests/data/fate/vsynth3-ffvhuff422p10left.out.rawvideo
4
-stddev:   38.45 PSNR: 16.43 MAXDIFF:  225 bytes:    86700/    86700
1
+5afec2536440c892919a1569c7109858 *tests/data/fate/vsynth3-ffvhuff422p10left.avi
2
+173548 tests/data/fate/vsynth3-ffvhuff422p10left.avi
3
+7815024a7239be263c6bf910021df1a0 *tests/data/fate/vsynth3-ffvhuff422p10left.out.rawvideo
4
+stddev:   38.41 PSNR: 16.44 MAXDIFF:  237 bytes:    86700/    86700