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