mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-03-02 02:30:58 +00:00
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>
This commit is contained in:
parent
25b9eef410
commit
43a36ad2ee
@ -132,6 +132,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
|
|||||||
PutBitContext pb;
|
PutBitContext pb;
|
||||||
AVFrame *p = data;
|
AVFrame *p = data;
|
||||||
int x, y;
|
int x, y;
|
||||||
|
uint32_t dither= avctx->frame_number;
|
||||||
|
|
||||||
p->pict_type = AV_PICTURE_TYPE_I;
|
p->pict_type = AV_PICTURE_TYPE_I;
|
||||||
p->key_frame = 1;
|
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 *cb = &p->data[1][y * p->linesize[1]];
|
||||||
uint8_t *cr = &p->data[2][y * p->linesize[2]];
|
uint8_t *cr = &p->data[2][y * p->linesize[2]];
|
||||||
for (x = 0; x < avctx->width; x += 4) {
|
for (x = 0; x < avctx->width; x += 4) {
|
||||||
put_bits(&pb, 5, luma[3] >> 3);
|
put_bits(&pb, 5, (luma[3] + (dither>>29) ) >> 3);
|
||||||
put_bits(&pb, 5, luma[2] >> 3);
|
put_bits(&pb, 5, (luma[2] + ((dither>>26)&7)) >> 3);
|
||||||
put_bits(&pb, 5, luma[1] >> 3);
|
put_bits(&pb, 5, (luma[1] + ((dither>>23)&7)) >> 3);
|
||||||
put_bits(&pb, 5, luma[0] >> 3);
|
put_bits(&pb, 5, (luma[0] + ((dither>>20)&7)) >> 3);
|
||||||
luma += 4;
|
luma += 4;
|
||||||
put_bits(&pb, 6, *(cb++) >> 2);
|
put_bits(&pb, 6, (*(cb++) + ((dither>>18)&3)) >> 2);
|
||||||
put_bits(&pb, 6, *(cr++) >> 2);
|
put_bits(&pb, 6, (*(cr++) + ((dither>>16)&3)) >> 2);
|
||||||
|
dither = dither*1664525+1013904223;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user