FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libswscale/utils.c
Date: 2024-02-16 17:37:06
Exec Total Coverage
Lines: 763 1316 58.0%
Functions: 24 44 54.5%
Branches: 621 1159 53.6%

Line Branch Exec Source
1 /*
2 * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "config.h"
22
23 #define _DEFAULT_SOURCE
24 #define _SVID_SOURCE // needed for MAP_ANONYMOUS
25 #define _DARWIN_C_SOURCE // needed for MAP_ANON
26 #include <inttypes.h>
27 #include <math.h>
28 #include <stdio.h>
29 #include <string.h>
30 #if HAVE_MMAP
31 #include <sys/mman.h>
32 #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS)
33 #define MAP_ANONYMOUS MAP_ANON
34 #endif
35 #endif
36 #if HAVE_VIRTUALALLOC
37 #include <windows.h>
38 #endif
39
40 #include "libavutil/attributes.h"
41 #include "libavutil/avassert.h"
42 #include "libavutil/cpu.h"
43 #include "libavutil/emms.h"
44 #include "libavutil/imgutils.h"
45 #include "libavutil/intreadwrite.h"
46 #include "libavutil/libm.h"
47 #include "libavutil/mathematics.h"
48 #include "libavutil/opt.h"
49 #include "libavutil/pixdesc.h"
50 #include "libavutil/slicethread.h"
51 #include "libavutil/thread.h"
52 #include "libavutil/aarch64/cpu.h"
53 #include "libavutil/ppc/cpu.h"
54 #include "libavutil/x86/asm.h"
55 #include "libavutil/x86/cpu.h"
56 #include "libavutil/loongarch/cpu.h"
57
58 #include "rgb2rgb.h"
59 #include "swscale.h"
60 #include "swscale_internal.h"
61
62 typedef struct FormatEntry {
63 uint8_t is_supported_in :1;
64 uint8_t is_supported_out :1;
65 uint8_t is_supported_endianness :1;
66 } FormatEntry;
67
68 static const FormatEntry format_entries[] = {
69 [AV_PIX_FMT_YUV420P] = { 1, 1 },
70 [AV_PIX_FMT_YUYV422] = { 1, 1 },
71 [AV_PIX_FMT_RGB24] = { 1, 1 },
72 [AV_PIX_FMT_BGR24] = { 1, 1 },
73 [AV_PIX_FMT_YUV422P] = { 1, 1 },
74 [AV_PIX_FMT_YUV444P] = { 1, 1 },
75 [AV_PIX_FMT_YUV410P] = { 1, 1 },
76 [AV_PIX_FMT_YUV411P] = { 1, 1 },
77 [AV_PIX_FMT_GRAY8] = { 1, 1 },
78 [AV_PIX_FMT_MONOWHITE] = { 1, 1 },
79 [AV_PIX_FMT_MONOBLACK] = { 1, 1 },
80 [AV_PIX_FMT_PAL8] = { 1, 0 },
81 [AV_PIX_FMT_YUVJ420P] = { 1, 1 },
82 [AV_PIX_FMT_YUVJ411P] = { 1, 1 },
83 [AV_PIX_FMT_YUVJ422P] = { 1, 1 },
84 [AV_PIX_FMT_YUVJ444P] = { 1, 1 },
85 [AV_PIX_FMT_YVYU422] = { 1, 1 },
86 [AV_PIX_FMT_UYVY422] = { 1, 1 },
87 [AV_PIX_FMT_UYYVYY411] = { 0, 0 },
88 [AV_PIX_FMT_BGR8] = { 1, 1 },
89 [AV_PIX_FMT_BGR4] = { 0, 1 },
90 [AV_PIX_FMT_BGR4_BYTE] = { 1, 1 },
91 [AV_PIX_FMT_RGB8] = { 1, 1 },
92 [AV_PIX_FMT_RGB4] = { 0, 1 },
93 [AV_PIX_FMT_RGB4_BYTE] = { 1, 1 },
94 [AV_PIX_FMT_NV12] = { 1, 1 },
95 [AV_PIX_FMT_NV21] = { 1, 1 },
96 [AV_PIX_FMT_ARGB] = { 1, 1 },
97 [AV_PIX_FMT_RGBA] = { 1, 1 },
98 [AV_PIX_FMT_ABGR] = { 1, 1 },
99 [AV_PIX_FMT_BGRA] = { 1, 1 },
100 [AV_PIX_FMT_0RGB] = { 1, 1 },
101 [AV_PIX_FMT_RGB0] = { 1, 1 },
102 [AV_PIX_FMT_0BGR] = { 1, 1 },
103 [AV_PIX_FMT_BGR0] = { 1, 1 },
104 [AV_PIX_FMT_GRAY9BE] = { 1, 1 },
105 [AV_PIX_FMT_GRAY9LE] = { 1, 1 },
106 [AV_PIX_FMT_GRAY10BE] = { 1, 1 },
107 [AV_PIX_FMT_GRAY10LE] = { 1, 1 },
108 [AV_PIX_FMT_GRAY12BE] = { 1, 1 },
109 [AV_PIX_FMT_GRAY12LE] = { 1, 1 },
110 [AV_PIX_FMT_GRAY14BE] = { 1, 1 },
111 [AV_PIX_FMT_GRAY14LE] = { 1, 1 },
112 [AV_PIX_FMT_GRAY16BE] = { 1, 1 },
113 [AV_PIX_FMT_GRAY16LE] = { 1, 1 },
114 [AV_PIX_FMT_YUV440P] = { 1, 1 },
115 [AV_PIX_FMT_YUVJ440P] = { 1, 1 },
116 [AV_PIX_FMT_YUV440P10LE] = { 1, 1 },
117 [AV_PIX_FMT_YUV440P10BE] = { 1, 1 },
118 [AV_PIX_FMT_YUV440P12LE] = { 1, 1 },
119 [AV_PIX_FMT_YUV440P12BE] = { 1, 1 },
120 [AV_PIX_FMT_YUVA420P] = { 1, 1 },
121 [AV_PIX_FMT_YUVA422P] = { 1, 1 },
122 [AV_PIX_FMT_YUVA444P] = { 1, 1 },
123 [AV_PIX_FMT_YUVA420P9BE] = { 1, 1 },
124 [AV_PIX_FMT_YUVA420P9LE] = { 1, 1 },
125 [AV_PIX_FMT_YUVA422P9BE] = { 1, 1 },
126 [AV_PIX_FMT_YUVA422P9LE] = { 1, 1 },
127 [AV_PIX_FMT_YUVA444P9BE] = { 1, 1 },
128 [AV_PIX_FMT_YUVA444P9LE] = { 1, 1 },
129 [AV_PIX_FMT_YUVA420P10BE]= { 1, 1 },
130 [AV_PIX_FMT_YUVA420P10LE]= { 1, 1 },
131 [AV_PIX_FMT_YUVA422P10BE]= { 1, 1 },
132 [AV_PIX_FMT_YUVA422P10LE]= { 1, 1 },
133 [AV_PIX_FMT_YUVA444P10BE]= { 1, 1 },
134 [AV_PIX_FMT_YUVA444P10LE]= { 1, 1 },
135 [AV_PIX_FMT_YUVA420P16BE]= { 1, 1 },
136 [AV_PIX_FMT_YUVA420P16LE]= { 1, 1 },
137 [AV_PIX_FMT_YUVA422P16BE]= { 1, 1 },
138 [AV_PIX_FMT_YUVA422P16LE]= { 1, 1 },
139 [AV_PIX_FMT_YUVA444P16BE]= { 1, 1 },
140 [AV_PIX_FMT_YUVA444P16LE]= { 1, 1 },
141 [AV_PIX_FMT_RGB48BE] = { 1, 1 },
142 [AV_PIX_FMT_RGB48LE] = { 1, 1 },
143 [AV_PIX_FMT_RGBA64BE] = { 1, 1, 1 },
144 [AV_PIX_FMT_RGBA64LE] = { 1, 1, 1 },
145 [AV_PIX_FMT_RGB565BE] = { 1, 1 },
146 [AV_PIX_FMT_RGB565LE] = { 1, 1 },
147 [AV_PIX_FMT_RGB555BE] = { 1, 1 },
148 [AV_PIX_FMT_RGB555LE] = { 1, 1 },
149 [AV_PIX_FMT_BGR565BE] = { 1, 1 },
150 [AV_PIX_FMT_BGR565LE] = { 1, 1 },
151 [AV_PIX_FMT_BGR555BE] = { 1, 1 },
152 [AV_PIX_FMT_BGR555LE] = { 1, 1 },
153 [AV_PIX_FMT_YUV420P16LE] = { 1, 1 },
154 [AV_PIX_FMT_YUV420P16BE] = { 1, 1 },
155 [AV_PIX_FMT_YUV422P16LE] = { 1, 1 },
156 [AV_PIX_FMT_YUV422P16BE] = { 1, 1 },
157 [AV_PIX_FMT_YUV444P16LE] = { 1, 1 },
158 [AV_PIX_FMT_YUV444P16BE] = { 1, 1 },
159 [AV_PIX_FMT_RGB444LE] = { 1, 1 },
160 [AV_PIX_FMT_RGB444BE] = { 1, 1 },
161 [AV_PIX_FMT_BGR444LE] = { 1, 1 },
162 [AV_PIX_FMT_BGR444BE] = { 1, 1 },
163 [AV_PIX_FMT_YA8] = { 1, 1 },
164 [AV_PIX_FMT_YA16BE] = { 1, 1 },
165 [AV_PIX_FMT_YA16LE] = { 1, 1 },
166 [AV_PIX_FMT_BGR48BE] = { 1, 1 },
167 [AV_PIX_FMT_BGR48LE] = { 1, 1 },
168 [AV_PIX_FMT_BGRA64BE] = { 1, 1, 1 },
169 [AV_PIX_FMT_BGRA64LE] = { 1, 1, 1 },
170 [AV_PIX_FMT_YUV420P9BE] = { 1, 1 },
171 [AV_PIX_FMT_YUV420P9LE] = { 1, 1 },
172 [AV_PIX_FMT_YUV420P10BE] = { 1, 1 },
173 [AV_PIX_FMT_YUV420P10LE] = { 1, 1 },
174 [AV_PIX_FMT_YUV420P12BE] = { 1, 1 },
175 [AV_PIX_FMT_YUV420P12LE] = { 1, 1 },
176 [AV_PIX_FMT_YUV420P14BE] = { 1, 1 },
177 [AV_PIX_FMT_YUV420P14LE] = { 1, 1 },
178 [AV_PIX_FMT_YUV422P9BE] = { 1, 1 },
179 [AV_PIX_FMT_YUV422P9LE] = { 1, 1 },
180 [AV_PIX_FMT_YUV422P10BE] = { 1, 1 },
181 [AV_PIX_FMT_YUV422P10LE] = { 1, 1 },
182 [AV_PIX_FMT_YUV422P12BE] = { 1, 1 },
183 [AV_PIX_FMT_YUV422P12LE] = { 1, 1 },
184 [AV_PIX_FMT_YUV422P14BE] = { 1, 1 },
185 [AV_PIX_FMT_YUV422P14LE] = { 1, 1 },
186 [AV_PIX_FMT_YUV444P9BE] = { 1, 1 },
187 [AV_PIX_FMT_YUV444P9LE] = { 1, 1 },
188 [AV_PIX_FMT_YUV444P10BE] = { 1, 1 },
189 [AV_PIX_FMT_YUV444P10LE] = { 1, 1 },
190 [AV_PIX_FMT_YUV444P12BE] = { 1, 1 },
191 [AV_PIX_FMT_YUV444P12LE] = { 1, 1 },
192 [AV_PIX_FMT_YUV444P14BE] = { 1, 1 },
193 [AV_PIX_FMT_YUV444P14LE] = { 1, 1 },
194 [AV_PIX_FMT_GBRP] = { 1, 1 },
195 [AV_PIX_FMT_GBRP9LE] = { 1, 1 },
196 [AV_PIX_FMT_GBRP9BE] = { 1, 1 },
197 [AV_PIX_FMT_GBRP10LE] = { 1, 1 },
198 [AV_PIX_FMT_GBRP10BE] = { 1, 1 },
199 [AV_PIX_FMT_GBRAP10LE] = { 1, 1 },
200 [AV_PIX_FMT_GBRAP10BE] = { 1, 1 },
201 [AV_PIX_FMT_GBRP12LE] = { 1, 1 },
202 [AV_PIX_FMT_GBRP12BE] = { 1, 1 },
203 [AV_PIX_FMT_GBRAP12LE] = { 1, 1 },
204 [AV_PIX_FMT_GBRAP12BE] = { 1, 1 },
205 [AV_PIX_FMT_GBRP14LE] = { 1, 1 },
206 [AV_PIX_FMT_GBRP14BE] = { 1, 1 },
207 [AV_PIX_FMT_GBRAP14LE] = { 1, 1 },
208 [AV_PIX_FMT_GBRAP14BE] = { 1, 1 },
209 [AV_PIX_FMT_GBRP16LE] = { 1, 1 },
210 [AV_PIX_FMT_GBRP16BE] = { 1, 1 },
211 [AV_PIX_FMT_GBRPF32LE] = { 1, 1 },
212 [AV_PIX_FMT_GBRPF32BE] = { 1, 1 },
213 [AV_PIX_FMT_GBRAPF32LE] = { 1, 1 },
214 [AV_PIX_FMT_GBRAPF32BE] = { 1, 1 },
215 [AV_PIX_FMT_GBRAP] = { 1, 1 },
216 [AV_PIX_FMT_GBRAP16LE] = { 1, 1 },
217 [AV_PIX_FMT_GBRAP16BE] = { 1, 1 },
218 [AV_PIX_FMT_BAYER_BGGR8] = { 1, 0 },
219 [AV_PIX_FMT_BAYER_RGGB8] = { 1, 0 },
220 [AV_PIX_FMT_BAYER_GBRG8] = { 1, 0 },
221 [AV_PIX_FMT_BAYER_GRBG8] = { 1, 0 },
222 [AV_PIX_FMT_BAYER_BGGR16LE] = { 1, 0 },
223 [AV_PIX_FMT_BAYER_BGGR16BE] = { 1, 0 },
224 [AV_PIX_FMT_BAYER_RGGB16LE] = { 1, 0 },
225 [AV_PIX_FMT_BAYER_RGGB16BE] = { 1, 0 },
226 [AV_PIX_FMT_BAYER_GBRG16LE] = { 1, 0 },
227 [AV_PIX_FMT_BAYER_GBRG16BE] = { 1, 0 },
228 [AV_PIX_FMT_BAYER_GRBG16LE] = { 1, 0 },
229 [AV_PIX_FMT_BAYER_GRBG16BE] = { 1, 0 },
230 [AV_PIX_FMT_XYZ12BE] = { 1, 1, 1 },
231 [AV_PIX_FMT_XYZ12LE] = { 1, 1, 1 },
232 [AV_PIX_FMT_AYUV64LE] = { 1, 1},
233 [AV_PIX_FMT_P010LE] = { 1, 1 },
234 [AV_PIX_FMT_P010BE] = { 1, 1 },
235 [AV_PIX_FMT_P012LE] = { 1, 1 },
236 [AV_PIX_FMT_P012BE] = { 1, 1 },
237 [AV_PIX_FMT_P016LE] = { 1, 1 },
238 [AV_PIX_FMT_P016BE] = { 1, 1 },
239 [AV_PIX_FMT_GRAYF32LE] = { 1, 1 },
240 [AV_PIX_FMT_GRAYF32BE] = { 1, 1 },
241 [AV_PIX_FMT_YUVA422P12BE] = { 1, 1 },
242 [AV_PIX_FMT_YUVA422P12LE] = { 1, 1 },
243 [AV_PIX_FMT_YUVA444P12BE] = { 1, 1 },
244 [AV_PIX_FMT_YUVA444P12LE] = { 1, 1 },
245 [AV_PIX_FMT_NV24] = { 1, 1 },
246 [AV_PIX_FMT_NV42] = { 1, 1 },
247 [AV_PIX_FMT_Y210LE] = { 1, 1 },
248 [AV_PIX_FMT_Y212LE] = { 1, 1 },
249 [AV_PIX_FMT_X2RGB10LE] = { 1, 1 },
250 [AV_PIX_FMT_X2BGR10LE] = { 1, 1 },
251 [AV_PIX_FMT_P210BE] = { 1, 1 },
252 [AV_PIX_FMT_P210LE] = { 1, 1 },
253 [AV_PIX_FMT_P212BE] = { 1, 1 },
254 [AV_PIX_FMT_P212LE] = { 1, 1 },
255 [AV_PIX_FMT_P410BE] = { 1, 1 },
256 [AV_PIX_FMT_P410LE] = { 1, 1 },
257 [AV_PIX_FMT_P412BE] = { 1, 1 },
258 [AV_PIX_FMT_P412LE] = { 1, 1 },
259 [AV_PIX_FMT_P216BE] = { 1, 1 },
260 [AV_PIX_FMT_P216LE] = { 1, 1 },
261 [AV_PIX_FMT_P416BE] = { 1, 1 },
262 [AV_PIX_FMT_P416LE] = { 1, 1 },
263 [AV_PIX_FMT_NV16] = { 1, 1 },
264 [AV_PIX_FMT_VUYA] = { 1, 1 },
265 [AV_PIX_FMT_VUYX] = { 1, 1 },
266 [AV_PIX_FMT_RGBAF16BE] = { 1, 0 },
267 [AV_PIX_FMT_RGBAF16LE] = { 1, 0 },
268 [AV_PIX_FMT_XV30LE] = { 1, 1 },
269 [AV_PIX_FMT_XV36LE] = { 1, 1 },
270 };
271
272 14630 int ff_shuffle_filter_coefficients(SwsContext *c, int *filterPos,
273 int filterSize, int16_t *filter,
274 int dstW)
275 {
276 #if ARCH_X86_64
277 int i, j, k;
278 14630 int cpu_flags = av_get_cpu_flags();
279
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14630 times.
14630 if (!filter)
280 return 0;
281
4/6
✓ Branch 0 taken 304 times.
✓ Branch 1 taken 14326 times.
✓ Branch 2 taken 304 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 304 times.
✗ Branch 5 not taken.
14630 if (EXTERNAL_AVX2_FAST(cpu_flags) && !(cpu_flags & AV_CPU_FLAG_SLOW_GATHER)) {
282
4/4
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 212 times.
✓ Branch 2 taken 54 times.
✓ Branch 3 taken 38 times.
304 if ((c->srcBpc == 8) && (c->dstBpc <= 14)) {
283 54 int16_t *filterCopy = NULL;
284
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 24 times.
54 if (filterSize > 4) {
285
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
30 if (!FF_ALLOC_TYPED_ARRAY(filterCopy, dstW * filterSize))
286 return AVERROR(ENOMEM);
287 30 memcpy(filterCopy, filter, dstW * filterSize * sizeof(int16_t));
288 }
289 // Do not swap filterPos for pixels which won't be processed by
290 // the main loop.
291
2/2
✓ Branch 0 taken 405 times.
✓ Branch 1 taken 54 times.
459 for (i = 0; i + 16 <= dstW; i += 16) {
292 405 FFSWAP(int, filterPos[i + 2], filterPos[i + 4]);
293 405 FFSWAP(int, filterPos[i + 3], filterPos[i + 5]);
294 405 FFSWAP(int, filterPos[i + 10], filterPos[i + 12]);
295 405 FFSWAP(int, filterPos[i + 11], filterPos[i + 13]);
296 }
297
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 24 times.
54 if (filterSize > 4) {
298 // 16 pixels are processed at a time.
299
2/2
✓ Branch 0 taken 330 times.
✓ Branch 1 taken 30 times.
360 for (i = 0; i + 16 <= dstW; i += 16) {
300 // 4 filter coeffs are processed at a time.
301
2/2
✓ Branch 0 taken 1782 times.
✓ Branch 1 taken 330 times.
2112 for (k = 0; k + 4 <= filterSize; k += 4) {
302
2/2
✓ Branch 0 taken 28512 times.
✓ Branch 1 taken 1782 times.
30294 for (j = 0; j < 16; ++j) {
303 28512 int from = (i + j) * filterSize + k;
304 28512 int to = i * filterSize + j * 4 + k * 16;
305 28512 memcpy(&filter[to], &filterCopy[from], 4 * sizeof(int16_t));
306 }
307 }
308 }
309 // 4 pixels are processed at a time in the tail.
310
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 30 times.
50 for (; i < dstW; i += 4) {
311 // 4 filter coeffs are processed at a time.
312 20 int rem = dstW - i >= 4 ? 4 : dstW - i;
313
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 20 times.
128 for (k = 0; k + 4 <= filterSize; k += 4) {
314
2/2
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 108 times.
540 for (j = 0; j < rem; ++j) {
315 432 int from = (i + j) * filterSize + k;
316 432 int to = i * filterSize + j * 4 + k * 4;
317 432 memcpy(&filter[to], &filterCopy[from], 4 * sizeof(int16_t));
318 }
319 }
320 }
321 }
322 54 av_free(filterCopy);
323 }
324 }
325 #endif
326 14630 return 0;
327 }
328
329 890558 int sws_isSupportedInput(enum AVPixelFormat pix_fmt)
330 {
331 890558 return (unsigned)pix_fmt < FF_ARRAY_ELEMS(format_entries) ?
332
2/2
✓ Branch 0 taken 886699 times.
✓ Branch 1 taken 3859 times.
890558 format_entries[pix_fmt].is_supported_in : 0;
333 }
334
335 890558 int sws_isSupportedOutput(enum AVPixelFormat pix_fmt)
336 {
337 890558 return (unsigned)pix_fmt < FF_ARRAY_ELEMS(format_entries) ?
338
2/2
✓ Branch 0 taken 886699 times.
✓ Branch 1 taken 3859 times.
890558 format_entries[pix_fmt].is_supported_out : 0;
339 }
340
341 291464 int sws_isSupportedEndiannessConversion(enum AVPixelFormat pix_fmt)
342 {
343 291464 return (unsigned)pix_fmt < FF_ARRAY_ELEMS(format_entries) ?
344
2/2
✓ Branch 0 taken 283748 times.
✓ Branch 1 taken 7716 times.
291464 format_entries[pix_fmt].is_supported_endianness : 0;
345 }
346
347 static double getSplineCoeff(double a, double b, double c, double d,
348 double dist)
349 {
350 if (dist <= 1.0)
351 return ((d * dist + c) * dist + b) * dist + a;
352 else
353 return getSplineCoeff(0.0,
354 b + 2.0 * c + 3.0 * d,
355 c + 3.0 * d,
356 -b - 3.0 * c - 6.0 * d,
357 dist - 1.0);
358 }
359
360 54776 static av_cold int get_local_pos(SwsContext *s, int chr_subsample, int pos, int dir)
361 {
362
3/4
✓ Branch 0 taken 54776 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21909 times.
✓ Branch 3 taken 32867 times.
54776 if (pos == -1 || pos <= -513) {
363 21909 pos = (128 << chr_subsample) - 128;
364 }
365 54776 pos += 128; // relative to ideal left edge
366 54776 return pos >> chr_subsample;
367 }
368
369 typedef struct {
370 int flag; ///< flag associated to the algorithm
371 const char *description; ///< human-readable description
372 int size_factor; ///< size factor used when initing the filters
373 } ScaleAlgorithm;
374
375 static const ScaleAlgorithm scale_algorithms[] = {
376 { SWS_AREA, "area averaging", 1 /* downscale only, for upscale it is bilinear */ },
377 { SWS_BICUBIC, "bicubic", 4 },
378 { SWS_BICUBLIN, "luma bicubic / chroma bilinear", -1 },
379 { SWS_BILINEAR, "bilinear", 2 },
380 { SWS_FAST_BILINEAR, "fast bilinear", -1 },
381 { SWS_GAUSS, "Gaussian", 8 /* infinite ;) */ },
382 { SWS_LANCZOS, "Lanczos", -1 /* custom */ },
383 { SWS_POINT, "nearest neighbor / point", -1 },
384 { SWS_SINC, "sinc", 20 /* infinite ;) */ },
385 { SWS_SPLINE, "bicubic spline", 20 /* infinite :)*/ },
386 { SWS_X, "experimental", 8 },
387 };
388
389 27388 static av_cold int initFilter(int16_t **outFilter, int32_t **filterPos,
390 int *outFilterSize, int xInc, int srcW,
391 int dstW, int filterAlign, int one,
392 int flags, int cpu_flags,
393 SwsVector *srcFilter, SwsVector *dstFilter,
394 double param[2], int srcPos, int dstPos)
395 {
396 int i;
397 int filterSize;
398 int filter2Size;
399 int minFilterSize;
400 27388 int64_t *filter = NULL;
401 27388 int64_t *filter2 = NULL;
402 27388 const int64_t fone = 1LL << (54 - FFMIN(av_log2(srcW/dstW), 8));
403 27388 int ret = -1;
404
405 27388 emms_c(); // FIXME should not be required but IS (even for non-MMX versions)
406
407 // NOTE: the +3 is for the MMX(+1) / SSE(+3) scaler which reads over the end
408
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 27388 times.
27388 if (!FF_ALLOC_TYPED_ARRAY(*filterPos, dstW + 3))
409 goto nomem;
410
411
6/8
✓ Branch 0 taken 22109 times.
✓ Branch 1 taken 5279 times.
✓ Branch 2 taken 19451 times.
✓ Branch 3 taken 2658 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5279 times.
✓ Branch 6 taken 19451 times.
✗ Branch 7 not taken.
46839 if (FFABS(xInc - 0x10000) < 10 && srcPos == dstPos) { // unscaled
412 int i;
413 19451 filterSize = 1;
414
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 19451 times.
19451 if (!FF_ALLOCZ_TYPED_ARRAY(filter, dstW * filterSize))
415 goto nomem;
416
417
2/2
✓ Branch 0 taken 5145854 times.
✓ Branch 1 taken 19451 times.
5165305 for (i = 0; i < dstW; i++) {
418 5145854 filter[i * filterSize] = fone;
419 5145854 (*filterPos)[i] = i;
420 }
421
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 7685 times.
7937 } else if (flags & SWS_POINT) { // lame looking point sampling mode
422 int i;
423 int64_t xDstInSrc;
424 252 filterSize = 1;
425
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 252 times.
252 if (!FF_ALLOC_TYPED_ARRAY(filter, dstW * filterSize))
426 goto nomem;
427
428 252 xDstInSrc = ((dstPos*(int64_t)xInc)>>8) - ((srcPos*0x8000LL)>>7);
429
2/2
✓ Branch 0 taken 78125 times.
✓ Branch 1 taken 252 times.
78377 for (i = 0; i < dstW; i++) {
430 78125 int xx = (xDstInSrc - ((filterSize - 1) << 15) + (1 << 15)) >> 16;
431
432 78125 (*filterPos)[i] = xx;
433 78125 filter[i] = fone;
434 78125 xDstInSrc += xInc;
435 }
436
4/4
✓ Branch 0 taken 5143 times.
✓ Branch 1 taken 2542 times.
✓ Branch 2 taken 5059 times.
✓ Branch 3 taken 84 times.
7685 } else if ((xInc <= (1 << 16) && (flags & SWS_AREA)) ||
437
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7601 times.
7685 (flags & SWS_FAST_BILINEAR)) { // bilinear upscale
438 int i;
439 int64_t xDstInSrc;
440 84 filterSize = 2;
441
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 84 times.
84 if (!FF_ALLOC_TYPED_ARRAY(filter, dstW * filterSize))
442 goto nomem;
443
444 84 xDstInSrc = ((dstPos*(int64_t)xInc)>>8) - ((srcPos*0x8000LL)>>7);
445
2/2
✓ Branch 0 taken 142992 times.
✓ Branch 1 taken 84 times.
143076 for (i = 0; i < dstW; i++) {
446 142992 int xx = (xDstInSrc - ((filterSize - 1) << 15) + (1 << 15)) >> 16;
447 int j;
448
449 142992 (*filterPos)[i] = xx;
450 // bilinear upscale / linear interpolate / area averaging
451
2/2
✓ Branch 0 taken 285984 times.
✓ Branch 1 taken 142992 times.
428976 for (j = 0; j < filterSize; j++) {
452 285984 int64_t coeff = fone - FFABS((int64_t)xx * (1 << 16) - xDstInSrc) * (fone >> 16);
453
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 285984 times.
285984 if (coeff < 0)
454 coeff = 0;
455 285984 filter[i * filterSize + j] = coeff;
456 285984 xx++;
457 }
458 142992 xDstInSrc += xInc;
459 }
460 } else {
461 int64_t xDstInSrc;
462 7601 int sizeFactor = -1;
463
464
1/2
✓ Branch 0 taken 15694 times.
✗ Branch 1 not taken.
15694 for (i = 0; i < FF_ARRAY_ELEMS(scale_algorithms); i++) {
465
3/4
✓ Branch 0 taken 7601 times.
✓ Branch 1 taken 8093 times.
✓ Branch 2 taken 7601 times.
✗ Branch 3 not taken.
15694 if (flags & scale_algorithms[i].flag && scale_algorithms[i].size_factor > 0) {
466 7601 sizeFactor = scale_algorithms[i].size_factor;
467 7601 break;
468 }
469 }
470
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7601 times.
7601 if (flags & SWS_LANCZOS)
471 sizeFactor = param[0] != SWS_PARAM_DEFAULT ? ceil(2 * param[0]) : 6;
472
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7601 times.
7601 av_assert0(sizeFactor > 0);
473
474
2/2
✓ Branch 0 taken 5059 times.
✓ Branch 1 taken 2542 times.
7601 if (xInc <= 1 << 16)
475 5059 filterSize = 1 + sizeFactor; // upscale
476 else
477 2542 filterSize = 1 + (sizeFactor * srcW + dstW - 1) / dstW;
478
479
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7601 times.
7601 filterSize = FFMIN(filterSize, srcW - 2);
480 7601 filterSize = FFMAX(filterSize, 1);
481
482
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 7601 times.
7601 if (!FF_ALLOC_TYPED_ARRAY(filter, dstW * filterSize))
483 goto nomem;
484 7601 xDstInSrc = ((dstPos*(int64_t)xInc)>>7) - ((srcPos*0x10000LL)>>7);
485
2/2
✓ Branch 0 taken 2204283 times.
✓ Branch 1 taken 7601 times.
2211884 for (i = 0; i < dstW; i++) {
486 2204283 int xx = (xDstInSrc - (filterSize - 2) * (1LL<<16)) / (1 << 17);
487 int j;
488 2204283 (*filterPos)[i] = xx;
489
2/2
✓ Branch 0 taken 12679070 times.
✓ Branch 1 taken 2204283 times.
14883353 for (j = 0; j < filterSize; j++) {
490 12679070 int64_t d = (FFABS(((int64_t)xx * (1 << 17)) - xDstInSrc)) << 13;
491 double floatd;
492 int64_t coeff;
493
494
2/2
✓ Branch 0 taken 3281855 times.
✓ Branch 1 taken 9397215 times.
12679070 if (xInc > 1 << 16)
495 3281855 d = d * dstW / srcW;
496 12679070 floatd = d * (1.0 / (1 << 30));
497
498
2/2
✓ Branch 0 taken 12025652 times.
✓ Branch 1 taken 653418 times.
12679070 if (flags & SWS_BICUBIC) {
499
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12025652 times.
12025652 int64_t B = (param[0] != SWS_PARAM_DEFAULT ? param[0] : 0) * (1 << 24);
500
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12025652 times.
12025652 int64_t C = (param[1] != SWS_PARAM_DEFAULT ? param[1] : 0.6) * (1 << 24);
501
502
2/2
✓ Branch 0 taken 2259592 times.
✓ Branch 1 taken 9766060 times.
12025652 if (d >= 1LL << 31) {
503 2259592 coeff = 0.0;
504 } else {
505 9766060 int64_t dd = (d * d) >> 30;
506 9766060 int64_t ddd = (dd * d) >> 30;
507
508
2/2
✓ Branch 0 taken 4889018 times.
✓ Branch 1 taken 4877042 times.
9766060 if (d < 1LL << 30)
509 4889018 coeff = (12 * (1 << 24) - 9 * B - 6 * C) * ddd +
510 4889018 (-18 * (1 << 24) + 12 * B + 6 * C) * dd +
511 4889018 (6 * (1 << 24) - 2 * B) * (1 << 30);
512 else
513 4877042 coeff = (-B - 6 * C) * ddd +
514 4877042 (6 * B + 30 * C) * dd +
515 4877042 (-12 * B - 48 * C) * d +
516 4877042 (8 * B + 24 * C) * (1 << 30);
517 }
518 12025652 coeff /= (1LL<<54)/fone;
519
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 653418 times.
653418 } else if (flags & SWS_X) {
520 double A = param[0] != SWS_PARAM_DEFAULT ? param[0] : 1.0;
521 double c;
522
523 if (floatd < 1.0)
524 c = cos(floatd * M_PI);
525 else
526 c = -1.0;
527 if (c < 0.0)
528 c = -pow(-c, A);
529 else
530 c = pow(c, A);
531 coeff = (c * 0.5 + 0.5) * fone;
532
2/2
✓ Branch 0 taken 292968 times.
✓ Branch 1 taken 360450 times.
653418 } else if (flags & SWS_AREA) {
533 292968 int64_t d2 = d - (1 << 29);
534
2/2
✓ Branch 0 taken 218924 times.
✓ Branch 1 taken 74044 times.
292968 if (d2 * xInc < -(1LL << (29 + 16)))
535 218924 coeff = 1.0 * (1LL << (30 + 16));
536
2/2
✓ Branch 0 taken 63602 times.
✓ Branch 1 taken 10442 times.
74044 else if (d2 * xInc < (1LL << (29 + 16)))
537 63602 coeff = -d2 * xInc + (1LL << (29 + 16));
538 else
539 10442 coeff = 0.0;
540 292968 coeff *= fone >> (30 + 16);
541
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 360450 times.
360450 } else if (flags & SWS_GAUSS) {
542 double p = param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0;
543 coeff = exp2(-p * floatd * floatd) * fone;
544
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 360450 times.
360450 } else if (flags & SWS_SINC) {
545 coeff = (d ? sin(floatd * M_PI) / (floatd * M_PI) : 1.0) * fone;
546
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 360450 times.
360450 } else if (flags & SWS_LANCZOS) {
547 double p = param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0;
548 coeff = (d ? sin(floatd * M_PI) * sin(floatd * M_PI / p) /
549 (floatd * floatd * M_PI * M_PI / p) : 1.0) * fone;
550 if (floatd > p)
551 coeff = 0;
552
1/2
✓ Branch 0 taken 360450 times.
✗ Branch 1 not taken.
360450 } else if (flags & SWS_BILINEAR) {
553 360450 coeff = (1 << 30) - d;
554
2/2
✓ Branch 0 taken 43542 times.
✓ Branch 1 taken 316908 times.
360450 if (coeff < 0)
555 43542 coeff = 0;
556 360450 coeff *= fone >> 30;
557 } else if (flags & SWS_SPLINE) {
558 double p = -2.196152422706632;
559 coeff = getSplineCoeff(1.0, 0.0, p, -p - 1.0, floatd) * fone;
560 } else {
561 av_assert0(0);
562 }
563
564 12679070 filter[i * filterSize + j] = coeff;
565 12679070 xx++;
566 }
567 2204283 xDstInSrc += 2 * xInc;
568 }
569 }
570
571 /* apply src & dst Filter to filter -> filter2
572 * av_free(filter);
573 */
574
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27388 times.
27388 av_assert0(filterSize > 0);
575 27388 filter2Size = filterSize;
576
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27388 times.
27388 if (srcFilter)
577 filter2Size += srcFilter->length - 1;
578
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27388 times.
27388 if (dstFilter)
579 filter2Size += dstFilter->length - 1;
580
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27388 times.
27388 av_assert0(filter2Size > 0);
581
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 27388 times.
27388 if (!FF_ALLOCZ_TYPED_ARRAY(filter2, dstW * filter2Size))
582 goto nomem;
583
2/2
✓ Branch 0 taken 7571254 times.
✓ Branch 1 taken 27388 times.
7598642 for (i = 0; i < dstW; i++) {
584 int j, k;
585
586
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7571254 times.
7571254 if (srcFilter) {
587 for (k = 0; k < srcFilter->length; k++) {
588 for (j = 0; j < filterSize; j++)
589 filter2[i * filter2Size + k + j] +=
590 srcFilter->coeff[k] * filter[i * filterSize + j];
591 }
592 } else {
593
2/2
✓ Branch 0 taken 18189033 times.
✓ Branch 1 taken 7571254 times.
25760287 for (j = 0; j < filterSize; j++)
594 18189033 filter2[i * filter2Size + j] = filter[i * filterSize + j];
595 }
596 // FIXME dstFilter
597
598 7571254 (*filterPos)[i] += (filterSize - 1) / 2 - (filter2Size - 1) / 2;
599 }
600 27388 av_freep(&filter);
601
602 /* try to reduce the filter-size (step1 find size and shift left) */
603 // Assume it is near normalized (*0.5 or *2.0 is OK but * 0.001 is not).
604 27388 minFilterSize = 0;
605
2/2
✓ Branch 0 taken 7571254 times.
✓ Branch 1 taken 27388 times.
7598642 for (i = dstW - 1; i >= 0; i--) {
606 7571254 int min = filter2Size;
607 int j;
608 7571254 int64_t cutOff = 0.0;
609
610 /* get rid of near zero elements on the left by shifting left */
611
1/2
✓ Branch 0 taken 8678749 times.
✗ Branch 1 not taken.
8678749 for (j = 0; j < filter2Size; j++) {
612 int k;
613 8678749 cutOff += FFABS(filter2[i * filter2Size]);
614
615
2/2
✓ Branch 0 taken 7568675 times.
✓ Branch 1 taken 1110074 times.
8678749 if (cutOff > SWS_MAX_REDUCE_CUTOFF * fone)
616 7568675 break;
617
618 /* preserve monotonicity because the core can't handle the
619 * filter otherwise */
620
4/4
✓ Branch 0 taken 1103817 times.
✓ Branch 1 taken 6257 times.
✓ Branch 2 taken 2579 times.
✓ Branch 3 taken 1101238 times.
1110074 if (i < dstW - 1 && (*filterPos)[i] >= (*filterPos)[i + 1])
621 2579 break;
622
623 // move filter coefficients left
624
2/2
✓ Branch 0 taken 5192141 times.
✓ Branch 1 taken 1107495 times.
6299636 for (k = 1; k < filter2Size; k++)
625 5192141 filter2[i * filter2Size + k - 1] = filter2[i * filter2Size + k];
626 1107495 filter2[i * filter2Size + k - 1] = 0;
627 1107495 (*filterPos)[i]++;
628 }
629
630 7571254 cutOff = 0;
631 /* count near zeros on the right */
632
2/2
✓ Branch 0 taken 4720935 times.
✓ Branch 1 taken 5224810 times.
9945745 for (j = filter2Size - 1; j > 0; j--) {
633 4720935 cutOff += FFABS(filter2[i * filter2Size + j]);
634
635
2/2
✓ Branch 0 taken 2346444 times.
✓ Branch 1 taken 2374491 times.
4720935 if (cutOff > SWS_MAX_REDUCE_CUTOFF * fone)
636 2346444 break;
637 2374491 min--;
638 }
639
640
2/2
✓ Branch 0 taken 28044 times.
✓ Branch 1 taken 7543210 times.
7571254 if (min > minFilterSize)
641 28044 minFilterSize = min;
642 }
643
644 if (PPC_ALTIVEC(cpu_flags)) {
645 // we can handle the special case 4, so we don't want to go the full 8
646 if (minFilterSize < 5)
647 filterAlign = 4;
648
649 /* We really don't want to waste our time doing useless computation, so
650 * fall back on the scalar C code for very small filters.
651 * Vectorizing is worth it only if you have a decent-sized vector. */
652 if (minFilterSize < 3)
653 filterAlign = 1;
654 }
655
656
2/2
✓ Branch 0 taken 860 times.
✓ Branch 1 taken 26528 times.
27388 if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) {
657 // special case for unscaled vertical filtering
658
4/4
✓ Branch 0 taken 853 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 427 times.
✓ Branch 3 taken 426 times.
860 if (minFilterSize == 1 && filterAlign == 2)
659 427 filterAlign = 1;
660 }
661
662 if (have_lasx(cpu_flags) || have_lsx(cpu_flags)) {
663 int reNum = minFilterSize & (0x07);
664
665 if (minFilterSize < 5)
666 filterAlign = 4;
667 if (reNum < 3)
668 filterAlign = 1;
669 }
670
671
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27388 times.
27388 av_assert0(minFilterSize > 0);
672 27388 filterSize = (minFilterSize + (filterAlign - 1)) & (~(filterAlign - 1));
673
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27388 times.
27388 av_assert0(filterSize > 0);
674 27388 filter = av_malloc_array(dstW, filterSize * sizeof(*filter));
675
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27388 times.
27388 if (!filter)
676 goto nomem;
677
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27388 times.
27388 if (filterSize >= MAX_FILTER_SIZE * 16 /
678
2/2
✓ Branch 0 taken 18316 times.
✓ Branch 1 taken 9072 times.
27388 ((flags & SWS_ACCURATE_RND) ? APCK_SIZE : 16)) {
679 ret = RETCODE_USE_CASCADE;
680 goto fail;
681 }
682 27388 *outFilterSize = filterSize;
683
684
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27388 times.
27388 if (flags & SWS_PRINT_INFO)
685 av_log(NULL, AV_LOG_VERBOSE,
686 "SwScaler: reducing / aligning filtersize %d -> %d\n",
687 filter2Size, filterSize);
688 /* try to reduce the filter-size (step2 reduce it) */
689
2/2
✓ Branch 0 taken 7571254 times.
✓ Branch 1 taken 27388 times.
7598642 for (i = 0; i < dstW; i++) {
690 int j;
691
692
2/2
✓ Branch 0 taken 16185853 times.
✓ Branch 1 taken 7571254 times.
23757107 for (j = 0; j < filterSize; j++) {
693
2/2
✓ Branch 0 taken 254034 times.
✓ Branch 1 taken 15931819 times.
16185853 if (j >= filter2Size)
694 254034 filter[i * filterSize + j] = 0;
695 else
696 15931819 filter[i * filterSize + j] = filter2[i * filter2Size + j];
697
4/4
✓ Branch 0 taken 12966699 times.
✓ Branch 1 taken 3219154 times.
✓ Branch 2 taken 207360 times.
✓ Branch 3 taken 12759339 times.
16185853 if ((flags & SWS_BITEXACT) && j >= minFilterSize)
698 207360 filter[i * filterSize + j] = 0;
699 }
700 }
701
702 // FIXME try to align filterPos if possible
703
704 // fix borders
705
2/2
✓ Branch 0 taken 7571254 times.
✓ Branch 1 taken 27388 times.
7598642 for (i = 0; i < dstW; i++) {
706 int j;
707
2/2
✓ Branch 0 taken 17450 times.
✓ Branch 1 taken 7553804 times.
7571254 if ((*filterPos)[i] < 0) {
708 // move filter coefficients left to compensate for filterPos
709
2/2
✓ Branch 0 taken 77577 times.
✓ Branch 1 taken 17450 times.
95027 for (j = 1; j < filterSize; j++) {
710 77577 int left = FFMAX(j + (*filterPos)[i], 0);
711 77577 filter[i * filterSize + left] += filter[i * filterSize + j];
712 77577 filter[i * filterSize + j] = 0;
713 }
714 17450 (*filterPos)[i]= 0;
715 }
716
717
2/2
✓ Branch 0 taken 25755 times.
✓ Branch 1 taken 7545499 times.
7571254 if ((*filterPos)[i] + filterSize > srcW) {
718 25755 int shift = (*filterPos)[i] + FFMIN(filterSize - srcW, 0);
719 25755 int64_t acc = 0;
720
721
2/2
✓ Branch 0 taken 130693 times.
✓ Branch 1 taken 25755 times.
156448 for (j = filterSize - 1; j >= 0; j--) {
722
2/2
✓ Branch 0 taken 41122 times.
✓ Branch 1 taken 89571 times.
130693 if ((*filterPos)[i] + j >= srcW) {
723 41122 acc += filter[i * filterSize + j];
724 41122 filter[i * filterSize + j] = 0;
725 }
726 }
727
2/2
✓ Branch 0 taken 130693 times.
✓ Branch 1 taken 25755 times.
156448 for (j = filterSize - 1; j >= 0; j--) {
728
2/2
✓ Branch 0 taken 41122 times.
✓ Branch 1 taken 89571 times.
130693 if (j < shift) {
729 41122 filter[i * filterSize + j] = 0;
730 } else {
731 89571 filter[i * filterSize + j] = filter[i * filterSize + j - shift];
732 }
733 }
734
735 25755 (*filterPos)[i]-= shift;
736 25755 filter[i * filterSize + srcW - 1 - (*filterPos)[i]] += acc;
737 }
738
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7571254 times.
7571254 av_assert0((*filterPos)[i] >= 0);
739
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7571254 times.
7571254 av_assert0((*filterPos)[i] < srcW);
740
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7571254 times.
7571254 if ((*filterPos)[i] + filterSize > srcW) {
741 for (j = 0; j < filterSize; j++) {
742 av_assert0((*filterPos)[i] + j < srcW || !filter[i * filterSize + j]);
743 }
744 }
745 }
746
747 // Note the +1 is for the MMX scaler which reads over the end
748 /* align at 16 for AltiVec (needed by hScale_altivec_real) */
749
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 27388 times.
27388 if (!FF_ALLOCZ_TYPED_ARRAY(*outFilter, *outFilterSize * (dstW + 3)))
750 goto nomem;
751
752 /* normalize & store in outFilter */
753
2/2
✓ Branch 0 taken 7571254 times.
✓ Branch 1 taken 27388 times.
7598642 for (i = 0; i < dstW; i++) {
754 int j;
755 7571254 int64_t error = 0;
756 7571254 int64_t sum = 0;
757
758
2/2
✓ Branch 0 taken 16185853 times.
✓ Branch 1 taken 7571254 times.
23757107 for (j = 0; j < filterSize; j++) {
759 16185853 sum += filter[i * filterSize + j];
760 }
761 7571254 sum = (sum + one / 2) / one;
762
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7571254 times.
7571254 if (!sum) {
763 av_log(NULL, AV_LOG_WARNING, "SwScaler: zero vector in scaling\n");
764 sum = 1;
765 }
766
2/2
✓ Branch 0 taken 16185853 times.
✓ Branch 1 taken 7571254 times.
23757107 for (j = 0; j < *outFilterSize; j++) {
767 16185853 int64_t v = filter[i * filterSize + j] + error;
768
2/2
✓ Branch 0 taken 11338082 times.
✓ Branch 1 taken 4847771 times.
16185853 int intV = ROUNDED_DIV(v, sum);
769 16185853 (*outFilter)[i * (*outFilterSize) + j] = intV;
770 16185853 error = v - intV * sum;
771 }
772 }
773
774 27388 (*filterPos)[dstW + 0] =
775 27388 (*filterPos)[dstW + 1] =
776 27388 (*filterPos)[dstW + 2] = (*filterPos)[dstW - 1]; /* the MMX/SSE scaler will
777 * read over the end */
778
2/2
✓ Branch 0 taken 68410 times.
✓ Branch 1 taken 27388 times.
95798 for (i = 0; i < *outFilterSize; i++) {
779 68410 int k = (dstW - 1) * (*outFilterSize) + i;
780 68410 (*outFilter)[k + 1 * (*outFilterSize)] =
781 68410 (*outFilter)[k + 2 * (*outFilterSize)] =
782 68410 (*outFilter)[k + 3 * (*outFilterSize)] = (*outFilter)[k];
783 }
784
785 27388 ret = 0;
786 27388 goto done;
787 nomem:
788 ret = AVERROR(ENOMEM);
789 fail:
790 if(ret < 0)
791 av_log(NULL, ret == RETCODE_USE_CASCADE ? AV_LOG_DEBUG : AV_LOG_ERROR, "sws: initFilter failed\n");
792 done:
793 27388 av_free(filter);
794 27388 av_free(filter2);
795 27388 return ret;
796 }
797
798 3595 static void fill_rgb2yuv_table(SwsContext *c, const int table[4], int dstRange)
799 {
800 int64_t W, V, Z, Cy, Cu, Cv;
801 3595 int64_t vr = table[0];
802 3595 int64_t ub = table[1];
803 3595 int64_t ug = -table[2];
804 3595 int64_t vg = -table[3];
805 3595 int64_t ONE = 65536;
806 3595 int64_t cy = ONE;
807 3595 uint8_t *p = (uint8_t*)c->input_rgb2yuv_table;
808 int i;
809 static const int8_t map[] = {
810 BY_IDX, GY_IDX, -1 , BY_IDX, BY_IDX, GY_IDX, -1 , BY_IDX,
811 RY_IDX, -1 , GY_IDX, RY_IDX, RY_IDX, -1 , GY_IDX, RY_IDX,
812 RY_IDX, GY_IDX, -1 , RY_IDX, RY_IDX, GY_IDX, -1 , RY_IDX,
813 BY_IDX, -1 , GY_IDX, BY_IDX, BY_IDX, -1 , GY_IDX, BY_IDX,
814 BU_IDX, GU_IDX, -1 , BU_IDX, BU_IDX, GU_IDX, -1 , BU_IDX,
815 RU_IDX, -1 , GU_IDX, RU_IDX, RU_IDX, -1 , GU_IDX, RU_IDX,
816 RU_IDX, GU_IDX, -1 , RU_IDX, RU_IDX, GU_IDX, -1 , RU_IDX,
817 BU_IDX, -1 , GU_IDX, BU_IDX, BU_IDX, -1 , GU_IDX, BU_IDX,
818 BV_IDX, GV_IDX, -1 , BV_IDX, BV_IDX, GV_IDX, -1 , BV_IDX,
819 RV_IDX, -1 , GV_IDX, RV_IDX, RV_IDX, -1 , GV_IDX, RV_IDX,
820 RV_IDX, GV_IDX, -1 , RV_IDX, RV_IDX, GV_IDX, -1 , RV_IDX,
821 BV_IDX, -1 , GV_IDX, BV_IDX, BV_IDX, -1 , GV_IDX, BV_IDX,
822 RY_IDX, BY_IDX, RY_IDX, BY_IDX, RY_IDX, BY_IDX, RY_IDX, BY_IDX,
823 BY_IDX, RY_IDX, BY_IDX, RY_IDX, BY_IDX, RY_IDX, BY_IDX, RY_IDX,
824 GY_IDX, -1 , GY_IDX, -1 , GY_IDX, -1 , GY_IDX, -1 ,
825 -1 , GY_IDX, -1 , GY_IDX, -1 , GY_IDX, -1 , GY_IDX,
826 RU_IDX, BU_IDX, RU_IDX, BU_IDX, RU_IDX, BU_IDX, RU_IDX, BU_IDX,
827 BU_IDX, RU_IDX, BU_IDX, RU_IDX, BU_IDX, RU_IDX, BU_IDX, RU_IDX,
828 GU_IDX, -1 , GU_IDX, -1 , GU_IDX, -1 , GU_IDX, -1 ,
829 -1 , GU_IDX, -1 , GU_IDX, -1 , GU_IDX, -1 , GU_IDX,
830 RV_IDX, BV_IDX, RV_IDX, BV_IDX, RV_IDX, BV_IDX, RV_IDX, BV_IDX,
831 BV_IDX, RV_IDX, BV_IDX, RV_IDX, BV_IDX, RV_IDX, BV_IDX, RV_IDX,
832 GV_IDX, -1 , GV_IDX, -1 , GV_IDX, -1 , GV_IDX, -1 ,
833 -1 , GV_IDX, -1 , GV_IDX, -1 , GV_IDX, -1 , GV_IDX, //23
834 -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //24
835 -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //25
836 -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //26
837 -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //27
838 -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //28
839 -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //29
840 -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //30
841 -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //31
842 BY_IDX, GY_IDX, RY_IDX, -1 , -1 , -1 , -1 , -1 , //32
843 BU_IDX, GU_IDX, RU_IDX, -1 , -1 , -1 , -1 , -1 , //33
844 BV_IDX, GV_IDX, RV_IDX, -1 , -1 , -1 , -1 , -1 , //34
845 };
846
847 3595 dstRange = 0; //FIXME range = 1 is handled elsewhere
848
849
1/2
✓ Branch 0 taken 3595 times.
✗ Branch 1 not taken.
3595 if (!dstRange) {
850 3595 cy = cy * 255 / 219;
851 } else {
852 vr = vr * 224 / 255;
853 ub = ub * 224 / 255;
854 ug = ug * 224 / 255;
855 vg = vg * 224 / 255;
856 }
857
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3595 times.
3595 W = ROUNDED_DIV(ONE*ONE*ug, ub);
858
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3595 times.
3595 V = ROUNDED_DIV(ONE*ONE*vg, vr);
859 3595 Z = ONE*ONE-W-V;
860
861
1/2
✓ Branch 0 taken 3595 times.
✗ Branch 1 not taken.
3595 Cy = ROUNDED_DIV(cy*Z, ONE);
862
1/2
✓ Branch 0 taken 3595 times.
✗ Branch 1 not taken.
3595 Cu = ROUNDED_DIV(ub*Z, ONE);
863
1/2
✓ Branch 0 taken 3595 times.
✗ Branch 1 not taken.
3595 Cv = ROUNDED_DIV(vr*Z, ONE);
864
865
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3595 times.
3595 c->input_rgb2yuv_table[RY_IDX] = -ROUNDED_DIV((1 << RGB2YUV_SHIFT)*V , Cy);
866 3595 c->input_rgb2yuv_table[GY_IDX] = ROUNDED_DIV((1 << RGB2YUV_SHIFT)*ONE*ONE , Cy);
867
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3595 times.
3595 c->input_rgb2yuv_table[BY_IDX] = -ROUNDED_DIV((1 << RGB2YUV_SHIFT)*W , Cy);
868
869
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3595 times.
3595 c->input_rgb2yuv_table[RU_IDX] = ROUNDED_DIV((1 << RGB2YUV_SHIFT)*V , Cu);
870 3595 c->input_rgb2yuv_table[GU_IDX] = -ROUNDED_DIV((1 << RGB2YUV_SHIFT)*ONE*ONE , Cu);
871
1/2
✓ Branch 0 taken 3595 times.
✗ Branch 1 not taken.
3595 c->input_rgb2yuv_table[BU_IDX] = ROUNDED_DIV((1 << RGB2YUV_SHIFT)*(Z+W) , Cu);
872
873
1/2
✓ Branch 0 taken 3595 times.
✗ Branch 1 not taken.
3595 c->input_rgb2yuv_table[RV_IDX] = ROUNDED_DIV((1 << RGB2YUV_SHIFT)*(V+Z) , Cv);
874 3595 c->input_rgb2yuv_table[GV_IDX] = -ROUNDED_DIV((1 << RGB2YUV_SHIFT)*ONE*ONE , Cv);
875
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3595 times.
3595 c->input_rgb2yuv_table[BV_IDX] = ROUNDED_DIV((1 << RGB2YUV_SHIFT)*W , Cv);
876
877
1/2
✓ Branch 0 taken 3595 times.
✗ Branch 1 not taken.
3595 if(/*!dstRange && */!memcmp(table, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT], sizeof(ff_yuv2rgb_coeffs[SWS_CS_DEFAULT]))) {
878 3595 c->input_rgb2yuv_table[BY_IDX] = ((int)(0.114 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
879 3595 c->input_rgb2yuv_table[BV_IDX] = (-(int)(0.081 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
880 3595 c->input_rgb2yuv_table[BU_IDX] = ((int)(0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
881 3595 c->input_rgb2yuv_table[GY_IDX] = ((int)(0.587 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
882 3595 c->input_rgb2yuv_table[GV_IDX] = (-(int)(0.419 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
883 3595 c->input_rgb2yuv_table[GU_IDX] = (-(int)(0.331 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
884 3595 c->input_rgb2yuv_table[RY_IDX] = ((int)(0.299 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
885 3595 c->input_rgb2yuv_table[RV_IDX] = ((int)(0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
886 3595 c->input_rgb2yuv_table[RU_IDX] = (-(int)(0.169 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
887 }
888
2/2
✓ Branch 0 taken 1006600 times.
✓ Branch 1 taken 3595 times.
1010195 for(i=0; i<FF_ARRAY_ELEMS(map); i++)
889
2/2
✓ Branch 0 taken 550035 times.
✓ Branch 1 taken 456565 times.
1006600 AV_WL16(p + 16*4 + 2*i, map[i] >= 0 ? c->input_rgb2yuv_table[map[i]] : 0);
890 3595 }
891
892 78 static void fill_xyztables(struct SwsContext *c)
893 {
894 int i;
895 78 double xyzgamma = XYZ_GAMMA;
896 78 double rgbgamma = 1.0 / RGB_GAMMA;
897 78 double xyzgammainv = 1.0 / XYZ_GAMMA;
898 78 double rgbgammainv = RGB_GAMMA;
899 static const int16_t xyz2rgb_matrix[3][4] = {
900 {13270, -6295, -2041},
901 {-3969, 7682, 170},
902 { 228, -835, 4329} };
903 static const int16_t rgb2xyz_matrix[3][4] = {
904 {1689, 1464, 739},
905 { 871, 2929, 296},
906 { 79, 488, 3891} };
907 static int16_t xyzgamma_tab[4096], rgbgamma_tab[4096], xyzgammainv_tab[4096], rgbgammainv_tab[4096];
908
909 78 memcpy(c->xyz2rgb_matrix, xyz2rgb_matrix, sizeof(c->xyz2rgb_matrix));
910 78 memcpy(c->rgb2xyz_matrix, rgb2xyz_matrix, sizeof(c->rgb2xyz_matrix));
911 78 c->xyzgamma = xyzgamma_tab;
912 78 c->rgbgamma = rgbgamma_tab;
913 78 c->xyzgammainv = xyzgammainv_tab;
914 78 c->rgbgammainv = rgbgammainv_tab;
915
916
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 24 times.
78 if (rgbgamma_tab[4095])
917 54 return;
918
919 /* set gamma vectors */
920
2/2
✓ Branch 0 taken 98304 times.
✓ Branch 1 taken 24 times.
98328 for (i = 0; i < 4096; i++) {
921 98304 xyzgamma_tab[i] = lrint(pow(i / 4095.0, xyzgamma) * 4095.0);
922 98304 rgbgamma_tab[i] = lrint(pow(i / 4095.0, rgbgamma) * 4095.0);
923 98304 xyzgammainv_tab[i] = lrint(pow(i / 4095.0, xyzgammainv) * 4095.0);
924 98304 rgbgammainv_tab[i] = lrint(pow(i / 4095.0, rgbgammainv) * 4095.0);
925 }
926 }
927
928 7980 static int handle_jpeg(enum AVPixelFormat *format)
929 {
930
7/7
✓ Branch 0 taken 157 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 42 times.
✓ Branch 3 taken 52 times.
✓ Branch 4 taken 21 times.
✓ Branch 5 taken 254 times.
✓ Branch 6 taken 7439 times.
7980 switch (*format) {
931 157 case AV_PIX_FMT_YUVJ420P:
932 157 *format = AV_PIX_FMT_YUV420P;
933 157 return 1;
934 15 case AV_PIX_FMT_YUVJ411P:
935 15 *format = AV_PIX_FMT_YUV411P;
936 15 return 1;
937 42 case AV_PIX_FMT_YUVJ422P:
938 42 *format = AV_PIX_FMT_YUV422P;
939 42 return 1;
940 52 case AV_PIX_FMT_YUVJ444P:
941 52 *format = AV_PIX_FMT_YUV444P;
942 52 return 1;
943 21 case AV_PIX_FMT_YUVJ440P:
944 21 *format = AV_PIX_FMT_YUV440P;
945 21 return 1;
946 254 case AV_PIX_FMT_GRAY8:
947 case AV_PIX_FMT_YA8:
948 case AV_PIX_FMT_GRAY9LE:
949 case AV_PIX_FMT_GRAY9BE:
950 case AV_PIX_FMT_GRAY10LE:
951 case AV_PIX_FMT_GRAY10BE:
952 case AV_PIX_FMT_GRAY12LE:
953 case AV_PIX_FMT_GRAY12BE:
954 case AV_PIX_FMT_GRAY14LE:
955 case AV_PIX_FMT_GRAY14BE:
956 case AV_PIX_FMT_GRAY16LE:
957 case AV_PIX_FMT_GRAY16BE:
958 case AV_PIX_FMT_YA16BE:
959 case AV_PIX_FMT_YA16LE:
960 254 return 1;
961 7439 default:
962 7439 return 0;
963 }
964 }
965
966 40724 static int handle_0alpha(enum AVPixelFormat *format)
967 {
968
5/5
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 202 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 40468 times.
40724 switch (*format) {
969 18 case AV_PIX_FMT_0BGR : *format = AV_PIX_FMT_ABGR ; return 1;
970 202 case AV_PIX_FMT_BGR0 : *format = AV_PIX_FMT_BGRA ; return 4;
971 18 case AV_PIX_FMT_0RGB : *format = AV_PIX_FMT_ARGB ; return 1;
972 18 case AV_PIX_FMT_RGB0 : *format = AV_PIX_FMT_RGBA ; return 4;
973 40468 default: return 0;
974 }
975 }
976
977 40724 static int handle_xyz(enum AVPixelFormat *format)
978 {
979
3/3
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 40696 times.
40724 switch (*format) {
980 13 case AV_PIX_FMT_XYZ12BE : *format = AV_PIX_FMT_RGB48BE; return 1;
981 15 case AV_PIX_FMT_XYZ12LE : *format = AV_PIX_FMT_RGB48LE; return 1;
982 40696 default: return 0;
983 }
984 }
985
986 20362 static void handle_formats(SwsContext *c)
987 {
988 20362 c->src0Alpha |= handle_0alpha(&c->srcFormat);
989 20362 c->dst0Alpha |= handle_0alpha(&c->dstFormat);
990 20362 c->srcXYZ |= handle_xyz(&c->srcFormat);
991 20362 c->dstXYZ |= handle_xyz(&c->dstFormat);
992
4/4
✓ Branch 0 taken 20353 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 69 times.
✓ Branch 3 taken 20284 times.
20362 if (c->srcXYZ || c->dstXYZ)
993 78 fill_xyztables(c);
994 20362 }
995
996 34616 static int range_override_needed(enum AVPixelFormat format)
997 {
998
4/4
✓ Branch 1 taken 13369 times.
✓ Branch 2 taken 21247 times.
✓ Branch 4 taken 12306 times.
✓ Branch 5 taken 1063 times.
34616 return !isYUV(format) && !isGray(format);
999 }
1000
1001 13879 int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4],
1002 int srcRange, const int table[4], int dstRange,
1003 int brightness, int contrast, int saturation)
1004 {
1005 const AVPixFmtDescriptor *desc_dst;
1006 const AVPixFmtDescriptor *desc_src;
1007 13879 int need_reinit = 0;
1008
1009
2/2
✓ Branch 0 taken 364 times.
✓ Branch 1 taken 13515 times.
13879 if (c->nb_slice_ctx) {
1010 364 int parent_ret = 0;
1011
2/2
✓ Branch 0 taken 3221 times.
✓ Branch 1 taken 364 times.
3585 for (int i = 0; i < c->nb_slice_ctx; i++) {
1012 3221 int ret = sws_setColorspaceDetails(c->slice_ctx[i], inv_table,
1013 srcRange, table, dstRange,
1014 brightness, contrast, saturation);
1015
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3221 times.
3221 if (ret < 0)
1016 parent_ret = ret;
1017 }
1018
1019 364 return parent_ret;
1020 }
1021
1022 13515 handle_formats(c);
1023 13515 desc_dst = av_pix_fmt_desc_get(c->dstFormat);
1024 13515 desc_src = av_pix_fmt_desc_get(c->srcFormat);
1025
1026
2/2
✓ Branch 1 taken 6489 times.
✓ Branch 2 taken 7026 times.
13515 if(range_override_needed(c->dstFormat))
1027 6489 dstRange = 0;
1028
2/2
✓ Branch 1 taken 4121 times.
✓ Branch 2 taken 9394 times.
13515 if(range_override_needed(c->srcFormat))
1029 4121 srcRange = 0;
1030
1031
2/2
✓ Branch 0 taken 11496 times.
✓ Branch 1 taken 2019 times.
13515 if (c->srcRange != srcRange ||
1032
2/2
✓ Branch 0 taken 10077 times.
✓ Branch 1 taken 1419 times.
11496 c->dstRange != dstRange ||
1033
1/2
✓ Branch 0 taken 10077 times.
✗ Branch 1 not taken.
10077 c->brightness != brightness ||
1034
2/2
✓ Branch 0 taken 6668 times.
✓ Branch 1 taken 3409 times.
10077 c->contrast != contrast ||
1035
1/2
✓ Branch 0 taken 6668 times.
✗ Branch 1 not taken.
6668 c->saturation != saturation ||
1036
2/2
✓ Branch 0 taken 6533 times.
✓ Branch 1 taken 135 times.
6668 memcmp(c->srcColorspaceTable, inv_table, sizeof(int) * 4) ||
1037
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6533 times.
6533 memcmp(c->dstColorspaceTable, table, sizeof(int) * 4)
1038 )
1039 6982 need_reinit = 1;
1040
1041 13515 memmove(c->srcColorspaceTable, inv_table, sizeof(int) * 4);
1042 13515 memmove(c->dstColorspaceTable, table, sizeof(int) * 4);
1043
1044
1045
1046 13515 c->brightness = brightness;
1047 13515 c->contrast = contrast;
1048 13515 c->saturation = saturation;
1049 13515 c->srcRange = srcRange;
1050 13515 c->dstRange = dstRange;
1051
1052
2/2
✓ Branch 0 taken 6982 times.
✓ Branch 1 taken 6533 times.
13515 if (need_reinit)
1053 6982 ff_sws_init_range_convert(c);
1054
1055 13515 c->dstFormatBpp = av_get_bits_per_pixel(desc_dst);
1056 13515 c->srcFormatBpp = av_get_bits_per_pixel(desc_src);
1057
1058
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13515 times.
13515 if (c->cascaded_context[c->cascaded_mainindex])
1059 return sws_setColorspaceDetails(c->cascaded_context[c->cascaded_mainindex],inv_table, srcRange,table, dstRange, brightness, contrast, saturation);
1060
1061
2/2
✓ Branch 0 taken 6533 times.
✓ Branch 1 taken 6982 times.
13515 if (!need_reinit)
1062 6533 return 0;
1063
1064
8/8
✓ Branch 1 taken 3541 times.
✓ Branch 2 taken 3441 times.
✓ Branch 4 taken 260 times.
✓ Branch 5 taken 3281 times.
✓ Branch 7 taken 377 times.
✓ Branch 8 taken 3324 times.
✓ Branch 10 taken 63 times.
✓ Branch 11 taken 314 times.
6982 if ((isYUV(c->dstFormat) || isGray(c->dstFormat)) && (isYUV(c->srcFormat) || isGray(c->srcFormat))) {
1065
1/2
✓ Branch 0 taken 3387 times.
✗ Branch 1 not taken.
3387 if (!c->cascaded_context[0] &&
1066
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3378 times.
3387 memcmp(c->dstColorspaceTable, c->srcColorspaceTable, sizeof(int) * 4) &&
1067
4/8
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9 times.
✗ Branch 7 not taken.
9 c->srcW && c->srcH && c->dstW && c->dstH) {
1068 enum AVPixelFormat tmp_format;
1069 int tmp_width, tmp_height;
1070 9 int srcW = c->srcW;
1071 9 int srcH = c->srcH;
1072 9 int dstW = c->dstW;
1073 9 int dstH = c->dstH;
1074 int ret;
1075 9 av_log(c, AV_LOG_VERBOSE, "YUV color matrix differs for YUV->YUV, using intermediate RGB to convert\n");
1076
1077
2/4
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
9 if (isNBPS(c->dstFormat) || is16BPS(c->dstFormat)) {
1078 if (isALPHA(c->srcFormat) && isALPHA(c->dstFormat)) {
1079 tmp_format = AV_PIX_FMT_BGRA64;
1080 } else {
1081 tmp_format = AV_PIX_FMT_BGR48;
1082 }
1083 } else {
1084
1/4
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
9 if (isALPHA(c->srcFormat) && isALPHA(c->dstFormat)) {
1085 tmp_format = AV_PIX_FMT_BGRA;
1086 } else {
1087 9 tmp_format = AV_PIX_FMT_BGR24;
1088 }
1089 }
1090
1091
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (srcW*srcH > dstW*dstH) {
1092 tmp_width = dstW;
1093 tmp_height = dstH;
1094 } else {
1095 9 tmp_width = srcW;
1096 9 tmp_height = srcH;
1097 }
1098
1099 9 ret = av_image_alloc(c->cascaded_tmp, c->cascaded_tmpStride,
1100 tmp_width, tmp_height, tmp_format, 64);
1101
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (ret < 0)
1102 return ret;
1103
1104 18 c->cascaded_context[0] = sws_alloc_set_opts(srcW, srcH, c->srcFormat,
1105 tmp_width, tmp_height, tmp_format,
1106 9 c->flags, c->param);
1107
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (!c->cascaded_context[0])
1108 return -1;
1109
1110 9 c->cascaded_context[0]->alphablend = c->alphablend;
1111 9 ret = sws_init_context(c->cascaded_context[0], NULL , NULL);
1112
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (ret < 0)
1113 return ret;
1114 //we set both src and dst depending on that the RGB side will be ignored
1115 9 sws_setColorspaceDetails(c->cascaded_context[0], inv_table,
1116 srcRange, table, dstRange,
1117 brightness, contrast, saturation);
1118
1119 18 c->cascaded_context[1] = sws_alloc_set_opts(tmp_width, tmp_height, tmp_format,
1120 dstW, dstH, c->dstFormat,
1121 9 c->flags, c->param);
1122
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (!c->cascaded_context[1])
1123 return -1;
1124 9 c->cascaded_context[1]->srcRange = srcRange;
1125 9 c->cascaded_context[1]->dstRange = dstRange;
1126 9 ret = sws_init_context(c->cascaded_context[1], NULL , NULL);
1127
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (ret < 0)
1128 return ret;
1129 9 sws_setColorspaceDetails(c->cascaded_context[1], inv_table,
1130 srcRange, table, dstRange,
1131 0, 1 << 16, 1 << 16);
1132 9 return 0;
1133 }
1134 //We do not support this combination currently, we need to cascade more contexts to compensate
1135
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3378 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3378 if (c->cascaded_context[0] && memcmp(c->dstColorspaceTable, c->srcColorspaceTable, sizeof(int) * 4))
1136 return -1; //AVERROR_PATCHWELCOME;
1137 3378 return 0;
1138 }
1139
1140
4/4
✓ Branch 1 taken 3326 times.
✓ Branch 2 taken 269 times.
✓ Branch 4 taken 3281 times.
✓ Branch 5 taken 45 times.
3595 if (!isYUV(c->dstFormat) && !isGray(c->dstFormat)) {
1141 3281 ff_yuv2rgb_c_init_tables(c, inv_table, srcRange, brightness,
1142 contrast, saturation);
1143 // FIXME factorize
1144
1145 #if ARCH_PPC
1146 ff_yuv2rgb_init_tables_ppc(c, inv_table, brightness,
1147 contrast, saturation);
1148 #endif
1149 }
1150
1151 3595 fill_rgb2yuv_table(c, table, dstRange);
1152
1153 3595 return 0;
1154 }
1155
1156 4157 int sws_getColorspaceDetails(struct SwsContext *c, int **inv_table,
1157 int *srcRange, int **table, int *dstRange,
1158 int *brightness, int *contrast, int *saturation)
1159 {
1160
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4157 times.
4157 if (!c )
1161 return -1;
1162
1163
2/2
✓ Branch 0 taken 364 times.
✓ Branch 1 taken 3793 times.
4157 if (c->nb_slice_ctx) {
1164 364 return sws_getColorspaceDetails(c->slice_ctx[0], inv_table, srcRange,
1165 table, dstRange, brightness, contrast,
1166 saturation);
1167 }
1168
1169 3793 *inv_table = c->srcColorspaceTable;
1170 3793 *table = c->dstColorspaceTable;
1171
2/2
✓ Branch 1 taken 3385 times.
✓ Branch 2 taken 408 times.
3793 *srcRange = range_override_needed(c->srcFormat) ? 1 : c->srcRange;
1172
2/2
✓ Branch 1 taken 2505 times.
✓ Branch 2 taken 1288 times.
3793 *dstRange = range_override_needed(c->dstFormat) ? 1 : c->dstRange;
1173 3793 *brightness = c->brightness;
1174 3793 *contrast = c->contrast;
1175 3793 *saturation = c->saturation;
1176
1177 3793 return 0;
1178 }
1179
1180 13991 SwsContext *sws_alloc_context(void)
1181 {
1182 13991 SwsContext *c = av_mallocz(sizeof(SwsContext));
1183
1184 av_assert0(offsetof(SwsContext, redDither) + DITHER32_INT == offsetof(SwsContext, dither32));
1185
1186
1/2
✓ Branch 0 taken 13991 times.
✗ Branch 1 not taken.
13991 if (c) {
1187 13991 c->av_class = &ff_sws_context_class;
1188 13991 av_opt_set_defaults(c);
1189 13991 atomic_init(&c->stride_unaligned_warned, 0);
1190 13991 atomic_init(&c->data_unaligned_warned, 0);
1191 }
1192
1193 13991 return c;
1194 }
1195
1196 static uint16_t * alloc_gamma_tbl(double e)
1197 {
1198 int i = 0;
1199 uint16_t * tbl;
1200 tbl = (uint16_t*)av_malloc(sizeof(uint16_t) * 1 << 16);
1201 if (!tbl)
1202 return NULL;
1203
1204 for (i = 0; i < 65536; ++i) {
1205 tbl[i] = pow(i / 65535.0, e) * 65535.0;
1206 }
1207 return tbl;
1208 }
1209
1210 979 static enum AVPixelFormat alphaless_fmt(enum AVPixelFormat fmt)
1211 {
1212
19/42
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 103 times.
✓ Branch 4 taken 45 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 4 times.
✓ Branch 8 taken 46 times.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
✓ Branch 16 taken 9 times.
✓ Branch 17 taken 1 times.
✓ Branch 18 taken 9 times.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 45 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✓ Branch 39 taken 9 times.
✓ Branch 40 taken 4 times.
✓ Branch 41 taken 673 times.
979 switch(fmt) {
1213 11 case AV_PIX_FMT_ARGB: return AV_PIX_FMT_RGB24;
1214 11 case AV_PIX_FMT_RGBA: return AV_PIX_FMT_RGB24;
1215 2 case AV_PIX_FMT_ABGR: return AV_PIX_FMT_BGR24;
1216 103 case AV_PIX_FMT_BGRA: return AV_PIX_FMT_BGR24;
1217 45 case AV_PIX_FMT_YA8: return AV_PIX_FMT_GRAY8;
1218
1219 case AV_PIX_FMT_YUVA420P: return AV_PIX_FMT_YUV420P;
1220 3 case AV_PIX_FMT_YUVA422P: return AV_PIX_FMT_YUV422P;
1221 4 case AV_PIX_FMT_YUVA444P: return AV_PIX_FMT_YUV444P;
1222
1223 46 case AV_PIX_FMT_GBRAP: return AV_PIX_FMT_GBRP;
1224
1225 1 case AV_PIX_FMT_GBRAP10LE: return AV_PIX_FMT_GBRP10;
1226 case AV_PIX_FMT_GBRAP10BE: return AV_PIX_FMT_GBRP10;
1227
1228 1 case AV_PIX_FMT_GBRAP12LE: return AV_PIX_FMT_GBRP12;
1229 case AV_PIX_FMT_GBRAP12BE: return AV_PIX_FMT_GBRP12;
1230
1231 case AV_PIX_FMT_GBRAP14LE: return AV_PIX_FMT_GBRP14;
1232 case AV_PIX_FMT_GBRAP14BE: return AV_PIX_FMT_GBRP14;
1233
1234 1 case AV_PIX_FMT_GBRAP16LE: return AV_PIX_FMT_GBRP16;
1235 9 case AV_PIX_FMT_GBRAP16BE: return AV_PIX_FMT_GBRP16;
1236
1237 1 case AV_PIX_FMT_RGBA64LE: return AV_PIX_FMT_RGB48;
1238 9 case AV_PIX_FMT_RGBA64BE: return AV_PIX_FMT_RGB48;
1239 1 case AV_PIX_FMT_BGRA64LE: return AV_PIX_FMT_BGR48;
1240 case AV_PIX_FMT_BGRA64BE: return AV_PIX_FMT_BGR48;
1241
1242 45 case AV_PIX_FMT_YA16BE: return AV_PIX_FMT_GRAY16;
1243 case AV_PIX_FMT_YA16LE: return AV_PIX_FMT_GRAY16;
1244
1245 case AV_PIX_FMT_YUVA420P9BE: return AV_PIX_FMT_YUV420P9;
1246 case AV_PIX_FMT_YUVA422P9BE: return AV_PIX_FMT_YUV422P9;
1247 case AV_PIX_FMT_YUVA444P9BE: return AV_PIX_FMT_YUV444P9;
1248 case AV_PIX_FMT_YUVA420P9LE: return AV_PIX_FMT_YUV420P9;
1249 case AV_PIX_FMT_YUVA422P9LE: return AV_PIX_FMT_YUV422P9;
1250 case AV_PIX_FMT_YUVA444P9LE: return AV_PIX_FMT_YUV444P9;
1251 case AV_PIX_FMT_YUVA420P10BE: return AV_PIX_FMT_YUV420P10;
1252 case AV_PIX_FMT_YUVA422P10BE: return AV_PIX_FMT_YUV422P10;
1253 case AV_PIX_FMT_YUVA444P10BE: return AV_PIX_FMT_YUV444P10;
1254 case AV_PIX_FMT_YUVA420P10LE: return AV_PIX_FMT_YUV420P10;
1255 case AV_PIX_FMT_YUVA422P10LE: return AV_PIX_FMT_YUV422P10;
1256 case AV_PIX_FMT_YUVA444P10LE: return AV_PIX_FMT_YUV444P10;
1257 case AV_PIX_FMT_YUVA420P16BE: return AV_PIX_FMT_YUV420P16;
1258 case AV_PIX_FMT_YUVA422P16BE: return AV_PIX_FMT_YUV422P16;
1259 case AV_PIX_FMT_YUVA444P16BE: return AV_PIX_FMT_YUV444P16;
1260 case AV_PIX_FMT_YUVA420P16LE: return AV_PIX_FMT_YUV420P16;
1261 9 case AV_PIX_FMT_YUVA422P16LE: return AV_PIX_FMT_YUV422P16;
1262 4 case AV_PIX_FMT_YUVA444P16LE: return AV_PIX_FMT_YUV444P16;
1263
1264 // case AV_PIX_FMT_AYUV64LE:
1265 // case AV_PIX_FMT_AYUV64BE:
1266 // case AV_PIX_FMT_PAL8:
1267 673 default: return AV_PIX_FMT_NONE;
1268 }
1269 }
1270
1271 static int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter,
1272 SwsFilter *dstFilter);
1273
1274 6847 static av_cold int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter,
1275 SwsFilter *dstFilter)
1276 {
1277 int i;
1278 int usesVFilter, usesHFilter;
1279 int unscaled;
1280 6847 SwsFilter dummyFilter = { NULL, NULL, NULL, NULL };
1281 6847 int srcW = c->srcW;
1282 6847 int srcH = c->srcH;
1283 6847 int dstW = c->dstW;
1284 6847 int dstH = c->dstH;
1285 6847 int dst_stride = FFALIGN(dstW * sizeof(int16_t) + 66, 16);
1286 int flags, cpu_flags;
1287 enum AVPixelFormat srcFormat, dstFormat;
1288 const AVPixFmtDescriptor *desc_src;
1289 const AVPixFmtDescriptor *desc_dst;
1290 6847 int ret = 0;
1291 enum AVPixelFormat tmpFmt;
1292 static const float float_mult = 1.0f / 255.0f;
1293
1294 6847 cpu_flags = av_get_cpu_flags();
1295 6847 flags = c->flags;
1296 6847 emms_c();
1297
1298
4/4
✓ Branch 0 taken 6062 times.
✓ Branch 1 taken 785 times.
✓ Branch 2 taken 5972 times.
✓ Branch 3 taken 90 times.
6847 unscaled = (srcW == dstW && srcH == dstH);
1299
1300
3/6
✓ Branch 0 taken 6847 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6847 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6847 times.
✗ Branch 5 not taken.
6847 if (!c->contrast && !c->saturation && !c->dstFormatBpp)
1301 6847 sws_setColorspaceDetails(c, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT], c->srcRange,
1302 ff_yuv2rgb_coeffs[SWS_CS_DEFAULT],
1303 c->dstRange, 0, 1 << 16, 1 << 16);
1304
1305 6847 handle_formats(c);
1306 6847 srcFormat = c->srcFormat;
1307 6847 dstFormat = c->dstFormat;
1308 6847 desc_src = av_pix_fmt_desc_get(srcFormat);
1309 6847 desc_dst = av_pix_fmt_desc_get(dstFormat);
1310
1311 // If the source has no alpha then disable alpha blendaway
1312
2/2
✓ Branch 0 taken 134 times.
✓ Branch 1 taken 6713 times.
6847 if (c->src0Alpha)
1313 134 c->alphablend = SWS_ALPHA_BLEND_NONE;
1314
1315
5/6
✓ Branch 0 taken 5972 times.
✓ Branch 1 taken 875 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 5960 times.
✓ Branch 5 taken 12 times.
✗ Branch 6 not taken.
6859 if (!(unscaled && sws_isSupportedEndiannessConversion(srcFormat) &&
1316 12 av_pix_fmt_swap_endianness(srcFormat) == dstFormat)) {
1317
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6847 times.
6847 if (!sws_isSupportedInput(srcFormat)) {
1318 av_log(c, AV_LOG_ERROR, "%s is not supported as input pixel format\n",
1319 av_get_pix_fmt_name(srcFormat));
1320 return AVERROR(EINVAL);
1321 }
1322
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6847 times.
6847 if (!sws_isSupportedOutput(dstFormat)) {
1323 av_log(c, AV_LOG_ERROR, "%s is not supported as output pixel format\n",
1324 av_get_pix_fmt_name(dstFormat));
1325 return AVERROR(EINVAL);
1326 }
1327 }
1328 av_assert2(desc_src && desc_dst);
1329
1330 6847 i = flags & (SWS_POINT |
1331 SWS_AREA |
1332 SWS_BILINEAR |
1333 SWS_FAST_BILINEAR |
1334 SWS_BICUBIC |
1335 SWS_X |
1336 SWS_GAUSS |
1337 SWS_LANCZOS |
1338 SWS_SINC |
1339 SWS_SPLINE |
1340 SWS_BICUBLIN);
1341
1342 /* provide a default scaler if not set by caller */
1343
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 6836 times.
6847 if (!i) {
1344
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
11 if (dstW < srcW && dstH < srcH)
1345 flags |= SWS_BICUBIC;
1346
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11 else if (dstW > srcW && dstH > srcH)
1347 flags |= SWS_BICUBIC;
1348 else
1349 11 flags |= SWS_BICUBIC;
1350 11 c->flags = flags;
1351
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6836 times.
6836 } else if (i & (i - 1)) {
1352 av_log(c, AV_LOG_ERROR,
1353 "Exactly one scaler algorithm must be chosen, got %X\n", i);
1354 return AVERROR(EINVAL);
1355 }
1356 /* sanity check */
1357
4/8
✓ Branch 0 taken 6847 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6847 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6847 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 6847 times.
6847 if (srcW < 1 || srcH < 1 || dstW < 1 || dstH < 1) {
1358 /* FIXME check if these are enough and try to lower them after
1359 * fixing the relevant parts of the code */
1360 av_log(c, AV_LOG_ERROR, "%dx%d -> %dx%d is invalid scaling dimension\n",
1361 srcW, srcH, dstW, dstH);
1362 return AVERROR(EINVAL);
1363 }
1364
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6847 times.
6847 if (flags & SWS_FAST_BILINEAR) {
1365 if (srcW < 8 || dstW < 8) {
1366 flags ^= SWS_FAST_BILINEAR | SWS_BILINEAR;
1367 c->flags = flags;
1368 }
1369 }
1370
1371
1/2
✓ Branch 0 taken 6847 times.
✗ Branch 1 not taken.
6847 if (!dstFilter)
1372 6847 dstFilter = &dummyFilter;
1373
1/2
✓ Branch 0 taken 6847 times.
✗ Branch 1 not taken.
6847 if (!srcFilter)
1374 6847 srcFilter = &dummyFilter;
1375
1376 6847 c->lumXInc = (((int64_t)srcW << 16) + (dstW >> 1)) / dstW;
1377 6847 c->lumYInc = (((int64_t)srcH << 16) + (dstH >> 1)) / dstH;
1378 6847 c->dstFormatBpp = av_get_bits_per_pixel(desc_dst);
1379 6847 c->srcFormatBpp = av_get_bits_per_pixel(desc_src);
1380 6847 c->vRounder = 4 * 0x0001000100010001ULL;
1381
1382 usesVFilter = (srcFilter->lumV && srcFilter->lumV->length > 1) ||
1383
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6847 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6847 (srcFilter->chrV && srcFilter->chrV->length > 1) ||
1384
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 6847 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6847 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
20541 (dstFilter->lumV && dstFilter->lumV->length > 1) ||
1385
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6847 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6847 (dstFilter->chrV && dstFilter->chrV->length > 1);
1386 usesHFilter = (srcFilter->lumH && srcFilter->lumH->length > 1) ||
1387
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6847 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6847 (srcFilter->chrH && srcFilter->chrH->length > 1) ||
1388
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 6847 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6847 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
20541 (dstFilter->lumH && dstFilter->lumH->length > 1) ||
1389
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6847 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6847 (dstFilter->chrH && dstFilter->chrH->length > 1);
1390
1391 6847 av_pix_fmt_get_chroma_sub_sample(srcFormat, &c->chrSrcHSubSample, &c->chrSrcVSubSample);
1392 6847 av_pix_fmt_get_chroma_sub_sample(dstFormat, &c->chrDstHSubSample, &c->chrDstVSubSample);
1393
1394 6847 c->dst_slice_align = 1 << c->chrDstVSubSample;
1395
1396
4/4
✓ Branch 1 taken 3272 times.
✓ Branch 2 taken 3575 times.
✓ Branch 3 taken 3260 times.
✓ Branch 4 taken 12 times.
6847 if (isAnyRGB(dstFormat) && !(flags&SWS_FULL_CHR_H_INT)) {
1397
2/2
✓ Branch 0 taken 273 times.
✓ Branch 1 taken 2987 times.
3260 if (dstW&1) {
1398 273 av_log(c, AV_LOG_DEBUG, "Forcing full internal H chroma due to odd output size\n");
1399 273 flags |= SWS_FULL_CHR_H_INT;
1400 273 c->flags = flags;
1401 }
1402
1403
2/2
✓ Branch 0 taken 2023 times.
✓ Branch 1 taken 1237 times.
3260 if ( c->chrSrcHSubSample == 0
1404
1/2
✓ Branch 0 taken 2023 times.
✗ Branch 1 not taken.
2023 && c->chrSrcVSubSample == 0
1405
1/2
✓ Branch 0 taken 2023 times.
✗ Branch 1 not taken.
2023 && c->dither != SWS_DITHER_BAYER //SWS_FULL_CHR_H_INT is currently not supported with SWS_DITHER_BAYER
1406
1/2
✓ Branch 0 taken 2023 times.
✗ Branch 1 not taken.
2023 && !(c->flags & SWS_FAST_BILINEAR)
1407 ) {
1408 2023 av_log(c, AV_LOG_DEBUG, "Forcing full internal H chroma due to input having non subsampled chroma\n");
1409 2023 flags |= SWS_FULL_CHR_H_INT;
1410 2023 c->flags = flags;
1411 }
1412 }
1413
1414
1/2
✓ Branch 0 taken 6847 times.
✗ Branch 1 not taken.
6847 if (c->dither == SWS_DITHER_AUTO) {
1415
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6847 times.
6847 if (flags & SWS_ERROR_DIFFUSION)
1416 c->dither = SWS_DITHER_ED;
1417 }
1418
1419
4/4
✓ Branch 0 taken 6834 times.
✓ Branch 1 taken 13 times.
✓ Branch 2 taken 6820 times.
✓ Branch 3 taken 14 times.
6847 if(dstFormat == AV_PIX_FMT_BGR4_BYTE ||
1420
2/2
✓ Branch 0 taken 6790 times.
✓ Branch 1 taken 30 times.
6820 dstFormat == AV_PIX_FMT_RGB4_BYTE ||
1421
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 6774 times.
6790 dstFormat == AV_PIX_FMT_BGR8 ||
1422 dstFormat == AV_PIX_FMT_RGB8) {
1423
1/2
✓ Branch 0 taken 73 times.
✗ Branch 1 not taken.
73 if (c->dither == SWS_DITHER_AUTO)
1424
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 62 times.
73 c->dither = (flags & SWS_FULL_CHR_H_INT) ? SWS_DITHER_ED : SWS_DITHER_BAYER;
1425
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 11 times.
73 if (!(flags & SWS_FULL_CHR_H_INT)) {
1426
4/8
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 62 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 62 times.
62 if (c->dither == SWS_DITHER_ED || c->dither == SWS_DITHER_A_DITHER || c->dither == SWS_DITHER_X_DITHER || c->dither == SWS_DITHER_NONE) {
1427 av_log(c, AV_LOG_DEBUG,
1428 "Desired dithering only supported in full chroma interpolation for destination format '%s'\n",
1429 av_get_pix_fmt_name(dstFormat));
1430 flags |= SWS_FULL_CHR_H_INT;
1431 c->flags = flags;
1432 }
1433 }
1434
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 62 times.
73 if (flags & SWS_FULL_CHR_H_INT) {
1435
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (c->dither == SWS_DITHER_BAYER) {
1436 av_log(c, AV_LOG_DEBUG,
1437 "Ordered dither is not supported in full chroma interpolation for destination format '%s'\n",
1438 av_get_pix_fmt_name(dstFormat));
1439 c->dither = SWS_DITHER_ED;
1440 }
1441 }
1442 }
1443
2/2
✓ Branch 1 taken 616 times.
✓ Branch 2 taken 6231 times.
6847 if (isPlanarRGB(dstFormat)) {
1444
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 232 times.
616 if (!(flags & SWS_FULL_CHR_H_INT)) {
1445 384 av_log(c, AV_LOG_DEBUG,
1446 "%s output is not supported with half chroma resolution, switching to full\n",
1447 av_get_pix_fmt_name(dstFormat));
1448 384 flags |= SWS_FULL_CHR_H_INT;
1449 384 c->flags = flags;
1450 }
1451 }
1452
1453 /* reuse chroma for 2 pixels RGB/BGR unless user wants full
1454 * chroma interpolation */
1455
3/4
✓ Branch 0 taken 2435 times.
✓ Branch 1 taken 4412 times.
✓ Branch 2 taken 2435 times.
✗ Branch 3 not taken.
9282 if (flags & SWS_FULL_CHR_H_INT &&
1456
2/2
✓ Branch 1 taken 1819 times.
✓ Branch 2 taken 616 times.
4870 isAnyRGB(dstFormat) &&
1457
2/2
✓ Branch 1 taken 1817 times.
✓ Branch 2 taken 2 times.
4254 !isPlanarRGB(dstFormat) &&
1458
2/2
✓ Branch 0 taken 1816 times.
✓ Branch 1 taken 1 times.
1817 dstFormat != AV_PIX_FMT_RGBA64LE &&
1459
2/2
✓ Branch 0 taken 1814 times.
✓ Branch 1 taken 2 times.
1816 dstFormat != AV_PIX_FMT_RGBA64BE &&
1460
2/2
✓ Branch 0 taken 1813 times.
✓ Branch 1 taken 1 times.
1814 dstFormat != AV_PIX_FMT_BGRA64LE &&
1461
2/2
✓ Branch 0 taken 1800 times.
✓ Branch 1 taken 13 times.
1813 dstFormat != AV_PIX_FMT_BGRA64BE &&
1462
2/2
✓ Branch 0 taken 1797 times.
✓ Branch 1 taken 3 times.
1800 dstFormat != AV_PIX_FMT_RGB48LE &&
1463
2/2
✓ Branch 0 taken 1795 times.
✓ Branch 1 taken 2 times.
1797 dstFormat != AV_PIX_FMT_RGB48BE &&
1464
2/2
✓ Branch 0 taken 1794 times.
✓ Branch 1 taken 1 times.
1795 dstFormat != AV_PIX_FMT_BGR48LE &&
1465
2/2
✓ Branch 0 taken 1745 times.
✓ Branch 1 taken 49 times.
1794 dstFormat != AV_PIX_FMT_BGR48BE &&
1466
2/2
✓ Branch 0 taken 1732 times.
✓ Branch 1 taken 13 times.
1745 dstFormat != AV_PIX_FMT_RGBA &&
1467
2/2
✓ Branch 0 taken 1224 times.
✓ Branch 1 taken 508 times.
1732 dstFormat != AV_PIX_FMT_ARGB &&
1468
2/2
✓ Branch 0 taken 1220 times.
✓ Branch 1 taken 4 times.
1224 dstFormat != AV_PIX_FMT_BGRA &&
1469
2/2
✓ Branch 0 taken 63 times.
✓ Branch 1 taken 1157 times.
1220 dstFormat != AV_PIX_FMT_ABGR &&
1470
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 36 times.
63 dstFormat != AV_PIX_FMT_RGB24 &&
1471
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 2 times.
27 dstFormat != AV_PIX_FMT_BGR24 &&
1472
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 2 times.
25 dstFormat != AV_PIX_FMT_BGR4_BYTE &&
1473
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 4 times.
23 dstFormat != AV_PIX_FMT_RGB4_BYTE &&
1474
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 3 times.
19 dstFormat != AV_PIX_FMT_BGR8 &&
1475 dstFormat != AV_PIX_FMT_RGB8
1476 ) {
1477 16 av_log(c, AV_LOG_WARNING,
1478 "full chroma interpolation for destination format '%s' not yet implemented\n",
1479 av_get_pix_fmt_name(dstFormat));
1480 16 flags &= ~SWS_FULL_CHR_H_INT;
1481 16 c->flags = flags;
1482 }
1483
4/4
✓ Branch 1 taken 3272 times.
✓ Branch 2 taken 3575 times.
✓ Branch 3 taken 853 times.
✓ Branch 4 taken 2419 times.
6847 if (isAnyRGB(dstFormat) && !(flags & SWS_FULL_CHR_H_INT))
1484 853 c->chrDstHSubSample = 1;
1485
1486 // drop some chroma lines if the user wants it
1487 6847 c->vChrDrop = (flags & SWS_SRC_V_CHR_DROP_MASK) >>
1488 SWS_SRC_V_CHR_DROP_SHIFT;
1489 6847 c->chrSrcVSubSample += c->vChrDrop;
1490
1491 /* drop every other pixel for chroma calculation unless user
1492 * wants full chroma */
1493
5/6
✓ Branch 1 taken 1226 times.
✓ Branch 2 taken 5621 times.
✓ Branch 3 taken 1226 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1225 times.
✓ Branch 6 taken 1 times.
6847 if (isAnyRGB(srcFormat) && !(flags & SWS_FULL_CHR_H_INP) &&
1494
3/4
✓ Branch 0 taken 1224 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1224 times.
✗ Branch 3 not taken.
1225 srcFormat != AV_PIX_FMT_RGB8 && srcFormat != AV_PIX_FMT_BGR8 &&
1495
3/4
✓ Branch 0 taken 1224 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1223 times.
✓ Branch 3 taken 1 times.
1224 srcFormat != AV_PIX_FMT_RGB4 && srcFormat != AV_PIX_FMT_BGR4 &&
1496
4/4
✓ Branch 0 taken 1222 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1221 times.
✓ Branch 3 taken 1 times.
1223 srcFormat != AV_PIX_FMT_RGB4_BYTE && srcFormat != AV_PIX_FMT_BGR4_BYTE &&
1497
4/4
✓ Branch 0 taken 1219 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1218 times.
✓ Branch 3 taken 1 times.
1221 srcFormat != AV_PIX_FMT_GBRP9BE && srcFormat != AV_PIX_FMT_GBRP9LE &&
1498
4/4
✓ Branch 0 taken 1202 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 1201 times.
✓ Branch 3 taken 1 times.
1218 srcFormat != AV_PIX_FMT_GBRP10BE && srcFormat != AV_PIX_FMT_GBRP10LE &&
1499
4/4
✓ Branch 0 taken 1199 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1198 times.
✓ Branch 3 taken 1 times.
1201 srcFormat != AV_PIX_FMT_GBRAP10BE && srcFormat != AV_PIX_FMT_GBRAP10LE &&
1500
4/4
✓ Branch 0 taken 1196 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1195 times.
✓ Branch 3 taken 1 times.
1198 srcFormat != AV_PIX_FMT_GBRP12BE && srcFormat != AV_PIX_FMT_GBRP12LE &&
1501
4/4
✓ Branch 0 taken 1193 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1192 times.
✓ Branch 3 taken 1 times.
1195 srcFormat != AV_PIX_FMT_GBRAP12BE && srcFormat != AV_PIX_FMT_GBRAP12LE &&
1502
4/4
✓ Branch 0 taken 1191 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1190 times.
✓ Branch 3 taken 1 times.
1192 srcFormat != AV_PIX_FMT_GBRAP14BE && srcFormat != AV_PIX_FMT_GBRAP14LE &&
1503
4/4
✓ Branch 0 taken 1188 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1178 times.
✓ Branch 3 taken 10 times.
1190 srcFormat != AV_PIX_FMT_GBRP14BE && srcFormat != AV_PIX_FMT_GBRP14LE &&
1504
4/4
✓ Branch 0 taken 1171 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 1161 times.
✓ Branch 3 taken 10 times.
1178 srcFormat != AV_PIX_FMT_GBRP16BE && srcFormat != AV_PIX_FMT_GBRP16LE &&
1505
4/4
✓ Branch 0 taken 1158 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 1157 times.
✓ Branch 3 taken 1 times.
1161 srcFormat != AV_PIX_FMT_GBRAP16BE && srcFormat != AV_PIX_FMT_GBRAP16LE &&
1506
4/4
✓ Branch 0 taken 1125 times.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 1124 times.
✓ Branch 3 taken 1 times.
1157 srcFormat != AV_PIX_FMT_GBRPF32BE && srcFormat != AV_PIX_FMT_GBRPF32LE &&
1507
2/2
✓ Branch 0 taken 1123 times.
✓ Branch 1 taken 1 times.
1124 srcFormat != AV_PIX_FMT_GBRAPF32BE && srcFormat != AV_PIX_FMT_GBRAPF32LE &&
1508
2/2
✓ Branch 0 taken 897 times.
✓ Branch 1 taken 226 times.
1123 ((dstW >> c->chrDstHSubSample) <= (srcW >> 1) ||
1509
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 897 times.
897 (flags & SWS_FAST_BILINEAR)))
1510 226 c->chrSrcHSubSample = 1;
1511
1512 // Note the AV_CEIL_RSHIFT is so that we always round toward +inf.
1513 6847 c->chrSrcW = AV_CEIL_RSHIFT(srcW, c->chrSrcHSubSample);
1514 6847 c->chrSrcH = AV_CEIL_RSHIFT(srcH, c->chrSrcVSubSample);
1515 6847 c->chrDstW = AV_CEIL_RSHIFT(dstW, c->chrDstHSubSample);
1516 6847 c->chrDstH = AV_CEIL_RSHIFT(dstH, c->chrDstVSubSample);
1517
1518
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6847 times.
6847 if (!FF_ALLOCZ_TYPED_ARRAY(c->formatConvBuffer, FFALIGN(srcW * 2 + 78, 16) * 2))
1519 goto nomem;
1520
1521 6847 c->srcBpc = desc_src->comp[0].depth;
1522
2/2
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 6667 times.
6847 if (c->srcBpc < 8)
1523 180 c->srcBpc = 8;
1524 6847 c->dstBpc = desc_dst->comp[0].depth;
1525
2/2
✓ Branch 0 taken 280 times.
✓ Branch 1 taken 6567 times.
6847 if (c->dstBpc < 8)
1526 280 c->dstBpc = 8;
1527
4/4
✓ Branch 1 taken 5621 times.
✓ Branch 2 taken 1226 times.
✓ Branch 3 taken 862 times.
✓ Branch 4 taken 4759 times.
6847 if (isAnyRGB(srcFormat) || srcFormat == AV_PIX_FMT_PAL8)
1528 2088 c->srcBpc = 16;
1529
2/2
✓ Branch 0 taken 616 times.
✓ Branch 1 taken 6231 times.
6847 if (c->dstBpc == 16)
1530 616 dst_stride <<= 1;
1531
1532
6/6
✓ Branch 0 taken 206 times.
✓ Branch 1 taken 6641 times.
✓ Branch 2 taken 100 times.
✓ Branch 3 taken 106 times.
✓ Branch 4 taken 99 times.
✓ Branch 5 taken 1 times.
6847 if (INLINE_MMXEXT(cpu_flags) && c->srcBpc == 8 && c->dstBpc <= 14) {
1533
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 99 times.
99 c->canMMXEXTBeUsed = dstW >= srcW && (dstW & 31) == 0 &&
1534
1/4
✓ Branch 0 taken 99 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
198 c->chrDstW >= c->chrSrcW &&
1535 (srcW & 15) == 0;
1536
4/8
✓ Branch 0 taken 99 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 99 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 99 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 99 times.
✗ Branch 7 not taken.
99 if (!c->canMMXEXTBeUsed && dstW >= srcW && c->chrDstW >= c->chrSrcW && (srcW & 15) == 0
1537
1538
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 99 times.
99 && (flags & SWS_FAST_BILINEAR)) {
1539 if (flags & SWS_PRINT_INFO)
1540 av_log(c, AV_LOG_INFO,
1541 "output width is not a multiple of 32 -> no MMXEXT scaler\n");
1542 }
1543
4/8
✓ Branch 0 taken 99 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 99 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 99 times.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 99 times.
99 if (usesHFilter || isNBPS(c->srcFormat) || is16BPS(c->srcFormat) || isAnyRGB(c->srcFormat))
1544 c->canMMXEXTBeUsed = 0;
1545 } else
1546 6748 c->canMMXEXTBeUsed = 0;
1547
1548 6847 c->chrXInc = (((int64_t)c->chrSrcW << 16) + (c->chrDstW >> 1)) / c->chrDstW;
1549 6847 c->chrYInc = (((int64_t)c->chrSrcH << 16) + (c->chrDstH >> 1)) / c->chrDstH;
1550
1551 /* Match pixel 0 of the src to pixel 0 of dst and match pixel n-2 of src
1552 * to pixel n-2 of dst, but only for the FAST_BILINEAR mode otherwise do
1553 * correct scaling.
1554 * n-2 is the last chrominance sample available.
1555 * This is not perfect, but no one should notice the difference, the more
1556 * correct variant would be like the vertical one, but that would require
1557 * some special code for the first and last pixel */
1558
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6847 times.
6847 if (flags & SWS_FAST_BILINEAR) {
1559 if (c->canMMXEXTBeUsed) {
1560 c->lumXInc += 20;
1561 c->chrXInc += 20;
1562 }
1563 // we don't use the x86 asm scaler if MMX is available
1564 else if (INLINE_MMX(cpu_flags) && c->dstBpc <= 14) {
1565 c->lumXInc = ((int64_t)(srcW - 2) << 16) / (dstW - 2) - 20;
1566 c->chrXInc = ((int64_t)(c->chrSrcW - 2) << 16) / (c->chrDstW - 2) - 20;
1567 }
1568 }
1569
1570 // hardcoded for now
1571 6847 c->gamma_value = 2.2;
1572 6847 tmpFmt = AV_PIX_FMT_RGBA64LE;
1573
1574
1575
3/8
✓ Branch 0 taken 875 times.
✓ Branch 1 taken 5972 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 875 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6847 if (!unscaled && c->gamma_flag && (srcFormat != tmpFmt || dstFormat != tmpFmt)) {
1576 SwsContext *c2;
1577 c->cascaded_context[0] = NULL;
1578
1579 ret = av_image_alloc(c->cascaded_tmp, c->cascaded_tmpStride,
1580 srcW, srcH, tmpFmt, 64);
1581 if (ret < 0)
1582 return ret;
1583
1584 c->cascaded_context[0] = sws_getContext(srcW, srcH, srcFormat,
1585 srcW, srcH, tmpFmt,
1586 flags, NULL, NULL, c->param);
1587 if (!c->cascaded_context[0]) {
1588 return AVERROR(ENOMEM);
1589 }
1590
1591 c->cascaded_context[1] = sws_getContext(srcW, srcH, tmpFmt,
1592 dstW, dstH, tmpFmt,
1593 flags, srcFilter, dstFilter, c->param);
1594
1595 if (!c->cascaded_context[1])
1596 return AVERROR(ENOMEM);
1597
1598 c2 = c->cascaded_context[1];
1599 c2->is_internal_gamma = 1;
1600 c2->gamma = alloc_gamma_tbl( c->gamma_value);
1601 c2->inv_gamma = alloc_gamma_tbl(1.f/c->gamma_value);
1602 if (!c2->gamma || !c2->inv_gamma)
1603 return AVERROR(ENOMEM);
1604
1605 // is_internal_flag is set after creating the context
1606 // to properly create the gamma convert FilterDescriptor
1607 // we have to re-initialize it
1608 ff_free_filters(c2);
1609 if ((ret = ff_init_filters(c2)) < 0) {
1610 sws_freeContext(c2);
1611 c->cascaded_context[1] = NULL;
1612 return ret;
1613 }
1614
1615 c->cascaded_context[2] = NULL;
1616 if (dstFormat != tmpFmt) {
1617 ret = av_image_alloc(c->cascaded1_tmp, c->cascaded1_tmpStride,
1618 dstW, dstH, tmpFmt, 64);
1619 if (ret < 0)
1620 return ret;
1621
1622 c->cascaded_context[2] = sws_getContext(dstW, dstH, tmpFmt,
1623 dstW, dstH, dstFormat,
1624 flags, NULL, NULL, c->param);
1625 if (!c->cascaded_context[2])
1626 return AVERROR(ENOMEM);
1627 }
1628 return 0;
1629 }
1630
1631
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6847 times.
6847 if (isBayer(srcFormat)) {
1632 if (!unscaled ||
1633 (dstFormat != AV_PIX_FMT_RGB24 && dstFormat != AV_PIX_FMT_YUV420P &&
1634 dstFormat != AV_PIX_FMT_RGB48)) {
1635 enum AVPixelFormat tmpFormat = isBayer16BPS(srcFormat) ? AV_PIX_FMT_RGB48 : AV_PIX_FMT_RGB24;
1636
1637 ret = av_image_alloc(c->cascaded_tmp, c->cascaded_tmpStride,
1638 srcW, srcH, tmpFormat, 64);
1639 if (ret < 0)
1640 return ret;
1641
1642 c->cascaded_context[0] = sws_getContext(srcW, srcH, srcFormat,
1643 srcW, srcH, tmpFormat,
1644 flags, srcFilter, NULL, c->param);
1645 if (!c->cascaded_context[0])
1646 return AVERROR(ENOMEM);
1647
1648 c->cascaded_context[1] = sws_getContext(srcW, srcH, tmpFormat,
1649 dstW, dstH, dstFormat,
1650 flags, NULL, dstFilter, c->param);
1651 if (!c->cascaded_context[1])
1652 return AVERROR(ENOMEM);
1653 return 0;
1654 }
1655 }
1656
1657
6/6
✓ Branch 0 taken 5972 times.
✓ Branch 1 taken 875 times.
✓ Branch 2 taken 3716 times.
✓ Branch 3 taken 2256 times.
✓ Branch 4 taken 16 times.
✓ Branch 5 taken 3700 times.
6847 if (unscaled && c->srcBpc == 8 && dstFormat == AV_PIX_FMT_GRAYF32){
1658
2/2
✓ Branch 0 taken 4096 times.
✓ Branch 1 taken 16 times.
4112 for (i = 0; i < 256; ++i){
1659 4096 c->uint2float_lut[i] = (float)i * float_mult;
1660 }
1661 }
1662
1663 // float will be converted to uint16_t
1664
6/6
✓ Branch 0 taken 6846 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 6844 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2 times.
6847 if ((srcFormat == AV_PIX_FMT_GRAYF32BE || srcFormat == AV_PIX_FMT_GRAYF32LE) &&
1665
4/8
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
1 (!unscaled || unscaled && dstFormat != srcFormat && (srcFormat != AV_PIX_FMT_GRAYF32 ||
1666 dstFormat != AV_PIX_FMT_GRAY8))){
1667 3 c->srcBpc = 16;
1668 }
1669
1670
4/4
✓ Branch 1 taken 1628 times.
✓ Branch 2 taken 5219 times.
✓ Branch 4 taken 979 times.
✓ Branch 5 taken 649 times.
6847 if (CONFIG_SWSCALE_ALPHA && isALPHA(srcFormat) && !isALPHA(dstFormat)) {
1671 979 enum AVPixelFormat tmpFormat = alphaless_fmt(srcFormat);
1672
1673
3/4
✓ Branch 0 taken 306 times.
✓ Branch 1 taken 673 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 306 times.
979 if (tmpFormat != AV_PIX_FMT_NONE && c->alphablend != SWS_ALPHA_BLEND_NONE) {
1674 if (!unscaled ||
1675 dstFormat != tmpFormat ||
1676 usesHFilter || usesVFilter ||
1677 c->srcRange != c->dstRange
1678 ) {
1679 c->cascaded_mainindex = 1;
1680 ret = av_image_alloc(c->cascaded_tmp, c->cascaded_tmpStride,
1681 srcW, srcH, tmpFormat, 64);
1682 if (ret < 0)
1683 return ret;
1684
1685 c->cascaded_context[0] = sws_alloc_set_opts(srcW, srcH, srcFormat,
1686 srcW, srcH, tmpFormat,
1687 flags, c->param);
1688 if (!c->cascaded_context[0])
1689 return AVERROR(EINVAL);
1690 c->cascaded_context[0]->alphablend = c->alphablend;
1691 ret = sws_init_context(c->cascaded_context[0], NULL , NULL);
1692 if (ret < 0)
1693 return ret;
1694
1695 c->cascaded_context[1] = sws_alloc_set_opts(srcW, srcH, tmpFormat,
1696 dstW, dstH, dstFormat,
1697 flags, c->param);
1698 if (!c->cascaded_context[1])
1699 return AVERROR(EINVAL);
1700
1701 c->cascaded_context[1]->srcRange = c->srcRange;
1702 c->cascaded_context[1]->dstRange = c->dstRange;
1703 ret = sws_init_context(c->cascaded_context[1], srcFilter , dstFilter);
1704 if (ret < 0)
1705 return ret;
1706
1707 return 0;
1708 }
1709 }
1710 }
1711
1712 /* alpha blend special case, note this has been split via cascaded contexts if its scaled */
1713
4/6
✓ Branch 0 taken 5972 times.
✓ Branch 1 taken 875 times.
✓ Branch 2 taken 5972 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5972 times.
✗ Branch 5 not taken.
6847 if (unscaled && !usesHFilter && !usesVFilter &&
1714
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 5972 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
5972 c->alphablend != SWS_ALPHA_BLEND_NONE &&
1715 isALPHA(srcFormat) &&
1716 alphaless_fmt(srcFormat) == dstFormat
1717 ) {
1718 c->convert_unscaled = ff_sws_alphablendaway;
1719
1720 if (flags & SWS_PRINT_INFO)
1721 av_log(c, AV_LOG_INFO,
1722 "alpha blendaway %s -> %s special converter is available\n",
1723 av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat));
1724 return 0;
1725 }
1726
1727 /* unscaled special cases */
1728
4/6
✓ Branch 0 taken 5972 times.
✓ Branch 1 taken 875 times.
✓ Branch 2 taken 5972 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5972 times.
✗ Branch 5 not taken.
6847 if (unscaled && !usesHFilter && !usesVFilter) {
1729 5972 ff_get_unscaled_swscale(c);
1730
1731
2/2
✓ Branch 0 taken 2461 times.
✓ Branch 1 taken 3511 times.
5972 if (c->convert_unscaled) {
1732
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2461 times.
2461 if (flags & SWS_PRINT_INFO)
1733 av_log(c, AV_LOG_INFO,
1734 "unscaled %s -> %s special converter is available\n",
1735 av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat));
1736 }
1737 }
1738
1739 #if HAVE_MMAP && HAVE_MPROTECT && defined(MAP_ANONYMOUS)
1740 #define USE_MMAP 1
1741 #else
1742 #define USE_MMAP 0
1743 #endif
1744
1745 /* precalculate horizontal scaler filter coefficients */
1746 {
1747 #if HAVE_MMXEXT_INLINE
1748 // can't downscale !!!
1749
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6847 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6847 if (c->canMMXEXTBeUsed && (flags & SWS_FAST_BILINEAR)) {
1750 c->lumMmxextFilterCodeSize = ff_init_hscaler_mmxext(dstW, c->lumXInc, NULL,
1751 NULL, NULL, 8);
1752 c->chrMmxextFilterCodeSize = ff_init_hscaler_mmxext(c->chrDstW, c->chrXInc,
1753 NULL, NULL, NULL, 4);
1754
1755 #if USE_MMAP
1756 c->lumMmxextFilterCode = mmap(NULL, c->lumMmxextFilterCodeSize,
1757 PROT_READ | PROT_WRITE,
1758 MAP_PRIVATE | MAP_ANONYMOUS,
1759 -1, 0);
1760 c->chrMmxextFilterCode = mmap(NULL, c->chrMmxextFilterCodeSize,
1761 PROT_READ | PROT_WRITE,
1762 MAP_PRIVATE | MAP_ANONYMOUS,
1763 -1, 0);
1764 #elif HAVE_VIRTUALALLOC
1765 c->lumMmxextFilterCode = VirtualAlloc(NULL,
1766 c->lumMmxextFilterCodeSize,
1767 MEM_COMMIT,
1768 PAGE_EXECUTE_READWRITE);
1769 c->chrMmxextFilterCode = VirtualAlloc(NULL,
1770 c->chrMmxextFilterCodeSize,
1771 MEM_COMMIT,
1772 PAGE_EXECUTE_READWRITE);
1773 #else
1774 c->lumMmxextFilterCode = av_malloc(c->lumMmxextFilterCodeSize);
1775 c->chrMmxextFilterCode = av_malloc(c->chrMmxextFilterCodeSize);
1776 #endif
1777
1778 #ifdef MAP_ANONYMOUS
1779 if (c->lumMmxextFilterCode == MAP_FAILED || c->chrMmxextFilterCode == MAP_FAILED)
1780 #else
1781 if (!c->lumMmxextFilterCode || !c->chrMmxextFilterCode)
1782 #endif
1783 {
1784 av_log(c, AV_LOG_ERROR, "Failed to allocate MMX2FilterCode\n");
1785 return AVERROR(ENOMEM);
1786 }
1787
1788 if (!FF_ALLOCZ_TYPED_ARRAY(c->hLumFilter, dstW / 8 + 8) ||
1789 !FF_ALLOCZ_TYPED_ARRAY(c->hChrFilter, c->chrDstW / 4 + 8) ||
1790 !FF_ALLOCZ_TYPED_ARRAY(c->hLumFilterPos, dstW / 2 / 8 + 8) ||
1791 !FF_ALLOCZ_TYPED_ARRAY(c->hChrFilterPos, c->chrDstW / 2 / 4 + 8))
1792 goto nomem;
1793
1794 ff_init_hscaler_mmxext( dstW, c->lumXInc, c->lumMmxextFilterCode,
1795 c->hLumFilter, (uint32_t*)c->hLumFilterPos, 8);
1796 ff_init_hscaler_mmxext(c->chrDstW, c->chrXInc, c->chrMmxextFilterCode,
1797 c->hChrFilter, (uint32_t*)c->hChrFilterPos, 4);
1798
1799 #if USE_MMAP
1800 if ( mprotect(c->lumMmxextFilterCode, c->lumMmxextFilterCodeSize, PROT_EXEC | PROT_READ) == -1
1801 || mprotect(c->chrMmxextFilterCode, c->chrMmxextFilterCodeSize, PROT_EXEC | PROT_READ) == -1) {
1802 av_log(c, AV_LOG_ERROR, "mprotect failed, cannot use fast bilinear scaler\n");
1803 ret = AVERROR(EINVAL);
1804 goto fail;
1805 }
1806 #endif
1807 } else
1808 #endif /* HAVE_MMXEXT_INLINE */
1809 {
1810
2/2
✓ Branch 0 taken 215 times.
✓ Branch 1 taken 6632 times.
6847 const int filterAlign = X86_MMX(cpu_flags) ? 4 :
1811 PPC_ALTIVEC(cpu_flags) ? 8 :
1812 have_neon(cpu_flags) ? 4 :
1813 have_lsx(cpu_flags) ? 8 :
1814 have_lasx(cpu_flags) ? 8 : 1;
1815
1816
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 6847 times.
13694 if ((ret = initFilter(&c->hLumFilter, &c->hLumFilterPos,
1817 &c->hLumFilterSize, c->lumXInc,
1818 srcW, dstW, filterAlign, 1 << 14,
1819 6847 (flags & SWS_BICUBLIN) ? (flags | SWS_BICUBIC) : flags,
1820 cpu_flags, srcFilter->lumH, dstFilter->lumH,
1821
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6847 times.
6847 c->param,
1822 get_local_pos(c, 0, 0, 0),
1823 get_local_pos(c, 0, 0, 0))) < 0)
1824 goto fail;
1825
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6847 times.
6847 if (ff_shuffle_filter_coefficients(c, c->hLumFilterPos, c->hLumFilterSize, c->hLumFilter, dstW) < 0)
1826 goto nomem;
1827
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 6847 times.
13694 if ((ret = initFilter(&c->hChrFilter, &c->hChrFilterPos,
1828 &c->hChrFilterSize, c->chrXInc,
1829 c->chrSrcW, c->chrDstW, filterAlign, 1 << 14,
1830 6847 (flags & SWS_BICUBLIN) ? (flags | SWS_BILINEAR) : flags,
1831 cpu_flags, srcFilter->chrH, dstFilter->chrH,
1832
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6847 times.
6847 c->param,
1833 get_local_pos(c, c->chrSrcHSubSample, c->src_h_chr_pos, 0),
1834 get_local_pos(c, c->chrDstHSubSample, c->dst_h_chr_pos, 0))) < 0)
1835 goto fail;
1836
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6847 times.
6847 if (ff_shuffle_filter_coefficients(c, c->hChrFilterPos, c->hChrFilterSize, c->hChrFilter, c->