FFmpeg  4.4.9
utils.c
Go to the documentation of this file.
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 #define WIN32_LEAN_AND_MEAN
38 #include <windows.h>
39 #endif
40 
41 #include "libavutil/attributes.h"
42 #include "libavutil/avassert.h"
43 #include "libavutil/avutil.h"
44 #include "libavutil/bswap.h"
45 #include "libavutil/cpu.h"
46 #include "libavutil/imgutils.h"
47 #include "libavutil/intreadwrite.h"
48 #include "libavutil/libm.h"
49 #include "libavutil/mathematics.h"
50 #include "libavutil/opt.h"
51 #include "libavutil/pixdesc.h"
52 #include "libavutil/thread.h"
53 #include "libavutil/aarch64/cpu.h"
54 #include "libavutil/ppc/cpu.h"
55 #include "libavutil/x86/asm.h"
56 #include "libavutil/x86/cpu.h"
57 
58 // We have to implement deprecated functions until they are removed, this is the
59 // simplest way to prevent warnings
60 #undef attribute_deprecated
61 #define attribute_deprecated
62 
63 #include "rgb2rgb.h"
64 #include "swscale.h"
65 #include "swscale_internal.h"
66 
67 #if !FF_API_SWS_VECTOR
68 static SwsVector *sws_getIdentityVec(void);
69 static void sws_addVec(SwsVector *a, SwsVector *b);
70 static void sws_shiftVec(SwsVector *a, int shift);
71 static void sws_printVec2(SwsVector *a, AVClass *log_ctx, int log_level);
72 #endif
73 
74 static void handle_formats(SwsContext *c);
75 
76 unsigned swscale_version(void)
77 {
80 }
81 
82 const char *swscale_configuration(void)
83 {
84  return FFMPEG_CONFIGURATION;
85 }
86 
87 const char *swscale_license(void)
88 {
89 #define LICENSE_PREFIX "libswscale license: "
90  return &LICENSE_PREFIX FFMPEG_LICENSE[sizeof(LICENSE_PREFIX) - 1];
91 }
92 
93 typedef struct FormatEntry {
97 } FormatEntry;
98 
99 static const FormatEntry format_entries[] = {
100  [AV_PIX_FMT_YUV420P] = { 1, 1 },
101  [AV_PIX_FMT_YUYV422] = { 1, 1 },
102  [AV_PIX_FMT_RGB24] = { 1, 1 },
103  [AV_PIX_FMT_BGR24] = { 1, 1 },
104  [AV_PIX_FMT_YUV422P] = { 1, 1 },
105  [AV_PIX_FMT_YUV444P] = { 1, 1 },
106  [AV_PIX_FMT_YUV410P] = { 1, 1 },
107  [AV_PIX_FMT_YUV411P] = { 1, 1 },
108  [AV_PIX_FMT_GRAY8] = { 1, 1 },
109  [AV_PIX_FMT_MONOWHITE] = { 1, 1 },
110  [AV_PIX_FMT_MONOBLACK] = { 1, 1 },
111  [AV_PIX_FMT_PAL8] = { 1, 0 },
112  [AV_PIX_FMT_YUVJ420P] = { 1, 1 },
113  [AV_PIX_FMT_YUVJ411P] = { 1, 1 },
114  [AV_PIX_FMT_YUVJ422P] = { 1, 1 },
115  [AV_PIX_FMT_YUVJ444P] = { 1, 1 },
116  [AV_PIX_FMT_YVYU422] = { 1, 1 },
117  [AV_PIX_FMT_UYVY422] = { 1, 1 },
118  [AV_PIX_FMT_UYYVYY411] = { 0, 0 },
119  [AV_PIX_FMT_BGR8] = { 1, 1 },
120  [AV_PIX_FMT_BGR4] = { 0, 1 },
121  [AV_PIX_FMT_BGR4_BYTE] = { 1, 1 },
122  [AV_PIX_FMT_RGB8] = { 1, 1 },
123  [AV_PIX_FMT_RGB4] = { 0, 1 },
124  [AV_PIX_FMT_RGB4_BYTE] = { 1, 1 },
125  [AV_PIX_FMT_NV12] = { 1, 1 },
126  [AV_PIX_FMT_NV21] = { 1, 1 },
127  [AV_PIX_FMT_ARGB] = { 1, 1 },
128  [AV_PIX_FMT_RGBA] = { 1, 1 },
129  [AV_PIX_FMT_ABGR] = { 1, 1 },
130  [AV_PIX_FMT_BGRA] = { 1, 1 },
131  [AV_PIX_FMT_0RGB] = { 1, 1 },
132  [AV_PIX_FMT_RGB0] = { 1, 1 },
133  [AV_PIX_FMT_0BGR] = { 1, 1 },
134  [AV_PIX_FMT_BGR0] = { 1, 1 },
135  [AV_PIX_FMT_GRAY9BE] = { 1, 1 },
136  [AV_PIX_FMT_GRAY9LE] = { 1, 1 },
137  [AV_PIX_FMT_GRAY10BE] = { 1, 1 },
138  [AV_PIX_FMT_GRAY10LE] = { 1, 1 },
139  [AV_PIX_FMT_GRAY12BE] = { 1, 1 },
140  [AV_PIX_FMT_GRAY12LE] = { 1, 1 },
141  [AV_PIX_FMT_GRAY14BE] = { 1, 1 },
142  [AV_PIX_FMT_GRAY14LE] = { 1, 1 },
143  [AV_PIX_FMT_GRAY16BE] = { 1, 1 },
144  [AV_PIX_FMT_GRAY16LE] = { 1, 1 },
145  [AV_PIX_FMT_YUV440P] = { 1, 1 },
146  [AV_PIX_FMT_YUVJ440P] = { 1, 1 },
147  [AV_PIX_FMT_YUV440P10LE] = { 1, 1 },
148  [AV_PIX_FMT_YUV440P10BE] = { 1, 1 },
149  [AV_PIX_FMT_YUV440P12LE] = { 1, 1 },
150  [AV_PIX_FMT_YUV440P12BE] = { 1, 1 },
151  [AV_PIX_FMT_YUVA420P] = { 1, 1 },
152  [AV_PIX_FMT_YUVA422P] = { 1, 1 },
153  [AV_PIX_FMT_YUVA444P] = { 1, 1 },
154  [AV_PIX_FMT_YUVA420P9BE] = { 1, 1 },
155  [AV_PIX_FMT_YUVA420P9LE] = { 1, 1 },
156  [AV_PIX_FMT_YUVA422P9BE] = { 1, 1 },
157  [AV_PIX_FMT_YUVA422P9LE] = { 1, 1 },
158  [AV_PIX_FMT_YUVA444P9BE] = { 1, 1 },
159  [AV_PIX_FMT_YUVA444P9LE] = { 1, 1 },
160  [AV_PIX_FMT_YUVA420P10BE]= { 1, 1 },
161  [AV_PIX_FMT_YUVA420P10LE]= { 1, 1 },
162  [AV_PIX_FMT_YUVA422P10BE]= { 1, 1 },
163  [AV_PIX_FMT_YUVA422P10LE]= { 1, 1 },
164  [AV_PIX_FMT_YUVA444P10BE]= { 1, 1 },
165  [AV_PIX_FMT_YUVA444P10LE]= { 1, 1 },
166  [AV_PIX_FMT_YUVA420P16BE]= { 1, 1 },
167  [AV_PIX_FMT_YUVA420P16LE]= { 1, 1 },
168  [AV_PIX_FMT_YUVA422P16BE]= { 1, 1 },
169  [AV_PIX_FMT_YUVA422P16LE]= { 1, 1 },
170  [AV_PIX_FMT_YUVA444P16BE]= { 1, 1 },
171  [AV_PIX_FMT_YUVA444P16LE]= { 1, 1 },
172  [AV_PIX_FMT_RGB48BE] = { 1, 1 },
173  [AV_PIX_FMT_RGB48LE] = { 1, 1 },
174  [AV_PIX_FMT_RGBA64BE] = { 1, 1, 1 },
175  [AV_PIX_FMT_RGBA64LE] = { 1, 1, 1 },
176  [AV_PIX_FMT_RGB565BE] = { 1, 1 },
177  [AV_PIX_FMT_RGB565LE] = { 1, 1 },
178  [AV_PIX_FMT_RGB555BE] = { 1, 1 },
179  [AV_PIX_FMT_RGB555LE] = { 1, 1 },
180  [AV_PIX_FMT_BGR565BE] = { 1, 1 },
181  [AV_PIX_FMT_BGR565LE] = { 1, 1 },
182  [AV_PIX_FMT_BGR555BE] = { 1, 1 },
183  [AV_PIX_FMT_BGR555LE] = { 1, 1 },
184  [AV_PIX_FMT_YUV420P16LE] = { 1, 1 },
185  [AV_PIX_FMT_YUV420P16BE] = { 1, 1 },
186  [AV_PIX_FMT_YUV422P16LE] = { 1, 1 },
187  [AV_PIX_FMT_YUV422P16BE] = { 1, 1 },
188  [AV_PIX_FMT_YUV444P16LE] = { 1, 1 },
189  [AV_PIX_FMT_YUV444P16BE] = { 1, 1 },
190  [AV_PIX_FMT_RGB444LE] = { 1, 1 },
191  [AV_PIX_FMT_RGB444BE] = { 1, 1 },
192  [AV_PIX_FMT_BGR444LE] = { 1, 1 },
193  [AV_PIX_FMT_BGR444BE] = { 1, 1 },
194  [AV_PIX_FMT_YA8] = { 1, 1 },
195  [AV_PIX_FMT_YA16BE] = { 1, 1 },
196  [AV_PIX_FMT_YA16LE] = { 1, 1 },
197  [AV_PIX_FMT_BGR48BE] = { 1, 1 },
198  [AV_PIX_FMT_BGR48LE] = { 1, 1 },
199  [AV_PIX_FMT_BGRA64BE] = { 1, 1, 1 },
200  [AV_PIX_FMT_BGRA64LE] = { 1, 1, 1 },
201  [AV_PIX_FMT_YUV420P9BE] = { 1, 1 },
202  [AV_PIX_FMT_YUV420P9LE] = { 1, 1 },
203  [AV_PIX_FMT_YUV420P10BE] = { 1, 1 },
204  [AV_PIX_FMT_YUV420P10LE] = { 1, 1 },
205  [AV_PIX_FMT_YUV420P12BE] = { 1, 1 },
206  [AV_PIX_FMT_YUV420P12LE] = { 1, 1 },
207  [AV_PIX_FMT_YUV420P14BE] = { 1, 1 },
208  [AV_PIX_FMT_YUV420P14LE] = { 1, 1 },
209  [AV_PIX_FMT_YUV422P9BE] = { 1, 1 },
210  [AV_PIX_FMT_YUV422P9LE] = { 1, 1 },
211  [AV_PIX_FMT_YUV422P10BE] = { 1, 1 },
212  [AV_PIX_FMT_YUV422P10LE] = { 1, 1 },
213  [AV_PIX_FMT_YUV422P12BE] = { 1, 1 },
214  [AV_PIX_FMT_YUV422P12LE] = { 1, 1 },
215  [AV_PIX_FMT_YUV422P14BE] = { 1, 1 },
216  [AV_PIX_FMT_YUV422P14LE] = { 1, 1 },
217  [AV_PIX_FMT_YUV444P9BE] = { 1, 1 },
218  [AV_PIX_FMT_YUV444P9LE] = { 1, 1 },
219  [AV_PIX_FMT_YUV444P10BE] = { 1, 1 },
220  [AV_PIX_FMT_YUV444P10LE] = { 1, 1 },
221  [AV_PIX_FMT_YUV444P12BE] = { 1, 1 },
222  [AV_PIX_FMT_YUV444P12LE] = { 1, 1 },
223  [AV_PIX_FMT_YUV444P14BE] = { 1, 1 },
224  [AV_PIX_FMT_YUV444P14LE] = { 1, 1 },
225  [AV_PIX_FMT_GBRP] = { 1, 1 },
226  [AV_PIX_FMT_GBRP9LE] = { 1, 1 },
227  [AV_PIX_FMT_GBRP9BE] = { 1, 1 },
228  [AV_PIX_FMT_GBRP10LE] = { 1, 1 },
229  [AV_PIX_FMT_GBRP10BE] = { 1, 1 },
230  [AV_PIX_FMT_GBRAP10LE] = { 1, 1 },
231  [AV_PIX_FMT_GBRAP10BE] = { 1, 1 },
232  [AV_PIX_FMT_GBRP12LE] = { 1, 1 },
233  [AV_PIX_FMT_GBRP12BE] = { 1, 1 },
234  [AV_PIX_FMT_GBRAP12LE] = { 1, 1 },
235  [AV_PIX_FMT_GBRAP12BE] = { 1, 1 },
236  [AV_PIX_FMT_GBRP14LE] = { 1, 1 },
237  [AV_PIX_FMT_GBRP14BE] = { 1, 1 },
238  [AV_PIX_FMT_GBRP16LE] = { 1, 1 },
239  [AV_PIX_FMT_GBRP16BE] = { 1, 1 },
240  [AV_PIX_FMT_GBRPF32LE] = { 1, 1 },
241  [AV_PIX_FMT_GBRPF32BE] = { 1, 1 },
242  [AV_PIX_FMT_GBRAPF32LE] = { 1, 1 },
243  [AV_PIX_FMT_GBRAPF32BE] = { 1, 1 },
244  [AV_PIX_FMT_GBRAP] = { 1, 1 },
245  [AV_PIX_FMT_GBRAP16LE] = { 1, 1 },
246  [AV_PIX_FMT_GBRAP16BE] = { 1, 1 },
247  [AV_PIX_FMT_BAYER_BGGR8] = { 1, 0 },
248  [AV_PIX_FMT_BAYER_RGGB8] = { 1, 0 },
249  [AV_PIX_FMT_BAYER_GBRG8] = { 1, 0 },
250  [AV_PIX_FMT_BAYER_GRBG8] = { 1, 0 },
251  [AV_PIX_FMT_BAYER_BGGR16LE] = { 1, 0 },
252  [AV_PIX_FMT_BAYER_BGGR16BE] = { 1, 0 },
253  [AV_PIX_FMT_BAYER_RGGB16LE] = { 1, 0 },
254  [AV_PIX_FMT_BAYER_RGGB16BE] = { 1, 0 },
255  [AV_PIX_FMT_BAYER_GBRG16LE] = { 1, 0 },
256  [AV_PIX_FMT_BAYER_GBRG16BE] = { 1, 0 },
257  [AV_PIX_FMT_BAYER_GRBG16LE] = { 1, 0 },
258  [AV_PIX_FMT_BAYER_GRBG16BE] = { 1, 0 },
259  [AV_PIX_FMT_XYZ12BE] = { 1, 1, 1 },
260  [AV_PIX_FMT_XYZ12LE] = { 1, 1, 1 },
261  [AV_PIX_FMT_AYUV64LE] = { 1, 1},
262  [AV_PIX_FMT_P010LE] = { 1, 1 },
263  [AV_PIX_FMT_P010BE] = { 1, 1 },
264  [AV_PIX_FMT_P016LE] = { 1, 1 },
265  [AV_PIX_FMT_P016BE] = { 1, 1 },
266  [AV_PIX_FMT_GRAYF32LE] = { 1, 1 },
267  [AV_PIX_FMT_GRAYF32BE] = { 1, 1 },
268  [AV_PIX_FMT_YUVA422P12BE] = { 1, 1 },
269  [AV_PIX_FMT_YUVA422P12LE] = { 1, 1 },
270  [AV_PIX_FMT_YUVA444P12BE] = { 1, 1 },
271  [AV_PIX_FMT_YUVA444P12LE] = { 1, 1 },
272  [AV_PIX_FMT_NV24] = { 1, 1 },
273  [AV_PIX_FMT_NV42] = { 1, 1 },
274  [AV_PIX_FMT_Y210LE] = { 1, 0 },
275  [AV_PIX_FMT_X2RGB10LE] = { 1, 1 },
276 };
277 
279 {
280  return (unsigned)pix_fmt < FF_ARRAY_ELEMS(format_entries) ?
282 }
283 
285 {
286  return (unsigned)pix_fmt < FF_ARRAY_ELEMS(format_entries) ?
288 }
289 
291 {
292  return (unsigned)pix_fmt < FF_ARRAY_ELEMS(format_entries) ?
294 }
295 
296 static double getSplineCoeff(double a, double b, double c, double d,
297  double dist)
298 {
299  if (dist <= 1.0)
300  return ((d * dist + c) * dist + b) * dist + a;
301  else
302  return getSplineCoeff(0.0,
303  b + 2.0 * c + 3.0 * d,
304  c + 3.0 * d,
305  -b - 3.0 * c - 6.0 * d,
306  dist - 1.0);
307 }
308 
309 static av_cold int get_local_pos(SwsContext *s, int chr_subsample, int pos, int dir)
310 {
311  if (pos == -1 || pos <= -513) {
312  pos = (128 << chr_subsample) - 128;
313  }
314  pos += 128; // relative to ideal left edge
315  return pos >> chr_subsample;
316 }
317 
318 typedef struct {
319  int flag; ///< flag associated to the algorithm
320  const char *description; ///< human-readable description
321  int size_factor; ///< size factor used when initing the filters
323 
325  { SWS_AREA, "area averaging", 1 /* downscale only, for upscale it is bilinear */ },
326  { SWS_BICUBIC, "bicubic", 4 },
327  { SWS_BICUBLIN, "luma bicubic / chroma bilinear", -1 },
328  { SWS_BILINEAR, "bilinear", 2 },
329  { SWS_FAST_BILINEAR, "fast bilinear", -1 },
330  { SWS_GAUSS, "Gaussian", 8 /* infinite ;) */ },
331  { SWS_LANCZOS, "Lanczos", -1 /* custom */ },
332  { SWS_POINT, "nearest neighbor / point", -1 },
333  { SWS_SINC, "sinc", 20 /* infinite ;) */ },
334  { SWS_SPLINE, "bicubic spline", 20 /* infinite :)*/ },
335  { SWS_X, "experimental", 8 },
336 };
337 
338 static av_cold int initFilter(int16_t **outFilter, int32_t **filterPos,
339  int *outFilterSize, int xInc, int srcW,
340  int dstW, int filterAlign, int one,
341  int flags, int cpu_flags,
342  SwsVector *srcFilter, SwsVector *dstFilter,
343  double param[2], int srcPos, int dstPos)
344 {
345  int i;
346  int filterSize;
347  int filter2Size;
348  int minFilterSize;
349  int64_t *filter = NULL;
350  int64_t *filter2 = NULL;
351  const int64_t fone = 1LL << (54 - FFMIN(av_log2(srcW/dstW), 8));
352  int ret = -1;
353 
354  emms_c(); // FIXME should not be required but IS (even for non-MMX versions)
355 
356  // NOTE: the +3 is for the MMX(+1) / SSE(+3) scaler which reads over the end
357  if (!FF_ALLOC_TYPED_ARRAY(*filterPos, dstW + 3))
358  goto nomem;
359 
360  if (FFABS(xInc - 0x10000) < 10 && srcPos == dstPos) { // unscaled
361  int i;
362  filterSize = 1;
363  if (!FF_ALLOCZ_TYPED_ARRAY(filter, dstW * filterSize))
364  goto nomem;
365 
366  for (i = 0; i < dstW; i++) {
367  filter[i * filterSize] = fone;
368  (*filterPos)[i] = i;
369  }
370  } else if (flags & SWS_POINT) { // lame looking point sampling mode
371  int i;
372  int64_t xDstInSrc;
373  filterSize = 1;
374  if (!FF_ALLOC_TYPED_ARRAY(filter, dstW * filterSize))
375  goto nomem;
376 
377  xDstInSrc = ((dstPos*(int64_t)xInc)>>8) - ((srcPos*0x8000LL)>>7);
378  for (i = 0; i < dstW; i++) {
379  int xx = (xDstInSrc - ((filterSize - 1) << 15) + (1 << 15)) >> 16;
380 
381  (*filterPos)[i] = xx;
382  filter[i] = fone;
383  xDstInSrc += xInc;
384  }
385  } else if ((xInc <= (1 << 16) && (flags & SWS_AREA)) ||
386  (flags & SWS_FAST_BILINEAR)) { // bilinear upscale
387  int i;
388  int64_t xDstInSrc;
389  filterSize = 2;
390  if (!FF_ALLOC_TYPED_ARRAY(filter, dstW * filterSize))
391  goto nomem;
392 
393  xDstInSrc = ((dstPos*(int64_t)xInc)>>8) - ((srcPos*0x8000LL)>>7);
394  for (i = 0; i < dstW; i++) {
395  int xx = (xDstInSrc - ((filterSize - 1) << 15) + (1 << 15)) >> 16;
396  int j;
397 
398  (*filterPos)[i] = xx;
399  // bilinear upscale / linear interpolate / area averaging
400  for (j = 0; j < filterSize; j++) {
401  int64_t coeff = fone - FFABS((int64_t)xx * (1 << 16) - xDstInSrc) * (fone >> 16);
402  if (coeff < 0)
403  coeff = 0;
404  filter[i * filterSize + j] = coeff;
405  xx++;
406  }
407  xDstInSrc += xInc;
408  }
409  } else {
410  int64_t xDstInSrc;
411  int sizeFactor = -1;
412 
413  for (i = 0; i < FF_ARRAY_ELEMS(scale_algorithms); i++) {
414  if (flags & scale_algorithms[i].flag && scale_algorithms[i].size_factor > 0) {
415  sizeFactor = scale_algorithms[i].size_factor;
416  break;
417  }
418  }
419  if (flags & SWS_LANCZOS)
420  sizeFactor = param[0] != SWS_PARAM_DEFAULT ? ceil(2 * param[0]) : 6;
421  av_assert0(sizeFactor > 0);
422 
423  if (sizeFactor > 50) {
424  ret = AVERROR(EINVAL);
425  goto fail;
426  }
427 
428  if (xInc <= 1 << 16)
429  filterSize = 1 + sizeFactor; // upscale
430  else
431  filterSize = 1 + (sizeFactor * srcW + dstW - 1) / dstW;
432 
433  filterSize = FFMIN(filterSize, srcW - 2);
434  filterSize = FFMAX(filterSize, 1);
435 
436  filter = av_malloc_array(dstW, filterSize * sizeof(*filter));
437  if (!filter)
438  goto nomem;
439  xDstInSrc = ((dstPos*(int64_t)xInc)>>7) - ((srcPos*0x10000LL)>>7);
440  for (i = 0; i < dstW; i++) {
441  int xx = (xDstInSrc - (filterSize - 2) * (1LL<<16)) / (1 << 17);
442  int j;
443  (*filterPos)[i] = xx;
444  for (j = 0; j < filterSize; j++) {
445  int64_t d = (FFABS(((int64_t)xx * (1 << 17)) - xDstInSrc)) << 13;
446  double floatd;
447  int64_t coeff;
448 
449  if (xInc > 1 << 16)
450  d = d * dstW / srcW;
451  floatd = d * (1.0 / (1 << 30));
452 
453  if (flags & SWS_BICUBIC) {
454  int64_t B = (param[0] != SWS_PARAM_DEFAULT ? param[0] : 0) * (1 << 24);
455  int64_t C = (param[1] != SWS_PARAM_DEFAULT ? param[1] : 0.6) * (1 << 24);
456 
457  if (d >= 1LL << 31) {
458  coeff = 0.0;
459  } else {
460  int64_t dd = (d * d) >> 30;
461  int64_t ddd = (dd * d) >> 30;
462 
463  if (d < 1LL << 30)
464  coeff = (12 * (1 << 24) - 9 * B - 6 * C) * ddd +
465  (-18 * (1 << 24) + 12 * B + 6 * C) * dd +
466  (6 * (1 << 24) - 2 * B) * (1 << 30);
467  else
468  coeff = (-B - 6 * C) * ddd +
469  (6 * B + 30 * C) * dd +
470  (-12 * B - 48 * C) * d +
471  (8 * B + 24 * C) * (1 << 30);
472  }
473  coeff /= (1LL<<54)/fone;
474  } else if (flags & SWS_X) {
475  double A = param[0] != SWS_PARAM_DEFAULT ? param[0] : 1.0;
476  double c;
477 
478  if (floatd < 1.0)
479  c = cos(floatd * M_PI);
480  else
481  c = -1.0;
482  if (c < 0.0)
483  c = -pow(-c, A);
484  else
485  c = pow(c, A);
486  coeff = (c * 0.5 + 0.5) * fone;
487  } else if (flags & SWS_AREA) {
488  int64_t d2 = d - (1 << 29);
489  if (d2 * xInc < -(1LL << (29 + 16)))
490  coeff = 1.0 * (1LL << (30 + 16));
491  else if (d2 * xInc < (1LL << (29 + 16)))
492  coeff = -d2 * xInc + (1LL << (29 + 16));
493  else
494  coeff = 0.0;
495  coeff *= fone >> (30 + 16);
496  } else if (flags & SWS_GAUSS) {
497  double p = param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0;
498  coeff = exp2(-p * floatd * floatd) * fone;
499  } else if (flags & SWS_SINC) {
500  coeff = (d ? sin(floatd * M_PI) / (floatd * M_PI) : 1.0) * fone;
501  } else if (flags & SWS_LANCZOS) {
502  double p = param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0;
503  coeff = (d ? sin(floatd * M_PI) * sin(floatd * M_PI / p) /
504  (floatd * floatd * M_PI * M_PI / p) : 1.0) * fone;
505  if (floatd > p)
506  coeff = 0;
507  } else if (flags & SWS_BILINEAR) {
508  coeff = (1 << 30) - d;
509  if (coeff < 0)
510  coeff = 0;
511  coeff *= fone >> 30;
512  } else if (flags & SWS_SPLINE) {
513  double p = -2.196152422706632;
514  coeff = getSplineCoeff(1.0, 0.0, p, -p - 1.0, floatd) * fone;
515  } else {
516  av_assert0(0);
517  }
518 
519  filter[i * filterSize + j] = coeff;
520  xx++;
521  }
522  xDstInSrc += 2LL * xInc;
523  }
524  }
525 
526  /* apply src & dst Filter to filter -> filter2
527  * av_free(filter);
528  */
529  av_assert0(filterSize > 0);
530  filter2Size = filterSize;
531  if (srcFilter)
532  filter2Size += srcFilter->length - 1;
533  if (dstFilter)
534  filter2Size += dstFilter->length - 1;
535  av_assert0(filter2Size > 0);
536  filter2 = av_calloc(dstW, filter2Size * sizeof(*filter2));
537  if (!filter2)
538  goto nomem;
539  for (i = 0; i < dstW; i++) {
540  int j, k;
541 
542  if (srcFilter) {
543  for (k = 0; k < srcFilter->length; k++) {
544  for (j = 0; j < filterSize; j++)
545  filter2[i * filter2Size + k + j] +=
546  srcFilter->coeff[k] * filter[i * filterSize + j];
547  }
548  } else {
549  for (j = 0; j < filterSize; j++)
550  filter2[i * filter2Size + j] = filter[i * filterSize + j];
551  }
552  // FIXME dstFilter
553 
554  (*filterPos)[i] += (filterSize - 1) / 2 - (filter2Size - 1) / 2;
555  }
556  av_freep(&filter);
557 
558  /* try to reduce the filter-size (step1 find size and shift left) */
559  // Assume it is near normalized (*0.5 or *2.0 is OK but * 0.001 is not).
560  minFilterSize = 0;
561  for (i = dstW - 1; i >= 0; i--) {
562  int min = filter2Size;
563  int j;
564  int64_t cutOff = 0.0;
565 
566  /* get rid of near zero elements on the left by shifting left */
567  for (j = 0; j < filter2Size; j++) {
568  int k;
569  cutOff += FFABS(filter2[i * filter2Size]);
570 
571  if (cutOff > SWS_MAX_REDUCE_CUTOFF * fone)
572  break;
573 
574  /* preserve monotonicity because the core can't handle the
575  * filter otherwise */
576  if (i < dstW - 1 && (*filterPos)[i] >= (*filterPos)[i + 1])
577  break;
578 
579  // move filter coefficients left
580  for (k = 1; k < filter2Size; k++)
581  filter2[i * filter2Size + k - 1] = filter2[i * filter2Size + k];
582  filter2[i * filter2Size + k - 1] = 0;
583  (*filterPos)[i]++;
584  }
585 
586  cutOff = 0;
587  /* count near zeros on the right */
588  for (j = filter2Size - 1; j > 0; j--) {
589  cutOff += FFABS(filter2[i * filter2Size + j]);
590 
591  if (cutOff > SWS_MAX_REDUCE_CUTOFF * fone)
592  break;
593  min--;
594  }
595 
596  if (min > minFilterSize)
597  minFilterSize = min;
598  }
599 
600  if (PPC_ALTIVEC(cpu_flags)) {
601  // we can handle the special case 4, so we don't want to go the full 8
602  if (minFilterSize < 5)
603  filterAlign = 4;
604 
605  /* We really don't want to waste our time doing useless computation, so
606  * fall back on the scalar C code for very small filters.
607  * Vectorizing is worth it only if you have a decent-sized vector. */
608  if (minFilterSize < 3)
609  filterAlign = 1;
610  }
611 
613  // special case for unscaled vertical filtering
614  if (minFilterSize == 1 && filterAlign == 2)
615  filterAlign = 1;
616  }
617 
618  av_assert0(minFilterSize > 0);
619  filterSize = (minFilterSize + (filterAlign - 1)) & (~(filterAlign - 1));
620  av_assert0(filterSize > 0);
621  filter = av_malloc_array(dstW, filterSize * sizeof(*filter));
622  if (!filter)
623  goto nomem;
624  if (filterSize >= MAX_FILTER_SIZE * 16 /
625  ((flags & SWS_ACCURATE_RND) ? APCK_SIZE : 16)) {
626  ret = RETCODE_USE_CASCADE;
627  goto fail;
628  }
629 
630  if (flags & SWS_PRINT_INFO)
632  "SwScaler: reducing / aligning filtersize %d -> %d\n",
633  filter2Size, filterSize);
634  /* try to reduce the filter-size (step2 reduce it) */
635  for (i = 0; i < dstW; i++) {
636  int j;
637 
638  for (j = 0; j < filterSize; j++) {
639  if (j >= filter2Size)
640  filter[i * filterSize + j] = 0;
641  else
642  filter[i * filterSize + j] = filter2[i * filter2Size + j];
643  if ((flags & SWS_BITEXACT) && j >= minFilterSize)
644  filter[i * filterSize + j] = 0;
645  }
646  }
647 
648  // FIXME try to align filterPos if possible
649 
650  // fix borders
651  for (i = 0; i < dstW; i++) {
652  int j;
653  if ((*filterPos)[i] < 0) {
654  // move filter coefficients left to compensate for filterPos
655  for (j = 1; j < filterSize; j++) {
656  int left = FFMAX(j + (*filterPos)[i], 0);
657  filter[i * filterSize + left] += filter[i * filterSize + j];
658  filter[i * filterSize + j] = 0;
659  }
660  (*filterPos)[i]= 0;
661  }
662 
663  if ((*filterPos)[i] + filterSize > srcW) {
664  int shift = (*filterPos)[i] + FFMIN(filterSize - srcW, 0);
665  int64_t acc = 0;
666 
667  for (j = filterSize - 1; j >= 0; j--) {
668  if ((*filterPos)[i] + j >= srcW) {
669  acc += filter[i * filterSize + j];
670  filter[i * filterSize + j] = 0;
671  }
672  }
673  for (j = filterSize - 1; j >= 0; j--) {
674  if (j < shift) {
675  filter[i * filterSize + j] = 0;
676  } else {
677  filter[i * filterSize + j] = filter[i * filterSize + j - shift];
678  }
679  }
680 
681  (*filterPos)[i]-= shift;
682  filter[i * filterSize + srcW - 1 - (*filterPos)[i]] += acc;
683  }
684  av_assert0((*filterPos)[i] >= 0);
685  av_assert0((*filterPos)[i] < srcW);
686  if ((*filterPos)[i] + filterSize > srcW) {
687  for (j = 0; j < filterSize; j++) {
688  av_assert0((*filterPos)[i] + j < srcW || !filter[i * filterSize + j]);
689  }
690  }
691  }
692 
693  *outFilterSize = FFMIN(filterSize, FFALIGN(srcW, filterAlign));
694 
695  // Note the +1 is for the MMX scaler which reads over the end
696  /* align at 16 for AltiVec (needed by hScale_altivec_real) */
697  *outFilter = av_calloc(dstW + 3, *outFilterSize * sizeof(**outFilter));
698  if (!*outFilter)
699  goto nomem;
700 
701  /* normalize & store in outFilter */
702  for (i = 0; i < dstW; i++) {
703  int j;
704  int64_t error = 0;
705  int64_t sum = 0;
706 
707  for (j = 0; j < filterSize; j++) {
708  sum += filter[i * filterSize + j];
709  }
710  sum = (sum + one / 2) / one;
711  if (!sum) {
712  av_log(NULL, AV_LOG_WARNING, "SwScaler: zero vector in scaling\n");
713  sum = 1;
714  }
715  for (j = 0; j < *outFilterSize; j++) {
716  int64_t v = filter[i * filterSize + j] + error;
717  int intV = ROUNDED_DIV(v, sum);
718  (*outFilter)[i * (*outFilterSize) + j] = intV;
719  error = v - intV * sum;
720  }
721  }
722 
723  (*filterPos)[dstW + 0] =
724  (*filterPos)[dstW + 1] =
725  (*filterPos)[dstW + 2] = (*filterPos)[dstW - 1]; /* the MMX/SSE scaler will
726  * read over the end */
727  for (i = 0; i < *outFilterSize; i++) {
728  int k = (dstW - 1) * (*outFilterSize) + i;
729  (*outFilter)[k + 1 * (*outFilterSize)] =
730  (*outFilter)[k + 2 * (*outFilterSize)] =
731  (*outFilter)[k + 3 * (*outFilterSize)] = (*outFilter)[k];
732  }
733 
734  ret = 0;
735  goto done;
736 nomem:
737  ret = AVERROR(ENOMEM);
738 fail:
739  if(ret < 0)
740  av_log(NULL, ret == RETCODE_USE_CASCADE ? AV_LOG_DEBUG : AV_LOG_ERROR, "sws: initFilter failed\n");
741 done:
742  av_free(filter);
743  av_free(filter2);
744  return ret;
745 }
746 
747 static void fill_rgb2yuv_table(SwsContext *c, const int table[4], int dstRange)
748 {
749  int64_t W, V, Z, Cy, Cu, Cv;
750  int64_t vr = table[0];
751  int64_t ub = table[1];
752  int64_t ug = -table[2];
753  int64_t vg = -table[3];
754  int64_t ONE = 65536;
755  int64_t cy = ONE;
756  uint8_t *p = (uint8_t*)c->input_rgb2yuv_table;
757  int i;
758  static const int8_t map[] = {
759  BY_IDX, GY_IDX, -1 , BY_IDX, BY_IDX, GY_IDX, -1 , BY_IDX,
760  RY_IDX, -1 , GY_IDX, RY_IDX, RY_IDX, -1 , GY_IDX, RY_IDX,
761  RY_IDX, GY_IDX, -1 , RY_IDX, RY_IDX, GY_IDX, -1 , RY_IDX,
762  BY_IDX, -1 , GY_IDX, BY_IDX, BY_IDX, -1 , GY_IDX, BY_IDX,
763  BU_IDX, GU_IDX, -1 , BU_IDX, BU_IDX, GU_IDX, -1 , BU_IDX,
764  RU_IDX, -1 , GU_IDX, RU_IDX, RU_IDX, -1 , GU_IDX, RU_IDX,
765  RU_IDX, GU_IDX, -1 , RU_IDX, RU_IDX, GU_IDX, -1 , RU_IDX,
766  BU_IDX, -1 , GU_IDX, BU_IDX, BU_IDX, -1 , GU_IDX, BU_IDX,
767  BV_IDX, GV_IDX, -1 , BV_IDX, BV_IDX, GV_IDX, -1 , BV_IDX,
768  RV_IDX, -1 , GV_IDX, RV_IDX, RV_IDX, -1 , GV_IDX, RV_IDX,
769  RV_IDX, GV_IDX, -1 , RV_IDX, RV_IDX, GV_IDX, -1 , RV_IDX,
770  BV_IDX, -1 , GV_IDX, BV_IDX, BV_IDX, -1 , GV_IDX, BV_IDX,
773  GY_IDX, -1 , GY_IDX, -1 , GY_IDX, -1 , GY_IDX, -1 ,
774  -1 , GY_IDX, -1 , GY_IDX, -1 , GY_IDX, -1 , GY_IDX,
777  GU_IDX, -1 , GU_IDX, -1 , GU_IDX, -1 , GU_IDX, -1 ,
778  -1 , GU_IDX, -1 , GU_IDX, -1 , GU_IDX, -1 , GU_IDX,
781  GV_IDX, -1 , GV_IDX, -1 , GV_IDX, -1 , GV_IDX, -1 ,
782  -1 , GV_IDX, -1 , GV_IDX, -1 , GV_IDX, -1 , GV_IDX, //23
783  -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //24
784  -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //25
785  -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //26
786  -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //27
787  -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //28
788  -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //29
789  -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //30
790  -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //31
791  BY_IDX, GY_IDX, RY_IDX, -1 , -1 , -1 , -1 , -1 , //32
792  BU_IDX, GU_IDX, RU_IDX, -1 , -1 , -1 , -1 , -1 , //33
793  BV_IDX, GV_IDX, RV_IDX, -1 , -1 , -1 , -1 , -1 , //34
794  };
795 
796  dstRange = 0; //FIXME range = 1 is handled elsewhere
797 
798  if (!dstRange) {
799  cy = cy * 255 / 219;
800  } else {
801  vr = vr * 224 / 255;
802  ub = ub * 224 / 255;
803  ug = ug * 224 / 255;
804  vg = vg * 224 / 255;
805  }
806  W = ROUNDED_DIV(ONE*ONE*ug, ub);
807  V = ROUNDED_DIV(ONE*ONE*vg, vr);
808  Z = ONE*ONE-W-V;
809 
810  Cy = ROUNDED_DIV(cy*Z, ONE);
811  Cu = ROUNDED_DIV(ub*Z, ONE);
812  Cv = ROUNDED_DIV(vr*Z, ONE);
813 
814  c->input_rgb2yuv_table[RY_IDX] = -ROUNDED_DIV((1 << RGB2YUV_SHIFT)*V , Cy);
815  c->input_rgb2yuv_table[GY_IDX] = ROUNDED_DIV((1 << RGB2YUV_SHIFT)*ONE*ONE , Cy);
816  c->input_rgb2yuv_table[BY_IDX] = -ROUNDED_DIV((1 << RGB2YUV_SHIFT)*W , Cy);
817 
818  c->input_rgb2yuv_table[RU_IDX] = ROUNDED_DIV((1 << RGB2YUV_SHIFT)*V , Cu);
819  c->input_rgb2yuv_table[GU_IDX] = -ROUNDED_DIV((1 << RGB2YUV_SHIFT)*ONE*ONE , Cu);
820  c->input_rgb2yuv_table[BU_IDX] = ROUNDED_DIV((1 << RGB2YUV_SHIFT)*(Z+W) , Cu);
821 
822  c->input_rgb2yuv_table[RV_IDX] = ROUNDED_DIV((1 << RGB2YUV_SHIFT)*(V+Z) , Cv);
823  c->input_rgb2yuv_table[GV_IDX] = -ROUNDED_DIV((1 << RGB2YUV_SHIFT)*ONE*ONE , Cv);
824  c->input_rgb2yuv_table[BV_IDX] = ROUNDED_DIV((1 << RGB2YUV_SHIFT)*W , Cv);
825 
826  if(/*!dstRange && */!memcmp(table, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT], sizeof(ff_yuv2rgb_coeffs[SWS_CS_DEFAULT]))) {
827  c->input_rgb2yuv_table[BY_IDX] = ((int)(0.114 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
828  c->input_rgb2yuv_table[BV_IDX] = (-(int)(0.081 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
829  c->input_rgb2yuv_table[BU_IDX] = ((int)(0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
830  c->input_rgb2yuv_table[GY_IDX] = ((int)(0.587 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
831  c->input_rgb2yuv_table[GV_IDX] = (-(int)(0.419 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
832  c->input_rgb2yuv_table[GU_IDX] = (-(int)(0.331 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
833  c->input_rgb2yuv_table[RY_IDX] = ((int)(0.299 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
834  c->input_rgb2yuv_table[RV_IDX] = ((int)(0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
835  c->input_rgb2yuv_table[RU_IDX] = (-(int)(0.169 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
836  }
837  for(i=0; i<FF_ARRAY_ELEMS(map); i++)
838  AV_WL16(p + 16*4 + 2*i, map[i] >= 0 ? c->input_rgb2yuv_table[map[i]] : 0);
839 }
840 
841 static void fill_xyztables(struct SwsContext *c)
842 {
843  int i;
844  double xyzgamma = XYZ_GAMMA;
845  double rgbgamma = 1.0 / RGB_GAMMA;
846  double xyzgammainv = 1.0 / XYZ_GAMMA;
847  double rgbgammainv = RGB_GAMMA;
848  static const int16_t xyz2rgb_matrix[3][4] = {
849  {13270, -6295, -2041},
850  {-3969, 7682, 170},
851  { 228, -835, 4329} };
852  static const int16_t rgb2xyz_matrix[3][4] = {
853  {1689, 1464, 739},
854  { 871, 2929, 296},
855  { 79, 488, 3891} };
856  static int16_t xyzgamma_tab[4096], rgbgamma_tab[4096], xyzgammainv_tab[4096], rgbgammainv_tab[4096];
857 
858  memcpy(c->xyz2rgb_matrix, xyz2rgb_matrix, sizeof(c->xyz2rgb_matrix));
859  memcpy(c->rgb2xyz_matrix, rgb2xyz_matrix, sizeof(c->rgb2xyz_matrix));
860  c->xyzgamma = xyzgamma_tab;
861  c->rgbgamma = rgbgamma_tab;
862  c->xyzgammainv = xyzgammainv_tab;
863  c->rgbgammainv = rgbgammainv_tab;
864 
865  if (rgbgamma_tab[4095])
866  return;
867 
868  /* set gamma vectors */
869  for (i = 0; i < 4096; i++) {
870  xyzgamma_tab[i] = lrint(pow(i / 4095.0, xyzgamma) * 4095.0);
871  rgbgamma_tab[i] = lrint(pow(i / 4095.0, rgbgamma) * 4095.0);
872  xyzgammainv_tab[i] = lrint(pow(i / 4095.0, xyzgammainv) * 4095.0);
873  rgbgammainv_tab[i] = lrint(pow(i / 4095.0, rgbgammainv) * 4095.0);
874  }
875 }
876 
878 {
879  return !isYUV(format) && !isGray(format);
880 }
881 
882 int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4],
883  int srcRange, const int table[4], int dstRange,
884  int brightness, int contrast, int saturation)
885 {
886  const AVPixFmtDescriptor *desc_dst;
887  const AVPixFmtDescriptor *desc_src;
888  int need_reinit = 0;
889 
890  handle_formats(c);
891  desc_dst = av_pix_fmt_desc_get(c->dstFormat);
892  desc_src = av_pix_fmt_desc_get(c->srcFormat);
893 
894  if(range_override_needed(c->dstFormat))
895  dstRange = 0;
896  if(range_override_needed(c->srcFormat))
897  srcRange = 0;
898 
899  if (c->srcRange != srcRange ||
900  c->dstRange != dstRange ||
901  c->brightness != brightness ||
902  c->contrast != contrast ||
903  c->saturation != saturation ||
904  memcmp(c->srcColorspaceTable, inv_table, sizeof(int) * 4) ||
905  memcmp(c->dstColorspaceTable, table, sizeof(int) * 4)
906  )
907  need_reinit = 1;
908 
909  memmove(c->srcColorspaceTable, inv_table, sizeof(int) * 4);
910  memmove(c->dstColorspaceTable, table, sizeof(int) * 4);
911 
912 
913 
914  c->brightness = brightness;
915  c->contrast = contrast;
916  c->saturation = saturation;
917  c->srcRange = srcRange;
918  c->dstRange = dstRange;
919 
920  //The srcBpc check is possibly wrong but we seem to lack a definitive reference to test this
921  //and what we have in ticket 2939 looks better with this check
922  if (need_reinit && (c->srcBpc == 8 || !isYUV(c->srcFormat)))
924 
925  c->dstFormatBpp = av_get_bits_per_pixel(desc_dst);
926  c->srcFormatBpp = av_get_bits_per_pixel(desc_src);
927 
928  if (c->cascaded_context[c->cascaded_mainindex])
929  return sws_setColorspaceDetails(c->cascaded_context[c->cascaded_mainindex],inv_table, srcRange,table, dstRange, brightness, contrast, saturation);
930 
931  if (!need_reinit)
932  return 0;
933 
934  if ((isYUV(c->dstFormat) || isGray(c->dstFormat)) && (isYUV(c->srcFormat) || isGray(c->srcFormat))) {
935  if (!c->cascaded_context[0] &&
936  memcmp(c->dstColorspaceTable, c->srcColorspaceTable, sizeof(int) * 4) &&
937  c->srcW && c->srcH && c->dstW && c->dstH) {
938  enum AVPixelFormat tmp_format;
939  int tmp_width, tmp_height;
940  int srcW = c->srcW;
941  int srcH = c->srcH;
942  int dstW = c->dstW;
943  int dstH = c->dstH;
944  int ret;
945  av_log(c, AV_LOG_VERBOSE, "YUV color matrix differs for YUV->YUV, using intermediate RGB to convert\n");
946 
947  if (isNBPS(c->dstFormat) || is16BPS(c->dstFormat)) {
948  if (isALPHA(c->srcFormat) && isALPHA(c->dstFormat)) {
949  tmp_format = AV_PIX_FMT_BGRA64;
950  } else {
951  tmp_format = AV_PIX_FMT_BGR48;
952  }
953  } else {
954  if (isALPHA(c->srcFormat) && isALPHA(c->dstFormat)) {
955  tmp_format = AV_PIX_FMT_BGRA;
956  } else {
957  tmp_format = AV_PIX_FMT_BGR24;
958  }
959  }
960 
961  if (srcW*srcH > dstW*dstH) {
962  tmp_width = dstW;
963  tmp_height = dstH;
964  } else {
965  tmp_width = srcW;
966  tmp_height = srcH;
967  }
968 
969  ret = av_image_alloc(c->cascaded_tmp, c->cascaded_tmpStride,
970  tmp_width, tmp_height, tmp_format, 64);
971  if (ret < 0)
972  return ret;
973 
974  c->cascaded_context[0] = sws_alloc_set_opts(srcW, srcH, c->srcFormat,
975  tmp_width, tmp_height, tmp_format,
976  c->flags, c->param);
977  if (!c->cascaded_context[0])
978  return -1;
979 
980  c->cascaded_context[0]->alphablend = c->alphablend;
981  ret = sws_init_context(c->cascaded_context[0], NULL , NULL);
982  if (ret < 0)
983  return ret;
984  //we set both src and dst depending on that the RGB side will be ignored
985  sws_setColorspaceDetails(c->cascaded_context[0], inv_table,
986  srcRange, table, dstRange,
987  brightness, contrast, saturation);
988 
989  c->cascaded_context[1] = sws_getContext(tmp_width, tmp_height, tmp_format,
990  dstW, dstH, c->dstFormat,
991  c->flags, NULL, NULL, c->param);
992  if (!c->cascaded_context[1])
993  return -1;
994  sws_setColorspaceDetails(c->cascaded_context[1], inv_table,
995  srcRange, table, dstRange,
996  0, 1 << 16, 1 << 16);
997  return 0;
998  }
999  return -1;
1000  }
1001 
1002  if (!isYUV(c->dstFormat) && !isGray(c->dstFormat)) {
1003  ff_yuv2rgb_c_init_tables(c, inv_table, srcRange, brightness,
1004  contrast, saturation);
1005  // FIXME factorize
1006 
1007  if (ARCH_PPC)
1008  ff_yuv2rgb_init_tables_ppc(c, inv_table, brightness,
1009  contrast, saturation);
1010  }
1011 
1012  fill_rgb2yuv_table(c, table, dstRange);
1013 
1014  return 0;
1015 }
1016 
1017 int sws_getColorspaceDetails(struct SwsContext *c, int **inv_table,
1018  int *srcRange, int **table, int *dstRange,
1019  int *brightness, int *contrast, int *saturation)
1020 {
1021  if (!c )
1022  return -1;
1023 
1024  *inv_table = c->srcColorspaceTable;
1025  *table = c->dstColorspaceTable;
1026  *srcRange = range_override_needed(c->srcFormat) ? 1 : c->srcRange;
1027  *dstRange = range_override_needed(c->dstFormat) ? 1 : c->dstRange;
1028  *brightness = c->brightness;
1029  *contrast = c->contrast;
1030  *saturation = c->saturation;
1031 
1032  return 0;
1033 }
1034 
1036 {
1037  switch (*format) {
1038  case AV_PIX_FMT_YUVJ420P:
1040  return 1;
1041  case AV_PIX_FMT_YUVJ411P:
1043  return 1;
1044  case AV_PIX_FMT_YUVJ422P:
1046  return 1;
1047  case AV_PIX_FMT_YUVJ444P:
1049  return 1;
1050  case AV_PIX_FMT_YUVJ440P:
1052  return 1;
1053  case AV_PIX_FMT_GRAY8:
1054  case AV_PIX_FMT_YA8:
1055  case AV_PIX_FMT_GRAY9LE:
1056  case AV_PIX_FMT_GRAY9BE:
1057  case AV_PIX_FMT_GRAY10LE:
1058  case AV_PIX_FMT_GRAY10BE:
1059  case AV_PIX_FMT_GRAY12LE:
1060  case AV_PIX_FMT_GRAY12BE:
1061  case AV_PIX_FMT_GRAY14LE:
1062  case AV_PIX_FMT_GRAY14BE:
1063  case AV_PIX_FMT_GRAY16LE:
1064  case AV_PIX_FMT_GRAY16BE:
1065  case AV_PIX_FMT_YA16BE:
1066  case AV_PIX_FMT_YA16LE:
1067  return 1;
1068  default:
1069  return 0;
1070  }
1071 }
1072 
1074 {
1075  switch (*format) {
1076  case AV_PIX_FMT_0BGR : *format = AV_PIX_FMT_ABGR ; return 1;
1077  case AV_PIX_FMT_BGR0 : *format = AV_PIX_FMT_BGRA ; return 4;
1078  case AV_PIX_FMT_0RGB : *format = AV_PIX_FMT_ARGB ; return 1;
1079  case AV_PIX_FMT_RGB0 : *format = AV_PIX_FMT_RGBA ; return 4;
1080  default: return 0;
1081  }
1082 }
1083 
1085 {
1086  switch (*format) {
1087  case AV_PIX_FMT_XYZ12BE : *format = AV_PIX_FMT_RGB48BE; return 1;
1088  case AV_PIX_FMT_XYZ12LE : *format = AV_PIX_FMT_RGB48LE; return 1;
1089  default: return 0;
1090  }
1091 }
1092 
1094 {
1095  c->src0Alpha |= handle_0alpha(&c->srcFormat);
1096  c->dst0Alpha |= handle_0alpha(&c->dstFormat);
1097  c->srcXYZ |= handle_xyz(&c->srcFormat);
1098  c->dstXYZ |= handle_xyz(&c->dstFormat);
1099  if (c->srcXYZ || c->dstXYZ)
1100  fill_xyztables(c);
1101 }
1102 
1104 {
1105  SwsContext *c = av_mallocz(sizeof(SwsContext));
1106 
1107  av_assert0(offsetof(SwsContext, redDither) + DITHER32_INT == offsetof(SwsContext, dither32));
1108 
1109  if (c) {
1110  c->av_class = &ff_sws_context_class;
1112  }
1113 
1114  return c;
1115 }
1116 
1117 static uint16_t * alloc_gamma_tbl(double e)
1118 {
1119  int i = 0;
1120  uint16_t * tbl;
1121  tbl = (uint16_t*)av_malloc(sizeof(uint16_t) * 1 << 16);
1122  if (!tbl)
1123  return NULL;
1124 
1125  for (i = 0; i < 65536; ++i) {
1126  tbl[i] = pow(i / 65535.0, e) * 65535.0;
1127  }
1128  return tbl;
1129 }
1130 
1131 static enum AVPixelFormat alphaless_fmt(enum AVPixelFormat fmt)
1132 {
1133  switch(fmt) {
1134  case AV_PIX_FMT_ARGB: return AV_PIX_FMT_RGB24;
1135  case AV_PIX_FMT_RGBA: return AV_PIX_FMT_RGB24;
1136  case AV_PIX_FMT_ABGR: return AV_PIX_FMT_BGR24;
1137  case AV_PIX_FMT_BGRA: return AV_PIX_FMT_BGR24;
1138  case AV_PIX_FMT_YA8: return AV_PIX_FMT_GRAY8;
1139 
1143 
1144  case AV_PIX_FMT_GBRAP: return AV_PIX_FMT_GBRP;
1145 
1148 
1151 
1154 
1159 
1160  case AV_PIX_FMT_YA16BE: return AV_PIX_FMT_GRAY16;
1161  case AV_PIX_FMT_YA16LE: return AV_PIX_FMT_GRAY16;
1162 
1181 
1182 // case AV_PIX_FMT_AYUV64LE:
1183 // case AV_PIX_FMT_AYUV64BE:
1184 // case AV_PIX_FMT_PAL8:
1185  default: return AV_PIX_FMT_NONE;
1186  }
1187 }
1188 
1190  SwsFilter *dstFilter)
1191 {
1192  int i;
1193  int usesVFilter, usesHFilter;
1194  int unscaled;
1195  SwsFilter dummyFilter = { NULL, NULL, NULL, NULL };
1196  int srcW = c->srcW;
1197  int srcH = c->srcH;
1198  int dstW = c->dstW;
1199  int dstH = c->dstH;
1200  int dst_stride = FFALIGN(dstW * sizeof(int16_t) + 66, 16);
1201  int flags, cpu_flags;
1202  enum AVPixelFormat srcFormat = c->srcFormat;
1203  enum AVPixelFormat dstFormat = c->dstFormat;
1204  const AVPixFmtDescriptor *desc_src;
1205  const AVPixFmtDescriptor *desc_dst;
1206  int ret = 0;
1207  enum AVPixelFormat tmpFmt;
1208  static const float float_mult = 1.0f / 255.0f;
1209  static AVOnce rgb2rgb_once = AV_ONCE_INIT;
1210 
1212  flags = c->flags;
1213  emms_c();
1214  if (ff_thread_once(&rgb2rgb_once, ff_sws_rgb2rgb_init) != 0)
1215  return AVERROR_UNKNOWN;
1216 
1217  unscaled = (srcW == dstW && srcH == dstH);
1218 
1219  c->srcRange |= handle_jpeg(&c->srcFormat);
1220  c->dstRange |= handle_jpeg(&c->dstFormat);
1221 
1222  if(srcFormat!=c->srcFormat || dstFormat!=c->dstFormat)
1223  av_log(c, AV_LOG_WARNING, "deprecated pixel format used, make sure you did set range correctly\n");
1224 
1225  if (!c->contrast && !c->saturation && !c->dstFormatBpp)
1228  c->dstRange, 0, 1 << 16, 1 << 16);
1229 
1230  handle_formats(c);
1231  srcFormat = c->srcFormat;
1232  dstFormat = c->dstFormat;
1233  desc_src = av_pix_fmt_desc_get(srcFormat);
1234  desc_dst = av_pix_fmt_desc_get(dstFormat);
1235 
1236  // If the source has no alpha then disable alpha blendaway
1237  if (c->src0Alpha)
1238  c->alphablend = SWS_ALPHA_BLEND_NONE;
1239 
1240  if (!(unscaled && sws_isSupportedEndiannessConversion(srcFormat) &&
1241  av_pix_fmt_swap_endianness(srcFormat) == dstFormat)) {
1242  if (!sws_isSupportedInput(srcFormat)) {
1243  av_log(c, AV_LOG_ERROR, "%s is not supported as input pixel format\n",
1244  av_get_pix_fmt_name(srcFormat));
1245  return AVERROR(EINVAL);
1246  }
1247  if (!sws_isSupportedOutput(dstFormat)) {
1248  av_log(c, AV_LOG_ERROR, "%s is not supported as output pixel format\n",
1249  av_get_pix_fmt_name(dstFormat));
1250  return AVERROR(EINVAL);
1251  }
1252  }
1253  av_assert2(desc_src && desc_dst);
1254 
1255  i = flags & (SWS_POINT |
1256  SWS_AREA |
1257  SWS_BILINEAR |
1259  SWS_BICUBIC |
1260  SWS_X |
1261  SWS_GAUSS |
1262  SWS_LANCZOS |
1263  SWS_SINC |
1264  SWS_SPLINE |
1265  SWS_BICUBLIN);
1266 
1267  /* provide a default scaler if not set by caller */
1268  if (!i) {
1269  if (dstW < srcW && dstH < srcH)
1270  flags |= SWS_BICUBIC;
1271  else if (dstW > srcW && dstH > srcH)
1272  flags |= SWS_BICUBIC;
1273  else
1274  flags |= SWS_BICUBIC;
1275  c->flags = flags;
1276  } else if (i & (i - 1)) {
1278  "Exactly one scaler algorithm must be chosen, got %X\n", i);
1279  return AVERROR(EINVAL);
1280  }
1281  /* sanity check */
1282  if (srcW < 1 || srcH < 1 || dstW < 1 || dstH < 1) {
1283  /* FIXME check if these are enough and try to lower them after
1284  * fixing the relevant parts of the code */
1285  av_log(c, AV_LOG_ERROR, "%dx%d -> %dx%d is invalid scaling dimension\n",
1286  srcW, srcH, dstW, dstH);
1287  return AVERROR(EINVAL);
1288  }
1289  if (flags & SWS_FAST_BILINEAR) {
1290  /* the fast bilinear scalers keep the source position in 16.16 fixed point */
1291  if (srcW < 8 || dstW <= 8 || srcW >= 65536) {
1293  c->flags = flags;
1294  }
1295  }
1296 
1297  ret = av_image_check_size2(srcW, srcH, INT64_MAX, AV_PIX_FMT_NONE, 0, c);
1298  if (ret >= 0)
1299  ret = av_image_check_size2(dstW, dstH, INT64_MAX, AV_PIX_FMT_NONE, 0, c);
1300  if (ret < 0)
1301  return ret;
1302 
1303  if (!dstFilter)
1304  dstFilter = &dummyFilter;
1305  if (!srcFilter)
1306  srcFilter = &dummyFilter;
1307 
1308  int64_t lumXInc = (((int64_t)srcW << 16) + (dstW >> 1)) / dstW;
1309  int64_t lumYInc = (((int64_t)srcH << 16) + (dstH >> 1)) / dstH;
1310  c->dstFormatBpp = av_get_bits_per_pixel(desc_dst);
1311  c->srcFormatBpp = av_get_bits_per_pixel(desc_src);
1312  c->vRounder = 4 * 0x0001000100010001ULL;
1313 
1314  usesVFilter = (srcFilter->lumV && srcFilter->lumV->length > 1) ||
1315  (srcFilter->chrV && srcFilter->chrV->length > 1) ||
1316  (dstFilter->lumV && dstFilter->lumV->length > 1) ||
1317  (dstFilter->chrV && dstFilter->chrV->length > 1);
1318  usesHFilter = (srcFilter->lumH && srcFilter->lumH->length > 1) ||
1319  (srcFilter->chrH && srcFilter->chrH->length > 1) ||
1320  (dstFilter->lumH && dstFilter->lumH->length > 1) ||
1321  (dstFilter->chrH && dstFilter->chrH->length > 1);
1322 
1323  av_pix_fmt_get_chroma_sub_sample(srcFormat, &c->chrSrcHSubSample, &c->chrSrcVSubSample);
1324  av_pix_fmt_get_chroma_sub_sample(dstFormat, &c->chrDstHSubSample, &c->chrDstVSubSample);
1325 
1326  if (isAnyRGB(dstFormat) && !(flags&SWS_FULL_CHR_H_INT)) {
1327  if (dstW&1) {
1328  av_log(c, AV_LOG_DEBUG, "Forcing full internal H chroma due to odd output size\n");
1330  c->flags = flags;
1331  }
1332 
1333  if ( c->chrSrcHSubSample == 0
1334  && c->chrSrcVSubSample == 0
1335  && c->dither != SWS_DITHER_BAYER //SWS_FULL_CHR_H_INT is currently not supported with SWS_DITHER_BAYER
1336  && !(c->flags & SWS_FAST_BILINEAR)
1337  ) {
1338  av_log(c, AV_LOG_DEBUG, "Forcing full internal H chroma due to input having non subsampled chroma\n");
1340  c->flags = flags;
1341  }
1342  }
1343 
1344  if (c->dither == SWS_DITHER_AUTO) {
1345  if (flags & SWS_ERROR_DIFFUSION)
1346  c->dither = SWS_DITHER_ED;
1347  }
1348 
1349  if(dstFormat == AV_PIX_FMT_BGR4_BYTE ||
1350  dstFormat == AV_PIX_FMT_RGB4_BYTE ||
1351  dstFormat == AV_PIX_FMT_BGR8 ||
1352  dstFormat == AV_PIX_FMT_RGB8) {
1353  if (c->dither == SWS_DITHER_AUTO)
1355  if (!(flags & SWS_FULL_CHR_H_INT)) {
1356  if (c->dither == SWS_DITHER_ED || c->dither == SWS_DITHER_A_DITHER || c->dither == SWS_DITHER_X_DITHER) {
1358  "Desired dithering only supported in full chroma interpolation for destination format '%s'\n",
1359  av_get_pix_fmt_name(dstFormat));
1361  c->flags = flags;
1362  }
1363  }
1364  if (flags & SWS_FULL_CHR_H_INT) {
1365  if (c->dither == SWS_DITHER_BAYER) {
1367  "Ordered dither is not supported in full chroma interpolation for destination format '%s'\n",
1368  av_get_pix_fmt_name(dstFormat));
1369  c->dither = SWS_DITHER_ED;
1370  }
1371  }
1372  }
1373  if (isPlanarRGB(dstFormat)) {
1374  if (!(flags & SWS_FULL_CHR_H_INT)) {
1376  "%s output is not supported with half chroma resolution, switching to full\n",
1377  av_get_pix_fmt_name(dstFormat));
1379  c->flags = flags;
1380  }
1381  }
1382 
1383  /* reuse chroma for 2 pixels RGB/BGR unless user wants full
1384  * chroma interpolation */
1385  if (flags & SWS_FULL_CHR_H_INT &&
1386  isAnyRGB(dstFormat) &&
1387  !isPlanarRGB(dstFormat) &&
1388  dstFormat != AV_PIX_FMT_RGBA64LE &&
1389  dstFormat != AV_PIX_FMT_RGBA64BE &&
1390  dstFormat != AV_PIX_FMT_BGRA64LE &&
1391  dstFormat != AV_PIX_FMT_BGRA64BE &&
1392  dstFormat != AV_PIX_FMT_RGB48LE &&
1393  dstFormat != AV_PIX_FMT_RGB48BE &&
1394  dstFormat != AV_PIX_FMT_BGR48LE &&
1395  dstFormat != AV_PIX_FMT_BGR48BE &&
1396  dstFormat != AV_PIX_FMT_RGBA &&
1397  dstFormat != AV_PIX_FMT_ARGB &&
1398  dstFormat != AV_PIX_FMT_BGRA &&
1399  dstFormat != AV_PIX_FMT_ABGR &&
1400  dstFormat != AV_PIX_FMT_RGB24 &&
1401  dstFormat != AV_PIX_FMT_BGR24 &&
1402  dstFormat != AV_PIX_FMT_BGR4_BYTE &&
1403  dstFormat != AV_PIX_FMT_RGB4_BYTE &&
1404  dstFormat != AV_PIX_FMT_BGR8 &&
1405  dstFormat != AV_PIX_FMT_RGB8
1406  ) {
1408  "full chroma interpolation for destination format '%s' not yet implemented\n",
1409  av_get_pix_fmt_name(dstFormat));
1411  c->flags = flags;
1412  }
1413  if (isAnyRGB(dstFormat) && !(flags & SWS_FULL_CHR_H_INT))
1414  c->chrDstHSubSample = 1;
1415 
1416  // drop some chroma lines if the user wants it
1417  c->vChrDrop = (flags & SWS_SRC_V_CHR_DROP_MASK) >>
1419  c->chrSrcVSubSample += c->vChrDrop;
1420 
1421  /* drop every other pixel for chroma calculation unless user
1422  * wants full chroma */
1423  if (isAnyRGB(srcFormat) && !(flags & SWS_FULL_CHR_H_INP) &&
1424  srcFormat != AV_PIX_FMT_RGB8 && srcFormat != AV_PIX_FMT_BGR8 &&
1425  srcFormat != AV_PIX_FMT_RGB4 && srcFormat != AV_PIX_FMT_BGR4 &&
1426  srcFormat != AV_PIX_FMT_RGB4_BYTE && srcFormat != AV_PIX_FMT_BGR4_BYTE &&
1427  srcFormat != AV_PIX_FMT_GBRP9BE && srcFormat != AV_PIX_FMT_GBRP9LE &&
1428  srcFormat != AV_PIX_FMT_GBRP10BE && srcFormat != AV_PIX_FMT_GBRP10LE &&
1429  srcFormat != AV_PIX_FMT_GBRAP10BE && srcFormat != AV_PIX_FMT_GBRAP10LE &&
1430  srcFormat != AV_PIX_FMT_GBRP12BE && srcFormat != AV_PIX_FMT_GBRP12LE &&
1431  srcFormat != AV_PIX_FMT_GBRAP12BE && srcFormat != AV_PIX_FMT_GBRAP12LE &&
1432  srcFormat != AV_PIX_FMT_GBRP14BE && srcFormat != AV_PIX_FMT_GBRP14LE &&
1433  srcFormat != AV_PIX_FMT_GBRP16BE && srcFormat != AV_PIX_FMT_GBRP16LE &&
1434  srcFormat != AV_PIX_FMT_GBRAP16BE && srcFormat != AV_PIX_FMT_GBRAP16LE &&
1435  srcFormat != AV_PIX_FMT_GBRPF32BE && srcFormat != AV_PIX_FMT_GBRPF32LE &&
1436  srcFormat != AV_PIX_FMT_GBRAPF32BE && srcFormat != AV_PIX_FMT_GBRAPF32LE &&
1437  ((dstW >> c->chrDstHSubSample) <= (srcW >> 1) ||
1438  (flags & SWS_FAST_BILINEAR)))
1439  c->chrSrcHSubSample = 1;
1440 
1441  // Note the AV_CEIL_RSHIFT is so that we always round toward +inf.
1442  c->chrSrcW = AV_CEIL_RSHIFT(srcW, c->chrSrcHSubSample);
1443  c->chrSrcH = AV_CEIL_RSHIFT(srcH, c->chrSrcVSubSample);
1444  c->chrDstW = AV_CEIL_RSHIFT(dstW, c->chrDstHSubSample);
1445  c->chrDstH = AV_CEIL_RSHIFT(dstH, c->chrDstVSubSample);
1446 
1447  if (!FF_ALLOCZ_TYPED_ARRAY(c->formatConvBuffer, FFALIGN(srcW * 2 + 78, 16) * 2))
1448  goto nomem;
1449 
1450  c->srcBpc = desc_src->comp[0].depth;
1451  if (c->srcBpc < 8)
1452  c->srcBpc = 8;
1453  c->dstBpc = desc_dst->comp[0].depth;
1454  if (c->dstBpc < 8)
1455  c->dstBpc = 8;
1456  if (isAnyRGB(srcFormat) || srcFormat == AV_PIX_FMT_PAL8)
1457  c->srcBpc = 16;
1458  if (c->dstBpc == 16)
1459  dst_stride <<= 1;
1460 
1461  if (INLINE_MMXEXT(cpu_flags) && c->srcBpc == 8 && c->dstBpc <= 14) {
1462  c->canMMXEXTBeUsed = dstW >= srcW && (dstW & 31) == 0 &&
1463  c->chrDstW >= c->chrSrcW &&
1464  (srcW & 15) == 0;
1465  if (!c->canMMXEXTBeUsed && dstW >= srcW && c->chrDstW >= c->chrSrcW && (srcW & 15) == 0
1466 
1467  && (flags & SWS_FAST_BILINEAR)) {
1468  if (flags & SWS_PRINT_INFO)
1469  av_log(c, AV_LOG_INFO,
1470  "output width is not a multiple of 32 -> no MMXEXT scaler\n");
1471  }
1472  if (usesHFilter || isNBPS(c->srcFormat) || is16BPS(c->srcFormat) || isAnyRGB(c->srcFormat))
1473  c->canMMXEXTBeUsed = 0;
1474  } else
1475  c->canMMXEXTBeUsed = 0;
1476 
1477  int64_t chrXInc = (((int64_t)c->chrSrcW << 16) + (c->chrDstW >> 1)) / c->chrDstW;
1478  int64_t chrYInc = (((int64_t)c->chrSrcH << 16) + (c->chrDstH >> 1)) / c->chrDstH;
1479 
1480  /* Match pixel 0 of the src to pixel 0 of dst and match pixel n-2 of src
1481  * to pixel n-2 of dst, but only for the FAST_BILINEAR mode otherwise do
1482  * correct scaling.
1483  * n-2 is the last chrominance sample available.
1484  * This is not perfect, but no one should notice the difference, the more
1485  * correct variant would be like the vertical one, but that would require
1486  * some special code for the first and last pixel */
1487  if (flags & SWS_FAST_BILINEAR) {
1488  if (c->canMMXEXTBeUsed) {
1489  lumXInc += 1;
1490  chrXInc += 1;
1491  }
1492  // we don't use the x86 asm scaler if MMX is available
1493  else if (INLINE_MMX(cpu_flags) && c->dstBpc <= 14) {
1494  lumXInc = ((int64_t)(srcW - 2) << 16) / (dstW - 2) - 20;
1495  chrXInc = ((int64_t)(c->chrSrcW - 2) << 16) / (c->chrDstW - 2) - 20;
1496  }
1497  }
1498  if (chrXInc < 10 || chrXInc > INT_MAX ||
1499  chrYInc < 10 || chrYInc > INT_MAX ||
1500  lumXInc < 10 || lumXInc > INT_MAX ||
1501  lumYInc < 10 || lumYInc > INT_MAX)
1502  return AVERROR_PATCHWELCOME;
1503 
1504  c->lumXInc = lumXInc;
1505  c->lumYInc = lumYInc;
1506  c->chrXInc = chrXInc;
1507  c->chrYInc = chrYInc;
1508 
1509 
1510  // hardcoded for now
1511  c->gamma_value = 2.2;
1512  tmpFmt = AV_PIX_FMT_RGBA64LE;
1513 
1514 
1515  if (!unscaled && c->gamma_flag && (srcFormat != tmpFmt || dstFormat != tmpFmt)) {
1516  SwsContext *c2;
1517  c->cascaded_context[0] = NULL;
1518 
1519  ret = av_image_alloc(c->cascaded_tmp, c->cascaded_tmpStride,
1520  srcW, srcH, tmpFmt, 64);
1521  if (ret < 0)
1522  return ret;
1523 
1524  c->cascaded_context[0] = sws_getContext(srcW, srcH, srcFormat,
1525  srcW, srcH, tmpFmt,
1526  flags, NULL, NULL, c->param);
1527  if (!c->cascaded_context[0]) {
1528  return AVERROR(ENOMEM);
1529  }
1530 
1531  c->cascaded_context[1] = sws_getContext(srcW, srcH, tmpFmt,
1532  dstW, dstH, tmpFmt,
1533  flags, srcFilter, dstFilter, c->param);
1534 
1535  if (!c->cascaded_context[1])
1536  return AVERROR(ENOMEM);
1537 
1538  c2 = c->cascaded_context[1];
1539  c2->is_internal_gamma = 1;
1540  c2->gamma = alloc_gamma_tbl( c->gamma_value);
1541  c2->inv_gamma = alloc_gamma_tbl(1.f/c->gamma_value);
1542  if (!c2->gamma || !c2->inv_gamma)
1543  return AVERROR(ENOMEM);
1544 
1545  // is_internal_flag is set after creating the context
1546  // to properly create the gamma convert FilterDescriptor
1547  // we have to re-initialize it
1549  if ((ret = ff_init_filters(c2)) < 0) {
1551  c->cascaded_context[1] = NULL;
1552  return ret;
1553  }
1554 
1555  c->cascaded_context[2] = NULL;
1556  if (dstFormat != tmpFmt) {
1557  ret = av_image_alloc(c->cascaded1_tmp, c->cascaded1_tmpStride,
1558  dstW, dstH, tmpFmt, 64);
1559  if (ret < 0)
1560  return ret;
1561 
1562  c->cascaded_context[2] = sws_getContext(dstW, dstH, tmpFmt,
1563  dstW, dstH, dstFormat,
1564  flags, NULL, NULL, c->param);
1565  if (!c->cascaded_context[2])
1566  return AVERROR(ENOMEM);
1567  }
1568  return 0;
1569  }
1570 
1571  if (isBayer(srcFormat)) {
1572  if (!unscaled ||
1573  (dstFormat != AV_PIX_FMT_RGB24 && dstFormat != AV_PIX_FMT_YUV420P &&
1574  dstFormat != AV_PIX_FMT_RGB48)) {
1575  enum AVPixelFormat tmpFormat = isBayer16BPS(srcFormat) ? AV_PIX_FMT_RGB48 : AV_PIX_FMT_RGB24;
1576 
1577  ret = av_image_alloc(c->cascaded_tmp, c->cascaded_tmpStride,
1578  srcW, srcH, tmpFormat, 64);
1579  if (ret < 0)
1580  return ret;
1581 
1582  c->cascaded_context[0] = sws_getContext(srcW, srcH, srcFormat,
1583  srcW, srcH, tmpFormat,
1584  flags, srcFilter, NULL, c->param);
1585  if (!c->cascaded_context[0])
1586  return AVERROR(ENOMEM);
1587 
1588  c->cascaded_context[1] = sws_getContext(srcW, srcH, tmpFormat,
1589  dstW, dstH, dstFormat,
1590  flags, NULL, dstFilter, c->param);
1591  if (!c->cascaded_context[1])
1592  return AVERROR(ENOMEM);
1593  return 0;
1594  }
1595  }
1596 
1597  if (unscaled && c->srcBpc == 8 && dstFormat == AV_PIX_FMT_GRAYF32){
1598  for (i = 0; i < 256; ++i){
1599  c->uint2float_lut[i] = (float)i * float_mult;
1600  }
1601  }
1602 
1603  // float will be converted to uint16_t
1604  if ((srcFormat == AV_PIX_FMT_GRAYF32BE || srcFormat == AV_PIX_FMT_GRAYF32LE) &&
1605  (!unscaled || unscaled && dstFormat != srcFormat && (srcFormat != AV_PIX_FMT_GRAYF32 ||
1606  dstFormat != AV_PIX_FMT_GRAY8))){
1607  c->srcBpc = 16;
1608  }
1609 
1610  if (CONFIG_SWSCALE_ALPHA && isALPHA(srcFormat) && !isALPHA(dstFormat)) {
1611  enum AVPixelFormat tmpFormat = alphaless_fmt(srcFormat);
1612 
1613  if (tmpFormat != AV_PIX_FMT_NONE && c->alphablend != SWS_ALPHA_BLEND_NONE) {
1614  if (!unscaled ||
1615  dstFormat != tmpFormat ||
1616  usesHFilter || usesVFilter ||
1617  c->srcRange != c->dstRange
1618  ) {
1619  c->cascaded_mainindex = 1;
1620  ret = av_image_alloc(c->cascaded_tmp, c->cascaded_tmpStride,
1621  srcW, srcH, tmpFormat, 64);
1622  if (ret < 0)
1623  return ret;
1624 
1625  c->cascaded_context[0] = sws_alloc_set_opts(srcW, srcH, srcFormat,
1626  srcW, srcH, tmpFormat,
1627  flags, c->param);
1628  if (!c->cascaded_context[0])
1629  return AVERROR(EINVAL);
1630  c->cascaded_context[0]->alphablend = c->alphablend;
1631  ret = sws_init_context(c->cascaded_context[0], NULL , NULL);
1632  if (ret < 0)
1633  return ret;
1634 
1635  c->cascaded_context[1] = sws_alloc_set_opts(srcW, srcH, tmpFormat,
1636  dstW, dstH, dstFormat,
1637  flags, c->param);
1638  if (!c->cascaded_context[1])
1639  return AVERROR(EINVAL);
1640 
1641  c->cascaded_context[1]->srcRange = c->srcRange;
1642  c->cascaded_context[1]->dstRange = c->dstRange;
1643  ret = sws_init_context(c->cascaded_context[1], srcFilter , dstFilter);
1644  if (ret < 0)
1645  return ret;
1646 
1647  return 0;
1648  }
1649  }
1650  }
1651 
1652 #if HAVE_MMAP && HAVE_MPROTECT && defined(MAP_ANONYMOUS)
1653 #define USE_MMAP 1
1654 #else
1655 #define USE_MMAP 0
1656 #endif
1657 
1658  /* precalculate horizontal scaler filter coefficients */
1659  {
1660 #if HAVE_MMXEXT_INLINE
1661 // can't downscale !!!
1662  if (c->canMMXEXTBeUsed && (flags & SWS_FAST_BILINEAR)) {
1663  c->lumMmxextFilterCodeSize = ff_init_hscaler_mmxext(dstW, c->lumXInc, NULL,
1664  NULL, NULL, 8);
1665  c->chrMmxextFilterCodeSize = ff_init_hscaler_mmxext(c->chrDstW, c->chrXInc,
1666  NULL, NULL, NULL, 4);
1667 
1668 #if USE_MMAP
1669  c->lumMmxextFilterCode = mmap(NULL, c->lumMmxextFilterCodeSize,
1670  PROT_READ | PROT_WRITE,
1671  MAP_PRIVATE | MAP_ANONYMOUS,
1672  -1, 0);
1673  c->chrMmxextFilterCode = mmap(NULL, c->chrMmxextFilterCodeSize,
1674  PROT_READ | PROT_WRITE,
1675  MAP_PRIVATE | MAP_ANONYMOUS,
1676  -1, 0);
1677 #elif HAVE_VIRTUALALLOC
1678  c->lumMmxextFilterCode = VirtualAlloc(NULL,
1679  c->lumMmxextFilterCodeSize,
1680  MEM_COMMIT,
1681  PAGE_EXECUTE_READWRITE);
1682  c->chrMmxextFilterCode = VirtualAlloc(NULL,
1683  c->chrMmxextFilterCodeSize,
1684  MEM_COMMIT,
1685  PAGE_EXECUTE_READWRITE);
1686 #else
1687  c->lumMmxextFilterCode = av_malloc(c->lumMmxextFilterCodeSize);
1688  c->chrMmxextFilterCode = av_malloc(c->chrMmxextFilterCodeSize);
1689 #endif
1690 
1691 #ifdef MAP_ANONYMOUS
1692  if (c->lumMmxextFilterCode == MAP_FAILED || c->chrMmxextFilterCode == MAP_FAILED)
1693 #else
1694  if (!c->lumMmxextFilterCode || !c->chrMmxextFilterCode)
1695 #endif
1696  {
1697  av_log(c, AV_LOG_ERROR, "Failed to allocate MMX2FilterCode\n");
1698  return AVERROR(ENOMEM);
1699  }
1700 
1701  if (!FF_ALLOCZ_TYPED_ARRAY(c->hLumFilter, dstW / 8 + 8) ||
1702  !FF_ALLOCZ_TYPED_ARRAY(c->hChrFilter, c->chrDstW / 4 + 8) ||
1703  !FF_ALLOCZ_TYPED_ARRAY(c->hLumFilterPos, dstW / 2 / 8 + 8) ||
1704  !FF_ALLOCZ_TYPED_ARRAY(c->hChrFilterPos, c->chrDstW / 2 / 4 + 8))
1705  goto nomem;
1706 
1707  ff_init_hscaler_mmxext( dstW, c->lumXInc, c->lumMmxextFilterCode,
1708  c->hLumFilter, (uint32_t*)c->hLumFilterPos, 8);
1709  ff_init_hscaler_mmxext(c->chrDstW, c->chrXInc, c->chrMmxextFilterCode,
1710  c->hChrFilter, (uint32_t*)c->hChrFilterPos, 4);
1711 
1712 #if USE_MMAP
1713  if ( mprotect(c->lumMmxextFilterCode, c->lumMmxextFilterCodeSize, PROT_EXEC | PROT_READ) == -1
1714  || mprotect(c->chrMmxextFilterCode, c->chrMmxextFilterCodeSize, PROT_EXEC | PROT_READ) == -1) {
1715  av_log(c, AV_LOG_ERROR, "mprotect failed, cannot use fast bilinear scaler\n");
1716  ret = AVERROR(EINVAL);
1717  goto fail;
1718  }
1719 #endif
1720  } else
1721 #endif /* HAVE_MMXEXT_INLINE */
1722  {
1723  const int filterAlign = X86_MMX(cpu_flags) ? 4 :
1724  PPC_ALTIVEC(cpu_flags) ? 8 :
1725  have_neon(cpu_flags) ? 8 : 1;
1726 
1727  if ((ret = initFilter(&c->hLumFilter, &c->hLumFilterPos,
1728  &c->hLumFilterSize, c->lumXInc,
1729  srcW, dstW, filterAlign, 1 << 14,
1731  cpu_flags, srcFilter->lumH, dstFilter->lumH,
1732  c->param,
1733  get_local_pos(c, 0, 0, 0),
1734  get_local_pos(c, 0, 0, 0))) < 0)
1735  goto fail;
1736  if ((ret = initFilter(&c->hChrFilter, &c->hChrFilterPos,
1737  &c->hChrFilterSize, c->chrXInc,
1738  c->chrSrcW, c->chrDstW, filterAlign, 1 << 14,
1740  cpu_flags, srcFilter->chrH, dstFilter->chrH,
1741  c->param,
1742  get_local_pos(c, c->chrSrcHSubSample, c->src_h_chr_pos, 0),
1743  get_local_pos(c, c->chrDstHSubSample, c->dst_h_chr_pos, 0))) < 0)
1744  goto fail;
1745  }
1746  } // initialize horizontal stuff
1747 
1748  /* precalculate vertical scaler filter coefficients */
1749  {
1750  const int filterAlign = X86_MMX(cpu_flags) ? 2 :
1751  PPC_ALTIVEC(cpu_flags) ? 8 :
1752  have_neon(cpu_flags) ? 2 : 1;
1753 
1754  ret = initFilter(&c->vLumFilter, &c->vLumFilterPos, &c->vLumFilterSize,
1755  c->lumYInc, srcH, dstH, filterAlign, (1 << 12),
1757  cpu_flags, srcFilter->lumV, dstFilter->lumV,
1758  c->param,
1759  get_local_pos(c, 0, 0, 1),
1760  get_local_pos(c, 0, 0, 1));
1761  int usecascade = (ret == RETCODE_USE_CASCADE);
1762  if (ret < 0 && !usecascade)
1763  goto fail;
1764  if ((ret = initFilter(&c->vChrFilter, &c->vChrFilterPos, &c->vChrFilterSize,
1765  c->chrYInc, c->chrSrcH, c->chrDstH,
1766  filterAlign, (1 << 12),
1768  cpu_flags, srcFilter->chrV, dstFilter->chrV,
1769  c->param,
1770  get_local_pos(c, c->chrSrcVSubSample, c->src_v_chr_pos, 1),
1771  get_local_pos(c, c->chrDstVSubSample, c->dst_v_chr_pos, 1))) < 0)
1772 
1773  goto fail;
1774  if (usecascade) {
1775  ret = RETCODE_USE_CASCADE;
1776  goto fail;
1777  }
1778 
1779 #if HAVE_ALTIVEC
1780  c->vYCoeffsBank = av_malloc_array(c->dstH, c->vLumFilterSize * sizeof(*c->vYCoeffsBank));
1781  c->vCCoeffsBank = av_malloc_array(c->chrDstH, c->vChrFilterSize * sizeof(*c->vCCoeffsBank));
1782  if (c->vYCoeffsBank == NULL || c->vCCoeffsBank == NULL)
1783  goto nomem;
1784 
1785  for (i = 0; i < c->vLumFilterSize * c->dstH; i++) {
1786  int j;
1787  short *p = (short *)&c->vYCoeffsBank[i];
1788  for (j = 0; j < 8; j++)
1789  p[j] = c->vLumFilter[i];
1790  }
1791 
1792  for (i = 0; i < c->vChrFilterSize * c->chrDstH; i++) {
1793  int j;
1794  short *p = (short *)&c->vCCoeffsBank[i];
1795  for (j = 0; j < 8; j++)
1796  p[j] = c->vChrFilter[i];
1797  }
1798 #endif
1799  }
1800 
1801  for (i = 0; i < 4; i++)
1802  if (!FF_ALLOCZ_TYPED_ARRAY(c->dither_error[i], c->dstW + 3))
1803  goto nomem;
1804 
1805  c->needAlpha = (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat) && isALPHA(c->dstFormat)) ? 1 : 0;
1806 
1807  // 64 / c->scalingBpp is the same as 16 / sizeof(scaling_intermediate)
1808  c->uv_off = (dst_stride>>1) + 64 / (c->dstBpc &~ 7);
1809  c->uv_offx2 = dst_stride + 16;
1810 
1811  av_assert0(c->chrDstH <= dstH);
1812 
1813  if (flags & SWS_PRINT_INFO) {
1814  const char *scaler = NULL, *cpucaps;
1815 
1816  for (i = 0; i < FF_ARRAY_ELEMS(scale_algorithms); i++) {
1817  if (flags & scale_algorithms[i].flag) {
1818  scaler = scale_algorithms[i].description;
1819  break;
1820  }
1821  }
1822  if (!scaler)
1823  scaler = "ehh flags invalid?!";
1824  av_log(c, AV_LOG_INFO, "%s scaler, from %s to %s%s ",
1825  scaler,
1826  av_get_pix_fmt_name(srcFormat),
1827 #ifdef DITHER1XBPP
1828  dstFormat == AV_PIX_FMT_BGR555 || dstFormat == AV_PIX_FMT_BGR565 ||
1829  dstFormat == AV_PIX_FMT_RGB444BE || dstFormat == AV_PIX_FMT_RGB444LE ||
1830  dstFormat == AV_PIX_FMT_BGR444BE || dstFormat == AV_PIX_FMT_BGR444LE ?
1831  "dithered " : "",
1832 #else
1833  "",
1834 #endif
1835  av_get_pix_fmt_name(dstFormat));
1836 
1837  if (INLINE_MMXEXT(cpu_flags))
1838  cpucaps = "MMXEXT";
1839  else if (INLINE_AMD3DNOW(cpu_flags))
1840  cpucaps = "3DNOW";
1841  else if (INLINE_MMX(cpu_flags))
1842  cpucaps = "MMX";
1843  else if (PPC_ALTIVEC(cpu_flags))
1844  cpucaps = "AltiVec";
1845  else
1846  cpucaps = "C";
1847 
1848  av_log(c, AV_LOG_INFO, "using %s\n", cpucaps);
1849 
1850  av_log(c, AV_LOG_VERBOSE, "%dx%d -> %dx%d\n", srcW, srcH, dstW, dstH);
1852  "lum srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n",
1853  c->srcW, c->srcH, c->dstW, c->dstH, c->lumXInc, c->lumYInc);
1855  "chr srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n",
1856  c->chrSrcW, c->chrSrcH, c->chrDstW, c->chrDstH,
1857  c->chrXInc, c->chrYInc);
1858  }
1859 
1860  /* alpha blend special case, note this has been split via cascaded contexts if its scaled */
1861  if (unscaled && !usesHFilter && !usesVFilter &&
1862  c->alphablend != SWS_ALPHA_BLEND_NONE &&
1863  isALPHA(srcFormat) &&
1864  (c->srcRange == c->dstRange || isAnyRGB(dstFormat)) &&
1865  alphaless_fmt(srcFormat) == dstFormat
1866  ) {
1867  c->swscale = ff_sws_alphablendaway;
1868 
1869  if (flags & SWS_PRINT_INFO)
1870  av_log(c, AV_LOG_INFO,
1871  "using alpha blendaway %s -> %s special converter\n",
1872  av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat));
1873  return 0;
1874  }
1875 
1876  /* unscaled special cases */
1877  if (unscaled && !usesHFilter && !usesVFilter &&
1878  (c->srcRange == c->dstRange || isAnyRGB(dstFormat) ||
1879  isFloat(srcFormat) || isFloat(dstFormat) || isBayer(srcFormat))){
1881 
1882  if (c->swscale) {
1883  if (flags & SWS_PRINT_INFO)
1884  av_log(c, AV_LOG_INFO,
1885  "using unscaled %s -> %s special converter\n",
1886  av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat));
1887  return 0;
1888  }
1889  }
1890 
1891  c->swscale = ff_getSwsFunc(c);
1892  return ff_init_filters(c);
1893 nomem:
1894  ret = AVERROR(ENOMEM);
1895 fail: // FIXME replace things by appropriate error codes
1896  if (ret == RETCODE_USE_CASCADE) {
1897  int tmpW = sqrt(srcW * (int64_t)dstW);
1898  int tmpH = sqrt(srcH * (int64_t)dstH);
1899  enum AVPixelFormat tmpFormat = AV_PIX_FMT_YUV420P;
1900 
1901  if (isALPHA(srcFormat))
1902  tmpFormat = AV_PIX_FMT_YUVA420P;
1903 
1904  if (srcW*(int64_t)srcH <= 4LL*dstW*dstH)
1905  return AVERROR(EINVAL);
1906 
1907  ret = av_image_alloc(c->cascaded_tmp, c->cascaded_tmpStride,
1908  tmpW, tmpH, tmpFormat, 64);
1909  if (ret < 0)
1910  return ret;
1911 
1912  c->cascaded_context[0] = sws_getContext(srcW, srcH, srcFormat,
1913  tmpW, tmpH, tmpFormat,
1914  flags, srcFilter, NULL, c->param);
1915  if (!c->cascaded_context[0])
1916  return AVERROR(ENOMEM);
1917 
1918  c->cascaded_context[1] = sws_getContext(tmpW, tmpH, tmpFormat,
1919  dstW, dstH, dstFormat,
1920  flags, NULL, dstFilter, c->param);
1921  if (!c->cascaded_context[1])
1922  return AVERROR(ENOMEM);
1923  return 0;
1924  }
1925  return ret;
1926 }
1927 
1928 SwsContext *sws_alloc_set_opts(int srcW, int srcH, enum AVPixelFormat srcFormat,
1929  int dstW, int dstH, enum AVPixelFormat dstFormat,
1930  int flags, const double *param)
1931 {
1932  SwsContext *c;
1933 
1934  if (!(c = sws_alloc_context()))
1935  return NULL;
1936 
1937  c->flags = flags;
1938  c->srcW = srcW;
1939  c->srcH = srcH;
1940  c->dstW = dstW;
1941  c->dstH = dstH;
1942  c->srcFormat = srcFormat;
1943  c->dstFormat = dstFormat;
1944 
1945  if (param) {
1946  c->param[0] = param[0];
1947  c->param[1] = param[1];
1948  }
1949 
1950  return c;
1951 }
1952 
1953 SwsContext *sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat,
1954  int dstW, int dstH, enum AVPixelFormat dstFormat,
1955  int flags, SwsFilter *srcFilter,
1956  SwsFilter *dstFilter, const double *param)
1957 {
1958  SwsContext *c;
1959 
1960  c = sws_alloc_set_opts(srcW, srcH, srcFormat,
1961  dstW, dstH, dstFormat,
1962  flags, param);
1963  if (!c)
1964  return NULL;
1965 
1966  if (sws_init_context(c, srcFilter, dstFilter) < 0) {
1967  sws_freeContext(c);
1968  return NULL;
1969  }
1970 
1971  return c;
1972 }
1973 
1974 static int isnan_vec(SwsVector *a)
1975 {
1976  int i;
1977  for (i=0; i<a->length; i++)
1978  if (isnan(a->coeff[i]))
1979  return 1;
1980  return 0;
1981 }
1982 
1983 static void makenan_vec(SwsVector *a)
1984 {
1985  int i;
1986  for (i=0; i<a->length; i++)
1987  a->coeff[i] = NAN;
1988 }
1989 
1990 SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,
1991  float lumaSharpen, float chromaSharpen,
1992  float chromaHShift, float chromaVShift,
1993  int verbose)
1994 {
1995  SwsFilter *filter = av_malloc(sizeof(SwsFilter));
1996  if (!filter)
1997  return NULL;
1998 
1999  if (lumaGBlur != 0.0) {
2000  filter->lumH = sws_getGaussianVec(lumaGBlur, 3.0);
2001  filter->lumV = sws_getGaussianVec(lumaGBlur, 3.0);
2002  } else {
2003  filter->lumH = sws_getIdentityVec();
2004  filter->lumV = sws_getIdentityVec();
2005  }
2006 
2007  if (chromaGBlur != 0.0) {
2008  filter->chrH = sws_getGaussianVec(chromaGBlur, 3.0);
2009  filter->chrV = sws_getGaussianVec(chromaGBlur, 3.0);
2010  } else {
2011  filter->chrH = sws_getIdentityVec();
2012  filter->chrV = sws_getIdentityVec();
2013  }
2014 
2015  if (!filter->lumH || !filter->lumV || !filter->chrH || !filter->chrV)
2016  goto fail;
2017 
2018  if (chromaSharpen != 0.0) {
2019  SwsVector *id = sws_getIdentityVec();
2020  if (!id)
2021  goto fail;
2022  sws_scaleVec(filter->chrH, -chromaSharpen);
2023  sws_scaleVec(filter->chrV, -chromaSharpen);
2024  sws_addVec(filter->chrH, id);
2025  sws_addVec(filter->chrV, id);
2026  sws_freeVec(id);
2027  }
2028 
2029  if (lumaSharpen != 0.0) {
2030  SwsVector *id = sws_getIdentityVec();
2031  if (!id)
2032  goto fail;
2033  sws_scaleVec(filter->lumH, -lumaSharpen);
2034  sws_scaleVec(filter->lumV, -lumaSharpen);
2035  sws_addVec(filter->lumH, id);
2036  sws_addVec(filter->lumV, id);
2037  sws_freeVec(id);
2038  }
2039 
2040  if (chromaHShift != 0.0)
2041  sws_shiftVec(filter->chrH, (int)(chromaHShift + 0.5));
2042 
2043  if (chromaVShift != 0.0)
2044  sws_shiftVec(filter->chrV, (int)(chromaVShift + 0.5));
2045 
2046  sws_normalizeVec(filter->chrH, 1.0);
2047  sws_normalizeVec(filter->chrV, 1.0);
2048  sws_normalizeVec(filter->lumH, 1.0);
2049  sws_normalizeVec(filter->lumV, 1.0);
2050 
2051  if (isnan_vec(filter->chrH) ||
2052  isnan_vec(filter->chrV) ||
2053  isnan_vec(filter->lumH) ||
2054  isnan_vec(filter->lumV))
2055  goto fail;
2056 
2057  if (verbose)
2059  if (verbose)
2061 
2062  return filter;
2063 
2064 fail:
2065  sws_freeVec(filter->lumH);
2066  sws_freeVec(filter->lumV);
2067  sws_freeVec(filter->chrH);
2068  sws_freeVec(filter->chrV);
2069  av_freep(&filter);
2070  return NULL;
2071 }
2072 
2074 {
2075  SwsVector *vec;
2076 
2077  if(length <= 0 || length > INT_MAX/ sizeof(double))
2078  return NULL;
2079 
2080  vec = av_malloc(sizeof(SwsVector));
2081  if (!vec)
2082  return NULL;
2083  vec->length = length;
2084  vec->coeff = av_malloc(sizeof(double) * length);
2085  if (!vec->coeff)
2086  av_freep(&vec);
2087  return vec;
2088 }
2089 
2090 SwsVector *sws_getGaussianVec(double variance, double quality)
2091 {
2092  const int length = (int)(variance * quality + 0.5) | 1;
2093  int i;
2094  double middle = (length - 1) * 0.5;
2095  SwsVector *vec;
2096 
2097  if(variance < 0 || quality < 0)
2098  return NULL;
2099 
2100  vec = sws_allocVec(length);
2101 
2102  if (!vec)
2103  return NULL;
2104 
2105  for (i = 0; i < length; i++) {
2106  double dist = i - middle;
2107  vec->coeff[i] = exp(-dist * dist / (2 * variance * variance)) /
2108  sqrt(2 * variance * M_PI);
2109  }
2110 
2111  sws_normalizeVec(vec, 1.0);
2112 
2113  return vec;
2114 }
2115 
2116 /**
2117  * Allocate and return a vector with length coefficients, all
2118  * with the same value c.
2119  */
2120 #if !FF_API_SWS_VECTOR
2121 static
2122 #endif
2123 SwsVector *sws_getConstVec(double c, int length)
2124 {
2125  int i;
2126  SwsVector *vec = sws_allocVec(length);
2127 
2128  if (!vec)
2129  return NULL;
2130 
2131  for (i = 0; i < length; i++)
2132  vec->coeff[i] = c;
2133 
2134  return vec;
2135 }
2136 
2137 /**
2138  * Allocate and return a vector with just one coefficient, with
2139  * value 1.0.
2140  */
2141 #if !FF_API_SWS_VECTOR
2142 static
2143 #endif
2145 {
2146  return sws_getConstVec(1.0, 1);
2147 }
2148 
2149 static double sws_dcVec(SwsVector *a)
2150 {
2151  int i;
2152  double sum = 0;
2153 
2154  for (i = 0; i < a->length; i++)
2155  sum += a->coeff[i];
2156 
2157  return sum;
2158 }
2159 
2160 void sws_scaleVec(SwsVector *a, double scalar)
2161 {
2162  int i;
2163 
2164  for (i = 0; i < a->length; i++)
2165  a->coeff[i] *= scalar;
2166 }
2167 
2169 {
2171 }
2172 
2173 #if FF_API_SWS_VECTOR
2175 {
2176  int length = a->length + b->length - 1;
2177  int i, j;
2178  SwsVector *vec = sws_getConstVec(0.0, length);
2179 
2180  if (!vec)
2181  return NULL;
2182 
2183  for (i = 0; i < a->length; i++) {
2184  for (j = 0; j < b->length; j++) {
2185  vec->coeff[i + j] += a->coeff[i] * b->coeff[j];
2186  }
2187  }
2188 
2189  return vec;
2190 }
2191 #endif
2192 
2194 {
2195  int length = FFMAX(a->length, b->length);
2196  int i;
2197  SwsVector *vec = sws_getConstVec(0.0, length);
2198 
2199  if (!vec)
2200  return NULL;
2201 
2202  for (i = 0; i < a->length; i++)
2203  vec->coeff[i + (length - 1) / 2 - (a->length - 1) / 2] += a->coeff[i];
2204  for (i = 0; i < b->length; i++)
2205  vec->coeff[i + (length - 1) / 2 - (b->length - 1) / 2] += b->coeff[i];
2206 
2207  return vec;
2208 }
2209 
2210 #if FF_API_SWS_VECTOR
2212 {
2213  int length = FFMAX(a->length, b->length);
2214  int i;
2215  SwsVector *vec = sws_getConstVec(0.0, length);
2216 
2217  if (!vec)
2218  return NULL;
2219 
2220  for (i = 0; i < a->length; i++)
2221  vec->coeff[i + (length - 1) / 2 - (a->length - 1) / 2] += a->coeff[i];
2222  for (i = 0; i < b->length; i++)
2223  vec->coeff[i + (length - 1) / 2 - (b->length - 1) / 2] -= b->coeff[i];
2224 
2225  return vec;
2226 }
2227 #endif
2228 
2229 /* shift left / or right if "shift" is negative */
2231 {
2232  int length = a->length + FFABS(shift) * 2;
2233  int i;
2234  SwsVector *vec = sws_getConstVec(0.0, length);
2235 
2236  if (!vec)
2237  return NULL;
2238 
2239  for (i = 0; i < a->length; i++) {
2240  vec->coeff[i + (length - 1) / 2 -
2241  (a->length - 1) / 2 - shift] = a->coeff[i];
2242  }
2243 
2244  return vec;
2245 }
2246 
2247 #if !FF_API_SWS_VECTOR
2248 static
2249 #endif
2251 {
2252  SwsVector *shifted = sws_getShiftedVec(a, shift);
2253  if (!shifted) {
2254  makenan_vec(a);
2255  return;
2256  }
2257  av_free(a->coeff);
2258  a->coeff = shifted->coeff;
2259  a->length = shifted->length;
2260  av_free(shifted);
2261 }
2262 
2263 #if !FF_API_SWS_VECTOR
2264 static
2265 #endif
2267 {
2268  SwsVector *sum = sws_sumVec(a, b);
2269  if (!sum) {
2270  makenan_vec(a);
2271  return;
2272  }
2273  av_free(a->coeff);
2274  a->coeff = sum->coeff;
2275  a->length = sum->length;
2276  av_free(sum);
2277 }
2278 
2279 #if FF_API_SWS_VECTOR
2281 {
2282  SwsVector *diff = sws_diffVec(a, b);
2283  if (!diff) {
2284  makenan_vec(a);
2285  return;
2286  }
2287  av_free(a->coeff);
2288  a->coeff = diff->coeff;
2289  a->length = diff->length;
2290  av_free(diff);
2291 }
2292 
2294 {
2296  if (!conv) {
2297  makenan_vec(a);
2298  return;
2299  }
2300  av_free(a->coeff);
2301  a->coeff = conv->coeff;
2302  a->length = conv->length;
2303  av_free(conv);
2304 }
2305 
2307 {
2308  SwsVector *vec = sws_allocVec(a->length);
2309 
2310  if (!vec)
2311  return NULL;
2312 
2313  memcpy(vec->coeff, a->coeff, a->length * sizeof(*a->coeff));
2314 
2315  return vec;
2316 }
2317 #endif
2318 
2319 /**
2320  * Print with av_log() a textual representation of the vector a
2321  * if log_level <= av_log_level.
2322  */
2323 #if !FF_API_SWS_VECTOR
2324 static
2325 #endif
2326 void sws_printVec2(SwsVector *a, AVClass *log_ctx, int log_level)
2327 {
2328  int i;
2329  double max = 0;
2330  double min = 0;
2331  double range;
2332 
2333  for (i = 0; i < a->length; i++)
2334  if (a->coeff[i] > max)
2335  max = a->coeff[i];
2336 
2337  for (i = 0; i < a->length; i++)
2338  if (a->coeff[i] < min)
2339  min = a->coeff[i];
2340 
2341  range = max - min;
2342 
2343  for (i = 0; i < a->length; i++) {
2344  int x = (int)((a->coeff[i] - min) * 60.0 / range + 0.5);
2345  av_log(log_ctx, log_level, "%1.3f ", a->coeff[i]);
2346  for (; x > 0; x--)
2347  av_log(log_ctx, log_level, " ");
2348  av_log(log_ctx, log_level, "|\n");
2349  }
2350 }
2351 
2353 {
2354  if (!a)
2355  return;
2356  av_freep(&a->coeff);
2357  a->length = 0;
2358  av_free(a);
2359 }
2360 
2362 {
2363  if (!filter)
2364  return;
2365 
2366  sws_freeVec(filter->lumH);
2367  sws_freeVec(filter->lumV);
2368  sws_freeVec(filter->chrH);
2369  sws_freeVec(filter->chrV);
2370  av_free(filter);
2371 }
2372 
2374 {
2375  int i;
2376  if (!c)
2377  return;
2378 
2379  for (i = 0; i < 4; i++)
2380  av_freep(&c->dither_error[i]);
2381 
2382  av_freep(&c->vLumFilter);
2383  av_freep(&c->vChrFilter);
2384  av_freep(&c->hLumFilter);
2385  av_freep(&c->hChrFilter);
2386 #if HAVE_ALTIVEC
2387  av_freep(&c->vYCoeffsBank);
2388  av_freep(&c->vCCoeffsBank);
2389 #endif
2390 
2391  av_freep(&c->vLumFilterPos);
2392  av_freep(&c->vChrFilterPos);
2393  av_freep(&c->hLumFilterPos);
2394  av_freep(&c->hChrFilterPos);
2395 
2396 #if HAVE_MMX_INLINE
2397 #if USE_MMAP
2398  if (c->lumMmxextFilterCode)
2399  munmap(c->lumMmxextFilterCode, c->lumMmxextFilterCodeSize);
2400  if (c->chrMmxextFilterCode)
2401  munmap(c->chrMmxextFilterCode, c->chrMmxextFilterCodeSize);
2402 #elif HAVE_VIRTUALALLOC
2403  if (c->lumMmxextFilterCode)
2404  VirtualFree(c->lumMmxextFilterCode, 0, MEM_RELEASE);
2405  if (c->chrMmxextFilterCode)
2406  VirtualFree(c->chrMmxextFilterCode, 0, MEM_RELEASE);
2407 #else
2408  av_free(c->lumMmxextFilterCode);
2409  av_free(c->chrMmxextFilterCode);
2410 #endif
2411  c->lumMmxextFilterCode = NULL;
2412  c->chrMmxextFilterCode = NULL;
2413 #endif /* HAVE_MMX_INLINE */
2414 
2415  av_freep(&c->yuvTable);
2416  av_freep(&c->formatConvBuffer);
2417 
2418  sws_freeContext(c->cascaded_context[0]);
2419  sws_freeContext(c->cascaded_context[1]);
2420  sws_freeContext(c->cascaded_context[2]);
2421  memset(c->cascaded_context, 0, sizeof(c->cascaded_context));
2422  av_freep(&c->cascaded_tmp[0]);
2423  av_freep(&c->cascaded1_tmp[0]);
2424 
2425  av_freep(&c->gamma);
2426  av_freep(&c->inv_gamma);
2427 
2428  ff_free_filters(c);
2429 
2430  av_free(c);
2431 }
2432 
2433 struct SwsContext *sws_getCachedContext(struct SwsContext *context, int srcW,
2434  int srcH, enum AVPixelFormat srcFormat,
2435  int dstW, int dstH,
2436  enum AVPixelFormat dstFormat, int flags,
2437  SwsFilter *srcFilter,
2438  SwsFilter *dstFilter,
2439  const double *param)
2440 {
2441  static const double default_param[2] = { SWS_PARAM_DEFAULT,
2443  int64_t src_h_chr_pos = -513, dst_h_chr_pos = -513,
2444  src_v_chr_pos = -513, dst_v_chr_pos = -513;
2445 
2446  if (!param)
2447  param = default_param;
2448 
2449  if (context &&
2450  (context->srcW != srcW ||
2451  context->srcH != srcH ||
2452  context->srcFormat != srcFormat ||
2453  context->dstW != dstW ||
2454  context->dstH != dstH ||
2455  context->dstFormat != dstFormat ||
2456  context->flags != flags ||
2457  context->param[0] != param[0] ||
2458  context->param[1] != param[1])) {
2459 
2460  av_opt_get_int(context, "src_h_chr_pos", 0, &src_h_chr_pos);
2461  av_opt_get_int(context, "src_v_chr_pos", 0, &src_v_chr_pos);
2462  av_opt_get_int(context, "dst_h_chr_pos", 0, &dst_h_chr_pos);
2463  av_opt_get_int(context, "dst_v_chr_pos", 0, &dst_v_chr_pos);
2464  sws_freeContext(context);
2465  context = NULL;
2466  }
2467 
2468  if (!context) {
2469  if (!(context = sws_alloc_context()))
2470  return NULL;
2471  context->srcW = srcW;
2472  context->srcH = srcH;
2473  context->srcFormat = srcFormat;
2474  context->dstW = dstW;
2475  context->dstH = dstH;
2476  context->dstFormat = dstFormat;
2477  context->flags = flags;
2478  context->param[0] = param[0];
2479  context->param[1] = param[1];
2480 
2481  av_opt_set_int(context, "src_h_chr_pos", src_h_chr_pos, 0);
2482  av_opt_set_int(context, "src_v_chr_pos", src_v_chr_pos, 0);
2483  av_opt_set_int(context, "dst_h_chr_pos", dst_h_chr_pos, 0);
2484  av_opt_set_int(context, "dst_v_chr_pos", dst_v_chr_pos, 0);
2485 
2486  if (sws_init_context(context, srcFilter, dstFilter) < 0) {
2487  sws_freeContext(context);
2488  return NULL;
2489  }
2490  }
2491  return context;
2492 }
#define have_neon(flags)
Definition: cpu.h:26
static const char *const format[]
Definition: af_aiir.c:457
#define MAX_FILTER_SIZE
Definition: af_dynaudnorm.c:33
int ff_sws_alphablendaway(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
Definition: alphablend.c:23
#define A(x)
Definition: vp56_arith.h:28
Macro definitions for various function/variable attributes.
#define av_cold
Definition: attributes.h:88
uint8_t
int32_t
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:64
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
#define V
Definition: avdct.c:30
Convenience header that includes libavutil's core.
byte swapping routines
#define flag(name)
Definition: cbs_av1.c:564
#define flags(name, subs,...)
Definition: cbs_av1.c:572
#define ub(width, name)
Definition: cbs_h2645.c:276
#define s(width, name)
Definition: cbs_vp9.c:257
static av_always_inline void filter(int16_t *output, ptrdiff_t out_stride, const int16_t *low, ptrdiff_t low_stride, const int16_t *high, ptrdiff_t high_stride, int len, int clip)
Definition: cfhddsp.c:27
int verbose
Definition: checkasm.c:285
#define fail()
Definition: checkasm.h:133
#define FFMIN(a, b)
Definition: common.h:105
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
#define ROUNDED_DIV(a, b)
Definition: common.h:56
#define FFMAX(a, b)
Definition: common.h:103
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
#define FFMPEG_CONFIGURATION
Definition: config.h:4
#define ARCH_PPC
Definition: config.h:30
#define CONFIG_SWSCALE_ALPHA
Definition: config.h:568
#define FFMPEG_LICENSE
Definition: config.h:5
#define HAVE_MMX
Definition: config.h:65
#define NULL
Definition: coverity.c:32
long long int64_t
Definition: coverity.c:34
static atomic_int cpu_flags
Definition: cpu.c:50
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:95
#define AV_CPU_FLAG_MMX
standard MMX
Definition: cpu.h:31
static __device__ float ceil(float a)
Definition: cuda_runtime.h:176
#define max(a, b)
Definition: cuda_runtime.h:33
static enum AVPixelFormat pix_fmt
int8_t exp
Definition: eval.c:74
int
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:1368
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
#define AVERROR(e)
Definition: error.h:43
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:215
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:210
#define AV_LOG_INFO
Standard information.
Definition: log.h:205
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:237
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:245
int av_image_alloc(uint8_t *pointers[4], int linesizes[4], int w, int h, enum AVPixelFormat pix_fmt, int align)
Allocate an image with size w and h and pixel format pix_fmt, and fill pointers and linesizes accordi...
Definition: imgutils.c:219
int av_image_check_size2(unsigned int w, unsigned int h, int64_t max_pixels, enum AVPixelFormat pix_fmt, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of a plane of an image with...
Definition: imgutils.c:291
#define SWS_BITEXACT
Definition: swscale.h:84
void sws_subVec(SwsVector *a, SwsVector *b)
Definition: utils.c:2280
#define SWS_BICUBIC
Definition: swscale.h:60
int sws_getColorspaceDetails(struct SwsContext *c, int **inv_table, int *srcRange, int **table, int *dstRange, int *brightness, int *contrast, int *saturation)
Definition: utils.c:1017
void sws_freeFilter(SwsFilter *filter)
Definition: utils.c:2361
void sws_addVec(SwsVector *a, SwsVector *b)
Definition: utils.c:2266
#define SWS_CS_DEFAULT
Definition: swscale.h:95
av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter)
Initialize the swscaler context sws_context.
Definition: utils.c:1189
SwsVector * sws_getGaussianVec(double variance, double quality)
Return a normalized Gaussian curve used to filter stuff quality = 3 is high quality,...
Definition: utils.c:2090
#define SWS_BILINEAR
Definition: swscale.h:59
#define SWS_ACCURATE_RND
Definition: swscale.h:83
void sws_shiftVec(SwsVector *a, int shift)
Definition: utils.c:2250
#define SWS_SRC_V_CHR_DROP_MASK
Definition: swscale.h:70
#define SWS_FULL_CHR_H_INT
Definition: swscale.h:79
#define SWS_FULL_CHR_H_INP
Definition: swscale.h:81
#define SWS_PRINT_INFO
Definition: swscale.h:75
SwsVector * sws_getConstVec(double c, int length)
Allocate and return a vector with length coefficients, all with the same value c.
Definition: utils.c:2123
int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4], int srcRange, const int table[4], int dstRange, int brightness, int contrast, int saturation)
Definition: utils.c:882
void sws_freeVec(SwsVector *a)
Definition: utils.c:2352
SwsVector * sws_cloneVec(SwsVector *a)
Definition: utils.c:2306
#define SWS_X
Definition: swscale.h:61
#define SWS_FAST_BILINEAR
Definition: swscale.h:58
int sws_isSupportedEndiannessConversion(enum AVPixelFormat pix_fmt)
Definition: utils.c:290
int sws_isSupportedOutput(enum AVPixelFormat pix_fmt)
Return a positive value if pix_fmt is a supported output format, 0 otherwise.
Definition: utils.c:284
#define SWS_GAUSS
Definition: swscale.h:65
#define SWS_AREA
Definition: swscale.h:63
#define SWS_SRC_V_CHR_DROP_SHIFT
Definition: swscale.h:71
#define SWS_SINC
Definition: swscale.h:66
SwsVector * sws_allocVec(int length)
Allocate and return an uninitialized vector with length coefficients.
Definition: utils.c:2073
#define SWS_BICUBLIN
Definition: swscale.h:64
void sws_printVec2(SwsVector *a, AVClass *log_ctx, int log_level)
Print with av_log() a textual representation of the vector a if log_level <= av_log_level.
Definition: utils.c:2326
#define SWS_ERROR_DIFFUSION
Definition: swscale.h:85
void sws_convVec(SwsVector *a, SwsVector *b)
Definition: utils.c:2293
SwsVector * sws_getIdentityVec(void)
Allocate and return a vector with just one coefficient, with value 1.0.
Definition: utils.c:2144
const char * swscale_license(void)
Return the libswscale license.
Definition: utils.c:87
#define SWS_POINT
Definition: swscale.h:62
#define SWS_LANCZOS
Definition: swscale.h:67
const char * swscale_configuration(void)
Return the libswscale build-time configuration.
Definition: utils.c:82
void sws_normalizeVec(SwsVector *a, double height)
Scale all the coefficients of a so that their sum equals height.
Definition: utils.c:2168
int sws_isSupportedInput(enum AVPixelFormat pix_fmt)
Return a positive value if pix_fmt is a supported input format, 0 otherwise.
Definition: utils.c:278
SwsFilter * sws_getDefaultFilter(float lumaGBlur, float chromaGBlur, float lumaSharpen, float chromaSharpen, float chromaHShift, float chromaVShift, int verbose)
Definition: utils.c:1990
SwsContext * sws_alloc_context(void)
Allocate an empty SwsContext.
Definition: utils.c:1103
unsigned swscale_version(void)
Definition: utils.c:76
#define SWS_MAX_REDUCE_CUTOFF
Definition: swscale.h:87
void sws_freeContext(SwsContext *c)
Free the swscaler context swsContext.
Definition: utils.c:2373
#define SWS_PARAM_DEFAULT
Definition: swscale.h:73
struct SwsContext * sws_getCachedContext(struct SwsContext *context, int srcW, int srcH, enum AVPixelFormat srcFormat, int dstW, int dstH, enum AVPixelFormat dstFormat, int flags, SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param)
Check if context can be reused, otherwise reallocate a new one.
Definition: utils.c:2433
SwsContext * sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat, int dstW, int dstH, enum AVPixelFormat dstFormat, int flags, SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param)
Allocate and return an SwsContext.
Definition: utils.c:1953
void sws_scaleVec(SwsVector *a, double scalar)
Scale all the coefficients of a by the scalar value.
Definition: utils.c:2160
#define SWS_SPLINE
Definition: swscale.h:68
int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
Definition: opt.c:922
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition: opt.c:596
for(j=16;j >0;--j)
#define B
Definition: huffyuvdsp.h:32
const VDPAUPixFmtMap * map
misc image utilities
int i
Definition: input.c:407
#define av_log2
Definition: intmath.h:83
#define AV_WL16(p, v)
Definition: intreadwrite.h:412
#define C
#define FF_ALLOC_TYPED_ARRAY(p, nelem)
Definition: internal.h:102
#define emms_c()
Definition: internal.h:54
#define FF_ALLOCZ_TYPED_ARRAY(p, nelem)
Definition: internal.h:103
#define AVOnce
Definition: thread.h:172
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:175
#define AV_ONCE_INIT
Definition: thread.h:173
Replacements for frequently missing libm functions.
#define isnan(x)
Definition: libm.h:340
#define exp2(x)
Definition: libm.h:288
const AVClass ff_sws_context_class
Definition: options.c:87
static int handle_0alpha(enum AVPixelFormat *format)
Definition: utils.c:1073
static int handle_xyz(enum AVPixelFormat *format)
Definition: utils.c:1084
static void fill_xyztables(struct SwsContext *c)
Definition: utils.c:841
static enum AVPixelFormat alphaless_fmt(enum AVPixelFormat fmt)
Definition: utils.c:1131
SwsContext * sws_alloc_set_opts(int srcW, int srcH, enum AVPixelFormat srcFormat, int dstW, int dstH, enum AVPixelFormat dstFormat, int flags, const double *param)
Allocate and return an SwsContext.
Definition: utils.c:1928
static av_cold int initFilter(int16_t **outFilter, int32_t **filterPos, int *outFilterSize, int xInc, int srcW, int dstW, int filterAlign, int one, int flags, int cpu_flags, SwsVector *srcFilter, SwsVector *dstFilter, double param[2], int srcPos, int dstPos)
Definition: utils.c:338
static int handle_jpeg(enum AVPixelFormat *format)
Definition: utils.c:1035
static const ScaleAlgorithm scale_algorithms[]
Definition: utils.c:324
static double getSplineCoeff(double a, double b, double c, double d, double dist)
Definition: utils.c:296
static void fill_rgb2yuv_table(SwsContext *c, const int table[4], int dstRange)
Definition: utils.c:747
static SwsVector * sws_getConvVec(SwsVector *a, SwsVector *b)
Definition: utils.c:2174
static SwsVector * sws_sumVec(SwsVector *a, SwsVector *b)
Definition: utils.c:2193
static av_cold int get_local_pos(SwsContext *s, int chr_subsample, int pos, int dir)
Definition: utils.c:309
static void makenan_vec(SwsVector *a)
Definition: utils.c:1983
static void handle_formats(SwsContext *c)
Definition: utils.c:1093
static double sws_dcVec(SwsVector *a)
Definition: utils.c:2149
static int isnan_vec(SwsVector *a)
Definition: utils.c:1974
static uint16_t * alloc_gamma_tbl(double e)
Definition: utils.c:1117
static const FormatEntry format_entries[]
Definition: utils.c:99
static SwsVector * sws_getShiftedVec(SwsVector *a, int shift)
Definition: utils.c:2230
static SwsVector * sws_diffVec(SwsVector *a, SwsVector *b)
Definition: utils.c:2211
#define LICENSE_PREFIX
static int range_override_needed(enum AVPixelFormat format)
Definition: utils.c:877
#define LIBSWSCALE_VERSION_INT
Definition: version.h:33
#define LIBSWSCALE_VERSION_MICRO
Definition: version.h:31
static int conv(int samples, float **pcm, char *buf, int channels)
Definition: libvorbisdec.c:131
#define FFALIGN(x, a)
Definition: macros.h:48
#define NAN
Definition: mathematics.h:64
#define M_PI
Definition: mathematics.h:52
static const uint64_t c2
Definition: murmur3.c:52
AVOptions.
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
Definition: pixdesc.c:2601
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel used by the pixel format described by pixdesc.
Definition: pixdesc.c:2525
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2489
enum AVPixelFormat av_pix_fmt_swap_endianness(enum AVPixelFormat pix_fmt)
Utility function to swap the endianness of a pixel format.
Definition: pixdesc.c:2669
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2573
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:410
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:398
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:399
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:397
#define AV_PIX_FMT_BGR555
Definition: pixfmt.h:392
#define AV_PIX_FMT_BGR48
Definition: pixfmt.h:390
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:415
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:400
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:416
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:396
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:385
#define AV_PIX_FMT_GRAYF32
Definition: pixfmt.h:431
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
@ AV_PIX_FMT_BAYER_GBRG8
bayer, GBGB..(odd line), RGRG..(even line), 8-bit samples
Definition: pixfmt.h:262
@ AV_PIX_FMT_YUV444P16BE
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:136
@ AV_PIX_FMT_GRAY16BE
Y , 16bpp, big-endian.
Definition: pixfmt.h:97
@ AV_PIX_FMT_XYZ12LE
packed XYZ 4:4:4, 36 bpp, (msb) 12X, 12Y, 12Z (lsb), the 2-byte value for each X/Y/Z is stored as lit...
Definition: pixfmt.h:199
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:89
@ AV_PIX_FMT_YUV420P16BE
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:132
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
@ AV_PIX_FMT_P010LE
like NV12, with 10bpp per component, data in the high bits, zeros in the low bits,...
Definition: pixfmt.h:284
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
@ AV_PIX_FMT_GRAY10LE
Y , 10bpp, little-endian.
Definition: pixfmt.h:298
@ AV_PIX_FMT_GRAYF32LE
IEEE-754 single precision Y, 32bpp, little-endian.
Definition: pixfmt.h:341
@ AV_PIX_FMT_GBRP10BE
planar GBR 4:4:4 30bpp, big-endian
Definition: pixfmt.h:172
@ AV_PIX_FMT_YA16BE
16 bits gray, 16 bits alpha (big-endian)
Definition: pixfmt.h:212
@ AV_PIX_FMT_YUVA420P9BE
planar YUV 4:2:0 22.5bpp, (1 Cr & Cb sample per 2x2 Y & A samples), big-endian
Definition: pixfmt.h:178
@ AV_PIX_FMT_YUVA444P12BE
planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), 12b alpha, big-endian
Definition: pixfmt.h:345
@ AV_PIX_FMT_NV42
as above, but U and V bytes are swapped
Definition: pixfmt.h:349
@ AV_PIX_FMT_YUV420P14LE
planar YUV 4:2:0,21bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:245
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
@ AV_PIX_FMT_YUV440P10BE
planar YUV 4:4:0,20bpp, (1 Cr & Cb sample per 1x2 Y samples), big-endian
Definition: pixfmt.h:276
@ AV_PIX_FMT_NV21
as above, but U and V bytes are swapped
Definition: pixfmt.h:90
@ AV_PIX_FMT_GBRPF32BE
IEEE-754 single precision planar GBR 4:4:4, 96bpp, big-endian.
Definition: pixfmt.h:318
@ AV_PIX_FMT_MONOBLACK
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb.
Definition: pixfmt.h:76
@ AV_PIX_FMT_BGR565BE
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), big-endian
Definition: pixfmt.h:110
@ AV_PIX_FMT_YUVA422P12BE
planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), 12b alpha, big-endian
Definition: pixfmt.h:343
@ AV_PIX_FMT_YUVA444P9LE
planar YUV 4:4:4 36bpp, (1 Cr & Cb sample per 1x1 Y & A samples), little-endian
Definition: pixfmt.h:183
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition: pixfmt.h:240
@ AV_PIX_FMT_YUVA444P10LE
planar YUV 4:4:4 40bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Definition: pixfmt.h:189
@ AV_PIX_FMT_GBRP9LE
planar GBR 4:4:4 27bpp, little-endian
Definition: pixfmt.h:171
@ AV_PIX_FMT_YUV444P14BE
planar YUV 4:4:4,42bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:252
@ AV_PIX_FMT_YUVA420P10BE
planar YUV 4:2:0 25bpp, (1 Cr & Cb sample per 2x2 Y & A samples, big-endian)
Definition: pixfmt.h:184
@ AV_PIX_FMT_YUVA422P12LE
planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), 12b alpha, little-endian
Definition: pixfmt.h:344
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
@ AV_PIX_FMT_BAYER_GRBG16LE
bayer, GRGR..(odd line), BGBG..(even line), 16-bit samples, little-endian
Definition: pixfmt.h:270
@ AV_PIX_FMT_P016LE
like NV12, with 16bpp per component, little-endian
Definition: pixfmt.h:300
@ AV_PIX_FMT_P010BE
like NV12, with 10bpp per component, data in the high bits, zeros in the low bits,...
Definition: pixfmt.h:285
@ AV_PIX_FMT_AYUV64LE
packed AYUV 4:4:4,64bpp (1 Cr & Cb sample per 1x1 Y & A samples), little-endian
Definition: pixfmt.h:279
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:92
@ AV_PIX_FMT_RGB555BE
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), big-endian , X=unused/undefined
Definition: pixfmt.h:107
@ AV_PIX_FMT_YVYU422
packed YUV 4:2:2, 16bpp, Y0 Cr Y1 Cb
Definition: pixfmt.h:210
@ AV_PIX_FMT_GBRP12BE
planar GBR 4:4:4 36bpp, big-endian
Definition: pixfmt.h:254
@ AV_PIX_FMT_YUVA422P9LE
planar YUV 4:2:2 27bpp, (1 Cr & Cb sample per 2x1 Y & A samples), little-endian
Definition: pixfmt.h:181
@ AV_PIX_FMT_GRAY12LE
Y , 12bpp, little-endian.
Definition: pixfmt.h:296
@ AV_PIX_FMT_GBRAP12BE
planar GBR 4:4:4:4 48bpp, big-endian
Definition: pixfmt.h:287
@ AV_PIX_FMT_YUV420P9LE
planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:157
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:95
@ AV_PIX_FMT_GRAY12BE
Y , 12bpp, big-endian.
Definition: pixfmt.h:295
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
@ AV_PIX_FMT_BGR48BE
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:148
@ AV_PIX_FMT_YA16LE
16 bits gray, 16 bits alpha (little-endian)
Definition: pixfmt.h:213
@ AV_PIX_FMT_YUVA420P10LE
planar YUV 4:2:0 25bpp, (1 Cr & Cb sample per 2x2 Y & A samples, little-endian)
Definition: pixfmt.h:185
@ AV_PIX_FMT_GRAY14LE
Y , 14bpp, little-endian.
Definition: pixfmt.h:338
@ AV_PIX_FMT_UYVY422
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:81
@ AV_PIX_FMT_Y210LE
packed YUV 4:2:2 like YUYV422, 20bpp, data in the high bits, little-endian
Definition: pixfmt.h:359
@ AV_PIX_FMT_RGB48BE
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:102
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:94
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:101
@ AV_PIX_FMT_YUV422P10BE
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:160
@ AV_PIX_FMT_P016BE
like NV12, with 16bpp per component, big-endian
Definition: pixfmt.h:301
@ AV_PIX_FMT_YUVA422P10LE
planar YUV 4:2:2 30bpp, (1 Cr & Cb sample per 2x1 Y & A samples, little-endian)
Definition: pixfmt.h:187
@ AV_PIX_FMT_YUV420P10LE
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:159
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
Definition: pixfmt.h:100
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
@ AV_PIX_FMT_RGBA64BE
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:205
@ AV_PIX_FMT_RGB8
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
Definition: pixfmt.h:86
@ AV_PIX_FMT_NV24
planar YUV 4:4:4, 24bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:348
@ AV_PIX_FMT_RGBA64LE
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:206
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
Definition: pixfmt.h:239
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
@ AV_PIX_FMT_YUV422P16LE
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:133
@ AV_PIX_FMT_YUV420P14BE
planar YUV 4:2:0,21bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:244
@ AV_PIX_FMT_GBRAP16BE
planar GBRA 4:4:4:4 64bpp, big-endian
Definition: pixfmt.h:216
@ AV_PIX_FMT_YUV444P14LE
planar YUV 4:4:4,42bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:253
@ AV_PIX_FMT_BAYER_RGGB16LE
bayer, RGRG..(odd line), GBGB..(even line), 16-bit samples, little-endian
Definition: pixfmt.h:266
@ AV_PIX_FMT_GBRPF32LE
IEEE-754 single precision planar GBR 4:4:4, 96bpp, little-endian.
Definition: pixfmt.h:319
@ AV_PIX_FMT_YUVA444P9BE
planar YUV 4:4:4 36bpp, (1 Cr & Cb sample per 1x1 Y & A samples), big-endian
Definition: pixfmt.h:182
@ AV_PIX_FMT_YUV422P12LE
planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:247
@ AV_PIX_FMT_BGR8
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition: pixfmt.h:83
@ AV_PIX_FMT_RGB444LE
packed RGB 4:4:4, 16bpp, (msb)4X 4R 4G 4B(lsb), little-endian, X=unused/undefined
Definition: pixfmt.h:139
@ AV_PIX_FMT_YUV444P10BE
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:164
@ AV_PIX_FMT_YUV440P12LE
planar YUV 4:4:0,24bpp, (1 Cr & Cb sample per 1x2 Y samples), little-endian
Definition: pixfmt.h:277
@ AV_PIX_FMT_RGB4_BYTE
packed RGB 1:2:1, 8bpp, (msb)1R 2G 1B(lsb)
Definition: pixfmt.h:88
@ AV_PIX_FMT_BGR4_BYTE
packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb)
Definition: pixfmt.h:85
@ AV_PIX_FMT_YUVA420P9LE
planar YUV 4:2:0 22.5bpp, (1 Cr & Cb sample per 2x2 Y & A samples), little-endian
Definition: pixfmt.h:179
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
@ AV_PIX_FMT_XYZ12BE
packed XYZ 4:4:4, 36 bpp, (msb) 12X, 12Y, 12Z (lsb), the 2-byte value for each X/Y/Z is stored as big...
Definition: pixfmt.h:200
@ AV_PIX_FMT_YUV444P9LE
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:163
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:177
@ AV_PIX_FMT_BAYER_GRBG8
bayer, GRGR..(odd line), BGBG..(even line), 8-bit samples
Definition: pixfmt.h:263
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:258
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:215
@ AV_PIX_FMT_GBRP12LE
planar GBR 4:4:4 36bpp, little-endian
Definition: pixfmt.h:255
@ AV_PIX_FMT_GRAY9BE
Y , 9bpp, big-endian.
Definition: pixfmt.h:315
@ AV_PIX_FMT_YUVA444P16LE
planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Definition: pixfmt.h:195
@ AV_PIX_FMT_YUVA422P10BE
planar YUV 4:2:2 30bpp, (1 Cr & Cb sample per 2x1 Y & A samples, big-endian)
Definition: pixfmt.h:186
@ AV_PIX_FMT_UYYVYY411
packed YUV 4:1:1, 12bpp, Cb Y0 Y1 Cr Y2 Y3
Definition: pixfmt.h:82
@ AV_PIX_FMT_YUVA422P16BE
planar YUV 4:2:2 48bpp, (1 Cr & Cb sample per 2x1 Y & A samples, big-endian)
Definition: pixfmt.h:192
@ AV_PIX_FMT_BGRA64BE
packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:207
@ AV_PIX_FMT_RGB565LE
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
Definition: pixfmt.h:106
@ AV_PIX_FMT_BAYER_BGGR16BE
bayer, BGBG..(odd line), GRGR..(even line), 16-bit samples, big-endian
Definition: pixfmt.h:265
@ AV_PIX_FMT_GBRP16BE
planar GBR 4:4:4 48bpp, big-endian
Definition: pixfmt.h:174
@ AV_PIX_FMT_GBRAP12LE
planar GBR 4:4:4:4 48bpp, little-endian
Definition: pixfmt.h:288
@ AV_PIX_FMT_GBRP9BE
planar GBR 4:4:4 27bpp, big-endian
Definition: pixfmt.h:170
@ AV_PIX_FMT_YUVA420P16LE
planar YUV 4:2:0 40bpp, (1 Cr & Cb sample per 2x2 Y & A samples, little-endian)
Definition: pixfmt.h:191
@ AV_PIX_FMT_RGB555LE
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), little-endian, X=unused/undefined
Definition: pixfmt.h:108
@ AV_PIX_FMT_BGR444BE
packed BGR 4:4:4, 16bpp, (msb)4X 4B 4G 4R(lsb), big-endian, X=unused/undefined
Definition: pixfmt.h:142
@ AV_PIX_FMT_RGB48LE
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as lit...
Definition: pixfmt.h:103
@ AV_PIX_FMT_BGR555BE
packed BGR 5:5:5, 16bpp, (msb)1X 5B 5G 5R(lsb), big-endian , X=unused/undefined
Definition: pixfmt.h:112
@ AV_PIX_FMT_GBRAPF32BE
IEEE-754 single precision planar GBRA 4:4:4:4, 128bpp, big-endian.
Definition: pixfmt.h:320
@ AV_PIX_FMT_BGR444LE
packed BGR 4:4:4, 16bpp, (msb)4X 4B 4G 4R(lsb), little-endian, X=unused/undefined
Definition: pixfmt.h:141
@ AV_PIX_FMT_YUVA420P16BE
planar YUV 4:2:0 40bpp, (1 Cr & Cb sample per 2x2 Y & A samples, big-endian)
Definition: pixfmt.h:190
@ AV_PIX_FMT_YUV420P12LE
planar YUV 4:2:0,18bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:243
@ AV_PIX_FMT_BAYER_RGGB16BE
bayer, RGRG..(odd line), GBGB..(even line), 16-bit samples, big-endian
Definition: pixfmt.h:267
@ AV_PIX_FMT_X2RGB10LE
packed RGB 10:10:10, 30bpp, (msb)2X 10R 10G 10B(lsb), little-endian, X=unused/undefined
Definition: pixfmt.h:361
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:79
@ AV_PIX_FMT_YUV444P9BE
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:162
@ AV_PIX_FMT_GBRAPF32LE
IEEE-754 single precision planar GBRA 4:4:4:4, 128bpp, little-endian.
Definition: pixfmt.h:321
@ AV_PIX_FMT_YUV422P9LE
planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:167
@ AV_PIX_FMT_GRAYF32BE
IEEE-754 single precision Y, 32bpp, big-endian.
Definition: pixfmt.h:340
@ AV_PIX_FMT_RGB444BE
packed RGB 4:4:4, 16bpp, (msb)4X 4R 4G 4B(lsb), big-endian, X=unused/undefined
Definition: pixfmt.h:140
@ AV_PIX_FMT_YUV422P9BE
planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:166
@ AV_PIX_FMT_BGR48LE
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as lit...
Definition: pixfmt.h:149
@ AV_PIX_FMT_GBRP14LE
planar GBR 4:4:4 42bpp, little-endian
Definition: pixfmt.h:257
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition: pixfmt.h:238
@ AV_PIX_FMT_YUV422P10LE
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:161
@ AV_PIX_FMT_GRAY16LE
Y , 16bpp, little-endian.
Definition: pixfmt.h:98
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:176
@ AV_PIX_FMT_GBRP10LE
planar GBR 4:4:4 30bpp, little-endian
Definition: pixfmt.h:173
@ AV_PIX_FMT_GBRAP10BE
planar GBR 4:4:4:4 40bpp, big-endian
Definition: pixfmt.h:290
@ AV_PIX_FMT_BAYER_GRBG16BE
bayer, GRGR..(odd line), BGBG..(even line), 16-bit samples, big-endian
Definition: pixfmt.h:271
@ AV_PIX_FMT_RGB565BE
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian
Definition: pixfmt.h:105
@ AV_PIX_FMT_BGR555LE
packed BGR 5:5:5, 16bpp, (msb)1X 5B 5G 5R(lsb), little-endian, X=unused/undefined
Definition: pixfmt.h:113
@ AV_PIX_FMT_YUV420P12BE
planar YUV 4:2:0,18bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:242
@ AV_PIX_FMT_BGRA64LE
packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:208
@ AV_PIX_FMT_YUV440P12BE
planar YUV 4:4:0,24bpp, (1 Cr & Cb sample per 1x2 Y samples), big-endian
Definition: pixfmt.h:278
@ AV_PIX_FMT_GBRAP10LE
planar GBR 4:4:4:4 40bpp, little-endian
Definition: pixfmt.h:291
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:67
@ AV_PIX_FMT_YUV422P16BE
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:134
@ AV_PIX_FMT_BAYER_GBRG16LE
bayer, GBGB..(odd line), RGRG..(even line), 16-bit samples, little-endian
Definition: pixfmt.h:268
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:77
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:69
@ AV_PIX_FMT_GRAY9LE
Y , 9bpp, little-endian.
Definition: pixfmt.h:316
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
@ AV_PIX_FMT_YUV422P14LE
planar YUV 4:2:2,28bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:249
@ AV_PIX_FMT_GBRAP16LE
planar GBRA 4:4:4:4 64bpp, little-endian
Definition: pixfmt.h:217
@ AV_PIX_FMT_BAYER_BGGR16LE
bayer, BGBG..(odd line), GRGR..(even line), 16-bit samples, little-endian
Definition: pixfmt.h:264
@ AV_PIX_FMT_YUV420P10BE
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:158
@ AV_PIX_FMT_YUV420P9BE
The following 12 formats have the disadvantage of needing 1 format for each bit depth.
Definition: pixfmt.h:156
@ AV_PIX_FMT_GRAY10BE
Y , 10bpp, big-endian.
Definition: pixfmt.h:297
@ AV_PIX_FMT_YUVA444P10BE
planar YUV 4:4:4 40bpp, (1 Cr & Cb sample per 1x1 Y & A samples, big-endian)
Definition: pixfmt.h:188
@ AV_PIX_FMT_YUV440P10LE
planar YUV 4:4:0,20bpp, (1 Cr & Cb sample per 1x2 Y samples), little-endian
Definition: pixfmt.h:275
@ AV_PIX_FMT_YA8
8 bits gray, 8 bits alpha
Definition: pixfmt.h:143
@ AV_PIX_FMT_YUV444P16LE
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:135
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition: pixfmt.h:237
@ AV_PIX_FMT_GRAY14BE
Y , 14bpp, big-endian.
Definition: pixfmt.h:337
@ AV_PIX_FMT_GBRP14BE
planar GBR 4:4:4 42bpp, big-endian
Definition: pixfmt.h:256
@ AV_PIX_FMT_BGR565LE
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), little-endian
Definition: pixfmt.h:111
@ AV_PIX_FMT_YUV422P14BE
planar YUV 4:2:2,28bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:248
@ AV_PIX_FMT_BAYER_GBRG16BE
bayer, GBGB..(odd line), RGRG..(even line), 16-bit samples, big-endian
Definition: pixfmt.h:269
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
@ AV_PIX_FMT_YUV444P12BE
planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:250
@ AV_PIX_FMT_YUVA444P16BE
planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, big-endian)
Definition: pixfmt.h:194
@ AV_PIX_FMT_YUVA422P16LE
planar YUV 4:2:2 48bpp, (1 Cr & Cb sample per 2x1 Y & A samples, little-endian)
Definition: pixfmt.h:193
@ AV_PIX_FMT_BAYER_RGGB8
bayer, RGRG..(odd line), GBGB..(even line), 8-bit samples
Definition: pixfmt.h:261
@ AV_PIX_FMT_GBRP16LE
planar GBR 4:4:4 48bpp, little-endian
Definition: pixfmt.h:175
@ AV_PIX_FMT_YUVA422P9BE
planar YUV 4:2:2 27bpp, (1 Cr & Cb sample per 2x1 Y & A samples), big-endian
Definition: pixfmt.h:180
@ AV_PIX_FMT_RGB4
packed RGB 1:2:1 bitstream, 4bpp, (msb)1R 2G 1B(lsb), a byte contains two pixels, the first pixel in ...
Definition: pixfmt.h:87
@ AV_PIX_FMT_YUVA444P12LE
planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), 12b alpha, little-endian
Definition: pixfmt.h:346
@ AV_PIX_FMT_MONOWHITE
Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb.
Definition: pixfmt.h:75
@ AV_PIX_FMT_BGR4
packed RGB 1:2:1 bitstream, 4bpp, (msb)1B 2G 1R(lsb), a byte contains two pixels, the first pixel in ...
Definition: pixfmt.h:84
@ AV_PIX_FMT_YUV444P10LE
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:165
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
@ AV_PIX_FMT_YUV422P12BE
planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:246
@ AV_PIX_FMT_BAYER_BGGR8
bayer, BGBG..(odd line), GRGR..(even line), 8-bit samples
Definition: pixfmt.h:260
@ AV_PIX_FMT_YUV420P16LE
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:131
@ AV_PIX_FMT_YUV444P12LE
planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:251
#define AV_PIX_FMT_BGR565
Definition: pixfmt.h:391
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:411
#define AV_PIX_FMT_BGRA64
Definition: pixfmt.h:394
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:383
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:418
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:412
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:402
#define PPC_ALTIVEC(flags)
Definition: cpu.h:25
static const uint16_t table[]
Definition: prosumer.c:206
av_cold void ff_sws_rgb2rgb_init(void)
Definition: rgb2rgb.c:137
#define FF_ARRAY_ELEMS(a)
int ff_free_filters(SwsContext *c)
Definition: slice.c:378
int ff_init_filters(SwsContext *c)
Definition: slice.c:244
static int shift(int a, int b)
Definition: sonic.c:82
unsigned int pos
Definition: spdifenc.c:412
Describe the class of an AVClass context structure.
Definition: log.h:67
int depth
Number of bits in the component.
Definition: pixdesc.h:58
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t is_supported_in
Definition: utils.c:94
uint8_t is_supported_endianness
Definition: utils.c:96
uint8_t is_supported_out
Definition: utils.c:95
int flag
flag associated to the algorithm
Definition: utils.c:319
int size_factor
size factor used when initing the filters
Definition: utils.c:321
const char * description
human-readable description
Definition: utils.c:320
int dstW
Width of destination luma/alpha planes.
int dstH
Height of destination luma/alpha planes.
int srcW
Width of source luma/alpha planes.
int flags
Flags passed by the user to select scaler algorithm, optimizations, subsampling, etc....
double param[2]
Input parameters for scaling algorithms that need them.
enum AVPixelFormat dstFormat
Destination pixel format.
int srcH
Height of source luma/alpha planes.
enum AVPixelFormat srcFormat
Source pixel format.
SwsVector * chrV
Definition: swscale.h:119
SwsVector * lumH
Definition: swscale.h:116
SwsVector * lumV
Definition: swscale.h:117
SwsVector * chrH
Definition: swscale.h:118
double * coeff
pointer to the list of coefficients
Definition: swscale.h:110
int length
number of coefficients in the vector
Definition: swscale.h:111
av_cold void ff_sws_init_range_convert(SwsContext *c)
Definition: swscale.c:527
#define RGB2YUV_SHIFT
SwsFunc ff_getSwsFunc(SwsContext *c)
Return function pointer to fastest main scaler path function depending on architecture and available ...
Definition: swscale.c:584
external API header
#define APCK_SIZE
static av_always_inline int isBayer(enum AVPixelFormat pix_fmt)
#define BU_IDX
#define RV_IDX
int ff_init_hscaler_mmxext(int dstW, int xInc, uint8_t *filterCode, int16_t *filter, int32_t *filterPos, int numSplits)
static av_always_inline int isFloat(enum AVPixelFormat pix_fmt)
#define DITHER1XBPP
static av_always_inline int isAnyRGB(enum AVPixelFormat pix_fmt)
#define DITHER32_INT
#define RY_IDX
void ff_get_unscaled_swscale(SwsContext *c)
Set c->swscale to an unscaled converter if one exists for the specific source and destination formats...
#define BV_IDX
static av_always_inline int is16BPS(enum AVPixelFormat pix_fmt)
#define GV_IDX
#define RETCODE_USE_CASCADE
@ SWS_DITHER_ED
@ SWS_DITHER_A_DITHER
@ SWS_DITHER_X_DITHER
@ SWS_DITHER_AUTO
@ SWS_DITHER_BAYER
#define XYZ_GAMMA
#define GU_IDX
@ SWS_ALPHA_BLEND_NONE
#define BY_IDX
#define RGB_GAMMA
int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation)
#define GY_IDX
static av_always_inline int isPlanarRGB(enum AVPixelFormat pix_fmt)
#define RU_IDX
static av_always_inline int isBayer16BPS(enum AVPixelFormat pix_fmt)
static av_always_inline int isNBPS(enum AVPixelFormat pix_fmt)
const int32_t ff_yuv2rgb_coeffs[11][4]
Definition: yuv2rgb.c:49
static av_always_inline int isYUV(enum AVPixelFormat pix_fmt)
#define lrint
Definition: tablegen.h:53
#define av_free(p)
#define av_malloc_array(a, b)
#define av_freep(p)
#define av_malloc(s)
#define av_log(a,...)
static void error(const char *err)
#define isALPHA(x)
Definition: swscale.c:51
#define isGray(x)
Definition: swscale.c:40
static int height
Definition: utils.c:158
@ ONE
Definition: vc1_parser.c:48
@ W
Definition: vf_addroi.c:26
const char * b
Definition: vf_curves.c:119
static const double coeff[2][5]
Definition: vf_owdenoise.c:73
static av_always_inline int diff(const uint32_t a, const uint32_t b)
float min
static double c[64]
#define X86_MMX(flags)
Definition: cpu.h:30
#define INLINE_MMXEXT(flags)
Definition: cpu.h:87
#define INLINE_MMX(flags)
Definition: cpu.h:86
#define INLINE_AMD3DNOW(flags)
Definition: cpu.h:84
int acc
Definition: yuv2rgb.c:721
av_cold void ff_yuv2rgb_init_tables_ppc(SwsContext *c, const int inv_table[4], int brightness, int contrast, int saturation)