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
18526Frankie Sierra dithering v2 "Lite" (error diffusion)18526Frankie Sierra dithering v2 "Lite" (error diffusion)
18527@item sierra318527@item sierra3
18528Frankie Sierra dithering v3 (error diffusion)18528Frankie Sierra dithering v3 (error diffusion)
18529@item burkes
18530Burkes dithering (error diffusion)
18529@end table18531@end table
18530 18532
18531Default is @var{sierra2_4a}.18533Default is @var{sierra2_4a}.
libavfilter/vf_paletteuse.c+24−0
@@ -43,6 +43,7 @@ enum dithering_mode { · 42 unmodified lines
43 DITHERING_SIERRA2,43 DITHERING_SIERRA2,
44 DITHERING_SIERRA2_4A,44 DITHERING_SIERRA2_4A,
45 DITHERING_SIERRA3,45 DITHERING_SIERRA3,
46 DITHERING_BURKES,
46 NB_DITHERING47 NB_DITHERING
47};48};
48 49
@@ -115,6 +116,7 @@ static const AVOption paletteuse_options[] = { · 66 unmodified lines
115 { "sierra2", "Frankie Sierra dithering v2 (error diffusion)", 0, AV_OPT_TYPE_CONST, {.i64=DITHERING_SIERRA2}, INT_MIN, INT_MAX, FLAGS, "dithering_mode" },116 { "sierra2", "Frankie Sierra dithering v2 (error diffusion)", 0, AV_OPT_TYPE_CONST, {.i64=DITHERING_SIERRA2}, INT_MIN, INT_MAX, FLAGS, "dithering_mode" },
116 { "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" },117 { "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" },
117 { "sierra3", "Frankie Sierra dithering v3 (error diffusion)", 0, AV_OPT_TYPE_CONST, {.i64=DITHERING_SIERRA3}, INT_MIN, INT_MAX, FLAGS, "dithering_mode" },118 { "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" },
118 { "bayer_scale", "set scale for bayer dithering", OFFSET(bayer_scale), AV_OPT_TYPE_INT, {.i64=2}, 0, 5, FLAGS },120 { "bayer_scale", "set scale for bayer dithering", OFFSET(bayer_scale), AV_OPT_TYPE_INT, {.i64=2}, 0, 5, FLAGS },
119 { "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" },121 { "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" },
120 { "rectangle", "process smallest different rectangle", 0, AV_OPT_TYPE_CONST, {.i64=DIFF_MODE_RECTANGLE}, INT_MIN, INT_MAX, FLAGS, "diff_mode" },122 { "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
396 }398 }
397 }399 }
398 400
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
399 } else {421 } else {
400 const int color = color_get(s, src[x]);422 const int color = color_get(s, src[x]);
401 423
@@ -871,6 +893,7 @@ DEFINE_SET_FRAME(floyd_steinberg, DITHERING_FLOYD_STEINBERG) · 469 unmodified lines
871DEFINE_SET_FRAME(sierra2, DITHERING_SIERRA2)893DEFINE_SET_FRAME(sierra2, DITHERING_SIERRA2)
872DEFINE_SET_FRAME(sierra2_4a, DITHERING_SIERRA2_4A)894DEFINE_SET_FRAME(sierra2_4a, DITHERING_SIERRA2_4A)
873DEFINE_SET_FRAME(sierra3, DITHERING_SIERRA3)895DEFINE_SET_FRAME(sierra3, DITHERING_SIERRA3)
896DEFINE_SET_FRAME(burkes, DITHERING_BURKES)
874 897
875static const set_frame_func set_frame_lut[NB_DITHERING] = {898static const set_frame_func set_frame_lut[NB_DITHERING] = {
876 set_frame_none,899 set_frame_none,
@@ -880,6 +903,7 @@ static const set_frame_func set_frame_lut[NB_DITHERING] = { · 3 unmodified lines
880 set_frame_sierra2,903 set_frame_sierra2,
881 set_frame_sierra2_4a,904 set_frame_sierra2_4a,
882 set_frame_sierra3,905 set_frame_sierra3,
906 set_frame_burkes,
883};907};
884 908
885static int dither_value(int p)909static 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