../../../ffmpeg/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
924 / 1455
63.5%
Branches:
749 / 1276
58.7%
Functions:
32 / 52
61.5%

libswscale/utils.c
Line Branch Exec Source
1 /*
2 * Copyright (C) 2024 Niklas Haas
3 * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include "config.h"
23
24 #define _DEFAULT_SOURCE
25 #include <inttypes.h>
26 #include <math.h>
27 #include <stdio.h>
28 #include <string.h>
29
30 #include "libavutil/attributes.h"
31 #include "libavutil/avassert.h"
32 #include "libavutil/cpu.h"
33 #include "libavutil/csp.h"
34 #include "libavutil/emms.h"
35 #include "libavutil/imgutils.h"
36 #include "libavutil/intreadwrite.h"
37 #include "libavutil/mathematics.h"
38 #include "libavutil/mem.h"
39 #include "libavutil/opt.h"
40 #include "libavutil/pixdesc.h"
41 #include "libavutil/refstruct.h"
42 #include "libavutil/slicethread.h"
43 #include "libavutil/thread.h"
44 #include "libavutil/aarch64/cpu.h"
45 #include "libavutil/ppc/cpu.h"
46 #include "libavutil/x86/cpu.h"
47 #include "libavutil/loongarch/cpu.h"
48
49 #include "csputils.h"
50 #include "rgb2rgb.h"
51 #include "swscale.h"
52 #include "swscale_internal.h"
53 #include "graph.h"
54 #include "jit.h"
55
56 #if CONFIG_SWSCALE_VULKAN
57 #include "vulkan/ops.h"
58 #endif
59
60 1486706 SwsBackend ff_sws_enabled_backends(const SwsContext *ctx)
61 {
62
2/2
✓ Branch 2 → 3 taken 1363329 times.
✓ Branch 2 → 4 taken 123377 times.
1486706 if (ctx->backends)
63 1363329 return ctx->backends;
64
65 123377 SwsBackend fallback = SWS_BACKEND_STABLE;
66
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 123377 times.
123377 if (ctx->flags & SWS_UNSTABLE)
67 ✗ fallback |= SWS_BACKEND_UNSTABLE;
68
69 123377 return fallback;
70 }
71
72 /**
73 * Allocate and return an SwsContext without performing initialization.
74 */
75 5750 static SwsContext *alloc_set_opts(int srcW, int srcH, enum AVPixelFormat srcFormat,
76 int dstW, int dstH, enum AVPixelFormat dstFormat,
77 int flags, const double *param)
78 {
79 5750 SwsContext *sws = sws_alloc_context();
80
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 5750 times.
5750 if (!sws)
81 ✗ return NULL;
82
83 5750 sws->flags = flags;
84 5750 sws->src_w = srcW;
85 5750 sws->src_h = srcH;
86 5750 sws->dst_w = dstW;
87 5750 sws->dst_h = dstH;
88 5750 sws->src_format = srcFormat;
89 5750 sws->dst_format = dstFormat;
90
91
4/4
✓ Branch 7 → 8 taken 30 times.
✓ Branch 7 → 9 taken 5740 times.
✓ Branch 8 → 6 taken 20 times.
✓ Branch 8 → 9 taken 10 times.
5770 for (int i = 0; param && i < SWS_NUM_SCALER_PARAMS; i++)
92 20 sws->scaler_params[i] = param[i];
93
94 5750 return sws;
95 }
96
97 8 static void set_cascade_chr_pos(SwsContext *cascade, const SwsContext *sws,
98 int src, int dst)
99 {
100
2/2
✓ Branch 2 → 3 taken 5 times.
✓ Branch 2 → 4 taken 3 times.
8 if (src) {
101 5 cascade->src_h_chr_pos = sws->src_h_chr_pos;
102 5 cascade->src_v_chr_pos = sws->src_v_chr_pos;
103 }
104
2/2
✓ Branch 4 → 5 taken 5 times.
✓ Branch 4 → 6 taken 3 times.
8 if (dst) {
105 5 cascade->dst_h_chr_pos = sws->dst_h_chr_pos;
106 5 cascade->dst_v_chr_pos = sws->dst_v_chr_pos;
107 }
108 8 }
109
110 299154 int ff_shuffle_filter_coefficients(SwsInternal *c, int *filterPos,
111 int filterSize, int16_t *filter,
112 int dstW)
113 {
114 #if ARCH_X86_64
115 int i, j, k;
116 299154 int cpu_flags = av_get_cpu_flags();
117
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 299154 times.
299154 if (!filter)
118 ✗ return 0;
119
4/6
✓ Branch 5 → 6 taken 239954 times.
✓ Branch 5 → 38 taken 59200 times.
✓ Branch 6 → 7 taken 239954 times.
✗ Branch 6 → 38 not taken.
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 38 taken 239954 times.
299154 if (EXTERNAL_AVX2_FAST(cpu_flags) && !(cpu_flags & AV_CPU_FLAG_SLOW_GATHER)) {
120
0/4
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 38 not taken.
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 38 not taken.
✗ if ((c->srcBpc == 8) && (c->dstBpc <= 14)) {
121 ✗ int16_t *filterCopy = NULL;
122
0/2
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 15 not taken.
✗ if (filterSize > 4) {
123 ✗ filterCopy = av_malloc_array(dstW, filterSize * sizeof(*filterCopy));
124
0/2
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 14 not taken.
✗ if (!filterCopy)
125 ✗ return AVERROR(ENOMEM);
126 ✗ memcpy(filterCopy, filter, dstW * filterSize * sizeof(int16_t));
127 }
128 // Do not swap filterPos for pixels which won't be processed by
129 // the main loop.
130
0/2
✗ Branch 17 → 16 not taken.
✗ Branch 17 → 18 not taken.
✗ for (i = 0; i + 16 <= dstW; i += 16) {
131 ✗ FFSWAP(int, filterPos[i + 2], filterPos[i + 4]);
132 ✗ FFSWAP(int, filterPos[i + 3], filterPos[i + 5]);
133 ✗ FFSWAP(int, filterPos[i + 10], filterPos[i + 12]);
134 ✗ FFSWAP(int, filterPos[i + 11], filterPos[i + 13]);
135 }
136
0/2
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 37 not taken.
✗ if (filterSize > 4) {
137 // 16 pixels are processed at a time.
138
0/2
✗ Branch 27 → 20 not taken.
✗ Branch 27 → 28 not taken.
✗ for (i = 0; i + 16 <= dstW; i += 16) {
139 // 4 filter coeffs are processed at a time.
140
0/2
✗ Branch 25 → 21 not taken.
✗ Branch 25 → 26 not taken.
✗ for (k = 0; k + 4 <= filterSize; k += 4) {
141
0/2
✗ Branch 23 → 22 not taken.
✗ Branch 23 → 24 not taken.
✗ for (j = 0; j < 16; ++j) {
142 ✗ int from = (i + j) * filterSize + k;
143 ✗ int to = i * filterSize + j * 4 + k * 16;
144 ✗ memcpy(&filter[to], &filterCopy[from], 4 * sizeof(int16_t));
145 }
146 }
147 }
148 // 4 pixels are processed at a time in the tail.
149
0/2
✗ Branch 36 → 29 not taken.
✗ Branch 36 → 37 not taken.
✗ for (; i < dstW; i += 4) {
150 // 4 filter coeffs are processed at a time.
151 ✗ int rem = dstW - i >= 4 ? 4 : dstW - i;
152
0/2
✗ Branch 34 → 30 not taken.
✗ Branch 34 → 35 not taken.
✗ for (k = 0; k + 4 <= filterSize; k += 4) {
153
0/2
✗ Branch 32 → 31 not taken.
✗ Branch 32 → 33 not taken.
✗ for (j = 0; j < rem; ++j) {
154 ✗ int from = (i + j) * filterSize + k;
155 ✗ int to = i * filterSize + j * 4 + k * 4;
156 ✗ memcpy(&filter[to], &filterCopy[from], 4 * sizeof(int16_t));
157 }
158 }
159 }
160 }
161 ✗ av_free(filterCopy);
162 }
163 }
164 #endif
165 299154 return 0;
166 }
167
168 ✗ static double getSplineCoeff(double a, double b, double c, double d,
169 double dist)
170 {
171
0/2
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 4 not taken.
✗ if (dist <= 1.0)
172 ✗ return ((d * dist + c) * dist + b) * dist + a;
173 else
174 ✗ return getSplineCoeff(0.0,
175 ✗ b + 2.0 * c + 3.0 * d,
176 ✗ c + 3.0 * d,
177 ✗ -b - 3.0 * c - 6.0 * d,
178 dist - 1.0);
179 }
180
181 1217560 static av_cold int get_local_pos(SwsInternal *s, int chr_subsample, int pos, int dir)
182 {
183
3/4
✓ Branch 2 → 3 taken 1217560 times.
✗ Branch 2 → 4 not taken.
✓ Branch 3 → 4 taken 562246 times.
✓ Branch 3 → 5 taken 655314 times.
1217560 if (pos == -1 || pos <= -513) {
184 562246 pos = (128 << chr_subsample) - 128;
185 }
186 1217560 pos += 128; // relative to ideal left edge
187 1217560 return pos >> chr_subsample;
188 }
189
190 24974 static av_cold int get_center_offset(SwsInternal *s, int chr_subsample, int pos, int dir)
191 {
192 24974 return (get_local_pos(s, chr_subsample, pos, dir) - 128) * (1 << chr_subsample);
193 }
194
195 typedef struct {
196 int flag; ///< flag associated to the algorithm
197 const char *description; ///< human-readable description
198 int size_factor; ///< size factor used when initing the filters
199 } ScaleAlgorithm;
200
201 static const ScaleAlgorithm scale_algorithms[] = {
202 { SWS_AREA, "area averaging", 1 /* downscale only, for upscale it is bilinear */ },
203 { SWS_BICUBIC, "bicubic", 4 },
204 { SWS_BICUBLIN, "luma bicubic / chroma bilinear", -1 },
205 { SWS_BILINEAR, "bilinear", 2 },
206 { SWS_FAST_BILINEAR, "fast bilinear", -1 },
207 { SWS_GAUSS, "Gaussian", 8 /* infinite ;) */ },
208 { SWS_LANCZOS, "Lanczos", -1 /* custom */ },
209 { SWS_POINT, "nearest neighbor / point", -1 },
210 { SWS_SINC, "sinc", 20 /* infinite ;) */ },
211 { SWS_SPLINE, "bicubic spline", 20 /* infinite :)*/ },
212 { SWS_X, "experimental", 8 },
213 };
214
215 596293 static av_cold int initFilter(int16_t **outFilter, int32_t **filterPos,
216 int *outFilterSize, int xInc, int srcW,
217 int dstW, int filterAlign, int one,
218 int scaler, int flags, int cpu_flags,
219 SwsVector *srcFilter, SwsVector *dstFilter,
220 double param[SWS_NUM_SCALER_PARAMS], int srcPos, int dstPos)
221 {
222 int i;
223 int filterSize;
224 int filter2Size;
225 int minFilterSize;
226 596293 int64_t *filter = NULL;
227 596293 int64_t *filter2 = NULL;
228 596293 const int64_t fone = 1LL << (54 - FFMIN(av_log2(srcW/dstW), 8));
229 596293 int ret = -1;
230
231 596293 emms_c(); // FIXME should not be required but IS (even for non-MMX versions)
232
233 // NOTE: the +3 is for the MMX(+1) / SSE(+3) scaler which reads over the end
234
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 596293 times.
596293 if (!FF_ALLOC_TYPED_ARRAY(*filterPos, dstW + 3))
235 ✗ goto nomem;
236
237
8/8
✓ Branch 6 → 7 taken 458326 times.
✓ Branch 6 → 8 taken 137967 times.
✓ Branch 7 → 9 taken 344992 times.
✓ Branch 7 → 17 taken 113334 times.
✓ Branch 8 → 9 taken 2 times.
✓ Branch 8 → 17 taken 137965 times.
✓ Branch 9 → 10 taken 344766 times.
✓ Branch 9 → 17 taken 228 times.
941059 if (FFABS(xInc - 0x10000) < 10 && srcPos == dstPos) { // unscaled
238 int i;
239 344766 filterSize = 1;
240
1/2
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 344766 times.
344766 if (!FF_ALLOCZ_TYPED_ARRAY(filter, dstW * filterSize))
241 ✗ goto nomem;
242
243
2/2
✓ Branch 15 → 14 taken 54721221 times.
✓ Branch 15 → 16 taken 344766 times.
55065987 for (i = 0; i < dstW; i++) {
244 54721221 filter[i * filterSize] = fone;
245 54721221 (*filterPos)[i] = i;
246 }
247
2/2
✓ Branch 17 → 18 taken 301 times.
✓ Branch 17 → 24 taken 251226 times.
251527 } else if (scaler == SWS_POINT) { // lame looking point sampling mode
248 int i;
249 int64_t xDstInSrc;
250 301 filterSize = 1;
251
1/2
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 21 taken 301 times.
301 if (!FF_ALLOC_TYPED_ARRAY(filter, dstW * filterSize))
252 ✗ goto nomem;
253
254 301 xDstInSrc = ((dstPos*(int64_t)xInc)>>8) - ((srcPos*0x8000LL)>>7);
255
2/2
✓ Branch 23 → 22 taken 87091 times.
✓ Branch 23 → 130 taken 301 times.
87392 for (i = 0; i < dstW; i++) {
256 87091 int xx = (xDstInSrc - ((filterSize - 1) << 15) + (1 << 15)) >> 16;
257
258 87091 (*filterPos)[i] = xx;
259 87091 filter[i] = fone;
260 87091 xDstInSrc += xInc;
261 }
262
6/6
✓ Branch 24 → 25 taken 138029 times.
✓ Branch 24 → 26 taken 113197 times.
✓ Branch 25 → 26 taken 137941 times.
✓ Branch 25 → 27 taken 88 times.
✓ Branch 26 → 27 taken 2 times.
✓ Branch 26 → 39 taken 251136 times.
251226 } else if ((xInc <= (1 << 16) && (scaler == SWS_AREA)) ||
263 90 (scaler == SWS_FAST_BILINEAR)) { // bilinear upscale
264 int i;
265 int64_t xDstInSrc;
266 90 filterSize = 2;
267
1/2
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 30 taken 90 times.
90 if (!FF_ALLOC_TYPED_ARRAY(filter, dstW * filterSize))
268 ✗ goto nomem;
269
270 90 xDstInSrc = ((dstPos*(int64_t)xInc)>>8) - ((srcPos*0x8000LL)>>7);
271
2/2
✓ Branch 37 → 31 taken 237300 times.
✓ Branch 37 → 38 taken 90 times.
237390 for (i = 0; i < dstW; i++) {
272 237300 int xx = (xDstInSrc - ((filterSize - 1) << 15) + (1 << 15)) >> 16;
273 int j;
274
275 237300 (*filterPos)[i] = xx;
276 // bilinear upscale / linear interpolate / area averaging
277
2/2
✓ Branch 35 → 32 taken 474600 times.
✓ Branch 35 → 36 taken 237300 times.
711900 for (j = 0; j < filterSize; j++) {
278 474600 int64_t coeff = fone - FFABS((int64_t)xx * (1 << 16) - xDstInSrc) * (fone >> 16);
279
1/2
✗ Branch 32 → 33 not taken.
✓ Branch 32 → 34 taken 474600 times.
474600 if (coeff < 0)
280 ✗ coeff = 0;
281 474600 filter[i * filterSize + j] = coeff;
282 474600 xx++;
283 }
284 237300 xDstInSrc += xInc;
285 }
286 } else {
287 int64_t xDstInSrc;
288 251136 int sizeFactor = -1;
289
290
2/2
✓ Branch 44 → 40 taken 954370 times.
✓ Branch 44 → 45 taken 6 times.
954376 for (i = 0; i < FF_ARRAY_ELEMS(scale_algorithms); i++) {
291
4/4
✓ Branch 40 → 41 taken 251136 times.
✓ Branch 40 → 43 taken 703234 times.
✓ Branch 41 → 42 taken 251130 times.
✓ Branch 41 → 43 taken 6 times.
954370 if (scaler == scale_algorithms[i].flag && scale_algorithms[i].size_factor > 0) {
292 251130 sizeFactor = scale_algorithms[i].size_factor;
293 251130 break;
294 }
295 }
296
2/2
✓ Branch 45 → 46 taken 6 times.
✓ Branch 45 → 49 taken 251130 times.
251136 if (scaler == SWS_LANCZOS)
297
1/2
✗ Branch 46 → 47 not taken.
✓ Branch 46 → 48 taken 6 times.
6 sizeFactor = param[0] != SWS_PARAM_DEFAULT ? ceil(2 * param[0]) : 6;
298
1/2
✗ Branch 49 → 50 not taken.
✓ Branch 49 → 52 taken 251136 times.
251136 av_assert0(sizeFactor > 0);
299
300
1/2
✗ Branch 52 → 53 not taken.
✓ Branch 52 → 54 taken 251136 times.
251136 if (sizeFactor > 50) {
301 ✗ ret = AVERROR(EINVAL);
302 ✗ goto fail;
303 }
304
305
2/2
✓ Branch 54 → 55 taken 137939 times.
✓ Branch 54 → 56 taken 113197 times.
251136 if (xInc <= 1 << 16)
306 137939 filterSize = 1 + sizeFactor; // upscale
307 else
308 113197 filterSize = 1 + (sizeFactor * srcW + dstW - 1) / dstW;
309
310
2/2
✓ Branch 57 → 58 taken 7328 times.
✓ Branch 57 → 59 taken 243808 times.
251136 filterSize = FFMIN(filterSize, srcW - 2);
311 251136 filterSize = FFMAX(filterSize, 1);
312
313 251136 filter = av_malloc_array(dstW, filterSize * sizeof(*filter));
314
1/2
✗ Branch 61 → 62 not taken.
✓ Branch 61 → 63 taken 251136 times.
251136 if (!filter)
315 ✗ goto nomem;
316 251136 xDstInSrc = ((dstPos*(int64_t)xInc)>>7) - ((srcPos*0x10000LL)>>7);
317
2/2
✓ Branch 129 → 64 taken 28864248 times.
✓ Branch 129 → 130 taken 251136 times.
29115384 for (i = 0; i < dstW; i++) {
318 28864248 int xx = (xDstInSrc - (filterSize - 2) * (1LL<<16)) / (1 << 17);
319 int j;
320 28864248 (*filterPos)[i] = xx;
321
2/2
✓ Branch 127 → 65 taken 119902856 times.
✓ Branch 127 → 128 taken 28864248 times.
148767104 for (j = 0; j < filterSize; j++) {
322 119902856 int64_t d = (FFABS(((int64_t)xx * (1 << 17)) - xDstInSrc)) << 13;
323 double floatd;
324 int64_t coeff;
325
326
2/2
✓ Branch 65 → 66 taken 53643321 times.
✓ Branch 65 → 67 taken 66259535 times.
119902856 if (xInc > 1 << 16)
327 53643321 d = d * dstW / srcW;
328 119902856 floatd = d * (1.0 / (1 << 30));
329
330
2/2
✓ Branch 67 → 68 taken 47890549 times.
✓ Branch 67 → 80 taken 72012307 times.
119902856 if (scaler == SWS_BICUBIC) {
331
1/2
✗ Branch 68 → 69 not taken.
✓ Branch 68 → 70 taken 47890549 times.
47890549 int64_t B = (param[0] != SWS_PARAM_DEFAULT ? param[0] : 0) * (1 << 24);
332
1/2
✗ Branch 71 → 72 not taken.
✓ Branch 71 → 73 taken 47890549 times.
47890549 int64_t C = (param[1] != SWS_PARAM_DEFAULT ? param[1] : 0.6) * (1 << 24);
333
334
2/2
✓ Branch 74 → 75 taken 8488857 times.
✓ Branch 74 → 76 taken 39401692 times.
47890549 if (d >= 1LL << 31) {
335 8488857 coeff = 0.0;
336 } else {
337 39401692 int64_t dd = (d * d) >> 30;
338 39401692 int64_t ddd = (dd * d) >> 30;
339
340
2/2
✓ Branch 76 → 77 taken 19713494 times.
✓ Branch 76 → 78 taken 19688198 times.
39401692 if (d < 1LL << 30)
341 19713494 coeff = (12 * (1 << 24) - 9 * B - 6 * C) * ddd +
342 19713494 (-18 * (1 << 24) + 12 * B + 6 * C) * dd +
343 19713494 (6 * (1 << 24) - 2 * B) * (1 << 30);
344 else
345 19688198 coeff = (-B - 6 * C) * ddd +
346 19688198 (6 * B + 30 * C) * dd +
347 19688198 (-12 * B - 48 * C) * d +
348 19688198 (8 * B + 24 * C) * (1 << 30);
349 }
350 47890549 coeff /= (1LL<<54)/fone;
351
1/2
✗ Branch 80 → 81 not taken.
✓ Branch 80 → 91 taken 72012307 times.
72012307 } else if (scaler == SWS_X) {
352
0/2
✗ Branch 81 → 82 not taken.
✗ Branch 81 → 83 not taken.
✗ double A = param[0] != SWS_PARAM_DEFAULT ? param[0] : 1.0;
353 double c;
354
355
0/2
✗ Branch 84 → 85 not taken.
✗ Branch 84 → 86 not taken.
✗ if (floatd < 1.0)
356 ✗ c = cos(floatd * M_PI);
357 else
358 ✗ c = -1.0;
359
0/2
✗ Branch 87 → 88 not taken.
✗ Branch 87 → 89 not taken.
✗ if (c < 0.0)
360 ✗ c = -pow(-c, A);
361 else
362 ✗ c = pow(c, A);
363 ✗ coeff = (c * 0.5 + 0.5) * fone;
364
2/2
✓ Branch 91 → 92 taken 288927 times.
✓ Branch 91 → 98 taken 71723380 times.
72012307 } else if (scaler == SWS_AREA) {
365 288927 int64_t d2 = d - (1 << 29);
366
2/2
✓ Branch 92 → 93 taken 218924 times.
✓ Branch 92 → 94 taken 70003 times.
288927 if (d2 * xInc < -(1LL << (29 + 16)))
367 218924 coeff = 1.0 * (1LL << (30 + 16));
368
2/2
✓ Branch 94 → 95 taken 60911 times.
✓ Branch 94 → 96 taken 9092 times.
70003 else if (d2 * xInc < (1LL << (29 + 16)))
369 60911 coeff = -d2 * xInc + (1LL << (29 + 16));
370 else
371 9092 coeff = 0.0;
372 288927 coeff *= fone >> (30 + 16);
373
1/2
✗ Branch 98 → 99 not taken.
✓ Branch 98 → 103 taken 71723380 times.
71723380 } else if (scaler == SWS_GAUSS) {
374
0/2
✗ Branch 99 → 100 not taken.
✗ Branch 99 → 101 not taken.
✗ double p = param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0;
375 ✗ coeff = exp2(-p * floatd * floatd) * fone;
376
1/2
✗ Branch 103 → 104 not taken.
✓ Branch 103 → 108 taken 71723380 times.
71723380 } else if (scaler == SWS_SINC) {
377
0/2
✗ Branch 104 → 105 not taken.
✗ Branch 104 → 106 not taken.
✗ coeff = (d ? sin(floatd * M_PI) / (floatd * M_PI) : 1.0) * fone;
378
2/2
✓ Branch 108 → 109 taken 832 times.
✓ Branch 108 → 117 taken 71722548 times.
71723380 } else if (scaler == SWS_LANCZOS) {
379
1/2
✗ Branch 109 → 110 not taken.
✓ Branch 109 → 111 taken 832 times.
832 double p = param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0;
380 1664 coeff = (d ? sin(floatd * M_PI) * sin(floatd * M_PI / p) /
381
1/2
✓ Branch 112 → 113 taken 832 times.
✗ Branch 112 → 114 not taken.
832 (floatd * floatd * M_PI * M_PI / p) : 1.0) * fone;
382
2/2
✓ Branch 115 → 116 taken 90 times.
✓ Branch 115 → 126 taken 742 times.
832 if (floatd > p)
383 90 coeff = 0;
384
1/2
✓ Branch 117 → 118 taken 71722548 times.
✗ Branch 117 → 121 not taken.
71722548 } else if (scaler == SWS_BILINEAR) {
385 71722548 coeff = (1 << 30) - d;
386
2/2
✓ Branch 118 → 119 taken 24028622 times.
✓ Branch 118 → 120 taken 47693926 times.
71722548 if (coeff < 0)
387 24028622 coeff = 0;
388 71722548 coeff *= fone >> 30;
389
0/2
✗ Branch 121 → 122 not taken.
✗ Branch 121 → 124 not taken.
✗ } else if (scaler == SWS_SPLINE) {
390 ✗ double p = -2.196152422706632;
391 ✗ coeff = getSplineCoeff(1.0, 0.0, p, -p - 1.0, floatd) * fone;
392 } else {
393 ✗ av_assert0(0);
394 }
395
396 119902856 filter[i * filterSize + j] = coeff;
397 119902856 xx++;
398 }
399 28864248 xDstInSrc += 2LL * xInc;
400 }
401 }
402
403 /* apply src & dst Filter to filter -> filter2
404 * av_free(filter);
405 */
406
1/2
✗ Branch 130 → 131 not taken.
✓ Branch 130 → 133 taken 596293 times.
596293 av_assert0(filterSize > 0);
407 596293 filter2Size = filterSize;
408
1/2
✗ Branch 133 → 134 not taken.
✓ Branch 133 → 135 taken 596293 times.
596293 if (srcFilter)
409 ✗ filter2Size += srcFilter->length - 1;
410
1/2
✗ Branch 135 → 136 not taken.
✓ Branch 135 → 137 taken 596293 times.
596293 if (dstFilter)
411 ✗ filter2Size += dstFilter->length - 1;
412
1/2
✗ Branch 137 → 138 not taken.
✓ Branch 137 → 140 taken 596293 times.
596293 av_assert0(filter2Size > 0);
413 596293 filter2 = av_calloc(dstW, filter2Size * sizeof(*filter2));
414
1/2
✗ Branch 141 → 142 not taken.
✓ Branch 141 → 143 taken 596293 times.
596293 if (!filter2)
415 ✗ goto nomem;
416
2/2
✓ Branch 155 → 144 taken 83909860 times.
✓ Branch 155 → 156 taken 596293 times.
84506153 for (i = 0; i < dstW; i++) {
417 int j, k;
418
419
1/2
✗ Branch 144 → 145 not taken.
✓ Branch 144 → 151 taken 83909860 times.
83909860 if (srcFilter) {
420
0/2
✗ Branch 150 → 146 not taken.
✗ Branch 150 → 154 not taken.
✗ for (k = 0; k < srcFilter->length; k++) {
421
0/2
✗ Branch 148 → 147 not taken.
✗ Branch 148 → 149 not taken.
✗ for (j = 0; j < filterSize; j++)
422 ✗ filter2[i * filter2Size + k + j] +=
423 ✗ srcFilter->coeff[k] * filter[i * filterSize + j];
424 }
425 } else {
426
2/2
✓ Branch 153 → 152 taken 175185768 times.
✓ Branch 153 → 154 taken 83909860 times.
259095628 for (j = 0; j < filterSize; j++)
427 175185768 filter2[i * filter2Size + j] = filter[i * filterSize + j];
428 }
429 // FIXME dstFilter
430
431 83909860 (*filterPos)[i] += (filterSize - 1) / 2 - (filter2Size - 1) / 2;
432 }
433 596293 av_freep(&filter);
434
435 /* try to reduce the filter-size (step1 find size and shift left) */
436 // Assume it is near normalized (*0.5 or *2.0 is OK but * 0.001 is not).
437 596293 minFilterSize = 0;
438
2/2
✓ Branch 177 → 158 taken 83909860 times.
✓ Branch 177 → 178 taken 596293 times.
84506153 for (i = dstW - 1; i >= 0; i--) {
439 83909860 int min = filter2Size;
440 int j;
441 83909860 int64_t cutOff = 0.0;
442
443 /* get rid of near zero elements on the left by shifting left */
444
1/2
✓ Branch 168 → 159 taken 97767241 times.
✗ Branch 168 → 169 not taken.
97767241 for (j = 0; j < filter2Size; j++) {
445 int k;
446 97767241 cutOff += FFABS(filter2[i * filter2Size]);
447
448
2/2
✓ Branch 159 → 160 taken 83897479 times.
✓ Branch 159 → 161 taken 13869762 times.
97767241 if (cutOff > SWS_MAX_REDUCE_CUTOFF * fone)
449 83897479 break;
450
451 /* preserve monotonicity because the core can't handle the
452 * filter otherwise */
453
4/4
✓ Branch 161 → 162 taken 13634253 times.
✓ Branch 161 → 164 taken 235509 times.
✓ Branch 162 → 163 taken 12381 times.
✓ Branch 162 → 164 taken 13621872 times.
13869762 if (i < dstW - 1 && (*filterPos)[i] >= (*filterPos)[i + 1])
454 12381 break;
455
456 // move filter coefficients left
457
2/2
✓ Branch 166 → 165 taken 42689823 times.
✓ Branch 166 → 167 taken 13857381 times.
56547204 for (k = 1; k < filter2Size; k++)
458 42689823 filter2[i * filter2Size + k - 1] = filter2[i * filter2Size + k];
459 13857381 filter2[i * filter2Size + k - 1] = 0;
460 13857381 (*filterPos)[i]++;
461 }
462
463 83909860 cutOff = 0;
464 /* count near zeros on the right */
465
2/2
✓ Branch 173 → 170 taken 61557643 times.
✓ Branch 173 → 174 taken 54956274 times.
116513917 for (j = filter2Size - 1; j > 0; j--) {
466 61557643 cutOff += FFABS(filter2[i * filter2Size + j]);
467
468
2/2
✓ Branch 170 → 171 taken 28953586 times.
✓ Branch 170 → 172 taken 32604057 times.
61557643 if (cutOff > SWS_MAX_REDUCE_CUTOFF * fone)
469 28953586 break;
470 32604057 min--;
471 }
472
473
2/2
✓ Branch 174 → 175 taken 597063 times.
✓ Branch 174 → 176 taken 83312797 times.
83909860 if (min > minFilterSize)
474 597063 minFilterSize = min;
475 }
476
477 if (PPC_ALTIVEC(cpu_flags)) {
478 // we can handle the special case 4, so we don't want to go the full 8
479 if (minFilterSize < 5)
480 filterAlign = 4;
481
482 /* We really don't want to waste our time doing useless computation, so
483 * fall back on the scalar C code for very small filters.
484 * Vectorizing is worth it only if you have a decent-sized vector. */
485 if (minFilterSize < 3)
486 filterAlign = 1;
487 }
488
489
2/2
✓ Branch 178 → 179 taken 490180 times.
✓ Branch 178 → 182 taken 106113 times.
596293 if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX || have_neon(cpu_flags)) {
490 // special case for unscaled vertical filtering
491
4/4
✓ Branch 179 → 180 taken 268654 times.
✓ Branch 179 → 182 taken 221526 times.
✓ Branch 180 → 181 taken 129008 times.
✓ Branch 180 → 182 taken 139646 times.
490180 if (minFilterSize == 1 && filterAlign == 2)
492 129008 filterAlign = 1;
493 }
494
495 if (have_lasx(cpu_flags) || have_lsx(cpu_flags)) {
496 int reNum = minFilterSize & (0x07);
497
498 if (minFilterSize < 5)
499 filterAlign = 4;
500 if (reNum < 3)
501 filterAlign = 1;
502 }
503
504
1/2
✗ Branch 182 → 183 not taken.
✓ Branch 182 → 185 taken 596293 times.
596293 av_assert0(minFilterSize > 0);
505 596293 filterSize = (minFilterSize + (filterAlign - 1)) & (~(filterAlign - 1));
506
1/2
✗ Branch 185 → 186 not taken.
✓ Branch 185 → 188 taken 596293 times.
596293 av_assert0(filterSize > 0);
507 596293 filter = av_malloc_array(dstW, filterSize * sizeof(*filter));
508
1/2
✗ Branch 189 → 190 not taken.
✓ Branch 189 → 191 taken 596293 times.
596293 if (!filter)
509 ✗ goto nomem;
510
2/2
✓ Branch 194 → 195 taken 1 time.
✓ Branch 194 → 196 taken 596292 times.
596293 if (filterSize >= MAX_FILTER_SIZE * 16 /
511
2/2
✓ Branch 191 → 192 taken 502457 times.
✓ Branch 191 → 193 taken 93836 times.
596293 ((flags & SWS_ACCURATE_RND) ? APCK_SIZE : 16)) {
512 1 ret = RETCODE_USE_CASCADE;
513 1 goto fail;
514 }
515 596292 *outFilterSize = filterSize;
516
517
2/2
✓ Branch 196 → 197 taken 8 times.
✓ Branch 196 → 198 taken 596284 times.
596292 if (flags & SWS_PRINT_INFO)
518 8 av_log(NULL, AV_LOG_VERBOSE,
519 "SwScaler: reducing / aligning filtersize %d -> %d\n",
520 filter2Size, filterSize);
521 /* try to reduce the filter-size (step2 reduce it) */
522
2/2
✓ Branch 209 → 199 taken 83909852 times.
✓ Branch 209 → 210 taken 596292 times.
84506144 for (i = 0; i < dstW; i++) {
523 int j;
524
525
2/2
✓ Branch 207 → 200 taken 215596313 times.
✓ Branch 207 → 208 taken 83909852 times.
299506165 for (j = 0; j < filterSize; j++) {
526
2/2
✓ Branch 200 → 201 taken 54307906 times.
✓ Branch 200 → 202 taken 161288407 times.
215596313 if (j >= filter2Size)
527 54307906 filter[i * filterSize + j] = 0;
528 else
529 161288407 filter[i * filterSize + j] = filter2[i * filter2Size + j];
530
4/4
✓ Branch 203 → 204 taken 195709739 times.
✓ Branch 203 → 206 taken 19886574 times.
✓ Branch 204 → 205 taken 57933888 times.
✓ Branch 204 → 206 taken 137775851 times.
215596313 if ((flags & SWS_BITEXACT) && j >= minFilterSize)
531 57933888 filter[i * filterSize + j] = 0;
532 }
533 }
534
535 // FIXME try to align filterPos if possible
536
537 // fix borders
538
2/2
✓ Branch 244 → 211 taken 83909852 times.
✓ Branch 244 → 245 taken 596292 times.
84506144 for (i = 0; i < dstW; i++) {
539 int j;
540
2/2
✓ Branch 211 → 212 taken 49986 times.
✓ Branch 211 → 216 taken 83859866 times.
83909852 if ((*filterPos)[i] < 0) {
541 // move filter coefficients left to compensate for filterPos
542
2/2
✓ Branch 214 → 213 taken 242811 times.
✓ Branch 214 → 215 taken 49986 times.
292797 for (j = 1; j < filterSize; j++) {
543 242811 int left = FFMAX(j + (*filterPos)[i], 0);
544 242811 filter[i * filterSize + left] += filter[i * filterSize + j];
545 242811 filter[i * filterSize + j] = 0;
546 }
547 49986 (*filterPos)[i]= 0;
548 }
549
550
2/2
✓ Branch 216 → 217 taken 971061 times.
✓ Branch 216 → 229 taken 82938791 times.
83909852 if ((*filterPos)[i] + filterSize > srcW) {
551 971061 int shift = (*filterPos)[i] + FFMIN(filterSize - srcW, 0);
552 971061 int64_t acc = 0;
553
554
2/2
✓ Branch 221 → 218 taken 3852741 times.
✓ Branch 221 → 222 taken 971061 times.
4823802 for (j = filterSize - 1; j >= 0; j--) {
555
2/2
✓ Branch 218 → 219 taken 1695835 times.
✓ Branch 218 → 220 taken 2156906 times.
3852741 if ((*filterPos)[i] + j >= srcW) {
556 1695835 acc += filter[i * filterSize + j];
557 1695835 filter[i * filterSize + j] = 0;
558 }
559 }
560
2/2
✓ Branch 227 → 223 taken 3852741 times.
✓ Branch 227 → 228 taken 971061 times.
4823802 for (j = filterSize - 1; j >= 0; j--) {
561
2/2
✓ Branch 223 → 224 taken 1695835 times.
✓ Branch 223 → 225 taken 2156906 times.
3852741 if (j < shift) {
562 1695835 filter[i * filterSize + j] = 0;
563 } else {
564 2156906 filter[i * filterSize + j] = filter[i * filterSize + j - shift];
565 }
566 }
567
568 971061 (*filterPos)[i]-= shift;
569 971061 filter[i * filterSize + srcW - 1 - (*filterPos)[i]] += acc;
570 }
571
1/2
✗ Branch 229 → 230 not taken.
✓ Branch 229 → 232 taken 83909852 times.
83909852 av_assert0((*filterPos)[i] >= 0);
572
1/2
✗ Branch 232 → 233 not taken.
✓ Branch 232 → 235 taken 83909852 times.
83909852 av_assert0((*filterPos)[i] < srcW);
573
1/2
✗ Branch 235 → 236 not taken.
✓ Branch 235 → 243 taken 83909852 times.
83909852 if ((*filterPos)[i] + filterSize > srcW) {
574
0/2
✗ Branch 242 → 237 not taken.
✗ Branch 242 → 243 not taken.
✗ for (j = 0; j < filterSize; j++) {
575
0/4
✗ Branch 237 → 238 not taken.
✗ Branch 237 → 241 not taken.
✗ Branch 238 → 239 not taken.
✗ Branch 238 → 241 not taken.
✗ av_assert0((*filterPos)[i] + j < srcW || !filter[i * filterSize + j]);
576 }
577 }
578 }
579
580 // Note the +1 is for the MMX scaler which reads over the end
581 /* align at 16 for AltiVec (needed by hScale_altivec_real) */
582 596292 *outFilter = av_calloc(dstW + 3, *outFilterSize * sizeof(**outFilter));
583
1/2
✗ Branch 246 → 247 not taken.
✓ Branch 246 → 248 taken 596292 times.
596292 if (!*outFilter)
584 ✗ goto nomem;
585
586 /* normalize & store in outFilter */
587
2/2
✓ Branch 262 → 249 taken 83909852 times.
✓ Branch 262 → 263 taken 596292 times.
84506144 for (i = 0; i < dstW; i++) {
588 int j;
589 83909852 int64_t error = 0;
590 83909852 int64_t sum = 0;
591
592
2/2
✓ Branch 251 → 250 taken 215596313 times.
✓ Branch 251 → 252 taken 83909852 times.
299506165 for (j = 0; j < filterSize; j++) {
593 215596313 sum += filter[i * filterSize + j];
594 }
595 83909852 sum = (sum + one / 2) / one;
596
1/2
✗ Branch 252 → 253 not taken.
✓ Branch 252 → 255 taken 83909852 times.
83909852 if (!sum) {
597 ✗ av_log(NULL, AV_LOG_WARNING, "SwScaler: zero vector in scaling\n");
598 ✗ sum = 1;
599 }
600
2/2
✓ Branch 260 → 256 taken 215596313 times.
✓ Branch 260 → 261 taken 83909852 times.
299506165 for (j = 0; j < *outFilterSize; j++) {
601 215596313 int64_t v = filter[i * filterSize + j] + error;
602
2/2
✓ Branch 256 → 257 taken 196045214 times.
✓ Branch 256 → 258 taken 19551099 times.
215596313 int intV = ROUNDED_DIV(v, sum);
603 215596313 (*outFilter)[i * (*outFilterSize) + j] = intV;
604 215596313 error = v - intV * sum;
605 }
606 }
607
608 596292 (*filterPos)[dstW + 0] =
609 596292 (*filterPos)[dstW + 1] =
610 596292 (*filterPos)[dstW + 2] = (*filterPos)[dstW - 1]; /* the MMX/SSE scaler will
611 * read over the end */
612
2/2
✓ Branch 265 → 264 taken 1671868 times.
✓ Branch 265 → 266 taken 596292 times.
2268160 for (i = 0; i < *outFilterSize; i++) {
613 1671868 int k = (dstW - 1) * (*outFilterSize) + i;
614 1671868 (*outFilter)[k + 1 * (*outFilterSize)] =
615 1671868 (*outFilter)[k + 2 * (*outFilterSize)] =
616 1671868 (*outFilter)[k + 3 * (*outFilterSize)] = (*outFilter)[k];
617 }
618
619 596292 ret = 0;
620 596292 goto done;
621 ✗ nomem:
622 ✗ ret = AVERROR(ENOMEM);
623 1 fail:
624
1/2
✗ Branch 268 → 269 not taken.
✓ Branch 268 → 270 taken 1 time.
1 if(ret < 0)
625
1/2
✓ Branch 270 → 271 taken 1 time.
✗ Branch 270 → 272 not taken.
1 av_log(NULL, ret == RETCODE_USE_CASCADE ? AV_LOG_DEBUG : AV_LOG_ERROR, "sws: initFilter failed\n");
626 ✗ done:
627 596293 av_free(filter);
628 596293 av_free(filter2);
629 596293 return ret;
630 }
631
632 100575 static void fill_rgb2yuv_table(SwsInternal *c, const int table[4], int dstRange)
633 {
634 int64_t W, V, Z, Cy, Cu, Cv;
635 100575 int64_t vr = table[0];
636 100575 int64_t ub = table[1];
637 100575 int64_t ug = -table[2];
638 100575 int64_t vg = -table[3];
639 100575 int64_t ONE = 65536;
640 100575 int64_t cy = ONE;
641 100575 uint8_t *p = (uint8_t*)c->input_rgb2yuv_table;
642 int i;
643 static const int8_t map[] = {
644 BY_IDX, GY_IDX, -1 , BY_IDX, BY_IDX, GY_IDX, -1 , BY_IDX,
645 RY_IDX, -1 , GY_IDX, RY_IDX, RY_IDX, -1 , GY_IDX, RY_IDX,
646 RY_IDX, GY_IDX, -1 , RY_IDX, RY_IDX, GY_IDX, -1 , RY_IDX,
647 BY_IDX, -1 , GY_IDX, BY_IDX, BY_IDX, -1 , GY_IDX, BY_IDX,
648 BU_IDX, GU_IDX, -1 , BU_IDX, BU_IDX, GU_IDX, -1 , BU_IDX,
649 RU_IDX, -1 , GU_IDX, RU_IDX, RU_IDX, -1 , GU_IDX, RU_IDX,
650 RU_IDX, GU_IDX, -1 , RU_IDX, RU_IDX, GU_IDX, -1 , RU_IDX,
651 BU_IDX, -1 , GU_IDX, BU_IDX, BU_IDX, -1 , GU_IDX, BU_IDX,
652 BV_IDX, GV_IDX, -1 , BV_IDX, BV_IDX, GV_IDX, -1 , BV_IDX,
653 RV_IDX, -1 , GV_IDX, RV_IDX, RV_IDX, -1 , GV_IDX, RV_IDX,
654 RV_IDX, GV_IDX, -1 , RV_IDX, RV_IDX, GV_IDX, -1 , RV_IDX,
655 BV_IDX, -1 , GV_IDX, BV_IDX, BV_IDX, -1 , GV_IDX, BV_IDX,
656 RY_IDX, BY_IDX, RY_IDX, BY_IDX, RY_IDX, BY_IDX, RY_IDX, BY_IDX,
657 BY_IDX, RY_IDX, BY_IDX, RY_IDX, BY_IDX, RY_IDX, BY_IDX, RY_IDX,
658 GY_IDX, -1 , GY_IDX, -1 , GY_IDX, -1 , GY_IDX, -1 ,
659 -1 , GY_IDX, -1 , GY_IDX, -1 , GY_IDX, -1 , GY_IDX,
660 RU_IDX, BU_IDX, RU_IDX, BU_IDX, RU_IDX, BU_IDX, RU_IDX, BU_IDX,
661 BU_IDX, RU_IDX, BU_IDX, RU_IDX, BU_IDX, RU_IDX, BU_IDX, RU_IDX,
662 GU_IDX, -1 , GU_IDX, -1 , GU_IDX, -1 , GU_IDX, -1 ,
663 -1 , GU_IDX, -1 , GU_IDX, -1 , GU_IDX, -1 , GU_IDX,
664 RV_IDX, BV_IDX, RV_IDX, BV_IDX, RV_IDX, BV_IDX, RV_IDX, BV_IDX,
665 BV_IDX, RV_IDX, BV_IDX, RV_IDX, BV_IDX, RV_IDX, BV_IDX, RV_IDX,
666 GV_IDX, -1 , GV_IDX, -1 , GV_IDX, -1 , GV_IDX, -1 ,
667 -1 , GV_IDX, -1 , GV_IDX, -1 , GV_IDX, -1 , GV_IDX, //23
668 -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //24
669 -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //25
670 -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //26
671 -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //27
672 -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //28
673 -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //29
674 -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //30
675 -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //31
676 BY_IDX, GY_IDX, RY_IDX, -1 , -1 , -1 , -1 , -1 , //32
677 BU_IDX, GU_IDX, RU_IDX, -1 , -1 , -1 , -1 , -1 , //33
678 BV_IDX, GV_IDX, RV_IDX, -1 , -1 , -1 , -1 , -1 , //34
679 };
680
681 100575 dstRange = 0; //FIXME range = 1 is handled elsewhere
682
683
1/2
✓ Branch 2 → 3 taken 100575 times.
✗ Branch 2 → 4 not taken.
100575 if (!dstRange) {
684 100575 cy = cy * 255 / 219;
685 } else {
686 ✗ vr = vr * 224 / 255;
687 ✗ ub = ub * 224 / 255;
688 ✗ ug = ug * 224 / 255;
689 ✗ vg = vg * 224 / 255;
690 }
691
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 100575 times.
100575 W = ROUNDED_DIV(ONE*ONE*ug, ub);
692
1/2
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 100575 times.
100575 V = ROUNDED_DIV(ONE*ONE*vg, vr);
693 100575 Z = ONE*ONE-W-V;
694
695
1/2
✓ Branch 11 → 12 taken 100575 times.
✗ Branch 11 → 13 not taken.
100575 Cy = ROUNDED_DIV(cy*Z, ONE);
696
1/2
✓ Branch 14 → 15 taken 100575 times.
✗ Branch 14 → 16 not taken.
100575 Cu = ROUNDED_DIV(ub*Z, ONE);
697
1/2
✓ Branch 17 → 18 taken 100575 times.
✗ Branch 17 → 19 not taken.
100575 Cv = ROUNDED_DIV(vr*Z, ONE);
698
699
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 100575 times.
100575 c->input_rgb2yuv_table[RY_IDX] = -ROUNDED_DIV((1 << RGB2YUV_SHIFT)*V , Cy);
700 100575 c->input_rgb2yuv_table[GY_IDX] = ROUNDED_DIV((1 << RGB2YUV_SHIFT)*ONE*ONE , Cy);
701
1/2
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 100575 times.
100575 c->input_rgb2yuv_table[BY_IDX] = -ROUNDED_DIV((1 << RGB2YUV_SHIFT)*W , Cy);
702
703
1/2
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 28 taken 100575 times.
100575 c->input_rgb2yuv_table[RU_IDX] = ROUNDED_DIV((1 << RGB2YUV_SHIFT)*V , Cu);
704 100575 c->input_rgb2yuv_table[GU_IDX] = -ROUNDED_DIV((1 << RGB2YUV_SHIFT)*ONE*ONE , Cu);
705
1/2
✓ Branch 29 → 30 taken 100575 times.
✗ Branch 29 → 31 not taken.
100575 c->input_rgb2yuv_table[BU_IDX] = ROUNDED_DIV((1 << RGB2YUV_SHIFT)*(Z+W) , Cu);
706
707
1/2
✓ Branch 32 → 33 taken 100575 times.
✗ Branch 32 → 34 not taken.
100575 c->input_rgb2yuv_table[RV_IDX] = ROUNDED_DIV((1 << RGB2YUV_SHIFT)*(V+Z) , Cv);
708 100575 c->input_rgb2yuv_table[GV_IDX] = -ROUNDED_DIV((1 << RGB2YUV_SHIFT)*ONE*ONE , Cv);
709
1/2
✗ Branch 35 → 36 not taken.
✓ Branch 35 → 37 taken 100575 times.
100575 c->input_rgb2yuv_table[BV_IDX] = ROUNDED_DIV((1 << RGB2YUV_SHIFT)*W , Cv);
710
711
1/2
✓ Branch 38 → 39 taken 100575 times.
✗ Branch 38 → 40 not taken.
100575 if(/*!dstRange && */!memcmp(table, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT], sizeof(ff_yuv2rgb_coeffs[SWS_CS_DEFAULT]))) {
712 100575 c->input_rgb2yuv_table[BY_IDX] = ((int)(0.114 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
713 100575 c->input_rgb2yuv_table[BV_IDX] = (-(int)(0.081 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
714 100575 c->input_rgb2yuv_table[BU_IDX] = ((int)(0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
715 100575 c->input_rgb2yuv_table[GY_IDX] = ((int)(0.587 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
716 100575 c->input_rgb2yuv_table[GV_IDX] = (-(int)(0.419 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
717 100575 c->input_rgb2yuv_table[GU_IDX] = (-(int)(0.331 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
718 100575 c->input_rgb2yuv_table[RY_IDX] = ((int)(0.299 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
719 100575 c->input_rgb2yuv_table[RV_IDX] = ((int)(0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
720 100575 c->input_rgb2yuv_table[RU_IDX] = (-(int)(0.169 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
721 }
722
2/2
✓ Branch 45 → 41 taken 28161000 times.
✓ Branch 45 → 46 taken 100575 times.
28261575 for(i=0; i<FF_ARRAY_ELEMS(map); i++)
723
2/2
✓ Branch 41 → 42 taken 15387975 times.
✓ Branch 41 → 43 taken 12773025 times.
28161000 AV_WL16(p + 16*4 + 2*i, map[i] >= 0 ? c->input_rgb2yuv_table[map[i]] : 0);
724 100575 }
725
726 480 static double trc_peak(enum AVColorTransferCharacteristic trc)
727 {
728 480 return av_csp_trc_func_inv_from_id(trc)(1.0);
729 }
730
731 76 static void init_xyz_luts(SwsLuts *luts, enum AVColorTransferCharacteristic trc_in,
732 enum AVColorTransferCharacteristic trc_out)
733 {
734 76 const av_csp_trc_function to_linear = av_csp_trc_func_inv_from_id(trc_in);
735 76 const av_csp_trc_function from_linear = av_csp_trc_func_from_id(trc_out);
736 76 const double peak_in = trc_peak(trc_in), peak_out = trc_peak(trc_out);
737
738
2/2
✓ Branch 9 → 7 taken 311296 times.
✓ Branch 9 → 10 taken 76 times.
311372 for (int i = 0; i < 4096; i++)
739 311296 luts->in[i] = lrint(to_linear(i / 4095.0) / peak_in * 65535.0);
740
2/2
✓ Branch 13 → 11 taken 4980736 times.
✓ Branch 13 → 14 taken 76 times.
4980812 for (int i = 0; i < 65536; i++)
741 4980736 luts->out[i] = lrint(from_linear(i / 65535.0 * peak_out) * 4095.0);
742 76 }
743
744 38 static void init_xyz_tables(SwsLuts *xyz2rgb, SwsLuts *rgb2xyz)
745 {
746 38 init_xyz_luts(xyz2rgb, XYZ_TRC, XYZ_RGB_TRC);
747 38 init_xyz_luts(rgb2xyz, XYZ_RGB_TRC, XYZ_TRC);
748 38 }
749
750 #if !CONFIG_SMALL
751 static uint16_t xyzgamma_tab[4096], rgbgammainv_tab[4096];
752 static uint16_t rgbgamma_tab[65536], xyzgammainv_tab[65536];
753 38 static av_cold void init_xyz_tables_once(void)
754 {
755 38 SwsLuts xyz2rgb = { xyzgamma_tab, rgbgamma_tab };
756 38 SwsLuts rgb2xyz = { rgbgammainv_tab, xyzgammainv_tab };
757 38 init_xyz_tables(&xyz2rgb, &rgb2xyz);
758 38 }
759 #endif
760
761 128 static void fill_xyz_matrix(int16_t mat[3][3], const SwsMatrix3x3 *m, double scale)
762 {
763
2/2
✓ Branch 7 → 3 taken 384 times.
✓ Branch 7 → 8 taken 128 times.
512 for (int i = 0; i < 3; i++) {
764
2/2
✓ Branch 5 → 4 taken 1152 times.
✓ Branch 5 → 6 taken 384 times.
1536 for (int j = 0; j < 3; j++) {
765 1152 const double v = m->m[i][j] * scale * 4096.0;
766 av_assert1(fabs(v) <= INT16_MAX);
767 1152 mat[i][j] = lrint(v);
768 }
769 }
770 128 }
771
772 164 av_cold int ff_sws_fill_st428_tables(SwsInternal *c)
773 {
774 /* X'Y'Z' puts its 48 cd/m2 white at code 3960 and the top code at
775 * 52.37 cd/m2 (ST 428-1), the codes above the white clip in RGB */
776 164 const double peak = trc_peak(XYZ_TRC) / trc_peak(XYZ_RGB_TRC);
777 164 const AVColorPrimariesDesc *bt709 = av_csp_primaries_desc_from_id(AVCOL_PRI_BT709);
778 164 const SwsMatrix3x3 xyz2rgb = ff_sws_xyz2rgb(bt709);
779 164 const SwsMatrix3x3 rgb2xyz = ff_sws_rgb2xyz(bt709);
780
781
2/2
✓ Branch 7 → 8 taken 100 times.
✓ Branch 7 → 9 taken 64 times.
164 if (c->xyz2rgb.gamma.in)
782 100 return 0;
783
784 64 fill_xyz_matrix(c->xyz2rgb.mat, &xyz2rgb, peak);
785 64 fill_xyz_matrix(c->rgb2xyz.mat, &rgb2xyz, 1.0 / peak);
786
787 #if CONFIG_SMALL
788 c->xyz2rgb.gamma.in = av_malloc(sizeof(uint16_t) * 2 * (4096 + 65536));
789 if (!c->xyz2rgb.gamma.in)
790 return AVERROR(ENOMEM);
791 c->rgb2xyz.gamma.in = c->xyz2rgb.gamma.in + 4096;
792 c->xyz2rgb.gamma.out = c->rgb2xyz.gamma.in + 4096;
793 c->rgb2xyz.gamma.out = c->xyz2rgb.gamma.out + 65536;
794 init_xyz_tables(&c->xyz2rgb.gamma, &c->rgb2xyz.gamma);
795 #else
796 64 c->xyz2rgb.gamma.in = xyzgamma_tab;
797 64 c->xyz2rgb.gamma.out = rgbgamma_tab;
798 64 c->rgb2xyz.gamma.in = rgbgammainv_tab;
799 64 c->rgb2xyz.gamma.out = xyzgammainv_tab;
800
801 static AVOnce xyz_init_static_once = AV_ONCE_INIT;
802 64 ff_thread_once(&xyz_init_static_once, init_xyz_tables_once);
803 #endif
804 64 return 0;
805 }
806
807 246032 static int handle_jpeg(/* enum AVPixelFormat */ int *format)
808 {
809
7/7
✓ Branch 2 → 3 taken 107 times.
✓ Branch 2 → 4 taken 16 times.
✓ Branch 2 → 5 taken 53 times.
✓ Branch 2 → 6 taken 1064 times.
✓ Branch 2 → 7 taken 44 times.
✓ Branch 2 → 8 taken 14394 times.
✓ Branch 2 → 9 taken 230354 times.
246032 switch (*format) {
810 107 case AV_PIX_FMT_YUVJ420P:
811 107 *format = AV_PIX_FMT_YUV420P;
812 107 return 1;
813 16 case AV_PIX_FMT_YUVJ411P:
814 16 *format = AV_PIX_FMT_YUV411P;
815 16 return 1;
816 53 case AV_PIX_FMT_YUVJ422P:
817 53 *format = AV_PIX_FMT_YUV422P;
818 53 return 1;
819 1064 case AV_PIX_FMT_YUVJ444P:
820 1064 *format = AV_PIX_FMT_YUV444P;
821 1064 return 1;
822 44 case AV_PIX_FMT_YUVJ440P:
823 44 *format = AV_PIX_FMT_YUV440P;
824 44 return 1;
825 14394 case AV_PIX_FMT_GRAY8:
826 case AV_PIX_FMT_YA8:
827 case AV_PIX_FMT_GRAY9LE:
828 case AV_PIX_FMT_GRAY9BE:
829 case AV_PIX_FMT_GRAY10LE:
830 case AV_PIX_FMT_GRAY10BE:
831 case AV_PIX_FMT_GRAY12LE:
832 case AV_PIX_FMT_GRAY12BE:
833 case AV_PIX_FMT_GRAY14LE:
834 case AV_PIX_FMT_GRAY14BE:
835 case AV_PIX_FMT_GRAY16LE:
836 case AV_PIX_FMT_GRAY16BE:
837 case AV_PIX_FMT_YA16BE:
838 case AV_PIX_FMT_YA16LE:
839 /* Floating point formats */
840 case AV_PIX_FMT_GRAYF16BE:
841 case AV_PIX_FMT_GRAYF16LE:
842 case AV_PIX_FMT_GRAYF32BE:
843 case AV_PIX_FMT_GRAYF32LE:
844 case AV_PIX_FMT_YAF16BE:
845 case AV_PIX_FMT_YAF16LE:
846 case AV_PIX_FMT_YAF32BE:
847 case AV_PIX_FMT_YAF32LE:
848 14394 return 1;
849 230354 default:
850 230354 return 0;
851 }
852 }
853
854 946020 static int handle_0alpha(/* enum AVPixelFormat */ int *format)
855 {
856
5/5
✓ Branch 2 → 3 taken 962 times.
✓ Branch 2 → 4 taken 1019 times.
✓ Branch 2 → 5 taken 1098 times.
✓ Branch 2 → 6 taken 1067 times.
✓ Branch 2 → 7 taken 941874 times.
946020 switch (*format) {
857 962 case AV_PIX_FMT_0BGR : *format = AV_PIX_FMT_ABGR ; return 1;
858 1019 case AV_PIX_FMT_BGR0 : *format = AV_PIX_FMT_BGRA ; return 4;
859 1098 case AV_PIX_FMT_0RGB : *format = AV_PIX_FMT_ARGB ; return 1;
860 1067 case AV_PIX_FMT_RGB0 : *format = AV_PIX_FMT_RGBA ; return 4;
861 941874 default: return 0;
862 }
863 }
864
865 946020 static int handle_xyz(/* enum AVPixelFormat */ int *format)
866 {
867
3/3
✓ Branch 2 → 3 taken 14 times.
✓ Branch 2 → 4 taken 38 times.
✓ Branch 2 → 5 taken 945968 times.
946020 switch (*format) {
868 14 case AV_PIX_FMT_XYZ12BE : *format = AV_PIX_FMT_RGB48BE; return 1;
869 38 case AV_PIX_FMT_XYZ12LE : *format = AV_PIX_FMT_RGB48LE; return 1;
870 945968 default: return 0;
871 }
872 }
873
874 473010 static int handle_formats(SwsContext *sws)
875 {
876 473010 SwsInternal *c = sws_internal(sws);
877 473010 c->src0Alpha |= handle_0alpha(&sws->src_format);
878 473010 c->dst0Alpha |= handle_0alpha(&sws->dst_format);
879 473010 c->srcXYZ |= handle_xyz(&sws->src_format);
880 473010 c->dstXYZ |= handle_xyz(&sws->dst_format);
881
4/4
✓ Branch 7 → 8 taken 472968 times.
✓ Branch 7 → 9 taken 42 times.
✓ Branch 8 → 9 taken 108 times.
✓ Branch 8 → 11 taken 472860 times.
473010 if (c->srcXYZ || c->dstXYZ)
882 150 return ff_sws_fill_st428_tables(c);
883 else
884 472860 return 0;
885 }
886
887 849226 static int range_override_needed(enum AVPixelFormat format)
888 {
889
4/4
✓ Branch 3 → 4 taken 293101 times.
✓ Branch 3 → 7 taken 556125 times.
✓ Branch 5 → 6 taken 255724 times.
✓ Branch 5 → 7 taken 37377 times.
849226 return !isYUV(format) && !isGray(format);
890 }
891
892 309656 int sws_setColorspaceDetails(SwsContext *sws, const int inv_table[4],
893 int srcRange, const int table[4], int dstRange,
894 int brightness, int contrast, int saturation)
895 {
896 309656 SwsInternal *c = sws_internal(sws);
897 const AVPixFmtDescriptor *desc_dst;
898 const AVPixFmtDescriptor *desc_src;
899 309656 int ret, need_reinit = 0;
900
901
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 11 taken 309656 times.
309656 if (c->nb_slice_ctx) {
902 ✗ int parent_ret = 0;
903
0/2
✗ Branch 9 → 5 not taken.
✗ Branch 9 → 10 not taken.
✗ for (int i = 0; i < c->nb_slice_ctx; i++) {
904 ✗ int ret = sws_setColorspaceDetails(c->slice_ctx[i], inv_table,
905 srcRange, table, dstRange,
906 brightness, contrast, saturation);
907
0/2
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 8 not taken.
✗ if (ret < 0)
908 ✗ parent_ret = ret;
909 }
910
911 ✗ return parent_ret;
912 }
913
914 309656 ret = handle_formats(sws);
915
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 309656 times.
309656 if (ret < 0)
916 ✗ return ret;
917 309656 desc_dst = av_pix_fmt_desc_get(sws->dst_format);
918 309656 desc_src = av_pix_fmt_desc_get(sws->src_format);
919
920
2/2
✓ Branch 17 → 18 taken 58838 times.
✓ Branch 17 → 19 taken 250818 times.
309656 if(range_override_needed(sws->dst_format))
921 58838 dstRange = 0;
922
2/2
✓ Branch 20 → 21 taken 154 times.
✓ Branch 20 → 22 taken 250664 times.
250818 else if (isFloat(sws->dst_format))
923 154 dstRange = 1; /* float gray formats are always full range */
924
2/2
✓ Branch 23 → 24 taken 133627 times.
✓ Branch 23 → 25 taken 176029 times.
309656 if(range_override_needed(sws->src_format))
925 133627 srcRange = 0;
926
2/2
✓ Branch 26 → 27 taken 118 times.
✓ Branch 26 → 28 taken 175911 times.
176029 else if (isFloat(sws->src_format))
927 118 srcRange = 1;
928
929
2/2
✓ Branch 28 → 29 taken 251208 times.
✓ Branch 28 → 35 taken 58448 times.
309656 if (sws->src_range != srcRange ||
930
2/2
✓ Branch 29 → 30 taken 246984 times.
✓ Branch 29 → 35 taken 4224 times.
251208 sws->dst_range != dstRange ||
931
1/2
✓ Branch 30 → 31 taken 246984 times.
✗ Branch 30 → 35 not taken.
246984 c->brightness != brightness ||
932
2/2
✓ Branch 31 → 32 taken 146302 times.
✓ Branch 31 → 35 taken 100682 times.
246984 c->contrast != contrast ||
933
1/2
✓ Branch 32 → 33 taken 146302 times.
✗ Branch 32 → 35 not taken.
146302 c->saturation != saturation ||
934
2/2
✓ Branch 33 → 34 taken 146122 times.
✓ Branch 33 → 35 taken 180 times.
146302 memcmp(c->srcColorspaceTable, inv_table, sizeof(int) * 4) ||
935
1/2
✗ Branch 34 → 35 not taken.
✓ Branch 34 → 36 taken 146122 times.
146122 memcmp(c->dstColorspaceTable, table, sizeof(int) * 4)
936 )
937 163534 need_reinit = 1;
938
939 309656 memmove(c->srcColorspaceTable, inv_table, sizeof(int) * 4);
940 309656 memmove(c->dstColorspaceTable, table, sizeof(int) * 4);
941
942
943
944 309656 c->brightness = brightness;
945 309656 c->contrast = contrast;
946 309656 c->saturation = saturation;
947 309656 sws->src_range = srcRange;
948 309656 sws->dst_range = dstRange;
949
950
2/2
✓ Branch 36 → 37 taken 163534 times.
✓ Branch 36 → 38 taken 146122 times.
309656 if (need_reinit)
951 163534 ff_sws_init_range_convert(c);
952
953 309656 c->dstFormatBpp = av_get_bits_per_pixel(desc_dst);
954 309656 c->srcFormatBpp = av_get_bits_per_pixel(desc_src);
955
956
2/2
✓ Branch 40 → 41 taken 3 times.
✓ Branch 40 → 43 taken 309653 times.
309656 if (c->cascaded_context[c->cascaded_mainindex])
957 3 return sws_setColorspaceDetails(c->cascaded_context[c->cascaded_mainindex],inv_table, srcRange,table, dstRange, brightness, contrast, saturation);
958
959
2/2
✓ Branch 43 → 44 taken 146119 times.
✓ Branch 43 → 45 taken 163534 times.
309653 if (!need_reinit)
960 146119 return 0;
961
962
8/8
✓ Branch 46 → 47 taken 38950 times.
✓ Branch 46 → 49 taken 124584 times.
✓ Branch 48 → 49 taken 1271 times.
✓ Branch 48 → 104 taken 37679 times.
✓ Branch 50 → 51 taken 74222 times.
✓ Branch 50 → 53 taken 51633 times.
✓ Branch 52 → 53 taken 11326 times.
✓ Branch 52 → 104 taken 62896 times.
163534 if ((isYUV(sws->dst_format) || isGray(sws->dst_format)) && (isYUV(sws->src_format) || isGray(sws->src_format))) {
963
1/2
✓ Branch 53 → 54 taken 62959 times.
✗ Branch 53 → 100 not taken.
62959 if (!c->cascaded_context[0] &&
964
2/2
✓ Branch 54 → 55 taken 2 times.
✓ Branch 54 → 100 taken 62957 times.
62959 memcmp(c->dstColorspaceTable, c->srcColorspaceTable, sizeof(int) * 4) &&
965
4/8
✓ Branch 55 → 56 taken 2 times.
✗ Branch 55 → 100 not taken.
✓ Branch 56 → 57 taken 2 times.
✗ Branch 56 → 100 not taken.
✓ Branch 57 → 58 taken 2 times.
✗ Branch 57 → 100 not taken.
✓ Branch 58 → 59 taken 2 times.
✗ Branch 58 → 100 not taken.
2 sws->src_w && sws->src_h && sws->dst_w && sws->dst_h) {
966 enum AVPixelFormat tmp_format;
967 int tmp_width, tmp_height;
968 2 int srcW = sws->src_w;
969 2 int srcH = sws->src_h;
970 2 int dstW = sws->dst_w;
971 2 int dstH = sws->dst_h;
972 int ret;
973 2 av_log(c, AV_LOG_VERBOSE, "YUV color matrix differs for YUV->YUV, using intermediate RGB to convert\n");
974
975
2/4
✓ Branch 61 → 62 taken 2 times.
✗ Branch 61 → 64 not taken.
✗ Branch 63 → 64 not taken.
✓ Branch 63 → 71 taken 2 times.
2 if (isNBPS(sws->dst_format) || is16BPS(sws->dst_format)) {
976
0/4
✗ Branch 65 → 66 not taken.
✗ Branch 65 → 69 not taken.
✗ Branch 67 → 68 not taken.
✗ Branch 67 → 69 not taken.
✗ if (isALPHA(sws->src_format) && isALPHA(sws->dst_format)) {
977 ✗ tmp_format = AV_PIX_FMT_BGRA64;
978 } else {
979 ✗ tmp_format = AV_PIX_FMT_BGR48;
980 }
981 } else {
982
1/4
✗ Branch 72 → 73 not taken.
✓ Branch 72 → 76 taken 2 times.
✗ Branch 74 → 75 not taken.
✗ Branch 74 → 76 not taken.
2 if (isALPHA(sws->src_format) && isALPHA(sws->dst_format)) {
983 ✗ tmp_format = AV_PIX_FMT_BGRA;
984 } else {
985 2 tmp_format = AV_PIX_FMT_BGR24;
986 }
987 }
988
989
1/2
✗ Branch 77 → 78 not taken.
✓ Branch 77 → 79 taken 2 times.
2 if (srcW*(int64_t)srcH > dstW*(int64_t)dstH) {
990 ✗ tmp_width = dstW;
991 ✗ tmp_height = dstH;
992 } else {
993 2 tmp_width = srcW;
994 2 tmp_height = srcH;
995 }
996
997 2 ret = av_image_alloc(c->cascaded_tmp[0], c->cascaded_tmpStride[0],
998 tmp_width, tmp_height, tmp_format, 64);
999
1/2
✗ Branch 81 → 82 not taken.
✓ Branch 81 → 83 taken 2 times.
2 if (ret < 0)
1000 ✗ return ret;
1001
1002 4 c->cascaded_context[0] = alloc_set_opts(srcW, srcH, sws->src_format,
1003 tmp_width, tmp_height, tmp_format,
1004 2 sws->flags, sws->scaler_params);
1005
1/2
✗ Branch 84 → 85 not taken.
✓ Branch 84 → 86 taken 2 times.
2 if (!c->cascaded_context[0])
1006 ✗ return -1;
1007
1008 2 c->cascaded_context[0]->alpha_blend = sws->alpha_blend;
1009 2 set_cascade_chr_pos(c->cascaded_context[0], sws, 1, 0);
1010 2 ret = sws_init_context(c->cascaded_context[0], NULL , NULL);
1011
1/2
✗ Branch 88 → 89 not taken.
✓ Branch 88 → 90 taken 2 times.
2 if (ret < 0)
1012 ✗ return ret;
1013 //we set both src and dst depending on that the RGB side will be ignored
1014 2 sws_setColorspaceDetails(c->cascaded_context[0], inv_table,
1015 srcRange, table, dstRange,
1016 brightness, contrast, saturation);
1017
1018 4 c->cascaded_context[1] = alloc_set_opts(tmp_width, tmp_height, tmp_format,
1019 2 dstW, dstH, sws->dst_format,
1020 2 sws->flags, sws->scaler_params);
1021
1/2
✗ Branch 92 → 93 not taken.
✓ Branch 92 → 94 taken 2 times.
2 if (!c->cascaded_context[1])
1022 ✗ return -1;
1023 2 c->cascaded_context[1]->src_range = srcRange;
1024 2 c->cascaded_context[1]->dst_range = dstRange;
1025 2 set_cascade_chr_pos(c->cascaded_context[1], sws, 0, 1);
1026 2 ret = sws_init_context(c->cascaded_context[1], NULL , NULL);
1027
1/2
✗ Branch 96 → 97 not taken.
✓ Branch 96 → 98 taken 2 times.
2 if (ret < 0)
1028 ✗ return ret;
1029 2 sws_setColorspaceDetails(c->cascaded_context[1], inv_table,
1030 srcRange, table, dstRange,
1031 0, 1 << 16, 1 << 16);
1032 2 return 0;
1033 }
1034 //We do not support this combination currently, we need to cascade more contexts to compensate
1035
1/4
✗ Branch 100 → 101 not taken.
✓ Branch 100 → 103 taken 62957 times.
✗ Branch 101 → 102 not taken.
✗ Branch 101 → 103 not taken.
62957 if (c->cascaded_context[0] && memcmp(c->dstColorspaceTable, c->srcColorspaceTable, sizeof(int) * 4))
1036 ✗ return -1; //AVERROR_PATCHWELCOME;
1037 62957 return 0;
1038 }
1039
1040
4/4
✓ Branch 105 → 106 taken 38099 times.
✓ Branch 105 → 109 taken 62476 times.
✓ Branch 107 → 108 taken 37679 times.
✓ Branch 107 → 109 taken 420 times.
100575 if (!isYUV(sws->dst_format) && !isGray(sws->dst_format)) {
1041 37679 ff_yuv2rgb_c_init_tables(c, inv_table, srcRange, brightness,
1042 contrast, saturation);
1043 // FIXME factorize
1044
1045 #if ARCH_PPC
1046 ff_yuv2rgb_init_tables_ppc(c, inv_table, brightness,
1047 contrast, saturation);
1048 #endif
1049 }
1050
1051 100575 fill_rgb2yuv_table(c, table, dstRange);
1052
1053 100575 return 0;
1054 }
1055
1056 114957 int sws_getColorspaceDetails(SwsContext *sws, int **inv_table,
1057 int *srcRange, int **table, int *dstRange,
1058 int *brightness, int *contrast, int *saturation)
1059 {
1060 114957 SwsInternal *c = sws_internal(sws);
1061
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 114957 times.
114957 if (!c)
1062 ✗ return -1;
1063
1064
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 114957 times.
114957 if (c->nb_slice_ctx) {
1065 ✗ return sws_getColorspaceDetails(c->slice_ctx[0], inv_table, srcRange,
1066 table, dstRange, brightness, contrast,
1067 saturation);
1068 }
1069
1070 114957 *inv_table = c->srcColorspaceTable;
1071 114957 *table = c->dstColorspaceTable;
1072
2/2
✓ Branch 9 → 10 taken 56460 times.
✓ Branch 9 → 11 taken 58497 times.
114957 *srcRange = range_override_needed(sws->src_format) ? 1 : sws->src_range;
1073
2/2
✓ Branch 13 → 14 taken 110195 times.
✓ Branch 13 → 15 taken 4762 times.
114957 *dstRange = range_override_needed(sws->dst_format) ? 1 : sws->dst_range;
1074 114957 *brightness = c->brightness;
1075 114957 *contrast = c->contrast;
1076 114957 *saturation = c->saturation;
1077
1078 114957 return 0;
1079 }
1080
1081 187506 SwsContext *sws_alloc_context(void)
1082 {
1083 187506 SwsInternal *c = av_mallocz(sizeof(*c) + SWSINTERNAL_ADDITIONAL_ASM_SIZE);
1084
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 187506 times.
187506 if (!c)
1085 ✗ return NULL;
1086
1087 187506 c->opts.av_class = &ff_sws_context_class;
1088 187506 av_opt_set_defaults(c);
1089 187506 atomic_init(&c->stride_unaligned_warned, 0);
1090 187506 atomic_init(&c->data_unaligned_warned, 0);
1091
1092 187506 return &c->opts;
1093 }
1094
1095 ✗ static uint16_t * alloc_gamma_tbl(double e)
1096 {
1097 ✗ int i = 0;
1098 uint16_t * tbl;
1099 ✗ tbl = (uint16_t*)av_malloc(sizeof(uint16_t) * 1 << 16);
1100
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ if (!tbl)
1101 ✗ return NULL;
1102
1103
0/2
✗ Branch 7 → 6 not taken.
✗ Branch 7 → 8 not taken.
✗ for (i = 0; i < 65536; ++i) {
1104 ✗ tbl[i] = pow(i / 65535.0, e) * 65535.0;
1105 }
1106 ✗ return tbl;
1107 }
1108
1109 5705 static enum AVPixelFormat alphaless_fmt(enum AVPixelFormat fmt)
1110 {
1111
19/42
✓ Branch 2 → 3 taken 12 times.
✓ Branch 2 → 4 taken 12 times.
✓ Branch 2 → 5 taken 2 times.
✓ Branch 2 → 6 taken 220 times.
✓ Branch 2 → 7 taken 20 times.
✓ Branch 2 → 8 taken 3668 times.
✓ Branch 2 → 9 taken 3 times.
✓ Branch 2 → 10 taken 936 times.
✓ Branch 2 → 11 taken 51 times.
✓ Branch 2 → 12 taken 1 time.
✗ Branch 2 → 13 not taken.
✓ Branch 2 → 14 taken 1 time.
✗ Branch 2 → 15 not taken.
✗ Branch 2 → 16 not taken.
✗ Branch 2 → 17 not taken.
✓ Branch 2 → 18 taken 1 time.
✗ Branch 2 → 19 not taken.
✓ Branch 2 → 20 taken 1 time.
✓ Branch 2 → 21 taken 10 times.
✓ Branch 2 → 22 taken 1 time.
✗ Branch 2 → 23 not taken.
✓ Branch 2 → 24 taken 10 times.
✗ Branch 2 → 25 not taken.
✗ Branch 2 → 26 not taken.
✗ Branch 2 → 27 not taken.
✗ Branch 2 → 28 not taken.
✗ Branch 2 → 29 not taken.
✗ Branch 2 → 30 not taken.
✗ Branch 2 → 31 not taken.
✗ Branch 2 → 32 not taken.
✗ Branch 2 → 33 not taken.
✗ Branch 2 → 34 not taken.
✗ Branch 2 → 35 not taken.
✗ Branch 2 → 36 not taken.
✗ Branch 2 → 37 not taken.
✗ Branch 2 → 38 not taken.
✗ Branch 2 → 39 not taken.
✗ Branch 2 → 40 not taken.
✗ Branch 2 → 41 not taken.
✓ Branch 2 → 42 taken 10 times.
✓ Branch 2 → 43 taken 4 times.
✓ Branch 2 → 44 taken 742 times.
5705 switch(fmt) {
1112 12 case AV_PIX_FMT_ARGB: return AV_PIX_FMT_RGB24;
1113 12 case AV_PIX_FMT_RGBA: return AV_PIX_FMT_RGB24;
1114 2 case AV_PIX_FMT_ABGR: return AV_PIX_FMT_BGR24;
1115 220 case AV_PIX_FMT_BGRA: return AV_PIX_FMT_BGR24;
1116 20 case AV_PIX_FMT_YA8: return AV_PIX_FMT_GRAY8;
1117
1118 3668 case AV_PIX_FMT_YUVA420P: return AV_PIX_FMT_YUV420P;
1119 3 case AV_PIX_FMT_YUVA422P: return AV_PIX_FMT_YUV422P;
1120 936 case AV_PIX_FMT_YUVA444P: return AV_PIX_FMT_YUV444P;
1121
1122 51 case AV_PIX_FMT_GBRAP: return AV_PIX_FMT_GBRP;
1123
1124 1 case AV_PIX_FMT_GBRAP10LE: return AV_PIX_FMT_GBRP10;
1125 ✗ case AV_PIX_FMT_GBRAP10BE: return AV_PIX_FMT_GBRP10;
1126
1127 1 case AV_PIX_FMT_GBRAP12LE: return AV_PIX_FMT_GBRP12;
1128 ✗ case AV_PIX_FMT_GBRAP12BE: return AV_PIX_FMT_GBRP12;
1129
1130 ✗ case AV_PIX_FMT_GBRAP14LE: return AV_PIX_FMT_GBRP14;
1131 ✗ case AV_PIX_FMT_GBRAP14BE: return AV_PIX_FMT_GBRP14;
1132
1133 1 case AV_PIX_FMT_GBRAP16LE: return AV_PIX_FMT_GBRP16;
1134 ✗ case AV_PIX_FMT_GBRAP16BE: return AV_PIX_FMT_GBRP16;
1135
1136 1 case AV_PIX_FMT_RGBA64LE: return AV_PIX_FMT_RGB48;
1137 10 case AV_PIX_FMT_RGBA64BE: return AV_PIX_FMT_RGB48;
1138 1 case AV_PIX_FMT_BGRA64LE: return AV_PIX_FMT_BGR48;
1139 ✗ case AV_PIX_FMT_BGRA64BE: return AV_PIX_FMT_BGR48;
1140
1141 10 case AV_PIX_FMT_YA16BE: return AV_PIX_FMT_GRAY16;
1142 ✗ case AV_PIX_FMT_YA16LE: return AV_PIX_FMT_GRAY16;
1143
1144 ✗ case AV_PIX_FMT_YUVA420P9BE: return AV_PIX_FMT_YUV420P9;
1145 ✗ case AV_PIX_FMT_YUVA422P9BE: return AV_PIX_FMT_YUV422P9;
1146 ✗ case AV_PIX_FMT_YUVA444P9BE: return AV_PIX_FMT_YUV444P9;
1147 ✗ case AV_PIX_FMT_YUVA420P9LE: return AV_PIX_FMT_YUV420P9;
1148 ✗ case AV_PIX_FMT_YUVA422P9LE: return AV_PIX_FMT_YUV422P9;
1149 ✗ case AV_PIX_FMT_YUVA444P9LE: return AV_PIX_FMT_YUV444P9;
1150 ✗ case AV_PIX_FMT_YUVA420P10BE: return AV_PIX_FMT_YUV420P10;
1151 ✗ case AV_PIX_FMT_YUVA422P10BE: return AV_PIX_FMT_YUV422P10;
1152 ✗ case AV_PIX_FMT_YUVA444P10BE: return AV_PIX_FMT_YUV444P10;
1153 ✗ case AV_PIX_FMT_YUVA420P10LE: return AV_PIX_FMT_YUV420P10;
1154 ✗ case AV_PIX_FMT_YUVA422P10LE: return AV_PIX_FMT_YUV422P10;
1155 ✗ case AV_PIX_FMT_YUVA444P10LE: return AV_PIX_FMT_YUV444P10;
1156 ✗ case AV_PIX_FMT_YUVA420P16BE: return AV_PIX_FMT_YUV420P16;
1157 ✗ case AV_PIX_FMT_YUVA422P16BE: return AV_PIX_FMT_YUV422P16;
1158 ✗ case AV_PIX_FMT_YUVA444P16BE: return AV_PIX_FMT_YUV444P16;
1159 ✗ case AV_PIX_FMT_YUVA420P16LE: return AV_PIX_FMT_YUV420P16;
1160 10 case AV_PIX_FMT_YUVA422P16LE: return AV_PIX_FMT_YUV422P16;
1161 4 case AV_PIX_FMT_YUVA444P16LE: return AV_PIX_FMT_YUV444P16;
1162
1163 // case AV_PIX_FMT_AYUV64LE:
1164 // case AV_PIX_FMT_AYUV64BE:
1165 // case AV_PIX_FMT_PAL8:
1166 742 default: return AV_PIX_FMT_NONE;
1167 }
1168 }
1169
1170 326708 static int scaler_flag(SwsScaler scaler, int fallback)
1171 {
1172
2/9
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 4 not taken.
✗ Branch 2 → 5 not taken.
✗ Branch 2 → 6 not taken.
✗ Branch 2 → 7 not taken.
✗ Branch 2 → 8 not taken.
✓ Branch 2 → 9 taken 3 times.
✗ Branch 2 → 10 not taken.
✓ Branch 2 → 11 taken 326705 times.
326708 switch (scaler) {
1173 ✗ case SWS_SCALE_BILINEAR: return SWS_BILINEAR; break;
1174 ✗ case SWS_SCALE_BICUBIC: return SWS_BICUBIC; break;
1175 ✗ case SWS_SCALE_POINT: return SWS_POINT; break;
1176 ✗ case SWS_SCALE_AREA: return SWS_AREA; break;
1177 ✗ case SWS_SCALE_GAUSSIAN: return SWS_GAUSS; break;
1178 ✗ case SWS_SCALE_SINC: return SWS_SINC; break;
1179 3 case SWS_SCALE_LANCZOS: return SWS_LANCZOS; break;
1180 ✗ case SWS_SCALE_SPLINE: return SWS_SPLINE; break;
1181 326705 default:
1182 326705 return fallback;
1183 }
1184 }
1185
1186 163354 av_cold int ff_sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter,
1187 SwsFilter *dstFilter)
1188 {
1189 int i;
1190 int usesVFilter, usesHFilter;
1191 int unscaled;
1192 163354 SwsInternal *c = sws_internal(sws);
1193 163354 SwsFilter dummyFilter = { NULL, NULL, NULL, NULL };
1194 163354 int srcW = sws->src_w;
1195 163354 int srcH = sws->src_h;
1196 163354 int dstW = sws->dst_w;
1197 163354 int dstH = sws->dst_h;
1198 163354 int dst_stride = FFALIGN(dstW * sizeof(int16_t) + 66, 16);
1199 int flags, cpu_flags;
1200 enum AVPixelFormat srcFormat, dstFormat;
1201 const AVPixFmtDescriptor *desc_src;
1202 const AVPixFmtDescriptor *desc_dst;
1203 163354 int ret = 0;
1204 enum AVPixelFormat tmpFmt;
1205 static const float float_mult = 1.0f / 255.0f;
1206
1207 163354 cpu_flags = av_get_cpu_flags();
1208 163354 flags = sws->flags;
1209 163354 emms_c();
1210
1211
4/4
✓ Branch 5 → 6 taken 110493 times.
✓ Branch 5 → 8 taken 52861 times.
✓ Branch 6 → 7 taken 93178 times.
✓ Branch 6 → 8 taken 17315 times.
163354 unscaled = (srcW == dstW && srcH == dstH);
1212
1213
3/6
✓ Branch 9 → 10 taken 163354 times.
✗ Branch 9 → 13 not taken.
✓ Branch 10 → 11 taken 163354 times.
✗ Branch 10 → 13 not taken.
✓ Branch 11 → 12 taken 163354 times.
✗ Branch 11 → 13 not taken.
163354 if (!c->contrast && !c->saturation && !c->dstFormatBpp)
1214 163354 sws_setColorspaceDetails(sws, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT], sws->src_range,
1215 ff_yuv2rgb_coeffs[SWS_CS_DEFAULT],
1216 sws->dst_range, 0, 1 << 16, 1 << 16);
1217
1218 163354 ret = handle_formats(sws);
1219
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 163354 times.
163354 if (ret < 0)
1220 ✗ return ret;
1221 163354 srcFormat = sws->src_format;
1222 163354 dstFormat = sws->dst_format;
1223 163354 desc_src = av_pix_fmt_desc_get(srcFormat);
1224 163354 desc_dst = av_pix_fmt_desc_get(dstFormat);
1225
1226 // If the source has no alpha then disable alpha blendaway
1227
2/2
✓ Branch 18 → 19 taken 4020 times.
✓ Branch 18 → 20 taken 159334 times.
163354 if (c->src0Alpha)
1228 4020 sws->alpha_blend = SWS_ALPHA_BLEND_NONE;
1229
1230
5/6
✓ Branch 20 → 21 taken 93178 times.
✓ Branch 20 → 25 taken 70176 times.
✓ Branch 22 → 23 taken 1302 times.
✓ Branch 22 → 25 taken 91876 times.
✓ Branch 24 → 25 taken 1302 times.
✗ Branch 24 → 35 not taken.
164656 if (!(unscaled && sws_isSupportedEndiannessConversion(srcFormat) &&
1231 1302 av_pix_fmt_swap_endianness(srcFormat) == dstFormat)) {
1232
1/2
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 30 taken 163354 times.
163354 if (!sws_isSupportedInput(srcFormat)) {
1233 ✗ av_log(c, AV_LOG_ERROR, "%s is not supported as input pixel format\n",
1234 av_get_pix_fmt_name(srcFormat));
1235 ✗ return AVERROR(EINVAL);
1236 }
1237
1/2
✗ Branch 31 → 32 not taken.
✓ Branch 31 → 35 taken 163354 times.
163354 if (!sws_isSupportedOutput(dstFormat)) {
1238 ✗ av_log(c, AV_LOG_ERROR, "%s is not supported as output pixel format\n",
1239 av_get_pix_fmt_name(dstFormat));
1240 ✗ return AVERROR(EINVAL);
1241 }
1242 }
1243 av_assert2(desc_src && desc_dst);
1244
1245 163354 i = flags & (SWS_POINT |
1246 SWS_AREA |
1247 SWS_BILINEAR |
1248 SWS_FAST_BILINEAR |
1249 SWS_BICUBIC |
1250 SWS_X |
1251 SWS_GAUSS |
1252 SWS_LANCZOS |
1253 SWS_SINC |
1254 SWS_SPLINE |
1255 SWS_BICUBLIN);
1256
1257 /* provide a default scaler if not set by caller */
1258
2/2
✓ Branch 35 → 36 taken 5690 times.
✓ Branch 35 → 44 taken 157664 times.
163354 if (!i) {
1259
4/4
✓ Branch 36 → 37 taken 4 times.
✓ Branch 36 → 39 taken 5686 times.
✓ Branch 37 → 38 taken 2 times.
✓ Branch 37 → 39 taken 2 times.
5690 if (dstW < srcW && dstH < srcH)
1260 2 i = SWS_BICUBIC;
1261
3/4
✓ Branch 39 → 40 taken 4 times.
✓ Branch 39 → 42 taken 5684 times.
✓ Branch 40 → 41 taken 4 times.
✗ Branch 40 → 42 not taken.
5688 else if (dstW > srcW && dstH > srcH)
1262 4 i = SWS_BICUBIC;
1263 else
1264 5684 i = SWS_BICUBIC;
1265 5690 flags |= i;
1266 5690 sws->flags = flags;
1267
1/2
✗ Branch 44 → 45 not taken.
✓ Branch 44 → 47 taken 157664 times.
157664 } else if (i & (i - 1)) {
1268 ✗ av_log(c, AV_LOG_ERROR,
1269 "Exactly one scaler algorithm must be chosen, got %X\n", i);
1270 ✗ return AVERROR(EINVAL);
1271 }
1272
1273
2/2
✓ Branch 47 → 48 taken 2 times.
✓ Branch 47 → 52 taken 163352 times.
163354 if (i == SWS_FAST_BILINEAR) {
1274 /* the fast bilinear scalers keep the source position in 16.16 fixed point */
1275
4/6
✓ Branch 48 → 49 taken 2 times.
✗ Branch 48 → 51 not taken.
✓ Branch 49 → 50 taken 2 times.
✗ Branch 49 → 51 not taken.
✓ Branch 50 → 51 taken 1 time.
✓ Branch 50 → 52 taken 1 time.
2 if (srcW < 8 || dstW <= 8 || srcW >= 65536) {
1276 1 i = SWS_BILINEAR;
1277 1 flags ^= SWS_FAST_BILINEAR | i;
1278 1 sws->flags = flags;
1279 }
1280 }
1281
1282
2/2
✓ Branch 52 → 53 taken 1 time.
✓ Branch 52 → 54 taken 163353 times.
163354 SwsScaler scaler_sub = sws->scaler_sub ? sws->scaler_sub : sws->scaler;
1283
2/2
✓ Branch 55 → 56 taken 163353 times.
✓ Branch 55 → 57 taken 1 time.
163354 int lum_scaler = scaler_flag(sws->scaler, i == SWS_BICUBLIN ? SWS_BICUBIC : i);
1284
2/2
✓ Branch 59 → 60 taken 163353 times.
✓ Branch 59 → 61 taken 1 time.
163354 int chr_scaler = scaler_flag(scaler_sub, i == SWS_BICUBLIN ? SWS_BILINEAR : i);
1285
2/2
✓ Branch 64 → 65 taken 1 time.
✓ Branch 64 → 67 taken 163352 times.
163355 const int info_scaler = sws->scaler == SWS_SCALE_AUTO &&
1286
1/2
✗ Branch 65 → 66 not taken.
✓ Branch 65 → 67 taken 1 time.
1 i == SWS_BICUBLIN &&
1287
2/2
✓ Branch 63 → 64 taken 163353 times.
✓ Branch 63 → 67 taken 1 time.
163354 chr_scaler == SWS_BILINEAR ? i : lum_scaler;
1288
1289 /* sanity check */
1290
4/8
✓ Branch 68 → 69 taken 163354 times.
✗ Branch 68 → 72 not taken.
✓ Branch 69 → 70 taken 163354 times.
✗ Branch 69 → 72 not taken.
✓ Branch 70 → 71 taken 163354 times.
✗ Branch 70 → 72 not taken.
✗ Branch 71 → 72 not taken.
✓ Branch 71 → 74 taken 163354 times.
163354 if (srcW < 1 || srcH < 1 || dstW < 1 || dstH < 1) {
1291 /* FIXME check if these are enough and try to lower them after
1292 * fixing the relevant parts of the code */
1293 ✗ av_log(c, AV_LOG_ERROR, "%dx%d -> %dx%d is invalid scaling dimension\n",
1294 srcW, srcH, dstW, dstH);
1295 ✗ return AVERROR(EINVAL);
1296 }
1297
1298 163354 ret = av_image_check_size2(srcW, srcH, INT64_MAX, AV_PIX_FMT_NONE, 0, c);
1299
1/2
✓ Branch 75 → 76 taken 163354 times.
✗ Branch 75 → 77 not taken.
163354 if (ret >= 0)
1300 163354 ret = av_image_check_size2(dstW, dstH, INT64_MAX, AV_PIX_FMT_NONE, 0, c);
1301
1/2
✗ Branch 77 → 78 not taken.
✓ Branch 77 → 79 taken 163354 times.
163354 if (ret < 0)
1302 ✗ return ret;
1303
1304
2/2
✓ Branch 79 → 80 taken 163351 times.
✓ Branch 79 → 81 taken 3 times.
163354 if (!dstFilter)
1305 163351 dstFilter = &dummyFilter;
1306
2/2
✓ Branch 81 → 82 taken 163351 times.
✓ Branch 81 → 83 taken 3 times.
163354 if (!srcFilter)
1307 163351 srcFilter = &dummyFilter;
1308
1309 163354 int64_t lumXInc = (((int64_t)srcW << 16) + (dstW >> 1)) / dstW;
1310 163354 int64_t lumYInc = (((int64_t)srcH << 16) + (dstH >> 1)) / dstH;
1311 163354 c->dstFormatBpp = av_get_bits_per_pixel(desc_dst);
1312 163354 c->srcFormatBpp = av_get_bits_per_pixel(desc_src);
1313 163354 c->vRounder = 4 * 0x0001000100010001ULL;
1314
1315
0/2
✗ Branch 86 → 87 not taken.
✗ Branch 86 → 93 not taken.
✗ usesVFilter = (srcFilter->lumV && srcFilter->lumV->length > 1) ||
1316
1/4
✗ Branch 87 → 88 not taken.
✓ Branch 87 → 89 taken 163354 times.
✗ Branch 88 → 89 not taken.
✗ Branch 88 → 93 not taken.
163354 (srcFilter->chrV && srcFilter->chrV->length > 1) ||
1317
2/6
✗ Branch 85 → 86 not taken.
✓ Branch 85 → 87 taken 163354 times.
✗ Branch 89 → 90 not taken.
✓ Branch 89 → 91 taken 163354 times.
✗ Branch 90 → 91 not taken.
✗ Branch 90 → 93 not taken.
490062 (dstFilter->lumV && dstFilter->lumV->length > 1) ||
1318
1/4
✗ Branch 91 → 92 not taken.
✓ Branch 91 → 94 taken 163354 times.
✗ Branch 92 → 93 not taken.
✗ Branch 92 → 94 not taken.
163354 (dstFilter->chrV && dstFilter->chrV->length > 1);
1319
0/2
✗ Branch 96 → 97 not taken.
✗ Branch 96 → 103 not taken.
✗ usesHFilter = (srcFilter->lumH && srcFilter->lumH->length > 1) ||
1320
1/4
✗ Branch 97 → 98 not taken.
✓ Branch 97 → 99 taken 163354 times.
✗ Branch 98 → 99 not taken.
✗ Branch 98 → 103 not taken.
163354 (srcFilter->chrH && srcFilter->chrH->length > 1) ||
1321
2/6
✗ Branch 95 → 96 not taken.
✓ Branch 95 → 97 taken 163354 times.
✗ Branch 99 → 100 not taken.
✓ Branch 99 → 101 taken 163354 times.
✗ Branch 100 → 101 not taken.
✗ Branch 100 → 103 not taken.
490062 (dstFilter->lumH && dstFilter->lumH->length > 1) ||
1322
1/4
✗ Branch 101 → 102 not taken.
✓ Branch 101 → 104 taken 163354 times.
✗ Branch 102 → 103 not taken.
✗ Branch 102 → 104 not taken.
163354 (dstFilter->chrH && dstFilter->chrH->length > 1);
1323
1324 163354 av_pix_fmt_get_chroma_sub_sample(srcFormat, &c->chrSrcHSubSample, &c->chrSrcVSubSample);
1325 163354 av_pix_fmt_get_chroma_sub_sample(dstFormat, &c->chrDstHSubSample, &c->chrDstVSubSample);
1326
1327 163354 c->dst_slice_align = 1 << c->chrDstVSubSample;
1328
1329
4/4
✓ Branch 108 → 109 taken 37659 times.
✓ Branch 108 → 119 taken 125695 times.
✓ Branch 109 → 110 taken 29969 times.
✓ Branch 109 → 119 taken 7690 times.
163354 if (isAnyRGB(dstFormat) && !(flags&SWS_FULL_CHR_H_INT)) {
1330
2/2
✓ Branch 110 → 111 taken 50 times.
✓ Branch 110 → 113 taken 29919 times.
29969 if (dstW&1) {
1331 50 av_log(c, AV_LOG_DEBUG, "Forcing full internal H chroma due to odd output size\n");
1332 50 flags |= SWS_FULL_CHR_H_INT;
1333 50 sws->flags = flags;
1334 }
1335
1336
2/2
✓ Branch 113 → 114 taken 2137 times.
✓ Branch 113 → 119 taken 27832 times.
29969 if ( c->chrSrcHSubSample == 0
1337
2/2
✓ Branch 114 → 115 taken 1999 times.
✓ Branch 114 → 119 taken 138 times.
2137 && c->chrSrcVSubSample == 0
1338
1/2
✓ Branch 115 → 116 taken 1999 times.
✗ Branch 115 → 119 not taken.
1999 && sws->dither != SWS_DITHER_BAYER //SWS_FULL_CHR_H_INT is currently not supported with SWS_DITHER_BAYER
1339
1/2
✓ Branch 116 → 117 taken 1999 times.
✗ Branch 116 → 119 not taken.
1999 && !(sws->flags & SWS_FAST_BILINEAR)
1340 ) {
1341 1999 av_log(c, AV_LOG_DEBUG, "Forcing full internal H chroma due to input having non subsampled chroma\n");
1342 1999 flags |= SWS_FULL_CHR_H_INT;
1343 1999 sws->flags = flags;
1344 }
1345 }
1346
1347
2/2
✓ Branch 119 → 120 taken 131880 times.
✓ Branch 119 → 122 taken 31474 times.
163354 if (sws->dither == SWS_DITHER_AUTO) {
1348
1/2
✗ Branch 120 → 121 not taken.
✓ Branch 120 → 122 taken 131880 times.
131880 if (flags & SWS_ERROR_DIFFUSION)
1349 ✗ sws->dither = SWS_DITHER_ED;
1350 }
1351
1352
4/4
✓ Branch 122 → 123 taken 163286 times.
✓ Branch 122 → 126 taken 68 times.
✓ Branch 123 → 124 taken 163217 times.
✓ Branch 123 → 126 taken 69 times.
163354 if(dstFormat == AV_PIX_FMT_BGR4_BYTE ||
1353
2/2
✓ Branch 124 → 125 taken 163132 times.
✓ Branch 124 → 126 taken 85 times.
163217 dstFormat == AV_PIX_FMT_RGB4_BYTE ||
1354
2/2
✓ Branch 125 → 126 taken 71 times.
✓ Branch 125 → 144 taken 163061 times.
163132 dstFormat == AV_PIX_FMT_BGR8 ||
1355 dstFormat == AV_PIX_FMT_RGB8) {
1356
1/2
✓ Branch 126 → 127 taken 293 times.
✗ Branch 126 → 131 not taken.
293 if (sws->dither == SWS_DITHER_AUTO)
1357
2/2
✓ Branch 127 → 128 taken 59 times.
✓ Branch 127 → 129 taken 234 times.
293 sws->dither = (flags & SWS_FULL_CHR_H_INT) ? SWS_DITHER_ED : SWS_DITHER_BAYER;
1358
2/2
✓ Branch 131 → 132 taken 234 times.
✓ Branch 131 → 139 taken 59 times.
293 if (!(flags & SWS_FULL_CHR_H_INT)) {
1359
4/8
✓ Branch 132 → 133 taken 234 times.
✗ Branch 132 → 136 not taken.
✓ Branch 133 → 134 taken 234 times.
✗ Branch 133 → 136 not taken.
✓ Branch 134 → 135 taken 234 times.
✗ Branch 134 → 136 not taken.
✗ Branch 135 → 136 not taken.
✓ Branch 135 → 139 taken 234 times.
234 if (sws->dither == SWS_DITHER_ED || sws->dither == SWS_DITHER_A_DITHER || sws->dither == SWS_DITHER_X_DITHER || sws->dither == SWS_DITHER_NONE) {
1360 ✗ av_log(c, AV_LOG_DEBUG,
1361 "Desired dithering only supported in full chroma interpolation for destination format '%s'\n",
1362 av_get_pix_fmt_name(dstFormat));
1363 ✗ flags |= SWS_FULL_CHR_H_INT;
1364 ✗ sws->flags = flags;
1365 }
1366 }
1367
2/2
✓ Branch 139 → 140 taken 59 times.
✓ Branch 139 → 144 taken 234 times.
293 if (flags & SWS_FULL_CHR_H_INT) {
1368
1/2
✗ Branch 140 → 141 not taken.
✓ Branch 140 → 144 taken 59 times.
59 if (sws->dither == SWS_DITHER_BAYER) {
1369 ✗ av_log(c, AV_LOG_DEBUG,
1370 "Ordered dither is not supported in full chroma interpolation for destination format '%s'\n",
1371 av_get_pix_fmt_name(dstFormat));
1372 ✗ sws->dither = SWS_DITHER_ED;
1373 }
1374 }
1375 }
1376
2/2
✓ Branch 145 → 146 taken 6892 times.
✓ Branch 145 → 150 taken 156462 times.
163354 if (isPlanarRGB(dstFormat)) {
1377
2/2
✓ Branch 146 → 147 taken 1673 times.
✓ Branch 146 → 150 taken 5219 times.
6892 if (!(flags & SWS_FULL_CHR_H_INT)) {
1378 1673 av_log(c, AV_LOG_DEBUG,
1379 "%s output is not supported with half chroma resolution, switching to full\n",
1380 av_get_pix_fmt_name(dstFormat));
1381 1673 flags |= SWS_FULL_CHR_H_INT;
1382 1673 sws->flags = flags;
1383 }
1384 }
1385
1386 /* reuse chroma for 2 pixels RGB/BGR unless user wants full
1387 * chroma interpolation */
1388
3/4
✓ Branch 150 → 151 taken 11366 times.
✓ Branch 150 → 178 taken 151988 times.
✓ Branch 152 → 153 taken 11366 times.
✗ Branch 152 → 178 not taken.
174720 if (flags & SWS_FULL_CHR_H_INT &&
1389
2/2
✓ Branch 154 → 155 taken 4474 times.
✓ Branch 154 → 178 taken 6892 times.
22732 isAnyRGB(dstFormat) &&
1390
2/2
✓ Branch 155 → 156 taken 4460 times.
✓ Branch 155 → 178 taken 14 times.
15840 !isPlanarRGB(dstFormat) &&
1391
2/2
✓ Branch 156 → 157 taken 4447 times.
✓ Branch 156 → 178 taken 13 times.
4460 dstFormat != AV_PIX_FMT_RGBA64LE &&
1392
2/2
✓ Branch 157 → 158 taken 4433 times.
✓ Branch 157 → 178 taken 14 times.
4447 dstFormat != AV_PIX_FMT_RGBA64BE &&
1393
2/2
✓ Branch 158 → 159 taken 4420 times.
✓ Branch 158 → 178 taken 13 times.
4433 dstFormat != AV_PIX_FMT_BGRA64LE &&
1394
2/2
✓ Branch 159 → 160 taken 3654 times.
✓ Branch 159 → 178 taken 766 times.
4420 dstFormat != AV_PIX_FMT_BGRA64BE &&
1395
2/2
✓ Branch 160 → 161 taken 3639 times.
✓ Branch 160 → 178 taken 15 times.
3654 dstFormat != AV_PIX_FMT_RGB48LE &&
1396
2/2
✓ Branch 161 → 162 taken 3625 times.
✓ Branch 161 → 178 taken 14 times.
3639 dstFormat != AV_PIX_FMT_RGB48BE &&
1397
2/2
✓ Branch 162 → 163 taken 3612 times.
✓ Branch 162 → 178 taken 13 times.
3625 dstFormat != AV_PIX_FMT_BGR48LE &&
1398
2/2
✓ Branch 163 → 164 taken 3515 times.
✓ Branch 163 → 178 taken 97 times.
3612 dstFormat != AV_PIX_FMT_BGR48BE &&
1399
2/2
✓ Branch 164 → 165 taken 3467 times.
✓ Branch 164 → 178 taken 48 times.
3515 dstFormat != AV_PIX_FMT_RGBA &&
1400
2/2
✓ Branch 165 → 166 taken 2903 times.
✓ Branch 165 → 178 taken 564 times.
3467 dstFormat != AV_PIX_FMT_ARGB &&
1401
2/2
✓ Branch 166 → 167 taken 2875 times.
✓ Branch 166 → 178 taken 28 times.
2903 dstFormat != AV_PIX_FMT_BGRA &&
1402
2/2
✓ Branch 167 → 168 taken 1103 times.
✓ Branch 167 → 178 taken 1772 times.
2875 dstFormat != AV_PIX_FMT_ABGR &&
1403
2/2
✓ Branch 168 → 169 taken 951 times.
✓ Branch 168 → 178 taken 152 times.
1103 dstFormat != AV_PIX_FMT_RGB24 &&
1404
2/2
✓ Branch 169 → 170 taken 937 times.
✓ Branch 169 → 178 taken 14 times.
951 dstFormat != AV_PIX_FMT_BGR24 &&
1405
2/2
✓ Branch 170 → 171 taken 923 times.
✓ Branch 170 → 178 taken 14 times.
937 dstFormat != AV_PIX_FMT_BGR4_BYTE &&
1406
2/2
✓ Branch 171 → 172 taken 907 times.
✓ Branch 171 → 178 taken 16 times.
923 dstFormat != AV_PIX_FMT_RGB4_BYTE &&
1407
2/2
✓ Branch 172 → 173 taken 892 times.
✓ Branch 172 → 178 taken 15 times.
907 dstFormat != AV_PIX_FMT_BGR8 &&
1408
2/2
✓ Branch 173 → 174 taken 769 times.
✓ Branch 173 → 178 taken 123 times.
892 dstFormat != AV_PIX_FMT_RGB8 &&
1409
2/2
✓ Branch 174 → 175 taken 646 times.
✓ Branch 174 → 178 taken 123 times.
769 dstFormat != AV_PIX_FMT_X2RGB10LE &&
1410 dstFormat != AV_PIX_FMT_X2BGR10LE
1411 ) {
1412 646 av_log(c, AV_LOG_WARNING,
1413 "full chroma interpolation for destination format '%s' not yet implemented\n",
1414 av_get_pix_fmt_name(dstFormat));
1415 646 flags &= ~SWS_FULL_CHR_H_INT;
1416 646 sws->flags = flags;
1417 }
1418
4/4
✓ Branch 179 → 180 taken 37659 times.
✓ Branch 179 → 182 taken 125695 times.
✓ Branch 180 → 181 taken 26939 times.
✓ Branch 180 → 182 taken 10720 times.
163354 if (isAnyRGB(dstFormat) && !(flags & SWS_FULL_CHR_H_INT))
1419 26939 c->chrDstHSubSample = 1;
1420
1421 // drop some chroma lines if the user wants it
1422 163354 c->vChrDrop = (flags & SWS_SRC_V_CHR_DROP_MASK) >>
1423 SWS_SRC_V_CHR_DROP_SHIFT;
1424 163354 c->chrSrcVSubSample += c->vChrDrop;
1425
1426 /* drop every other pixel for chroma calculation unless user
1427 * wants full chroma */
1428
7/8
✓ Branch 183 → 184 taken 66024 times.
✓ Branch 183 → 225 taken 97330 times.
✓ Branch 184 → 185 taken 65661 times.
✓ Branch 184 → 225 taken 363 times.
✓ Branch 185 → 186 taken 65661 times.
✗ Branch 185 → 225 not taken.
✓ Branch 186 → 187 taken 64705 times.
✓ Branch 186 → 225 taken 956 times.
163354 if (isAnyRGB(srcFormat) && !(srcW & 1) && !(flags & SWS_FULL_CHR_H_INP) &&
1429
3/4
✓ Branch 187 → 188 taken 63723 times.
✓ Branch 187 → 225 taken 982 times.
✓ Branch 188 → 189 taken 63723 times.
✗ Branch 188 → 225 not taken.
64705 srcFormat != AV_PIX_FMT_RGB8 && srcFormat != AV_PIX_FMT_BGR8 &&
1430
3/4
✓ Branch 189 → 190 taken 63723 times.
✗ Branch 189 → 225 not taken.
✓ Branch 190 → 191 taken 62779 times.
✓ Branch 190 → 225 taken 944 times.
63723 srcFormat != AV_PIX_FMT_RGB4 && srcFormat != AV_PIX_FMT_BGR4 &&
1431
4/4
✓ Branch 191 → 192 taken 61752 times.
✓ Branch 191 → 225 taken 1027 times.
✓ Branch 192 → 193 taken 60756 times.
✓ Branch 192 → 225 taken 996 times.
62779 srcFormat != AV_PIX_FMT_RGB4_BYTE && srcFormat != AV_PIX_FMT_BGR4_BYTE &&
1432
4/4
✓ Branch 193 → 194 taken 59822 times.
✓ Branch 193 → 225 taken 934 times.
✓ Branch 194 → 195 taken 58737 times.
✓ Branch 194 → 225 taken 1085 times.
60756 srcFormat != AV_PIX_FMT_GBRP9BE && srcFormat != AV_PIX_FMT_GBRP9LE &&
1433
4/4
✓ Branch 195 → 196 taken 56687 times.
✓ Branch 195 → 225 taken 2050 times.
✓ Branch 196 → 197 taken 55750 times.
✓ Branch 196 → 225 taken 937 times.
58737 srcFormat != AV_PIX_FMT_GBRP10BE && srcFormat != AV_PIX_FMT_GBRP10LE &&
1434
4/4
✓ Branch 197 → 198 taken 54778 times.
✓ Branch 197 → 225 taken 972 times.
✓ Branch 198 → 199 taken 54158 times.
✓ Branch 198 → 225 taken 620 times.
55750 srcFormat != AV_PIX_FMT_GBRP10MSBBE && srcFormat != AV_PIX_FMT_GBRP10MSBLE &&
1435
4/4
✓ Branch 199 → 200 taken 53425 times.
✓ Branch 199 → 225 taken 733 times.
✓ Branch 200 → 201 taken 52396 times.
✓ Branch 200 → 225 taken 1029 times.
54158 srcFormat != AV_PIX_FMT_GBRAP10BE && srcFormat != AV_PIX_FMT_GBRAP10LE &&
1436
4/4
✓ Branch 201 → 202 taken 50422 times.
✓ Branch 201 → 225 taken 1974 times.
✓ Branch 202 → 203 taken 49295 times.
✓ Branch 202 → 225 taken 1127 times.
52396 srcFormat != AV_PIX_FMT_GBRP12BE && srcFormat != AV_PIX_FMT_GBRP12LE &&
1437
4/4
✓ Branch 203 → 204 taken 48281 times.
✓ Branch 203 → 225 taken 1014 times.
✓ Branch 204 → 205 taken 47635 times.
✓ Branch 204 → 225 taken 646 times.
49295 srcFormat != AV_PIX_FMT_GBRP12MSBBE && srcFormat != AV_PIX_FMT_GBRP12MSBLE &&
1438
4/4
✓ Branch 205 → 206 taken 46932 times.
✓ Branch 205 → 225 taken 703 times.
✓ Branch 206 → 207 taken 46289 times.
✓ Branch 206 → 225 taken 643 times.
47635 srcFormat != AV_PIX_FMT_GBRAP12BE && srcFormat != AV_PIX_FMT_GBRAP12LE &&
1439
4/4
✓ Branch 207 → 208 taken 45723 times.
✓ Branch 207 → 225 taken 566 times.
✓ Branch 208 → 209 taken 44678 times.
✓ Branch 208 → 225 taken 1045 times.
46289 srcFormat != AV_PIX_FMT_GBRAP14BE && srcFormat != AV_PIX_FMT_GBRAP14LE &&
1440
4/4
✓ Branch 209 → 210 taken 43778 times.
✓ Branch 209 → 225 taken 900 times.
✓ Branch 210 → 211 taken 42603 times.
✓ Branch 210 → 225 taken 1175 times.
44678 srcFormat != AV_PIX_FMT_GBRP14BE && srcFormat != AV_PIX_FMT_GBRP14LE &&
1441
4/4
✓ Branch 211 → 212 taken 41292 times.
✓ Branch 211 → 225 taken 1311 times.
✓ Branch 212 → 213 taken 40303 times.
✓ Branch 212 → 225 taken 989 times.
42603 srcFormat != AV_PIX_FMT_GBRP16BE && srcFormat != AV_PIX_FMT_GBRP16LE &&
1442
4/4
✓ Branch 213 → 214 taken 39306 times.
✓ Branch 213 → 225 taken 997 times.
✓ Branch 214 → 215 taken 39305 times.
✓ Branch 214 → 225 taken 1 time.
40303 srcFormat != AV_PIX_FMT_GBRAP16BE && srcFormat != AV_PIX_FMT_GBRAP16LE &&
1443
4/4
✓ Branch 215 → 216 taken 39242 times.
✓ Branch 215 → 225 taken 63 times.
✓ Branch 216 → 217 taken 39241 times.
✓ Branch 216 → 225 taken 1 time.
39305 srcFormat != AV_PIX_FMT_GBRPF32BE && srcFormat != AV_PIX_FMT_GBRPF32LE &&
1444
3/4
✓ Branch 217 → 218 taken 39240 times.
✓ Branch 217 → 225 taken 1 time.
✓ Branch 218 → 219 taken 39240 times.
✗ Branch 218 → 225 not taken.
39241 srcFormat != AV_PIX_FMT_GBRAPF32BE && srcFormat != AV_PIX_FMT_GBRAPF32LE &&
1445
3/4
✓ Branch 219 → 220 taken 39021 times.
✓ Branch 219 → 225 taken 219 times.
✓ Branch 220 → 221 taken 39021 times.
✗ Branch 220 → 225 not taken.
39240 srcFormat != AV_PIX_FMT_GBRPF16BE && srcFormat != AV_PIX_FMT_GBRPF16LE &&
1446
2/2
✓ Branch 221 → 222 taken 38976 times.
✓ Branch 221 → 225 taken 45 times.
39021 srcFormat != AV_PIX_FMT_GBRAPF16BE && srcFormat != AV_PIX_FMT_GBRAPF16LE &&
1447
2/2
✓ Branch 222 → 223 taken 37479 times.
✓ Branch 222 → 224 taken 1497 times.
38976 ((dstW >> c->chrDstHSubSample) <= (srcW >> 1) ||
1448
1/2
✗ Branch 223 → 224 not taken.
✓ Branch 223 → 225 taken 37479 times.
37479 (flags & SWS_FAST_BILINEAR)))
1449 1497 c->chrSrcHSubSample = 1;
1450
1451 // Note the AV_CEIL_RSHIFT is so that we always round toward +inf.
1452 163354 c->chrSrcW = AV_CEIL_RSHIFT(srcW, c->chrSrcHSubSample);
1453 163354 c->chrSrcH = AV_CEIL_RSHIFT(srcH, c->chrSrcVSubSample);
1454 163354 c->chrDstW = AV_CEIL_RSHIFT(dstW, c->chrDstHSubSample);
1455 163354 c->chrDstH = AV_CEIL_RSHIFT(dstH, c->chrDstVSubSample);
1456
1457
1/2
✗ Branch 226 → 227 not taken.
✓ Branch 226 → 228 taken 163354 times.
163354 if (!FF_ALLOCZ_TYPED_ARRAY(c->formatConvBuffer, FFALIGN(srcW * 2 + 78, 16) * 2))
1458 ✗ goto nomem;
1459
1460 163354 c->srcBpc = desc_src->comp[0].depth;
1461
2/2
✓ Branch 228 → 229 taken 18065 times.
✓ Branch 228 → 230 taken 145289 times.
163354 if (c->srcBpc < 8)
1462 18065 c->srcBpc = 8;
1463 163354 c->dstBpc = desc_dst->comp[0].depth;
1464
2/2
✓ Branch 230 → 231 taken 14940 times.
✓ Branch 230 → 232 taken 148414 times.
163354 if (c->dstBpc < 8)
1465 14940 c->dstBpc = 8;
1466
4/4
✓ Branch 233 → 234 taken 97330 times.
✓ Branch 233 → 235 taken 66024 times.
✓ Branch 234 → 235 taken 827 times.
✓ Branch 234 → 236 taken 96503 times.
163354 if (isAnyRGB(srcFormat) || srcFormat == AV_PIX_FMT_PAL8)
1467 66851 c->srcBpc = 16;
1468
2/2
✓ Branch 236 → 237 taken 5729 times.
✓ Branch 236 → 238 taken 157625 times.
163354 if (c->dstBpc == 16)
1469 5729 dst_stride <<= 1;
1470
1471
6/6
✓ Branch 238 → 239 taken 132349 times.
✓ Branch 238 → 263 taken 31005 times.
✓ Branch 239 → 240 taken 36981 times.
✓ Branch 239 → 263 taken 95368 times.
✓ Branch 240 → 241 taken 36404 times.
✓ Branch 240 → 263 taken 577 times.
163354 if (INLINE_MMXEXT(cpu_flags) && c->srcBpc == 8 && c->dstBpc <= 14) {
1472
2/2
✓ Branch 242 → 243 taken 31568 times.
✓ Branch 242 → 246 taken 2220 times.
33788 c->canMMXEXTBeUsed = dstW >= srcW && (dstW & 31) == 0 &&
1473
4/4
✓ Branch 241 → 242 taken 33788 times.
✓ Branch 241 → 246 taken 2616 times.
✓ Branch 243 → 244 taken 31328 times.
✓ Branch 243 → 246 taken 240 times.
101520 c->chrDstW >= c->chrSrcW &&
1474
1/2
✓ Branch 244 → 245 taken 31328 times.
✗ Branch 244 → 246 not taken.
31328 (srcW & 15) == 0;
1475
8/8
✓ Branch 247 → 248 taken 5076 times.
✓ Branch 247 → 254 taken 31328 times.
✓ Branch 248 → 249 taken 2460 times.
✓ Branch 248 → 254 taken 2616 times.
✓ Branch 249 → 250 taken 2172 times.
✓ Branch 249 → 254 taken 288 times.
✓ Branch 250 → 251 taken 372 times.
✓ Branch 250 → 254 taken 1800 times.
36404 if (!c->canMMXEXTBeUsed && dstW >= srcW && c->chrDstW >= c->chrSrcW && (srcW & 15) == 0
1476
1477
1/2
✗ Branch 251 → 252 not taken.
✓ Branch 251 → 254 taken 372 times.
372 && (flags & SWS_FAST_BILINEAR)) {
1478
0/2
✗ Branch 252 → 253 not taken.
✗ Branch 252 → 254 not taken.
✗ if (flags & SWS_PRINT_INFO)
1479 ✗ av_log(c, AV_LOG_INFO,
1480 "output width is not a multiple of 32 -> no MMXEXT scaler\n");
1481 }
1482
4/8
✓ Branch 254 → 255 taken 36404 times.
✗ Branch 254 → 261 not taken.
✓ Branch 256 → 257 taken 36404 times.
✗ Branch 256 → 261 not taken.
✓ Branch 258 → 259 taken 36404 times.
✗ Branch 258 → 261 not taken.
✗ Branch 260 → 261 not taken.
✓ Branch 260 → 262 taken 36404 times.
36404 if (usesHFilter || isNBPS(sws->src_format) || is16BPS(sws->src_format) || isAnyRGB(sws->src_format))
1483 ✗ c->canMMXEXTBeUsed = 0;
1484 } else
1485 126950 c->canMMXEXTBeUsed = 0;
1486
1487 163354 int64_t chrXInc = (((int64_t)c->chrSrcW << 16) + (c->chrDstW >> 1)) / c->chrDstW;
1488 163354 int64_t chrYInc = (((int64_t)c->chrSrcH << 16) + (c->chrDstH >> 1)) / c->chrDstH;
1489
1490 /* Match pixel 0 of the src to pixel 0 of dst and match pixel n-2 of src
1491 * to pixel n-2 of dst, but only for the FAST_BILINEAR mode otherwise do
1492 * correct scaling.
1493 * n-2 is the last chrominance sample available.
1494 * This is not perfect, but no one should notice the difference, the more
1495 * correct variant would be like the vertical one, but that would require
1496 * some special code for the first and last pixel */
1497
2/2
✓ Branch 264 → 265 taken 1 time.
✓ Branch 264 → 270 taken 163353 times.
163354 if (flags & SWS_FAST_BILINEAR) {
1498
1/2
✗ Branch 265 → 266 not taken.
✓ Branch 265 → 267 taken 1 time.
1 if (c->canMMXEXTBeUsed) {
1499 ✗ lumXInc += 1;
1500 ✗ chrXInc += 1;
1501 }
1502 // we don't use the x86 asm scaler if MMX is available
1503
1/4
✗ Branch 267 → 268 not taken.
✓ Branch 267 → 270 taken 1 time.
✗ Branch 268 → 269 not taken.
✗ Branch 268 → 270 not taken.
1 else if (INLINE_MMX(cpu_flags) && c->dstBpc <= 14) {
1504 ✗ lumXInc = ((int64_t)(srcW - 2) << 16) / (dstW - 2) - 20;
1505 ✗ chrXInc = ((int64_t)(c->chrSrcW - 2) << 16) / (c->chrDstW - 2) - 20;
1506 }
1507 }
1508
3/6
✓ Branch 270 → 271 taken 163354 times.
✗ Branch 270 → 278 not taken.
✓ Branch 271 → 272 taken 163354 times.
✗ Branch 271 → 278 not taken.
✓ Branch 272 → 273 taken 163354 times.
✗ Branch 272 → 278 not taken.
163354 if (chrXInc < 10 || chrXInc > INT_MAX ||
1509
2/4
✓ Branch 273 → 274 taken 163354 times.
✗ Branch 273 → 278 not taken.
✓ Branch 274 → 275 taken 163354 times.
✗ Branch 274 → 278 not taken.
163354 chrYInc < 10 || chrYInc > INT_MAX ||
1510
2/4
✓ Branch 275 → 276 taken 163354 times.
✗ Branch 275 → 278 not taken.
✓ Branch 276 → 277 taken 163354 times.
✗ Branch 276 → 278 not taken.
163354 lumXInc < 10 || lumXInc > INT_MAX ||
1511
1/2
✗ Branch 277 → 278 not taken.
✓ Branch 277 → 279 taken 163354 times.
163354 lumYInc < 10 || lumYInc > INT_MAX)
1512 ✗ return AVERROR_PATCHWELCOME;
1513
1514 163354 c->lumXInc = lumXInc;
1515 163354 c->lumYInc = lumYInc;
1516 163354 c->chrXInc = chrXInc;
1517 163354 c->chrYInc = chrYInc;
1518
1519
1520 // hardcoded for now
1521 163354 c->gamma_value = 2.2;
1522 163354 tmpFmt = AV_PIX_FMT_RGBA64LE;
1523
1524
3/8
✓ Branch 279 → 280 taken 70176 times.
✓ Branch 279 → 319 taken 93178 times.
✗ Branch 280 → 281 not taken.
✓ Branch 280 → 319 taken 70176 times.
✗ Branch 281 → 282 not taken.
✗ Branch 281 → 283 not taken.
✗ Branch 282 → 283 not taken.
✗ Branch 282 → 319 not taken.
163354 if (!unscaled && sws->gamma_flag && (srcFormat != tmpFmt || dstFormat != tmpFmt)) {
1525 SwsInternal *c2;
1526 ✗ c->cascaded_context[0] = NULL;
1527
1528 ✗ ret = av_image_alloc(c->cascaded_tmp[0], c->cascaded_tmpStride[0],
1529 srcW, srcH, tmpFmt, 64);
1530
0/2
✗ Branch 284 → 285 not taken.
✗ Branch 284 → 286 not taken.
✗ if (ret < 0)
1531 ✗ return ret;
1532
1533 ✗ c->cascaded_context[0] = alloc_set_opts(srcW, srcH, srcFormat,
1534 srcW, srcH, tmpFmt,
1535 ✗ flags, sws->scaler_params);
1536
0/2
✗ Branch 287 → 288 not taken.
✗ Branch 287 → 289 not taken.
✗ if (!c->cascaded_context[0])
1537 ✗ return AVERROR(ENOMEM);
1538 ✗ set_cascade_chr_pos(c->cascaded_context[0], sws, 1, 0);
1539 ✗ ret = sws_init_context(c->cascaded_context[0], NULL, NULL);
1540
0/2
✗ Branch 291 → 292 not taken.
✗ Branch 291 → 293 not taken.
✗ if (ret < 0)
1541 ✗ return ret;
1542
1543 ✗ c->cascaded_context[1] = sws_getContext(srcW, srcH, tmpFmt,
1544 dstW, dstH, tmpFmt,
1545 flags, srcFilter, dstFilter,
1546 ✗ sws->scaler_params);
1547
1548
0/2
✗ Branch 294 → 295 not taken.
✗ Branch 294 → 296 not taken.
✗ if (!c->cascaded_context[1])
1549 ✗ return AVERROR(ENOMEM);
1550
1551 ✗ c2 = sws_internal(c->cascaded_context[1]);
1552 ✗ c2->is_internal_gamma = 1;
1553 ✗ c2->gamma = alloc_gamma_tbl( c->gamma_value);
1554 ✗ c2->inv_gamma = alloc_gamma_tbl(1.f/c->gamma_value);
1555
0/4
✗ Branch 299 → 300 not taken.
✗ Branch 299 → 301 not taken.
✗ Branch 300 → 301 not taken.
✗ Branch 300 → 302 not taken.
✗ if (!c2->gamma || !c2->inv_gamma)
1556 ✗ return AVERROR(ENOMEM);
1557
1558 // is_internal_flag is set after creating the context
1559 // to properly create the gamma convert FilterDescriptor
1560 // we have to re-initialize it
1561 ✗ ff_free_filters(c2);
1562
0/2
✗ Branch 304 → 305 not taken.
✗ Branch 304 → 307 not taken.
✗ if ((ret = ff_init_filters(c2)) < 0) {
1563 ✗ sws_freeContext(c->cascaded_context[1]);
1564 ✗ c->cascaded_context[1] = NULL;
1565 ✗ return ret;
1566 }
1567
1568 ✗ c->cascaded_context[2] = NULL;
1569
0/2
✗ Branch 307 → 308 not taken.
✗ Branch 307 → 318 not taken.
✗ if (dstFormat != tmpFmt) {
1570 ✗ ret = av_image_alloc(c->cascaded_tmp[1], c->cascaded_tmpStride[1],
1571 dstW, dstH, tmpFmt, 64);
1572
0/2
✗ Branch 309 → 310 not taken.
✗ Branch 309 → 311 not taken.
✗ if (ret < 0)
1573 ✗ return ret;
1574
1575 ✗ c->cascaded_context[2] = alloc_set_opts(dstW, dstH, tmpFmt,
1576 dstW, dstH, dstFormat,
1577 ✗ flags, sws->scaler_params);
1578
0/2
✗ Branch 312 → 313 not taken.
✗ Branch 312 → 314 not taken.
✗ if (!c->cascaded_context[2])
1579 ✗ return AVERROR(ENOMEM);
1580 ✗ set_cascade_chr_pos(c->cascaded_context[2], sws, 0, 1);
1581 ✗ ret = sws_init_context(c->cascaded_context[2], NULL, NULL);
1582
0/2
✗ Branch 316 → 317 not taken.
✗ Branch 316 → 318 not taken.
✗ if (ret < 0)
1583 ✗ return ret;
1584 }
1585 ✗ return 0;
1586 }
1587
1588
2/2
✓ Branch 320 → 321 taken 148625 times.
✓ Branch 320 → 330 taken 14729 times.
163354 if (!isGray(srcFormat) &&
1589
4/4
✓ Branch 321 → 322 taken 7728 times.
✓ Branch 321 → 325 taken 140897 times.
✓ Branch 324 → 325 taken 7444 times.
✓ Branch 324 → 329 taken 284 times.
156353 ((desc_dst->log2_chroma_w &&
1590 7728 get_center_offset(c, desc_src->log2_chroma_w, sws->src_h_chr_pos, 0) !=
1591 7728 get_center_offset(c, desc_dst->log2_chroma_w, sws->dst_h_chr_pos, 0)) ||
1592
4/4
✓ Branch 325 → 326 taken 4759 times.
✓ Branch 325 → 330 taken 143582 times.
✓ Branch 328 → 329 taken 11 times.
✓ Branch 328 → 330 taken 4748 times.
153100 (desc_dst->log2_chroma_h &&
1593 4759 get_center_offset(c, desc_src->log2_chroma_h, sws->src_v_chr_pos, 1) !=
1594 4759 get_center_offset(c, desc_dst->log2_chroma_h, sws->dst_v_chr_pos, 1))))
1595 295 unscaled = 0;
1596
1597
1/2
✗ Branch 331 → 332 not taken.
✓ Branch 331 → 354 taken 163354 times.
163354 if (isBayer(srcFormat)) {
1598
0/4
✗ Branch 332 → 333 not taken.
✗ Branch 332 → 336 not taken.
✗ Branch 333 → 334 not taken.
✗ Branch 333 → 354 not taken.
✗ if (!unscaled ||
1599
0/4
✗ Branch 334 → 335 not taken.
✗ Branch 334 → 354 not taken.
✗ Branch 335 → 336 not taken.
✗ Branch 335 → 354 not taken.
✗ (dstFormat != AV_PIX_FMT_RGB24 && dstFormat != AV_PIX_FMT_YUV420P &&
1600 dstFormat != AV_PIX_FMT_RGB48)) {
1601
0/2
✗ Branch 337 → 338 not taken.
✗ Branch 337 → 339 not taken.
✗ enum AVPixelFormat tmpFormat = isBayer16BPS(srcFormat) ? AV_PIX_FMT_RGB48 : AV_PIX_FMT_RGB24;
1602
1603 ✗ ret = av_image_alloc(c->cascaded_tmp[0], c->cascaded_tmpStride[0],
1604 srcW, srcH, tmpFormat, 64);
1605
0/2
✗ Branch 341 → 342 not taken.
✗ Branch 341 → 343 not taken.
✗ if (ret < 0)
1606 ✗ return ret;
1607
1608 ✗ c->cascaded_context[0] = sws_getContext(srcW, srcH, srcFormat,
1609 srcW, srcH, tmpFormat,
1610 flags, srcFilter, NULL,
1611 ✗ sws->scaler_params);
1612
0/2
✗ Branch 344 → 345 not taken.
✗ Branch 344 → 346 not taken.
✗ if (!c->cascaded_context[0])
1613 ✗ return AVERROR(ENOMEM);
1614
1615 ✗ c->cascaded_context[1] = alloc_set_opts(srcW, srcH, tmpFormat,
1616 dstW, dstH, dstFormat,
1617 ✗ flags, sws->scaler_params);
1618
0/2
✗ Branch 347 → 348 not taken.
✗ Branch 347 → 349 not taken.
✗ if (!c->cascaded_context[1])
1619 ✗ return AVERROR(ENOMEM);
1620 ✗ set_cascade_chr_pos(c->cascaded_context[1], sws, 0, 1);
1621 ✗ ret = sws_init_context(c->cascaded_context[1], NULL, dstFilter);
1622
0/2
✗ Branch 351 → 352 not taken.
✗ Branch 351 → 353 not taken.
✗ if (ret < 0)
1623 ✗ return ret;
1624 ✗ return 0;
1625 }
1626 }
1627
1628
6/6
✓ Branch 354 → 355 taken 92940 times.
✓ Branch 354 → 360 taken 70414 times.
✓ Branch 355 → 356 taken 39259 times.
✓ Branch 355 → 360 taken 53681 times.
✓ Branch 356 → 357 taken 17 times.
✓ Branch 356 → 360 taken 39242 times.
163354 if (unscaled && c->srcBpc == 8 && dstFormat == AV_PIX_FMT_GRAYF32){
1629
2/2
✓ Branch 359 → 358 taken 4352 times.
✓ Branch 359 → 360 taken 17 times.
4369 for (i = 0; i < 256; ++i){
1630 4352 c->uint2float_lut[i] = (float)i * float_mult;
1631 }
1632 }
1633
1634 // float will be converted to uint16_t
1635
6/6
✓ Branch 361 → 362 taken 509 times.
✓ Branch 361 → 370 taken 162845 times.
✓ Branch 363 → 364 taken 59 times.
✓ Branch 363 → 370 taken 450 times.
✓ Branch 364 → 365 taken 55 times.
✓ Branch 364 → 369 taken 4 times.
163354 if (isFloat(srcFormat) && !isAnyRGB(srcFormat) &&
1636
6/8
✓ Branch 365 → 366 taken 55 times.
✗ Branch 365 → 370 not taken.
✓ Branch 366 → 367 taken 55 times.
✗ Branch 366 → 370 not taken.
✓ Branch 367 → 368 taken 28 times.
✓ Branch 367 → 369 taken 27 times.
✓ Branch 368 → 369 taken 10 times.
✓ Branch 368 → 370 taken 18 times.
55 (!unscaled || unscaled && dstFormat != srcFormat && (srcFormat != AV_PIX_FMT_GRAYF32 ||
1637 dstFormat != AV_PIX_FMT_GRAY8))){
1638 41 c->srcBpc = 16;
1639 }
1640
1641
4/4
✓ Branch 371 → 372 taken 41362 times.
✓ Branch 371 → 399 taken 121992 times.
✓ Branch 373 → 374 taken 5687 times.
✓ Branch 373 → 399 taken 35675 times.
163354 if (CONFIG_SWSCALE_ALPHA && isALPHA(srcFormat) && !isALPHA(dstFormat)) {
1642 5687 enum AVPixelFormat tmpFormat = alphaless_fmt(srcFormat);
1643
1644
4/4
✓ Branch 375 → 376 taken 4945 times.
✓ Branch 375 → 399 taken 742 times.
✓ Branch 376 → 377 taken 20 times.
✓ Branch 376 → 399 taken 4925 times.
5687 if (tmpFormat != AV_PIX_FMT_NONE && sws->alpha_blend != SWS_ALPHA_BLEND_NONE) {
1645
3/4
✓ Branch 377 → 378 taken 18 times.
✓ Branch 377 → 382 taken 2 times.
✓ Branch 378 → 379 taken 18 times.
✗ Branch 378 → 382 not taken.
20 if (!unscaled ||
1646
1/2
✓ Branch 379 → 380 taken 18 times.
✗ Branch 379 → 382 not taken.
18 dstFormat != tmpFormat ||
1647
1/2
✓ Branch 380 → 381 taken 18 times.
✗ Branch 380 → 382 not taken.
18 usesHFilter || usesVFilter ||
1648
1/2
✗ Branch 381 → 382 not taken.
✓ Branch 381 → 399 taken 18 times.
18 sws->src_range != sws->dst_range
1649 ) {
1650 2 c->cascaded_mainindex = 1;
1651 2 ret = av_image_alloc(c->cascaded_tmp[0], c->cascaded_tmpStride[0],
1652 srcW, srcH, tmpFormat, 64);
1653
1/2
✗ Branch 383 → 384 not taken.
✓ Branch 383 → 385 taken 2 times.
2 if (ret < 0)
1654 ✗ return ret;
1655
1656 4 c->cascaded_context[0] = alloc_set_opts(srcW, srcH, srcFormat,
1657 srcW, srcH, tmpFormat,
1658 2 flags, sws->scaler_params);
1659
1/2
✗ Branch 386 → 387 not taken.
✓ Branch 386 → 388 taken 2 times.
2 if (!c->cascaded_context[0])
1660 ✗ return AVERROR(EINVAL);
1661 2 c->cascaded_context[0]->alpha_blend = sws->alpha_blend;
1662 2 ret = sws_init_context(c->cascaded_context[0], NULL , NULL);
1663
1/2
✗ Branch 389 → 390 not taken.
✓ Branch 389 → 391 taken 2 times.
2 if (ret < 0)
1664 ✗ return ret;
1665
1666 4 c->cascaded_context[1] = alloc_set_opts(srcW, srcH, tmpFormat,
1667 dstW, dstH, dstFormat,
1668 2 flags, sws->scaler_params);
1669
1/2
✗ Branch 392 → 393 not taken.
✓ Branch 392 → 394 taken 2 times.
2 if (!c->cascaded_context[1])
1670 ✗ return AVERROR(EINVAL);
1671
1672 2 c->cascaded_context[1]->src_range = sws->src_range;
1673 2 c->cascaded_context[1]->dst_range = sws->dst_range;
1674 2 set_cascade_chr_pos(c->cascaded_context[1], sws, 1, 1);
1675 2 ret = sws_init_context(c->cascaded_context[1], srcFilter , dstFilter);
1676
1/2
✗ Branch 396 → 397 not taken.
✓ Branch 396 → 398 taken 2 times.
2 if (ret < 0)
1677 ✗ return ret;
1678
1679 2 return 0;
1680 }
1681 }
1682 }
1683
1684 /* alpha blend special case, note this has been split via cascaded contexts if its scaled */
1685
4/6
✓ Branch 399 → 400 taken 92940 times.
✓ Branch 399 → 415 taken 70412 times.
✓ Branch 400 → 401 taken 92940 times.
✗ Branch 400 → 415 not taken.
✓ Branch 401 → 402 taken 92940 times.
✗ Branch 401 → 415 not taken.
163352 if (unscaled && !usesHFilter && !usesVFilter &&
1686
3/4
✓ Branch 402 → 403 taken 18 times.
✓ Branch 402 → 415 taken 92922 times.
✓ Branch 404 → 405 taken 18 times.
✗ Branch 404 → 415 not taken.
92958 sws->alpha_blend != SWS_ALPHA_BLEND_NONE &&
1687 18 isALPHA(srcFormat) &&
1688
2/6
✗ Branch 405 → 406 not taken.
✓ Branch 405 → 408 taken 18 times.
✗ Branch 407 → 408 not taken.
✗ Branch 407 → 415 not taken.
✓ Branch 409 → 410 taken 18 times.
✗ Branch 409 → 415 not taken.
36 (sws->src_range == sws->dst_range || isAnyRGB(dstFormat)) &&
1689 18 alphaless_fmt(srcFormat) == dstFormat
1690 ) {
1691 18 c->convert_unscaled = ff_sws_alphablendaway;
1692
1693
1/2
✗ Branch 410 → 411 not taken.
✓ Branch 410 → 414 taken 18 times.
18 if (flags & SWS_PRINT_INFO)
1694 ✗ av_log(c, AV_LOG_INFO,
1695 "using alpha blendaway %s -> %s special converter\n",
1696 av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat));
1697 18 return 0;
1698 }
1699
1700 /* unscaled special cases */
1701
4/6
✓ Branch 415 → 416 taken 92922 times.
✓ Branch 415 → 430 taken 70412 times.
✓ Branch 416 → 417 taken 92922 times.
✗ Branch 416 → 430 not taken.
✓ Branch 417 → 418 taken 92922 times.
✗ Branch 417 → 430 not taken.
163334 if (unscaled && !usesHFilter && !usesVFilter &&
1702
5/6
✓ Branch 418 → 419 taken 8444 times.
✓ Branch 418 → 423 taken 84478 times.
✓ Branch 420 → 421 taken 7776 times.
✓ Branch 420 → 423 taken 668 times.
✗ Branch 422 → 423 not taken.
✓ Branch 422 → 430 taken 7776 times.
100698 (sws->src_range == sws->dst_range || isAnyRGB(dstFormat) ||
1703 7776 isBayer(srcFormat))){
1704
1705 85146 ff_get_unscaled_swscale(c);
1706
1707
2/2
✓ Branch 424 → 425 taken 14260 times.
✓ Branch 424 → 430 taken 70886 times.
85146 if (c->convert_unscaled) {
1708
1/2
✗ Branch 425 → 426 not taken.
✓ Branch 425 → 429 taken 14260 times.
14260 if (flags & SWS_PRINT_INFO)
1709 ✗ av_log(c, AV_LOG_INFO,
1710 "using unscaled %s -> %s special converter\n",
1711 av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat));
1712 14260 return 0;
1713 }
1714 }
1715
1716 /* precalculate horizontal scaler filter coefficients */
1717 {
1718 #if HAVE_MMXEXT_INLINE
1719 // can't downscale !!!
1720
3/4
✓ Branch 430 → 431 taken 29688 times.
✓ Branch 430 → 458 taken 119386 times.
✗ Branch 431 → 432 not taken.
✓ Branch 431 → 458 taken 29688 times.
149074 if (c->canMMXEXTBeUsed && (flags & SWS_FAST_BILINEAR)) {
1721 ✗ c->lumMmxextFilterCodeSize = ff_init_hscaler_mmxext(dstW, c->lumXInc, NULL,
1722 NULL, NULL, 8);
1723 ✗ c->chrMmxextFilterCodeSize = ff_init_hscaler_mmxext(c->chrDstW, c->chrXInc,
1724 NULL, NULL, NULL, 4);
1725
1726 ✗ c->lumMmxextFilterCode = ff_sws_jit_alloc(c->lumMmxextFilterCodeSize);
1727 ✗ c->chrMmxextFilterCode = ff_sws_jit_alloc(c->chrMmxextFilterCodeSize);
1728
0/4
✗ Branch 436 → 437 not taken.
✗ Branch 436 → 438 not taken.
✗ Branch 437 → 438 not taken.
✗ Branch 437 → 440 not taken.
✗ if (!c->lumMmxextFilterCode || !c->chrMmxextFilterCode) {
1729 ✗ av_log(c, AV_LOG_ERROR, "Failed to allocate MMX2FilterCode\n");
1730 ✗ return AVERROR(ENOMEM);
1731 }
1732
1733
0/2
✗ Branch 441 → 442 not taken.
✗ Branch 441 → 448 not taken.
✗ if (!FF_ALLOCZ_TYPED_ARRAY(c->hLumFilter, dstW / 8 + 8) ||
1734
0/2
✗ Branch 443 → 444 not taken.
✗ Branch 443 → 448 not taken.
✗ !FF_ALLOCZ_TYPED_ARRAY(c->hChrFilter, c->chrDstW / 4 + 8) ||
1735
0/2
✗ Branch 445 → 446 not taken.
✗ Branch 445 → 448 not taken.
✗ !FF_ALLOCZ_TYPED_ARRAY(c->hLumFilterPos, dstW / 2 / 8 + 8) ||
1736
0/2
✗ Branch 447 → 448 not taken.
✗ Branch 447 → 449 not taken.
✗ !FF_ALLOCZ_TYPED_ARRAY(c->hChrFilterPos, c->chrDstW / 2 / 4 + 8))
1737 ✗ goto nomem;
1738
1739 ✗ ff_init_hscaler_mmxext( dstW, c->lumXInc, c->lumMmxextFilterCode,
1740 c->hLumFilter, (uint32_t*)c->hLumFilterPos, 8);
1741 ✗ ff_init_hscaler_mmxext(c->chrDstW, c->chrXInc, c->chrMmxextFilterCode,
1742 c->hChrFilter, (uint32_t*)c->hChrFilterPos, 4);
1743
1744
0/4
✗ Branch 452 → 453 not taken.
✗ Branch 452 → 455 not taken.
✗ Branch 454 → 455 not taken.
✗ Branch 454 → 457 not taken.
✗ if ((ret = ff_sws_jit_protect(c->lumMmxextFilterCode, c->lumMmxextFilterCodeSize)) < 0 ||
1745 ✗ (ret = ff_sws_jit_protect(c->chrMmxextFilterCode, c->chrMmxextFilterCodeSize)) < 0) {
1746 ✗ av_log(c, AV_LOG_ERROR, "mprotect failed, cannot use fast bilinear scaler\n");
1747 ✗ goto fail;
1748 }
1749 } else
1750 #endif /* HAVE_MMXEXT_INLINE */
1751 {
1752
2/2
✓ Branch 458 → 459 taken 122545 times.
✓ Branch 458 → 460 taken 26529 times.
149074 const int filterAlign = X86_MMX(cpu_flags) ? 4 :
1753 PPC_ALTIVEC(cpu_flags) ? 8 :
1754 have_neon(cpu_flags) ? 4 :
1755 have_lsx(cpu_flags) ? 8 :
1756 have_lasx(cpu_flags) ? 8 : 1;
1757
1758
2/2
✓ Branch 464 → 465 taken 1 time.
✓ Branch 464 → 466 taken 149073 times.
298148 if ((ret = initFilter(&c->hLumFilter, &c->hLumFilterPos,
1759 &c->hLumFilterSize, c->lumXInc,
1760 srcW, dstW, filterAlign, 1 << 14,
1761 lum_scaler, flags,
1762 cpu_flags, srcFilter->lumH, dstFilter->lumH,
1763 149074 sws->scaler_params,
1764 get_local_pos(c, 0, 0, 0),
1765 get_local_pos(c, 0, 0, 0))) < 0)
1766 1 goto fail;
1767
1/2
✗ Branch 467 → 468 not taken.
✓ Branch 467 → 469 taken 149073 times.
149073 if (ff_shuffle_filter_coefficients(c, c->hLumFilterPos, c->hLumFilterSize, c->hLumFilter, dstW) < 0)
1768 ✗ goto nomem;
1769
1/2
✗ Branch 472 → 473 not taken.
✓ Branch 472 → 474 taken 149073 times.
298146 if ((ret = initFilter(&c->hChrFilter, &c->hChrFilterPos,
1770 &c->hChrFilterSize, c->chrXInc,
1771 c->chrSrcW, c->chrDstW, filterAlign, 1 << 14,
1772 chr_scaler, flags,
1773 cpu_flags, srcFilter->chrH, dstFilter->chrH,
1774 149073 sws->scaler_params,
1775 get_local_pos(c, c->chrSrcHSubSample, sws->src_h_chr_pos, 0),
1776 get_local_pos(c, c->chrDstHSubSample, sws->dst_h_chr_pos, 0))) < 0)
1777 ✗ goto fail;
1778
1/2
✗ Branch 475 → 476 not taken.
✓ Branch 475 → 477 taken 149073 times.
149073 if (ff_shuffle_filter_coefficients(c, c->hChrFilterPos, c->hChrFilterSize, c->hChrFilter, c->chrDstW) < 0)
1779 ✗ goto nomem;
1780 }
1781 } // initialize horizontal stuff
1782
1783 /* precalculate vertical scaler filter coefficients */
1784 {
1785
2/2
✓ Branch 477 → 478 taken 122545 times.
✓ Branch 477 → 479 taken 26528 times.
149073 const int filterAlign = X86_MMX(cpu_flags) ? 2 :
1786 PPC_ALTIVEC(cpu_flags) ? 8 :
1787 have_neon(cpu_flags) ? 2 : 1;
1788
1789 149073 ret = initFilter(&c->vLumFilter, &c->vLumFilterPos, &c->vLumFilterSize,
1790 c->lumYInc, srcH, dstH, filterAlign, (1 << 12),
1791 lum_scaler, flags,
1792 cpu_flags, srcFilter->lumV, dstFilter->lumV,
1793 149073 sws->scaler_params,
1794 get_local_pos(c, 0, 0, 1),
1795 get_local_pos(c, 0, 0, 1));
1796 149073 int usecascade = (ret == RETCODE_USE_CASCADE);
1797
1/4
✗ Branch 483 → 484 not taken.
✓ Branch 483 → 486 taken 149073 times.
✗ Branch 484 → 485 not taken.
✗ Branch 484 → 486 not taken.
149073 if (ret < 0 && !usecascade)
1798 ✗ goto fail;
1799
1/2
✗ Branch 489 → 490 not taken.
✓ Branch 489 → 491 taken 149073 times.
298146 if ((ret = initFilter(&c->vChrFilter, &c->vChrFilterPos, &c->vChrFilterSize,
1800 c->chrYInc, c->chrSrcH, c->chrDstH,
1801 filterAlign, (1 << 12),
1802 chr_scaler, flags,
1803 cpu_flags, srcFilter->chrV, dstFilter->chrV,
1804 149073 sws->scaler_params,
1805 get_local_pos(c, c->chrSrcVSubSample, sws->src_v_chr_pos, 1),
1806 get_local_pos(c, c->chrDstVSubSample, sws->dst_v_chr_pos, 1))) < 0)
1807
1808 ✗ goto fail;
1809
1/2
✗ Branch 491 → 492 not taken.
✓ Branch 491 → 493 taken 149073 times.
149073 if (usecascade) {
1810 ✗ ret = RETCODE_USE_CASCADE;
1811 ✗ goto fail;
1812 }
1813
1814 #if HAVE_ALTIVEC
1815 ret = ff_sws_init_altivec_bufs(c);
1816 if (ret < 0)
1817 goto fail;
1818 #endif
1819 }
1820
1821
2/2
✓ Branch 498 → 494 taken 596292 times.
✓ Branch 498 → 499 taken 149073 times.
745365 for (i = 0; i < 4; i++)
1822
1/2
✗ Branch 495 → 496 not taken.
✓ Branch 495 → 497 taken 596292 times.
596292 if (!FF_ALLOCZ_TYPED_ARRAY(c->dither_error[i], sws->dst_w + 3))
1823 ✗ goto nomem;
1824
1825
4/4
✓ Branch 500 → 501 taken 36960 times.
✓ Branch 500 → 504 taken 112113 times.
✓ Branch 502 → 503 taken 32939 times.
✓ Branch 502 → 504 taken 4021 times.
149073 c->needAlpha = (CONFIG_SWSCALE_ALPHA && isALPHA(sws->src_format) && isALPHA(sws->dst_format)) ? 1 : 0;
1826
1827 // 64 / c->scalingBpp is the same as 16 / sizeof(scaling_intermediate)
1828 149073 c->uv_off = (dst_stride>>1) + 64 / (c->dstBpc &~ 7);
1829 149073 c->uv_offx2 = dst_stride + 16;
1830
1831
1/2
✗ Branch 505 → 506 not taken.
✓ Branch 505 → 508 taken 149073 times.
149073 av_assert0(c->chrDstH <= dstH);
1832
1833
2/2
✓ Branch 508 → 509 taken 2 times.
✓ Branch 508 → 536 taken 149071 times.
149073 if (flags & SWS_PRINT_INFO) {
1834 2 const char *scaler = NULL, *cpucaps;
1835
1836
1/2
✓ Branch 513 → 510 taken 9 times.
✗ Branch 513 → 514 not taken.
9 for (i = 0; i < FF_ARRAY_ELEMS(scale_algorithms); i++) {
1837
2/2
✓ Branch 510 → 511 taken 2 times.
✓ Branch 510 → 512 taken 7 times.
9 if (info_scaler == scale_algorithms[i].flag) {
1838 2 scaler = scale_algorithms[i].description;
1839 2 break;
1840 }
1841 }
1842
1/2
✗ Branch 514 → 515 not taken.
✓ Branch 514 → 516 taken 2 times.
2 if (!scaler)
1843 ✗ scaler = "ehh flags invalid?!";
1844
1/2
✓ Branch 517 → 518 taken 2 times.
✗ Branch 517 → 523 not taken.
4 av_log(c, AV_LOG_INFO, "%s scaler, from %s to %s%s ",
1845 scaler,
1846 av_get_pix_fmt_name(srcFormat),
1847
2/4
✓ Branch 518 → 519 taken 2 times.
✗ Branch 518 → 523 not taken.
✓ Branch 519 → 520 taken 2 times.
✗ Branch 519 → 523 not taken.
2 dstFormat == AV_PIX_FMT_BGR555 || dstFormat == AV_PIX_FMT_BGR565 ||
1848
2/4
✓ Branch 520 → 521 taken 2 times.
✗ Branch 520 → 523 not taken.
✓ Branch 521 → 522 taken 2 times.
✗ Branch 521 → 523 not taken.
2 dstFormat == AV_PIX_FMT_RGB444BE || dstFormat == AV_PIX_FMT_RGB444LE ||
1849
1/2
✗ Branch 522 → 523 not taken.
✓ Branch 522 → 524 taken 2 times.
2 dstFormat == AV_PIX_FMT_BGR444BE || dstFormat == AV_PIX_FMT_BGR444LE ?
1850 "dithered " : "",
1851 av_get_pix_fmt_name(dstFormat));
1852
1853
1/2
✓ Branch 527 → 528 taken 2 times.
✗ Branch 527 → 529 not taken.
2 if (INLINE_MMXEXT(cpu_flags))
1854 2 cpucaps = "MMXEXT";
1855
0/2
✗ Branch 529 → 530 not taken.
✗ Branch 529 → 531 not taken.
✗ else if (INLINE_MMX(cpu_flags))
1856 ✗ cpucaps = "MMX";
1857 else if (PPC_ALTIVEC(cpu_flags))
1858 cpucaps = "AltiVec";
1859 else
1860 ✗ cpucaps = "C";
1861
1862 2 av_log(c, AV_LOG_INFO, "using %s\n", cpucaps);
1863
1864 2 av_log(c, AV_LOG_VERBOSE, "%dx%d -> %dx%d\n", srcW, srcH, dstW, dstH);
1865 2 av_log(c, AV_LOG_DEBUG,
1866 "lum srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n",
1867 sws->src_w, sws->src_h, sws->dst_w, sws->dst_h, c->lumXInc, c->lumYInc);
1868 2 av_log(c, AV_LOG_DEBUG,
1869 "chr srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n",
1870 c->chrSrcW, c->chrSrcH, c->chrDstW, c->chrDstH,
1871 c->chrXInc, c->chrYInc);
1872 }
1873
1874 149073 ff_sws_init_scale(c);
1875
1876 149073 return ff_init_filters(c);
1877 ✗ nomem:
1878 ✗ ret = AVERROR(ENOMEM);
1879 1 fail: // FIXME replace things by appropriate error codes
1880
1/2
✓ Branch 539 → 540 taken 1 time.
✗ Branch 539 → 563 not taken.
1 if (ret == RETCODE_USE_CASCADE) {
1881 1 int tmpW = sqrt(srcW * (int64_t)dstW);
1882 1 int tmpH = sqrt(srcH * (int64_t)dstH);
1883 1 enum AVPixelFormat tmpFormat = AV_PIX_FMT_YUV420P;
1884
1885
1/2
✗ Branch 541 → 542 not taken.
✓ Branch 541 → 543 taken 1 time.
1 if (isALPHA(srcFormat))
1886 ✗ tmpFormat = AV_PIX_FMT_YUVA420P;
1887
1888
1/2
✗ Branch 543 → 544 not taken.
✓ Branch 543 → 545 taken 1 time.
1 if (srcW*(int64_t)srcH <= 4LL*dstW*dstH)
1889 ✗ return AVERROR(EINVAL);
1890
1891 1 ret = av_image_alloc(c->cascaded_tmp[0], c->cascaded_tmpStride[0],
1892 tmpW, tmpH, tmpFormat, 64);
1893
1/2
✗ Branch 546 → 547 not taken.
✓ Branch 546 → 548 taken 1 time.
1 if (ret < 0)
1894 ✗ return ret;
1895
1896 2 c->cascaded_context[0] = alloc_set_opts(srcW, srcH, srcFormat,
1897 tmpW, tmpH, tmpFormat,
1898 1 flags, sws->scaler_params);
1899
1/2
✗ Branch 549 → 550 not taken.
✓ Branch 549 → 551 taken 1 time.
1 if (!c->cascaded_context[0])
1900 ✗ return AVERROR(ENOMEM);
1901 1 set_cascade_chr_pos(c->cascaded_context[0], sws, 1, 0);
1902 1 ret = sws_init_context(c->cascaded_context[0], srcFilter, NULL);
1903
1/2
✗ Branch 553 → 554 not taken.
✓ Branch 553 → 555 taken 1 time.
1 if (ret < 0)
1904 ✗ return ret;
1905
1906 2 c->cascaded_context[1] = alloc_set_opts(tmpW, tmpH, tmpFormat,
1907 dstW, dstH, dstFormat,
1908 1 flags, sws->scaler_params);
1909
1/2
✗ Branch 556 → 557 not taken.
✓ Branch 556 → 558 taken 1 time.
1 if (!c->cascaded_context[1])
1910 ✗ return AVERROR(ENOMEM);
1911 1 set_cascade_chr_pos(c->cascaded_context[1], sws, 0, 1);
1912 1 ret = sws_init_context(c->cascaded_context[1], NULL, dstFilter);
1913
1/2
✗ Branch 560 → 561 not taken.
✓ Branch 560 → 562 taken 1 time.
1 if (ret < 0)
1914 ✗ return ret;
1915 1 return 0;
1916 }
1917 ✗ return ret;
1918 }
1919
1920 1500 static int context_init_threaded(SwsContext *sws,
1921 SwsFilter *src_filter, SwsFilter *dst_filter)
1922 {
1923 1500 SwsInternal *c = sws_internal(sws);
1924 int ret;
1925
1926 1500 ret = avpriv_slicethread_create2(&c->slicethread, (void*) sws,
1927 ff_sws_slice_worker, NULL, sws->threads);
1928
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 1500 times.
1500 if (ret == AVERROR(ENOSYS)) {
1929 ✗ sws->threads = 1;
1930 ✗ return 0;
1931
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 1500 times.
1500 } else if (ret < 0)
1932 ✗ return ret;
1933
1934 1500 sws->threads = ret;
1935
1936 1500 c->slice_ctx = av_calloc(sws->threads, sizeof(*c->slice_ctx));
1937
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 1500 times.
1500 if (!c->slice_ctx)
1938 ✗ return AVERROR(ENOMEM);
1939
1940
2/2
✓ Branch 26 → 12 taken 10500 times.
✓ Branch 26 → 27 taken 1500 times.
12000 for (int i = 0; i < sws->threads; i++) {
1941 SwsContext *slice;
1942 10500 slice = c->slice_ctx[i] = sws_alloc_context();
1943
1/2
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 15 taken 10500 times.
10500 if (!slice)
1944 ✗ return AVERROR(ENOMEM);
1945 10500 sws_internal(slice)->parent = sws;
1946 10500 c->nb_slice_ctx++;
1947
1948 10500 ret = av_opt_copy(slice, sws);
1949
1/2
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 10500 times.
10500 if (ret < 0)
1950 ✗ return ret;
1951 10500 slice->threads = 1;
1952
1953 10500 ret = ff_sws_init_single_context(slice, src_filter, dst_filter);
1954
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 10500 times.
10500 if (ret < 0)
1955 ✗ return ret;
1956
1957
1/2
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 25 taken 10500 times.
10500 if (slice->dither == SWS_DITHER_ED) {
1958 ✗ av_log(c, AV_LOG_VERBOSE,
1959 "Error-diffusion dither is in use, scaling will be single-threaded.");
1960 ✗ break;
1961 }
1962 }
1963
1964 1500 return 0;
1965 }
1966
1967 123016 av_cold int sws_init_context(SwsContext *sws, SwsFilter *srcFilter,
1968 SwsFilter *dstFilter)
1969 {
1970 123016 SwsInternal *c = sws_internal(sws);
1971 static AVOnce rgb2rgb_once = AV_ONCE_INIT;
1972 enum AVPixelFormat src_format, dst_format;
1973 int ret;
1974
1975 123016 c->is_legacy_init = 1;
1976 123016 c->frame_src = av_frame_alloc();
1977 123016 c->frame_dst = av_frame_alloc();
1978
2/4
✓ Branch 5 → 6 taken 123016 times.
✗ Branch 5 → 7 not taken.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 123016 times.
123016 if (!c->frame_src || !c->frame_dst)
1979 ✗ return AVERROR(ENOMEM);
1980
1981
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 123016 times.
123016 if (ff_thread_once(&rgb2rgb_once, ff_sws_rgb2rgb_init) != 0)
1982 ✗ return AVERROR_UNKNOWN;
1983
1984 123016 src_format = sws->src_format;
1985 123016 dst_format = sws->dst_format;
1986 123016 sws->src_range |= handle_jpeg(&sws->src_format);
1987 123016 sws->dst_range |= handle_jpeg(&sws->dst_format);
1988
1989
4/4
✓ Branch 13 → 14 taken 121928 times.
✓ Branch 13 → 15 taken 1088 times.
✓ Branch 14 → 15 taken 191 times.
✓ Branch 14 → 16 taken 121737 times.
123016 if (src_format != sws->src_format || dst_format != sws->dst_format)
1990 1279 av_log(c, AV_LOG_WARNING, "deprecated pixel format used, make sure you did set range correctly\n");
1991
1992
2/2
✓ Branch 16 → 17 taken 1500 times.
✓ Branch 16 → 21 taken 121516 times.
123016 if (sws->threads != 1) {
1993 1500 ret = context_init_threaded(sws, srcFilter, dstFilter);
1994
2/4
✓ Branch 18 → 19 taken 1500 times.
✗ Branch 18 → 20 not taken.
✓ Branch 19 → 20 taken 1500 times.
✗ Branch 19 → 21 not taken.
1500 if (ret < 0 || sws->threads > 1)
1995 1500 return ret;
1996 // threading disabled in this build, init as single-threaded
1997 }
1998
1999 121516 return ff_sws_init_single_context(sws, srcFilter, dstFilter);
2000 }
2001
2002 5740 SwsContext *sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat,
2003 int dstW, int dstH, enum AVPixelFormat dstFormat,
2004 int flags, SwsFilter *srcFilter,
2005 SwsFilter *dstFilter, const double *param)
2006 {
2007 SwsContext *sws;
2008
2009 5740 sws = alloc_set_opts(srcW, srcH, srcFormat,
2010 dstW, dstH, dstFormat,
2011 flags, param);
2012
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 5740 times.
5740 if (!sws)
2013 ✗ return NULL;
2014
2015
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 9 taken 5740 times.
5740 if (sws_init_context(sws, srcFilter, dstFilter) < 0) {
2016 ✗ sws_freeContext(sws);
2017 ✗ return NULL;
2018 }
2019
2020 5740 return sws;
2021 }
2022
2023 ✗ static int isnan_vec(SwsVector *a)
2024 {
2025 int i;
2026
0/2
✗ Branch 6 → 3 not taken.
✗ Branch 6 → 7 not taken.
✗ for (i=0; i<a->length; i++)
2027
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ if (isnan(a->coeff[i]))
2028 ✗ return 1;
2029 ✗ return 0;
2030 }
2031
2032 ✗ static void makenan_vec(SwsVector *a)
2033 {
2034 int i;
2035
0/2
✗ Branch 4 → 3 not taken.
✗ Branch 4 → 5 not taken.
✗ for (i=0; i<a->length; i++)
2036 ✗ a->coeff[i] = NAN;
2037 ✗ }
2038
2039 ✗ SwsVector *sws_allocVec(int length)
2040 {
2041 SwsVector *vec;
2042
2043
0/4
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 4 not taken.
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ if(length <= 0 || length > INT_MAX/ sizeof(double))
2044 ✗ return NULL;
2045
2046 ✗ vec = av_malloc(sizeof(SwsVector));
2047
0/2
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 8 not taken.
✗ if (!vec)
2048 ✗ return NULL;
2049 ✗ vec->length = length;
2050 ✗ vec->coeff = av_malloc(sizeof(double) * length);
2051
0/2
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 11 not taken.
✗ if (!vec->coeff)
2052 ✗ av_freep(&vec);
2053 ✗ return vec;
2054 }
2055
2056 ✗ SwsVector *sws_getGaussianVec(double variance, double quality)
2057 {
2058 ✗ const int length = (int)(variance * quality + 0.5) | 1;
2059 int i;
2060 ✗ double middle = (length - 1) * 0.5;
2061 SwsVector *vec;
2062
2063
0/4
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 4 not taken.
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ if(variance < 0 || quality < 0)
2064 ✗ return NULL;
2065
2066 ✗ vec = sws_allocVec(length);
2067
2068
0/2
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 8 not taken.
✗ if (!vec)
2069 ✗ return NULL;
2070
2071
0/2
✗ Branch 10 → 9 not taken.
✗ Branch 10 → 11 not taken.
✗ for (i = 0; i < length; i++) {
2072 ✗ double dist = i - middle;
2073 ✗ vec->coeff[i] = exp(-dist * dist / (2 * variance * variance)) /
2074 ✗ sqrt(2 * variance * M_PI);
2075 }
2076
2077 ✗ sws_normalizeVec(vec, 1.0);
2078
2079 ✗ return vec;
2080 }
2081
2082 /**
2083 * Allocate and return a vector with length coefficients, all
2084 * with the same value c.
2085 */
2086 static
2087 ✗ SwsVector *sws_getConstVec(double c, int length)
2088 {
2089 int i;
2090 ✗ SwsVector *vec = sws_allocVec(length);
2091
2092
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ if (!vec)
2093 ✗ return NULL;
2094
2095
0/2
✗ Branch 7 → 6 not taken.
✗ Branch 7 → 8 not taken.
✗ for (i = 0; i < length; i++)
2096 ✗ vec->coeff[i] = c;
2097
2098 ✗ return vec;
2099 }
2100
2101 /**
2102 * Allocate and return a vector with just one coefficient, with
2103 * value 1.0.
2104 */
2105 static
2106 ✗ SwsVector *sws_getIdentityVec(void)
2107 {
2108 ✗ return sws_getConstVec(1.0, 1);
2109 }
2110
2111 ✗ static double sws_dcVec(SwsVector *a)
2112 {
2113 int i;
2114 ✗ double sum = 0;
2115
2116
0/2
✗ Branch 4 → 3 not taken.
✗ Branch 4 → 5 not taken.
✗ for (i = 0; i < a->length; i++)
2117 ✗ sum += a->coeff[i];
2118
2119 ✗ return sum;
2120 }
2121
2122 ✗ void sws_scaleVec(SwsVector *a, double scalar)
2123 {
2124 int i;
2125
2126
0/2
✗ Branch 4 → 3 not taken.
✗ Branch 4 → 5 not taken.
✗ for (i = 0; i < a->length; i++)
2127 ✗ a->coeff[i] *= scalar;
2128 ✗ }
2129
2130 ✗ void sws_normalizeVec(SwsVector *a, double height)
2131 {
2132 ✗ sws_scaleVec(a, height / sws_dcVec(a));
2133 ✗ }
2134
2135 ✗ static SwsVector *sws_sumVec(SwsVector *a, SwsVector *b)
2136 {
2137 ✗ int length = FFMAX(a->length, b->length);
2138 int i;
2139 ✗ SwsVector *vec = sws_getConstVec(0.0, length);
2140
2141
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ if (!vec)
2142 ✗ return NULL;
2143
2144
0/2
✗ Branch 7 → 6 not taken.
✗ Branch 7 → 8 not taken.
✗ for (i = 0; i < a->length; i++)
2145 ✗ vec->coeff[i + (length - 1) / 2 - (a->length - 1) / 2] += a->coeff[i];
2146
0/2
✗ Branch 10 → 9 not taken.
✗ Branch 10 → 11 not taken.
✗ for (i = 0; i < b->length; i++)
2147 ✗ vec->coeff[i + (length - 1) / 2 - (b->length - 1) / 2] += b->coeff[i];
2148
2149 ✗ return vec;
2150 }
2151
2152 /* shift left / or right if "shift" is negative */
2153 ✗ static SwsVector *sws_getShiftedVec(SwsVector *a, int shift)
2154 {
2155 ✗ int length = a->length + FFABS(shift) * 2;
2156 int i;
2157 ✗ SwsVector *vec = sws_getConstVec(0.0, length);
2158
2159
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ if (!vec)
2160 ✗ return NULL;
2161
2162
0/2
✗ Branch 7 → 6 not taken.
✗ Branch 7 → 8 not taken.
✗ for (i = 0; i < a->length; i++) {
2163 ✗ vec->coeff[i + (length - 1) / 2 -
2164 ✗ (a->length - 1) / 2 - shift] = a->coeff[i];
2165 }
2166
2167 ✗ return vec;
2168 }
2169
2170 static
2171 ✗ void sws_shiftVec(SwsVector *a, int shift)
2172 {
2173 ✗ SwsVector *shifted = sws_getShiftedVec(a, shift);
2174
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 6 not taken.
✗ if (!shifted) {
2175 ✗ makenan_vec(a);
2176 ✗ return;
2177 }
2178 ✗ av_free(a->coeff);
2179 ✗ a->coeff = shifted->coeff;
2180 ✗ a->length = shifted->length;
2181 ✗ av_free(shifted);
2182 }
2183
2184 static
2185 ✗ void sws_addVec(SwsVector *a, SwsVector *b)
2186 {
2187 ✗ SwsVector *sum = sws_sumVec(a, b);
2188
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 6 not taken.
✗ if (!sum) {
2189 ✗ makenan_vec(a);
2190 ✗ return;
2191 }
2192 ✗ av_free(a->coeff);
2193 ✗ a->coeff = sum->coeff;
2194 ✗ a->length = sum->length;
2195 ✗ av_free(sum);
2196 }
2197
2198 /**
2199 * Print with av_log() a textual representation of the vector a
2200 * if log_level <= av_log_level.
2201 */
2202 static
2203 ✗ void sws_printVec2(SwsVector *a, AVClass *log_ctx, int log_level)
2204 {
2205 int i;
2206 ✗ double max = 0;
2207 ✗ double min = 0;
2208 double range;
2209
2210
0/2
✗ Branch 6 → 3 not taken.
✗ Branch 6 → 7 not taken.
✗ for (i = 0; i < a->length; i++)
2211
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ if (a->coeff[i] > max)
2212 ✗ max = a->coeff[i];
2213
2214
0/2
✗ Branch 11 → 8 not taken.
✗ Branch 11 → 12 not taken.
✗ for (i = 0; i < a->length; i++)
2215
0/2
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 10 not taken.
✗ if (a->coeff[i] < min)
2216 ✗ min = a->coeff[i];
2217
2218 ✗ range = max - min;
2219
2220
0/2
✗ Branch 20 → 13 not taken.
✗ Branch 20 → 21 not taken.
✗ for (i = 0; i < a->length; i++) {
2221 ✗ int x = (int)((a->coeff[i] - min) * 60.0 / range + 0.5);
2222 ✗ av_log(log_ctx, log_level, "%1.3f ", a->coeff[i]);
2223
0/2
✗ Branch 17 → 15 not taken.
✗ Branch 17 → 18 not taken.
✗ for (; x > 0; x--)
2224 ✗ av_log(log_ctx, log_level, " ");
2225 ✗ av_log(log_ctx, log_level, "|\n");
2226 }
2227 ✗ }
2228
2229 ✗ void sws_freeVec(SwsVector *a)
2230 {
2231
0/2
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 4 not taken.
✗ if (!a)
2232 ✗ return;
2233 ✗ av_freep(&a->coeff);
2234 ✗ a->length = 0;
2235 ✗ av_free(a);
2236 }
2237
2238 ✗ void sws_freeFilter(SwsFilter *filter)
2239 {
2240
0/2
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 4 not taken.
✗ if (!filter)
2241 ✗ return;
2242
2243 ✗ sws_freeVec(filter->lumH);
2244 ✗ sws_freeVec(filter->lumV);
2245 ✗ sws_freeVec(filter->chrH);
2246 ✗ sws_freeVec(filter->chrV);
2247 ✗ av_free(filter);
2248 }
2249
2250 ✗ SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,
2251 float lumaSharpen, float chromaSharpen,
2252 float chromaHShift, float chromaVShift,
2253 int verbose)
2254 {
2255 ✗ SwsFilter *filter = av_malloc(sizeof(SwsFilter));
2256
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ if (!filter)
2257 ✗ return NULL;
2258
2259
0/2
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 9 not taken.
✗ if (lumaGBlur != 0.0) {
2260 ✗ filter->lumH = sws_getGaussianVec(lumaGBlur, 3.0);
2261 ✗ filter->lumV = sws_getGaussianVec(lumaGBlur, 3.0);
2262 } else {
2263 ✗ filter->lumH = sws_getIdentityVec();
2264 ✗ filter->lumV = sws_getIdentityVec();
2265 }
2266
2267
0/2
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 16 not taken.
✗ if (chromaGBlur != 0.0) {
2268 ✗ filter->chrH = sws_getGaussianVec(chromaGBlur, 3.0);
2269 ✗ filter->chrV = sws_getGaussianVec(chromaGBlur, 3.0);
2270 } else {
2271 ✗ filter->chrH = sws_getIdentityVec();
2272 ✗ filter->chrV = sws_getIdentityVec();
2273 }
2274
2275
0/8
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 23 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 23 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 23 not taken.
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 24 not taken.
✗ if (!filter->lumH || !filter->lumV || !filter->chrH || !filter->chrV)
2276 ✗ goto fail;
2277
2278
0/2
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 33 not taken.
✗ if (chromaSharpen != 0.0) {
2279 ✗ SwsVector *id = sws_getIdentityVec();
2280
0/2
✗ Branch 26 → 27 not taken.
✗ Branch 26 → 28 not taken.
✗ if (!id)
2281 ✗ goto fail;
2282 ✗ sws_scaleVec(filter->chrH, -chromaSharpen);
2283 ✗ sws_scaleVec(filter->chrV, -chromaSharpen);
2284 ✗ sws_addVec(filter->chrH, id);
2285 ✗ sws_addVec(filter->chrV, id);
2286 ✗ sws_freeVec(id);
2287 }
2288
2289
0/2
✗ Branch 33 → 34 not taken.
✗ Branch 33 → 42 not taken.
✗ if (lumaSharpen != 0.0) {
2290 ✗ SwsVector *id = sws_getIdentityVec();
2291
0/2
✗ Branch 35 → 36 not taken.
✗ Branch 35 → 37 not taken.
✗ if (!id)
2292 ✗ goto fail;
2293 ✗ sws_scaleVec(filter->lumH, -lumaSharpen);
2294 ✗ sws_scaleVec(filter->lumV, -lumaSharpen);
2295 ✗ sws_addVec(filter->lumH, id);
2296 ✗ sws_addVec(filter->lumV, id);
2297 ✗ sws_freeVec(id);
2298 }
2299
2300
0/2
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 44 not taken.
✗ if (chromaHShift != 0.0)
2301 ✗ sws_shiftVec(filter->chrH, (int)(chromaHShift + 0.5));
2302
2303
0/2
✗ Branch 44 → 45 not taken.
✗ Branch 44 → 46 not taken.
✗ if (chromaVShift != 0.0)
2304 ✗ sws_shiftVec(filter->chrV, (int)(chromaVShift + 0.5));
2305
2306 ✗ sws_normalizeVec(filter->chrH, 1.0);
2307 ✗ sws_normalizeVec(filter->chrV, 1.0);
2308 ✗ sws_normalizeVec(filter->lumH, 1.0);
2309 ✗ sws_normalizeVec(filter->lumV, 1.0);
2310
2311
0/4
✗ Branch 51 → 52 not taken.
✗ Branch 51 → 58 not taken.
✗ Branch 53 → 54 not taken.
✗ Branch 53 → 58 not taken.
✗ if (isnan_vec(filter->chrH) ||
2312
0/2
✗ Branch 55 → 56 not taken.
✗ Branch 55 → 58 not taken.
✗ isnan_vec(filter->chrV) ||
2313
0/2
✗ Branch 57 → 58 not taken.
✗ Branch 57 → 59 not taken.
✗ isnan_vec(filter->lumH) ||
2314 ✗ isnan_vec(filter->lumV))
2315 ✗ goto fail;
2316
2317
0/2
✗ Branch 59 → 60 not taken.
✗ Branch 59 → 61 not taken.
✗ if (verbose)
2318 ✗ sws_printVec2(filter->chrH, NULL, AV_LOG_DEBUG);
2319
0/2
✗ Branch 61 → 62 not taken.
✗ Branch 61 → 63 not taken.
✗ if (verbose)
2320 ✗ sws_printVec2(filter->lumH, NULL, AV_LOG_DEBUG);
2321
2322 ✗ return filter;
2323
2324 ✗ fail:
2325 ✗ sws_freeVec(filter->lumH);
2326 ✗ sws_freeVec(filter->lumV);
2327 ✗ sws_freeVec(filter->chrH);
2328 ✗ sws_freeVec(filter->chrV);
2329 ✗ av_freep(&filter);
2330 ✗ return NULL;
2331 }
2332
2333 750025 void sws_freeContext(SwsContext *sws)
2334 {
2335 750025 SwsInternal *c = sws_internal(sws);
2336 int i;
2337
2/2
✓ Branch 3 → 4 taken 562519 times.
✓ Branch 3 → 5 taken 187506 times.
750025 if (!c)
2338 562519 return;
2339
2340 187506 av_refstruct_unref(&c->hw_priv);
2341
2342
2/2
✓ Branch 9 → 7 taken 375012 times.
✓ Branch 9 → 10 taken 187506 times.
562518 for (i = 0; i < FF_ARRAY_ELEMS(c->graph); i++)
2343 375012 ff_sws_graph_free(&c->graph[i]);
2344 187506 ff_frame_pool_uninit(&c->frame_pool);
2345
2346
2/2
✓ Branch 14 → 12 taken 41838 times.
✓ Branch 14 → 15 taken 187506 times.
229344 for (i = 0; i < c->nb_slice_ctx; i++)
2347 41838 sws_freeContext(c->slice_ctx[i]);
2348 187506 av_freep(&c->slice_ctx);
2349
2350 187506 avpriv_slicethread_free(&c->slicethread);
2351
2352
2/2
✓ Branch 20 → 18 taken 750024 times.
✓ Branch 20 → 21 taken 187506 times.
937530 for (i = 0; i < 4; i++)
2353 750024 av_freep(&c->dither_error[i]);
2354
2355 187506 av_frame_free(&c->frame_src);
2356 187506 av_frame_free(&c->frame_dst);
2357
2358 187506 av_freep(&c->src_ranges.ranges);
2359
2360 187506 av_freep(&c->vLumFilter);
2361 187506 av_freep(&c->vChrFilter);
2362 187506 av_freep(&c->hLumFilter);
2363 187506 av_freep(&c->hChrFilter);
2364 #if HAVE_ALTIVEC
2365 ff_sws_free_altivec_bufs(c);
2366 #endif
2367
2368 187506 av_freep(&c->vLumFilterPos);
2369 187506 av_freep(&c->vChrFilterPos);
2370 187506 av_freep(&c->hLumFilterPos);
2371 187506 av_freep(&c->hChrFilterPos);
2372
2373 #if HAVE_MMX_INLINE
2374 187506 ff_sws_jit_free(c->lumMmxextFilterCode, c->lumMmxextFilterCodeSize);
2375 187506 ff_sws_jit_free(c->chrMmxextFilterCode, c->chrMmxextFilterCodeSize);
2376 187506 c->lumMmxextFilterCode = NULL;
2377 187506 c->chrMmxextFilterCode = NULL;
2378 #endif /* HAVE_MMX_INLINE */
2379
2380 187506 av_freep(&c->yuvTable);
2381 187506 av_freep(&c->formatConvBuffer);
2382
2383 187506 sws_freeContext(c->cascaded_context[0]);
2384 187506 sws_freeContext(c->cascaded_context[1]);
2385 187506 sws_freeContext(c->cascaded_context[2]);
2386 187506 memset(c->cascaded_context, 0, sizeof(c->cascaded_context));
2387 187506 av_freep(&c->cascaded_tmp[0][0]);
2388 187506 av_freep(&c->cascaded_tmp[1][0]);
2389
2390 187506 av_freep(&c->gamma);
2391 187506 av_freep(&c->inv_gamma);
2392 #if CONFIG_SMALL
2393 av_freep(&c->xyz2rgb.gamma.in);
2394 #endif
2395
2396 187506 av_freep(&c->rgb0_scratch);
2397 187506 av_freep(&c->xyz_scratch);
2398
2399 187506 ff_free_filters(c);
2400
2401 187506 av_free(c);
2402 }
2403
2404 135743 void sws_free_context(SwsContext **pctx)
2405 {
2406 135743 SwsContext *ctx = *pctx;
2407
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 135743 times.
135743 if (!ctx)
2408 ✗ return;
2409
2410 135743 sws_freeContext(ctx);
2411 135743 *pctx = NULL;
2412 }
2413
2414 ✗ SwsContext *sws_getCachedContext(SwsContext *prev, int srcW,
2415 int srcH, enum AVPixelFormat srcFormat,
2416 int dstW, int dstH,
2417 enum AVPixelFormat dstFormat, int flags,
2418 SwsFilter *srcFilter,
2419 SwsFilter *dstFilter,
2420 const double *param)
2421 {
2422 SwsContext *sws;
2423 static const double default_param[2] = { SWS_PARAM_DEFAULT,
2424 SWS_PARAM_DEFAULT };
2425
2426
0/2
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 4 not taken.
✗ if (!param)
2427 ✗ param = default_param;
2428
2429
0/4
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 14 not taken.
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 14 not taken.
✗ if (prev && (prev->src_w == srcW &&
2430
0/2
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 14 not taken.
✗ prev->src_h == srcH &&
2431
0/2
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 14 not taken.
✗ prev->src_format == srcFormat &&
2432
0/2
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 14 not taken.
✗ prev->dst_w == dstW &&
2433
0/2
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 14 not taken.
✗ prev->dst_h == dstH &&
2434
0/2
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 14 not taken.
✗ prev->dst_format == dstFormat &&
2435
0/2
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 14 not taken.
✗ prev->flags == flags &&
2436
0/2
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 14 not taken.
✗ !memcmp(prev->scaler_params, param,
2437 sizeof(prev->scaler_params)))) {
2438 ✗ return prev;
2439 }
2440
2441
0/2
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 18 not taken.
✗ if (!(sws = sws_alloc_context())) {
2442 ✗ sws_free_context(&prev);
2443 ✗ return NULL;
2444 }
2445
2446
0/2
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 21 not taken.
✗ if (prev) {
2447 ✗ av_opt_copy(sws, prev);
2448 ✗ sws_free_context(&prev);
2449 }
2450
2451 ✗ sws->src_w = srcW;
2452 ✗ sws->src_h = srcH;
2453 ✗ sws->src_format = srcFormat;
2454 ✗ sws->dst_w = dstW;
2455 ✗ sws->dst_h = dstH;
2456 ✗ sws->dst_format = dstFormat;
2457 ✗ sws->flags = flags;
2458
0/2
✗ Branch 23 → 22 not taken.
✗ Branch 23 → 24 not taken.
✗ for (int i = 0; i < SWS_NUM_SCALER_PARAMS; i++)
2459 ✗ sws->scaler_params[i] = param[i];
2460
2461
0/2
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 27 not taken.
✗ if (sws_init_context(sws, srcFilter, dstFilter) < 0)
2462 ✗ sws_free_context(&sws);
2463
2464 ✗ return sws;
2465 }
2466
2467 1875 int ff_range_add(RangeList *rl, unsigned int start, unsigned int len)
2468 {
2469 Range *tmp;
2470 unsigned int idx;
2471
2472 /* find the first existing range after the new one */
2473
1/2
✗ Branch 6 → 3 not taken.
✓ Branch 6 → 7 taken 1875 times.
1875 for (idx = 0; idx < rl->nb_ranges; idx++)
2474
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ if (rl->ranges[idx].start > start)
2475 ✗ break;
2476
2477 /* check for overlap */
2478
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 10 taken 1875 times.
1875 if (idx > 0) {
2479 ✗ Range *prev = &rl->ranges[idx - 1];
2480
0/2
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 10 not taken.
✗ if (prev->start + prev->len > start)
2481 ✗ return AVERROR(EINVAL);
2482 }
2483
1/2
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 13 taken 1875 times.
1875 if (idx < rl->nb_ranges) {
2484 ✗ Range *next = &rl->ranges[idx];
2485
0/2
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 13 not taken.
✗ if (start + len > next->start)
2486 ✗ return AVERROR(EINVAL);
2487 }
2488
2489 1875 tmp = av_fast_realloc(rl->ranges, &rl->ranges_allocated,
2490 1875 (rl->nb_ranges + 1) * sizeof(*rl->ranges));
2491
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 1875 times.
1875 if (!tmp)
2492 ✗ return AVERROR(ENOMEM);
2493 1875 rl->ranges = tmp;
2494
2495 1875 memmove(rl->ranges + idx + 1, rl->ranges + idx,
2496 1875 sizeof(*rl->ranges) * (rl->nb_ranges - idx));
2497 1875 rl->ranges[idx].start = start;
2498 1875 rl->ranges[idx].len = len;
2499 1875 rl->nb_ranges++;
2500
2501 /* merge ranges */
2502
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 19 taken 1875 times.
1875 if (idx > 0) {
2503 ✗ Range *prev = &rl->ranges[idx - 1];
2504 ✗ Range *cur = &rl->ranges[idx];
2505
0/2
✗ Branch 17 → 18 not taken.
✗ Branch 17 → 19 not taken.
✗ if (prev->start + prev->len == cur->start) {
2506 ✗ prev->len += cur->len;
2507 ✗ memmove(rl->ranges + idx - 1, rl->ranges + idx,
2508 ✗ sizeof(*rl->ranges) * (rl->nb_ranges - idx));
2509 ✗ rl->nb_ranges--;
2510 ✗ idx--;
2511 }
2512 }
2513
1/2
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 22 taken 1875 times.
1875 if (idx < rl->nb_ranges - 1) {
2514 ✗ Range *cur = &rl->ranges[idx];
2515 ✗ Range *next = &rl->ranges[idx + 1];
2516
0/2
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 22 not taken.
✗ if (cur->start + cur->len == next->start) {
2517 ✗ cur->len += next->len;
2518 ✗ memmove(rl->ranges + idx, rl->ranges + idx + 1,
2519 ✗ sizeof(*rl->ranges) * (rl->nb_ranges - idx - 1));
2520 ✗ rl->nb_ranges--;
2521 }
2522 }
2523
2524 1875 return 0;
2525 }
2526
2527 14 int ff_sws_thread_exec(void *priv,
2528 int (*func)(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads),
2529 int nb_threads, int nb_jobs)
2530 {
2531 AVSliceThread *slicethread;
2532 14 int ret = avpriv_slicethread_create2(&slicethread, priv, func, NULL, nb_threads);
2533
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 11 taken 14 times.
14 if (ret == AVERROR(ENOSYS)) {
2534 /* Fallback for build configurations without threading */
2535
0/2
✗ Branch 9 → 5 not taken.
✗ Branch 9 → 10 not taken.
✗ for (int i = 0; i < nb_jobs; i++) {
2536 ✗ int ret = func(priv, i, 0, nb_jobs, 1);
2537
0/2
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 8 not taken.
✗ if (ret)
2538 ✗ return ret;
2539 }
2540 ✗ return 0;
2541
1/2
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 14 times.
14 } else if (ret < 0) {
2542 ✗ return ret;
2543 }
2544
2545 14 ret = avpriv_slicethread_execute2(slicethread, nb_jobs, 0);
2546 14 avpriv_slicethread_free(&slicethread);
2547 14 return ret;
2548 }
2549