FFmpeg
Loading...
Searching...
No Matches
swscale.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024 Niklas 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#include <signal.h>
28
29#undef HAVE_AV_CONFIG_H
30#include "libavutil/cpu.h"
31#include "libavutil/avstring.h"
33#include "libavutil/pixdesc.h"
34#include "libavutil/lfg.h"
35#include "libavutil/sfc64.h"
36#include "libavutil/frame.h"
37#include "libavutil/opt.h"
38#include "libavutil/time.h"
39#include "libavutil/pixfmt.h"
40#include "libavutil/avassert.h"
41#include "libavutil/macros.h"
42#include "libavutil/hwcontext.h"
43
44#include "libswscale/swscale.h"
45#include "libswscale/format.h"
46
47#define IMPL_NEW 0
48#define IMPL_LEGACY 1
49
70
77
79 float ssim[4];
80 float loss;
82 int iters;
83};
84
95
97
98/* reused between tests for efficiency */
102
105
106static double speedup_logavg;
107static double speedup_min = 1e10;
108static double speedup_max = 0;
109static int speedup_count;
110
111static const char *speedup_color(double ratio)
112{
113 return ratio > 10.00 ? "\033[1;94m" : /* bold blue */
114 ratio > 2.00 ? "\033[1;32m" : /* bold green */
115 ratio > 1.02 ? "\033[32m" : /* green */
116 ratio > 0.98 ? "" : /* default */
117 ratio > 0.90 ? "\033[33m" : /* yellow */
118 ratio > 0.75 ? "\033[31m" : /* red */
119 "\033[1;31m"; /* bold red */
120}
121
122static void exit_handler(int sig)
123{
124 if (speedup_count) {
125 double ratio = exp(speedup_logavg / speedup_count);
126 fprintf(stderr, "Overall speedup=%.3fx %s%s\033[0m, min=%.3fx max=%.3fx\n", ratio,
127 speedup_color(ratio), ratio >= 1.0 ? "faster" : "slower",
129 }
130
131 exit(sig);
132}
133
134/* Estimate luma variance assuming uniform dither noise distribution */
136{
138 float variance = 1.0 / 12;
139 if (desc->comp[0].depth < 8) {
140 /* Extra headroom for very low bit depth output */
141 variance *= (8 - desc->comp[0].depth);
142 }
143
144 if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) {
145 return 0.0;
146 } else if (desc->flags & AV_PIX_FMT_FLAG_RGB) {
147 const float r = 0.299 / (1 << desc->comp[0].depth);
148 const float g = 0.587 / (1 << desc->comp[1].depth);
149 const float b = 0.114 / (1 << desc->comp[2].depth);
150 return (r * r + g * g + b * b) * variance;
151 } else {
152 const float y = 1.0 / (1 << desc->comp[0].depth);
153 return y * y * variance;
154 }
155}
156
157static int fmt_comps(enum AVPixelFormat fmt)
158{
160 int comps = desc->nb_components >= 3 ? 0x7 : 0x1;
161 if (desc->flags & AV_PIX_FMT_FLAG_ALPHA)
162 comps |= 0x8;
163 return comps;
164}
165
166static void get_ssim(float ssim[4], const AVFrame *out, const AVFrame *ref, int comps)
167{
169 av_assert1(ref->format == out->format);
170 av_assert1(ref->width == out->width && ref->height == out->height);
171
172 for (int p = 0; p < 4; p++) {
173 const int stride_a = out->linesize[p];
174 const int stride_b = ref->linesize[p];
175 const int w = out->width;
176 const int h = out->height;
177
178 const int is_chroma = p == 1 || p == 2;
179 const uint8_t def = is_chroma ? 128 : 0xFF;
180 const int has_ref = comps & (1 << p);
181 double sum = 0;
182 int count = 0;
183
184 /* 4x4 SSIM */
185 for (int y = 0; y < (h & ~3); y += 4) {
186 for (int x = 0; x < (w & ~3); x += 4) {
187 const float c1 = .01 * .01 * 255 * 255 * 64;
188 const float c2 = .03 * .03 * 255 * 255 * 64 * 63;
189 int s1 = 0, s2 = 0, ss = 0, s12 = 0, var, covar;
190
191 for (int yy = 0; yy < 4; yy++) {
192 for (int xx = 0; xx < 4; xx++) {
193 int a = out->data[p][(y + yy) * stride_a + x + xx];
194 int b = has_ref ? ref->data[p][(y + yy) * stride_b + x + xx] : def;
195 s1 += a;
196 s2 += b;
197 ss += a * a + b * b;
198 s12 += a * b;
199 }
200 }
201
202 var = ss * 64 - s1 * s1 - s2 * s2;
203 covar = s12 * 64 - s1 * s2;
204 sum += (2 * s1 * s2 + c1) * (2 * covar + c2) /
205 ((s1 * s1 + s2 * s2 + c1) * (var + c2));
206 count++;
207 }
208 }
209
210 ssim[p] = count ? sum / count : 0.0;
211 }
212}
213
214static float get_loss(const float ssim[4])
215{
216 const float weights[3] = { 0.8, 0.1, 0.1 }; /* tuned for Y'CbCr */
217
218 float sum = 0;
219 for (int i = 0; i < 3; i++)
220 sum += weights[i] * ssim[i];
221 sum *= ssim[3]; /* ensure alpha errors get caught */
222
223 return 1.0 - sum;
224}
225
227{
228 for (int i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++) {
229 if (!frame->buf[i])
230 break;
231 av_buffer_unref(&frame->buf[i]);
232 }
233
234 memset(frame->data, 0, sizeof(frame->data));
235 memset(frame->linesize, 0, sizeof(frame->linesize));
236}
237
239{
240 int ret = sws_scale_frame(c, dst, src);
241 if (ret < 0) {
242 av_log(NULL, AV_LOG_ERROR, "Failed %s ---> %s\n",
244 }
245 return ret;
246}
247
248static int scale_new(AVFrame *dst, const AVFrame *src,
249 const struct mode *mode, const struct options *opts,
250 int64_t *out_time)
251{
252 sws_src_dst->flags = mode->flags;
253 sws_src_dst->dither = mode->dither;
254 sws_src_dst->scaler = mode->scaler;
255 sws_src_dst->scaler_sub = mode->scaler_sub;
256 sws_src_dst->threads = opts->threads;
257 sws_src_dst->backends = opts->backends;
258
259 int ret = sws_frame_setup(sws_src_dst, dst, src);
260 if (ret < 0) {
261 av_log(NULL, AV_LOG_ERROR, "Failed to setup %s ---> %s\n",
263 return ret;
264 }
265
267 for (int i = 0; ret >= 0 && i < opts->iters; i++) {
269 if (opts->align_dst) {
270 ret = av_frame_get_buffer(dst, opts->align_dst);
271 if (ret < 0)
272 return ret;
273 }
274
276 }
277 *out_time = av_gettime_relative() - time;
278
279 return ret;
280}
281
282static int scale_legacy(AVFrame *dst, const AVFrame *src,
283 const struct mode *mode, const struct options *opts,
284 int64_t *out_time)
285{
286 SwsContext *sws_legacy;
287 int ret;
288
289 sws_legacy = sws_alloc_context();
290 if (!sws_legacy)
291 return -1;
292
293 sws_legacy->src_w = src->width;
294 sws_legacy->src_h = src->height;
295 sws_legacy->src_format = src->format;
296 sws_legacy->dst_w = dst->width;
297 sws_legacy->dst_h = dst->height;
298 sws_legacy->dst_format = dst->format;
299 sws_legacy->flags = mode->flags;
300 sws_legacy->dither = mode->dither;
301 sws_legacy->scaler = mode->scaler;
302 sws_legacy->scaler_sub = mode->scaler_sub;
303 sws_legacy->threads = opts->threads;
304
306 dst->width = sws_legacy->dst_w;
307 dst->height = sws_legacy->dst_h;
308 dst->format = sws_legacy->dst_format;
309 ret = av_frame_get_buffer(dst, opts->align_dst);
310 if (ret < 0)
311 goto error;
312
313 ret = sws_init_context(sws_legacy, NULL, NULL);
314 if (ret < 0)
315 goto error;
316
318 for (int i = 0; ret >= 0 && i < opts->iters; i++)
319 ret = checked_sws_scale_frame(sws_legacy, dst, src);
320 *out_time = av_gettime_relative() - time;
321
322error:
323 sws_freeContext(sws_legacy);
324 return ret;
325}
326
327static int scale_hw(AVFrame *dst, const AVFrame *src,
328 const struct mode *mode, const struct options *opts,
329 int64_t *out_time)
330{
331 SwsContext *sws_hw = NULL;
332 AVBufferRef *in_ref = NULL;
333 AVBufferRef *out_ref = NULL;
334 AVHWFramesContext *in_ctx = NULL;
335 AVHWFramesContext *out_ctx = NULL;
336 AVFrame *in_f = NULL;
337 AVFrame *out_f = NULL;
338 int ret;
339
340 sws_hw = sws_alloc_context();
341 if (!sws_hw) {
342 ret = AVERROR(ENOMEM);
343 goto error;
344 }
345
346 sws_hw->flags = mode->flags;
347 sws_hw->dither = mode->dither;
348 sws_hw->scaler = mode->scaler;
349 sws_hw->scaler_sub = mode->scaler_sub;
350 sws_hw->threads = opts->threads;
351 sws_hw->backends = opts->backends;
352
354 if (!in_ref) {
355 ret = AVERROR(ENOMEM);
356 goto error;
357 }
358
359 in_ctx = (AVHWFramesContext *)in_ref->data;
360 in_ctx->format = AV_PIX_FMT_VULKAN;
361 in_ctx->sw_format = src->format;
362 in_ctx->width = src->width;
363 in_ctx->height = src->height;
364 ret = av_hwframe_ctx_init(in_ref);
365 if (ret < 0) {
366 if (ret != AVERROR(ENOTSUP))
367 av_log(NULL, AV_LOG_ERROR, "Failed to create input HW context: %s\n",
368 av_err2str(ret));
369 goto error;
370 }
371
373 if (!out_ref) {
374 ret = AVERROR(ENOMEM);
375 goto error;
376 }
377
378 out_ctx = (AVHWFramesContext *) out_ref->data;
379 out_ctx->format = AV_PIX_FMT_VULKAN;
380 out_ctx->sw_format = dst->format;
381 out_ctx->width = dst->width;
382 out_ctx->height = dst->height;
383 ret = av_hwframe_ctx_init(out_ref);
384 if (ret < 0) {
385 if (ret != AVERROR(ENOTSUP))
386 av_log(NULL, AV_LOG_ERROR, "Failed to create output HW context: %s\n",
387 av_err2str(ret));
388 goto error;
389 }
390
391 in_f = av_frame_alloc();
392 if (!in_f) {
393 ret = AVERROR(ENOMEM);
394 goto error;
395 }
396 in_f->width = src->width;
397 in_f->height = src->height;
399 ret = av_hwframe_get_buffer(in_ref, in_f, 0);
400 if (ret < 0) {
401 av_log(NULL, AV_LOG_ERROR, "Failed to allocate input HW frame\n");
402 goto error;
403 }
404
405 ret = av_hwframe_transfer_data(in_f, src, 0);
406 if (ret < 0) {
407 av_log(NULL, AV_LOG_ERROR, "Failed to upload HW frame\n");
408 goto error;
409 }
410
411 out_f = av_frame_alloc();
412 if (!out_f) {
413 ret = AVERROR(ENOMEM);
414 goto error;
415 }
416 out_f->width = dst->width;
417 out_f->height = dst->height;
418 out_f->format = AV_PIX_FMT_VULKAN;
419 ret = av_hwframe_get_buffer(out_ref, out_f, 0);
420 if (ret < 0) {
421 av_log(NULL, AV_LOG_ERROR, "Failed to allocate output HW frame\n");
422 goto error;
423 }
424
426 for (int i = 0; ret >= 0 && i < opts->iters; i++) {
427 ret = checked_sws_scale_frame(sws_hw, out_f, in_f);
428 if (ret < 0)
429 goto error;
430 }
431 *out_time = av_gettime_relative() - time;
432
433 ret = av_frame_get_buffer(dst, 0);
434 if (ret < 0)
435 goto error;
436
437 ret = av_hwframe_transfer_data(dst, out_f, 0);
438 if (ret < 0) {
439 av_log(NULL, AV_LOG_ERROR, "Failed to download HW frame\n");
440 goto error;
441 }
442
443 ret = 0;
444
445error:
446 av_frame_free(&in_f);
447 av_frame_free(&out_f);
448 av_buffer_unref(&in_ref);
449 av_buffer_unref(&out_ref);
450 sws_free_context(&sws_hw);
451 return ret;
452}
453
454static void print_test_params(char *buf, size_t buf_size,
455 const AVFrame *src, const AVFrame *dst,
456 const struct mode *mode, const struct options *opts)
457{
458 snprintf(buf, buf_size,
459 "%-*s %*dx%*d -> %-*s %*dx%*d, flags=0x%0*x dither=%u scaler=%d/%d",
460 opts->pretty ? 14 : 0, av_get_pix_fmt_name(src->format),
461 opts->pretty ? 4 : 0, src->width,
462 opts->pretty ? 4 : 0, src->height,
463 opts->pretty ? 14 : 0, av_get_pix_fmt_name(dst->format),
464 opts->pretty ? 4 : 0, dst->width,
465 opts->pretty ? 4 : 0, dst->height,
466 opts->pretty ? 8 : 0, mode->flags,
467 mode->dither,
468 mode->scaler,
470}
471
472static void print_results(const AVFrame *ref, const AVFrame *src, const AVFrame *dst,
473 int dst_w, int dst_h,
474 const struct mode *mode, const struct options *opts,
475 const struct test_results *r,
476 const struct test_results *ref_r,
477 float expected_loss)
478{
479 char buf[128];
480
481 if (av_log_get_level() >= AV_LOG_INFO) {
482 print_test_params(buf, sizeof(buf), src, dst, mode, opts);
483 printf("%s", buf);
484
485 if (!opts->bench || !ref_r) {
486 printf(", SSIM={Y=%f U=%f V=%f A=%f} loss=%e",
487 r->ssim[0], r->ssim[1], r->ssim[2], r->ssim[3],
488 r->loss);
489 if (ref_r)
490 printf(" (ref=%e)", ref_r->loss);
491 }
492
493 if (opts->bench) {
494 printf(", time=%*"PRId64"/%u us",
495 opts->pretty ? 7 : 0, r->time, opts->iters);
496 if (ref_r) {
497 double ratio = ((double) ref_r->time / ref_r->iters)
498 / ((double) r->time / opts->iters);
499 if (FFMIN(r->time, ref_r->time) > 100 /* don't pollute stats with low precision */) {
500 speedup_min = FFMIN(speedup_min, ratio);
501 speedup_max = FFMAX(speedup_max, ratio);
502 speedup_logavg += log(ratio);
504 }
505
506 printf(" (ref=%*"PRId64"/%u us), speedup=%*.3fx %s%s\033[0m",
507 opts->pretty ? 7 : 0, ref_r->time, ref_r->iters,
508 opts->pretty ? 6 : 0, ratio,
509 speedup_color(ratio), ratio >= 1.0 ? "faster" : "slower");
510 }
511 }
512 printf("\n");
513
514 fflush(stdout);
515 }
516
517 if (r->loss - expected_loss > 1e-4 && dst_w >= ref->width && dst_h >= ref->height) {
518 const int bad = r->loss - expected_loss > 1e-2;
519 const int level = bad ? AV_LOG_ERROR : AV_LOG_WARNING;
520 const char *worse_str = bad ? "WORSE" : "worse";
521 if (bad) {
522 print_test_params(buf, sizeof(buf), src, dst, mode, opts);
523 av_log(NULL, level, "%s\n", buf);
524 }
526 " loss %e is %s by %e, expected loss %e\n",
527 r->loss, worse_str, r->loss - expected_loss, expected_loss);
528 }
529
530 if (ref_r && r->loss - ref_r->loss > 1e-4) {
531 /**
532 * The new scaling code does not (yet) perform error diffusion for
533 * low bit depth output, which impacts the SSIM score slightly for
534 * very low bit-depth formats (e.g. monow, monob). Since this is an
535 * expected result, drop the badness from an error to a warning for
536 * such cases. This can be removed again once error diffusion is
537 * implemented in the new ops code.
538 */
539 const int dst_bits = av_pix_fmt_desc_get(dst->format)->comp[0].depth;
540 const int bad = r->loss - ref_r->loss > 1e-2 && dst_bits > 1;
541 const int level = bad ? AV_LOG_ERROR : AV_LOG_WARNING;
542 const char *worse_str = bad ? "WORSE" : "worse";
543 if (bad) {
544 print_test_params(buf, sizeof(buf), src, dst, mode, opts);
545 av_log(NULL, level, "%s\n", buf);
546 }
548 " loss %e is %s by %e, ref loss %e SSIM={Y=%f U=%f V=%f A=%f}\n",
549 r->loss, worse_str, r->loss - ref_r->loss, ref_r->loss,
550 ref_r->ssim[0], ref_r->ssim[1], ref_r->ssim[2], ref_r->ssim[3]);
551 }
552}
553
554static int init_frame(AVFrame **pframe, const AVFrame *ref,
555 int width, int height, enum AVPixelFormat format)
556{
558 if (!frame)
559 return AVERROR(ENOMEM);
561 frame->width = width;
562 frame->height = height;
563 frame->format = format;
564 *pframe = frame;
565 return 0;
566}
567
568/* Runs a series of ref -> src -> dst -> out, and compares out vs ref */
569static int run_test(enum AVPixelFormat src_fmt, enum AVPixelFormat dst_fmt,
570 int dst_w, int dst_h,
571 const struct mode *mode, const struct options *opts,
572 const AVFrame *ref, AVFrame **psrc,
573 const struct test_results *ref_r)
574{
575 AVFrame *src = *psrc;
576 AVFrame *dst = NULL, *out = NULL;
577 const int comps = fmt_comps(src_fmt) & fmt_comps(dst_fmt);
578 int ret;
579
580 /* Estimate the expected amount of loss from bit depth reduction */
581 const float c1 = 0.01 * 0.01; /* stabilization constant */
582 const float ref_var = 1.0 / 12.0; /* uniformly distributed signal */
583 const float src_var = estimate_quantization_noise(src_fmt);
584 const float dst_var = estimate_quantization_noise(dst_fmt);
585 const float out_var = estimate_quantization_noise(ref->format);
586 const float total_var = src_var + dst_var + out_var;
587 const float ssim_luma = (2 * ref_var + c1) / (2 * ref_var + total_var + c1);
588 const float ssim_expected[4] = { ssim_luma, 1, 1, 1 }; /* for simplicity */
589 const float expected_loss = get_loss(ssim_expected);
590
591 struct test_results r = { 0 };
592
593 if (!src || src->format != src_fmt) {
594 av_frame_free(psrc);
595 ret = init_frame(&src, ref, ref->width, ref->height, src_fmt);
596 if (ret < 0)
597 goto error;
598 if (opts->align_src) {
599 ret = av_frame_get_buffer(src, opts->align_src);
600 if (ret < 0)
601 goto error;
602 }
603
605 if (ret < 0)
606 goto error;
607 *psrc = src;
608 }
609
610 ret = init_frame(&dst, ref, dst_w, dst_h, dst_fmt);
611 if (ret < 0)
612 goto error;
613
614 ret = (opts->api == IMPL_LEGACY) ? scale_legacy(dst, src, mode, opts, &r.time)
615 : hw_device_ctx ? scale_hw(dst, src, mode, opts, &r.time)
616 : scale_new(dst, src, mode, opts, &r.time);
617 if (ret < 0) {
618 if (ret == AVERROR(ENOTSUP))
619 ret = 0;
620 goto error;
621 }
622
623 ret = init_frame(&out, ref, ref->width, ref->height, ref->format);
624 if (ret < 0)
625 goto error;
626
628 if (ret < 0)
629 goto error;
630
631 get_ssim(r.ssim, out, ref, comps);
632
633 if (opts->api == IMPL_LEGACY) {
634 /* Legacy swscale does not perform bit accurate upconversions of low
635 * bit depth RGB. This artificially improves the SSIM score because the
636 * resulting error deletes some of the input dither noise. This gives
637 * it an unfair advantage when compared against a bit exact reference.
638 * Work around this by ensuring that the resulting SSIM score is not
639 * higher than it theoretically "should" be. */
640 if (src_var > dst_var) {
641 const float src_loss = (2 * ref_var + c1) / (2 * ref_var + src_var + c1);
642 r.ssim[0] = FFMIN(r.ssim[0], src_loss);
643 }
644 }
645
646 r.loss = get_loss(r.ssim);
647 if ((opts->api != IMPL_LEGACY) && r.loss - expected_loss > 1e-2 && dst_w >= ref->width && dst_h >= ref->height) {
648 ret = -1;
649 goto bad_loss;
650 }
651
652 if (ref_r && r.loss - ref_r->loss > 1e-2) {
653 ret = -1;
654 goto bad_loss;
655 }
656
657 ret = 0; /* fall through */
658
659bad_loss:
661 dst_w, dst_h,
662 mode, opts,
663 &r, ref_r,
664 expected_loss);
665
666 error:
669 return ret;
670}
671
672static inline int fmt_is_subsampled(enum AVPixelFormat fmt)
673{
674 return av_pix_fmt_desc_get(fmt)->log2_chroma_w != 0 ||
676}
677
678static inline int fmt_is_supported_by_hw(enum AVPixelFormat fmt)
679{
680 /* Semi-planar formats are only supported by the legacy path, which
681 * does not support hardware frames. */
682 if (fmt == AV_PIX_FMT_NV24 || fmt == AV_PIX_FMT_P410 ||
683 fmt == AV_PIX_FMT_P412 || fmt == AV_PIX_FMT_P416)
684 return 0;
685 for (int i = 0;
686 hw_device_constr->valid_sw_formats[i] != AV_PIX_FMT_NONE; i++) {
687 if (hw_device_constr->valid_sw_formats[i] == fmt)
688 return 1;
689 }
690 return 0;
691}
692
693static inline int fmt_disabled(const struct options *opts, enum AVPixelFormat fmt)
694{
695 const int scaler_sub = opts->scaler_sub ? opts->scaler_sub : opts->scaler;
696 return (hw_device_constr && !fmt_is_supported_by_hw(fmt)) ||
697 (scaler_sub < 0 && fmt_is_subsampled(fmt));
698}
699
700static inline int test_formats(const struct options *opts,
702{
703 /* Test auxiliary conversions */
704 if (!ff_sws_test_pixfmt_backend(sws_ref_src->backends, src, 1) ||
706 return 0;
707
708 /* Test main conversion */
709 enum SwsBackend backend = opts->backends ? opts->backends : SWS_BACKEND_STABLE;
710 if (opts->api == IMPL_LEGACY)
711 backend = SWS_BACKEND_LEGACY; /* Legacy API forces legacy backend */
712 return ff_sws_test_pixfmt_backend(backend, src, 0) &&
713 ff_sws_test_pixfmt_backend(backend, dst, 1);
714}
715
716static int run_self_tests(const AVFrame *ref, const struct options *opts)
717{
718 const int dst_w_values[] = { opts->w, opts->w - opts->w / 3, opts->w + opts->w / 3 };
719 const int dst_h_values[] = { opts->h, opts->h - opts->h / 3, opts->h + opts->h / 3 };
720
721 enum AVPixelFormat src_fmt, dst_fmt,
722 src_fmt_min = 0,
723 dst_fmt_min = 0,
724 src_fmt_max = AV_PIX_FMT_NB - 1,
725 dst_fmt_max = AV_PIX_FMT_NB - 1;
726
727 AVFrame *src = NULL;
728
729 int ret = 0;
730
731 if (opts->src_fmt != AV_PIX_FMT_NONE)
732 src_fmt_min = src_fmt_max = opts->src_fmt;
733 if (opts->dst_fmt != AV_PIX_FMT_NONE)
734 dst_fmt_min = dst_fmt_max = opts->dst_fmt;
735
736 for (src_fmt = src_fmt_min; src_fmt <= src_fmt_max; src_fmt++) {
737 if (fmt_disabled(opts, src_fmt))
738 continue;
739 for (dst_fmt = dst_fmt_min; dst_fmt <= dst_fmt_max; dst_fmt++) {
740 if (fmt_disabled(opts, dst_fmt))
741 continue;
742 if (!test_formats(opts, src_fmt, dst_fmt))
743 continue;
744 for (int h = 0; h < FF_ARRAY_ELEMS(dst_h_values); h++) {
745 for (int w = 0; w < FF_ARRAY_ELEMS(dst_w_values); w++) {
746 for (int f = 0; f < FF_ARRAY_ELEMS(flags); f++) {
747 struct mode mode = {
748 .flags = opts->flags >= 0 ? opts->flags : flags[f],
749 .dither = opts->dither >= 0 ? opts->dither : SWS_DITHER_AUTO,
750 .scaler = opts->scaler >= 0 ? opts->scaler : SWS_SCALE_AUTO,
751 .scaler_sub = opts->scaler_sub >= 0 ? opts->scaler_sub : SWS_SCALE_AUTO,
752 };
753 int dst_w = (opts->dst_w >= 0) ? opts->dst_w : dst_w_values[w];
754 int dst_h = (opts->dst_h >= 0) ? opts->dst_h : dst_h_values[h];
755
756 if (opts->scaler > SWS_SCALE_AUTO && opts->w == dst_w && opts->h == dst_h)
757 continue;
758
759 if (ff_sfc64_get(&prng_state) <= UINT64_MAX * opts->prob) {
760 ret = run_test(src_fmt, dst_fmt, dst_w, dst_h,
761 &mode, opts, ref, &src, NULL);
762 if (ret < 0)
763 goto error;
764 }
765
766 if (opts->flags >= 0 || opts->scaler != SWS_SCALE_AUTO)
767 break;
768 }
769 if (opts->dst_w >= 0 || opts->dst_h >= 0)
770 break;
771 if (opts->scaler < 0)
772 break;
773 }
774 if (opts->dst_w >= 0 || opts->dst_h >= 0)
775 break;
776 if (opts->scaler < 0)
777 break;
778 }
779 }
780 }
781
782 ret = 0;
783
784error:
786 return ret;
787}
788
789static int run_file_tests(const AVFrame *ref, FILE *fp, const struct options *opts)
790{
791 char buf[256];
792 int ret = 0;
793
794 AVFrame *src = NULL;
795
796 for (int line = 1; fgets(buf, sizeof(buf), fp); line++) {
797 char src_fmt_str[21], dst_fmt_str[21];
798 enum AVPixelFormat src_fmt;
799 enum AVPixelFormat dst_fmt;
800 int sw, sh, dw, dh;
801 struct test_results r = { 0 };
802 struct mode mode;
803 int n = 0;
804
805 ret = sscanf(buf,
806 "%20s %dx%d -> %20s %dx%d, flags=0x%x dither=%u scaler=%u/%u, "
807 "SSIM={Y=%f U=%f V=%f A=%f} loss=%e%n",
808 src_fmt_str, &sw, &sh, dst_fmt_str, &dw, &dh,
811 &r.ssim[0], &r.ssim[1], &r.ssim[2], &r.ssim[3],
812 &r.loss, &n);
813 if (ret != 15) {
815 "Malformed reference file in line %d\n", line);
816 goto error;
817 }
818 if (opts->bench) {
819 ret = sscanf(buf + n,
820 ", time=%"PRId64"/%u us",
821 &r.time, &r.iters);
822 if (ret != 2) {
824 "Missing benchmarks from reference file in line %d\n",
825 line);
826 goto error;
827 }
828 }
829
830 src_fmt = av_get_pix_fmt(src_fmt_str);
831 dst_fmt = av_get_pix_fmt(dst_fmt_str);
832 if (src_fmt == AV_PIX_FMT_NONE || dst_fmt == AV_PIX_FMT_NONE) {
834 "Unknown pixel formats (%s and/or %s) in line %d\n",
835 src_fmt_str, dst_fmt_str, line);
836 goto error;
837 }
838
839 if (sw != ref->width || sh != ref->height) {
841 "Mismatching dimensions %dx%d (ref is %dx%d) in line %d\n",
842 sw, sh, ref->width, ref->height, line);
843 goto error;
844 }
845
846 if (opts->src_fmt != AV_PIX_FMT_NONE && src_fmt != opts->src_fmt ||
847 opts->dst_fmt != AV_PIX_FMT_NONE && dst_fmt != opts->dst_fmt)
848 continue;
849
850 ret = run_test(src_fmt, dst_fmt, dw, dh, &mode, opts, ref, &src, &r);
851 if (ret < 0)
852 goto error;
853 }
854
855 ret = 0;
856
857error:
859 return ret;
860}
861
862static int init_ref(AVFrame *ref, const struct options *opts)
863{
866 AVLFG rand;
867 int ret = -1;
868
869 if (!ctx || !rgb)
870 goto error;
871
872 rgb->width = opts->w > 32 ? opts->w / 12 : opts->w;
873 rgb->height = opts->h > 32 ? opts->h / 12 : opts->h;
874 rgb->format = AV_PIX_FMT_RGBA;
875 ret = av_frame_get_buffer(rgb, 32);
876 if (ret < 0)
877 goto error;
878
879 av_lfg_init(&rand, 1);
880 for (int y = 0; y < rgb->height; y++) {
881 for (int x = 0; x < rgb->width; x++) {
882 for (int c = 0; c < 4; c++)
883 rgb->data[0][y * rgb->linesize[0] + x * 4 + c] = av_lfg_get(&rand);
884 }
885 }
886
889
890error:
893 return ret;
894}
895
896static int parse_size(struct options *opts, const char *str, char **pbuf)
897{
898 int ret = av_parse_video_size(&opts->w, &opts->h, str);
899 if (ret < 0 && strchr(str, ':')) {
900 av_freep(pbuf);
901 char *buf = av_strdup(str);
902 if (!buf)
903 return AVERROR(ENOMEM);
904 *pbuf = buf;
905 char *saveptr = NULL;
906 char *s = av_strtok(buf, ":", &saveptr);
907 if (s) {
908 ret = av_parse_video_size(&opts->w, &opts->h, s);
909 if (ret >= 0) {
910 s = av_strtok(NULL, ":", &saveptr);
911 if (s) {
912 ret = av_parse_video_size(&opts->dst_w, &opts->dst_h, s);
913 }
914 }
915 }
916 }
917 return ret;
918}
919
920static int parse_implementation(const char *str)
921{
922 if (!strcmp(str, "legacy"))
923 return IMPL_LEGACY;
924 if (!strcmp(str, "new"))
925 return IMPL_NEW;
926 return -1;
927}
928
929static int parse_options(int argc, char **argv, struct options *opts, FILE **fp)
930{
932 char *buf = NULL;
933 int ret;
934
935 for (int i = 1; i < argc; i += 2) {
936 if (!strcmp(argv[i], "-help") || !strcmp(argv[i], "--help")) {
937 fprintf(stderr,
938 "swscale [options...]\n"
939 " -help\n"
940 " This text\n"
941 " -ref <file>\n"
942 " Uses file as reference to compare tests against. Tests that have become worse will contain the string worse or WORSE\n"
943 " -p <number between 0.0 and 1.0>\n"
944 " The proportion of tests or comparisons to perform.\n"
945 " It is often convenient to perform a random subset\n"
946 " -dst <pixfmt>\n"
947 " Only test the specified destination pixel format\n"
948 " -src <pixfmt>\n"
949 " Only test the specified source pixel format\n"
950 " -s <size>[:<size>]\n"
951 " Set frame size (WxH or abbreviation)\n"
952 " Optionally set destination frame size (after a ':' separator character).\n"
953 " -bench <iters>\n"
954 " Run benchmarks with the specified number of iterations. This mode also sets the frame size to 1920x1080 (unless -s is specified)\n"
955 " -flags <flags>\n"
956 " Test with a specific combination of flags\n"
957 " -dither <mode>\n"
958 " Test with a specific dither mode\n"
959 " -backends <backends>\n"
960 " Restrict to the given set of allowed swscale backends\n"
961 " -scaler <algorithm>\n"
962 " Test with a specified scaler algorithm\n"
963 " If 'none', test only conversions that do not involve scaling\n"
964 " -scaler_sub <algorithm>\n"
965 " Test with a specified scaler algorithm for chroma planes\n"
966 " -align_src <alignment>\n"
967 " If nonzero, allocate source buffers with a custom stride alignment\n"
968 " -align_dst <alignment>\n"
969 " If nonzero, allocate destination buffers with a custom stride alignment\n"
970 " -api <new or legacy>\n"
971 " Use selected swscale API for the main conversion (default: new)\n"
972 " -hw <device>\n"
973 " Use Vulkan hardware acceleration on the specified device for the main conversion\n"
974 " If 'default', use the default device, and skip all tests if none is available\n"
975 " -threads <threads>\n"
976 " Use the specified number of threads\n"
977 " -cpuflags <cpuflags>\n"
978 " Uses the specified cpuflags in the tests\n"
979 " -pretty <1 or 0>\n"
980 " Align fields while printing results\n"
981 " -v <level>\n"
982 " Enable log verbosity at given level\n"
983 );
984 exit(0);
985 }
986 if (argv[i][0] != '-' || i + 1 == argc)
987 goto bad_option;
988 if (!strcmp(argv[i], "-ref")) {
989 *fp = fopen(argv[i + 1], "r");
990 if (!*fp) {
991 fprintf(stderr, "could not open '%s'\n", argv[i + 1]);
992 ret = AVERROR(errno);
993 goto end;
994 }
995 } else if (!strcmp(argv[i], "-cpuflags")) {
996 unsigned flags = av_get_cpu_flags();
997 ret = av_parse_cpu_caps(&flags, argv[i + 1]);
998 if (ret < 0) {
999 fprintf(stderr, "invalid cpu flags %s\n", argv[i + 1]);
1000 goto end;
1001 }
1003 } else if (!strcmp(argv[i], "-src")) {
1004 opts->src_fmt = av_get_pix_fmt(argv[i + 1]);
1005 if (opts->src_fmt == AV_PIX_FMT_NONE) {
1006 fprintf(stderr, "invalid pixel format %s\n", argv[i + 1]);
1007 ret = AVERROR(EINVAL);
1008 goto end;
1009 }
1010 } else if (!strcmp(argv[i], "-dst")) {
1011 opts->dst_fmt = av_get_pix_fmt(argv[i + 1]);
1012 if (opts->dst_fmt == AV_PIX_FMT_NONE) {
1013 fprintf(stderr, "invalid pixel format %s\n", argv[i + 1]);
1014 ret = AVERROR(EINVAL);
1015 goto end;
1016 }
1017 } else if (!strcmp(argv[i], "-s")) {
1018 ret = parse_size(opts, argv[i + 1], &buf);
1019 if (ret < 0) {
1020 fprintf(stderr, "invalid frame size %s\n", argv[i + 1]);
1021 goto end;
1022 }
1023 } else if (!strcmp(argv[i], "-bench")) {
1024 int iters = atoi(argv[i + 1]);
1025 if (iters <= 0) {
1026 opts->bench = 0;
1027 opts->iters = 1;
1028 } else {
1029 opts->bench = 1;
1030 opts->iters = iters;
1031 }
1032 } else if (!strcmp(argv[i], "-flags")) {
1033 const AVOption *flags_opt = av_opt_find(dummy, "sws_flags", NULL, 0, 0);
1034 ret = av_opt_eval_flags(dummy, flags_opt, argv[i + 1], &opts->flags);
1035 if (ret < 0) {
1036 fprintf(stderr, "invalid flags %s\n", argv[i + 1]);
1037 goto end;
1038 }
1039 } else if (!strcmp(argv[i], "-backends")) {
1040 const AVOption *backends_opt = av_opt_find(dummy, "sws_backends", NULL, 0, 0);
1041 ret = av_opt_eval_flags(dummy, backends_opt, argv[i + 1], &opts->backends);
1042 if (ret < 0) {
1043 fprintf(stderr, "invalid backends %s\n", argv[i + 1]);
1044 goto end;
1045 }
1046 } else if (!strcmp(argv[i], "-dither")) {
1047 opts->dither = atoi(argv[i + 1]);
1048 } else if (!strcmp(argv[i], "-scaler") || !strcmp(argv[i], "-scaler_sub")) {
1049 int opt_is_scaler = !strcmp(argv[i], "-scaler");
1050 if (opt_is_scaler && !strcmp(argv[i + 1], "none")) {
1051 opts->scaler = -1;
1052 continue;
1053 }
1054 const AVOption *scaler_opt = av_opt_find(dummy, "scaler", NULL, 0, 0);
1055 ret = av_opt_eval_int(dummy, scaler_opt, argv[i + 1], opt_is_scaler ? &opts->scaler : &opts->scaler_sub);
1056 if (ret < 0) {
1057 fprintf(stderr, "invalid scaler algorithm %s\n", argv[i + 1]);
1058 goto end;
1059 }
1060 } else if (!strcmp(argv[i], "-align_src")) {
1061 opts->align_src = atoi(argv[i + 1]);
1062 if (opts->align_src < 0 || (opts->align_src & (opts->align_src - 1))) {
1063 fprintf(stderr, "invalid alignment %s\n", argv[i + 1]);
1064 return -1;
1065 }
1066 } else if (!strcmp(argv[i], "-align_dst")) {
1067 opts->align_dst = atoi(argv[i + 1]);
1068 if (opts->align_dst < 0 || (opts->align_dst & (opts->align_dst - 1))) {
1069 fprintf(stderr, "invalid alignment %s\n", argv[i + 1]);
1070 return -1;
1071 }
1072 } else if (!strcmp(argv[i], "-api")) {
1073 ret = parse_implementation(argv[i + 1]);
1074 if (ret < 0) {
1075 fprintf(stderr, "invalid api %s\n", argv[i + 1]);
1076 goto end;
1077 }
1078 opts->api = ret;
1079 } else if (!strcmp(argv[i], "-hw")) {
1080 const int hw_default = !strcmp(argv[i + 1], "default");
1083 hw_default ? NULL : argv[i + 1], NULL, 0);
1084 if (ret < 0) {
1085 if (hw_default) {
1086 fprintf(stderr, "No Vulkan device available, skipping.\n");
1087 ret = AVERROR(ENOTSUP);
1088 } else {
1089 fprintf(stderr, "Failed to create Vulkan device '%s'\n",
1090 argv[i + 1]);
1091 }
1092 goto end;
1093 }
1095 NULL);
1096 if (!hw_device_constr) {
1097 fprintf(stderr, "Failed to retrieve Vulkan device constraints '%s'\n",
1098 argv[i + 1]);
1099 ret = AVERROR(ENOMEM);
1100 goto end;
1101 }
1102 } else if (!strcmp(argv[i], "-threads")) {
1103 opts->threads = atoi(argv[i + 1]);
1104 } else if (!strcmp(argv[i], "-p")) {
1105 opts->prob = atof(argv[i + 1]);
1106 } else if (!strcmp(argv[i], "-pretty")) {
1107 opts->pretty = atoi(argv[i + 1]);
1108 } else if (!strcmp(argv[i], "-v")) {
1109 av_log_set_level(atoi(argv[i + 1]));
1110 } else {
1111bad_option:
1112 fprintf(stderr, "bad option or argument missing (%s) see -help\n", argv[i]);
1113 ret = AVERROR(EINVAL);
1114 goto end;
1115 }
1116 }
1117
1118 if (opts->w < 0 || opts->h < 0) {
1119 opts->w = opts->bench ? 1920 : 96;
1120 opts->h = opts->bench ? 1080 : 96;
1121 }
1122
1123 ret = 0;
1124
1125end:
1127 av_freep(&buf);
1128 return ret;
1129}
1130
1131int main(int argc, char **argv)
1132{
1133 struct options opts = {
1134 .src_fmt = AV_PIX_FMT_NONE,
1135 .dst_fmt = AV_PIX_FMT_NONE,
1136 .w = -1,
1137 .h = -1,
1138 .dst_w = -1,
1139 .dst_h = -1,
1140 .threads = 1,
1141 .iters = 1,
1142 .prob = 1.0,
1143 .flags = -1,
1144 .dither = -1,
1145 .scaler = SWS_SCALE_AUTO,
1146 .scaler_sub = SWS_SCALE_AUTO,
1147 };
1148
1149 AVFrame *ref = NULL;
1150 FILE *fp = NULL;
1151
1152 int ret = parse_options(argc, argv, &opts, &fp);
1153 if (ret == AVERROR(ENOTSUP)) {
1154 ret = 0;
1155 goto error;
1156 }
1157 if (ret < 0)
1158 goto error;
1159
1160 ff_sfc64_init(&prng_state, 0, 0, 0, 12);
1161 signal(SIGINT, exit_handler);
1162
1166 if (!sws_ref_src || !sws_src_dst || !sws_dst_out) {
1167 ret = AVERROR(ENOMEM);
1168 goto error;
1169 }
1172 sws_ref_src->backends = SWS_BACKEND_ALL;
1173 sws_dst_out->backends = SWS_BACKEND_ALL;
1174
1175 ref = av_frame_alloc();
1176 if (!ref) {
1177 ret = AVERROR(ENOMEM);
1178 goto error;
1179 }
1180 ref->width = opts.w;
1181 ref->height = opts.h;
1182 ref->format = AV_PIX_FMT_YUVA444P;
1183
1184 ret = init_ref(ref, &opts);
1185 if (ret < 0)
1186 goto error;
1187
1188 ret = fp ? run_file_tests(ref, fp, &opts)
1189 : run_self_tests(ref, &opts);
1190
1191 /* fall through */
1192error:
1199 if (fp)
1200 fclose(fp);
1201 exit_handler(ret);
1202}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
static const char *const format[]
Definition af_aiir.c:445
static FILE * out
static AVFormatContext * ctx
static AVDictionary * opts
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition avassert.h:58
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define f(width, name)
Definition cbs_vp8.c:236
#define ss(width, name, subs,...)
Definition cbs_vp9.c:202
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
__device__ int printf(const char *,...)
static AVFrame * frame
int main
Definition dovi_rpuenc.c:38
int8_t exp
Definition eval.c:76
static int dummy
Definition ffplay.c:4657
reference-counted frame API
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition buffer.c:140
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition error.h:122
#define AVERROR(e)
Definition error.h:45
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition frame.c:496
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition frame.c:206
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition frame.c:599
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition frame.c:52
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition log.h:204
#define AV_LOG_INFO
Standard information.
Definition log.h:221
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
void av_log_set_level(int level)
Set the log level.
Definition log.c:476
int av_log_get_level(void)
Get the current log level.
Definition log.c:471
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
Definition avstring.c:179
av_warn_unused_result int sws_init_context(SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter)
Initialize the swscaler context sws_context.
Definition utils.c:1937
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:1405
SwsContext * sws_alloc_context(void)
Allocate an empty SwsContext and set its fields to default values.
Definition utils.c:1051
void sws_free_context(SwsContext **ctx)
Free the context and everything associated with it, and write NULL to the provided pointer.
Definition utils.c:2374
SwsDither
Definition swscale.h:77
SwsBackend
Definition swscale.h:110
int sws_frame_setup(SwsContext *ctx, const AVFrame *dst, const AVFrame *src)
Like sws_scale_frame, but without actually scaling.
Definition swscale.c:1500
SwsScaler
Definition swscale.h:96
void sws_freeContext(SwsContext *swsContext)
Free the swscaler context swsContext.
Definition utils.c:2303
SwsFlags
Definition swscale.h:131
@ SWS_DITHER_AUTO
Definition swscale.h:79
@ SWS_BACKEND_LEGACY
Legacy bespoke format-specific code.
Definition swscale.h:112
@ SWS_BACKEND_STABLE
Definition swscale.h:113
@ SWS_BACKEND_ALL
Definition swscale.h:127
@ SWS_SCALE_AUTO
Definition swscale.h:97
@ SWS_BICUBIC
2-tap cubic B-spline
Definition swscale.h:199
@ SWS_BITEXACT
Definition swscale.h:178
@ SWS_AREA
area averaging
Definition swscale.h:202
@ SWS_BILINEAR
bilinear filtering
Definition swscale.h:198
@ SWS_FULL_CHR_H_INP
Perform full chroma interpolation when downscaling RGB sources.
Definition swscale.h:167
@ SWS_FAST_BILINEAR
Scaler selection options.
Definition swscale.h:197
@ SWS_ACCURATE_RND
Force bit-exact output.
Definition swscale.h:177
@ SWS_X
experimental
Definition swscale.h:200
@ SWS_POINT
nearest neighbor
Definition swscale.h:201
@ SWS_FULL_CHR_H_INT
Perform full chroma upsampling when upscaling to RGB.
Definition swscale.h:154
int av_opt_eval_int(void *obj, const AVOption *o, const char *val, int *int_out)
int av_opt_eval_flags(void *obj, const AVOption *o, const char *val, int *flags_out)
const AVOption * av_opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
Look for an option in an object.
Definition opt.c:2071
int a
static const int weights[]
Definition hevc_pel.c:32
static AVBufferRef * hw_device_ctx
Definition hw_decode.c:45
int av_hwdevice_ctx_create(AVBufferRef **pdevice_ref, enum AVHWDeviceType type, const char *device, AVDictionary *opts, int flags)
Open a device of the specified type and create an AVHWDeviceContext for it.
Definition hwcontext.c:615
void av_hwframe_constraints_free(AVHWFramesConstraints **constraints)
Free an AVHWFrameConstraints structure.
Definition hwcontext.c:606
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition hwcontext.c:337
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition hwcontext.c:263
int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags)
Copy data to or from a hw surface.
Definition hwcontext.c:448
AVHWFramesConstraints * av_hwdevice_get_hwframe_constraints(AVBufferRef *ref, const void *hwconfig)
Get the constraints on HW frames given a device and the HW-specific configuration to be used with tha...
Definition hwcontext.c:581
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
Definition hwcontext.c:506
@ AV_HWDEVICE_TYPE_VULKAN
Definition hwcontext.h:39
#define r
Definition input.c:42
#define b
Definition input.c:43
static int bad(InterplayACMContext *s, unsigned ind, unsigned col)
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
Definition lfg.c:32
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
Definition lfg.h:53
void av_force_cpu_flags(int arg)
Disables cpu detection and forces the specified flags.
Definition cpu.c:81
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
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition cpu.c:109
const char * desc
Definition libsvtav1.c:83
int ff_sws_test_pixfmt_backend(const SwsBackend backends, enum AVPixelFormat format, int output)
Definition format.c:628
uint8_t w
Definition llvidencdsp.c:39
Utility Preprocessor macros.
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
static const uint64_t c2
Definition murmur3.c:53
static const uint64_t c1
Definition murmur3.c:52
#define av_strdup(s)
Definition ops_static.c:55
AVOptions.
int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
Parse str and put in width_ptr and height_ptr the detected values.
Definition parseutils.c:150
misc parsing utilities
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:3380
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition pixdesc.c:3392
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3460
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition pixdesc.h:147
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition pixdesc.h:136
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
Definition pixdesc.h:158
pixel format definitions
#define AV_PIX_FMT_P412
Definition pixfmt.h:625
#define AV_PIX_FMT_P410
Definition pixfmt.h:623
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
Definition pixfmt.h:379
@ 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:508
@ AV_PIX_FMT_NV24
planar YUV 4:4:4, 24bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition pixfmt.h:371
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition pixfmt.h:100
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition pixfmt.h:174
#define AV_PIX_FMT_P416
Definition pixfmt.h:627
simple Pseudo Random Number Generator
static uint64_t ff_sfc64_get(FFSFC64 *s)
Definition sfc64.h:41
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
static volatile sig_atomic_t sig
Definition signal.c:48
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
Definition buffer.h:82
uint8_t * data
The data buffer.
Definition buffer.h:90
int depth
Number of bits in the component.
Definition pixdesc.h:57
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
int width
Definition frame.h:551
int height
Definition frame.h:551
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition frame.h:566
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
Definition hwcontext.h:444
This struct describes a set or pool of "hardware" frames (i.e.
Definition hwcontext.h:118
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition hwcontext.h:200
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition hwcontext.h:213
int width
The allocated dimensions of the frames in this pool.
Definition hwcontext.h:220
Context structure for the Lagged Fibonacci PRNG.
Definition lfg.h:33
AVOption.
Definition opt.h:428
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition pixdesc.h:105
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition pixdesc.h:80
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition pixdesc.h:89
Main external API structure.
Definition swscale.h:227
int src_h
Width and height of the source frame.
Definition swscale.h:272
int dst_format
Destination pixel format.
Definition swscale.h:275
int threads
How many threads to use for processing, or 0 for automatic selection.
Definition swscale.h:249
SwsScaler scaler
Scaling filter.
Definition swscale.h:294
int dst_h
Width and height of the destination frame.
Definition swscale.h:273
int dst_w
Definition swscale.h:273
SwsBackend backends
Bitmask of SWS_BACKEND_*.
Definition swscale.h:312
SwsScaler scaler_sub
Scaler used specifically for up/downsampling subsampled (chroma) planes.
Definition swscale.h:302
int src_w
Deprecated frame property overrides, for the legacy API only.
Definition swscale.h:272
int src_format
Source pixel format.
Definition swscale.h:274
SwsDither dither
Dither mode.
Definition swscale.h:254
unsigned flags
Bitmask of SWS_*.
Definition swscale.h:238
Definition swscale.c:71
SwsScaler scaler
Definition swscale.c:74
SwsDither dither
Definition swscale.c:73
SwsFlags flags
Definition swscale.c:72
SwsScaler scaler_sub
Definition swscale.c:75
int align_src
Definition swscale.c:64
int align_dst
Definition swscale.c:65
enum AVPixelFormat dst_fmt
Definition swscale.c:52
int bench
Definition swscale.c:59
enum AVPixelFormat src_fmt
Definition swscale.c:51
int backends
Definition swscale.c:68
int w
Definition swscale.c:54
int iters
Definition swscale.c:58
int h
Definition swscale.c:54
double prob
Definition swscale.c:53
int pretty
Definition swscale.c:67
int dither
Definition swscale.c:61
int scaler_sub
Definition swscale.c:63
int scaler
Definition swscale.c:62
int dst_h
Definition swscale.c:56
int threads
Definition swscale.c:57
int dst_w
Definition swscale.c:55
int api
Definition swscale.c:66
int flags
Definition swscale.c:60
Definition rpzaenc.c:60
float loss
Definition swscale.c:80
float ssim[4]
Definition swscale.c:79
int64_t time
Definition swscale.c:81
uint8_t level
Definition svq3.c:208
external API header
#define av_freep(p)
#define av_log(a,...)
static void error(const char *err)
#define src
Definition vp8dsp.c:248
static int ref[MAX_W *MAX_W]
#define height
Definition dsp.h:89
#define width
Definition dsp.h:89
static double speedup_min
Definition swscale.c:107
static const char * speedup_color(double ratio)
Definition swscale.c:111
static int init_ref(AVFrame *ref, const struct options *opts)
Definition swscale.c:862
static double speedup_logavg
Definition swscale.c:106
#define IMPL_LEGACY
Definition swscale.c:48
static int scale_new(AVFrame *dst, const AVFrame *src, const struct mode *mode, const struct options *opts, int64_t *out_time)
Definition swscale.c:248
static float estimate_quantization_noise(enum AVPixelFormat fmt)
Definition swscale.c:135
static int speedup_count
Definition swscale.c:109
static void exit_handler(int sig)
Definition swscale.c:122
static void print_test_params(char *buf, size_t buf_size, const AVFrame *src, const AVFrame *dst, const struct mode *mode, const struct options *opts)
Definition swscale.c:454
static double speedup_max
Definition swscale.c:108
static int fmt_disabled(const struct options *opts, enum AVPixelFormat fmt)
Definition swscale.c:693
static float get_loss(const float ssim[4])
Definition swscale.c:214
#define IMPL_NEW
Definition swscale.c:47
static int checked_sws_scale_frame(SwsContext *c, AVFrame *dst, const AVFrame *src)
Definition swscale.c:238
static FFSFC64 prng_state
Definition swscale.c:96
static int init_frame(AVFrame **pframe, const AVFrame *ref, int width, int height, enum AVPixelFormat format)
Definition swscale.c:554
static int run_self_tests(const AVFrame *ref, const struct options *opts)
Definition swscale.c:716
static int run_file_tests(const AVFrame *ref, FILE *fp, const struct options *opts)
Definition swscale.c:789
static int parse_implementation(const char *str)
Definition swscale.c:920
static int scale_hw(AVFrame *dst, const AVFrame *src, const struct mode *mode, const struct options *opts, int64_t *out_time)
Definition swscale.c:327
static int run_test(enum AVPixelFormat src_fmt, enum AVPixelFormat dst_fmt, int dst_w, int dst_h, const struct mode *mode, const struct options *opts, const AVFrame *ref, AVFrame **psrc, const struct test_results *ref_r)
Definition swscale.c:569
static int fmt_is_supported_by_hw(enum AVPixelFormat fmt)
Definition swscale.c:678
static int scale_legacy(AVFrame *dst, const AVFrame *src, const struct mode *mode, const struct options *opts, int64_t *out_time)
Definition swscale.c:282
static void get_ssim(float ssim[4], const AVFrame *out, const AVFrame *ref, int comps)
Definition swscale.c:166
static int fmt_is_subsampled(enum AVPixelFormat fmt)
Definition swscale.c:672
static SwsContext * sws_ref_src
Definition swscale.c:99
static int parse_size(struct options *opts, const char *str, char **pbuf)
Definition swscale.c:896
static int parse_options(int argc, char **argv, struct options *opts, FILE **fp)
Definition swscale.c:929
static int fmt_comps(enum AVPixelFormat fmt)
Definition swscale.c:157
static void print_results(const AVFrame *ref, const AVFrame *src, const AVFrame *dst, int dst_w, int dst_h, const struct mode *mode, const struct options *opts, const struct test_results *r, const struct test_results *ref_r, float expected_loss)
Definition swscale.c:472
static AVHWFramesConstraints * hw_device_constr
Definition swscale.c:104
static SwsContext * sws_src_dst
Definition swscale.c:100
static int test_formats(const struct options *opts, enum AVPixelFormat src, enum AVPixelFormat dst)
Definition swscale.c:700
static void unref_buffers(AVFrame *frame)
Definition swscale.c:226
static SwsContext * sws_dst_out
Definition swscale.c:101
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition time.c:57
const char * g
Definition vf_curves.c:128
static double c[64]