FFmpeg
Loading...
Searching...
No Matches
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/bprint.h"
#include "libavutil/parseutils.h"
#include "libavutil/pixdesc.h"
#include "libavutil/lfg.h"
#include "libavutil/md5.h"
#include "libavutil/sfc64.h"
#include "libavutil/slicethread.h"
#include "libavutil/thread.h"
#include "libavutil/threadmessage.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"
#include "libswscale/swscale_internal.h"

Go to the source code of this file.

Data Structures

struct  options
 
struct  mode
 
struct  test_results
 
struct  runner
 
struct  test_case
 

Macros

#define IMPL_NEW   0
 
#define IMPL_LEGACY   1
 

Enumerations

enum  { AUX_BACKENDS = SWS_BACKEND_ALL , AUX_FLAGS = SWS_BILINEAR | SWS_BITEXACT | SWS_ACCURATE_RND }
 

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 get_buffer (AVFrame *frame, int align)
 
static int checked_sws_scale_frame (SwsContext *c, AVFrame *dst, const AVFrame *src)
 
static int scale_new (struct runner *runner, 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 (AVBPrint *bp, 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 const char * backend_name (SwsBackend backend)
 
static void describe_passes (AVBPrint *bp, const SwsGraph *graph)
 
static void print_coverage_result (const AVFrame *src, const AVFrame *dst, const struct mode *mode, const struct options *opts, const SwsGraph *graph)
 
static int check_coverage (struct runner *runner, const struct test_case *t, const struct mode *mode, const struct options *opts)
 
static int run_coverage (struct runner *runner, const struct test_case *t, const struct options *opts)
 
static void print_coverage_summary (void)
 
static int run_test (struct runner *runner, const struct test_case *t, const struct options *opts)
 
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 push_test (const struct test_case *t, const struct options *opts)
 
static int run_self_tests (const struct options *opts)
 
static int run_file_tests (const struct options *opts)
 
static int runner_init (struct runner *runner)
 
static void runner_free (struct runner *runner)
 
static int run_tests (const struct options *opts)
 
static int run_producer (void *priv)
 
static int run_runner (void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads)
 
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_threads (struct options *opts, const char *str)
 
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 []
 
struct { 
 
   FFSFC64   prng_state 
 
   AVBufferRef *   hw_device_ctx 
 
   AVHWFramesConstraints *   hw_device_constr 
 
   AVMutex   speedup_lock 
 
   double   speedup_logavg 
 
   double   speedup_min 
 
   double   speedup_max 
 
   int   speedup_count 
 
   int   coverage_total 
 
   int   coverage_supported 
 
   struct AVMD5 *   coverage_md5 
 
   struct runner *   runners 
 
   AVFrame *   ref 
 
   FILE *   fp 
 
   AVThreadMessageQueue *   queue 
 
} state 
 
static const SwsFlags coverage_flags []
 

Macro Definition Documentation

◆ IMPL_NEW

#define IMPL_NEW   0

Definition at line 53 of file swscale.c.

Referenced by parse_implementation().

◆ IMPL_LEGACY

#define IMPL_LEGACY   1

Definition at line 54 of file swscale.c.

Referenced by parse_implementation(), parse_options(), run_test(), and test_formats().

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
AUX_BACKENDS 
AUX_FLAGS 

Definition at line 57 of file swscale.c.

Function Documentation

◆ speedup_color()

static const char * speedup_color ( double ratio)
static

Definition at line 154 of file swscale.c.

Referenced by exit_handler(), and print_results().

◆ exit_handler()

static void exit_handler ( int sig)
static

Definition at line 165 of file swscale.c.

Referenced by main().

◆ estimate_quantization_noise()

static float estimate_quantization_noise ( enum AVPixelFormat fmt)
static

Definition at line 178 of file swscale.c.

Referenced by run_test().

◆ fmt_comps()

static int fmt_comps ( enum AVPixelFormat fmt)
static

Definition at line 200 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 209 of file swscale.c.

Referenced by run_test().

◆ get_loss()

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

Definition at line 257 of file swscale.c.

Referenced by run_test().

◆ unref_buffers()

static void unref_buffers ( AVFrame * frame)
static

Definition at line 269 of file swscale.c.

Referenced by scale_new().

◆ get_buffer()

static int get_buffer ( AVFrame * frame,
int align )
static

Definition at line 282 of file swscale.c.

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

◆ checked_sws_scale_frame()

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

Definition at line 301 of file swscale.c.

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

◆ scale_new()

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

Definition at line 311 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 346 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 391 of file swscale.c.

Referenced by run_test().

◆ print_test_params()

static void print_test_params ( AVBPrint * bp,
const AVFrame * src,
const AVFrame * dst,
const struct mode * mode,
const struct options * opts )
static

Definition at line 518 of file swscale.c.

Referenced by print_coverage_result(), and 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 536 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 627 of file swscale.c.

Referenced by check_coverage(), and run_test().

◆ backend_name()

static const char * backend_name ( SwsBackend backend)
static

Definition at line 641 of file swscale.c.

Referenced by describe_passes().

◆ describe_passes()

static void describe_passes ( AVBPrint * bp,
const SwsGraph * graph )
static

Definition at line 654 of file swscale.c.

Referenced by print_coverage_result().

◆ print_coverage_result()

static void print_coverage_result ( const AVFrame * src,
const AVFrame * dst,
const struct mode * mode,
const struct options * opts,
const SwsGraph * graph )
static

Definition at line 669 of file swscale.c.

Referenced by check_coverage().

◆ check_coverage()

static int check_coverage ( struct runner * runner,
const struct test_case * t,
const struct mode * mode,
const struct options * opts )
static

Definition at line 696 of file swscale.c.

Referenced by run_coverage().

◆ run_coverage()

static int run_coverage ( struct runner * runner,
const struct test_case * t,
const struct options * opts )
static

Definition at line 747 of file swscale.c.

Referenced by push_test().

◆ print_coverage_summary()

static void print_coverage_summary ( void )
static

Definition at line 764 of file swscale.c.

Referenced by main().

◆ run_test()

static int run_test ( struct runner * runner,
const struct test_case * t,
const struct options * opts )
static

Definition at line 775 of file swscale.c.

Referenced by push_test(), and run_runner().

◆ fmt_is_subsampled()

static int fmt_is_subsampled ( enum AVPixelFormat fmt)
inlinestatic

Definition at line 881 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 887 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 902 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 909 of file swscale.c.

Referenced by run_self_tests().

◆ push_test()

static int push_test ( const struct test_case * t,
const struct options * opts )
static

Definition at line 925 of file swscale.c.

Referenced by run_file_tests(), and run_self_tests().

◆ run_self_tests()

static int run_self_tests ( const struct options * opts)
static

Definition at line 934 of file swscale.c.

Referenced by run_tests().

◆ run_file_tests()

static int run_file_tests ( const struct options * opts)
static

Definition at line 1011 of file swscale.c.

Referenced by run_tests().

◆ runner_init()

static int runner_init ( struct runner * runner)
static

Definition at line 1093 of file swscale.c.

Referenced by main().

◆ runner_free()

static void runner_free ( struct runner * runner)
static

Definition at line 1107 of file swscale.c.

Referenced by main().

◆ run_tests()

static int run_tests ( const struct options * opts)
static

Definition at line 1115 of file swscale.c.

Referenced by main(), and run_producer().

◆ run_producer()

static int run_producer ( void * priv)
static

Definition at line 1120 of file swscale.c.

Referenced by main().

◆ run_runner()

static int run_runner ( void * priv,
int jobnr,
int threadnr,
int nb_jobs,
int nb_threads )
static

Definition at line 1129 of file swscale.c.

Referenced by main().

◆ init_ref()

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

Definition at line 1149 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 1183 of file swscale.c.

Referenced by parse_options().

◆ parse_threads()

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

Definition at line 1208 of file swscale.c.

Referenced by parse_options().

◆ parse_implementation()

static int parse_implementation ( const char * str)
static

Definition at line 1228 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 1237 of file swscale.c.

Referenced by main().

◆ main()

int main ( int argc,
char ** argv )

Definition at line 1463 of file swscale.c.

Variable Documentation

◆ flags

const SwsFlags flags[]
Initial value:
= {
0,
}
@ 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

Definition at line 116 of file swscale.c.

◆ prng_state

FFSFC64 prng_state

Definition at line 128 of file swscale.c.

◆ hw_device_ctx

AVBufferRef* hw_device_ctx

Definition at line 130 of file swscale.c.

◆ hw_device_constr

AVHWFramesConstraints* hw_device_constr

Definition at line 131 of file swscale.c.

◆ speedup_lock

AVMutex speedup_lock

Definition at line 133 of file swscale.c.

◆ speedup_logavg

double speedup_logavg

Definition at line 134 of file swscale.c.

◆ speedup_min

double speedup_min

Definition at line 135 of file swscale.c.

◆ speedup_max

double speedup_max

Definition at line 136 of file swscale.c.

◆ speedup_count

int speedup_count

Definition at line 137 of file swscale.c.

◆ coverage_total

int coverage_total

Definition at line 139 of file swscale.c.

◆ coverage_supported

int coverage_supported

Definition at line 140 of file swscale.c.

◆ coverage_md5

struct AVMD5* coverage_md5

Definition at line 141 of file swscale.c.

◆ runners

struct runner* runners

Definition at line 143 of file swscale.c.

Referenced by parse_threads().

◆ ref

AVFrame* ref

Definition at line 144 of file swscale.c.

◆ fp

◆ queue

◆ [struct]

struct { ... } state
Initial value:
= {
.speedup_lock = AV_MUTEX_INITIALIZER,
.speedup_min = 1e10,
}
#define AV_MUTEX_INITIALIZER
Definition thread.h:185

Referenced by aac_sync(), adts_aac_resync(), adx_parse(), ahx_parse(), apng_probe(), apv_decode_long_level(), apv_decode_long_run(), apv_entropy_decode_block(), apv_entropy_decode_block_internal(), atrac9_init_static(), atrac9_init_vlc(), au_compress(), au_decompress(), av1_filter_obus(), av_log_once(), av_log_once(), av_lzo1x_decode(), av_rc4_crypt(), av_rc4_init(), avi_read_packet(), avpriv_find_start_code(), avpriv_find_start_code(), avpriv_fits_header_init(), avs2_find_frame_end(), avs2_probe(), avs3_find_frame_end(), avs3video_probe(), bfi_read_packet(), bmp_parse(), bonk_decode(), build_coeff_vlc(), build_vlc(), cabac_init_state(), cavs_find_frame_end(), ccitt_unpack_init(), check_coverage(), check_cpu_flag(), check_script(), checkasm_bench_runs(), checkasm_bench_update(), checkasm_check_key(), checkasm_list_functions(), checkasm_report(), checkasm_run(), clv_init_static(), cng_rand(), compute_gru(), cri_parse(), dca_find_frame_end(), decode_cabac_intra_mb_type(), decode_current_mul(), decode_init_static(), decode_line_TMPL(), decode_remap(), decode_significance_8x8_loongarch(), decode_significance_loongarch(), decode_slice_header(), decode_spectrum_ac(), delta_decode(), dfpwm_dec_frame(), dfpwm_dec_init(), dfpwm_enc_frame(), dfpwm_enc_init(), dnxhd_find_frame_end(), dnxuc_parse(), dpx_parse(), draw_cubic_curve_to(), draw_quad_curve_to(), draw_scope(), dts_probe(), dvdvideo_chapters_setup_preindex(), dvdvideo_menu_close(), dvdvideo_menu_next_ps_block(), dvdvideo_menu_open(), dvdvideo_play_close(), dvdvideo_play_next_ps_block(), dvdvideo_play_open(), dxv_compress_dxt1(), dxv_decompress_cgo(), dxv_decompress_dxt1(), dxv_decompress_dxt5(), dxv_decompress_yo(), ec_gain_code(), ec_gain_pitch(), encode_float32_remap_segment(), encode_high(), encode_histogram_remap(), encode_line_TMPL(), encode_low(), encode_picture_ls(), encode_slice_header(), exit_handler(), extract_extradata_mpeg12(), extract_extradata_mpeg4(), extract_extradata_vc1(), ff_aac_ac_finish(), ff_aac_ac_get_context(), ff_aac_ac_map_process(), ff_aac_ac_update_context(), ff_apv_entropy_decode_block(), ff_dshow_filter_GetState(), ff_dshow_filter_Pause(), ff_dshow_filter_Run(), ff_dshow_filter_Stop(), ff_ffv1_get_symbol(), ff_ffv1_parse_header(), ff_ffv1_read_extra_header(), ff_ffv1_write_extradata(), ff_h264_decode_init_vlc(), ff_http_auth_create_response(), ff_http_auth_handle_header(), ff_jpegls_decode_picture(), ff_jpegls_downscale_state(), ff_jpegls_init_state(), ff_jpegls_update_state_regular(), ff_mlp_filter_channel_arm(), ff_rtp_send_h263_rfc2190(), ff_spdif_probe(), ff_spdif_read_packet(), ff_vlc_init_tables(), ff_vlc_init_tables_from_lengths(), ff_vlc_init_tables_sparse(), filter_frame(), find_any_startcode(), find_frame_end(), find_frame_end(), find_frame_end(), find_group3_syncmarker(), find_next_start_code(), find_start_code(), fmt_disabled(), fmt_is_supported_by_hw(), format_child_class_iterate(), frame_merge_filter(), ftr_parse(), gem_decode_frame(), gen_vlc(), get_cabac(), get_cabac_inline(), get_cabac_inline_loongarch(), get_cabac_inline_mips(), get_cabac_noinline(), get_ffv1_unsigned_symbol(), get_rac(), get_random_number(), get_symbol(), get_symbol2(), get_symbol_inline(), get_vlc_symbol(), h261_find_frame_end(), h263_find_frame_end(), h264_find_frame_end(), h264_split(), handle_basic_params(), handle_digest_params(), handle_digest_update(), hdcd_analyze_prepare(), hdcd_control(), hdcd_detect_onech(), hdcd_process(), hdcd_reset(), hdr_parse(), hevc_split(), hqx_init_static(), iir_filter(), imc_init_static(), init_base_tables(), init_sbr_tables(), init_tables_once(), ipu_parse(), iterative_me(), jpeg_probe(), jpegxs_find_frame_end(), latm_find_frame_end(), LCEVC_BLOCK_FUNC(), LCEVC_BLOCK_FUNC(), LCEVC_BLOCK_FUNC(), LCEVC_BLOCK_FUNC(), LCEVC_BLOCK_FUNC(), LCEVC_BLOCK_FUNC(), libgsm_encode_frame(), ls_decode_line(), ls_encode_line(), ls_encode_regular(), ls_encode_run(), ls_encode_runterm(), ls_get_code_regular(), ls_get_code_runterm(), ls_store_lse(), main(), main(), make_digest_auth(), message(), misc4_parse(), mix(), mlp_filter_channel(), mobiclip_init_static(), mpc7_init_static(), mpeg1_find_frame_end(), mpeg4_find_frame_end(), mpeg4video_split(), mpegaudio_parse(), mpegaudiodec_common_init_static(), mpegts_write_packet_internal(), mpegvideo_split(), msmp4_vc1_vlcs_init(), msmpeg4_decode_init_static(), mxf_parse_ffv1_frame(), mxf_parse_h264_frame(), nc_read_packet(), next_gain(), opus_find_frame_end(), parse(), parse_adaptation_sets(), parse_adaptation_sets(), parse_nal_units(), parse_options(), parse_presentation_segment(), parse_profile_level(), predictor_calc_error(), predictor_init_state(), print_bench_header(), print_bench_iter(), print_coverage_result(), print_coverage_summary(), print_info(), print_results(), print_summary(), prng_shift(), process_block(), process_new(), process_old(), pulse_context_wait(), pulse_read_header(), pulse_stream_wait(), push_test(), put_cabac(), put_lines_bits(), put_lines_bytes(), put_rac(), put_symbol(), put_symbol(), put_symbol2(), put_symbol_inline(), put_vlc_symbol(), qoi_parse(), ran(), read_header(), read_high_coeffs(), read_low_coeffs(), read_quant_table(), ripemd128_transform(), ripemd160_transform(), ripemd256_transform(), ripemd320_transform(), rm_sync(), rtsp_read_set_state(), run_file_tests(), run_producer(), run_runner(), run_self_tests(), run_test(), run_tests(), rv40_init_table(), rv40_init_tables(), rv60_init_static_data(), rw2_parse(), s337m_get_offset_and_codec(), s337m_probe(), s337m_read_packet(), sbc_synthesize_audio(), sbc_synthesize_eight(), sbc_synthesize_four(), scale_hw(), SEI_FUNC(), SEI_FUNC(), SEI_FUNC(), SEI_FUNC(), SEI_FUNC(), SEI_FUNC(), SEI_FUNC(), SEI_FUNC(), SEI_FUNC(), SEI_FUNC(), SEI_FUNC(), SEI_FUNC(), send_mode_b(), sha1_transform(), sha256_transform(), sha512_transform(), shared_read(), speex_default_user_handler(), speex_inband_handler(), speex_std_stereo(), splitmix64(), svc_decode_frame(), svq1_static_init(), test_apv_entropy_decode_block(), uninit(), update_statusline(), update_vlc_state(), vc1_init_static(), vc1_split(), vgs_eval(), vgs_eval_state_free(), vgs_eval_state_init(), vgs_fn_p(), vgs_fn_pathlen(), vgs_fn_randomg(), webp_parse(), write_header(), write_quant_table(), x8_init_vlc(), x8_vlc_init(), xbm_parse(), and xhe_aac_encode_frame().

◆ coverage_flags

const SwsFlags coverage_flags[]
static
Initial value:

Definition at line 740 of file swscale.c.

Referenced by run_coverage().