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