FFmpeg
vf_convolution.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 <string.h>
20 #include "checkasm.h"
21 #include "libavfilter/avfilter.h"
23 #include "libavutil/intreadwrite.h"
24 #include "libavutil/mem_internal.h"
25 
26 #define WIDTH 512
27 #define HEIGHT 512
28 #define SRC_STRIDE 512
29 #define PIXELS (WIDTH * HEIGHT)
30 
31 #define randomize_buffers(buf, size) \
32  do { \
33  int j; \
34  uint8_t *tmp_buf = (uint8_t *)buf;\
35  for (j = 0; j< size; j++) \
36  tmp_buf[j] = rnd() & 0xFF; \
37  } while (0)
38 
39 static void check_sobel(const char * report_name)
40 {
41  LOCAL_ALIGNED_32(uint8_t, src, [PIXELS]);
42  LOCAL_ALIGNED_32(uint8_t, dst_ref, [PIXELS]);
43  LOCAL_ALIGNED_32(uint8_t, dst_new, [PIXELS]);
44  const int height = WIDTH;
45  const int width = HEIGHT;
46  const int stride = SRC_STRIDE;
47  const int dstride = SRC_STRIDE;
48  int mode = 0;
49  const uint8_t *c[49];
50  const int radius = 1;
51  const int bpc = 1;
52  const int step = mode == MATRIX_COLUMN ? 16 : 1;
53  const int slice_start = 0;
54  const int slice_end = height;
55  int y;
56  const int sizew = mode == MATRIX_COLUMN ? height : width;
57  float scale = 2;
58  float delta = 10;
59 
61 
62  declare_func(void, uint8_t *dst, int width, float scale, float delta, const int *const matrix,
63  const uint8_t *c[], int peak, int radius, int dstride, int stride, int size);
64 
65  s.scale = scale;
66  s.delta = delta;
67  s.depth = 8;
68  s.nb_planes = 3;
69  s.planes = 15;
70  ff_sobel_init(&s, s.depth, s.nb_planes);
71 
72  memset(dst_ref, 0, PIXELS);
73  memset(dst_new, 0, PIXELS);
75 
76  if (check_func(s.filter[0], "%s", report_name)) {
77  for (y = slice_start; y < slice_end; y += step) {
78  const int xoff = mode == MATRIX_COLUMN ? (y - slice_start) * bpc : radius * bpc;
79  const int yoff = mode == MATRIX_COLUMN ? radius * dstride : 0;
80 
81  s.setup[0](radius, c, src, stride, radius, width, y, height, bpc);
82  call_ref(dst_ref + yoff + xoff, sizew - 2 * radius,
83  scale, delta, NULL, c, 0, radius,
84  dstride, stride, slice_end - step);
85  call_new(dst_new + yoff + xoff, sizew - 2 * radius,
86  scale, delta, NULL, c, 0, radius,
87  dstride, stride, slice_end - step);
88  if (memcmp(dst_ref + yoff + xoff, dst_new + yoff + xoff, slice_end - step))
89  fail();
90  bench_new(dst_new + yoff + xoff, sizew - 2 * radius,
91  scale, delta, NULL, c, 0, radius,
92  dstride, stride, slice_end - step);
93  if (mode != MATRIX_COLUMN)
94  dst_ref += dstride;
95  }
96  }
97 
98 }
99 
101 {
102  check_sobel("sobel");
103  report("convolution:sobel");
104 }
mem_internal.h
matrix
Definition: vc1dsp.c:42
step
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
Definition: rate_distortion.txt:58
check_func
#define check_func(func,...)
Definition: checkasm.h:170
PIXELS
#define PIXELS
Definition: vf_convolution.c:29
call_ref
#define call_ref(...)
Definition: checkasm.h:185
ff_sobel_init
static av_unused void ff_sobel_init(ConvolutionContext *s, int depth, int nb_planes)
Definition: convolution.h:122
convolution.h
HEIGHT
#define HEIGHT
Definition: vf_convolution.c:27
fail
#define fail()
Definition: checkasm.h:179
checkasm.h
slice_start
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)
Definition: vvcdec.c:694
width
#define width
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:198
WIDTH
#define WIDTH
Definition: vf_convolution.c:26
slice_end
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
Definition: mpeg12dec.c:1725
call_new
#define call_new(...)
Definition: checkasm.h:288
NULL
#define NULL
Definition: coverity.c:32
LOCAL_ALIGNED_32
#define LOCAL_ALIGNED_32(t, v,...)
Definition: mem_internal.h:156
check_sobel
static void check_sobel(const char *report_name)
Definition: vf_convolution.c:39
ConvolutionContext
Definition: convolution.h:33
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: vvc_intra.c:291
size
int size
Definition: twinvq_data.h:10344
height
#define height
report
#define report
Definition: checkasm.h:182
bench_new
#define bench_new(...)
Definition: checkasm.h:358
delta
float delta
Definition: vorbis_enc_data.h:430
checkasm_check_vf_sobel
void checkasm_check_vf_sobel(void)
Definition: vf_convolution.c:100
stride
#define stride
Definition: h264pred_template.c:537
mode
mode
Definition: ebur128.h:83
avfilter.h
MATRIX_COLUMN
@ MATRIX_COLUMN
Definition: convolution.h:29
randomize_buffers
#define randomize_buffers(buf, size)
Definition: vf_convolution.c:31
declare_func
#define declare_func(ret,...)
Definition: checkasm.h:174
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
SRC_STRIDE
#define SRC_STRIDE
Definition: vf_convolution.c:28