FFmpeg  4.3
vf_nlmeans.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Clément Bœsch <u pkh me>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "checkasm.h"
22 #include "libavfilter/vf_nlmeans.h"
23 #include "libavutil/avassert.h"
24 
25 #define randomize_buffer(buf, size) do { \
26  int i; \
27  for (i = 0; i < size / 4; i++) \
28  ((uint32_t *)buf)[i] = rnd(); \
29 } while (0)
30 
32 {
33  NLMeansDSPContext dsp = {0};
34 
35  const int w = 123; // source width
36  const int h = 45; // source height
37  const int p = 3; // patch half size
38  const int r = 2; // research window half size
39 
40  ff_nlmeans_init(&dsp);
41 
42  /* See the filter's code for the explanations on the variables */
43  if (check_func(dsp.compute_safe_ssd_integral_image, "ssd_integral_image")) {
44  int offx, offy;
45  const int e = p + r;
46  const int ii_w = w + e*2;
47  const int ii_h = h + e*2;
48  const int ii_lz_32 = FFALIGN(ii_w + 1, 4);
49  uint32_t *ii_orig_ref = av_mallocz_array(ii_h + 1, ii_lz_32 * sizeof(*ii_orig_ref));
50  uint32_t *ii_ref = ii_orig_ref + ii_lz_32 + 1;
51  uint32_t *ii_orig_new = av_mallocz_array(ii_h + 1, ii_lz_32 * sizeof(*ii_orig_new));
52  uint32_t *ii_new = ii_orig_new + ii_lz_32 + 1;
53  const int src_lz = FFALIGN(w, 16);
54  uint8_t *src = av_mallocz_array(h, src_lz);
55 
56  declare_func(void, uint32_t *dst, ptrdiff_t dst_linesize_32,
57  const uint8_t *s1, ptrdiff_t linesize1,
58  const uint8_t *s2, ptrdiff_t linesize2,
59  int w, int h);
60 
61  randomize_buffer(src, h * src_lz);
62 
63  for (offy = -r; offy <= r; offy++) {
64  for (offx = -r; offx <= r; offx++) {
65  if (offx || offy) {
66  const int s1x = e;
67  const int s1y = e;
68  const int s2x = e + offx;
69  const int s2y = e + offy;
70  const int startx_safe = FFMAX(s1x, s2x);
71  const int starty_safe = FFMAX(s1y, s2y);
72  const int u_endx_safe = FFMIN(s1x + w, s2x + w);
73  const int endy_safe = FFMIN(s1y + h, s2y + h);
74  const int safe_pw = (u_endx_safe - startx_safe) & ~0xf;
75  const int safe_ph = endy_safe - starty_safe;
76 
77  av_assert0(safe_pw && safe_ph);
78  av_assert0(startx_safe - s1x >= 0); av_assert0(startx_safe - s1x < w);
79  av_assert0(starty_safe - s1y >= 0); av_assert0(starty_safe - s1y < h);
80  av_assert0(startx_safe - s2x >= 0); av_assert0(startx_safe - s2x < w);
81  av_assert0(starty_safe - s2y >= 0); av_assert0(starty_safe - s2y < h);
82 
83  memset(ii_ref, 0, (ii_lz_32 * ii_h - 1) * sizeof(*ii_ref));
84  memset(ii_new, 0, (ii_lz_32 * ii_h - 1) * sizeof(*ii_new));
85 
86  call_ref(ii_ref + starty_safe*ii_lz_32 + startx_safe, ii_lz_32,
87  src + (starty_safe - s1y) * src_lz + (startx_safe - s1x), src_lz,
88  src + (starty_safe - s2y) * src_lz + (startx_safe - s2x), src_lz,
89  safe_pw, safe_ph);
90  call_new(ii_new + starty_safe*ii_lz_32 + startx_safe, ii_lz_32,
91  src + (starty_safe - s1y) * src_lz + (startx_safe - s1x), src_lz,
92  src + (starty_safe - s2y) * src_lz + (startx_safe - s2x), src_lz,
93  safe_pw, safe_ph);
94 
95  if (memcmp(ii_ref, ii_new, (ii_lz_32 * ii_h - 1) * sizeof(*ii_ref)))
96  fail();
97 
98  memset(ii_new, 0, (ii_lz_32 * ii_h - 1) * sizeof(*ii_new));
99  bench_new(ii_new + starty_safe*ii_lz_32 + startx_safe, ii_lz_32,
100  src + (starty_safe - s1y) * src_lz + (startx_safe - s1x), src_lz,
101  src + (starty_safe - s2y) * src_lz + (startx_safe - s2x), src_lz,
102  safe_pw, safe_ph);
103  }
104  }
105  }
106 
107  av_freep(&ii_orig_ref);
108  av_freep(&ii_orig_new);
109  av_freep(&src);
110  }
111 
112  report("dsp");
113 }
check_func
#define check_func(func,...)
Definition: checkasm.h:114
av_mallocz_array
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().
Definition: mem.c:192
call_ref
#define call_ref(...)
Definition: checkasm.h:129
NLMeansDSPContext
Definition: vf_nlmeans.h:25
fail
#define fail()
Definition: checkasm.h:123
checkasm.h
NLMeansDSPContext::compute_safe_ssd_integral_image
void(* compute_safe_ssd_integral_image)(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)
Definition: vf_nlmeans.h:26
avassert.h
s1
#define s1
Definition: regdef.h:38
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
call_new
#define call_new(...)
Definition: checkasm.h:201
src
#define src
Definition: vp8dsp.c:254
s2
#define s2
Definition: regdef.h:39
vf_nlmeans.h
FFMAX
#define FFMAX(a, b)
Definition: common.h:94
FFMIN
#define FFMIN(a, b)
Definition: common.h:96
randomize_buffer
#define randomize_buffer(buf, size)
Definition: vf_nlmeans.c:25
r
#define r
Definition: input.c:40
report
#define report
Definition: checkasm.h:126
bench_new
#define bench_new(...)
Definition: checkasm.h:261
xf
#define xf(width, name, var, range_min, range_max, subs,...)
Definition: cbs_av1.c:667
uint8_t
uint8_t
Definition: audio_convert.c:194
checkasm_check_nlmeans
void checkasm_check_nlmeans(void)
Definition: vf_nlmeans.c:31
w
FFmpeg Automated Testing Environment ************************************Introduction Using FATE from your FFmpeg source directory Submitting the results to the FFmpeg result aggregation server Uploading new samples to the fate suite FATE makefile targets and variables Makefile targets Makefile variables Examples Introduction **************FATE is an extended regression suite on the client side and a means for results aggregation and presentation on the server side The first part of this document explains how you can use FATE from your FFmpeg source directory to test your ffmpeg binary The second part describes how you can run FATE to submit the results to FFmpeg’s FATE server In any way you can have a look at the publicly viewable FATE results by visiting this as it can be seen if some test on some platform broke with their recent contribution This usually happens on the platforms the developers could not test on The second part of this document describes how you can run FATE to submit your results to FFmpeg’s FATE server If you want to submit your results be sure to check that your combination of OS and compiler is not already listed on the above mentioned website In the third part you can find a comprehensive listing of FATE makefile targets and variables Using FATE from your FFmpeg source directory **********************************************If you want to run FATE on your machine you need to have the samples in place You can get the samples via the build target fate rsync Use this command from the top level source this will cause FATE to fail NOTE To use a custom wrapper to run the pass ‘ target exec’ to ‘configure’ or set the TARGET_EXEC Make variable Submitting the results to the FFmpeg result aggregation server ****************************************************************To submit your results to the server you should run fate through the shell script ‘tests fate sh’ from the FFmpeg sources This script needs to be invoked with a configuration file as its first argument tests fate sh path to fate_config A configuration file template with comments describing the individual configuration variables can be found at ‘doc fate_config sh template’ Create a configuration that suits your based on the configuration template The ‘slot’ configuration variable can be any string that is not yet but it is suggested that you name it adhering to the following pattern ‘ARCH OS COMPILER COMPILER VERSION’ The configuration file itself will be sourced in a shell therefore all shell features may be used This enables you to setup the environment as you need it for your build For your first test runs the ‘fate_recv’ variable should be empty or commented out This will run everything as normal except that it will omit the submission of the results to the server The following files should be present in $workdir as specified in the configuration it may help to try out the ‘ssh’ command with one or more ‘ v’ options You should get detailed output concerning your SSH configuration and the authentication process The only thing left is to automate the execution of the fate sh script and the synchronisation of the samples directory Uploading new samples to the fate suite *****************************************If you need a sample uploaded send a mail to samples request This is for developers who have an account on the fate suite server If you upload new please make sure they are as small as space on each network bandwidth and so on benefit from smaller test cases Also keep in mind older checkouts use existing sample that means in practice generally do not remove or overwrite files as it likely would break older checkouts or releases Also all needed samples for a commit should be ideally before the push If you need an account for frequently uploading samples or you wish to help others by doing that send a mail to ffmpeg devel rsync vauL Duo ug o o w
Definition: fate.txt:150
declare_func
#define declare_func(ret,...)
Definition: checkasm.h:118
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:48
ff_nlmeans_init
void ff_nlmeans_init(NLMeansDSPContext *dsp)
Definition: vf_nlmeans.c:509
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
h
h
Definition: vp9dsp_template.c:2038
thread_data::p
int p
Definition: vf_nlmeans.c:340