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