From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id E8A9B42813 for ; Fri, 30 Dec 2022 11:35:17 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D6A2368B9AC; Fri, 30 Dec 2022 13:35:09 +0200 (EET) Received: from ssq0.pkh.me (unknown [92.154.28.164]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3D8C968B53C for ; Fri, 30 Dec 2022 13:35:03 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pkh.me; s=selector1; t=1672400097; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tRr9BEhPW6gQcELeeL1ibAGlvCwlNy/+0Ao/wuWt5yI=; b=PkdbdLVffzuxVMe0iWl4KuWYgmuMPaDfhMM2LBURx/nztmgER7u9+oQkTUXSF05kqPiJQL 27hJp5VKlPjP+xflwKeEbdZynqt7FGmifCZubVGyjqAUs7OewTLPbHMKKxebJaALz3UZoS y2t93hZfLk5AcCwxgstu6DCh1nDcovU= Received: from localhost (ssq0.pkh.me [local]) by ssq0.pkh.me (OpenSMTPD) with ESMTPA id cd181b27; Fri, 30 Dec 2022 11:34:57 +0000 (UTC) From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= To: ffmpeg-devel@ffmpeg.org Date: Fri, 30 Dec 2022 12:34:52 +0100 Message-Id: <20221230113455.2632289-2-u@pkh.me> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221230113455.2632289-1-u@pkh.me> References: <20221230113455.2632289-1-u@pkh.me> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/4] avfilter/paletteuse: add sierra3 dithering X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Sierra3 according to https://bisqwit.iki.fi/jutut/kuvat/ordered_dither/error_diffusion.txt: * 5 3 2 4 5 4 2 2 3 2 / 32 --- doc/filters.texi | 2 ++ libavfilter/vf_paletteuse.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/doc/filters.texi b/doc/filters.texi index f51623d16a..84034072be 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -18516,6 +18516,8 @@ Floyd and Steingberg dithering (error diffusion) Frankie Sierra dithering v2 (error diffusion) @item sierra2_4a Frankie Sierra dithering v2 "Lite" (error diffusion) +@item sierra3 +Frankie Sierra dithering v3 (error diffusion) @end table Default is @var{sierra2_4a}. diff --git a/libavfilter/vf_paletteuse.c b/libavfilter/vf_paletteuse.c index 67e065da7f..902bf5d82f 100644 --- a/libavfilter/vf_paletteuse.c +++ b/libavfilter/vf_paletteuse.c @@ -42,6 +42,7 @@ enum dithering_mode { DITHERING_FLOYD_STEINBERG, DITHERING_SIERRA2, DITHERING_SIERRA2_4A, + DITHERING_SIERRA3, NB_DITHERING }; @@ -113,6 +114,7 @@ static const AVOption paletteuse_options[] = { { "floyd_steinberg", "Floyd and Steingberg dithering (error diffusion)", 0, AV_OPT_TYPE_CONST, {.i64=DITHERING_FLOYD_STEINBERG}, INT_MIN, INT_MAX, FLAGS, "dithering_mode" }, { "sierra2", "Frankie Sierra dithering v2 (error diffusion)", 0, AV_OPT_TYPE_CONST, {.i64=DITHERING_SIERRA2}, INT_MIN, INT_MAX, FLAGS, "dithering_mode" }, { "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" }, + { "sierra3", "Frankie Sierra dithering v3 (error diffusion)", 0, AV_OPT_TYPE_CONST, {.i64=DITHERING_SIERRA3}, INT_MIN, INT_MAX, FLAGS, "dithering_mode" }, { "bayer_scale", "set scale for bayer dithering", OFFSET(bayer_scale), AV_OPT_TYPE_INT, {.i64=2}, 0, 5, FLAGS }, { "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" }, { "rectangle", "process smallest different rectangle", 0, AV_OPT_TYPE_CONST, {.i64=DIFF_MODE_RECTANGLE}, INT_MIN, INT_MAX, FLAGS, "diff_mode" }, @@ -368,6 +370,32 @@ static av_always_inline int set_frame(PaletteUseContext *s, AVFrame *out, AVFram if (left && down) src[src_linesize + x - 1] = dither_color(src[src_linesize + x - 1], er, eg, eb, 1, 2); if ( down) src[src_linesize + x ] = dither_color(src[src_linesize + x ], er, eg, eb, 1, 2); + } else if (dither == DITHERING_SIERRA3) { + const int right = x < w - 1, down = y < h - 1, left = x > x_start; + const int right2 = x < w - 2, down2 = y < h - 2, left2 = x > x_start + 1; + const int color = get_dst_color_err(s, src[x], &er, &eg, &eb); + + if (color < 0) + return color; + dst[x] = color; + + if (right) src[ x + 1] = dither_color(src[ x + 1], er, eg, eb, 5, 5); + if (right2) src[ x + 2] = dither_color(src[ x + 2], er, eg, eb, 3, 5); + + if (down) { + if (left2) src[src_linesize + x - 2] = dither_color(src[src_linesize + x - 2], er, eg, eb, 2, 5); + if (left) src[src_linesize + x - 1] = dither_color(src[src_linesize + x - 1], er, eg, eb, 4, 5); + if (1) src[src_linesize + x ] = dither_color(src[src_linesize + x ], er, eg, eb, 5, 5); + if (right) src[src_linesize + x + 1] = dither_color(src[src_linesize + x + 1], er, eg, eb, 4, 5); + if (right2) src[src_linesize + x + 2] = dither_color(src[src_linesize + x + 2], er, eg, eb, 2, 5); + + if (down2) { + if (left) src[src_linesize*2 + x - 1] = dither_color(src[src_linesize*2 + x - 1], er, eg, eb, 2, 5); + if (1) src[src_linesize*2 + x ] = dither_color(src[src_linesize*2 + x ], er, eg, eb, 3, 5); + if (right) src[src_linesize*2 + x + 1] = dither_color(src[src_linesize*2 + x + 1], er, eg, eb, 2, 5); + } + } + } else { const int color = color_get(s, src[x]); @@ -842,6 +870,7 @@ DEFINE_SET_FRAME(heckbert, DITHERING_HECKBERT) DEFINE_SET_FRAME(floyd_steinberg, DITHERING_FLOYD_STEINBERG) DEFINE_SET_FRAME(sierra2, DITHERING_SIERRA2) DEFINE_SET_FRAME(sierra2_4a, DITHERING_SIERRA2_4A) +DEFINE_SET_FRAME(sierra3, DITHERING_SIERRA3) static const set_frame_func set_frame_lut[NB_DITHERING] = { set_frame_none, @@ -850,6 +879,7 @@ static const set_frame_func set_frame_lut[NB_DITHERING] = { set_frame_floyd_steinberg, set_frame_sierra2, set_frame_sierra2_4a, + set_frame_sierra3, }; static int dither_value(int p) -- 2.39.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".