Go to the documentation of this file.
21 #include "config_components.h"
49 ptrdiff_t mlinesize, ptrdiff_t alinesize,
55 #define OFFSET(x) offsetof(PreMultiplyContext, x)
56 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
97 ptrdiff_t mlinesize, ptrdiff_t alinesize,
104 for (y = 0; y <
h; y++) {
105 for (x = 0; x <
w; x++) {
106 dst[x] = ((msrc[x] * (((asrc[x] >> 1) & 1) + asrc[x])) + 128) >> 8;
117 ptrdiff_t mlinesize, ptrdiff_t alinesize,
124 for (y = 0; y <
h; y++) {
125 for (x = 0; x <
w; x++) {
126 dst[x] = ((((msrc[x] - 128) * (((asrc[x] >> 1) & 1) + asrc[x]))) >> 8) + 128;
137 ptrdiff_t mlinesize, ptrdiff_t alinesize,
144 for (y = 0; y <
h; y++) {
145 for (x = 0; x <
w; x++) {
146 dst[x] = ((((msrc[x] -
offset) * (((asrc[x] >> 1) & 1) + asrc[x])) + 128) >> 8) +
offset;
157 ptrdiff_t mlinesize, ptrdiff_t alinesize,
162 const uint16_t *msrc = (
const uint16_t *)mmsrc;
163 const uint16_t *asrc = (
const uint16_t *)aasrc;
164 uint16_t *
dst = (uint16_t *)ddst;
167 for (y = 0; y <
h; y++) {
168 for (x = 0; x <
w; x++) {
169 dst[x] = ((msrc[x] * (((asrc[x] >> 1) & 1) + asrc[x])) +
half) >>
shift;
172 dst += dlinesize / 2;
173 msrc += mlinesize / 2;
174 asrc += alinesize / 2;
180 ptrdiff_t mlinesize, ptrdiff_t alinesize,
185 const uint16_t *msrc = (
const uint16_t *)mmsrc;
186 const uint16_t *asrc = (
const uint16_t *)aasrc;
187 uint16_t *
dst = (uint16_t *)ddst;
190 for (y = 0; y <
h; y++) {
191 for (x = 0; x <
w; x++) {
195 dst += dlinesize / 2;
196 msrc += mlinesize / 2;
197 asrc += alinesize / 2;
203 ptrdiff_t mlinesize, ptrdiff_t alinesize,
208 const uint16_t *msrc = (
const uint16_t *)mmsrc;
209 const uint16_t *asrc = (
const uint16_t *)aasrc;
210 uint16_t *
dst = (uint16_t *)ddst;
213 for (y = 0; y <
h; y++) {
214 for (x = 0; x <
w; x++) {
218 dst += dlinesize / 2;
219 msrc += mlinesize / 2;
220 asrc += alinesize / 2;
226 ptrdiff_t mlinesize, ptrdiff_t alinesize,
231 const float *msrc = (
const float *)mmsrc;
232 const float *asrc = (
const float *)aasrc;
233 float *
dst = (
float *)ddst;
236 for (y = 0; y <
h; y++) {
237 for (x = 0; x <
w; x++) {
238 dst[x] = msrc[x] * asrc[x];
241 dst += dlinesize / 4;
242 msrc += mlinesize / 4;
243 asrc += alinesize / 4;
249 ptrdiff_t mlinesize, ptrdiff_t alinesize,
254 const float *msrc = (
const float *)mmsrc;
255 const float *asrc = (
const float *)aasrc;
256 float *
dst = (
float *)ddst;
259 float offsetf =
offset / 65535.0f;
261 for (y = 0; y <
h; y++) {
262 for (x = 0; x <
w; x++) {
263 dst[x] = ((msrc[x] - offsetf) * asrc[x]) + offsetf;
266 dst += dlinesize / 4;
267 msrc += mlinesize / 4;
268 asrc += alinesize / 4;
274 ptrdiff_t mlinesize, ptrdiff_t alinesize,
281 for (y = 0; y <
h; y++) {
282 for (x = 0; x <
w; x++) {
283 if (asrc[x] > 0 && asrc[x] < 255)
284 dst[x] =
FFMIN(msrc[x] * 255 / asrc[x], 255);
297 ptrdiff_t mlinesize, ptrdiff_t alinesize,
304 for (y = 0; y <
h; y++) {
305 for (x = 0; x <
w; x++) {
306 if (asrc[x] > 0 && asrc[x] < 255)
307 dst[x] =
FFMIN((msrc[x] - 128) * 255 / asrc[x] + 128, 255);
320 ptrdiff_t mlinesize, ptrdiff_t alinesize,
327 for (y = 0; y <
h; y++) {
328 for (x = 0; x <
w; x++) {
329 if (asrc[x] > 0 && asrc[x] < 255)
343 ptrdiff_t mlinesize, ptrdiff_t alinesize,
348 const uint16_t *msrc = (
const uint16_t *)mmsrc;
349 const uint16_t *asrc = (
const uint16_t *)aasrc;
350 uint16_t *
dst = (uint16_t *)ddst;
353 for (y = 0; y <
h; y++) {
354 for (x = 0; x <
w; x++) {
355 if (asrc[x] > 0 && asrc[x] <
max)
361 dst += dlinesize / 2;
362 msrc += mlinesize / 2;
363 asrc += alinesize / 2;
369 ptrdiff_t mlinesize, ptrdiff_t alinesize,
374 const uint16_t *msrc = (
const uint16_t *)mmsrc;
375 const uint16_t *asrc = (
const uint16_t *)aasrc;
376 uint16_t *
dst = (uint16_t *)ddst;
379 for (y = 0; y <
h; y++) {
380 for (x = 0; x <
w; x++) {
381 if (asrc[x] > 0 && asrc[x] <
max)
387 dst += dlinesize / 2;
388 msrc += mlinesize / 2;
389 asrc += alinesize / 2;
395 ptrdiff_t mlinesize, ptrdiff_t alinesize,
400 const uint16_t *msrc = (
const uint16_t *)mmsrc;
401 const uint16_t *asrc = (
const uint16_t *)aasrc;
402 uint16_t *
dst = (uint16_t *)ddst;
405 for (y = 0; y <
h; y++) {
406 for (x = 0; x <
w; x++) {
407 if (asrc[x] > 0 && asrc[x] <
max)
413 dst += dlinesize / 2;
414 msrc += mlinesize / 2;
415 asrc += alinesize / 2;
421 ptrdiff_t mlinesize, ptrdiff_t alinesize,
426 const float *msrc = (
const float *)mmsrc;
427 const float *asrc = (
const float *)aasrc;
429 float *
dst = (
float *)ddst;
432 for (y = 0; y <
h; y++) {
433 for (x = 0; x <
w; x++) {
435 dst[x] = msrc[x] / asrc[x];
440 dst += dlinesize / 4;
441 msrc += mlinesize / 4;
442 asrc += alinesize / 4;
448 ptrdiff_t mlinesize, ptrdiff_t alinesize,
453 const float *msrc = (
const float *)mmsrc;
454 const float *asrc = (
const float *)aasrc;
456 float *
dst = (
float *)ddst;
459 float offsetf =
offset / 65535.0f;
461 for (y = 0; y <
h; y++) {
462 for (x = 0; x <
w; x++) {
464 dst[x] = (msrc[x] - offsetf) / asrc[x] + offsetf;
469 dst += dlinesize / 4;
470 msrc += mlinesize / 4;
471 asrc += alinesize / 4;
484 for (p = 0; p <
s->nb_planes; p++) {
485 const int slice_start = (
s->height[p] * jobnr) / nb_jobs;
486 const int slice_end = (
s->height[p] * (jobnr+1)) / nb_jobs;
488 if (!((1 << p) &
s->planes) || p == 3) {
501 base->linesize[p],
s->inplace ?
alpha->linesize[3] :
alpha->linesize[0],
504 s->half,
s->inverse ?
s->max :
s->depth,
s->offset);
516 if (
ctx->is_disabled) {
533 switch (outlink->
format) {
585 switch (outlink->
format) {
681 vsub =
desc->log2_chroma_h;
683 s->height[0] =
s->height[3] =
inlink->h;
685 s->width[0] =
s->width[3] =
inlink->w;
688 s->max = (1 <<
s->depth) - 1;
689 s->half = (1 <<
s->depth) / 2;
690 s->offset = 16 << (
s->depth - 8);
712 "(size %dx%d) do not match the corresponding "
713 "second input link %s parameters (%dx%d) ",
720 outlink->
w =
base->w;
721 outlink->
h =
base->h;
787 if (!strcmp(
ctx->filter->name,
"unpremultiply"))
825 #if CONFIG_PREMULTIPLY_FILTER
828 .
name =
"premultiply",
829 .description =
NULL_IF_CONFIG_SMALL(
"PreMultiply first stream with first plane of second stream."),
837 .priv_class = &premultiply_class,
845 #if CONFIG_UNPREMULTIPLY_FILTER
848 .
name =
"unpremultiply",
849 .description =
NULL_IF_CONFIG_SMALL(
"UnPreMultiply first stream with first plane of second stream."),
850 .priv_class = &premultiply_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
#define AV_PIX_FMT_GBRAP16
AVRational time_base
Time base for the incoming frames.
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
AVPixelFormat
Pixel format.
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
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
int ff_framesync_get_frame(FFFrameSync *fs, unsigned in, AVFrame **rframe, unsigned get)
Get the current frame in an input.
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
#define AV_VIDEO_MAX_PLANES
Maximum number of planes in any pixel format.
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
static void unpremultiply16yuv(const uint8_t *mmsrc, const uint8_t *aasrc, uint8_t *ddst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int max, int offset)
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.
@ AVCOL_RANGE_JPEG
Full range content.
static void unpremultiply8offset(const uint8_t *msrc, const uint8_t *asrc, uint8_t *dst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int max, int offset)
static uint8_t half(int a, int b)
int linesize[AV_VIDEO_MAX_PLANES]
static void unpremultiplyf32(const uint8_t *mmsrc, const uint8_t *aasrc, uint8_t *ddst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int max, int offset)
const char * name
Filter name.
@ EXT_INFINITY
Extend the frame to infinity.
A link between two filters.
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
Link properties exposed to filter code, but not external callers.
static const struct @466 planes[]
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
static void premultiplyf32offset(const uint8_t *mmsrc, const uint8_t *aasrc, uint8_t *ddst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int shift, int offset)
static const AVOption options[]
@ EXT_STOP
Completely stop all streams with this one.
#define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter)
Forward the status on an output link to all input links.
#define AV_PIX_FMT_GBRP14
int ff_append_inpad(AVFilterContext *f, AVFilterPad *p)
Append a new input/output pad to the filter's list of such pads.
const AVFilter ff_vf_unpremultiply
static int slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output)
Handle slice ends.
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
int height[AV_VIDEO_MAX_PLANES]
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_YUVA444P16
static void unpremultiply8yuv(const uint8_t *msrc, const uint8_t *asrc, uint8_t *dst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int max, int offset)
#define AV_PIX_FMT_GRAY16
unsigned sync
Synchronization level: frames on input at the highest sync level will generate output frame events.
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
A filter pad used for either input or output.
#define AV_PIX_FMT_YUV444P10
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int premultiply_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AV_PIX_FMT_GBRAP10
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
static int process_frame(FFFrameSync *fs)
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
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.
#define AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_YUV444P16
#define AV_CEIL_RSHIFT(a, b)
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
#define AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_GRAY14
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static void unpremultiply8(const uint8_t *msrc, const uint8_t *asrc, uint8_t *dst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int max, int offset)
#define FILTER_OUTPUTS(array)
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
#define AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GBRP16
Describe the class of an AVClass context structure.
static void premultiply16offset(const uint8_t *mmsrc, const uint8_t *aasrc, uint8_t *ddst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int shift, int offset)
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
#define fs(width, name, subs,...)
static void premultiply8offset(const uint8_t *msrc, const uint8_t *asrc, uint8_t *dst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int shift, int offset)
AVFILTER_DEFINE_CLASS_EXT(premultiply, "(un)premultiply", options)
static av_cold int init(AVFilterContext *ctx)
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 inputs
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
const AVFilter ff_vf_premultiply
static FilterLink * ff_filter_link(AVFilterLink *link)
static int activate(AVFilterContext *ctx)
int(* config_props)(AVFilterLink *link)
Link configuration callback.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static void premultiplyf32(const uint8_t *mmsrc, const uint8_t *aasrc, uint8_t *ddst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int shift, int offset)
static int shift(int a, int b)
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static void unpremultiply16offset(const uint8_t *mmsrc, const uint8_t *aasrc, uint8_t *ddst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int max, int offset)
static void unpremultiplyf32offset(const uint8_t *mmsrc, const uint8_t *aasrc, uint8_t *ddst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int max, int offset)
#define AV_PIX_FMT_GBRPF32
int format
agreed upon media format
#define AV_PIX_FMT_YUV444P12
static int config_output(AVFilterLink *outlink)
AVFilterContext * src
source filter
static void premultiply8yuv(const uint8_t *msrc, const uint8_t *asrc, uint8_t *dst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int shift, int offset)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
#define AV_PIX_FMT_YUVA444P10
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 offset
static void premultiply8(const uint8_t *msrc, const uint8_t *asrc, uint8_t *dst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int shift, int offset)
static av_cold void uninit(AVFilterContext *ctx)
int w
agreed upon image width
void(* premultiply[AV_VIDEO_MAX_PLANES])(const uint8_t *msrc, const uint8_t *asrc, uint8_t *dst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int shift, int offset)
#define AV_PIX_FMT_GBRP12
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Used for passing data between threads.
#define FILTER_QUERY_FUNC2(func)
static void unpremultiply16(const uint8_t *mmsrc, const uint8_t *aasrc, uint8_t *ddst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int max, int offset)
const char * name
Pad name.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
#define AV_PIX_FMT_YUV444P9
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)
enum AVMediaType type
AVFilterPad type.
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
#define AV_PIX_FMT_YUVA444P9
int ff_framesync_init(FFFrameSync *fs, AVFilterContext *parent, unsigned nb_in)
Initialize a frame sync structure.
enum FFFrameSyncExtMode before
Extrapolation mode for timestamps before the first frame.
int h
agreed upon image height
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
static void premultiply16yuv(const uint8_t *mmsrc, const uint8_t *aasrc, uint8_t *ddst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int shift, int offset)
@ AV_OPT_TYPE_INT
Underlying C type is int.
#define AV_PIX_FMT_GBRAPF32
static void premultiply16(const uint8_t *mmsrc, const uint8_t *aasrc, uint8_t *ddst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int shift, int offset)
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
static const AVFilterPad premultiply_outputs[]
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static int config_input(AVFilterLink *inlink)
static const int16_t alpha[]
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
enum FFFrameSyncExtMode after
Extrapolation mode for timestamps after the last frame.
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function. If this function returns true
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable.
#define AV_PIX_FMT_YUV444P14
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
int width[AV_VIDEO_MAX_PLANES]
#define AV_PIX_FMT_GRAY12
static enum AVPixelFormat alpha_pix_fmts[]
static int filter_frame(AVFilterContext *ctx, AVFrame **out, AVFrame *base, AVFrame *alpha)