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