Go to the documentation of this file.
28 #undef HAVE_AV_CONFIG_H
74 int comps =
desc->nb_components >= 3 ? 0b111 : 0
b1;
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;
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];
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;
111 mse[p] = sum / (
w *
h);
138 for (
int i = 0;
ret >= 0 &&
i <
opts.iters;
i++)
152 int mse[4], mse_sws[4],
ret = -1;
167 out->format =
ref->format;
168 src->format = src_fmt;
169 dst->format = dst_fmt;
185 for (
int i = 0;
i <
opts.iters;
i++) {
202 printf(
"%s %dx%d -> %s %3dx%3d, flags=%u dither=%u, "
203 "MSE={%5d %5d %5d %5d}\n",
207 mse[0], mse[1], mse[2], mse[3]);
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]);
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);
268 src_fmt_min = src_fmt_max =
opts.src_fmt;
270 dst_fmt_min = dst_fmt_max =
opts.dst_fmt;
272 for (src_fmt = src_fmt_min; src_fmt <= src_fmt_max; src_fmt++) {
275 for (dst_fmt = dst_fmt_min; dst_fmt <= dst_fmt_max; dst_fmt++) {
284 if (
run_test(src_fmt, dst_fmt, dst_w[
w], dst_h[
h],
299 while (fgets(buf,
sizeof(buf), fp)) {
300 char src_fmt_str[20], dst_fmt_str[20];
303 int sw, sh, dw, dh, mse[4];
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,
311 &mse[0], &mse[1], &mse[2], &mse[3]);
320 sw !=
ref->width || sh !=
ref->height || dw > 8192 || dh > 8192 ||
322 fprintf(stderr,
"malformed input file\n");
337 int main(
int argc,
char **argv)
354 for (
int i = 1;
i < argc;
i += 2) {
355 if (!strcmp(argv[
i],
"-help") || !strcmp(argv[
i],
"--help")) {
357 "swscale [options...]\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"
366 " Only test the specified destination pixel format\n"
368 " Only test the specified source pixel format\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"
378 if (argv[
i][0] !=
'-' ||
i + 1 == argc)
380 if (!strcmp(argv[
i],
"-ref")) {
381 fp = fopen(argv[
i + 1],
"r");
383 fprintf(stderr,
"could not open '%s'\n", argv[
i + 1]);
386 }
else if (!strcmp(argv[
i],
"-cpuflags")) {
390 fprintf(stderr,
"invalid cpu flags %s\n", argv[
i + 1]);
394 }
else if (!strcmp(argv[
i],
"-src")) {
397 fprintf(stderr,
"invalid pixel format %s\n", argv[
i + 1]);
400 }
else if (!strcmp(argv[
i],
"-dst")) {
403 fprintf(stderr,
"invalid pixel format %s\n", argv[
i + 1]);
406 }
else if (!strcmp(argv[
i],
"-bench")) {
408 opts.iters = atoi(argv[
i + 1]);
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]);
418 fprintf(stderr,
"bad option or argument missing (%s) see -help\n", argv[
i]);
426 for (
int i = 0;
i < 3;
i++) {
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++)
464 for (
int i = 0;
i < 3;
i++)
static void error(const char *err)
void av_force_cpu_flags(int arg)
Disables cpu detection and forces the specified flags.
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
AVPixelFormat
Pixel format.
static int scale_legacy(AVFrame *dst, const AVFrame *src, struct mode mode, struct options opts)
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
int src_w
Deprecated frame property overrides, for the legacy API only.
void sws_freeContext(SwsContext *swsContext)
Free the swscaler context swsContext.
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])
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
@ SWS_BILINEAR
bilinear filtering
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.
unsigned flags
Bitmask of SWS_*.
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
static FFSFC64 prng_state
static int run_file_tests(const AVFrame *ref, FILE *fp, struct options opts)
@ AV_PIX_FMT_NB
number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of...
@ SWS_FAST_BILINEAR
Scaler selection options.
static double b1(void *priv, double x, double y)
@ SWS_FULL_CHR_H_INP
Perform full chroma interpolation when downscaling RGB sources.
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.
av_warn_unused_result int sws_init_context(SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter)
Initialize the swscaler context sws_context.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
enum AVPixelFormat dst_fmt
#define FF_ARRAY_ELEMS(a)
SwsDither dither
Dither mode.
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
int threads
How many threads to use for processing, or 0 for automatic selection.
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
static int run_self_tests(const AVFrame *ref, struct options opts)
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
static void get_mse(int mse[4], const AVFrame *a, const AVFrame *b, int comps)
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
@ SWS_BICUBIC
2-tap cubic B-spline
int sws_test_format(enum AVPixelFormat format, int output)
Test if a given pixel format is supported.
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
enum AVPixelFormat src_fmt
Context structure for the Lagged Fibonacci PRNG.
SwsContext * sws_alloc_context(void)
Allocate an empty SwsContext and set its fields to default values.
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
@ SWS_POINT
nearest neighbor
int src_h
Width and height of the source frame.
printf("static const uint8_t my_array[100] = {\n")
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
int dst_format
Destination pixel format.
static SwsContext * sws[3]
#define i(width, name, range_min, range_max)
const struct mode modes[]
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
int dst_h
Width and height of the destination frame.
static uint64_t ff_sfc64_get(FFSFC64 *s)
@ SWS_FULL_CHR_H_INT
Perform full chroma upsampling when upscaling to RGB.
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
int main(int argc, char **argv)
static int ref[MAX_W *MAX_W]
static int bad(InterplayACMContext *s, unsigned ind, unsigned col)
int src_format
Source pixel format.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
void sws_free_context(SwsContext **ctx)
Free the context and everything associated with it, and write NULL to the provided pointer.
#define flags(name, subs,...)
int sws_scale_frame(SwsContext *sws, AVFrame *dst, const AVFrame *src)
Scale source data from src and write the output to dst.
@ SWS_ACCURATE_RND
Force bit-exact output.
Main external API structure.
static int fmt_comps(enum AVPixelFormat fmt)
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.