From 6ee7681723a41c8c9bf5f3d11c723c6907848f7d Mon Sep 17 00:00:00 2001 From: Christophe Gisquet Date: Mon, 25 Aug 2014 20:24:29 +0000 Subject: [PATCH] huffyuvenc: write last odd sample If width is odd, last sample wouldn't be written. Signed-off-by: Michael Niedermayer --- libavcodec/huffyuvenc.c | 61 ++++++++++++++++++++-- tests/ref/vsynth/vsynth3-ffvhuff420p12 | 8 +-- tests/ref/vsynth/vsynth3-ffvhuff422p10left | 8 +-- 3 files changed, 65 insertions(+), 12 deletions(-) diff --git a/libavcodec/huffyuvenc.c b/libavcodec/huffyuvenc.c index fd6f570e66..c7e69d5cee 100644 --- a/libavcodec/huffyuvenc.c +++ b/libavcodec/huffyuvenc.c @@ -488,15 +488,31 @@ static int encode_422_bitstream(HYuvContext *s, int offset, int count) return 0; } -static int encode_plane_bitstream(HYuvContext *s, int count, int plane) +static int encode_plane_bitstream(HYuvContext *s, int width, int plane) { - int i; + int i, count = width/2; if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) < count * s->bps / 2) { av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); return -1; } +#define LOADEND\ + int y0 = s->temp[0][width-1]; +#define LOADEND_14\ + int y0 = s->temp16[0][width-1] & mask; +#define LOADEND_16\ + int y0 = s->temp16[0][width-1]; +#define STATEND\ + s->stats[plane][y0]++; +#define STATEND_16\ + s->stats[plane][y0>>2]++; +#define WRITEEND\ + put_bits(&s->pb, s->len[plane][y0], s->bits[plane][y0]); +#define WRITEEND_16\ + put_bits(&s->pb, s->len[plane][y0>>2], s->bits[plane][y0>>2]);\ + put_bits(&s->pb, 2, y0&3); + #define LOAD2\ int y0 = s->temp[0][2 * i];\ int y1 = s->temp[0][2 * i + 1]; @@ -521,14 +537,16 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane) put_bits(&s->pb, s->len[plane][y1>>2], s->bits[plane][y1>>2]);\ put_bits(&s->pb, 2, y1&3); - count /= 2; - if (s->bps <= 8) { if (s->flags & CODEC_FLAG_PASS1) { for (i = 0; i < count; i++) { LOAD2; STAT2; } + if (width&1) { + LOADEND; + STATEND; + } } if (s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT) return 0; @@ -539,11 +557,20 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane) STAT2; WRITE2; } + if (width&1) { + LOADEND; + STATEND; + WRITEEND; + } } else { for (i = 0; i < count; i++) { LOAD2; WRITE2; } + if (width&1) { + LOADEND; + WRITEEND; + } } } else if (s->bps <= 14) { int mask = s->n - 1; @@ -552,6 +579,10 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane) LOAD2_14; STAT2; } + if (width&1) { + LOADEND_14; + STATEND; + } } if (s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT) return 0; @@ -562,11 +593,20 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane) STAT2; WRITE2; } + if (width&1) { + LOADEND_14; + STATEND; + WRITEEND; + } } else { for (i = 0; i < count; i++) { LOAD2_14; WRITE2; } + if (width&1) { + LOADEND_14; + WRITEEND; + } } } else { if (s->flags & CODEC_FLAG_PASS1) { @@ -574,6 +614,10 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane) LOAD2_16; STAT2_16; } + if (width&1) { + LOADEND_16; + STATEND_16; + } } if (s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT) return 0; @@ -584,11 +628,20 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane) STAT2_16; WRITE2_16; } + if (width&1) { + LOADEND_16; + STATEND_16; + WRITEEND_16; + } } else { for (i = 0; i < count; i++) { LOAD2_16; WRITE2_16; } + if (width&1) { + LOADEND_16; + WRITEEND_16; + } } } #undef LOAD2 diff --git a/tests/ref/vsynth/vsynth3-ffvhuff420p12 b/tests/ref/vsynth/vsynth3-ffvhuff420p12 index b51882eedf..3db1c5d717 100644 --- a/tests/ref/vsynth/vsynth3-ffvhuff420p12 +++ b/tests/ref/vsynth/vsynth3-ffvhuff420p12 @@ -1,4 +1,4 @@ -a6164daa3036ae92eb0b3f0831268165 *tests/data/fate/vsynth3-ffvhuff420p12.avi -172132 tests/data/fate/vsynth3-ffvhuff420p12.avi -eb1a8ff2c33ba5145b5a89727ee5dcb8 *tests/data/fate/vsynth3-ffvhuff420p12.out.rawvideo -stddev: 46.89 PSNR: 14.71 MAXDIFF: 239 bytes: 86700/ 86700 +9b3e44ccdd28614f588804a0682db312 *tests/data/fate/vsynth3-ffvhuff420p12.avi +175256 tests/data/fate/vsynth3-ffvhuff420p12.avi +faf8b5ec29b12ac41b1bd1a6ebd8a757 *tests/data/fate/vsynth3-ffvhuff420p12.out.rawvideo +stddev: 47.95 PSNR: 14.51 MAXDIFF: 237 bytes: 86700/ 86700 diff --git a/tests/ref/vsynth/vsynth3-ffvhuff422p10left b/tests/ref/vsynth/vsynth3-ffvhuff422p10left index 7dca14e9ba..a18f2c8ffb 100644 --- a/tests/ref/vsynth/vsynth3-ffvhuff422p10left +++ b/tests/ref/vsynth/vsynth3-ffvhuff422p10left @@ -1,4 +1,4 @@ -2459272ee10f3b503940324ba5dcc1e5 *tests/data/fate/vsynth3-ffvhuff422p10left.avi -168836 tests/data/fate/vsynth3-ffvhuff422p10left.avi -863818eed035b3fa7b19535927687879 *tests/data/fate/vsynth3-ffvhuff422p10left.out.rawvideo -stddev: 38.45 PSNR: 16.43 MAXDIFF: 225 bytes: 86700/ 86700 +5afec2536440c892919a1569c7109858 *tests/data/fate/vsynth3-ffvhuff422p10left.avi +173548 tests/data/fate/vsynth3-ffvhuff422p10left.avi +7815024a7239be263c6bf910021df1a0 *tests/data/fate/vsynth3-ffvhuff422p10left.out.rawvideo +stddev: 38.41 PSNR: 16.44 MAXDIFF: 237 bytes: 86700/ 86700