If width is odd, last sample wouldn't be written. --- libavcodec/huffyuvenc.c | 61 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 4 deletions(-)
diff --git a/libavcodec/huffyuvenc.c b/libavcodec/huffyuvenc.c index fd6f570..c7e69d5 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 -- 1.9.2.msysgit.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel