FFmpeg coverage


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