[FFmpeg-cvslog] cljrenc: Add dither to avoid the banding artifcats caused by the very low
Michael Niedermayer
git at videolan.org
Fri Dec 9 01:23:27 CET 2011
ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Fri Dec 9 01:11:06 2011 +0100| [43a36ad2eec6e365fcf9de3eac75da5d9d3cdb38] | committer: Michael Niedermayer
cljrenc: Add dither to avoid the banding artifcats caused by the very low
number of bits used to represent brightness levels.
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=43a36ad2eec6e365fcf9de3eac75da5d9d3cdb38
---
libavcodec/cljr.c | 14 ++++++++------
1 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/libavcodec/cljr.c b/libavcodec/cljr.c
index 183652b..950b46a 100644
--- a/libavcodec/cljr.c
+++ b/libavcodec/cljr.c
@@ -132,6 +132,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
PutBitContext pb;
AVFrame *p = data;
int x, y;
+ uint32_t dither= avctx->frame_number;
p->pict_type = AV_PICTURE_TYPE_I;
p->key_frame = 1;
@@ -143,13 +144,14 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
uint8_t *cb = &p->data[1][y * p->linesize[1]];
uint8_t *cr = &p->data[2][y * p->linesize[2]];
for (x = 0; x < avctx->width; x += 4) {
- put_bits(&pb, 5, luma[3] >> 3);
- put_bits(&pb, 5, luma[2] >> 3);
- put_bits(&pb, 5, luma[1] >> 3);
- put_bits(&pb, 5, luma[0] >> 3);
+ put_bits(&pb, 5, (luma[3] + (dither>>29) ) >> 3);
+ put_bits(&pb, 5, (luma[2] + ((dither>>26)&7)) >> 3);
+ put_bits(&pb, 5, (luma[1] + ((dither>>23)&7)) >> 3);
+ put_bits(&pb, 5, (luma[0] + ((dither>>20)&7)) >> 3);
luma += 4;
- put_bits(&pb, 6, *(cb++) >> 2);
- put_bits(&pb, 6, *(cr++) >> 2);
+ put_bits(&pb, 6, (*(cb++) + ((dither>>18)&3)) >> 2);
+ put_bits(&pb, 6, (*(cr++) + ((dither>>16)&3)) >> 2);
+ dither = dither*1664525+1013904223;
}
}
More information about the ffmpeg-cvslog
mailing list