FFmpeg
vf_gblur.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #include <float.h>
20 #include <string.h>
21 #include "checkasm.h"
22 #include "libavutil/mem.h"
24 
25 #define WIDTH 256
26 #define HEIGHT 256
27 #define PIXELS (WIDTH * HEIGHT)
28 #define BUF_SIZE (PIXELS * 4)
29 
30 #define randomize_buffers(buf, size) \
31  do { \
32  int j; \
33  float *tmp_buf = (float *)buf; \
34  for (j = 0; j < size; j++) \
35  tmp_buf[j] = (float)(rnd() & 0xFF); \
36  } while (0)
37 
38 static void check_horiz_slice(float *dst_ref, float *dst_new, float *localbuf)
39 {
40  int steps = 2;
41  float nu = 0.101f;
42  float bscale = 1.112f;
43 
44  declare_func(void, float *dst, int w, int h, int steps, float nu, float bscale, float *localbuf);
45  call_ref(dst_ref, WIDTH, HEIGHT, steps, nu, bscale, localbuf);
46  call_new(dst_new, WIDTH, HEIGHT, steps, nu, bscale, localbuf);
47  if (!float_near_abs_eps_array(dst_ref, dst_new, 0.01f, PIXELS)) {
48  fail();
49  }
50  bench_new(dst_new, WIDTH, HEIGHT, 1, nu, bscale, localbuf);
51 }
52 
53 static void check_verti_slice(float *dst_ref, float *dst_new)
54 {
55  int steps = 2;
56  float nu = 0.101f;
57  float bscale = 1.112f;
58 
59  declare_func(void, float *buffer, int width, int height, int column_begin,
60  int column_end, int steps, float nu, float bscale);
61  call_ref(dst_ref, WIDTH, HEIGHT, 0, WIDTH, steps, nu, bscale);
62  call_new(dst_new, WIDTH, HEIGHT, 0, WIDTH, steps, nu, bscale);
63  if (!float_near_abs_eps_array(dst_ref, dst_new, 0.01f, PIXELS)) {
64  fail();
65  }
66  bench_new(dst_new, WIDTH, HEIGHT, 0, WIDTH, 1, nu, bscale);
67 }
68 
69 static void check_postscale_slice(float *dst_ref, float *dst_new)
70 {
71  float postscale = 0.0603f;
72 
73  declare_func(void, float *dst, int len, float postscale, float min, float max);
74  call_ref(dst_ref, PIXELS, postscale, -FLT_MAX, FLT_MAX);
75  call_new(dst_new, PIXELS, postscale, -FLT_MAX, FLT_MAX);
76  if (!float_near_abs_eps_array(dst_ref, dst_new, FLT_EPSILON, PIXELS)) {
77  fail();
78  }
79  bench_new(dst_new, PIXELS, postscale, -FLT_MAX, FLT_MAX);
80 }
81 
83 {
84  float *dst_ref = av_malloc(BUF_SIZE);
85  float *dst_new = av_malloc(BUF_SIZE);
87 
88  randomize_buffers(dst_ref, PIXELS);
89  memcpy(dst_new, dst_ref, BUF_SIZE);
90 
91  s.planewidth[0] = WIDTH;
92  s.planeheight[0] = HEIGHT;
93  ff_gblur_init(&s);
94 
95  if (check_func(s.horiz_slice, "horiz_slice")) {
96  check_horiz_slice(dst_ref, dst_new, s.localbuf);
97  }
98  report("horiz_slice");
99 
100  randomize_buffers(dst_ref, PIXELS);
101  memcpy(dst_new, dst_ref, BUF_SIZE);
102  if (check_func(s.postscale_slice, "postscale_slice")) {
103  check_postscale_slice(dst_ref, dst_new);
104  }
105  report("postscale_slice");
106 
107  randomize_buffers(dst_ref, PIXELS);
108  memcpy(dst_new, dst_ref, BUF_SIZE);
109  if (check_func(s.verti_slice, "verti_slice")) {
110  check_verti_slice(dst_ref, dst_new);
111  }
112  report("verti_slice");
113 
114  if (s.localbuf)
115  av_free(s.localbuf);
116 
117  av_freep(&dst_ref);
118  av_freep(&dst_new);
119 }
float_near_abs_eps_array
int float_near_abs_eps_array(const float *a, const float *b, float eps, unsigned len)
Definition: checkasm.c:399
w
uint8_t w
Definition: llviddspenc.c:38
check_func
#define check_func(func,...)
Definition: checkasm.h:170
float.h
max
#define max(a, b)
Definition: cuda_runtime.h:33
call_ref
#define call_ref(...)
Definition: checkasm.h:185
WIDTH
#define WIDTH
Definition: vf_gblur.c:25
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
fail
#define fail()
Definition: checkasm.h:179
checkasm.h
width
#define width
s
#define s(width, name)
Definition: cbs_vp9.c:198
checkasm_check_vf_gblur
void checkasm_check_vf_gblur(void)
Definition: vf_gblur.c:82
BUF_SIZE
#define BUF_SIZE
Definition: vf_gblur.c:28
call_new
#define call_new(...)
Definition: checkasm.h:288
vf_gblur_init.h
randomize_buffers
#define randomize_buffers(buf, size)
Definition: vf_gblur.c:30
check_postscale_slice
static void check_postscale_slice(float *dst_ref, float *dst_new)
Definition: vf_gblur.c:69
check_verti_slice
static void check_verti_slice(float *dst_ref, float *dst_new)
Definition: vf_gblur.c:53
postscale
static const FLOAT postscale[64]
Definition: faandct.c:55
f
f
Definition: af_crystalizer.c:121
height
#define height
HEIGHT
#define HEIGHT
Definition: vf_gblur.c:26
PIXELS
#define PIXELS
Definition: vf_gblur.c:27
report
#define report
Definition: checkasm.h:182
bench_new
#define bench_new(...)
Definition: checkasm.h:358
len
int len
Definition: vorbis_enc_data.h:426
ff_gblur_init
static av_unused void ff_gblur_init(GBlurContext *s)
Definition: vf_gblur_init.h:112
steps
static const int16_t steps[16]
Definition: misc4.c:30
check_horiz_slice
static void check_horiz_slice(float *dst_ref, float *dst_new, float *localbuf)
Definition: vf_gblur.c:38
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
mem.h
declare_func
#define declare_func(ret,...)
Definition: checkasm.h:174
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
GBlurContext
Definition: gblur.h:32
h
h
Definition: vp9dsp_template.c:2038
min
float min
Definition: vorbis_enc_data.h:429