FFmpeg
Data Structures | Macros | Functions | Variables
swscale.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <stdarg.h>
#include <signal.h>
#include "libavutil/cpu.h"
#include "libavutil/avstring.h"
#include "libavutil/parseutils.h"
#include "libavutil/pixdesc.h"
#include "libavutil/lfg.h"
#include "libavutil/sfc64.h"
#include "libavutil/frame.h"
#include "libavutil/opt.h"
#include "libavutil/time.h"
#include "libavutil/pixfmt.h"
#include "libavutil/avassert.h"
#include "libavutil/macros.h"
#include "libavutil/hwcontext.h"
#include "libswscale/swscale.h"
#include "libswscale/format.h"

Go to the source code of this file.

Data Structures

struct  options
 
struct  mode
 
struct  test_results
 

Macros

#define IMPL_NEW   0
 
#define IMPL_LEGACY   1
 

Functions

static const char * speedup_color (double ratio)
 
static void exit_handler (int sig)
 
static float estimate_quantization_noise (enum AVPixelFormat fmt)
 
static int fmt_comps (enum AVPixelFormat fmt)
 
static void get_ssim (float ssim[4], const AVFrame *out, const AVFrame *ref, int comps)
 
static float get_loss (const float ssim[4])
 
static void unref_buffers (AVFrame *frame)
 
static int checked_sws_scale_frame (SwsContext *c, AVFrame *dst, const AVFrame *src)
 
static int scale_new (AVFrame *dst, const AVFrame *src, const struct mode *mode, const struct options *opts, int64_t *out_time)
 
static int scale_legacy (AVFrame *dst, const AVFrame *src, const struct mode *mode, const struct options *opts, int64_t *out_time)
 
static int scale_hw (AVFrame *dst, const AVFrame *src, const struct mode *mode, const struct options *opts, int64_t *out_time)
 
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)
 
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)
 
static int init_frame (AVFrame **pframe, const AVFrame *ref, int width, int height, enum AVPixelFormat format)
 
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)
 
static int fmt_is_subsampled (enum AVPixelFormat fmt)
 
static int fmt_is_supported_by_hw (enum AVPixelFormat fmt)
 
static int fmt_disabled (const struct options *opts, enum AVPixelFormat fmt)
 
static int test_formats (const struct options *opts, enum AVPixelFormat src, enum AVPixelFormat dst)
 
static int run_self_tests (const AVFrame *ref, const struct options *opts)
 
static int run_file_tests (const AVFrame *ref, FILE *fp, const struct options *opts)
 
static int init_ref (AVFrame *ref, const struct options *opts)
 
static int parse_size (struct options *opts, const char *str, char **pbuf)
 
static int parse_implementation (const char *str)
 
static int parse_options (int argc, char **argv, struct options *opts, FILE **fp)
 
int main (int argc, char **argv)
 

Variables

const SwsFlags flags []
 
static FFSFC64 prng_state
 
static SwsContextsws_ref_src
 
static SwsContextsws_src_dst
 
static SwsContextsws_dst_out
 
static AVBufferRefhw_device_ctx = NULL
 
static AVHWFramesConstraintshw_device_constr = NULL
 
static double speedup_logavg
 
static double speedup_min = 1e10
 
static double speedup_max = 0
 
static int speedup_count
 

Macro Definition Documentation

◆ IMPL_NEW

#define IMPL_NEW   0

Definition at line 47 of file swscale.c.

◆ IMPL_LEGACY

#define IMPL_LEGACY   1

Definition at line 48 of file swscale.c.

Function Documentation

◆ speedup_color()

static const char* speedup_color ( double  ratio)
static

Definition at line 111 of file swscale.c.

Referenced by exit_handler(), and print_results().

◆ exit_handler()

static void exit_handler ( int  sig)
static

Definition at line 122 of file swscale.c.

Referenced by main().

◆ estimate_quantization_noise()

static float estimate_quantization_noise ( enum AVPixelFormat  fmt)
static

Definition at line 135 of file swscale.c.

Referenced by run_test().

◆ fmt_comps()

static int fmt_comps ( enum AVPixelFormat  fmt)
static

Definition at line 157 of file swscale.c.

Referenced by run_test().

◆ get_ssim()

static void get_ssim ( float  ssim[4],
const AVFrame out,
const AVFrame ref,
int  comps 
)
static

Definition at line 166 of file swscale.c.

Referenced by run_test().

◆ get_loss()

static float get_loss ( const float  ssim[4])
static

Definition at line 214 of file swscale.c.

Referenced by run_test().

◆ unref_buffers()

static void unref_buffers ( AVFrame frame)
static

Definition at line 226 of file swscale.c.

Referenced by scale_new().

◆ checked_sws_scale_frame()

static int checked_sws_scale_frame ( SwsContext c,
AVFrame dst,
const AVFrame src 
)
static

Definition at line 238 of file swscale.c.

Referenced by init_ref(), run_test(), scale_hw(), scale_legacy(), and scale_new().

◆ scale_new()

static int scale_new ( AVFrame dst,
const AVFrame src,
const struct mode mode,
const struct options opts,
int64_t out_time 
)
static

Definition at line 248 of file swscale.c.

Referenced by run_test().

◆ scale_legacy()

static int scale_legacy ( AVFrame dst,
const AVFrame src,
const struct mode mode,
const struct options opts,
int64_t out_time 
)
static

Definition at line 282 of file swscale.c.

Referenced by run_test().

◆ scale_hw()

static int scale_hw ( AVFrame dst,
const AVFrame src,
const struct mode mode,
const struct options opts,
int64_t out_time 
)
static

Definition at line 327 of file swscale.c.

Referenced by run_test().

