History

avfilter/paletteuse: add burkes dithering

Burkes according to https://bisqwit.iki.fi/jutut/kuvat/ordered_dither/error_diffusion.txt: * 8 4 2 4 8 4 2 / 32

Clément Bœsch committed 3 years ago

Commit c973e8a1 parent 99733432 files · +26 −0Browse files

Unified · Split

2 files
  1. doc/filters.texi +2 −0
  2. libavfilter/vf_paletteuse.c +24 −0
doc/filters.texi+2−0
@@ -18526,6 +18526,8 @@ Frankie Sierra dithering v2 (error diffusion) · 18525 unmodified lines
1852618526 Frankie Sierra dithering v2 "Lite" (error diffusion)
1852718527 @item sierra3
1852818528 Frankie Sierra dithering v3 (error diffusion)
18529+@item burkes
18530+Burkes dithering (error diffusion)
1852918531 @end table
1853018532
1853118533 Default is @var{sierra2_4a}.
libavfilter/vf_paletteuse.c+24−0
@@ -43,6 +43,7 @@ enum dithering_mode { · 42 unmodified lines
4343 DITHERING_SIERRA2,
4444 DITHERING_SIERRA2_4A,
4545 DITHERING_SIERRA3,
46+ DITHERING_BURKES,
4647 NB_DITHERING
4748 };
4849
@@ -115,6 +116,7 @@ static const AVOption paletteuse_options[] = { · 66 unmodified lines
115116 { "sierra2", "Frankie Sierra dithering v2 (error diffusion)", 0, AV_OPT_TYPE_CONST, {.i64=DITHERING_SIERRA2}, INT_MIN, INT_MAX, FLAGS, "dithering_mode" },
116117 { "sierra2_4a", "Frankie Sierra dithering v2 \"Lite\" (error diffusion)", 0, AV_OPT_TYPE_CONST, {.i64=DITHERING_SIERRA2_4A}, INT_MIN, INT_MAX, FLAGS, "dithering_mode" },
117118 { "sierra3", "Frankie Sierra dithering v3 (error diffusion)", 0, AV_OPT_TYPE_CONST, {.i64=DITHERING_SIERRA3}, INT_MIN, INT_MAX, FLAGS, "dithering_mode" },
119+ { "burkes", "Burkes dithering (error diffusion)", 0, AV_OPT_TYPE_CONST, {.i64=DITHERING_BURKES}, INT_MIN, INT_MAX, FLAGS, "dithering_mode" },
118120 { "bayer_scale", "set scale for bayer dithering", OFFSET(bayer_scale), AV_OPT_TYPE_INT, {.i64=2}, 0, 5, FLAGS },
119121 { "diff_mode", "set frame difference mode", OFFSET(diff_mode), AV_OPT_TYPE_INT, {.i64=DIFF_MODE_NONE}, 0, NB_DIFF_MODE-1, FLAGS, "diff_mode" },
120122 { "rectangle", "process smallest different rectangle", 0, AV_OPT_TYPE_CONST, {.i64=DIFF_MODE_RECTANGLE}, INT_MIN, INT_MAX, FLAGS, "diff_mode" },
@@ -396,6 +398,26 @@ static av_always_inline int set_frame(PaletteUseContext *s, AVFrame *out, AVFram · 275 unmodified lines
396398 }
397399 }
398400
401+ } else if (dither == DITHERING_BURKES) {
402+ const int right = x < w - 1, down = y < h - 1, left = x > x_start;
403+ const int right2 = x < w - 2, left2 = x > x_start + 1;
404+ const int color = get_dst_color_err(s, src[x], &er, &eg, &eb);
405+
406+ if (color < 0)
407+ return color;
408+ dst[x] = color;
409+
410+ if (right) src[ x + 1] = dither_color(src[ x + 1], er, eg, eb, 8, 5);
411+ if (right2) src[ x + 2] = dither_color(src[ x + 2], er, eg, eb, 4, 5);
412+
413+ if (down) {
414+ if (left2) src[src_linesize + x - 2] = dither_color(src[src_linesize + x - 2], er, eg, eb, 2, 5);
415+ if (left) src[src_linesize + x - 1] = dither_color(src[src_linesize + x - 1], er, eg, eb, 4, 5);
416+ if (1) src[src_linesize + x ] = dither_color(src[src_linesize + x ], er, eg, eb, 8, 5);
417+ if (right) src[src_linesize + x + 1] = dither_color(src[src_linesize + x + 1], er, eg, eb, 4, 5);
418+ if (right2) src[src_linesize + x + 2] = dither_color(src[src_linesize + x + 2], er, eg, eb, 2, 5);
419+ }
420+
399421 } else {
400422 const int color = color_get(s, src[x]);
401423
@@ -871,6 +893,7 @@ DEFINE_SET_FRAME(floyd_steinberg, DITHERING_FLOYD_STEINBERG) · 469 unmodified lines
871893 DEFINE_SET_FRAME(sierra2, DITHERING_SIERRA2)
872894 DEFINE_SET_FRAME(sierra2_4a, DITHERING_SIERRA2_4A)
873895 DEFINE_SET_FRAME(sierra3, DITHERING_SIERRA3)
896+DEFINE_SET_FRAME(burkes, DITHERING_BURKES)
874897
875898 static const set_frame_func set_frame_lut[NB_DITHERING] = {
876899 set_frame_none,
@@ -880,6 +903,7 @@ static const set_frame_func set_frame_lut[NB_DITHERING] = { · 3 unmodified lines
880903 set_frame_sierra2,
881904 set_frame_sierra2_4a,
882905 set_frame_sierra3,
906+ set_frame_burkes,
883907 };
884908
885909 static int dither_value(int p)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t