Commit 6ee76817 authored by Christophe Gisquet's avatar Christophe Gisquet Committed by Michael Niedermayer

huffyuvenc: write last odd sample

If width is odd, last sample wouldn't be written.
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 2a85826e
...@@ -488,15 +488,31 @@ static int encode_422_bitstream(HYuvContext *s, int offset, int count) ...@@ -488,15 +488,31 @@ static int encode_422_bitstream(HYuvContext *s, int offset, int count)
return 0; 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) { 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"); av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
return -1; 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\ #define LOAD2\
int y0 = s->temp[0][2 * i];\ int y0 = s->temp[0][2 * i];\
int y1 = s->temp[0][2 * i + 1]; int y1 = s->temp[0][2 * i + 1];
...@@ -521,14 +537,16 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane) ...@@ -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, s->len[plane][y1>>2], s->bits[plane][y1>>2]);\
put_bits(&s->pb, 2, y1&3); put_bits(&s->pb, 2, y1&3);
count /= 2;
if (s->bps <= 8) { if (s->bps <= 8) {
if (s->flags & CODEC_FLAG_PASS1) { if (s->flags & CODEC_FLAG_PASS1) {
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
LOAD2; LOAD2;
STAT2; STAT2;
} }
if (width&1) {
LOADEND;
STATEND;
}
} }
if (s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT) if (s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT)
return 0; return 0;
...@@ -539,11 +557,20 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane) ...@@ -539,11 +557,20 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane)
STAT2; STAT2;
WRITE2; WRITE2;
} }
if (width&1) {
LOADEND;
STATEND;
WRITEEND;
}
} else { } else {
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
LOAD2; LOAD2;
WRITE2; WRITE2;
} }
if (width&1) {
LOADEND;
WRITEEND;
}
} }
} else if (s->bps <= 14) { } else if (s->bps <= 14) {
int mask = s->n - 1; int mask = s->n - 1;
...@@ -552,6 +579,10 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane) ...@@ -552,6 +579,10 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane)
LOAD2_14; LOAD2_14;
STAT2; STAT2;
} }
if (width&1) {
LOADEND_14;
STATEND;
}
} }
if (s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT) if (s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT)
return 0; return 0;
...@@ -562,11 +593,20 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane) ...@@ -562,11 +593,20 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane)
STAT2; STAT2;
WRITE2; WRITE2;
} }
if (width&1) {
LOADEND_14;
STATEND;
WRITEEND;
}
} else { } else {
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
LOAD2_14; LOAD2_14;
WRITE2; WRITE2;
} }
if (width&1) {
LOADEND_14;
WRITEEND;
}
} }
} else { } else {
if (s->flags & CODEC_FLAG_PASS1) { if (s->flags & CODEC_FLAG_PASS1) {
...@@ -574,6 +614,10 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane) ...@@ -574,6 +614,10 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane)
LOAD2_16; LOAD2_16;
STAT2_16; STAT2_16;
} }
if (width&1) {
LOADEND_16;
STATEND_16;
}
} }
if (s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT) if (s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT)
return 0; return 0;
...@@ -584,11 +628,20 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane) ...@@ -584,11 +628,20 @@ static int encode_plane_bitstream(HYuvContext *s, int count, int plane)
STAT2_16; STAT2_16;
WRITE2_16; WRITE2_16;
} }
if (width&1) {
LOADEND_16;
STATEND_16;
WRITEEND_16;
}
} else { } else {
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
LOAD2_16; LOAD2_16;
WRITE2_16; WRITE2_16;
} }
if (width&1) {
LOADEND_16;
WRITEEND_16;
}
} }
} }
#undef LOAD2 #undef LOAD2
......
a6164daa3036ae92eb0b3f0831268165 *tests/data/fate/vsynth3-ffvhuff420p12.avi 9b3e44ccdd28614f588804a0682db312 *tests/data/fate/vsynth3-ffvhuff420p12.avi
172132 tests/data/fate/vsynth3-ffvhuff420p12.avi 175256 tests/data/fate/vsynth3-ffvhuff420p12.avi
eb1a8ff2c33ba5145b5a89727ee5dcb8 *tests/data/fate/vsynth3-ffvhuff420p12.out.rawvideo faf8b5ec29b12ac41b1bd1a6ebd8a757 *tests/data/fate/vsynth3-ffvhuff420p12.out.rawvideo
stddev: 46.89 PSNR: 14.71 MAXDIFF: 239 bytes: 86700/ 86700 stddev: 47.95 PSNR: 14.51 MAXDIFF: 237 bytes: 86700/ 86700
2459272ee10f3b503940324ba5dcc1e5 *tests/data/fate/vsynth3-ffvhuff422p10left.avi 5afec2536440c892919a1569c7109858 *tests/data/fate/vsynth3-ffvhuff422p10left.avi
168836 tests/data/fate/vsynth3-ffvhuff422p10left.avi 173548 tests/data/fate/vsynth3-ffvhuff422p10left.avi
863818eed035b3fa7b19535927687879 *tests/data/fate/vsynth3-ffvhuff422p10left.out.rawvideo 7815024a7239be263c6bf910021df1a0 *tests/data/fate/vsynth3-ffvhuff422p10left.out.rawvideo
stddev: 38.45 PSNR: 16.43 MAXDIFF: 225 bytes: 86700/ 86700 stddev: 38.41 PSNR: 16.44 MAXDIFF: 237 bytes: 86700/ 86700
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment