summaryrefslogtreecommitdiff
path: root/libavcodec/cljr.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-12-09 01:11:06 +0100
committerMichael Niedermayer <michaelni@gmx.at>2011-12-09 01:11:06 +0100
commit43a36ad2eec6e365fcf9de3eac75da5d9d3cdb38 (patch)
tree2963abad72139f82297f2817950a486de01cd5ce /libavcodec/cljr.c
parent25b9eef410f4a737250dcf2d17b65f6c0c39cd6a (diff)
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@gmx.at>
Diffstat (limited to 'libavcodec/cljr.c')
-rw-r--r--libavcodec/cljr.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/libavcodec/cljr.c b/libavcodec/cljr.c
index 183652b3a1..950b46a3f7 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;
}
}