libswscale/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/intreadwrite.h"
46 #include "libavutil/mathematics.h"
47 #include "libavutil/opt.h"
48 #include "libavutil/pixdesc.h"
49 #include "libavutil/x86/asm.h"
50 #include "libavutil/x86/cpu.h"
51 #include "rgb2rgb.h"
52 #include "swscale.h"
53 #include "swscale_internal.h"
54 
55 unsigned swscale_version(void)
56 {
59 }
60 
61 const char *swscale_configuration(void)
62 {
63  return FFMPEG_CONFIGURATION;
64 }
65 
66 const char *swscale_license(void)
67 {
68 #define LICENSE_PREFIX "libswscale license: "
69  return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
70 }
71 
72 #define RET 0xC3 // near return opcode for x86
73 
74 typedef struct FormatEntry {
76 } FormatEntry;
77 
79  [AV_PIX_FMT_YUV420P] = { 1, 1 },
80  [AV_PIX_FMT_YUYV422] = { 1, 1 },
81  [AV_PIX_FMT_RGB24] = { 1, 1 },
82  [AV_PIX_FMT_BGR24] = { 1, 1 },
83  [AV_PIX_FMT_YUV422P] = { 1, 1 },
84  [AV_PIX_FMT_YUV444P] = { 1, 1 },
85  [AV_PIX_FMT_YUV410P] = { 1, 1 },
86  [AV_PIX_FMT_YUV411P] = { 1, 1 },
87  [AV_PIX_FMT_GRAY8] = { 1, 1 },
88  [AV_PIX_FMT_MONOWHITE] = { 1, 1 },
89  [AV_PIX_FMT_MONOBLACK] = { 1, 1 },
90  [AV_PIX_FMT_PAL8] = { 1, 0 },
91  [AV_PIX_FMT_YUVJ420P] = { 1, 1 },
92  [AV_PIX_FMT_YUVJ422P] = { 1, 1 },
93  [AV_PIX_FMT_YUVJ444P] = { 1, 1 },
94  [AV_PIX_FMT_UYVY422] = { 1, 1 },
95  [AV_PIX_FMT_UYYVYY411] = { 0, 0 },
96  [AV_PIX_FMT_BGR8] = { 1, 1 },
97  [AV_PIX_FMT_BGR4] = { 0, 1 },
98  [AV_PIX_FMT_BGR4_BYTE] = { 1, 1 },
99  [AV_PIX_FMT_RGB8] = { 1, 1 },
100  [AV_PIX_FMT_RGB4] = { 0, 1 },
101  [AV_PIX_FMT_RGB4_BYTE] = { 1, 1 },
102  [AV_PIX_FMT_NV12] = { 1, 1 },
103  [AV_PIX_FMT_NV21] = { 1, 1 },
104  [AV_PIX_FMT_ARGB] = { 1, 1 },
105  [AV_PIX_FMT_RGBA] = { 1, 1 },
106  [AV_PIX_FMT_ABGR] = { 1, 1 },
107  [AV_PIX_FMT_BGRA] = { 1, 1 },
108  [AV_PIX_FMT_0RGB] = { 1, 1 },
109  [AV_PIX_FMT_RGB0] = { 1, 1 },
110  [AV_PIX_FMT_0BGR] = { 1, 1 },
111  [AV_PIX_FMT_BGR0] = { 1, 1 },
112  [AV_PIX_FMT_GRAY16BE] = { 1, 1 },
113  [AV_PIX_FMT_GRAY16LE] = { 1, 1 },
114  [AV_PIX_FMT_YUV440P] = { 1, 1 },
115  [AV_PIX_FMT_YUVJ440P] = { 1, 1 },
116  [AV_PIX_FMT_YUVA420P] = { 1, 1 },
117  [AV_PIX_FMT_YUVA422P] = { 1, 1 },
118  [AV_PIX_FMT_YUVA444P] = { 1, 1 },
119  [AV_PIX_FMT_YUVA420P9BE] = { 1, 1 },
120  [AV_PIX_FMT_YUVA420P9LE] = { 1, 1 },
121  [AV_PIX_FMT_YUVA422P9BE] = { 1, 1 },
122  [AV_PIX_FMT_YUVA422P9LE] = { 1, 1 },
123  [AV_PIX_FMT_YUVA444P9BE] = { 1, 1 },
124  [AV_PIX_FMT_YUVA444P9LE] = { 1, 1 },
125  [AV_PIX_FMT_YUVA420P10BE]= { 1, 1 },
126  [AV_PIX_FMT_YUVA420P10LE]= { 1, 1 },
127  [AV_PIX_FMT_YUVA422P10BE]= { 1, 1 },
128  [AV_PIX_FMT_YUVA422P10LE]= { 1, 1 },
129  [AV_PIX_FMT_YUVA444P10BE]= { 1, 1 },
130  [AV_PIX_FMT_YUVA444P10LE]= { 1, 1 },
131  [AV_PIX_FMT_YUVA420P16BE]= { 1, 1 },
132  [AV_PIX_FMT_YUVA420P16LE]= { 1, 1 },
133  [AV_PIX_FMT_YUVA422P16BE]= { 1, 1 },
134  [AV_PIX_FMT_YUVA422P16LE]= { 1, 1 },
135  [AV_PIX_FMT_YUVA444P16BE]= { 1, 1 },
136  [AV_PIX_FMT_YUVA444P16LE]= { 1, 1 },
137  [AV_PIX_FMT_RGB48BE] = { 1, 1 },
138  [AV_PIX_FMT_RGB48LE] = { 1, 1 },
139  [AV_PIX_FMT_RGBA64BE] = { 1, 0 },
140  [AV_PIX_FMT_RGBA64LE] = { 1, 0 },
141  [AV_PIX_FMT_RGB565BE] = { 1, 1 },
142  [AV_PIX_FMT_RGB565LE] = { 1, 1 },
143  [AV_PIX_FMT_RGB555BE] = { 1, 1 },
144  [AV_PIX_FMT_RGB555LE] = { 1, 1 },
145  [AV_PIX_FMT_BGR565BE] = { 1, 1 },
146  [AV_PIX_FMT_BGR565LE] = { 1, 1 },
147  [AV_PIX_FMT_BGR555BE] = { 1, 1 },
148  [AV_PIX_FMT_BGR555LE] = { 1, 1 },
149  [AV_PIX_FMT_YUV420P16LE] = { 1, 1 },
150  [AV_PIX_FMT_YUV420P16BE] = { 1, 1 },
151  [AV_PIX_FMT_YUV422P16LE] = { 1, 1 },
152  [AV_PIX_FMT_YUV422P16BE] = { 1, 1 },
153  [AV_PIX_FMT_YUV444P16LE] = { 1, 1 },
154  [AV_PIX_FMT_YUV444P16BE] = { 1, 1 },
155  [AV_PIX_FMT_RGB444LE] = { 1, 1 },
156  [AV_PIX_FMT_RGB444BE] = { 1, 1 },
157  [AV_PIX_FMT_BGR444LE] = { 1, 1 },
158  [AV_PIX_FMT_BGR444BE] = { 1, 1 },
159  [AV_PIX_FMT_Y400A] = { 1, 0 },
160  [AV_PIX_FMT_BGR48BE] = { 1, 1 },
161  [AV_PIX_FMT_BGR48LE] = { 1, 1 },
162  [AV_PIX_FMT_BGRA64BE] = { 0, 0 },
163  [AV_PIX_FMT_BGRA64LE] = { 0, 0 },
164  [AV_PIX_FMT_YUV420P9BE] = { 1, 1 },
165  [AV_PIX_FMT_YUV420P9LE] = { 1, 1 },
166  [AV_PIX_FMT_YUV420P10BE] = { 1, 1 },
167  [AV_PIX_FMT_YUV420P10LE] = { 1, 1 },
168  [AV_PIX_FMT_YUV420P12BE] = { 1, 1 },
169  [AV_PIX_FMT_YUV420P12LE] = { 1, 1 },
170  [AV_PIX_FMT_YUV420P14BE] = { 1, 1 },
171  [AV_PIX_FMT_YUV420P14LE] = { 1, 1 },
172  [AV_PIX_FMT_YUV422P9BE] = { 1, 1 },
173  [AV_PIX_FMT_YUV422P9LE] = { 1, 1 },
174  [AV_PIX_FMT_YUV422P10BE] = { 1, 1 },
175  [AV_PIX_FMT_YUV422P10LE] = { 1, 1 },
176  [AV_PIX_FMT_YUV422P12BE] = { 1, 1 },
177  [AV_PIX_FMT_YUV422P12LE] = { 1, 1 },
178  [AV_PIX_FMT_YUV422P14BE] = { 1, 1 },
179  [AV_PIX_FMT_YUV422P14LE] = { 1, 1 },
180  [AV_PIX_FMT_YUV444P9BE] = { 1, 1 },
181  [AV_PIX_FMT_YUV444P9LE] = { 1, 1 },
182  [AV_PIX_FMT_YUV444P10BE] = { 1, 1 },
183  [AV_PIX_FMT_YUV444P10LE] = { 1, 1 },
184  [AV_PIX_FMT_YUV444P12BE] = { 1, 1 },
185  [AV_PIX_FMT_YUV444P12LE] = { 1, 1 },
186  [AV_PIX_FMT_YUV444P14BE] = { 1, 1 },
187  [AV_PIX_FMT_YUV444P14LE] = { 1, 1 },
188  [AV_PIX_FMT_GBRP] = { 1, 1 },
189  [AV_PIX_FMT_GBRP9LE] = { 1, 1 },
190  [AV_PIX_FMT_GBRP9BE] = { 1, 1 },
191  [AV_PIX_FMT_GBRP10LE] = { 1, 1 },
192  [AV_PIX_FMT_GBRP10BE] = { 1, 1 },
193  [AV_PIX_FMT_GBRP12LE] = { 1, 1 },
194  [AV_PIX_FMT_GBRP12BE] = { 1, 1 },
195  [AV_PIX_FMT_GBRP14LE] = { 1, 1 },
196  [AV_PIX_FMT_GBRP14BE] = { 1, 1 },
197  [AV_PIX_FMT_GBRP16LE] = { 1, 0 },
198  [AV_PIX_FMT_GBRP16BE] = { 1, 0 },
199 };
200 
202 {
203  return (unsigned)pix_fmt < AV_PIX_FMT_NB ?
204  format_entries[pix_fmt].is_supported_in : 0;
205 }
206 
208 {
209  return (unsigned)pix_fmt < AV_PIX_FMT_NB ?
210  format_entries[pix_fmt].is_supported_out : 0;
211 }
212 
213 extern const int32_t ff_yuv2rgb_coeffs[8][4];
214 
215 #if FF_API_SWS_FORMAT_NAME
217 {
218  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(format);
219  if (desc)
220  return desc->name;
221  else
222  return "Unknown format";
223 }
224 #endif
225 
226 static double getSplineCoeff(double a, double b, double c, double d,
227  double dist)
228 {
229  if (dist <= 1.0)
230  return ((d * dist + c) * dist + b) * dist + a;
231  else
232  return getSplineCoeff(0.0,
233  b + 2.0 * c + 3.0 * d,
234  c + 3.0 * d,
235  -b - 3.0 * c - 6.0 * d,
236  dist - 1.0);
237 }
238 
239 static int initFilter(int16_t **outFilter, int32_t **filterPos,
240  int *outFilterSize, int xInc, int srcW, int dstW,
241  int filterAlign, int one, int flags, int cpu_flags,
242  SwsVector *srcFilter, SwsVector *dstFilter,
243  double param[2])
244 {
245  int i;
246  int filterSize;
247  int filter2Size;
248  int minFilterSize;
249  int64_t *filter = NULL;
250  int64_t *filter2 = NULL;
251  const int64_t fone = 1LL << (54 - FFMIN(av_log2(srcW/dstW), 8));
252  int ret = -1;
253 
254  emms_c(); // FIXME should not be required but IS (even for non-MMX versions)
255 
256  // NOTE: the +3 is for the MMX(+1) / SSE(+3) scaler which reads over the end
257  FF_ALLOC_OR_GOTO(NULL, *filterPos, (dstW + 3) * sizeof(**filterPos), fail);
258 
259  if (FFABS(xInc - 0x10000) < 10) { // unscaled
260  int i;
261  filterSize = 1;
262  FF_ALLOCZ_OR_GOTO(NULL, filter,
263  dstW * sizeof(*filter) * filterSize, fail);
264 
265  for (i = 0; i < dstW; i++) {
266  filter[i * filterSize] = fone;
267  (*filterPos)[i] = i;
268  }
269  } else if (flags & SWS_POINT) { // lame looking point sampling mode
270  int i;
271  int64_t xDstInSrc;
272  filterSize = 1;
273  FF_ALLOC_OR_GOTO(NULL, filter,
274  dstW * sizeof(*filter) * filterSize, fail);
275 
276  xDstInSrc = xInc / 2 - 0x8000;
277  for (i = 0; i < dstW; i++) {
278  int xx = (xDstInSrc - ((filterSize - 1) << 15) + (1 << 15)) >> 16;
279 
280  (*filterPos)[i] = xx;
281  filter[i] = fone;
282  xDstInSrc += xInc;
283  }
284  } else if ((xInc <= (1 << 16) && (flags & SWS_AREA)) ||
285  (flags & SWS_FAST_BILINEAR)) { // bilinear upscale
286  int i;
287  int64_t xDstInSrc;
288  filterSize = 2;
289  FF_ALLOC_OR_GOTO(NULL, filter,
290  dstW * sizeof(*filter) * filterSize, fail);
291 
292  xDstInSrc = xInc / 2 - 0x8000;
293  for (i = 0; i < dstW; i++) {
294  int xx = (xDstInSrc - ((filterSize - 1) << 15) + (1 << 15)) >> 16;
295  int j;
296 
297  (*filterPos)[i] = xx;
298  // bilinear upscale / linear interpolate / area averaging
299  for (j = 0; j < filterSize; j++) {
300  int64_t coeff= fone - FFABS(((int64_t)xx<<16) - xDstInSrc)*(fone>>16);
301  if (coeff < 0)
302  coeff = 0;
303  filter[i * filterSize + j] = coeff;
304  xx++;
305  }
306  xDstInSrc += xInc;
307  }
308  } else {
309  int64_t xDstInSrc;
310  int sizeFactor;
311 
312  if (flags & SWS_BICUBIC)
313  sizeFactor = 4;
314  else if (flags & SWS_X)
315  sizeFactor = 8;
316  else if (flags & SWS_AREA)
317  sizeFactor = 1; // downscale only, for upscale it is bilinear
318  else if (flags & SWS_GAUSS)
319  sizeFactor = 8; // infinite ;)
320  else if (flags & SWS_LANCZOS)
321  sizeFactor = param[0] != SWS_PARAM_DEFAULT ? ceil(2 * param[0]) : 6;
322  else if (flags & SWS_SINC)
323  sizeFactor = 20; // infinite ;)
324  else if (flags & SWS_SPLINE)
325  sizeFactor = 20; // infinite ;)
326  else if (flags & SWS_BILINEAR)
327  sizeFactor = 2;
328  else {
329  av_assert0(0);
330  }
331 
332  if (xInc <= 1 << 16)
333  filterSize = 1 + sizeFactor; // upscale
334  else
335  filterSize = 1 + (sizeFactor * srcW + dstW - 1) / dstW;
336 
337  filterSize = FFMIN(filterSize, srcW - 2);
338  filterSize = FFMAX(filterSize, 1);
339 
340  FF_ALLOC_OR_GOTO(NULL, filter,
341  dstW * sizeof(*filter) * filterSize, fail);
342 
343  xDstInSrc = xInc - 0x10000;
344  for (i = 0; i < dstW; i++) {
345  int xx = (xDstInSrc - ((filterSize - 2) << 16)) / (1 << 17);
346  int j;
347  (*filterPos)[i] = xx;
348  for (j = 0; j < filterSize; j++) {
349  int64_t d = (FFABS(((int64_t)xx << 17) - xDstInSrc)) << 13;
350  double floatd;
351  int64_t coeff;
352 
353  if (xInc > 1 << 16)
354  d = d * dstW / srcW;
355  floatd = d * (1.0 / (1 << 30));
356 
357  if (flags & SWS_BICUBIC) {
358  int64_t B = (param[0] != SWS_PARAM_DEFAULT ? param[0] : 0) * (1 << 24);
359  int64_t C = (param[1] != SWS_PARAM_DEFAULT ? param[1] : 0.6) * (1 << 24);
360 
361  if (d >= 1LL << 31) {
362  coeff = 0.0;
363  } else {
364  int64_t dd = (d * d) >> 30;
365  int64_t ddd = (dd * d) >> 30;
366 
367  if (d < 1LL << 30)
368  coeff = (12 * (1 << 24) - 9 * B - 6 * C) * ddd +
369  (-18 * (1 << 24) + 12 * B + 6 * C) * dd +
370  (6 * (1 << 24) - 2 * B) * (1 << 30);
371  else
372  coeff = (-B - 6 * C) * ddd +
373  (6 * B + 30 * C) * dd +
374  (-12 * B - 48 * C) * d +
375  (8 * B + 24 * C) * (1 << 30);
376  }
377  coeff /= (1LL<<54)/fone;
378  }
379 #if 0
380  else if (flags & SWS_X) {
381  double p = param ? param * 0.01 : 0.3;
382  coeff = d ? sin(d * M_PI) / (d * M_PI) : 1.0;
383  coeff *= pow(2.0, -p * d * d);
384  }
385 #endif
386  else if (flags & SWS_X) {
387  double A = param[0] != SWS_PARAM_DEFAULT ? param[0] : 1.0;
388  double c;
389 
390  if (floatd < 1.0)
391  c = cos(floatd * M_PI);
392  else
393  c = -1.0;
394  if (c < 0.0)
395  c = -pow(-c, A);
396  else
397  c = pow(c, A);
398  coeff = (c * 0.5 + 0.5) * fone;
399  } else if (flags & SWS_AREA) {
400  int64_t d2 = d - (1 << 29);
401  if (d2 * xInc < -(1LL << (29 + 16)))
402  coeff = 1.0 * (1LL << (30 + 16));
403  else if (d2 * xInc < (1LL << (29 + 16)))
404  coeff = -d2 * xInc + (1LL << (29 + 16));
405  else
406  coeff = 0.0;
407  coeff *= fone >> (30 + 16);
408  } else if (flags & SWS_GAUSS) {
409  double p = param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0;
410  coeff = (pow(2.0, -p * floatd * floatd)) * fone;
411  } else if (flags & SWS_SINC) {
412  coeff = (d ? sin(floatd * M_PI) / (floatd * M_PI) : 1.0) * fone;
413  } else if (flags & SWS_LANCZOS) {
414  double p = param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0;
415  coeff = (d ? sin(floatd * M_PI) * sin(floatd * M_PI / p) /
416  (floatd * floatd * M_PI * M_PI / p) : 1.0) * fone;
417  if (floatd > p)
418  coeff = 0;
419  } else if (flags & SWS_BILINEAR) {
420  coeff = (1 << 30) - d;
421  if (coeff < 0)
422  coeff = 0;
423  coeff *= fone >> 30;
424  } else if (flags & SWS_SPLINE) {
425  double p = -2.196152422706632;
426  coeff = getSplineCoeff(1.0, 0.0, p, -p - 1.0, floatd) * fone;
427  } else {
428  av_assert0(0);
429  }
430 
431  filter[i * filterSize + j] = coeff;
432  xx++;
433  }
434  xDstInSrc += 2 * xInc;
435  }
436  }
437 
438  /* apply src & dst Filter to filter -> filter2
439  * av_free(filter);
440  */
441  av_assert0(filterSize > 0);
442  filter2Size = filterSize;
443  if (srcFilter)
444  filter2Size += srcFilter->length - 1;
445  if (dstFilter)
446  filter2Size += dstFilter->length - 1;
447  av_assert0(filter2Size > 0);
448  FF_ALLOCZ_OR_GOTO(NULL, filter2, filter2Size * dstW * sizeof(*filter2), fail);
449 
450  for (i = 0; i < dstW; i++) {
451  int j, k;
452 
453  if (srcFilter) {
454  for (k = 0; k < srcFilter->length; k++) {
455  for (j = 0; j < filterSize; j++)
456  filter2[i * filter2Size + k + j] +=
457  srcFilter->coeff[k] * filter[i * filterSize + j];
458  }
459  } else {
460  for (j = 0; j < filterSize; j++)
461  filter2[i * filter2Size + j] = filter[i * filterSize + j];
462  }
463  // FIXME dstFilter
464 
465  (*filterPos)[i] += (filterSize - 1) / 2 - (filter2Size - 1) / 2;
466  }
467  av_freep(&filter);
468 
469  /* try to reduce the filter-size (step1 find size and shift left) */
470  // Assume it is near normalized (*0.5 or *2.0 is OK but * 0.001 is not).
471  minFilterSize = 0;
472  for (i = dstW - 1; i >= 0; i--) {
473  int min = filter2Size;
474  int j;
475  int64_t cutOff = 0.0;
476 
477  /* get rid of near zero elements on the left by shifting left */
478  for (j = 0; j < filter2Size; j++) {
479  int k;
480  cutOff += FFABS(filter2[i * filter2Size]);
481 
482  if (cutOff > SWS_MAX_REDUCE_CUTOFF * fone)
483  break;
484 
485  /* preserve monotonicity because the core can't handle the
486  * filter otherwise */
487  if (i < dstW - 1 && (*filterPos)[i] >= (*filterPos)[i + 1])
488  break;
489 
490  // move filter coefficients left
491  for (k = 1; k < filter2Size; k++)
492  filter2[i * filter2Size + k - 1] = filter2[i * filter2Size + k];
493  filter2[i * filter2Size + k - 1] = 0;
494  (*filterPos)[i]++;
495  }
496 
497  cutOff = 0;
498  /* count near zeros on the right */
499  for (j = filter2Size - 1; j > 0; j--) {
500  cutOff += FFABS(filter2[i * filter2Size + j]);
501 
502  if (cutOff > SWS_MAX_REDUCE_CUTOFF * fone)
503  break;
504  min--;
505  }
506 
507  if (min > minFilterSize)
508  minFilterSize = min;
509  }
510 
511  if (HAVE_ALTIVEC && cpu_flags & AV_CPU_FLAG_ALTIVEC) {
512  // we can handle the special case 4, so we don't want to go the full 8
513  if (minFilterSize < 5)
514  filterAlign = 4;
515 
516  /* We really don't want to waste our time doing useless computation, so
517  * fall back on the scalar C code for very small filters.
518  * Vectorizing is worth it only if you have a decent-sized vector. */
519  if (minFilterSize < 3)
520  filterAlign = 1;
521  }
522 
523  if (INLINE_MMX(cpu_flags)) {
524  // special case for unscaled vertical filtering
525  if (minFilterSize == 1 && filterAlign == 2)
526  filterAlign = 1;
527  }
528 
529  av_assert0(minFilterSize > 0);
530  filterSize = (minFilterSize + (filterAlign - 1)) & (~(filterAlign - 1));
531  av_assert0(filterSize > 0);
532  filter = av_malloc(filterSize * dstW * sizeof(*filter));
533  if (filterSize >= MAX_FILTER_SIZE * 16 /
534  ((flags & SWS_ACCURATE_RND) ? APCK_SIZE : 16) || !filter) {
535  av_log(NULL, AV_LOG_ERROR, "sws: filterSize %d is too large, try less extreem scaling or increase MAX_FILTER_SIZE and recompile\n", filterSize);
536  goto fail;
537  }
538  *outFilterSize = filterSize;
539 
540  if (flags & SWS_PRINT_INFO)
542  "SwScaler: reducing / aligning filtersize %d -> %d\n",
543  filter2Size, filterSize);
544  /* try to reduce the filter-size (step2 reduce it) */
545  for (i = 0; i < dstW; i++) {
546  int j;
547 
548  for (j = 0; j < filterSize; j++) {
549  if (j >= filter2Size)
550  filter[i * filterSize + j] = 0;
551  else
552  filter[i * filterSize + j] = filter2[i * filter2Size + j];
553  if ((flags & SWS_BITEXACT) && j >= minFilterSize)
554  filter[i * filterSize + j] = 0;
555  }
556  }
557 
558  // FIXME try to align filterPos if possible
559 
560  // fix borders
561  for (i = 0; i < dstW; i++) {
562  int j;
563  if ((*filterPos)[i] < 0) {
564  // move filter coefficients left to compensate for filterPos
565  for (j = 1; j < filterSize; j++) {
566  int left = FFMAX(j + (*filterPos)[i], 0);
567  filter[i * filterSize + left] += filter[i * filterSize + j];
568  filter[i * filterSize + j] = 0;
569  }
570  (*filterPos)[i]= 0;
571  }
572 
573  if ((*filterPos)[i] + filterSize > srcW) {
574  int shift = (*filterPos)[i] + filterSize - srcW;
575  // move filter coefficients right to compensate for filterPos
576  for (j = filterSize - 2; j >= 0; j--) {
577  int right = FFMIN(j + shift, filterSize - 1);
578  filter[i * filterSize + right] += filter[i * filterSize + j];
579  filter[i * filterSize + j] = 0;
580  }
581  (*filterPos)[i]= srcW - filterSize;
582  }
583  }
584 
585  // Note the +1 is for the MMX scaler which reads over the end
586  /* align at 16 for AltiVec (needed by hScale_altivec_real) */
587  FF_ALLOCZ_OR_GOTO(NULL, *outFilter,
588  *outFilterSize * (dstW + 3) * sizeof(int16_t), fail);
589 
590  /* normalize & store in outFilter */
591  for (i = 0; i < dstW; i++) {
592  int j;
593  int64_t error = 0;
594  int64_t sum = 0;
595 
596  for (j = 0; j < filterSize; j++) {
597  sum += filter[i * filterSize + j];
598  }
599  sum = (sum + one / 2) / one;
600  for (j = 0; j < *outFilterSize; j++) {
601  int64_t v = filter[i * filterSize + j] + error;
602  int intV = ROUNDED_DIV(v, sum);
603  (*outFilter)[i * (*outFilterSize) + j] = intV;
604  error = v - intV * sum;
605  }
606  }
607 
608  (*filterPos)[dstW + 0] =
609  (*filterPos)[dstW + 1] =
610  (*filterPos)[dstW + 2] = (*filterPos)[dstW - 1]; /* the MMX/SSE scaler will
611  * read over the end */
612  for (i = 0; i < *outFilterSize; i++) {
613  int k = (dstW - 1) * (*outFilterSize) + i;
614  (*outFilter)[k + 1 * (*outFilterSize)] =
615  (*outFilter)[k + 2 * (*outFilterSize)] =
616  (*outFilter)[k + 3 * (*outFilterSize)] = (*outFilter)[k];
617  }
618 
619  ret = 0;
620 
621 fail:
622  if(ret < 0)
623  av_log(NULL, AV_LOG_ERROR, "sws: initFilter failed\n");
624  av_free(filter);
625  av_free(filter2);
626  return ret;
627 }
628 
629 #if HAVE_MMXEXT_INLINE
630 static int init_hscaler_mmxext(int dstW, int xInc, uint8_t *filterCode,
631  int16_t *filter, int32_t *filterPos,
632  int numSplits)
633 {
634  uint8_t *fragmentA;
635  x86_reg imm8OfPShufW1A;
636  x86_reg imm8OfPShufW2A;
637  x86_reg fragmentLengthA;
638  uint8_t *fragmentB;
639  x86_reg imm8OfPShufW1B;
640  x86_reg imm8OfPShufW2B;
641  x86_reg fragmentLengthB;
642  int fragmentPos;
643 
644  int xpos, i;
645 
646  // create an optimized horizontal scaling routine
647  /* This scaler is made of runtime-generated MMXEXT code using specially tuned
648  * pshufw instructions. For every four output pixels, if four input pixels
649  * are enough for the fast bilinear scaling, then a chunk of fragmentB is
650  * used. If five input pixels are needed, then a chunk of fragmentA is used.
651  */
652 
653  // code fragment
654 
655  __asm__ volatile (
656  "jmp 9f \n\t"
657  // Begin
658  "0: \n\t"
659  "movq (%%"REG_d", %%"REG_a"), %%mm3 \n\t"
660  "movd (%%"REG_c", %%"REG_S"), %%mm0 \n\t"
661  "movd 1(%%"REG_c", %%"REG_S"), %%mm1 \n\t"
662  "punpcklbw %%mm7, %%mm1 \n\t"
663  "punpcklbw %%mm7, %%mm0 \n\t"
664  "pshufw $0xFF, %%mm1, %%mm1 \n\t"
665  "1: \n\t"
666  "pshufw $0xFF, %%mm0, %%mm0 \n\t"
667  "2: \n\t"
668  "psubw %%mm1, %%mm0 \n\t"
669  "movl 8(%%"REG_b", %%"REG_a"), %%esi \n\t"
670  "pmullw %%mm3, %%mm0 \n\t"
671  "psllw $7, %%mm1 \n\t"
672  "paddw %%mm1, %%mm0 \n\t"
673 
674  "movq %%mm0, (%%"REG_D", %%"REG_a") \n\t"
675 
676  "add $8, %%"REG_a" \n\t"
677  // End
678  "9: \n\t"
679  // "int $3 \n\t"
680  "lea " LOCAL_MANGLE(0b) ", %0 \n\t"
681  "lea " LOCAL_MANGLE(1b) ", %1 \n\t"
682  "lea " LOCAL_MANGLE(2b) ", %2 \n\t"
683  "dec %1 \n\t"
684  "dec %2 \n\t"
685  "sub %0, %1 \n\t"
686  "sub %0, %2 \n\t"
687  "lea " LOCAL_MANGLE(9b) ", %3 \n\t"
688  "sub %0, %3 \n\t"
689 
690 
691  : "=r" (fragmentA), "=r" (imm8OfPShufW1A), "=r" (imm8OfPShufW2A),
692  "=r" (fragmentLengthA)
693  );
694 
695  __asm__ volatile (
696  "jmp 9f \n\t"
697  // Begin
698  "0: \n\t"
699  "movq (%%"REG_d", %%"REG_a"), %%mm3 \n\t"
700  "movd (%%"REG_c", %%"REG_S"), %%mm0 \n\t"
701  "punpcklbw %%mm7, %%mm0 \n\t"
702  "pshufw $0xFF, %%mm0, %%mm1 \n\t"
703  "1: \n\t"
704  "pshufw $0xFF, %%mm0, %%mm0 \n\t"
705  "2: \n\t"
706  "psubw %%mm1, %%mm0 \n\t"
707  "movl 8(%%"REG_b", %%"REG_a"), %%esi \n\t"
708  "pmullw %%mm3, %%mm0 \n\t"
709  "psllw $7, %%mm1 \n\t"
710  "paddw %%mm1, %%mm0 \n\t"
711 
712  "movq %%mm0, (%%"REG_D", %%"REG_a") \n\t"
713 
714  "add $8, %%"REG_a" \n\t"
715  // End
716  "9: \n\t"
717  // "int $3 \n\t"
718  "lea " LOCAL_MANGLE(0b) ", %0 \n\t"
719  "lea " LOCAL_MANGLE(1b) ", %1 \n\t"
720  "lea " LOCAL_MANGLE(2b) ", %2 \n\t"
721  "dec %1 \n\t"
722  "dec %2 \n\t"
723  "sub %0, %1 \n\t"
724  "sub %0, %2 \n\t"
725  "lea " LOCAL_MANGLE(9b) ", %3 \n\t"
726  "sub %0, %3 \n\t"
727 
728 
729  : "=r" (fragmentB), "=r" (imm8OfPShufW1B), "=r" (imm8OfPShufW2B),
730  "=r" (fragmentLengthB)
731  );
732 
733  xpos = 0; // lumXInc/2 - 0x8000; // difference between pixel centers
734  fragmentPos = 0;
735 
736  for (i = 0; i < dstW / numSplits; i++) {
737  int xx = xpos >> 16;
738 
739  if ((i & 3) == 0) {
740  int a = 0;
741  int b = ((xpos + xInc) >> 16) - xx;
742  int c = ((xpos + xInc * 2) >> 16) - xx;
743  int d = ((xpos + xInc * 3) >> 16) - xx;
744  int inc = (d + 1 < 4);
745  uint8_t *fragment = (d + 1 < 4) ? fragmentB : fragmentA;
746  x86_reg imm8OfPShufW1 = (d + 1 < 4) ? imm8OfPShufW1B : imm8OfPShufW1A;
747  x86_reg imm8OfPShufW2 = (d + 1 < 4) ? imm8OfPShufW2B : imm8OfPShufW2A;
748  x86_reg fragmentLength = (d + 1 < 4) ? fragmentLengthB : fragmentLengthA;
749  int maxShift = 3 - (d + inc);
750  int shift = 0;
751 
752  if (filterCode) {
753  filter[i] = ((xpos & 0xFFFF) ^ 0xFFFF) >> 9;
754  filter[i + 1] = (((xpos + xInc) & 0xFFFF) ^ 0xFFFF) >> 9;
755  filter[i + 2] = (((xpos + xInc * 2) & 0xFFFF) ^ 0xFFFF) >> 9;
756  filter[i + 3] = (((xpos + xInc * 3) & 0xFFFF) ^ 0xFFFF) >> 9;
757  filterPos[i / 2] = xx;
758 
759  memcpy(filterCode + fragmentPos, fragment, fragmentLength);
760 
761  filterCode[fragmentPos + imm8OfPShufW1] = (a + inc) |
762  ((b + inc) << 2) |
763  ((c + inc) << 4) |
764  ((d + inc) << 6);
765  filterCode[fragmentPos + imm8OfPShufW2] = a | (b << 2) |
766  (c << 4) |
767  (d << 6);
768 
769  if (i + 4 - inc >= dstW)
770  shift = maxShift; // avoid overread
771  else if ((filterPos[i / 2] & 3) <= maxShift)
772  shift = filterPos[i / 2] & 3; // align
773 
774  if (shift && i >= shift) {
775  filterCode[fragmentPos + imm8OfPShufW1] += 0x55 * shift;
776  filterCode[fragmentPos + imm8OfPShufW2] += 0x55 * shift;
777  filterPos[i / 2] -= shift;
778  }
779  }
780 
781  fragmentPos += fragmentLength;
782 
783  if (filterCode)
784  filterCode[fragmentPos] = RET;
785  }
786  xpos += xInc;
787  }
788  if (filterCode)
789  filterPos[((i / 2) + 1) & (~1)] = xpos >> 16; // needed to jump to the next part
790 
791  return fragmentPos + 1;
792 }
793 #endif /* HAVE_MMXEXT_INLINE */
794 
795 static void getSubSampleFactors(int *h, int *v, enum AVPixelFormat format)
796 {
797  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(format);
798  *h = desc->log2_chroma_w;
799  *v = desc->log2_chroma_h;
800 }
801 
802 static void fill_rgb2yuv_table(SwsContext *c, const int table[4], int dstRange)
803 {
804  int64_t W, V, Z, Cy, Cu, Cv;
805  int64_t vr = table[0];
806  int64_t ub = table[1];
807  int64_t ug = -table[2];
808  int64_t vg = -table[3];
809  int64_t ONE = 65536;
810  int64_t cy = ONE;
811  uint8_t *p = (uint8_t*)c->input_rgb2yuv_table;
812  int i;
813  static const int8_t map[] = {
814  BY_IDX, GY_IDX, -1 , BY_IDX, BY_IDX, GY_IDX, -1 , BY_IDX,
815  RY_IDX, -1 , GY_IDX, RY_IDX, RY_IDX, -1 , GY_IDX, RY_IDX,
816  RY_IDX, GY_IDX, -1 , RY_IDX, RY_IDX, GY_IDX, -1 , RY_IDX,
817  BY_IDX, -1 , GY_IDX, BY_IDX, BY_IDX, -1 , GY_IDX, BY_IDX,
818  BU_IDX, GU_IDX, -1 , BU_IDX, BU_IDX, GU_IDX, -1 , BU_IDX,
819  RU_IDX, -1 , GU_IDX, RU_IDX, RU_IDX, -1 , GU_IDX, RU_IDX,
820  RU_IDX, GU_IDX, -1 , RU_IDX, RU_IDX, GU_IDX, -1 , RU_IDX,
821  BU_IDX, -1 , GU_IDX, BU_IDX, BU_IDX, -1 , GU_IDX, BU_IDX,
822  BV_IDX, GV_IDX, -1 , BV_IDX, BV_IDX, GV_IDX, -1 , BV_IDX,
823  RV_IDX, -1 , GV_IDX, RV_IDX, RV_IDX, -1 , GV_IDX, RV_IDX,
824  RV_IDX, GV_IDX, -1 , RV_IDX, RV_IDX, GV_IDX, -1 , RV_IDX,
825  BV_IDX, -1 , GV_IDX, BV_IDX, BV_IDX, -1 , GV_IDX, BV_IDX,
828  GY_IDX, -1 , GY_IDX, -1 , GY_IDX, -1 , GY_IDX, -1 ,
829  -1 , GY_IDX, -1 , GY_IDX, -1 , GY_IDX, -1 , GY_IDX,
832  GU_IDX, -1 , GU_IDX, -1 , GU_IDX, -1 , GU_IDX, -1 ,
833  -1 , GU_IDX, -1 , GU_IDX, -1 , GU_IDX, -1 , GU_IDX,
836  GV_IDX, -1 , GV_IDX, -1 , GV_IDX, -1 , GV_IDX, -1 ,
837  -1 , GV_IDX, -1 , GV_IDX, -1 , GV_IDX, -1 , GV_IDX, //23
838  -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //24
839  -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //25
840  -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //26
841  -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //27
842  -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //28
843  -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //29
844  -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //30
845  -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , //31
846  BY_IDX, GY_IDX, RY_IDX, -1 , -1 , -1 , -1 , -1 , //32
847  BU_IDX, GU_IDX, RU_IDX, -1 , -1 , -1 , -1 , -1 , //33
848  BV_IDX, GV_IDX, RV_IDX, -1 , -1 , -1 , -1 , -1 , //34
849  };
850 
851  dstRange = 0; //FIXME range = 1 is handled elsewhere
852 
853  if (!dstRange) {
854  cy = cy * 255 / 219;
855  } else {
856  vr = vr * 224 / 255;
857  ub = ub * 224 / 255;
858  ug = ug * 224 / 255;
859  vg = vg * 224 / 255;
860  }
861  W = ROUNDED_DIV(ONE*ONE*ug, ub);
862  V = ROUNDED_DIV(ONE*ONE*vg, vr);
863  Z = ONE*ONE-W-V;
864 
865  Cy = ROUNDED_DIV(cy*Z, ONE);
866  Cu = ROUNDED_DIV(ub*Z, ONE);
867  Cv = ROUNDED_DIV(vr*Z, ONE);
868 
869  c->input_rgb2yuv_table[RY_IDX] = -ROUNDED_DIV((1 << RGB2YUV_SHIFT)*V , Cy);
870  c->input_rgb2yuv_table[GY_IDX] = ROUNDED_DIV((1 << RGB2YUV_SHIFT)*ONE*ONE , Cy);
871  c->input_rgb2yuv_table[BY_IDX] = -ROUNDED_DIV((1 << RGB2YUV_SHIFT)*W , Cy);
872 
873  c->input_rgb2yuv_table[RU_IDX] = ROUNDED_DIV((1 << RGB2YUV_SHIFT)*V , Cu);
874  c->input_rgb2yuv_table[GU_IDX] = -ROUNDED_DIV((1 << RGB2YUV_SHIFT)*ONE*ONE , Cu);
875  c->input_rgb2yuv_table[BU_IDX] = ROUNDED_DIV((1 << RGB2YUV_SHIFT)*(Z+W) , Cu);
876 
877  c->input_rgb2yuv_table[RV_IDX] = ROUNDED_DIV((1 << RGB2YUV_SHIFT)*(V+Z) , Cv);
878  c->input_rgb2yuv_table[GV_IDX] = -ROUNDED_DIV((1 << RGB2YUV_SHIFT)*ONE*ONE , Cv);
879  c->input_rgb2yuv_table[BV_IDX] = ROUNDED_DIV((1 << RGB2YUV_SHIFT)*W , Cv);
880 
881  if(/*!dstRange && */table == ff_yuv2rgb_coeffs[SWS_CS_DEFAULT]) {
882  c->input_rgb2yuv_table[BY_IDX] = ((int)(0.114 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
883  c->input_rgb2yuv_table[BV_IDX] = (-(int)(0.081 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
884  c->input_rgb2yuv_table[BU_IDX] = ((int)(0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
885  c->input_rgb2yuv_table[GY_IDX] = ((int)(0.587 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
886  c->input_rgb2yuv_table[GV_IDX] = (-(int)(0.419 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
887  c->input_rgb2yuv_table[GU_IDX] = (-(int)(0.331 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
888  c->input_rgb2yuv_table[RY_IDX] = ((int)(0.299 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
889  c->input_rgb2yuv_table[RV_IDX] = ((int)(0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
890  c->input_rgb2yuv_table[RU_IDX] = (-(int)(0.169 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5));
891  }
892  for(i=0; i<FF_ARRAY_ELEMS(map); i++)
893  AV_WL16(p + 16*4 + 2*i, map[i] >= 0 ? c->input_rgb2yuv_table[map[i]] : 0);
894 }
895 
896 int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4],
897  int srcRange, const int table[4], int dstRange,
898  int brightness, int contrast, int saturation)
899 {
900  const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->dstFormat);
901  const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(c->srcFormat);
902  memcpy(c->srcColorspaceTable, inv_table, sizeof(int) * 4);
903  memcpy(c->dstColorspaceTable, table, sizeof(int) * 4);
904 
905  if(!isYUV(c->dstFormat) && !isGray(c->dstFormat))
906  dstRange = 0;
907  if(!isYUV(c->srcFormat) && !isGray(c->srcFormat))
908  srcRange = 0;
909 
910  c->brightness = brightness;
911  c->contrast = contrast;
912  c->saturation = saturation;
913  c->srcRange = srcRange;
914  c->dstRange = dstRange;
915 
916  if ((isYUV(c->dstFormat) || isGray(c->dstFormat)) && (isYUV(c->srcFormat) || isGray(c->srcFormat)))
917  return -1;
918 
919  c->dstFormatBpp = av_get_bits_per_pixel(desc_dst);
920  c->srcFormatBpp = av_get_bits_per_pixel(desc_src);
921 
922  if (!isYUV(c->dstFormat) && !isGray(c->dstFormat)) {
923  ff_yuv2rgb_c_init_tables(c, inv_table, srcRange, brightness,
924  contrast, saturation);
925  // FIXME factorize
926 
928  ff_yuv2rgb_init_tables_altivec(c, inv_table, brightness,
929  contrast, saturation);
930  }
931 
932  fill_rgb2yuv_table(c, table, dstRange);
933 
934  return 0;
935 }
936 
937 int sws_getColorspaceDetails(struct SwsContext *c, int **inv_table,
938  int *srcRange, int **table, int *dstRange,
939  int *brightness, int *contrast, int *saturation)
940 {
941  if (!c || isYUV(c->dstFormat) || isGray(c->dstFormat))
942  return -1;
943 
944  *inv_table = c->srcColorspaceTable;
945  *table = c->dstColorspaceTable;
946  *srcRange = c->srcRange;
947  *dstRange = c->dstRange;
948  *brightness = c->brightness;
949  *contrast = c->contrast;
950  *saturation = c->saturation;
951 
952  return 0;
953 }
954 
956 {
957  switch (*format) {
958  case AV_PIX_FMT_YUVJ420P:
959  *format = AV_PIX_FMT_YUV420P;
960  return 1;
961  case AV_PIX_FMT_YUVJ422P:
962  *format = AV_PIX_FMT_YUV422P;
963  return 1;
964  case AV_PIX_FMT_YUVJ444P:
965  *format = AV_PIX_FMT_YUV444P;
966  return 1;
967  case AV_PIX_FMT_YUVJ440P:
968  *format = AV_PIX_FMT_YUV440P;
969  return 1;
970  default:
971  return 0;
972  }
973 }
974 
976 {
977  switch (*format) {
978  case AV_PIX_FMT_0BGR : *format = AV_PIX_FMT_ABGR ; return 1;
979  case AV_PIX_FMT_BGR0 : *format = AV_PIX_FMT_BGRA ; return 4;
980  case AV_PIX_FMT_0RGB : *format = AV_PIX_FMT_ARGB ; return 1;
981  case AV_PIX_FMT_RGB0 : *format = AV_PIX_FMT_RGBA ; return 4;
982  default: return 0;
983  }
984 }
985 
987 {
988  SwsContext *c = av_mallocz(sizeof(SwsContext));
989 
990  if (c) {
993  }
994 
995  return c;
996 }
997 
999  SwsFilter *dstFilter)
1000 {
1001  int i, j;
1002  int usesVFilter, usesHFilter;
1003  int unscaled;
1004  SwsFilter dummyFilter = { NULL, NULL, NULL, NULL };
1005  int srcW = c->srcW;
1006  int srcH = c->srcH;
1007  int dstW = c->dstW;
1008  int dstH = c->dstH;
1009  int dst_stride = FFALIGN(dstW * sizeof(int16_t) + 66, 16);
1010  int flags, cpu_flags;
1011  enum AVPixelFormat srcFormat = c->srcFormat;
1012  enum AVPixelFormat dstFormat = c->dstFormat;
1013  const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(srcFormat);
1014  const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(dstFormat);
1015 
1016  cpu_flags = av_get_cpu_flags();
1017  flags = c->flags;
1018  emms_c();
1019  if (!rgb15to16)
1020  sws_rgb2rgb_init();
1021 
1022  unscaled = (srcW == dstW && srcH == dstH);
1023 
1024  handle_jpeg(&srcFormat);
1025  handle_jpeg(&dstFormat);
1026  handle_0alpha(&srcFormat);
1027  handle_0alpha(&dstFormat);
1028 
1029  if(srcFormat!=c->srcFormat || dstFormat!=c->dstFormat){
1030  av_log(c, AV_LOG_WARNING, "deprecated pixel format used, make sure you did set range correctly\n");
1031  c->srcFormat= srcFormat;
1032  c->dstFormat= dstFormat;
1033  }
1034 
1035  if (!sws_isSupportedInput(srcFormat)) {
1036  av_log(c, AV_LOG_ERROR, "%s is not supported as input pixel format\n",
1037  av_get_pix_fmt_name(srcFormat));
1038  return AVERROR(EINVAL);
1039  }
1040  if (!sws_isSupportedOutput(dstFormat)) {
1041  av_log(c, AV_LOG_ERROR, "%s is not supported as output pixel format\n",
1042  av_get_pix_fmt_name(dstFormat));
1043  return AVERROR(EINVAL);
1044  }
1045 
1046  i = flags & (SWS_POINT |
1047  SWS_AREA |
1048  SWS_BILINEAR |
1050  SWS_BICUBIC |
1051  SWS_X |
1052  SWS_GAUSS |
1053  SWS_LANCZOS |
1054  SWS_SINC |
1055  SWS_SPLINE |
1056  SWS_BICUBLIN);
1057  if (!i || (i & (i - 1))) {
1058  av_log(c, AV_LOG_ERROR, "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 
1070  if (!dstFilter)
1071  dstFilter = &dummyFilter;
1072  if (!srcFilter)
1073  srcFilter = &dummyFilter;
1074 
1075  c->lumXInc = (((int64_t)srcW << 16) + (dstW >> 1)) / dstW;
1076  c->lumYInc = (((int64_t)srcH << 16) + (dstH >> 1)) / dstH;
1077  c->dstFormatBpp = av_get_bits_per_pixel(desc_dst);
1078  c->srcFormatBpp = av_get_bits_per_pixel(desc_src);
1079  c->vRounder = 4 * 0x0001000100010001ULL;
1080 
1081  usesVFilter = (srcFilter->lumV && srcFilter->lumV->length > 1) ||
1082  (srcFilter->chrV && srcFilter->chrV->length > 1) ||
1083  (dstFilter->lumV && dstFilter->lumV->length > 1) ||
1084  (dstFilter->chrV && dstFilter->chrV->length > 1);
1085  usesHFilter = (srcFilter->lumH && srcFilter->lumH->length > 1) ||
1086  (srcFilter->chrH && srcFilter->chrH->length > 1) ||
1087  (dstFilter->lumH && dstFilter->lumH->length > 1) ||
1088  (dstFilter->chrH && dstFilter->chrH->length > 1);
1089 
1092 
1093  if (isAnyRGB(dstFormat) && !(flags&SWS_FULL_CHR_H_INT)) {
1094  if (dstW&1) {
1095  av_log(c, AV_LOG_DEBUG, "Forcing full internal H chroma due to odd output size\n");
1096  flags |= SWS_FULL_CHR_H_INT;
1097  c->flags = flags;
1098  }
1099  }
1100 
1101  if(dstFormat == AV_PIX_FMT_BGR4_BYTE ||
1102  dstFormat == AV_PIX_FMT_RGB4_BYTE ||
1103  dstFormat == AV_PIX_FMT_BGR8 ||
1104  dstFormat == AV_PIX_FMT_RGB8) {
1105  if (flags & SWS_ERROR_DIFFUSION && !(flags & SWS_FULL_CHR_H_INT)) {
1106  av_log(c, AV_LOG_DEBUG,
1107  "Error diffusion dither is only supported in full chroma interpolation for destination format '%s'\n",
1108  av_get_pix_fmt_name(dstFormat));
1109  flags |= SWS_FULL_CHR_H_INT;
1110  c->flags = flags;
1111  }
1112  if (!(flags & SWS_ERROR_DIFFUSION) && (flags & SWS_FULL_CHR_H_INT)) {
1113  av_log(c, AV_LOG_DEBUG,
1114  "Ordered dither is not supported in full chroma interpolation for destination format '%s'\n",
1115  av_get_pix_fmt_name(dstFormat));
1116  flags |= SWS_ERROR_DIFFUSION;
1117  c->flags = flags;
1118  }
1119  }
1120  if (isPlanarRGB(dstFormat)) {
1121  if (!(flags & SWS_FULL_CHR_H_INT)) {
1122  av_log(c, AV_LOG_DEBUG,
1123  "%s output is not supported with half chroma resolution, switching to full\n",
1124  av_get_pix_fmt_name(dstFormat));
1125  flags |= SWS_FULL_CHR_H_INT;
1126  c->flags = flags;
1127  }
1128  }
1129 
1130  /* reuse chroma for 2 pixels RGB/BGR unless user wants full
1131  * chroma interpolation */
1132  if (flags & SWS_FULL_CHR_H_INT &&
1133  isAnyRGB(dstFormat) &&
1134  !isPlanarRGB(dstFormat) &&
1135  dstFormat != AV_PIX_FMT_RGBA &&
1136  dstFormat != AV_PIX_FMT_ARGB &&
1137  dstFormat != AV_PIX_FMT_BGRA &&
1138  dstFormat != AV_PIX_FMT_ABGR &&
1139  dstFormat != AV_PIX_FMT_RGB24 &&
1140  dstFormat != AV_PIX_FMT_BGR24 &&
1141  dstFormat != AV_PIX_FMT_BGR4_BYTE &&
1142  dstFormat != AV_PIX_FMT_RGB4_BYTE &&
1143  dstFormat != AV_PIX_FMT_BGR8 &&
1144  dstFormat != AV_PIX_FMT_RGB8
1145  ) {
1147  "full chroma interpolation for destination format '%s' not yet implemented\n",
1148  av_get_pix_fmt_name(dstFormat));
1149  flags &= ~SWS_FULL_CHR_H_INT;
1150  c->flags = flags;
1151  }
1152  if (isAnyRGB(dstFormat) && !(flags & SWS_FULL_CHR_H_INT))
1153  c->chrDstHSubSample = 1;
1154 
1155  // drop some chroma lines if the user wants it
1156  c->vChrDrop = (flags & SWS_SRC_V_CHR_DROP_MASK) >>
1158  c->chrSrcVSubSample += c->vChrDrop;
1159 
1160  /* drop every other pixel for chroma calculation unless user
1161  * wants full chroma */
1162  if (isAnyRGB(srcFormat) && !(flags & SWS_FULL_CHR_H_INP) &&
1163  srcFormat != AV_PIX_FMT_RGB8 && srcFormat != AV_PIX_FMT_BGR8 &&
1164  srcFormat != AV_PIX_FMT_RGB4 && srcFormat != AV_PIX_FMT_BGR4 &&
1165  srcFormat != AV_PIX_FMT_RGB4_BYTE && srcFormat != AV_PIX_FMT_BGR4_BYTE &&
1166  srcFormat != AV_PIX_FMT_GBRP9BE && srcFormat != AV_PIX_FMT_GBRP9LE &&
1167  srcFormat != AV_PIX_FMT_GBRP10BE && srcFormat != AV_PIX_FMT_GBRP10LE &&
1168  srcFormat != AV_PIX_FMT_GBRP12BE && srcFormat != AV_PIX_FMT_GBRP12LE &&
1169  srcFormat != AV_PIX_FMT_GBRP14BE && srcFormat != AV_PIX_FMT_GBRP14LE &&
1170  srcFormat != AV_PIX_FMT_GBRP16BE && srcFormat != AV_PIX_FMT_GBRP16LE &&
1171  ((dstW >> c->chrDstHSubSample) <= (srcW >> 1) ||
1172  (flags & SWS_FAST_BILINEAR)))
1173  c->chrSrcHSubSample = 1;
1174 
1175  // Note the -((-x)>>y) is so that we always round toward +inf.
1176  c->chrSrcW = -((-srcW) >> c->chrSrcHSubSample);
1177  c->chrSrcH = -((-srcH) >> c->chrSrcVSubSample);
1178  c->chrDstW = -((-dstW) >> c->chrDstHSubSample);
1179  c->chrDstH = -((-dstH) >> c->chrDstVSubSample);
1180 
1181  FF_ALLOC_OR_GOTO(c, c->formatConvBuffer, FFALIGN(srcW*2+78, 16) * 2, fail);
1182 
1183  /* unscaled special cases */
1184  if (unscaled && !usesHFilter && !usesVFilter &&
1185  (c->srcRange == c->dstRange || isAnyRGB(dstFormat))) {
1187 
1188  if (c->swScale) {
1189  if (flags & SWS_PRINT_INFO)
1190  av_log(c, AV_LOG_INFO,
1191  "using unscaled %s -> %s special converter\n",
1192  av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat));
1193  return 0;
1194  }
1195  }
1196 
1197  c->srcBpc = 1 + desc_src->comp[0].depth_minus1;
1198  if (c->srcBpc < 8)
1199  c->srcBpc = 8;
1200  c->dstBpc = 1 + desc_dst->comp[0].depth_minus1;
1201  if (c->dstBpc < 8)
1202  c->dstBpc = 8;
1203  if (isAnyRGB(srcFormat) || srcFormat == AV_PIX_FMT_PAL8)
1204  c->srcBpc = 16;
1205  if (c->dstBpc == 16)
1206  dst_stride <<= 1;
1207 
1208  if (INLINE_MMXEXT(cpu_flags) && c->srcBpc == 8 && c->dstBpc <= 14) {
1209  c->canMMXEXTBeUsed = (dstW >= srcW && (dstW & 31) == 0 &&
1210  (srcW & 15) == 0) ? 1 : 0;
1211  if (!c->canMMXEXTBeUsed && dstW >= srcW && (srcW & 15) == 0
1212 
1213  && (flags & SWS_FAST_BILINEAR)) {
1214  if (flags & SWS_PRINT_INFO)
1215  av_log(c, AV_LOG_INFO,
1216  "output width is not a multiple of 32 -> no MMXEXT scaler\n");
1217  }
1218  if (usesHFilter || isNBPS(c->srcFormat) || is16BPS(c->srcFormat) || isAnyRGB(c->srcFormat))
1219  c->canMMXEXTBeUsed = 0;
1220  } else
1221  c->canMMXEXTBeUsed = 0;
1222 
1223  c->chrXInc = (((int64_t)c->chrSrcW << 16) + (c->chrDstW >> 1)) / c->chrDstW;
1224  c->chrYInc = (((int64_t)c->chrSrcH << 16) + (c->chrDstH >> 1)) / c->chrDstH;
1225 
1226  /* Match pixel 0 of the src to pixel 0 of dst and match pixel n-2 of src
1227  * to pixel n-2 of dst, but only for the FAST_BILINEAR mode otherwise do
1228  * correct scaling.
1229  * n-2 is the last chrominance sample available.
1230  * This is not perfect, but no one should notice the difference, the more
1231  * correct variant would be like the vertical one, but that would require
1232  * some special code for the first and last pixel */
1233  if (flags & SWS_FAST_BILINEAR) {
1234  if (c->canMMXEXTBeUsed) {
1235  c->lumXInc += 20;
1236  c->chrXInc += 20;
1237  }
1238  // we don't use the x86 asm scaler if MMX is available
1239  else if (INLINE_MMX(cpu_flags) && c->dstBpc <= 14) {
1240  c->lumXInc = ((int64_t)(srcW - 2) << 16) / (dstW - 2) - 20;
1241  c->chrXInc = ((int64_t)(c->chrSrcW - 2) << 16) / (c->chrDstW - 2) - 20;
1242  }
1243  }
1244 
1245 #define USE_MMAP (HAVE_MMAP && HAVE_MPROTECT && defined MAP_ANONYMOUS)
1246 
1247  /* precalculate horizontal scaler filter coefficients */
1248  {
1249 #if HAVE_MMXEXT_INLINE
1250 // can't downscale !!!
1251  if (c->canMMXEXTBeUsed && (flags & SWS_FAST_BILINEAR)) {
1252  c->lumMmxextFilterCodeSize = init_hscaler_mmxext(dstW, c->lumXInc, NULL,
1253  NULL, NULL, 8);
1254  c->chrMmxextFilterCodeSize = init_hscaler_mmxext(c->chrDstW, c->chrXInc,
1255  NULL, NULL, NULL, 4);
1256 
1257 #if USE_MMAP
1258  c->lumMmxextFilterCode = mmap(NULL, c->lumMmxextFilterCodeSize,
1259  PROT_READ | PROT_WRITE,
1260  MAP_PRIVATE | MAP_ANONYMOUS,
1261  -1, 0);
1262  c->chrMmxextFilterCode = mmap(NULL, c->chrMmxextFilterCodeSize,
1263  PROT_READ | PROT_WRITE,
1264  MAP_PRIVATE | MAP_ANONYMOUS,
1265  -1, 0);
1266 #elif HAVE_VIRTUALALLOC
1267  c->lumMmxextFilterCode = VirtualAlloc(NULL,
1269  MEM_COMMIT,
1270  PAGE_EXECUTE_READWRITE);
1271  c->chrMmxextFilterCode = VirtualAlloc(NULL,
1273  MEM_COMMIT,
1274  PAGE_EXECUTE_READWRITE);
1275 #else
1278 #endif
1279 
1280 #ifdef MAP_ANONYMOUS
1281  if (c->lumMmxextFilterCode == MAP_FAILED || c->chrMmxextFilterCode == MAP_FAILED)
1282 #else
1284 #endif
1285  {
1286  av_log(c, AV_LOG_ERROR, "Failed to allocate MMX2FilterCode\n");
1287  return AVERROR(ENOMEM);
1288  }
1289 
1290  FF_ALLOCZ_OR_GOTO(c, c->hLumFilter, (dstW / 8 + 8) * sizeof(int16_t), fail);
1291  FF_ALLOCZ_OR_GOTO(c, c->hChrFilter, (c->chrDstW / 4 + 8) * sizeof(int16_t), fail);
1292  FF_ALLOCZ_OR_GOTO(c, c->hLumFilterPos, (dstW / 2 / 8 + 8) * sizeof(int32_t), fail);
1293  FF_ALLOCZ_OR_GOTO(c, c->hChrFilterPos, (c->chrDstW / 2 / 4 + 8) * sizeof(int32_t), fail);
1294 
1295  init_hscaler_mmxext( dstW, c->lumXInc, c->lumMmxextFilterCode,
1296  c->hLumFilter, (uint32_t*)c->hLumFilterPos, 8);
1297  init_hscaler_mmxext(c->chrDstW, c->chrXInc, c->chrMmxextFilterCode,
1298  c->hChrFilter, (uint32_t*)c->hChrFilterPos, 4);
1299 
1300 #if USE_MMAP
1301  mprotect(c->lumMmxextFilterCode, c->lumMmxextFilterCodeSize, PROT_EXEC | PROT_READ);
1302  mprotect(c->chrMmxextFilterCode, c->chrMmxextFilterCodeSize, PROT_EXEC | PROT_READ);
1303 #endif
1304  } else
1305 #endif /* HAVE_MMXEXT_INLINE */
1306  {
1307  const int filterAlign =
1308  (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? 4 :
1309  (HAVE_ALTIVEC && cpu_flags & AV_CPU_FLAG_ALTIVEC) ? 8 :
1310  1;
1311 
1312  if (initFilter(&c->hLumFilter, &c->hLumFilterPos,
1313  &c->hLumFilterSize, c->lumXInc,
1314  srcW, dstW, filterAlign, 1 << 14,
1315  (flags & SWS_BICUBLIN) ? (flags | SWS_BICUBIC) : flags,
1316  cpu_flags, srcFilter->lumH, dstFilter->lumH,
1317  c->param) < 0)
1318  goto fail;
1319  if (initFilter(&c->hChrFilter, &c->hChrFilterPos,
1320  &c->hChrFilterSize, c->chrXInc,
1321  c->chrSrcW, c->chrDstW, filterAlign, 1 << 14,
1322  (flags & SWS_BICUBLIN) ? (flags | SWS_BILINEAR) : flags,
1323  cpu_flags, srcFilter->chrH, dstFilter->chrH,
1324  c->param) < 0)
1325  goto fail;
1326  }
1327  } // initialize horizontal stuff
1328 
1329  /* precalculate vertical scaler filter coefficients */
1330  {
1331  const int filterAlign =
1332  (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? 2 :
1333  (HAVE_ALTIVEC && cpu_flags & AV_CPU_FLAG_ALTIVEC) ? 8 :
1334  1;
1335 
1337  c->lumYInc, srcH, dstH, filterAlign, (1 << 12),
1338  (flags & SWS_BICUBLIN) ? (flags | SWS_BICUBIC) : flags,
1339  cpu_flags, srcFilter->lumV, dstFilter->lumV,
1340  c->param) < 0)
1341  goto fail;
1343  c->chrYInc, c->chrSrcH, c->chrDstH,
1344  filterAlign, (1 << 12),
1345  (flags & SWS_BICUBLIN) ? (flags | SWS_BILINEAR) : flags,
1346  cpu_flags, srcFilter->chrV, dstFilter->chrV,
1347  c->param) < 0)
1348  goto fail;
1349 
1350 #if HAVE_ALTIVEC
1351  FF_ALLOC_OR_GOTO(c, c->vYCoeffsBank, sizeof(vector signed short) * c->vLumFilterSize * c->dstH, fail);
1352  FF_ALLOC_OR_GOTO(c, c->vCCoeffsBank, sizeof(vector signed short) * c->vChrFilterSize * c->chrDstH, fail);
1353 
1354  for (i = 0; i < c->vLumFilterSize * c->dstH; i++) {
1355  int j;
1356  short *p = (short *)&c->vYCoeffsBank[i];
1357  for (j = 0; j < 8; j++)
1358  p[j] = c->vLumFilter[i];
1359  }
1360 
1361  for (i = 0; i < c->vChrFilterSize * c->chrDstH; i++) {
1362  int j;
1363  short *p = (short *)&c->vCCoeffsBank[i];
1364  for (j = 0; j < 8; j++)
1365  p[j] = c->vChrFilter[i];
1366  }
1367 #endif
1368  }
1369 
1370  // calculate buffer sizes so that they won't run out while handling these damn slices
1371  c->vLumBufSize = c->vLumFilterSize;
1372  c->vChrBufSize = c->vChrFilterSize;
1373  for (i = 0; i < dstH; i++) {
1374  int chrI = (int64_t)i * c->chrDstH / dstH;
1375  int nextSlice = FFMAX(c->vLumFilterPos[i] + c->vLumFilterSize - 1,
1376  ((c->vChrFilterPos[chrI] + c->vChrFilterSize - 1)
1377  << c->chrSrcVSubSample));
1378 
1379  nextSlice >>= c->chrSrcVSubSample;
1380  nextSlice <<= c->chrSrcVSubSample;
1381  if (c->vLumFilterPos[i] + c->vLumBufSize < nextSlice)
1382  c->vLumBufSize = nextSlice - c->vLumFilterPos[i];
1383  if (c->vChrFilterPos[chrI] + c->vChrBufSize <
1384  (nextSlice >> c->chrSrcVSubSample))
1385  c->vChrBufSize = (nextSlice >> c->chrSrcVSubSample) -
1386  c->vChrFilterPos[chrI];
1387  }
1388 
1389  for (i = 0; i < 4; i++)
1390  FF_ALLOCZ_OR_GOTO(c, c->dither_error[i], (c->dstW+2) * sizeof(int), fail);
1391 
1392  /* Allocate pixbufs (we use dynamic allocation because otherwise we would
1393  * need to allocate several megabytes to handle all possible cases) */
1394  FF_ALLOC_OR_GOTO(c, c->lumPixBuf, c->vLumBufSize * 3 * sizeof(int16_t *), fail);
1395  FF_ALLOC_OR_GOTO(c, c->chrUPixBuf, c->vChrBufSize * 3 * sizeof(int16_t *), fail);
1396  FF_ALLOC_OR_GOTO(c, c->chrVPixBuf, c->vChrBufSize * 3 * sizeof(int16_t *), fail);
1398  FF_ALLOCZ_OR_GOTO(c, c->alpPixBuf, c->vLumBufSize * 3 * sizeof(int16_t *), fail);
1399  /* Note we need at least one pixel more at the end because of the MMX code
1400  * (just in case someone wants to replace the 4000/8000). */
1401  /* align at 16 bytes for AltiVec */
1402  for (i = 0; i < c->vLumBufSize; i++) {
1403  FF_ALLOCZ_OR_GOTO(c, c->lumPixBuf[i + c->vLumBufSize],
1404  dst_stride + 16, fail);
1405  c->lumPixBuf[i] = c->lumPixBuf[i + c->vLumBufSize];
1406  }
1407  // 64 / c->scalingBpp is the same as 16 / sizeof(scaling_intermediate)
1408  c->uv_off = (dst_stride>>1) + 64 / (c->dstBpc &~ 7);
1409  c->uv_offx2 = dst_stride + 16;
1410  for (i = 0; i < c->vChrBufSize; i++) {
1411  FF_ALLOC_OR_GOTO(c, c->chrUPixBuf[i + c->vChrBufSize],
1412  dst_stride * 2 + 32, fail);
1413  c->chrUPixBuf[i] = c->chrUPixBuf[i + c->vChrBufSize];
1414  c->chrVPixBuf[i] = c->chrVPixBuf[i + c->vChrBufSize]
1415  = c->chrUPixBuf[i] + (dst_stride >> 1) + 8;
1416  }
1417  if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf)
1418  for (i = 0; i < c->vLumBufSize; i++) {
1419  FF_ALLOCZ_OR_GOTO(c, c->alpPixBuf[i + c->vLumBufSize],
1420  dst_stride + 16, fail);
1421  c->alpPixBuf[i] = c->alpPixBuf[i + c->vLumBufSize];
1422  }
1423 
1424  // try to avoid drawing green stuff between the right end and the stride end
1425  for (i = 0; i < c->vChrBufSize; i++)
1426  if(desc_dst->comp[0].depth_minus1 == 15){
1427  av_assert0(c->dstBpc > 14);
1428  for(j=0; j<dst_stride/2+1; j++)
1429  ((int32_t*)(c->chrUPixBuf[i]))[j] = 1<<18;
1430  } else
1431  for(j=0; j<dst_stride+1; j++)
1432  ((int16_t*)(c->chrUPixBuf[i]))[j] = 1<<14;
1433 
1434  av_assert0(c->chrDstH <= dstH);
1435 
1436  if (flags & SWS_PRINT_INFO) {
1437  if (flags & SWS_FAST_BILINEAR)
1438  av_log(c, AV_LOG_INFO, "FAST_BILINEAR scaler, ");
1439  else if (flags & SWS_BILINEAR)
1440  av_log(c, AV_LOG_INFO, "BILINEAR scaler, ");
1441  else if (flags & SWS_BICUBIC)
1442  av_log(c, AV_LOG_INFO, "BICUBIC scaler, ");
1443  else if (flags & SWS_X)
1444  av_log(c, AV_LOG_INFO, "Experimental scaler, ");
1445  else if (flags & SWS_POINT)
1446  av_log(c, AV_LOG_INFO, "Nearest Neighbor / POINT scaler, ");
1447  else if (flags & SWS_AREA)
1448  av_log(c, AV_LOG_INFO, "Area Averaging scaler, ");
1449  else if (flags & SWS_BICUBLIN)
1450  av_log(c, AV_LOG_INFO, "luma BICUBIC / chroma BILINEAR scaler, ");
1451  else if (flags & SWS_GAUSS)
1452  av_log(c, AV_LOG_INFO, "Gaussian scaler, ");
1453  else if (flags & SWS_SINC)
1454  av_log(c, AV_LOG_INFO, "Sinc scaler, ");
1455  else if (flags & SWS_LANCZOS)
1456  av_log(c, AV_LOG_INFO, "Lanczos scaler, ");
1457  else if (flags & SWS_SPLINE)
1458  av_log(c, AV_LOG_INFO, "Bicubic spline scaler, ");
1459  else
1460  av_log(c, AV_LOG_INFO, "ehh flags invalid?! ");
1461 
1462  av_log(c, AV_LOG_INFO, "from %s to %s%s ",
1463  av_get_pix_fmt_name(srcFormat),
1464 #ifdef DITHER1XBPP
1465  dstFormat == AV_PIX_FMT_BGR555 || dstFormat == AV_PIX_FMT_BGR565 ||
1466  dstFormat == AV_PIX_FMT_RGB444BE || dstFormat == AV_PIX_FMT_RGB444LE ||
1467  dstFormat == AV_PIX_FMT_BGR444BE || dstFormat == AV_PIX_FMT_BGR444LE ?
1468  "dithered " : "",
1469 #else
1470  "",
1471 #endif
1472  av_get_pix_fmt_name(dstFormat));
1473 
1474  if (INLINE_MMXEXT(cpu_flags))
1475  av_log(c, AV_LOG_INFO, "using MMXEXT\n");
1476  else if (INLINE_AMD3DNOW(cpu_flags))
1477  av_log(c, AV_LOG_INFO, "using 3DNOW\n");
1478  else if (INLINE_MMX(cpu_flags))
1479  av_log(c, AV_LOG_INFO, "using MMX\n");
1480  else if (HAVE_ALTIVEC && cpu_flags & AV_CPU_FLAG_ALTIVEC)
1481  av_log(c, AV_LOG_INFO, "using AltiVec\n");
1482  else
1483  av_log(c, AV_LOG_INFO, "using C\n");
1484 
1485  av_log(c, AV_LOG_VERBOSE, "%dx%d -> %dx%d\n", srcW, srcH, dstW, dstH);
1486  av_log(c, AV_LOG_DEBUG,
1487  "lum srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n",
1488  c->srcW, c->srcH, c->dstW, c->dstH, c->lumXInc, c->lumYInc);
1489  av_log(c, AV_LOG_DEBUG,
1490  "chr srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n",
1491  c->chrSrcW, c->chrSrcH, c->chrDstW, c->chrDstH,
1492  c->chrXInc, c->chrYInc);
1493  }
1494 
1495  c->swScale = ff_getSwsFunc(c);
1496  return 0;
1497 fail: // FIXME replace things by appropriate error codes
1498  return -1;
1499 }
1500 
1501 #if FF_API_SWS_GETCONTEXT
1502 SwsContext *sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat,
1503  int dstW, int dstH, enum AVPixelFormat dstFormat,
1504  int flags, SwsFilter *srcFilter,
1505  SwsFilter *dstFilter, const double *param)
1506 {
1507  SwsContext *c;
1508 
1509  if (!(c = sws_alloc_context()))
1510  return NULL;
1511 
1512  c->flags = flags;
1513  c->srcW = srcW;
1514  c->srcH = srcH;
1515  c->dstW = dstW;
1516  c->dstH = dstH;
1517  c->srcRange = handle_jpeg(&srcFormat);
1518  c->dstRange = handle_jpeg(&dstFormat);
1519  c->src0Alpha = handle_0alpha(&srcFormat);
1520  c->dst0Alpha = handle_0alpha(&dstFormat);
1521  c->srcFormat = srcFormat;
1522  c->dstFormat = dstFormat;
1523 
1524  if (param) {
1525  c->param[0] = param[0];
1526  c->param[1] = param[1];
1527  }
1528  sws_setColorspaceDetails(c, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT], c->srcRange,
1529  ff_yuv2rgb_coeffs[SWS_CS_DEFAULT] /* FIXME*/,
1530  c->dstRange, 0, 1 << 16, 1 << 16);
1531 
1532  if (sws_init_context(c, srcFilter, dstFilter) < 0) {
1533  sws_freeContext(c);
1534  return NULL;
1535  }
1536 
1537  return c;
1538 }
1539 #endif
1540 
1541 SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,
1542  float lumaSharpen, float chromaSharpen,
1543  float chromaHShift, float chromaVShift,
1544  int verbose)
1545 {
1546  SwsFilter *filter = av_malloc(sizeof(SwsFilter));
1547  if (!filter)
1548  return NULL;
1549 
1550  if (lumaGBlur != 0.0) {
1551  filter->lumH = sws_getGaussianVec(lumaGBlur, 3.0);
1552  filter->lumV = sws_getGaussianVec(lumaGBlur, 3.0);
1553  } else {
1554  filter->lumH = sws_getIdentityVec();
1555  filter->lumV = sws_getIdentityVec();
1556  }
1557 
1558  if (chromaGBlur != 0.0) {
1559  filter->chrH = sws_getGaussianVec(chromaGBlur, 3.0);
1560  filter->chrV = sws_getGaussianVec(chromaGBlur, 3.0);
1561  } else {
1562  filter->chrH = sws_getIdentityVec();
1563  filter->chrV = sws_getIdentityVec();
1564  }
1565 
1566  if (chromaSharpen != 0.0) {
1567  SwsVector *id = sws_getIdentityVec();
1568  sws_scaleVec(filter->chrH, -chromaSharpen);
1569  sws_scaleVec(filter->chrV, -chromaSharpen);
1570  sws_addVec(filter->chrH, id);
1571  sws_addVec(filter->chrV, id);
1572  sws_freeVec(id);
1573  }
1574 
1575  if (lumaSharpen != 0.0) {
1576  SwsVector *id = sws_getIdentityVec();
1577  sws_scaleVec(filter->lumH, -lumaSharpen);
1578  sws_scaleVec(filter->lumV, -lumaSharpen);
1579  sws_addVec(filter->lumH, id);
1580  sws_addVec(filter->lumV, id);
1581  sws_freeVec(id);
1582  }
1583 
1584  if (chromaHShift != 0.0)
1585  sws_shiftVec(filter->chrH, (int)(chromaHShift + 0.5));
1586 
1587  if (chromaVShift != 0.0)
1588  sws_shiftVec(filter->chrV, (int)(chromaVShift + 0.5));
1589 
1590  sws_normalizeVec(filter->chrH, 1.0);
1591  sws_normalizeVec(filter->chrV, 1.0);
1592  sws_normalizeVec(filter->lumH, 1.0);
1593  sws_normalizeVec(filter->lumV, 1.0);
1594 
1595  if (verbose)
1596  sws_printVec2(filter->chrH, NULL, AV_LOG_DEBUG);
1597  if (verbose)
1598  sws_printVec2(filter->lumH, NULL, AV_LOG_DEBUG);
1599 
1600  return filter;
1601 }
1602 
1604 {
1605  SwsVector *vec;
1606 
1607  if(length <= 0 || length > INT_MAX/ sizeof(double))
1608  return NULL;
1609 
1610  vec = av_malloc(sizeof(SwsVector));
1611  if (!vec)
1612  return NULL;
1613  vec->length = length;
1614  vec->coeff = av_malloc(sizeof(double) * length);
1615  if (!vec->coeff)
1616  av_freep(&vec);
1617  return vec;
1618 }
1619 
1620 SwsVector *sws_getGaussianVec(double variance, double quality)
1621 {
1622  const int length = (int)(variance * quality + 0.5) | 1;
1623  int i;
1624  double middle = (length - 1) * 0.5;
1625  SwsVector *vec;
1626 
1627  if(variance < 0 || quality < 0)
1628  return NULL;
1629 
1630  vec = sws_allocVec(length);
1631 
1632  if (!vec)
1633  return NULL;
1634 
1635  for (i = 0; i < length; i++) {
1636  double dist = i - middle;
1637  vec->coeff[i] = exp(-dist * dist / (2 * variance * variance)) /
1638  sqrt(2 * variance * M_PI);
1639  }
1640 
1641  sws_normalizeVec(vec, 1.0);
1642 
1643  return vec;
1644 }
1645 
1647 {
1648  int i;
1649  SwsVector *vec = sws_allocVec(length);
1650 
1651  if (!vec)
1652  return NULL;
1653 
1654  for (i = 0; i < length; i++)
1655  vec->coeff[i] = c;
1656 
1657  return vec;
1658 }
1659 
1661 {
1662  return sws_getConstVec(1.0, 1);
1663 }
1664 
1665 static double sws_dcVec(SwsVector *a)
1666 {
1667  int i;
1668  double sum = 0;
1669 
1670  for (i = 0; i < a->length; i++)
1671  sum += a->coeff[i];
1672 
1673  return sum;
1674 }
1675 
1676 void sws_scaleVec(SwsVector *a, double scalar)
1677 {
1678  int i;
1679 
1680  for (i = 0; i < a->length; i++)
1681  a->coeff[i] *= scalar;
1682 }
1683 
1685 {
1686  sws_scaleVec(a, height / sws_dcVec(a));
1687 }
1688 
1690 {
1691  int length = a->length + b->length - 1;
1692  int i, j;
1693  SwsVector *vec = sws_getConstVec(0.0, length);
1694 
1695  if (!vec)
1696  return NULL;
1697 
1698  for (i = 0; i < a->length; i++) {
1699  for (j = 0; j < b->length; j++) {
1700  vec->coeff[i + j] += a->coeff[i] * b->coeff[j];
1701  }
1702  }
1703 
1704  return vec;
1705 }
1706 
1708 {
1709  int length = FFMAX(a->length, b->length);
1710  int i;
1711  SwsVector *vec = sws_getConstVec(0.0, length);
1712 
1713  if (!vec)
1714  return NULL;
1715 
1716  for (i = 0; i < a->length; i++)
1717  vec->coeff[i + (length - 1) / 2 - (a->length - 1) / 2] += a->coeff[i];
1718  for (i = 0; i < b->length; i++)
1719  vec->coeff[i + (length - 1) / 2 - (b->length - 1) / 2] += b->coeff[i];
1720 
1721  return vec;
1722 }
1723 
1725 {
1726  int length = FFMAX(a->length, b->length);
1727  int i;
1728  SwsVector *vec = sws_getConstVec(0.0, length);
1729 
1730  if (!vec)
1731  return NULL;
1732 
1733  for (i = 0; i < a->length; i++)
1734  vec->coeff[i + (length - 1) / 2 - (a->length - 1) / 2] += a->coeff[i];
1735  for (i = 0; i < b->length; i++)
1736  vec->coeff[i + (length - 1) / 2 - (b->length - 1) / 2] -= b->coeff[i];
1737 
1738  return vec;
1739 }
1740 
1741 /* shift left / or right if "shift" is negative */
1743 {
1744  int length = a->length + FFABS(shift) * 2;
1745  int i;
1746  SwsVector *vec = sws_getConstVec(0.0, length);
1747 
1748  if (!vec)
1749  return NULL;
1750 
1751  for (i = 0; i < a->length; i++) {
1752  vec->coeff[i + (length - 1) / 2 -
1753  (a->length - 1) / 2 - shift] = a->coeff[i];
1754  }
1755 
1756  return vec;
1757 }
1758 
1760 {
1761  SwsVector *shifted = sws_getShiftedVec(a, shift);
1762  av_free(a->coeff);
1763  a->coeff = shifted->coeff;
1764  a->length = shifted->length;
1765  av_free(shifted);
1766 }
1767 
1769 {
1770  SwsVector *sum = sws_sumVec(a, b);
1771  av_free(a->coeff);
1772  a->coeff = sum->coeff;
1773  a->length = sum->length;
1774  av_free(sum);
1775 }
1776 
1778 {
1779  SwsVector *diff = sws_diffVec(a, b);
1780  av_free(a->coeff);
1781  a->coeff = diff->coeff;
1782  a->length = diff->length;
1783  av_free(diff);
1784 }
1785 
1787 {
1788  SwsVector *conv = sws_getConvVec(a, b);
1789  av_free(a->coeff);
1790  a->coeff = conv->coeff;
1791  a->length = conv->length;
1792  av_free(conv);
1793 }
1794 
1796 {
1797  int i;
1798  SwsVector *vec = sws_allocVec(a->length);
1799 
1800  if (!vec)
1801  return NULL;
1802 
1803  for (i = 0; i < a->length; i++)
1804  vec->coeff[i] = a->coeff[i];
1805 
1806  return vec;
1807 }
1808 
1809 void sws_printVec2(SwsVector *a, AVClass *log_ctx, int log_level)
1810 {
1811  int i;
1812  double max = 0;
1813  double min = 0;
1814  double range;
1815 
1816  for (i = 0; i < a->length; i++)
1817  if (a->coeff[i] > max)
1818  max = a->coeff[i];
1819 
1820  for (i = 0; i < a->length; i++)
1821  if (a->coeff[i] < min)
1822  min = a->coeff[i];
1823 
1824  range = max - min;
1825 
1826  for (i = 0; i < a->length; i++) {
1827  int x = (int)((a->coeff[i] - min) * 60.0 / range + 0.5);
1828  av_log(log_ctx, log_level, "%1.3f ", a->coeff[i]);
1829  for (; x > 0; x--)
1830  av_log(log_ctx, log_level, " ");
1831  av_log(log_ctx, log_level, "|\n");
1832  }
1833 }
1834 
1836 {
1837  if (!a)
1838  return;
1839  av_freep(&a->coeff);
1840  a->length = 0;
1841  av_free(a);
1842 }
1843 
1845 {
1846  if (!filter)
1847  return;
1848 
1849  if (filter->lumH)
1850  sws_freeVec(filter->lumH);
1851  if (filter->lumV)
1852  sws_freeVec(filter->lumV);
1853  if (filter->chrH)
1854  sws_freeVec(filter->chrH);
1855  if (filter->chrV)
1856  sws_freeVec(filter->chrV);
1857  av_free(filter);
1858 }
1859 
1861 {
1862  int i;
1863  if (!c)
1864  return;
1865 
1866  if (c->lumPixBuf) {
1867  for (i = 0; i < c->vLumBufSize; i++)
1868  av_freep(&c->lumPixBuf[i]);
1869  av_freep(&c->lumPixBuf);
1870  }
1871 
1872  if (c->chrUPixBuf) {
1873  for (i = 0; i < c->vChrBufSize; i++)
1874  av_freep(&c->chrUPixBuf[i]);
1875  av_freep(&c->chrUPixBuf);
1876  av_freep(&c->chrVPixBuf);
1877  }
1878 
1879  if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {
1880  for (i = 0; i < c->vLumBufSize; i++)
1881  av_freep(&c->alpPixBuf[i]);
1882  av_freep(&c->alpPixBuf);
1883  }
1884 
1885  for (i = 0; i < 4; i++)
1886  av_freep(&c->dither_error[i]);
1887 
1888  av_freep(&c->vLumFilter);
1889  av_freep(&c->vChrFilter);
1890  av_freep(&c->hLumFilter);
1891  av_freep(&c->hChrFilter);
1892 #if HAVE_ALTIVEC
1893  av_freep(&c->vYCoeffsBank);
1894  av_freep(&c->vCCoeffsBank);
1895 #endif
1896 
1897  av_freep(&c->vLumFilterPos);
1898  av_freep(&c->vChrFilterPos);
1899  av_freep(&c->hLumFilterPos);
1900  av_freep(&c->hChrFilterPos);
1901 
1902 #if HAVE_MMX_INLINE
1903 #if USE_MMAP
1904  if (c->lumMmxextFilterCode)
1906  if (c->chrMmxextFilterCode)
1908 #elif HAVE_VIRTUALALLOC
1909  if (c->lumMmxextFilterCode)
1910  VirtualFree(c->lumMmxextFilterCode, 0, MEM_RELEASE);
1911  if (c->chrMmxextFilterCode)
1912  VirtualFree(c->chrMmxextFilterCode, 0, MEM_RELEASE);
1913 #else
1916 #endif
1919 #endif /* HAVE_MMX_INLINE */
1920 
1921  av_freep(&c->yuvTable);
1923 
1924  av_free(c);
1925 }
1926 
1927 struct SwsContext *sws_getCachedContext(struct SwsContext *context, int srcW,
1928  int srcH, enum AVPixelFormat srcFormat,
1929  int dstW, int dstH,
1930  enum AVPixelFormat dstFormat, int flags,
1931  SwsFilter *srcFilter,
1932  SwsFilter *dstFilter,
1933  const double *param)
1934 {
1935  static const double default_param[2] = { SWS_PARAM_DEFAULT,
1937 
1938  if (!param)
1939  param = default_param;
1940 
1941  if (context &&
1942  (context->srcW != srcW ||
1943  context->srcH != srcH ||
1944  context->srcFormat != srcFormat ||
1945  context->dstW != dstW ||
1946  context->dstH != dstH ||
1947  context->dstFormat != dstFormat ||
1948  context->flags != flags ||
1949  context->param[0] != param[0] ||
1950  context->param[1] != param[1])) {
1951  sws_freeContext(context);
1952  context = NULL;
1953  }
1954 
1955  if (!context) {
1956  if (!(context = sws_alloc_context()))
1957  return NULL;
1958  context->srcW = srcW;
1959  context->srcH = srcH;
1960  context->srcRange = handle_jpeg(&srcFormat);
1961  context->src0Alpha = handle_0alpha(&srcFormat);
1962  context->srcFormat = srcFormat;
1963  context->dstW = dstW;
1964  context->dstH = dstH;
1965  context->dstRange = handle_jpeg(&dstFormat);
1966  context->dst0Alpha = handle_0alpha(&dstFormat);
1967  context->dstFormat = dstFormat;
1968  context->flags = flags;
1969  context->param[0] = param[0];
1970  context->param[1] = param[1];
1971  sws_setColorspaceDetails(context, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT],
1972  context->srcRange,
1973  ff_yuv2rgb_coeffs[SWS_CS_DEFAULT] /* FIXME*/,
1974  context->dstRange, 0, 1 << 16, 1 << 16);
1975  if (sws_init_context(context, srcFilter, dstFilter) < 0) {
1976  sws_freeContext(context);
1977  return NULL;
1978  }
1979  }
1980  return context;
1981 }
SwsFilter * sws_getDefaultFilter(float lumaGBlur, float chromaGBlur, float lumaSharpen, float chromaSharpen, float chromaHShift, float chromaVShift, int verbose)
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:85
SwsVector * chrV
Definition: swscale.h:132
int16_t ** alpPixBuf
Ring buffer for scaled horizontal alpha plane lines to be fed to the vertical scaler.
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:205
static const FormatEntry format_entries[AV_PIX_FMT_NB]
planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:158
#define AV_CPU_FLAG_ALTIVEC
standard
Definition: cpu.h:52
float v
planar YUV 4:4:4,42bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:231
#define SWS_POINT
Definition: swscale.h:62
void sws_freeVec(SwsVector *a)
av_cold void ff_yuv2rgb_init_tables_altivec(SwsContext *c, const int inv_table[4], int brightness, int contrast, int saturation)
SwsContext * sws_alloc_context(void)
Allocate an empty SwsContext.
static SwsVector * sws_sumVec(SwsVector *a, SwsVector *b)
static int shift(int a, int b)
Definition: sonic.c:86
static int handle_0alpha(enum AVPixelFormat *format)
planar YUV 4:2:0,21bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:224
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1778
int chrSrcH
Height of source chroma planes.
static av_always_inline int isPlanarRGB(enum AVPixelFormat pix_fmt)
#define LIBSWSCALE_VERSION_MICRO
#define RV_IDX
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)
planar YUV 4:2:2,28bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:228
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:151
#define BV_IDX
static int conv(int samples, float **pcm, char *buf, int channels)
Definition: libvorbisdec.c:111
#define C
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:212
const char * sws_format_name(enum AVPixelFormat format)
uint8_t * lumMmxextFilterCode
Runtime-generated MMXEXT horizontal fast bilinear scaler code for luma/alpha planes.
#define B
Definition: dsputil.c:2025
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:73
SwsVector * lumV
Definition: swscale.h:130
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:70
const char * swscale_configuration(void)
Return the libswscale build-time configuration.
packed RGB 1:2:1 bitstream, 4bpp, (msb)1B 2G 1R(lsb), a byte contains two pixels, the first pixel in ...
Definition: pixfmt.h:88
if max(w)>1 w=0.9 *w/max(w)
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:154
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:1731
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:154
#define SWS_SRC_V_CHR_DROP_MASK
Definition: swscale.h:70
void sws_shiftVec(SwsVector *a, int shift)
planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:229
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:942
int vChrDrop
Binary logarithm of extra vertical subsampling factor in source image chroma planes specified by user...
int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation)
Definition: yuv2rgb.c:706
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
int sws_getColorspaceDetails(struct SwsContext *c, int **inv_table, int *srcRange, int **table, int *dstRange, int *brightness, int *contrast, int *saturation)
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:211
packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), little-endian, most significant bit to 0 ...
Definition: pixfmt.h:117
#define SWS_FAST_BILINEAR
Definition: swscale.h:58
static double getSplineCoeff(double a, double b, double c, double d, double dist)
#define HAVE_ALTIVEC
Definition: config.h:56
#define SWS_BICUBIC
Definition: swscale.h:60
#define GV_IDX
location of range
int dstFormatBpp
Number of bits per pixel of the destination pixel format.
#define SWS_FULL_CHR_H_INT
Definition: swscale.h:79
planar YUV 4:4:4 40bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Definition: pixfmt.h:195
static av_always_inline int is16BPS(enum AVPixelFormat pix_fmt)
external API header
static int handle_jpeg(enum AVPixelFormat *format)
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), little-endian
Definition: pixfmt.h:120
planar GBR 4:4:4 36bpp, little-endian
Definition: pixfmt.h:234
planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:148
packed RGB 4:4:4, 16bpp, (msb)4A 4R 4G 4B(lsb), big-endian, most significant bits to 0 ...
Definition: pixfmt.h:138
#define FF_ARRAY_ELEMS(a)
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.
packed BGR 8:8:8, 32bpp, 0BGR0BGR...
Definition: pixfmt.h:216
int srcRange
0 = MPG YUV range, 1 = JPG YUV range (source image).
void sws_convVec(SwsVector *a, SwsVector *b)
#define SWS_SPLINE
Definition: swscale.h:68
SwsFunc swScale
Note that src, dst, srcStride, dstStride will be copied in the sws_scale() wrapper so they can be fre...
planar GBR 4:4:4 36bpp, big-endian
Definition: pixfmt.h:233
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:128
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:66
packed RGB 1:2:1 bitstream, 4bpp, (msb)1R 2G 1B(lsb), a byte contains two pixels, the first pixel in ...
Definition: pixfmt.h:91
#define FFMPEG_LICENSE
Definition: config.h:5
Macro definitions for various function/variable attributes.
#define FFALIGN(x, a)
Definition: common.h:63
#define SWS_SINC
Definition: swscale.h:66
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
unsigned swscale_version(void)
Return the LIBSWSCALE_VERSION_INT constant.
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
Definition: pixfmt.h:115
set threshold d
int srcH
Height of source luma/alpha planes.
packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb)
Definition: pixfmt.h:89
planar YUV 4:2:0 22.5bpp, (1 Cr & Cb sample per 2x2 Y & A samples), little-endian ...
Definition: pixfmt.h:185
#define RU_IDX
#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:196
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:105
int chrDstVSubSample
Binary logarithm of vertical subsampling factor between luma/alpha and chroma planes in destination i...
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:86
uint8_t
#define av_cold
Definition: attributes.h:78
int length
number of coefficients in the vector
Definition: swscale.h:124
packed RGB 8:8:8, 32bpp, RGB0RGB0...
Definition: pixfmt.h:215
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:112
int vChrFilterSize
Vertical filter size for chroma pixels.
#define b
Definition: input.c:42
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:209
int16_t ** lumPixBuf
Ring buffer for scaled horizontal luma plane lines to be fed to the vertical scaler.
av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter)
Initialize the swscaler context sws_context.
packed RGB 4:4:4, 16bpp, (msb)4A 4R 4G 4B(lsb), little-endian, most significant bits to 0 ...
Definition: pixfmt.h:137
planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:230
#define emms_c()
void sws_normalizeVec(SwsVector *a, double height)
Scale all the coefficients of a so that their sum equals height.
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian
Definition: pixfmt.h:114
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:98
planar YUV 4:2:0 40bpp, (1 Cr & Cb sample per 2x2 Y & A samples, little-endian)
Definition: pixfmt.h:197
the mask is usually to keep the same permissions Filters should remove permissions on reference they give to output whenever necessary It can be automatically done by setting the rej_perms field on the output pad Here are a few guidelines corresponding to common then the filter should push the output frames on the output link immediately As an exception to the previous rule if the input frame is enough to produce several output frames then the filter needs output only at least one per link The additional frames can be left buffered in the filter
void sws_scaleVec(SwsVector *a, double scalar)
Scale all the coefficients of a by the scalar value.
#define SWS_BITEXACT
Definition: swscale.h:84
planar GBR 4:4:4 48bpp, big-endian
Definition: pixfmt.h:173
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of PIX_FMT_YUV440P and setting color_range ...
Definition: pixfmt.h:104
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...
Definition: pixfmt.h:81
#define SWS_BICUBLIN
Definition: swscale.h:64
planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, big-endian)
Definition: pixfmt.h:200
enum AVPixelFormat pix_fmt
Definition: v4l.c:63
integer sqrt
Definition: avutil.txt:2
#define isAnyRGB(x)
external API header
enum AVPixelFormat dstFormat
Destination pixel format.
#define isALPHA(x)
Definition: swscale-test.c:47
#define A(x)
int chrSrcHSubSample
Binary logarithm of horizontal subsampling factor between luma/alpha and chroma planes in source imag...
static av_always_inline int isYUV(enum AVPixelFormat pix_fmt)
static SwsVector * sws_getShiftedVec(SwsVector *a, int shift)
const char * name
Definition: pixdesc.h:56
#define ONE
Definition: jrevdct.c:132
#define ROUNDED_DIV(a, b)
Definition: common.h:50
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:149
Discrete Time axis x
planar GBR 4:4:4 27bpp, big-endian
Definition: pixfmt.h:169
#define INLINE_MMX(flags)
Definition: x86/cpu.h:46
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:157
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:219
uint16_t depth_minus1
number of bits in the component minus 1
Definition: pixdesc.h:43
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:183
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.
const char * swscale_license(void)
Return the libswscale license.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:75
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:133
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:755
#define AV_WL16(p, darg)
Definition: intreadwrite.h:250
static const struct endianess table[]
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)
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:99
planar YUV 4:4:4 36bpp, (1 Cr & Cb sample per 1x1 Y & A samples), big-endian
Definition: pixfmt.h:188
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:153
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:93
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:227
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
SwsVector * sws_allocVec(int length)
Allocate and return an uninitialized vector with length coefficients.
init variable d2
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:131
#define SWS_X
Definition: swscale.h:61
#define SWS_PARAM_DEFAULT
Definition: swscale.h:73
int vChrBufSize
Number of vertical chroma lines allocated in the ring buffer.
av_cold void sws_rgb2rgb_init(void)
Definition: rgb2rgb.c:129
planar YUV 4:4:4 36bpp, (1 Cr & Cb sample per 1x1 Y & A samples), little-endian
Definition: pixfmt.h:189
#define FFMAX(a, b)
Definition: common.h:56
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:96
int chrDstW
Width of destination chroma planes.
SwsVector * lumH
Definition: swscale.h:129
#define SWS_FULL_CHR_H_INP
Definition: swscale.h:81
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:143
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:97
#define isNBPS(x)
planar YUV 4:2:0 25bpp, (1 Cr & Cb sample per 2x2 Y & A samples, big-endian)
Definition: pixfmt.h:190
int verbose
#define LICENSE_PREFIX
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:72
void sws_addVec(SwsVector *a, SwsVector *b)
int sws_isSupportedInput(enum AVPixelFormat pix_fmt)
Return a positive value if pix_fmt is a supported input format, 0 otherwise.
int32_t * hLumFilterPos
Array of horizontal filter starting positions for each dst[i] for luma/alpha planes.
int hChrFilterSize
Horizontal filter size for chroma pixels.
#define AV_LOG_VERBOSE
Definition: log.h:157
as above, but U and V bytes are swapped
Definition: pixfmt.h:94
int dstRange
0 = MPG YUV range, 1 = JPG YUV range (destination image).
#define RGB2YUV_SHIFT
#define V
#define SWS_ERROR_DIFFUSION
Definition: swscale.h:85
#define APCK_SIZE
#define FFMIN(a, b)
Definition: common.h:58
packed RGB 1:2:1, 8bpp, (msb)1R 2G 1B(lsb)
Definition: pixfmt.h:92
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
Definition: pixfmt.h:80
SwsVector * chrH
Definition: swscale.h:131
uint8_t * formatConvBuffer
#define INLINE_AMD3DNOW(flags)
Definition: x86/cpu.h:44
SwsVector * sws_getIdentityVec(void)
Allocate and return a vector with just one coefficient, with value 1.0.
int vLumBufSize
Number of vertical luma/alpha lines allocated in the ring buffer.
ret
Definition: avfilter.c:821
int16_t ** chrUPixBuf
Ring buffer for scaled horizontal chroma plane lines to be fed to the vertical scaler.
int32_t
#define RY_IDX
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate.The lists are not just lists
#define SWS_ACCURATE_RND
Definition: swscale.h:83
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about quality
planar YUV 4:4:4 40bpp, (1 Cr & Cb sample per 1x1 Y & A samples, big-endian)
Definition: pixfmt.h:194
#define FFABS(a)
Definition: common.h:53
planar YUV 4:2:2 27bpp, (1 Cr & Cb sample per 2x1 Y & A samples), big-endian
Definition: pixfmt.h:186
SwsVector * sws_cloneVec(SwsVector *a)
Allocate and return a clone of the vector a, that is a vector with the same coefficients as a...
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:222
#define diff(a, as, b, bs)
Definition: vf_phase.c:80
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:150
static int cpu_flags
Definition: dct-test.c:77
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:159
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:142
#define DITHER1XBPP
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), big-endian
Definition: pixfmt.h:119
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.
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:273
for k
1i.*Xphase exp()
NULL
Definition: eval.c:55
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition: pixfmt.h:87
double * coeff
pointer to the list of coefficients
Definition: swscale.h:123
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:129
int dstColorspaceTable[4]
const AVClass * av_class
info on struct for av_log
int sws_isSupportedOutput(enum AVPixelFormat pix_fmt)
Return a positive value if pix_fmt is a supported output format, 0 otherwise.
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:218
#define SWS_GAUSS
Definition: swscale.h:65
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:55
#define SWS_SRC_V_CHR_DROP_SHIFT
Definition: swscale.h:71
planar GBR 4:4:4 30bpp, big-endian
Definition: pixfmt.h:171
#define AV_CPU_FLAG_MMX
standard MMX
Definition: cpu.h:29
planar YUV 4:2:2 48bpp, (1 Cr & Cb sample per 2x1 Y & A samples, big-endian)
Definition: pixfmt.h:198
int chrDstH
Height of destination chroma planes.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
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:236
static void getSubSampleFactors(int *h, int *v, enum AVPixelFormat format)
BYTE int const BYTE int int int height
Definition: avisynth_c.h:713
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:199
static SwsVector * sws_diffVec(SwsVector *a, SwsVector *b)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:73
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:50
planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Definition: pixfmt.h:201
#define RET
Y , 16bpp, big-endian.
Definition: pixfmt.h:101
synthesis window for stochastic i
int vLumFilterSize
Vertical filter size for luma/alpha pixels.
byte swapping routines
#define SWS_CS_DEFAULT
Definition: swscale.h:109
planar YUV 4:2:0,21bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:223
packed BGR 8:8:8, 32bpp, BGR0BGR0...
Definition: pixfmt.h:217
int chrMmxextFilterCodeSize
Runtime-generated MMXEXT horizontal fast bilinear scaler code size for chroma planes.
static const double coeff[2][5]
Definition: vf_ow.c:64
planar GBR 4:4:4 42bpp, big-endian
Definition: pixfmt.h:235
planar YUV 4:2:0 22.5bpp, (1 Cr & Cb sample per 2x2 Y & A samples), big-endian
Definition: pixfmt.h:184
packed BGR 5:5:5, 16bpp, (msb)1A 5B 5G 5R(lsb), little-endian, most significant bit to 1 ...
Definition: pixfmt.h:122
int16_t * vChrFilter
Array of vertical filter coefficients for chroma planes.
#define isGray(x)
Definition: swscale-test.c:38
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:30
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
SwsVector * sws_getConstVec(double c, int length)
Allocate and return a vector with length coefficients, all with the same value c. ...
int16_t * hLumFilter
Array of horizontal filter coefficients for luma/alpha planes.
#define GY_IDX
#define AV_PIX_FMT_BGR565
Definition: pixfmt.h:272
#define AV_PIX_FMT_Y400A
Definition: pixfmt.h:250
#define LOCAL_MANGLE(a)
planar YUV 4:2:2 30bpp, (1 Cr & Cb sample per 2x1 Y & A samples, little-endian)
Definition: pixfmt.h:193
static int flags
Definition: cpu.c:23
packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), big-endian, most significant bit to 0 ...
Definition: pixfmt.h:116
packed BGR 4:4:4, 16bpp, (msb)4A 4B 4G 4R(lsb), big-endian, most significant bits to 1 ...
Definition: pixfmt.h:140
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:155
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:132
const AVClass sws_context_class
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: x86/cpu.h:47
static double sws_dcVec(SwsVector *a)
#define CONFIG_SWSCALE_ALPHA
Definition: config.h:394
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:226
Y , 8bpp.
Definition: pixfmt.h:76
double param[2]
Input parameters for scaling algorithms that need them.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:162
Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb...
Definition: pixfmt.h:77
#define FF_ALLOC_OR_GOTO(ctx, p, size, label)
planar GBR 4:4:4 27bpp, little-endian
Definition: pixfmt.h:170
static double c[64]
static 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])
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:111
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:130
#define SWS_BILINEAR
Definition: swscale.h:59
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_...
Definition: pixfmt.h:82
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
Definition: pixfmt.h:90
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:75
planar YUV 4:2:0 25bpp, (1 Cr & Cb sample per 2x2 Y & A samples, little-endian)
Definition: pixfmt.h:191
#define FFMPEG_CONFIGURATION
Definition: config.h:4
#define SWS_AREA
Definition: swscale.h:63
#define MAX_FILTER_SIZE
int x86_reg
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.
planar YUV 4:4:4,42bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:232
#define av_log2
Definition: intmath.h:89
int srcFormatBpp
Number of bits per pixel of the source pixel format.
#define SWS_MAX_REDUCE_CUTOFF
Definition: swscale.h:101
#define SWS_LANCZOS
Definition: swscale.h:67
Y , 16bpp, little-endian.
Definition: pixfmt.h:102
struct FormatEntry FormatEntry
void sws_freeFilter(SwsFilter *filter)
planar YUV 4:2:2 30bpp, (1 Cr & Cb sample per 2x1 Y & A samples, big-endian)
Definition: pixfmt.h:192
packed BGR 5:5:5, 16bpp, (msb)1A 5B 5G 5R(lsb), big-endian, most significant bit to 1 ...
Definition: pixfmt.h:121
number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of...
Definition: pixfmt.h:237
int16_t * vLumFilter
Array of vertical filter coefficients for luma/alpha planes.
#define AV_LOG_INFO
Definition: log.h:156
#define GU_IDX
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:103
void sws_freeContext(SwsContext *c)
Free the swscaler context swsContext.
#define M_PI
Definition: mathematics.h:46
planar GBR 4:4:4 48bpp, little-endian
Definition: pixfmt.h:174
int16_t * hChrFilter
Array of horizontal filter coefficients for chroma planes.
packed BGR 4:4:4, 16bpp, (msb)4A 4B 4G 4R(lsb), little-endian, most significant bits to 1 ...
Definition: pixfmt.h:139
const char int length
Definition: avisynth_c.h:668
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:1700
planar YUV 4:2:2 27bpp, (1 Cr & Cb sample per 2x1 Y & A samples), little-endian
Definition: pixfmt.h:187
#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...
void sws_subVec(SwsVector *a, SwsVector *b)
packed RGB 8:8:8, 32bpp, 0RGB0RGB...
Definition: pixfmt.h:214
int srcW
Width of source luma/alpha planes.
packed YUV 4:1:1, 12bpp, Cb Y0 Y1 Cr Y2 Y3
Definition: pixfmt.h:86
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
planar YUV 4:2:0,18bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:221
#define SWS_PRINT_INFO
Definition: swscale.h:75
void(* rgb15to16)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:51
#define BU_IDX
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:156
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:225
#define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)
planar GBR 4:4:4 30bpp, little-endian
Definition: pixfmt.h:172
const int32_t ff_yuv2rgb_coeffs[8][4]
Definition: yuv2rgb.c:45
static SwsVector * sws_getConvVec(SwsVector *a, SwsVector *b)
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:210
#define HAVE_MMX
Definition: config.h:48
normalize window W
Definition: stft_peak.m:10
#define LIBSWSCALE_VERSION_INT
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:152