Go to the documentation of this file.
46 size_t aligned_w =
width;
49 return aligned_w <= INT_MAX ? aligned_w :
width;
66 ptrdiff_t linesize1[4];
67 for (
int i = 0;
i < 4;
i++)
75 for (
int i = 0;
i < 4;
i++) {
107 buffer->avframe = avframe;
129 void *priv,
void (*free_cb)(
void *priv),
144 pass->
free = free_cb;
183 for (
int i = 0;
i < 4;
i++) {
194 uint8_t *in_data[4], *out_data[4];
198 for (
int i = 0;
i < 4 && out_data[
i];
i++) {
202 if (in_data[
i] == out_data[
i]) {
205 memcpy(out_data[
i], in_data[
i], lines *
out->linesize[
i]);
208 for (
int j = 0; j < lines; j++) {
209 memcpy(out_data[
i], in_data[
i], linesize);
211 out_data[
i] +=
out->linesize[
i];
221 const int x0 =
c->src0Alpha - 1;
222 const int w4 = 4 * pass->
width;
223 const int src_stride = in->
linesize[0];
224 const int dst_stride =
out->linesize[0];
225 const uint8_t *
src = in->
data[0] + y * src_stride;
226 uint8_t *
dst =
out->data[0] + y * dst_stride;
228 for (
int y = 0; y <
h; y++) {
230 for (
int x = x0; x < w4; x += 4)
242 c->xyz12Torgb48(
c,
out->data[0] + y *
out->linesize[0],
out->linesize[0],
251 c->rgb48Toxyz12(
c,
out->data[0] + y *
out->linesize[0],
out->linesize[0],
274 for (
int i = 0;
i < 4;
i++)
275 memset(
c->dither_error[
i], 0,
sizeof(
c->dither_error[0][0]) * (sws->
dst_w + 2));
311 c->convert_unscaled(
c, (
const uint8_t *
const *) in_data, in->
linesize, y,
h,
312 out->data,
out->linesize);
320 uint8_t *out_data[4];
324 sws->
src_h, out_data,
out->linesize, y,
h);
345 x_pos *= (1 << sub_x) - 1;
346 y_pos *= (1 << sub_y) - 1;
358 y_pos += (256 << sub_y) - 256;
366 *h_chr_pos = sub_x ? x_pos : -513;
367 *v_chr_pos = sub_y ? y_pos : -513;
372 if (
override == -513 ||
override == *chr_pos)
377 "Setting chroma position directly is deprecated, make sure "
378 "the frame is tagged with the correct chroma location.\n");
390 const int src_w = sws->
src_w, src_h = sws->
src_h;
391 const int dst_w = sws->
dst_w, dst_h = sws->
dst_h;
392 const int unscaled = src_w == dst_w && src_h == dst_h;
393 int align =
c->dst_slice_align;
397 if (
c->cascaded_context[0]) {
398 const int num_cascaded =
c->cascaded_context[2] ? 3 : 2;
399 for (
int i = 0;
i < num_cascaded;
i++) {
400 const int is_last =
i + 1 == num_cascaded;
404 c->cascaded_context[
i] =
NULL;
427 if (
c->srcXYZ && !(
c->dstXYZ && unscaled)) {
479 c2->srcColorspaceTable[
i] =
c->srcColorspaceTable[
i];
480 c2->dstColorspaceTable[
i] =
c->dstColorspaceTable[
i];
485 if (
c->dstXYZ && !(
c->srcXYZ && unscaled)) {
548 int in_full, out_full, brightness, contrast,
saturation;
549 const int *inv_table, *
table;
551 (
int **)&
table, &out_full,
603 if (src_size == dst_size)
608 .src_size = src_size,
609 .dst_size = dst_size,
620 if (
mean == src_size ||
mean == dst_size)
626 }
else if (
ret < 0) {
633 .filter.kernel = kernel,
708 #define add_convert_pass add_legacy_sws_pass
735 uint8_t *in_data[4], *out_data[4];
782 if (fmt_in !=
src.format) {
842 const int slice_y = jobnr * pass->
slice_h;
862 if (
ctx->threads == 1) {
869 graph->num_threads = 1;
870 }
else if (
ret < 0) {
873 graph->num_threads =
ret;
922 return c1->flags ==
c2->flags &&
923 c1->threads ==
c2->threads &&
924 c1->dither ==
c2->dither &&
925 c1->alpha_blend ==
c2->alpha_blend &&
926 c1->gamma_flag ==
c2->gamma_flag &&
927 c1->src_h_chr_pos ==
c2->src_h_chr_pos &&
928 c1->src_v_chr_pos ==
c2->src_v_chr_pos &&
929 c1->dst_h_chr_pos ==
c2->dst_h_chr_pos &&
930 c1->dst_v_chr_pos ==
c2->dst_v_chr_pos &&
931 c1->intent ==
c2->intent &&
932 c1->scaler ==
c2->scaler &&
933 c1->scaler_sub ==
c2->scaler_sub &&
934 !memcmp(
c1->scaler_params,
c2->scaler_params,
sizeof(
c1->scaler_params));
974 for (
int i = 0;
i < 4;
i++) {
983 for (
int i = 0;
i < 4;
i++)
static void error(const char *err)
int sws_setColorspaceDetails(SwsContext *c, const int inv_table[4], int srcRange, const int table[4], int dstRange, int brightness, int contrast, int saturation)
void ff_sws_op_list_free(SwsOpList **p_ops)
#define AV_LOG_WARNING
Something somehow does not look correct.
AVPixelFormat
Pixel format.
static int add_legacy_sws_pass(SwsGraph *graph, const SwsFormat *src, const SwsFormat *dst, SwsPass *input, SwsPass **output)
AVSliceThread * slicethread
Represents a single filter pass in the scaling graph.
SwsOpList * ff_sws_op_list_alloc(void)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
SwsPass ** passes
Sorted sequence of filter passes to apply.
static int adapt_colors(SwsGraph *graph, SwsFormat src, SwsFormat dst, SwsPass *input, SwsPass **output)
static int init_passes(SwsGraph *graph)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
int src_w
Deprecated frame property overrides, for the legacy API only.
uint8_t * data
The data buffer.
@ SWS_SCALE_BILINEAR
bilinear filtering
int ff_sws_graph_reinit(SwsContext *ctx, const SwsFormat *dst, const SwsFormat *src, int field, SwsGraph **out_graph)
Wrapper around ff_sws_graph_create() that reuses the existing graph if the format is compatible.
RefStruct is an API for creating reference-counted objects with minimal overhead.
enum AVPixelFormat format
static IPT saturation(const CmsCtx *ctx, IPT ipt)
static void run_rgb0(const SwsFrame *out, const SwsFrame *in, int y, int h, const SwsPass *pass)
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
int ff_sws_op_list_append(SwsOpList *ops, SwsOp *op)
These will take over ownership of op and set it to {0}, even on failure.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
SwsFormat src
Currently active format and processing parameters.
void avpriv_slicethread_execute(AVSliceThread *ctx, int nb_jobs, int execute_main)
Execute slice threading.
This structure describes decoded (raw) audio or video data.
static void frame_shift(const SwsFrame *f, const int y, uint8_t *data[4])
@ AVCOL_RANGE_JPEG
Full range content.
static av_always_inline int isGray(enum AVPixelFormat pix_fmt)
Represents a computed filter kernel.
@ SWS_BILINEAR
bilinear filtering
static void run_copy(const SwsFrame *out, const SwsFrame *in, int y, int h, const SwsPass *pass)
static void pass_free(SwsPass *pass)
SwsPassSetup setup
Called once from the main thread before running the filter.
static const uint16_t table[]
unsigned flags
Bitmask of SWS_*.
#define AV_LOG_VERBOSE
Detailed information.
void(* filter)(uint8_t *src, int stride, int qscale)
enum AVPixelFormat ff_sws_lut3d_pick_pixfmt(SwsFormat fmt, int output)
Pick the best compatible pixfmt for a given SwsFormat.
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
void(* free)(void *priv)
Optional private state and associated free() function.
@ SWS_BICUBLIN
bicubic luma, bilinear chroma
SwsPass * input
Filter input.
int ff_sws_filter_generate(void *log, const SwsFilterParams *params, SwsFilterWeights **out)
Generate a filter kernel for the given parameters.
int ff_sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter, SwsFilter *dstFilter)
SwsPixelType
Copyright (C) 2025 Niklas Haas.
void ff_sws_op_list_print(void *log, int lev, int lev_extra, const SwsOpList *ops)
Print out the contents of an operation list.
static int init_legacy_subpass(SwsGraph *graph, SwsContext *sws, SwsPass *input, SwsPass **output)
static int setup_lut3d(const SwsFrame *out, const SwsFrame *in, const SwsPass *pass)
int avpriv_slicethread_create(AVSliceThread **pctx, void *priv, void(*worker_func)(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads), void(*main_func)(void *priv), int nb_threads)
Create slice threading context.
int src_v_chr_pos
Source vertical chroma position in luma grid / 256.
static SwsContext * slice_ctx(const SwsPass *pass, int y)
av_warn_unused_result int sws_init_context(SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter)
Initialize the swscaler context sws_context.
SwsContext opts_copy
Cached copy of the public options that were used to construct this SwsGraph.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
int av_image_check_size2(unsigned int w, unsigned int h, int64_t max_pixels, enum AVPixelFormat pix_fmt, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of a plane of an image with...
int ff_sws_graph_create(SwsContext *ctx, const SwsFormat *dst, const SwsFormat *src, int field, SwsGraph **out_graph)
Allocate and initialize the filter graph.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Represents a view into a single field of frame data.
@ SWS_SCALE_BICUBIC
2-tap cubic BC-spline
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define FF_ARRAY_ELEMS(a)
static void legacy_chr_pos(SwsGraph *graph, int *chr_pos, int override, int *warned)
enum AVPixelFormat format
SwsDither dither
Dither mode.
static void run_xyz2rgb(const SwsFrame *out, const SwsFrame *in, int y, int h, const SwsPass *pass)
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
Fill plane linesizes for an image with pixel format pix_fmt and width width.
int av_chroma_location_enum_to_pos(int *xpos, int *ypos, enum AVChromaLocation pos)
Converts AVChromaLocation to swscale x/y chroma position.
void ff_update_palette(SwsInternal *c, const uint32_t *pal)
@ SWS_SCALE_LANCZOS
3-tap sinc/sinc
int flags
Flags modifying the (de)muxer behaviour.
SwsLut3D * ff_sws_lut3d_alloc(void)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int intent
Desired ICC intent for color space conversions.
static void * av_refstruct_alloc_ext(size_t size, unsigned flags, void *opaque, void(*free_cb)(AVRefStructOpaque opaque, void *obj))
A wrapper around av_refstruct_alloc_ext_c() for the common case of a non-const qualified opaque.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
static AVFormatContext * ctx
void ff_sws_lut3d_update(SwsLut3D *lut3d, const SwsColor *new_src)
Update the tone mapping state.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this field
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
SwsPassFunc run
Filter main execution function.
static void free_buffer(AVRefStructOpaque opaque, void *obj)
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
void ff_sws_lut3d_free(SwsLut3D **plut3d)
static const int sizes[][2]
static void run_legacy_swscale(const SwsFrame *out, const SwsFrame *in, int y, int h, const SwsPass *pass)
@ SWS_BICUBIC
2-tap cubic B-spline
int gamma_flag
Use gamma correct scaling.
int av_image_fill_plane_sizes(size_t sizes[4], enum AVPixelFormat pix_fmt, int height, const ptrdiff_t linesizes[4])
Fill plane sizes for an image with pixel format pix_fmt and height height.
int ff_sws_lut3d_generate(SwsLut3D *lut3d, enum AVPixelFormat fmt_in, enum AVPixelFormat fmt_out, const SwsColorMap *map)
Recalculate the (static) 3DLUT state with new settings.
int src_range
Source is full range.
size_t av_cpu_max_align(void)
Get the maximum data alignment that may be required by FFmpeg.
@ AVCOL_RANGE_UNSPECIFIED
int dst_h_chr_pos
Destination horizontal chroma position.
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
int ff_sws_pass_aligned_width(const SwsPass *pass, int width)
Align width to the optimal size for pass.
int av_opt_copy(void *dst, const void *src)
Copy options from src object into dest object.
@ SWS_SCALE_SINC
unwindowed sinc
void ff_sws_graph_free(SwsGraph **pgraph)
Uninitialize any state associate with this filter graph and free it.
static void free_lut3d(void *priv)
static int frame_alloc_planes(AVFrame *dst)
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
static av_always_inline int usePal(enum AVPixelFormat pix_fmt)
#define i(width, name, range_min, range_max)
void ff_sws_lut3d_apply(const SwsLut3D *lut3d, const uint8_t *in, int in_stride, uint8_t *out, int out_stride, int w, int h)
Applies a color transformation to a plane.
static void run_legacy_unscaled(const SwsFrame *out, const SwsFrame *in, int y, int h, const SwsPass *pass)
@ SWS_POINT
nearest neighbor
SwsAlphaBlend alpha_blend
Alpha blending mode.
@ SWS_SPLINE
unwindowed natural cubic spline
int src_h
Width and height of the source frame.
@ AVCHROMA_LOC_UNSPECIFIED
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
int sws_getColorspaceDetails(SwsContext *c, int **inv_table, int *srcRange, int **table, int *dstRange, int *brightness, int *contrast, int *saturation)
static const uint8_t *BS_FUNC() align(BSCTX *bc)
Skip bits to a byte boundary.
SwsPassBuffer * output
Filter output buffer.
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
int dst_format
Destination pixel format.
struct SwsGraph::@563 exec
Temporary execution state inside ff_sws_graph_run(); used to pass data to worker threads.
static void run_lut3d(const SwsFrame *out, const SwsFrame *in, int y, int h, const SwsPass *pass)
static int add_filter(AudioNEqualizerContext *s, AVFilterLink *inlink)
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
AVChromaLocation
Location of chroma samples.
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
@ SWS_SCALE_POINT
nearest neighbor (point sampling)
static void free_legacy_swscale(void *priv)
static av_always_inline av_const int ff_fmt_vshift(enum AVPixelFormat fmt, int plane)
static int opts_equal(const SwsContext *c1, const SwsContext *c2)
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
static int setup_legacy_swscale(const SwsFrame *out, const SwsFrame *in, const SwsPass *pass)
SwsScaler scaler
Scaling filter.
double scaler_params[SWS_NUM_SCALER_PARAMS]
SwsScaler scaler_sub
Scaler used specifically for up/downsampling subsampled (chroma) planes.
int dst_h
Width and height of the destination frame.
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
void * av_calloc(size_t nmemb, size_t size)
static void get_chroma_pos(SwsGraph *graph, int *h_chr_pos, int *v_chr_pos, const SwsFormat *fmt)
@ SWS_SCALE_GAUSSIAN
2-tap gaussian approximation
int ff_sws_graph_add_pass(SwsGraph *graph, enum AVPixelFormat fmt, int width, int height, SwsPass *input, int align, SwsPassFunc run, SwsPassSetup setup, void *priv, void(*free_cb)(void *priv), SwsPass **out_pass)
Allocate and add a new pass to the filter graph.
void(* SwsPassFunc)(const SwsFrame *out, const SwsFrame *in, int y, int h, const SwsPass *pass)
Output h lines of filtered data.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
@ AVCHROMA_LOC_CENTER
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
#define SWS_NUM_SCALER_PARAMS
Extra parameters for fine-tuning certain scalers.
@ SWS_SCALE_SPLINE
unwindowned natural cubic spline
static void get_field(SwsGraph *graph, const AVFrame *avframe, SwsFrame *frame)
@ SWS_GAUSS
gaussian approximation
static float mean(const float *input, int size)
bool ff_sws_color_map_noop(const SwsColorMap *map)
Returns true if the given color map is a semantic no-op - that is, the overall RGB end to end transfo...
int(* SwsPassSetup)(const SwsFrame *out, const SwsFrame *in, const SwsPass *pass)
Function to run from the main thread before processing any lines.
int ff_swscale(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[], int dstSliceY, int dstSliceH)
A reference to a data buffer.
const int * sws_getCoefficients(int colorspace)
Return a pointer to yuv<->rgb coefficients for the given colorspace suitable for sws_setColorspaceDet...
Filter graph, which represents a 'baked' pixel format conversion.
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...
const VDPAUPixFmtMap * map
static void run_rgb2xyz(const SwsFrame *out, const SwsFrame *in, int y, int h, const SwsPass *pass)
int dst_range
Destination is full range.
static int pass_alloc_output(SwsPass *pass)
int ff_sws_graph_run(SwsGraph *graph, const AVFrame *dst, const AVFrame *src)
Dispatch the filter graph on a single field of the given frames.
void sws_free_context(SwsContext **ctx)
Free the context and everything associated with it, and write NULL to the provided pointer.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
void avpriv_slicethread_free(AVSliceThread **pctx)
Destroy slice threading context.
int src_h_chr_pos
Source horizontal chroma position.
@ SWS_SCALE_AREA
area averaging
static SwsInternal * sws_internal(const SwsContext *sws)
Represents an output buffer for a filter pass.
@ SWS_LANCZOS
3-tap sinc/sinc
Helper struct for representing a list of operations.
int dst_v_chr_pos
Destination vertical chroma position.
@ SWS_SINC
unwindowed sinc
Main external API structure.
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
SwsScaler scaler
The filter kernel and parameters to use.
static void sws_graph_worker(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads)
void ff_sws_graph_update_metadata(SwsGraph *graph, const SwsColor *color)
Update dynamic per-frame HDR metadata without requiring a full reinit.
@ SWS_UNSTABLE
Allow using experimental new code paths.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
int ff_sws_compile_pass(SwsGraph *graph, SwsOpList **ops, int flags, SwsPass *input, SwsPass **output)
Resolves an operation list to a graph pass.
double scaler_params[SWS_NUM_SCALER_PARAMS]
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.
static av_always_inline int isALPHA(enum AVPixelFormat pix_fmt)
void ff_sws_graph_rollback(SwsGraph *graph, int since_idx)
Remove all passes added since the given index.