FFmpeg
swscale.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2024 Nikles Haas
3  * Copyright (C) 2003-2011 Michael Niedermayer <michaelni@gmx.at>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <inttypes.h>
26 #include <stdarg.h>
27 
28 #undef HAVE_AV_CONFIG_H
29 #include "libavutil/cpu.h"
30 #include "libavutil/pixdesc.h"
31 #include "libavutil/lfg.h"
32 #include "libavutil/sfc64.h"
33 #include "libavutil/frame.h"
34 #include "libavutil/opt.h"
35 #include "libavutil/time.h"
36 #include "libavutil/pixfmt.h"
37 #include "libavutil/avassert.h"
38 #include "libavutil/macros.h"
39 
40 #include "libswscale/swscale.h"
41 
42 struct options {
45  double prob;
46  int w, h;
47  int threads;
48  int iters;
49  int bench;
50 };
51 
52 struct mode {
55 };
56 
57 const struct mode modes[] = {
59  { SWS_BILINEAR },
60  { SWS_BICUBIC },
61  { SWS_X | SWS_BITEXACT },
62  { SWS_POINT },
65  {0}, // test defaults
66 };
67 
69 static SwsContext *sws[3]; /* reused between tests for efficiency */
70 
71 static int fmt_comps(enum AVPixelFormat fmt)
72 {
74  int comps = desc->nb_components >= 3 ? 0b111 : 0b1;
75  if (desc->flags & AV_PIX_FMT_FLAG_ALPHA)
76  comps |= 0b1000;
77  return comps;
78 }
79 
80 static void get_mse(int mse[4], const AVFrame *a, const AVFrame *b, int comps)
81 {
82  av_assert1(a->format == AV_PIX_FMT_YUVA420P);
83  av_assert1(b->format == a->format);
84  av_assert1(b->width == a->width && b->height == a->height);
85 
86  for (int p = 0; p < 4; p++) {
87  const int is_chroma = p == 1 || p == 2;
88  const int stride_a = a->linesize[p];
89  const int stride_b = b->linesize[p];
90  const int w = (a->width + is_chroma) >> is_chroma;
91  const int h = (a->height + is_chroma) >> is_chroma;
92  uint64_t sum = 0;
93 
94  if (comps & (1 << p)) {
95  for (int y = 0; y < h; y++) {
96  for (int x = 0; x < w; x++) {
97  int d = a->data[p][y * stride_a + x] - b->data[p][y * stride_b + x];
98  sum += d * d;
99  }
100  }
101  } else {
102  const int ref = is_chroma ? 128 : 0xFF;
103  for (int y = 0; y < h; y++) {
104  for (int x = 0; x < w; x++) {
105  int d = a->data[p][y * stride_a + x] - ref;
106  sum += d * d;
107  }
108  }
109  }
110 
111  mse[p] = sum / (w * h);
112  }
113 }
114 
115 static int scale_legacy(AVFrame *dst, const AVFrame *src, struct mode mode,
116  struct options opts)
117 {
118  SwsContext *sws_legacy;
119  int ret;
120 
121  sws_legacy = sws_alloc_context();
122  if (!sws_legacy)
123  return -1;
124 
125  sws_legacy->src_w = src->width;
126  sws_legacy->src_h = src->height;
127  sws_legacy->src_format = src->format;
128  sws_legacy->dst_w = dst->width;
129  sws_legacy->dst_h = dst->height;
130  sws_legacy->dst_format = dst->format;
131  sws_legacy->flags = mode.flags;
132  sws_legacy->dither = mode.dither;
133  sws_legacy->threads = opts.threads;
134 
135  if ((ret = sws_init_context(sws_legacy, NULL, NULL)) < 0)
136  goto error;
137 
138  for (int i = 0; ret >= 0 && i < opts.iters; i++)
139  ret = sws_scale_frame(sws_legacy, dst, src);
140 
141 error:
142  sws_freeContext(sws_legacy);
143  return ret;
144 }
145 
146 /* Runs a series of ref -> src -> dst -> out, and compares out vs ref */
147 static int run_test(enum AVPixelFormat src_fmt, enum AVPixelFormat dst_fmt,
148  int dst_w, int dst_h, struct mode mode, struct options opts,
149  const AVFrame *ref, const int mse_ref[4])
150 {
151  AVFrame *src = NULL, *dst = NULL, *out = NULL;
152  int mse[4], mse_sws[4], ret = -1;
153  const int comps = fmt_comps(src_fmt) & fmt_comps(dst_fmt);
154  int64_t time, time_ref = 0;
155 
156  src = av_frame_alloc();
157  dst = av_frame_alloc();
158  out = av_frame_alloc();
159  if (!src || !dst || !out)
160  goto error;
161 
165  src->width = out->width = ref->width;
166  src->height = out->height = ref->height;
167  out->format = ref->format;
168  src->format = src_fmt;
169  dst->format = dst_fmt;
170  dst->width = dst_w;
171  dst->height = dst_h;
172 
173  if (sws_scale_frame(sws[0], src, ref) < 0) {
174  fprintf(stderr, "Failed %s ---> %s\n", av_get_pix_fmt_name(ref->format),
175  av_get_pix_fmt_name(src->format));
176  goto error;
177  }
178 
179  sws[1]->flags = mode.flags;
180  sws[1]->dither = mode.dither;
181  sws[1]->threads = opts.threads;
182 
183  time = av_gettime_relative();
184 
185  for (int i = 0; i < opts.iters; i++) {
186  if (sws_scale_frame(sws[1], dst, src) < 0) {
187  fprintf(stderr, "Failed %s ---> %s\n", av_get_pix_fmt_name(src->format),
188  av_get_pix_fmt_name(dst->format));
189  goto error;
190  }
191  }
192 
193  time = av_gettime_relative() - time;
194 
195  if (sws_scale_frame(sws[2], out, dst) < 0) {
196  fprintf(stderr, "Failed %s ---> %s\n", av_get_pix_fmt_name(dst->format),
197  av_get_pix_fmt_name(out->format));
198  goto error;
199  }
200 
201  get_mse(mse, out, ref, comps);
202  printf("%s %dx%d -> %s %3dx%3d, flags=%u dither=%u, "
203  "MSE={%5d %5d %5d %5d}\n",
204  av_get_pix_fmt_name(src->format), src->width, src->height,
205  av_get_pix_fmt_name(dst->format), dst->width, dst->height,
207  mse[0], mse[1], mse[2], mse[3]);
208 
209  if (!mse_ref) {
210  /* Compare against the legacy swscale API as a reference */
211  time_ref = av_gettime_relative();
212  if (scale_legacy(dst, src, mode, opts) < 0) {
213  fprintf(stderr, "Failed ref %s ---> %s\n", av_get_pix_fmt_name(src->format),
214  av_get_pix_fmt_name(dst->format));
215  goto error;
216  }
217  time_ref = av_gettime_relative() - time_ref;
218 
219  if (sws_scale_frame(sws[2], out, dst) < 0)
220  goto error;
221 
222  get_mse(mse_sws, out, ref, comps);
223  mse_ref = mse_sws;
224  }
225 
226  for (int i = 0; i < 4; i++) {
227  if (mse[i] > mse_ref[i]) {
228  int bad = mse[i] > mse_ref[i] * 1.02 + 1;
229  printf("\033[1;31m %s, ref MSE={%5d %5d %5d %5d}\033[0m\n",
230  bad ? "WORSE" : "worse",
231  mse_ref[0], mse_ref[1], mse_ref[2], mse_ref[3]);
232  if (bad)
233  goto error;
234  break;
235  }
236  }
237 
238  if (opts.bench && time_ref) {
239  printf(" time=%"PRId64" us, ref=%"PRId64" us, speedup=%.3fx %s\n",
240  time / opts.iters, time_ref / opts.iters,
241  (double) time_ref / time,
242  time <= time_ref ? "faster" : "\033[1;33mslower\033[0m");
243  } else if (opts.bench) {
244  printf(" time=%"PRId64" us\n", time / opts.iters);
245  }
246 
247  fflush(stdout);
248  ret = 0; /* fall through */
249  error:
250  av_frame_free(&src);
251  av_frame_free(&dst);
252  av_frame_free(&out);
253  return ret;
254 }
255 
256 static int run_self_tests(const AVFrame *ref, struct options opts)
257 {
258  const int dst_w[] = { opts.w, opts.w - opts.w / 3, opts.w + opts.w / 3 };
259  const int dst_h[] = { opts.h, opts.h - opts.h / 3, opts.h + opts.h / 3 };
260 
261  enum AVPixelFormat src_fmt, dst_fmt,
262  src_fmt_min = 0,
263  dst_fmt_min = 0,
264  src_fmt_max = AV_PIX_FMT_NB - 1,
265  dst_fmt_max = AV_PIX_FMT_NB - 1;
266 
267  if (opts.src_fmt != AV_PIX_FMT_NONE)
268  src_fmt_min = src_fmt_max = opts.src_fmt;
269  if (opts.dst_fmt != AV_PIX_FMT_NONE)
270  dst_fmt_min = dst_fmt_max = opts.dst_fmt;
271 
272  for (src_fmt = src_fmt_min; src_fmt <= src_fmt_max; src_fmt++) {
273  if (!sws_test_format(src_fmt, 0) || !sws_test_format(src_fmt, 1))
274  continue;
275  for (dst_fmt = dst_fmt_min; dst_fmt <= dst_fmt_max; dst_fmt++) {
276  if (!sws_test_format(dst_fmt, 0) || !sws_test_format(dst_fmt, 1))
277  continue;
278  for (int h = 0; h < FF_ARRAY_ELEMS(dst_h); h++)
279  for (int w = 0; w < FF_ARRAY_ELEMS(dst_w); w++)
280  for (int m = 0; m < FF_ARRAY_ELEMS(modes); m++) {
281  if (ff_sfc64_get(&prng_state) > UINT64_MAX * opts.prob)
282  continue;
283 
284  if (run_test(src_fmt, dst_fmt, dst_w[w], dst_h[h],
285  modes[m], opts, ref, NULL) < 0)
286  return -1;
287  }
288  }
289  }
290 
291  return 0;
292 }
293 
294 static int run_file_tests(const AVFrame *ref, FILE *fp, struct options opts)
295 {
296  char buf[256];
297  int ret;
298 
299  while (fgets(buf, sizeof(buf), fp)) {
300  char src_fmt_str[20], dst_fmt_str[20];
301  enum AVPixelFormat src_fmt;
302  enum AVPixelFormat dst_fmt;
303  int sw, sh, dw, dh, mse[4];
304  struct mode mode;
305 
306  ret = sscanf(buf,
307  " %20s %dx%d -> %20s %dx%d, flags=%u dither=%u, "
308  "MSE={%d %d %d %d}\n",
309  src_fmt_str, &sw, &sh, dst_fmt_str, &dw, &dh,
310  &mode.flags, &mode.dither,
311  &mse[0], &mse[1], &mse[2], &mse[3]);
312  if (ret != 12) {
313  printf("%s", buf);
314  continue;
315  }
316 
317  src_fmt = av_get_pix_fmt(src_fmt_str);
318  dst_fmt = av_get_pix_fmt(dst_fmt_str);
319  if (src_fmt == AV_PIX_FMT_NONE || dst_fmt == AV_PIX_FMT_NONE ||
320  sw != ref->width || sh != ref->height || dw > 8192 || dh > 8192 ||
322  fprintf(stderr, "malformed input file\n");
323  return -1;
324  }
325 
326  if (opts.src_fmt != AV_PIX_FMT_NONE && src_fmt != opts.src_fmt ||
327  opts.dst_fmt != AV_PIX_FMT_NONE && dst_fmt != opts.dst_fmt)
328  continue;
329 
330  if (run_test(src_fmt, dst_fmt, dw, dh, mode, opts, ref, mse) < 0)
331  return -1;
332  }
333 
334  return 0;
335 }
336 
337 int main(int argc, char **argv)
338 {
339  struct options opts = {
340  .src_fmt = AV_PIX_FMT_NONE,
341  .dst_fmt = AV_PIX_FMT_NONE,
342  .w = 96,
343  .h = 96,
344  .threads = 1,
345  .iters = 1,
346  .prob = 1.0,
347  };
348 
349  AVFrame *rgb = NULL, *ref = NULL;
350  FILE *fp = NULL;
351  AVLFG rand;
352  int ret = -1;
353 
354  for (int i = 1; i < argc; i += 2) {
355  if (!strcmp(argv[i], "-help") || !strcmp(argv[i], "--help")) {
356  fprintf(stderr,
357  "swscale [options...]\n"
358  " -help\n"
359  " This text\n"
360  " -ref <file>\n"
361  " Uses file as reference to compare tests againsts. Tests that have become worse will contain the string worse or WORSE\n"
362  " -p <number between 0.0 and 1.0>\n"
363  " The percentage of tests or comparisons to perform. Doing all tests will take long and generate over a hundred MB text output\n"
364  " It is often convenient to perform a random subset\n"
365  " -dst <pixfmt>\n"
366  " Only test the specified destination pixel format\n"
367  " -src <pixfmt>\n"
368  " Only test the specified source pixel format\n"
369  " -bench <iters>\n"
370  " Run benchmarks with the specified number of iterations. This mode also increases the size of the test images\n"
371  " -threads <threads>\n"
372  " Use the specified number of threads\n"
373  " -cpuflags <cpuflags>\n"
374  " Uses the specified cpuflags in the tests\n"
375  );
376  return 0;
377  }
378  if (argv[i][0] != '-' || i + 1 == argc)
379  goto bad_option;
380  if (!strcmp(argv[i], "-ref")) {
381  fp = fopen(argv[i + 1], "r");
382  if (!fp) {
383  fprintf(stderr, "could not open '%s'\n", argv[i + 1]);
384  goto error;
385  }
386  } else if (!strcmp(argv[i], "-cpuflags")) {
387  unsigned flags = av_get_cpu_flags();
388  int res = av_parse_cpu_caps(&flags, argv[i + 1]);
389  if (res < 0) {
390  fprintf(stderr, "invalid cpu flags %s\n", argv[i + 1]);
391  goto error;
392  }
394  } else if (!strcmp(argv[i], "-src")) {
395  opts.src_fmt = av_get_pix_fmt(argv[i + 1]);
396  if (opts.src_fmt == AV_PIX_FMT_NONE) {
397  fprintf(stderr, "invalid pixel format %s\n", argv[i + 1]);
398  goto error;
399  }
400  } else if (!strcmp(argv[i], "-dst")) {
401  opts.dst_fmt = av_get_pix_fmt(argv[i + 1]);
402  if (opts.dst_fmt == AV_PIX_FMT_NONE) {
403  fprintf(stderr, "invalid pixel format %s\n", argv[i + 1]);
404  goto error;
405  }
406  } else if (!strcmp(argv[i], "-bench")) {
407  opts.bench = 1;
408  opts.iters = atoi(argv[i + 1]);
409  opts.iters = FFMAX(opts.iters, 1);
410  opts.w = 1920;
411  opts.h = 1080;
412  } else if (!strcmp(argv[i], "-threads")) {
413  opts.threads = atoi(argv[i + 1]);
414  } else if (!strcmp(argv[i], "-p")) {
415  opts.prob = atof(argv[i + 1]);
416  } else {
417 bad_option:
418  fprintf(stderr, "bad option or argument missing (%s) see -help\n", argv[i]);
419  goto error;
420  }
421  }
422 
423  ff_sfc64_init(&prng_state, 0, 0, 0, 12);
424  av_lfg_init(&rand, 1);
425 
426  for (int i = 0; i < 3; i++) {
427  sws[i] = sws_alloc_context();
428  if (!sws[i])
429  goto error;
430  sws[i]->flags = SWS_BILINEAR;
431  }
432 
433  rgb = av_frame_alloc();
434  if (!rgb)
435  goto error;
436  rgb->width = opts.w / 12;
437  rgb->height = opts.h / 12;
438  rgb->format = AV_PIX_FMT_RGBA;
439  if (av_frame_get_buffer(rgb, 32) < 0)
440  goto error;
441 
442  for (int y = 0; y < rgb->height; y++) {
443  for (int x = 0; x < rgb->width; x++) {
444  for (int c = 0; c < 4; c++)
445  rgb->data[0][y * rgb->linesize[0] + x * 4 + c] = av_lfg_get(&rand);
446  }
447  }
448 
449  ref = av_frame_alloc();
450  if (!ref)
451  goto error;
452  ref->width = opts.w;
453  ref->height = opts.h;
454  ref->format = AV_PIX_FMT_YUVA420P;
455 
456  if (sws_scale_frame(sws[0], ref, rgb) < 0)
457  goto error;
458 
459  ret = fp ? run_file_tests(ref, fp, opts)
460  : run_self_tests(ref, opts);
461 
462  /* fall through */
463 error:
464  for (int i = 0; i < 3; i++)
466  av_frame_free(&rgb);
467  av_frame_free(&ref);
468  if (fp)
469  fclose(fp);
470  return ret;
471 }
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:32
av_force_cpu_flags
void av_force_cpu_flags(int arg)
Disables cpu detection and forces the specified flags.
Definition: cpu.c:81
av_gettime_relative
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition: time.c:56
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
opt.h
scale_legacy
static int scale_legacy(AVFrame *dst, const AVFrame *src, struct mode mode, struct options opts)
Definition: swscale.c:115
out
FILE * out
Definition: movenc.c:55
av_frame_get_buffer
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:304
av_lfg_init
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
Definition: lfg.c:32
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3170
SwsContext::src_w
int src_w
Deprecated frame property overrides, for the legacy API only.
Definition: swscale.h:220
int64_t
long long int64_t
Definition: coverity.c:34
sws_freeContext
void sws_freeContext(SwsContext *swsContext)
Free the swscaler context swsContext.
Definition: utils.c:2447
run_test
static int run_test(enum AVPixelFormat src_fmt, enum AVPixelFormat dst_fmt, int dst_w, int dst_h, struct mode mode, struct options opts, const AVFrame *ref, const int mse_ref[4])
Definition: swscale.c:147
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:162
mode
Definition: swscale.c:52
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
pixdesc.h
w
uint8_t w
Definition: llviddspenc.c:38
SWS_BILINEAR
@ SWS_BILINEAR
bilinear filtering
Definition: swscale.h:99
SWS_BITEXACT
@ SWS_BITEXACT
Definition: swscale.h:156
b
#define b
Definition: input.c:41
ff_sfc64_init
static void ff_sfc64_init(FFSFC64 *s, uint64_t seeda, uint64_t seedb, uint64_t seedc, int rounds)
Initialize sfc64 with up to 3 seeds.
Definition: sfc64.h:75
SwsContext::flags
unsigned flags
Bitmask of SWS_*.
Definition: swscale.h:187
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
av_get_cpu_flags
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:109
mode::dither
SwsDither dither
Definition: swscale.c:54
prng_state
static FFSFC64 prng_state
Definition: swscale.c:68
run_file_tests
static int run_file_tests(const AVFrame *ref, FILE *fp, struct options opts)
Definition: swscale.c:294
AV_PIX_FMT_NB
@ AV_PIX_FMT_NB
number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of...
Definition: pixfmt.h:466
SWS_FAST_BILINEAR
@ SWS_FAST_BILINEAR
Scaler selection options.
Definition: swscale.h:98
rgb
Definition: rpzaenc.c:60
b1
static double b1(void *priv, double x, double y)
Definition: vf_xfade.c:2034
SWS_FULL_CHR_H_INP
@ SWS_FULL_CHR_H_INP
Perform full chroma interpolation when downscaling RGB sources.
Definition: swscale.h:145
macros.h
FFSFC64
Definition: sfc64.h:37
SwsDither
SwsDither
Definition: swscale.h:77
options::iters
int iters
Definition: swscale.c:48
av_parse_cpu_caps
int av_parse_cpu_caps(unsigned *flags, const char *s)
Parse CPU caps from a string and update the given AV_CPU_* flags based on that.
Definition: cpu.c:119
sws_init_context
av_warn_unused_result int sws_init_context(SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter)
Initialize the swscaler context sws_context.
Definition: utils.c:2082
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:150
avassert.h
options::dst_fmt
enum AVPixelFormat dst_fmt
Definition: swscale.c:44
options::w
int w
Definition: swscale.c:46
SWS_AREA
@ SWS_AREA
area averaging
Definition: swscale.h:103
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
SwsContext::dither
SwsDither dither
Dither mode.
Definition: swscale.h:202
options::h
int h
Definition: swscale.c:46
SwsFlags
SwsFlags
Definition: swscale.h:94
AV_PIX_FMT_YUVA420P
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:108
SwsContext::threads
int threads
How many threads to use for processing, or 0 for automatic selection.
Definition: swscale.h:197
av_lfg_get
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
Definition: lfg.h:53
lfg.h
run_self_tests
static int run_self_tests(const AVFrame *ref, struct options opts)
Definition: swscale.c:256
AV_PIX_FMT_FLAG_ALPHA
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:147
sfc64.h
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:100
get_mse
static void get_mse(int mse[4], const AVFrame *a, const AVFrame *b, int comps)
Definition: swscale.c:80
opts
AVDictionary * opts
Definition: movenc.c:51
NULL
#define NULL
Definition: coverity.c:32
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:725
SWS_BICUBIC
@ SWS_BICUBIC
2-tap cubic B-spline
Definition: swscale.h:100
options::threads
int threads
Definition: swscale.c:47
options
Definition: swscale.c:42
sws_test_format
int sws_test_format(enum AVPixelFormat format, int output)
Test if a given pixel format is supported.
Definition: utils.c:2711
time.h
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
options::src_fmt
enum AVPixelFormat src_fmt
Definition: swscale.c:43
AVLFG
Context structure for the Lagged Fibonacci PRNG.
Definition: lfg.h:33
sws_alloc_context
SwsContext * sws_alloc_context(void)
Allocate an empty SwsContext and set its fields to default values.
Definition: utils.c:1227
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
cpu.h
mode::flags
SwsFlags flags
Definition: swscale.c:53
SWS_POINT
@ SWS_POINT
nearest neighbor
Definition: swscale.h:102
SwsContext::src_h
int src_h
Width and height of the source frame.
Definition: swscale.h:220
printf
printf("static const uint8_t my_array[100] = {\n")
frame.h
options::prob
double prob
Definition: swscale.c:45
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
SWS_DITHER_NB
@ SWS_DITHER_NB
Definition: swscale.h:86
SwsContext::dst_format
int dst_format
Destination pixel format.
Definition: swscale.h:223
sws
static SwsContext * sws[3]
Definition: swscale.c:69
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
modes
const struct mode modes[]
Definition: swscale.c:57
SWS_X
@ SWS_X
experimental
Definition: swscale.h:101
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:56
SwsContext::dst_h
int dst_h
Width and height of the destination frame.
Definition: swscale.h:221
ff_sfc64_get
static uint64_t ff_sfc64_get(FFSFC64 *s)
Definition: sfc64.h:41
ret
ret
Definition: filter_design.txt:187
pixfmt.h
SWS_FULL_CHR_H_INT
@ SWS_FULL_CHR_H_INT
Perform full chroma upsampling when upscaling to RGB.
Definition: swscale.h:132
av_get_pix_fmt
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:3102
main
int main(int argc, char **argv)
Definition: swscale.c:337
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:117
bad
static int bad(InterplayACMContext *s, unsigned ind, unsigned col)
Definition: interplayacm.c:130
desc
const char * desc
Definition: libsvtav1.c:79
SwsContext::dst_w
int dst_w
Definition: swscale.h:221
SwsContext::src_format
int src_format
Source pixel format.
Definition: swscale.h:222
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
options::bench
int bench
Definition: swscale.c:49
sws_free_context
void sws_free_context(SwsContext **ctx)
Free the context and everything associated with it, and write NULL to the provided pointer.
Definition: utils.c:2526
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
sws_scale_frame
int sws_scale_frame(SwsContext *sws, AVFrame *dst, const AVFrame *src)
Scale source data from src and write the output to dst.
Definition: swscale.c:1347
SWS_ACCURATE_RND
@ SWS_ACCURATE_RND
Force bit-exact output.
Definition: swscale.h:155
h
h
Definition: vp9dsp_template.c:2070
SwsContext
Main external API structure.
Definition: swscale.h:174
fmt_comps
static int fmt_comps(enum AVPixelFormat fmt)
Definition: swscale.c:71
src
#define src
Definition: vp8dsp.c:248
swscale.h
av_get_pix_fmt_name
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:3090