◆ print_test_params()

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 
)
static

Definition at line 453 of file swscale.c.

Referenced by print_results().

◆ print_results()

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 
)
static

The new scaling code does not (yet) perform error diffusion for low bit depth output, which impacts the SSIM score slightly for very low bit-depth formats (e.g. monow, monob). Since this is an expected result, drop the badness from an error to a warning for such cases. This can be removed again once error diffusion is implemented in the new ops code.

Definition at line 471 of file swscale.c.

Referenced by run_test().

◆ init_frame()

static int init_frame ( AVFrame **  pframe,
const AVFrame ref,
int  width,
int  height,
enum AVPixelFormat  format 
)
static

Definition at line 553 of file swscale.c.

Referenced by run_test().

◆ run_test()

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 
)
static

Definition at line 568 of file swscale.c.

Referenced by run_file_tests(), and run_self_tests().

◆ fmt_is_subsampled()

static int fmt_is_subsampled ( enum AVPixelFormat  fmt)
inlinestatic

Definition at line 671 of file swscale.c.

Referenced by fmt_disabled().

◆ fmt_is_supported_by_hw()

static int fmt_is_supported_by_hw ( enum AVPixelFormat  fmt)
inlinestatic

Definition at line 677 of file swscale.c.

Referenced by fmt_disabled().

◆ fmt_disabled()

static int fmt_disabled ( const struct options opts,
enum AVPixelFormat  fmt 
)
inlinestatic

Definition at line 692 of file swscale.c.

Referenced by run_self_tests().

◆ test_formats()

static int test_formats ( const struct options opts,
enum AVPixelFormat  src,
enum AVPixelFormat  dst 
)
inlinestatic

Definition at line 699 of file swscale.c.

Referenced by run_self_tests().

◆ run_self_tests()

static int run_self_tests ( const AVFrame ref,
const struct options opts 
)
static

Definition at line 715 of file swscale.c.

Referenced by main().

◆ run_file_tests()

static int run_file_tests ( const AVFrame ref,
FILE *  fp,
const struct options opts 
)
static

Definition at line 788 of file swscale.c.

Referenced by main().

◆ init_ref()

static int init_ref ( AVFrame ref,
const struct options opts 
)
static

Definition at line 861 of file swscale.c.

Referenced by main().

◆ parse_size()

static int parse_size ( struct options opts,
const char *  str,
char **  pbuf 
)
static

Definition at line 895 of file swscale.c.

Referenced by parse_options().

◆ parse_implementation()

static int parse_implementation ( const char *  str)
static

Definition at line 919 of file swscale.c.

Referenced by parse_options().

◆ parse_options()

static int parse_options ( int  argc,
char **  argv,
struct options opts,
FILE **  fp 
)
static

Definition at line 928 of file swscale.c.

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 1123 of file swscale.c.

Variable Documentation

◆ flags

const SwsFlags flags[]

◆ prng_state

FFSFC64 prng_state
static

Definition at line 96 of file swscale.c.

Referenced by main(), and run_self_tests().

◆ sws_ref_src

SwsContext* sws_ref_src
static

Definition at line 99 of file swscale.c.

Referenced by main(), run_test(), and test_formats().

◆ sws_src_dst

SwsContext* sws_src_dst
static

Definition at line 100 of file swscale.c.

Referenced by main(), and scale_new().

◆ sws_dst_out

SwsContext* sws_dst_out
static

Definition at line 101 of file swscale.c.

Referenced by main(), run_test(), and test_formats().

◆ hw_device_ctx

AVBufferRef* hw_device_ctx = NULL
static

Definition at line 103 of file swscale.c.

Referenced by main(), parse_options(), run_test(), and scale_hw().

◆ hw_device_constr

AVHWFramesConstraints* hw_device_constr = NULL
static

Definition at line 104 of file swscale.c.

Referenced by fmt_disabled(), fmt_is_supported_by_hw(), main(), and parse_options().

◆ speedup_logavg

double speedup_logavg
static

Definition at line 106 of file swscale.c.

Referenced by exit_handler(), and print_results().

◆ speedup_min

double speedup_min = 1e10
static

Definition at line 107 of file swscale.c.

Referenced by exit_handler(), and print_results().

◆ speedup_max

double speedup_max = 0
static

Definition at line 108 of file swscale.c.

Referenced by exit_handler(), and print_results().

◆ speedup_count

int speedup_count
static

Definition at line 109 of file swscale.c.

Referenced by exit_handler(), and print_results().

SWS_BILINEAR
@ SWS_BILINEAR
bilinear filtering
Definition: swscale.h:198
SWS_BITEXACT
@ SWS_BITEXACT
Definition: swscale.h:178
SWS_FAST_BILINEAR
@ SWS_FAST_BILINEAR
Scaler selection options.
Definition: swscale.h:197
SWS_FULL_CHR_H_INP
@ SWS_FULL_CHR_H_INP
Perform full chroma interpolation when downscaling RGB sources.
Definition: swscale.h:167
SWS_AREA
@ SWS_AREA
area averaging
Definition: swscale.h:202
SWS_BICUBIC
@ SWS_BICUBIC
2-tap cubic B-spline
Definition: swscale.h:199
SWS_POINT
@ SWS_POINT
nearest neighbor
Definition: swscale.h:201
SWS_X
@ SWS_X
experimental
Definition: swscale.h:200
SWS_FULL_CHR_H_INT
@ SWS_FULL_CHR_H_INT
Perform full chroma upsampling when upscaling to RGB.
Definition: swscale.h:154
SWS_ACCURATE_RND
@ SWS_ACCURATE_RND
Force bit-exact output.
Definition: swscale.h:177