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