FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/median_template.c
Date: 2024-07-17 14:05:47
Exec Total Coverage
Lines: 71 71 100.0%
Functions: 1 6 16.7%
Branches: 41 46 89.1%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2019 Paul B Mahol
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 htype
36 #define htype uint16_t
37
38 #undef fn
39 #undef fn2
40 #undef fn3
41 #define SHIFT ((DEPTH + 1) / 2)
42 #define BINS (1 << SHIFT)
43 #define MASK (BINS - 1)
44 #define fn3(a,b) a##_##b
45 #define fn2(a,b) fn3(a,b)
46 #define fn(a) fn2(a, DEPTH)
47
48 #define PICK_COARSE_BIN(x, y) (BINS * (x) + ((y) >> SHIFT))
49 #define PICK_FINE_BIN(x, y, z) (BINS * ((x) * ((y) >> SHIFT) + (z)) + ((y) & MASK))
50
51 30 static void fn(filter_plane)(AVFilterContext *ctx, const uint8_t *ssrc, int src_linesize,
52 uint8_t *ddst, int dst_linesize, int width, int height,
53 int slice_h_start, int slice_h_end, int jobnr)
54 {
55 30 MedianContext *s = ctx->priv;
56 30 htype *ccoarse = s->coarse[jobnr];
57 30 htype *cfine = s->fine[jobnr];
58 30 const int radius = s->radius;
59 30 const int radiusV = s->radiusV;
60 30 const int t = s->t;
61 30 const pixel *src = (const pixel *)ssrc;
62 30 pixel *dst = (pixel *)ddst;
63 const pixel *srcp;
64 const pixel *p;
65
66 30 src_linesize /= sizeof(pixel);
67 30 dst_linesize /= sizeof(pixel);
68
69 30 memset(cfine, 0, s->fine_size * sizeof(*cfine));
70 30 memset(ccoarse, 0, s->coarse_size * sizeof(*ccoarse));
71
72 30 srcp = src + FFMAX(0, slice_h_start - radiusV) * src_linesize;
73
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
30 if (jobnr == 0) {
74
2/2
✓ Branch 0 taken 3520 times.
✓ Branch 1 taken 15 times.
7070 for (int i = 0; i < width; i++) {
75 7040 cfine[PICK_FINE_BIN(width, srcp[i], i)] += radiusV + 1;
76 7040 ccoarse[PICK_COARSE_BIN(i, srcp[i])] += radiusV + 1;
77 }
78 }
79
80 30 srcp = src + FFMAX(0, slice_h_start - radiusV - (jobnr != 0)) * src_linesize;
81
2/2
✓ Branch 0 taken 75 times.
✓ Branch 1 taken 15 times.
180 for (int i = 0; i < radiusV + (jobnr != 0) * (1 + radiusV); i++) {
82
2/2
✓ Branch 0 taken 17600 times.
✓ Branch 1 taken 75 times.
35350 for (int j = 0; j < width; j++) {
83 35200 cfine[PICK_FINE_BIN(width, srcp[j], j)]++;
84 35200 ccoarse[PICK_COARSE_BIN(j, srcp[j])]++;
85 }
86 150 srcp += src_linesize;
87 }
88
89 30 srcp = src;
90
91
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 15 times.
5790 for (int i = slice_h_start; i < slice_h_end; i++) {
92 5760 htype coarse[BINS] = { 0 };
93 5760 htype fine[BINS][BINS] = { { 0 } };
94 5760 htype luc[BINS] = { 0 };
95
96 5760 p = srcp + src_linesize * FFMAX(0, i - radiusV - 1);
97
2/2
✓ Branch 0 taken 760320 times.
✓ Branch 1 taken 2880 times.
1526400 for (int j = 0; j < width; j++) {
98 1520640 cfine[PICK_FINE_BIN(width, p[j], j)]--;
99 1520640 ccoarse[PICK_COARSE_BIN(j, p[j])]--;
100 }
101
102 5760 p = srcp + src_linesize * FFMIN(height - 1, i + radiusV);
103
2/2
✓ Branch 0 taken 760320 times.
✓ Branch 1 taken 2880 times.
1526400 for (int j = 0; j < width; j++) {
104 1520640 cfine[PICK_FINE_BIN(width, p[j], j)]++;
105 1520640 ccoarse[PICK_COARSE_BIN(j, p[j])]++;
106 }
107
108 5760 s->hmuladd(coarse, &ccoarse[0], radius, BINS);
109
2/2
✓ Branch 0 taken 14400 times.
✓ Branch 1 taken 2880 times.
34560 for (int j = 0; j < radius; j++)
110 28800 s->hadd(coarse, &ccoarse[BINS * j], BINS);
111
2/2
✓ Branch 0 taken 46080 times.
✓ Branch 1 taken 2880 times.
97920 for (int k = 0; k < BINS; k++)
112 92160 s->hmuladd(&fine[k][0], &cfine[BINS * width * k], 2 * radius + 1, BINS);
113
114
2/2
✓ Branch 0 taken 760320 times.
✓ Branch 1 taken 2880 times.
1526400 for (int j = 0; j < width; j++) {
115 1520640 int sum = 0, k, b;
116 htype *segment;
117
118
2/2
✓ Branch 0 taken 14400 times.
✓ Branch 1 taken 745920 times.
1520640 s->hadd(coarse, &ccoarse[BINS * FFMIN(j + radius, width - 1)], BINS);
119
120
1/2
✓ Branch 0 taken 6354526 times.
✗ Branch 1 not taken.
12709052 for (k = 0; k < BINS; k++) {
121 12709052 sum += coarse[k];
122
2/2
✓ Branch 0 taken 760320 times.
✓ Branch 1 taken 5594206 times.
12709052 if (sum > t) {
123 1520640 sum -= coarse[k];
124 1520640 break;
125 }
126 }
127
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 760320 times.
1520640 av_assert0(k < BINS);
128
129
2/2
✓ Branch 0 taken 119597 times.
✓ Branch 1 taken 640723 times.
1520640 if (luc[k] <= j - radius) {
130 239194 memset(&fine[k], 0, BINS * sizeof(htype));
131
4/4
✓ Branch 0 taken 1407180 times.
✓ Branch 1 taken 20878 times.
✓ Branch 2 taken 1308461 times.
✓ Branch 3 taken 119597 times.
2856116 for (luc[k] = j - radius; luc[k] < FFMIN(j + radius + 1, width); luc[k]++)
132 2616922 s->hadd(fine[k], &cfine[BINS * (width * k + luc[k])], BINS);
133
2/2
✓ Branch 0 taken 2332 times.
✓ Branch 1 taken 117265 times.
239194 if (luc[k] < j + radius + 1) {
134 4664 s->hmuladd(&fine[k][0], &cfine[BINS * (width * k + width - 1)], j + radius + 1 - width, BINS);
135 4664 luc[k] = j + radius + 1;
136 }
137 } else {
138
2/2
✓ Branch 0 taken 893016 times.
✓ Branch 1 taken 640723 times.
3067478 for (; luc[k] < j + radius + 1; luc[k]++) {
139 1786032 s->hsub(fine[k], &cfine[BINS * (width * k + FFMAX(luc[k] - 2 * radius - 1, 0))], BINS);
140
2/2
✓ Branch 0 taken 13080 times.
✓ Branch 1 taken 879936 times.
1786032 s->hadd(fine[k], &cfine[BINS * (width * k + FFMIN(luc[k], width - 1))], BINS);
141 }
142 }
143
144 1520640 s->hsub(coarse, &ccoarse[BINS * FFMAX(j - radius, 0)], BINS);
145
146 1520640 segment = fine[k];
147
1/2
✓ Branch 0 taken 6277163 times.
✗ Branch 1 not taken.
12554326 for (b = 0; b < BINS; b++) {
148 12554326 sum += segment[b];
149
2/2
✓ Branch 0 taken 760320 times.
✓ Branch 1 taken 5516843 times.
12554326 if (sum > t) {
150 1520640 dst[j] = BINS * k + b;
151 1520640 break;
152 }
153 }
154
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 760320 times.
1520640 av_assert0(b < BINS);
155 }
156
157 5760 dst += dst_linesize;
158 }
159 30 }
160