From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: ffmpeg-devel@ffmpeg.org Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Subject: [FFmpeg-devel] [PATCH 07/10] avfilter/vf_nlmeans: Move ff_nlmeans_init into a header Date: Tue, 3 May 2022 08:37:48 +0200 Message-ID: <AS8PR01MB79444DB5BC9AE98E12E417C58FC09@AS8PR01MB7944.eurprd01.prod.exchangelabs.com> (raw) In-Reply-To: <AS8PR01MB7944F1A5A2DE2EE9898F81A28FC09@AS8PR01MB7944.eurprd01.prod.exchangelabs.com> This removes a dependency of checkasm on lavfi/vf_nlmeans.o and also allows to inline ff_nlmeans_init() irrespectively of interposing. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavfilter/vf_nlmeans.c | 108 +------------------------- libavfilter/vf_nlmeans.h | 1 - libavfilter/vf_nlmeans_init.h | 139 ++++++++++++++++++++++++++++++++++ tests/checkasm/vf_nlmeans.c | 2 +- 4 files changed, 141 insertions(+), 109 deletions(-) create mode 100644 libavfilter/vf_nlmeans_init.h diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c index 8a05965c9b..2fc3adacca 100644 --- a/libavfilter/vf_nlmeans.c +++ b/libavfilter/vf_nlmeans.c @@ -36,6 +36,7 @@ #include "formats.h" #include "internal.h" #include "vf_nlmeans.h" +#include "vf_nlmeans_init.h" #include "video.h" typedef struct NLMeansContext { @@ -84,48 +85,6 @@ static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_NONE }; -/** - * Compute squared difference of the safe area (the zone where s1 and s2 - * overlap). It is likely the largest integral zone, so it is interesting to do - * as little checks as possible; contrary to the unsafe version of this - * function, we do not need any clipping here. - * - * The line above dst and the column to its left are always readable. - */ -static void compute_safe_ssd_integral_image_c(uint32_t *dst, ptrdiff_t dst_linesize_32, - const uint8_t *s1, ptrdiff_t linesize1, - const uint8_t *s2, ptrdiff_t linesize2, - int w, int h) -{ - const uint32_t *dst_top = dst - dst_linesize_32; - - /* SIMD-friendly assumptions allowed here */ - av_assert2(!(w & 0xf) && w >= 16 && h >= 1); - - for (int y = 0; y < h; y++) { - for (int x = 0; x < w; x += 4) { - const int d0 = s1[x ] - s2[x ]; - const int d1 = s1[x + 1] - s2[x + 1]; - const int d2 = s1[x + 2] - s2[x + 2]; - const int d3 = s1[x + 3] - s2[x + 3]; - - dst[x ] = dst_top[x ] - dst_top[x - 1] + d0*d0; - dst[x + 1] = dst_top[x + 1] - dst_top[x ] + d1*d1; - dst[x + 2] = dst_top[x + 2] - dst_top[x + 1] + d2*d2; - dst[x + 3] = dst_top[x + 3] - dst_top[x + 2] + d3*d3; - - dst[x ] += dst[x - 1]; - dst[x + 1] += dst[x ]; - dst[x + 2] += dst[x + 1]; - dst[x + 3] += dst[x + 2]; - } - s1 += linesize1; - s2 += linesize2; - dst += dst_linesize_32; - dst_top += dst_linesize_32; - } -} - /** * Compute squared difference of an unsafe area (the zone nor s1 nor s2 could * be readable). @@ -326,59 +285,6 @@ struct thread_data { int p; }; -static void compute_weights_line_c(const uint32_t *const iia, - const uint32_t *const iib, - const uint32_t *const iid, - const uint32_t *const iie, - const uint8_t *const src, - float *total_weight, - float *sum, - const float *const weight_lut, - int max_meaningful_diff, - int startx, int endx) -{ - for (int x = startx; x < endx; x++) { - /* - * M is a discrete map where every entry contains the sum of all the entries - * in the rectangle from the top-left origin of M to its coordinate. In the - * following schema, "i" contains the sum of the whole map: - * - * M = +----------+-----------------+----+ - * | | | | - * | | | | - * | a| b| c| - * +----------+-----------------+----+ - * | | | | - * | | | | - * | | X | | - * | | | | - * | d| e| f| - * +----------+-----------------+----+ - * | | | | - * | g| h| i| - * +----------+-----------------+----+ - * - * The sum of the X box can be calculated with: - * X = e-d-b+a - * - * See https://en.wikipedia.org/wiki/Summed_area_table - * - * The compute*_ssd functions compute the integral image M where every entry - * contains the sum of the squared difference of every corresponding pixels of - * two input planes of the same size as M. - */ - const uint32_t a = iia[x]; - const uint32_t b = iib[x]; - const uint32_t d = iid[x]; - const uint32_t e = iie[x]; - const uint32_t patch_diff_sq = FFMIN(e - d - b + a, max_meaningful_diff); - const float weight = weight_lut[patch_diff_sq]; // exp(-patch_diff_sq * s->pdiff_scale) - - total_weight[x] += weight; - sum[x] += weight * src[x]; - } -} - static int nlmeans_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) { NLMeansContext *s = ctx->priv; @@ -512,18 +418,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) } \ } while (0) -void ff_nlmeans_init(NLMeansDSPContext *dsp) -{ - dsp->compute_safe_ssd_integral_image = compute_safe_ssd_integral_image_c; - dsp->compute_weights_line = compute_weights_line_c; - - if (ARCH_AARCH64) - ff_nlmeans_init_aarch64(dsp); - - if (ARCH_X86) - ff_nlmeans_init_x86(dsp); -} - static av_cold int init(AVFilterContext *ctx) { NLMeansContext *s = ctx->priv; diff --git a/libavfilter/vf_nlmeans.h b/libavfilter/vf_nlmeans.h index 43611a03bd..61377f8c69 100644 --- a/libavfilter/vf_nlmeans.h +++ b/libavfilter/vf_nlmeans.h @@ -39,7 +39,6 @@ typedef struct NLMeansDSPContext { int startx, int endx); } NLMeansDSPContext; -void ff_nlmeans_init(NLMeansDSPContext *dsp); void ff_nlmeans_init_aarch64(NLMeansDSPContext *dsp); void ff_nlmeans_init_x86(NLMeansDSPContext *dsp); diff --git a/libavfilter/vf_nlmeans_init.h b/libavfilter/vf_nlmeans_init.h new file mode 100644 index 0000000000..04ad8801b6 --- /dev/null +++ b/libavfilter/vf_nlmeans_init.h @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2016 Clément Bœsch <u pkh me> + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVFILTER_NLMEANS_INIT_H +#define AVFILTER_NLMEANS_INIT_H + +#include <stddef.h> +#include <stdint.h> + +#include "config.h" +#include "libavutil/avassert.h" +#include "libavutil/macros.h" +#include "vf_nlmeans.h" + +/** + * Compute squared difference of the safe area (the zone where s1 and s2 + * overlap). It is likely the largest integral zone, so it is interesting to do + * as little checks as possible; contrary to the unsafe version of this + * function, we do not need any clipping here. + * + * The line above dst and the column to its left are always readable. + */ +static void compute_safe_ssd_integral_image_c(uint32_t *dst, ptrdiff_t dst_linesize_32, + const uint8_t *s1, ptrdiff_t linesize1, + const uint8_t *s2, ptrdiff_t linesize2, + int w, int h) +{ + const uint32_t *dst_top = dst - dst_linesize_32; + + /* SIMD-friendly assumptions allowed here */ + av_assert2(!(w & 0xf) && w >= 16 && h >= 1); + + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x += 4) { + const int d0 = s1[x ] - s2[x ]; + const int d1 = s1[x + 1] - s2[x + 1]; + const int d2 = s1[x + 2] - s2[x + 2]; + const int d3 = s1[x + 3] - s2[x + 3]; + + dst[x ] = dst_top[x ] - dst_top[x - 1] + d0*d0; + dst[x + 1] = dst_top[x + 1] - dst_top[x ] + d1*d1; + dst[x + 2] = dst_top[x + 2] - dst_top[x + 1] + d2*d2; + dst[x + 3] = dst_top[x + 3] - dst_top[x + 2] + d3*d3; + + dst[x ] += dst[x - 1]; + dst[x + 1] += dst[x ]; + dst[x + 2] += dst[x + 1]; + dst[x + 3] += dst[x + 2]; + } + s1 += linesize1; + s2 += linesize2; + dst += dst_linesize_32; + dst_top += dst_linesize_32; + } +} + +static void compute_weights_line_c(const uint32_t *const iia, + const uint32_t *const iib, + const uint32_t *const iid, + const uint32_t *const iie, + const uint8_t *const src, + float *total_weight, + float *sum, + const float *const weight_lut, + int max_meaningful_diff, + int startx, int endx) +{ + for (int x = startx; x < endx; x++) { + /* + * M is a discrete map where every entry contains the sum of all the entries + * in the rectangle from the top-left origin of M to its coordinate. In the + * following schema, "i" contains the sum of the whole map: + * + * M = +----------+-----------------+----+ + * | | | | + * | | | | + * | a| b| c| + * +----------+-----------------+----+ + * | | | | + * | | | | + * | | X | | + * | | | | + * | d| e| f| + * +----------+-----------------+----+ + * | | | | + * | g| h| i| + * +----------+-----------------+----+ + * + * The sum of the X box can be calculated with: + * X = e-d-b+a + * + * See https://en.wikipedia.org/wiki/Summed_area_table + * + * The compute*_ssd functions compute the integral image M where every entry + * contains the sum of the squared difference of every corresponding pixels of + * two input planes of the same size as M. + */ + const uint32_t a = iia[x]; + const uint32_t b = iib[x]; + const uint32_t d = iid[x]; + const uint32_t e = iie[x]; + const uint32_t patch_diff_sq = FFMIN(e - d - b + a, max_meaningful_diff); + const float weight = weight_lut[patch_diff_sq]; // exp(-patch_diff_sq * s->pdiff_scale) + + total_weight[x] += weight; + sum[x] += weight * src[x]; + } +} + +static av_unused void ff_nlmeans_init(NLMeansDSPContext *dsp) +{ + dsp->compute_safe_ssd_integral_image = compute_safe_ssd_integral_image_c; + dsp->compute_weights_line = compute_weights_line_c; + + if (ARCH_AARCH64) + ff_nlmeans_init_aarch64(dsp); + + if (ARCH_X86) + ff_nlmeans_init_x86(dsp); +} + +#endif /* AVFILTER_NLMEANS_INIT_H */ diff --git a/tests/checkasm/vf_nlmeans.c b/tests/checkasm/vf_nlmeans.c index 87474d6803..0f1f9fd403 100644 --- a/tests/checkasm/vf_nlmeans.c +++ b/tests/checkasm/vf_nlmeans.c @@ -19,7 +19,7 @@ */ #include "checkasm.h" -#include "libavfilter/vf_nlmeans.h" +#include "libavfilter/vf_nlmeans_init.h" #include "libavutil/avassert.h" #define randomize_buffer(buf, size) do { \ -- 2.32.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".
next prev parent reply other threads:[~2022-05-03 6:39 UTC|newest] Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-05-03 6:18 [FFmpeg-devel] [PATCH 01/10] avfilter/af_afir: Only keep DSP stuff in header Andreas Rheinhardt 2022-05-03 6:37 ` [FFmpeg-devel] [PATCH 02/10] avfilter/af_afir: Move ff_afir_init() to header Andreas Rheinhardt 2022-05-03 6:37 ` [FFmpeg-devel] [PATCH 03/10] avfilter/vf_blend: Move ff_blend_init into a header Andreas Rheinhardt 2022-05-03 6:37 ` [FFmpeg-devel] [PATCH 04/10] avfilter/vf_eq: Move ff_nlmeans_init " Andreas Rheinhardt 2022-05-03 6:37 ` [FFmpeg-devel] [PATCH 05/10] avfilter/vf_gblur: Move ff_gblur_init " Andreas Rheinhardt 2022-05-03 6:37 ` [FFmpeg-devel] [PATCH 06/10] avfilter/vf_hflip: Move ff_hflip_init " Andreas Rheinhardt 2022-05-03 6:37 ` Andreas Rheinhardt [this message] 2022-05-13 6:28 ` [FFmpeg-devel] [PATCH 07/10] avfilter/vf_nlmeans: Move ff_nlmeans_init " Soft Works 2022-05-13 8:27 ` Andreas Rheinhardt 2022-05-13 9:00 ` Hendrik Leppkes 2022-05-13 9:03 ` Soft Works 2022-05-13 9:01 ` Soft Works 2022-05-13 9:13 ` Hendrik Leppkes 2022-05-13 9:25 ` Andreas Rheinhardt 2022-05-13 9:27 ` Hendrik Leppkes 2022-05-13 9:34 ` Soft Works 2022-05-13 9:32 ` Soft Works 2022-05-03 6:37 ` [FFmpeg-devel] [PATCH 08/10] avfilter/vf_threshold: Move ff_threshold_init " Andreas Rheinhardt 2022-05-03 6:37 ` [FFmpeg-devel] [PATCH 09/10] avcodec/v210_dec: Move ff_v210dec_init " Andreas Rheinhardt 2022-05-03 6:37 ` [FFmpeg-devel] [PATCH 10/10] avcodec/v210_enc: Move ff_v210enc_init " Andreas Rheinhardt 2022-05-05 1:55 ` [FFmpeg-devel] [PATCH 01/10] avfilter/af_afir: Only keep DSP stuff in header Andreas Rheinhardt
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=AS8PR01MB79444DB5BC9AE98E12E417C58FC09@AS8PR01MB7944.eurprd01.prod.exchangelabs.com \ --to=andreas.rheinhardt@outlook.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git