FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/edge_common.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 44 44 100.0%
Functions: 3 3 100.0%
Branches: 72 73 98.6%

Line Branch Exec Source
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (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 GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "edge_common.h"
20
21 // Internal helper for ff_sobel()
22 31246752 static int get_rounded_direction(int gx, int gy)
23 {
24 /* reference angles:
25 * tan( pi/8) = sqrt(2)-1
26 * tan(3pi/8) = sqrt(2)+1
27 * Gy/Gx is the tangent of the angle (theta), so Gy/Gx is compared against
28 * <ref-angle>, or more simply Gy against <ref-angle>*Gx
29 *
30 * Gx and Gy bounds = [-1020;1020], using 16-bit arithmetic:
31 * round((sqrt(2)-1) * (1<<16)) = 27146
32 * round((sqrt(2)+1) * (1<<16)) = 158218
33 */
34
2/2
✓ Branch 0 taken 17738232 times.
✓ Branch 1 taken 13508520 times.
31246752 if (gx) {
35 int tanpi8gx, tan3pi8gx;
36
37
2/2
✓ Branch 0 taken 7363947 times.
✓ Branch 1 taken 10374285 times.
17738232 if (gx < 0)
38 7363947 gx = -gx, gy = -gy;
39 17738232 gy *= (1 << 16);
40 17738232 tanpi8gx = 27146 * gx;
41 17738232 tan3pi8gx = 158218 * gx;
42
4/4
✓ Branch 0 taken 15268125 times.
✓ Branch 1 taken 2470107 times.
✓ Branch 2 taken 3011029 times.
✓ Branch 3 taken 12257096 times.
17738232 if (gy > -tan3pi8gx && gy < -tanpi8gx) return DIRECTION_45UP;
43
4/4
✓ Branch 0 taken 12257096 times.
✓ Branch 1 taken 2470107 times.
✓ Branch 2 taken 4386962 times.
✓ Branch 3 taken 7870134 times.
14727203 if (gy > -tanpi8gx && gy < tanpi8gx) return DIRECTION_HORIZONTAL;
44
4/4
✓ Branch 0 taken 7870134 times.
✓ Branch 1 taken 2470107 times.
✓ Branch 2 taken 5230506 times.
✓ Branch 3 taken 2639628 times.
10340241 if (gy > tanpi8gx && gy < tan3pi8gx) return DIRECTION_45DOWN;
45 }
46 18618255 return DIRECTION_VERTICAL;
47 }
48
49 #undef DEPTH
50 #define DEPTH 8
51 #include "edge_template.c"
52
53 #undef DEPTH
54 #define DEPTH 16
55 #include "edge_template.c"
56
57 // Filters rounded gradients to drop all non-maxima
58 // Expects gradients generated by ff_sobel()
59 // Expects zero's destination buffer
60 99 void ff_non_maximum_suppression(int w, int h,
61 uint8_t *dst, int dst_linesize,
62 const int8_t *dir, int dir_linesize,
63 const uint16_t *src, int src_linesize)
64 {
65 int i, j;
66
67 #define COPY_MAXIMA(ay, ax, by, bx) do { \
68 if (src[i] > src[(ay)*src_linesize + i+(ax)] && \
69 src[i] > src[(by)*src_linesize + i+(bx)]) \
70 dst[i] = av_clip_uint8(src[i]); \
71 } while (0)
72
73
2/2
✓ Branch 0 taken 45962 times.
✓ Branch 1 taken 99 times.
46061 for (j = 1; j < h - 1; j++) {
74 45962 dst += dst_linesize;
75 45962 dir += dir_linesize;
76 45962 src += src_linesize;
77
2/2
✓ Branch 0 taken 31246752 times.
✓ Branch 1 taken 45962 times.
31292714 for (i = 1; i < w - 1; i++) {
78
4/5
✓ Branch 0 taken 3011029 times.
✓ Branch 1 taken 5230506 times.
✓ Branch 2 taken 4386962 times.
✓ Branch 3 taken 18618255 times.
✗ Branch 4 not taken.
31246752 switch (dir[i]) {
79
4/4
✓ Branch 0 taken 1557942 times.
✓ Branch 1 taken 1453087 times.
✓ Branch 2 taken 745685 times.
✓ Branch 3 taken 812257 times.
3011029 case DIRECTION_45UP: COPY_MAXIMA( 1, -1, -1, 1); break;
80
4/4
✓ Branch 0 taken 2592554 times.
✓ Branch 1 taken 2637952 times.
✓ Branch 2 taken 1301471 times.
✓ Branch 3 taken 1291083 times.
5230506 case DIRECTION_45DOWN: COPY_MAXIMA(-1, -1, 1, 1); break;
81
4/4
✓ Branch 0 taken 2017349 times.
✓ Branch 1 taken 2369613 times.
✓ Branch 2 taken 640234 times.
✓ Branch 3 taken 1377115 times.
4386962 case DIRECTION_HORIZONTAL: COPY_MAXIMA( 0, -1, 0, 1); break;
82
4/4
✓ Branch 0 taken 3618621 times.
✓ Branch 1 taken 14999634 times.
✓ Branch 2 taken 1061397 times.
✓ Branch 3 taken 2557224 times.
18618255 case DIRECTION_VERTICAL: COPY_MAXIMA(-1, 0, 1, 0); break;
83 }
84 }
85 }
86 99 }
87
88 // Filter to keep all pixels > high, and keep all pixels > low where all surrounding pixels > high
89 99 void ff_double_threshold(int low, int high, int w, int h,
90 uint8_t *dst, int dst_linesize,
91 const uint8_t *src, int src_linesize)
92 {
93 int i, j;
94
95
2/2
✓ Branch 0 taken 46160 times.
✓ Branch 1 taken 99 times.
46259 for (j = 0; j < h; j++) {
96
2/2
✓ Branch 0 taken 31428320 times.
✓ Branch 1 taken 46160 times.
31474480 for (i = 0; i < w; i++) {
97
2/2
✓ Branch 0 taken 2609150 times.
✓ Branch 1 taken 28819170 times.
31428320 if (src[i] > high) {
98 2609150 dst[i] = src[i];
99 2609150 continue;
100 }
101
102
8/8
✓ Branch 0 taken 28773010 times.
✓ Branch 1 taken 46160 times.
✓ Branch 2 taken 28726850 times.
✓ Branch 3 taken 46160 times.
✓ Branch 4 taken 28682226 times.
✓ Branch 5 taken 44624 times.
✓ Branch 6 taken 28637602 times.
✓ Branch 7 taken 44624 times.
28819170 if (!(!i || i == w - 1 || !j || j == h - 1) &&
103
2/2
✓ Branch 0 taken 455708 times.
✓ Branch 1 taken 28181894 times.
28637602 src[i] > low &&
104
2/2
✓ Branch 0 taken 446341 times.
✓ Branch 1 taken 9367 times.
455708 (src[-src_linesize + i-1] > high ||
105
2/2
✓ Branch 0 taken 437187 times.
✓ Branch 1 taken 9154 times.
446341 src[-src_linesize + i ] > high ||
106
2/2
✓ Branch 0 taken 431132 times.
✓ Branch 1 taken 6055 times.
437187 src[-src_linesize + i+1] > high ||
107
2/2
✓ Branch 0 taken 422756 times.
✓ Branch 1 taken 8376 times.
431132 src[ i-1] > high ||
108
2/2
✓ Branch 0 taken 415784 times.
✓ Branch 1 taken 6972 times.
422756 src[ i+1] > high ||
109
2/2
✓ Branch 0 taken 410540 times.
✓ Branch 1 taken 5244 times.
415784 src[ src_linesize + i-1] > high ||
110
2/2
✓ Branch 0 taken 403711 times.
✓ Branch 1 taken 6829 times.
410540 src[ src_linesize + i ] > high ||
111
2/2
✓ Branch 0 taken 5741 times.
✓ Branch 1 taken 397970 times.
403711 src[ src_linesize + i+1] > high))
112 57738 dst[i] = src[i];
113 else
114 28761432 dst[i] = 0;
115 }
116 46160 dst += dst_linesize;
117 46160 src += src_linesize;
118 }
119 99 }
120