51 size_t aligned_w =
width;
54 return aligned_w <= INT_MAX ? aligned_w :
width;
59 const int plane_copy[4])
72 ptrdiff_t linesize1[4];
73 for (
int i = 0;
i < 4;
i++)
81 for (
int i = 0;
i < 4;
i++) {
84 int src_idx = plane_copy[
i];
85 if (src_idx >= 0 &&
src) {
90 dst->data[
i] =
src->data[src_idx];
91 dst->linesize[
i] =
src->linesize[src_idx];
116 hwfc->sw_format = pass->
format;
117 hwfc->width =
buffer->width;
118 hwfc->height =
buffer->height;
150 ret = pass_alloc_output_hw(pass, avframe, dev_ref);
172 buffer->avframe = avframe;
193 int lines,
int align,
195 void *priv,
void (*free_cb)(
void *priv),
213 pass->
free = free_cb;
265 else if (drop->plane_copy[
i] >= 0)
274 for (
int i = 0;
i < 4;
i++) {
285 uint8_t *in_data[4], *out_data[4];
289 for (
int i = 0;
i < 4 && out_data[
i];
i++) {
293 if (in_data[
i] == out_data[
i]) {
296 memcpy(out_data[
i], in_data[
i], lines *
out->linesize[
i]);
299 for (
int j = 0; j < lines; j++) {
300 memcpy(out_data[
i], in_data[
i], linesize);
302 out_data[
i] +=
out->linesize[
i];
312 const int x0 =
c->src0Alpha - 1;
313 const int w4 = 4 *
out->width;
314 const int src_stride = in->
linesize[0];
315 const int dst_stride =
out->linesize[0];
316 const uint8_t *
src = in->
data[0] + y * src_stride;
317 uint8_t *
dst =
out->data[0] + y * dst_stride;
319 for (
int y = 0; y <
h; y++) {
321 for (
int x = x0; x < w4; x += 4)
333 c->xyz12Torgb48(
c,
out->data[0] + y *
out->linesize[0],
out->linesize[0],
342 c->rgb48Toxyz12(
c,
out->data[0] + y *
out->linesize[0],
out->linesize[0],
365 for (
int i = 0;
i < 4;
i++)
366 memset(
c->dither_error[
i], 0,
sizeof(
c->dither_error[0][0]) * (sws->
dst_w + 2));
402 c->convert_unscaled(
c, (
const uint8_t *
const *) in_data, in->
linesize, y,
h,
403 out->data,
out->linesize);
411 uint8_t *out_data[4];
415 sws->
src_h, out_data,
out->linesize, y,
h);
422 uint8_t *in_data[4], *out_data[4];
427 out->linesize[0],
out->width,
h);
432 if (
override == -513 ||
override == *chr_pos)
437 "Setting chroma position directly is deprecated, make sure "
438 "the frame is tagged with the correct chroma location.\n");
450 const int src_w = sws->
src_w, src_h = sws->
src_h;
451 const int dst_w = sws->
dst_w, dst_h = sws->
dst_h;
452 const int unscaled = src_w == dst_w && src_h == dst_h;
453 int align =
c->dst_slice_align;
457 if (
c->cascaded_context[0]) {
458 const int num_cascaded =
c->cascaded_context[2] ? 3 : 2;
459 for (
int i = 0;
i < num_cascaded;
i++) {
460 const int is_last =
i + 1 == num_cascaded;
464 c->cascaded_context[
i] =
NULL;
487 if (
c->srcXYZ && !(
c->dstXYZ && unscaled)) {
540 c2->srcColorspaceTable[
i] =
c->srcColorspaceTable[
i];
541 c2->dstColorspaceTable[
i] =
c->dstColorspaceTable[
i];
546 if (
c->dstXYZ && !(
c->srcXYZ && unscaled)) {
623 if (!
src->desc->log2_chroma_w)
625 if (!
src->desc->log2_chroma_h)
627 if (!
dst->desc->log2_chroma_w)
629 if (!
dst->desc->log2_chroma_h)
643 int in_full, out_full, brightness, contrast,
saturation;
644 const int *inv_table, *
table;
646 (
int **)&
table, &out_full,
673 if (
src->format != fmt) {
822 for (
int i = 0;
i < nb_planes;
i++)
844 "plane %d\n",
i, idx);
859 const int slice_y = jobnr * pass->
slice_h;
881 memset(graph, 0,
sizeof(*graph));
901 if (
ctx->threads == 1) {
908 graph->num_threads = 1;
909 }
else if (ret < 0) {
912 graph->num_threads = ret;
956 return c1->flags ==
c2->flags &&
957 c1->threads ==
c2->threads &&
958 c1->dither ==
c2->dither &&
959 c1->alpha_blend ==
c2->alpha_blend &&
960 c1->gamma_flag ==
c2->gamma_flag &&
961 c1->src_h_chr_pos ==
c2->src_h_chr_pos &&
962 c1->src_v_chr_pos ==
c2->src_v_chr_pos &&
963 c1->dst_h_chr_pos ==
c2->dst_h_chr_pos &&
964 c1->dst_v_chr_pos ==
c2->dst_v_chr_pos &&
965 c1->intent ==
c2->intent &&
966 c1->scaler ==
c2->scaler &&
967 c1->scaler_sub ==
c2->scaler_sub &&
968 c1->backends ==
c2->backends &&
969 !memcmp(
c1->scaler_params,
c2->scaler_params,
sizeof(
c1->scaler_params));
1011 for (
int i = 0;
i < 4;
i++) {
1020 for (
int i = 0;
i < 4;
i++)
1021 frame->linesize[
i] <<= 1;
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static AVFormatContext * ctx
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.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static const uint8_t *BS_FUNC align(BSCTX *bc)
Skip bits to a byte boundary.
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
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...
static IPT saturation(const CmsCtx *ctx, IPT ipt)
static void free_buffer(void *data, size_t length)
void ff_sws_graph_update_metadata(SwsGraph *graph, const SwsColor *color)
Update dynamic per-frame HDR metadata without requiring a full reinit.
static void run_rgb2xyz(const SwsFrame *out, const SwsFrame *in, int y, int h, const SwsPass *pass)
int ff_sws_graph_init(SwsGraph *graph, SwsContext *ctx, const SwsFormat *dst, const SwsFormat *src)
Initialize the filter graph for a given pair of formats.
int ff_sws_graph_add_pass(SwsGraph *graph, enum AVPixelFormat fmt, int width, int height, SwsPass *input, int lines, 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.
static bool prefer_ops_backend(SwsContext *ctx, const SwsFormat *src, const SwsFormat *dst)
static void legacy_chr_pos(SwsGraph *graph, int *chr_pos, int override, int *warned)
static int add_ops_convert_pass(SwsGraph *graph, const SwsFormat *src, const SwsFormat *dst, const SwsLut3D *lut3d, SwsPass *input, SwsPass **output)
static int sws_graph_worker(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads)
static void run_rgb0(const SwsFrame *out, const SwsFrame *in, int y, int h, const SwsPass *pass)
void ff_sws_pass_link_output(SwsPass *dst, const SwsPass *src)
Link the output buffers to a different pass, rather than allocating new image buffers.
void ff_sws_graph_rollback(SwsGraph *graph, int since_idx)
Remove all passes added since the given index.
static int add_legacy_3dlut_pass(SwsGraph *graph, const SwsFormat *src, SwsPass *input, SwsPass **output)
static int add_convert_pass(SwsGraph *graph, const SwsFormat *src, const SwsFormat *dst, const SwsLut3D *lut3d, SwsPass *input, SwsPass **output)
static void graph_uninit(SwsGraph *graph)
static int opts_equal(const SwsContext *c1, const SwsContext *c2)
static void run_legacy_unscaled(const SwsFrame *out, const SwsFrame *in, int y, int h, const SwsPass *pass)
static SwsContext * slice_ctx(const SwsPass *pass, int y)
static void free_buffer(AVRefStructOpaque opaque, void *obj)
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.
static void run_legacy_swscale(const SwsFrame *out, const SwsFrame *in, int y, int h, const SwsPass *pass)
static int frame_alloc_planes_ref(AVFrame *dst, const AVFrame *src, const int plane_copy[4])
static int pass_alloc_output(SwsPass *pass)
static void run_legacy_lut3d(const SwsFrame *out, const SwsFrame *in, int y, int h, const SwsPass *pass)
static int add_legacy_sws_pass(SwsGraph *graph, const SwsFormat *src, const SwsFormat *dst, const SwsLut3D *lut3d, SwsPass *input, SwsPass **output)
SwsGraph * ff_sws_graph_alloc(void)
Allocate an empty SwsGraph.
int ff_sws_pass_aligned_width(const SwsPass *pass, int width)
Align width to the optimal size for pass.
static void run_copy(const SwsFrame *out, const SwsFrame *in, int y, int h, const SwsPass *pass)
int ff_sws_graph_reinit(SwsGraph *graph, SwsContext *ctx, const SwsFormat *dst, const SwsFormat *src)
Wrapper around ff_sws_graph_init() that reuses the existing graph if the format is compatible.
static void frame_shift(const SwsFrame *f, const int y, uint8_t *data[4])
static int init_legacy_subpass(SwsGraph *graph, SwsContext *sws, SwsPass *input, SwsPass **output)
void ff_sws_graph_free(SwsGraph **pgraph)
Uninitialize any state associate with this filter graph and free it.
static void run_xyz2rgb(const SwsFrame *out, const SwsFrame *in, int y, int h, const SwsPass *pass)
static void free_legacy_swscale(void *priv)
static int generate_3dlut(SwsGraph *graph, SwsFormat *src, SwsFormat *dst)
static void get_field(SwsGraph *graph, const SwsFormat *fmt, const AVFrame *avframe, SwsFrame *frame)
static void pass_free(SwsPass *pass)
static int setup_legacy_swscale(const SwsFrame *out, const SwsFrame *in, const SwsPass *pass)
static int init_passes(SwsGraph *graph)
void(* SwsPassFunc)(const SwsFrame *out, const SwsFrame *in, int y, int h, const SwsPass *pass)
Output h lines of filtered data.
int(* SwsPassSetup)(const SwsFrame *out, const SwsFrame *in, const SwsPass *pass)
Function to run from the main thread before processing any lines.
static av_always_inline av_const int ff_fmt_vshift(enum AVPixelFormat fmt, int plane)
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
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 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 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 sws_getColorspaceDetails(SwsContext *c, int **inv_table, int *srcRange, int **table, int *dstRange, int *brightness, int *contrast, int *saturation)
av_warn_unused_result int sws_init_context(SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter)
Initialize the swscaler context sws_context.
SwsContext * sws_alloc_context(void)
Allocate an empty SwsContext and set its fields to default values.
void sws_free_context(SwsContext **ctx)
Free the context and everything associated with it, and write NULL to the provided pointer.
const int * sws_getCoefficients(int colorspace)
Return a pointer to yuv<->rgb coefficients for the given colorspace suitable for sws_setColorspaceDet...
int sws_setColorspaceDetails(SwsContext *c, const int inv_table[4], int srcRange, const int table[4], int dstRange, int brightness, int contrast, int saturation)
@ SWS_BACKEND_LEGACY
Legacy bespoke format-specific code.
@ SWS_UNSTABLE
Allow/prefer using experimental new code paths.
int av_opt_copy(void *dst, const void *src)
Copy options from src object into dest object.
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
const VDPAUPixFmtMap * map
static const int sizes[][2]
size_t av_cpu_max_align(void)
Get the maximum data alignment that may be required by FFmpeg.
SwsLut3D * ff_sws_lut3d_alloc(void)
Allocates a refstruct.
void ff_sws_lut3d_update(SwsLut3D *lut3d, const SwsColor *new_src)
Update the tone mapping state.
void ff_sws_lut3d_apply_rgba64(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 in RGBA64 format.
int ff_sws_lut3d_generate(SwsLut3D *lut3d, const SwsColorMap *map)
Recalculate the (static) 3DLUT state with new settings.
Utility Preprocessor macros.
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
void ff_sws_op_list_print(void *log, int lev, int lev_extra, const SwsOpList *ops)
Print out the contents of an operation list.
int ff_sws_compile_pass(SwsGraph *graph, const SwsOpBackend *backend, SwsOpList **pops, int flags, SwsPass *input, SwsPass **output)
Resolves an operation list to a graph pass.
@ SWS_OP_FLAG_SPLIT_MEMCPY
#define sws_isSupportedOutput(x)
#define sws_isSupportedInput(x)
int av_pix_fmt_count_planes(enum AVPixelFormat pix_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.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
@ AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_JPEG
Full range content.
#define AV_PIX_FMT_RGBA64
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
static const uint16_t table[]
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
void av_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
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 FF_ARRAY_ELEMS(a)
void avpriv_slicethread_free(AVSliceThread **pctx)
Destroy slice threading context.
int avpriv_slicethread_execute2(AVSliceThread *ctx, int nb_jobs, int execute_main)
Execute slice threading.
int avpriv_slicethread_create2(AVSliceThread **pctx, void *priv, int(*worker_func)(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads), int(*main_func)(void *priv), int nb_threads)
Create slice threading context.
A reference to a data buffer.
uint8_t * data
The data buffer.
This structure describes decoded (raw) audio or video data.
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
This struct describes a set or pool of "hardware" frames (i.e.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Main external API structure.
int src_h
Width and height of the source frame.
int dst_format
Destination pixel format.
int intent
Desired ICC intent for color space conversions.
int gamma_flag
Use gamma correct scaling.
SwsScaler scaler
Scaling filter.
int dst_h
Width and height of the destination frame.
SwsAlphaBlend alpha_blend
Alpha blending mode.
double scaler_params[SWS_NUM_SCALER_PARAMS]
int dst_h_chr_pos
Destination horizontal chroma position.
SwsScaler scaler_sub
Scaler used specifically for up/downsampling subsampled (chroma) planes.
int src_w
Deprecated frame property overrides, for the legacy API only.
int src_format
Source pixel format.
int src_v_chr_pos
Source vertical chroma position in luma grid / 256.
int dst_v_chr_pos
Destination vertical chroma position.
SwsDither dither
Dither mode.
int dst_range
Destination is full range.
unsigned flags
Bitmask of SWS_*.
int src_range
Source is full range.
int src_h_chr_pos
Source horizontal chroma position.
Represents a view into a single field of frame data.
enum AVPixelFormat format
Filter graph, which represents a 'baked' pixel format conversion.
SwsPass ** passes
Sorted sequence of filter passes to apply.
SwsFormat src
Currently active format and processing parameters.
SwsContext opts_copy
Cached copy of the public options that were used to construct this SwsGraph.
SwsLut3D * lut3d
3DLUT state used for gamut/tone mapping.
int plane_copy[4]
Map of planes which directly copied from the input.
AVSliceThread * slicethread
struct SwsGraph::@252226332054334034101247363262236031041275151254 exec
Temporary execution state inside ff_sws_graph_run(); used to pass data to worker threads.
Append a set of operations for applying a gamut/tone mapping 3D LUT to the pixels.
Helper struct for representing a list of operations.
Represents an output buffer for a filter pass.
int plane_copy[4]
Map of planes which are directly copied from the pass input.
Represents a single filter pass in the scaling graph.
SwsPass * input
Filter input.
enum AVPixelFormat format
SwsPassFunc run
Filter main execution function.
SwsPassBuffer * output
Filter output buffer.
void(* free)(void *priv)
Optional private state and associated free() function.
SwsPassSetup setup
Called once from the main thread before running the filter.
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)
void ff_update_palette(SwsInternal *c, const uint32_t *pal)
#define SWS_NUM_SCALER_PARAMS
Extra parameters for fine-tuning certain scalers.
int ff_sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter, SwsFilter *dstFilter)
static av_always_inline int isFloat(enum AVPixelFormat pix_fmt)
static av_always_inline int usePal(enum AVPixelFormat pix_fmt)
SwsBackend ff_sws_enabled_backends(const SwsContext *ctx)
static av_always_inline int isGray(enum AVPixelFormat pix_fmt)
static SwsInternal * sws_internal(const SwsContext *sws)
static av_always_inline int isALPHA(enum AVPixelFormat pix_fmt)
static void error(const char *err)
RefStruct is an API for creating reference-counted objects with minimal overhead.
AVBufferRef * ff_sws_vk_device_ref(SwsContext *sws)
Returns the Vulkan device reference associated with sws, or NULL if Vulkan has not been initialized f...