FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/edge_template.c
Date: 2024-07-17 14:05:47
Exec Total Coverage
Lines: 59 59 100.0%
Functions: 2 4 50.0%
Branches: 16 16 100.0%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2022 Thilo Borgmann <thilo.borgmann _at_ mail.de>
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 * Redistribution and use in source and binary forms, with or without modification,
20 * are permitted provided that the following conditions are met:
21 */
22
23 #include "libavutil/avassert.h"
24 #include "avfilter.h"
25 #include "internal.h"
26 #include "video.h"
27
28 #undef pixel
29 #if DEPTH == 8
30 #define pixel uint8_t
31 #else
32 #define pixel uint16_t
33 #endif
34
35 #undef fn
36 #undef fn2
37 #undef fn3
38 #define fn3(a,b) ff_##a##_##b
39 #define fn2(a,b) fn3(a,b)
40 #define fn(a) fn2(a, DEPTH)
41
42 198 void fn(sobel)(int w, int h,
43 uint16_t *dst, int dst_linesize,
44 int8_t *dir, int dir_linesize,
45 const uint8_t *src, int src_linesize, int src_stride)
46 {
47 198 pixel *srcp = (pixel *)src;
48
49 198 src_stride /= sizeof(pixel);
50 198 src_linesize /= sizeof(pixel);
51 198 dst_linesize /= sizeof(pixel);
52
53
2/2
✓ Branch 0 taken 45962 times.
✓ Branch 1 taken 99 times.
92122 for (int j = 1; j < h - 1; j++) {
54 91924 dst += dst_linesize;
55 91924 dir += dir_linesize;
56 91924 srcp += src_linesize;
57
2/2
✓ Branch 0 taken 31246752 times.
✓ Branch 1 taken 45962 times.
62585428 for (int i = 1; i < w - 1; i++) {
58 62493504 const int gx =
59 62493504 -1*srcp[-src_linesize + (i-1)*src_stride] + 1*srcp[-src_linesize + (i+1)*src_stride]
60 62493504 -2*srcp[ (i-1)*src_stride] + 2*srcp[ (i+1)*src_stride]
61 62493504 -1*srcp[ src_linesize + (i-1)*src_stride] + 1*srcp[ src_linesize + (i+1)*src_stride];
62 62493504 const int gy =
63 62493504 -1*srcp[-src_linesize + (i-1)*src_stride] + 1*srcp[ src_linesize + (i-1)*src_stride]
64 62493504 -2*srcp[-src_linesize + (i )*src_stride] + 2*srcp[ src_linesize + (i )*src_stride]
65 62493504 -1*srcp[-src_linesize + (i+1)*src_stride] + 1*srcp[ src_linesize + (i+1)*src_stride];
66
67 62493504 dst[i] = FFABS(gx) + FFABS(gy);
68 62493504 dir[i] = get_rounded_direction(gx, gy);
69 }
70 }
71 198 }
72
73 198 void fn(gaussian_blur)(int w, int h,
74 uint8_t *dst, int dst_linesize,
75 const uint8_t *src, int src_linesize, int src_stride)
76 {
77 int j;
78 198 pixel *srcp = (pixel *)src;
79 198 pixel *dstp = (pixel *)dst;
80
81 198 src_stride /= sizeof(pixel);
82 198 src_linesize /= sizeof(pixel);
83 198 dst_linesize /= sizeof(pixel);
84
85
2/2
✓ Branch 0 taken 198 times.
✓ Branch 1 taken 99 times.
594 for (j = 0; j < FFMIN(h, 2); j++) {
86 396 memcpy(dstp, srcp, w*sizeof(pixel));
87 396 dstp += dst_linesize;
88 396 srcp += src_linesize;
89 }
90
91
2/2
✓ Branch 0 taken 45764 times.
✓ Branch 1 taken 99 times.
91726 for (; j < h - 2; j++) {
92 int i;
93
2/2
✓ Branch 0 taken 91528 times.
✓ Branch 1 taken 45764 times.
274584 for (i = 0; i < FFMIN(w, 2); i++)
94 183056 dstp[i] = srcp[i*src_stride];
95
2/2
✓ Branch 0 taken 31065976 times.
✓ Branch 1 taken 45764 times.
62223480 for (; i < w - 2; i++) {
96 /* Gaussian mask of size 5x5 with sigma = 1.4 */
97 62131952 dstp[i] = ((srcp[-2*src_linesize + (i-2)*src_stride] + srcp[2*src_linesize + (i-2)*src_stride]) * 2
98 62131952 + (srcp[-2*src_linesize + (i-1)*src_stride] + srcp[2*src_linesize + (i-1)*src_stride]) * 4
99 62131952 + (srcp[-2*src_linesize + (i )*src_stride] + srcp[2*src_linesize + (i )*src_stride]) * 5
100 62131952 + (srcp[-2*src_linesize + (i+1)*src_stride] + srcp[2*src_linesize + (i+1)*src_stride]) * 4
101 62131952 + (srcp[-2*src_linesize + (i+2)*src_stride] + srcp[2*src_linesize + (i+2)*src_stride]) * 2
102
103 62131952 + (srcp[ -src_linesize + (i-2)*src_stride] + srcp[ src_linesize + (i-2)*src_stride]) * 4
104 62131952 + (srcp[ -src_linesize + (i-1)*src_stride] + srcp[ src_linesize + (i-1)*src_stride]) * 9
105 62131952 + (srcp[ -src_linesize + (i )*src_stride] + srcp[ src_linesize + (i )*src_stride]) * 12
106 62131952 + (srcp[ -src_linesize + (i+1)*src_stride] + srcp[ src_linesize + (i+1)*src_stride]) * 9
107 62131952 + (srcp[ -src_linesize + (i+2)*src_stride] + srcp[ src_linesize + (i+2)*src_stride]) * 4
108
109 62131952 + srcp[(i-2)*src_stride] * 5
110 62131952 + srcp[(i-1)*src_stride] * 12
111 62131952 + srcp[(i )*src_stride] * 15
112 62131952 + srcp[(i+1)*src_stride] * 12
113 62131952 + srcp[(i+2)*src_stride] * 5) / 159;
114 }
115
2/2
✓ Branch 0 taken 91528 times.
✓ Branch 1 taken 45764 times.
274584 for (; i < w; i++)
116 183056 dstp[i] = srcp[i*src_stride];
117
118 91528 dstp += dst_linesize;
119 91528 srcp += src_linesize;
120 }
121
2/2
✓ Branch 0 taken 198 times.
✓ Branch 1 taken 99 times.
594 for (; j < h; j++) {
122 396 memcpy(dstp, srcp, w*sizeof(pixel));
123 396 dstp += dst_linesize;
124 396 srcp += src_linesize;
125 }
126 198 }
127