diff options
author | Christophe Gisquet <christophe.gisquet@gmail.com> | 2014-08-25 20:24:29 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2014-08-25 23:12:30 +0200 |
commit | 6ee7681723a41c8c9bf5f3d11c723c6907848f7d (patch) | |
tree | 073596df0fcd9b68f473affea65958c245f1cf99 /libavcodec/huffyuvenc.c | |
parent | 2a85826e5753aac8964254bd5688a03e49a7f551 (diff) | |
download | ffmpeg-6ee7681723a41c8c9bf5f3d11c723c6907848f7d.tar.gz |
huffyuvenc: write last odd sample
If width is odd, last sample wouldn't be written.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/huffyuvenc.c')
-rw-r--r-- | libavcodec/huffyuvenc.c | 61 |
1 files changed, 57 insertions, 4 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 |