21#include "config_components.h"
50 ptrdiff_t mlinesize, ptrdiff_t alinesize,
56#define OFFSET(x) offsetof(PreMultiplyContext, x)
57#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
122 ptrdiff_t mlinesize, ptrdiff_t alinesize,
129 for (y = 0; y <
h; y++) {
130 for (x = 0; x <
w; x++) {
131 dst[x] = (msrc[x] * asrc[x] + 128) >> 8;
142 ptrdiff_t mlinesize, ptrdiff_t alinesize,
149 for (y = 0; y <
h; y++) {
150 for (x = 0; x <
w; x++) {
151 dst[x] = (((msrc[x] - 128) * asrc[x]) >> 8) + 128;
162 ptrdiff_t mlinesize, ptrdiff_t alinesize,
169 for (y = 0; y <
h; y++) {
170 for (x = 0; x <
w; x++) {
182 ptrdiff_t mlinesize, ptrdiff_t alinesize,
187 const uint16_t *msrc = (
const uint16_t *)mmsrc;
188 const uint16_t *asrc = (
const uint16_t *)aasrc;
189 uint16_t *
dst = (uint16_t *)ddst;
192 for (y = 0; y <
h; y++) {
193 for (x = 0; x <
w; x++) {
197 dst += dlinesize / 2;
198 msrc += mlinesize / 2;
199 asrc += alinesize / 2;
205 ptrdiff_t mlinesize, ptrdiff_t alinesize,
210 const uint16_t *msrc = (
const uint16_t *)mmsrc;
211 const uint16_t *asrc = (
const uint16_t *)aasrc;
212 uint16_t *
dst = (uint16_t *)ddst;
215 for (y = 0; y <
h; y++) {
216 for (x = 0; x <
w; x++) {
220 dst += dlinesize / 2;
221 msrc += mlinesize / 2;
222 asrc += alinesize / 2;
228 ptrdiff_t mlinesize, ptrdiff_t alinesize,
233 const uint16_t *msrc = (
const uint16_t *)mmsrc;
234 const uint16_t *asrc = (
const uint16_t *)aasrc;
235 uint16_t *
dst = (uint16_t *)ddst;
238 for (y = 0; y <
h; y++) {
239 for (x = 0; x <
w; x++) {
243 dst += dlinesize / 2;
244 msrc += mlinesize / 2;
245 asrc += alinesize / 2;
251 ptrdiff_t mlinesize, ptrdiff_t alinesize,
256 const float *msrc = (
const float *)mmsrc;
257 const float *asrc = (
const float *)aasrc;
258 float *
dst = (
float *)ddst;
261 for (y = 0; y <
h; y++) {
262 for (x = 0; x <
w; x++) {
263 dst[x] = msrc[x] * asrc[x];
266 dst += dlinesize / 4;
267 msrc += mlinesize / 4;
268 asrc += alinesize / 4;
274 ptrdiff_t mlinesize, ptrdiff_t alinesize,
279 const float *msrc = (
const float *)mmsrc;
280 const float *asrc = (
const float *)aasrc;
281 float *
dst = (
float *)ddst;
284 float offsetf =
offset / 65535.0f;
286 for (y = 0; y <
h; y++) {
287 for (x = 0; x <
w; x++) {
288 dst[x] = ((msrc[x] - offsetf) * asrc[x]) + offsetf;
291 dst += dlinesize / 4;
292 msrc += mlinesize / 4;
293 asrc += alinesize / 4;
299 ptrdiff_t mlinesize, ptrdiff_t alinesize,
306 for (y = 0; y <
h; y++) {
307 for (x = 0; x <
w; x++) {
308 if (asrc[x] > 0 && asrc[x] < 255)
309 dst[x] =
FFMIN(msrc[x] * 255 / asrc[x], 255);
322 ptrdiff_t mlinesize, ptrdiff_t alinesize,
329 for (y = 0; y <
h; y++) {
330 for (x = 0; x <
w; x++) {
331 if (asrc[x] > 0 && asrc[x] < 255)
332 dst[x] =
FFMIN((msrc[x] - 128) * 255 / asrc[x] + 128, 255);
345 ptrdiff_t mlinesize, ptrdiff_t alinesize,
352 for (y = 0; y <
h; y++) {
353 for (x = 0; x <
w; x++) {
354 if (asrc[x] > 0 && asrc[x] < 255)
368 ptrdiff_t mlinesize, ptrdiff_t alinesize,
373 const uint16_t *msrc = (
const uint16_t *)mmsrc;
374 const uint16_t *asrc = (
const uint16_t *)aasrc;
375 uint16_t *
dst = (uint16_t *)ddst;
378 for (y = 0; y <
h; y++) {
379 for (x = 0; x <
w; x++) {
380 if (asrc[x] > 0 && asrc[x] <
max)
386 dst += dlinesize / 2;
387 msrc += mlinesize / 2;
388 asrc += alinesize / 2;
394 ptrdiff_t mlinesize, ptrdiff_t alinesize,
399 const uint16_t *msrc = (
const uint16_t *)mmsrc;
400 const uint16_t *asrc = (
const uint16_t *)aasrc;
401 uint16_t *
dst = (uint16_t *)ddst;
404 for (y = 0; y <
h; y++) {
405 for (x = 0; x <
w; x++) {
406 if (asrc[x] > 0 && asrc[x] <
max)
412 dst += dlinesize / 2;
413 msrc += mlinesize / 2;
414 asrc += alinesize / 2;
420 ptrdiff_t mlinesize, ptrdiff_t alinesize,
425 const uint16_t *msrc = (
const uint16_t *)mmsrc;
426 const uint16_t *asrc = (
const uint16_t *)aasrc;
427 uint16_t *
dst = (uint16_t *)ddst;
430 for (y = 0; y <
h; y++) {
431 for (x = 0; x <
w; x++) {
432 if (asrc[x] > 0 && asrc[x] <
max)
438 dst += dlinesize / 2;
439 msrc += mlinesize / 2;
440 asrc += alinesize / 2;
446 ptrdiff_t mlinesize, ptrdiff_t alinesize,
451 const float *msrc = (
const float *)mmsrc;
452 const float *asrc = (
const float *)aasrc;
454 float *
dst = (
float *)ddst;
457 for (y = 0; y <
h; y++) {
458 for (x = 0; x <
w; x++) {
460 dst[x] = msrc[x] / asrc[x];
465 dst += dlinesize / 4;
466 msrc += mlinesize / 4;
467 asrc += alinesize / 4;
473 ptrdiff_t mlinesize, ptrdiff_t alinesize,
478 const float *msrc = (
const float *)mmsrc;
479 const float *asrc = (
const float *)aasrc;
481 float *
dst = (
float *)ddst;
484 float offsetf =
offset / 65535.0f;
486 for (y = 0; y <
h; y++) {
487 for (x = 0; x <
w; x++) {
489 dst[x] = (msrc[x] - offsetf) / asrc[x] + offsetf;
494 dst += dlinesize / 4;
495 msrc += mlinesize / 4;
496 asrc += alinesize / 4;
509 for (p = 0; p <
s->nb_planes; p++) {
513 if (!((1 << p) &
s->planes) || p == 3) {
526 base->linesize[p],
s->inplace ?
alpha->linesize[3] :
alpha->linesize[0],
529 s->half,
s->inverse ?
s->max :
s->depth,
s->offset);
559 switch (outlink->
format) {
611 switch (outlink->
format) {
707 vsub =
desc->log2_chroma_h;
709 s->height[0] =
s->height[3] = inlink->
h;
711 s->width[0] =
s->width[3] = inlink->
w;
714 s->max = (1 <<
s->depth) - 1;
715 s->half = (1 <<
s->depth) / 2;
716 s->offset = 16 << (
s->depth - 8);
738 "(size %dx%d) do not match the corresponding "
739 "second input link %s parameters (%dx%d) ",
746 outlink->
w =
base->w;
747 outlink->
h =
base->h;
816 if (!strcmp(
ctx->filter->name,
"premultiply_dynamic")) {
817 s->dynamic =
s->inplace = 1;
821 if (!strcmp(
ctx->filter->name,
"unpremultiply"))
859#if CONFIG_PREMULTIPLY_FILTER
862 .p.name =
"premultiply",
863 .p.description =
NULL_IF_CONFIG_SMALL(
"PreMultiply first stream with first plane of second stream."),
864 .p.priv_class = &premultiply_class,
878#if CONFIG_UNPREMULTIPLY_FILTER
881 .p.name =
"unpremultiply",
882 .p.description =
NULL_IF_CONFIG_SMALL(
"UnPreMultiply first stream with first plane of second stream."),
883 .p.priv_class = &premultiply_class,
897#if CONFIG_PREMULTIPLY_DYNAMIC_FILTER
908 .p.name =
"premultiply_dynamic",
909 .p.description =
NULL_IF_CONFIG_SMALL(
"Premultiply or unpremultiply an image in-place, as needed."),
910 .p.priv_class = &premultiply_class,
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static int config_input(AVFilterLink *inlink)
const FFFilter ff_vf_premultiply_dynamic
const FFFilter ff_vf_unpremultiply
const FFFilter ff_vf_premultiply
static AVFormatContext * ctx
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_append_inpad(AVFilterContext *f, AVFilterPad *p)
Append a new input/output pad to the filter's list of such pads.
int ff_outlink_frame_wanted(AVFilterLink *link)
Test if a frame is wanted on an output link.
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Main libavfilter public API header.
#define fs(width, name, subs,...)
#define AV_CEIL_RSHIFT(a, b)
int(* init)(AVBSFContext *ctx)
static av_always_inline int process_frame(AVTextFormatContext *tfc, InputFile *ifile, AVFrame *frame, const AVPacket *pkt, int *packet_new)
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
int ff_framesync_get_frame(FFFrameSync *fs, unsigned in, AVFrame **rframe, unsigned get)
Get the current frame in an input.
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
int ff_framesync_init(FFFrameSync *fs, AVFilterContext *parent, unsigned nb_in)
Initialize a frame sync structure.
@ EXT_INFINITY
Extend the frame to infinity.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
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.
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.
static const int16_t alpha[]
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
static int config_output(AVBitStreamFilterLink *outlink)
static int shift(int a, int b)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
static int ff_slice_pos(int total, int jobnr, int nb_jobs)
Compute the boundary index for a slice when work of size total is split into nb_jobs slices.
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
#define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter)
Forward the status on an output link to all input links.
#define AVFILTER_DEFINE_CLASS_EXT(name, desc, options)
static FilterLink * ff_filter_link(AVFilterLink *link)
#define FILTER_QUERY_FUNC2(func)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static const struct @257111027162314367033347246032313251342043035002 planes[]
static uint8_t half(int a, int b)
static int slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output)
Handle slice ends.
@ EXT_STOP
Completely stop all streams with this one.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
#define AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRPF32
#define AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_GBRAP16
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AVCOL_RANGE_JPEG
Full range content.
#define AV_PIX_FMT_YUVA444P10
@ AVALPHA_MODE_STRAIGHT
Alpha channel is independent of color values.
@ AVALPHA_MODE_PREMULTIPLIED
Alpha channel is multiplied into color values.
#define AV_VIDEO_MAX_PLANES
Maximum number of planes in any pixel format.
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GBRP12
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
@ 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_GRAY14
#define AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_GBRAPF32
#define AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P10
Describe the class of an AVClass context structure.
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
enum AVAlphaMode alpha_mode
alpha mode (for videos with an alpha channel)
AVFilterContext * dst
dest filter
int format
agreed upon media format
A filter pad used for either input or output.
int(* config_props)(AVFilterLink *link)
Link configuration callback.
enum AVMediaType type
AVFilterPad type.
const char * name
Pad name.
This structure describes decoded (raw) audio or video data.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
enum FFFrameSyncExtMode after
Extrapolation mode for timestamps after the last frame.
enum FFFrameSyncExtMode before
Extrapolation mode for timestamps before the first frame.
AVRational time_base
Time base for the incoming frames.
unsigned sync
Synchronization level: frames on input at the highest sync level will generate output frame events.
Link properties exposed to filter code, but not external callers.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable.
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)
int height[AV_VIDEO_MAX_PLANES]
int width[AV_VIDEO_MAX_PLANES]
int linesize[AV_VIDEO_MAX_PLANES]
Used for passing data between threads.
static enum AVPixelFormat alpha_pix_fmts[]
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 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)
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)
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)
static const AVFilterPad premultiply_outputs[]
static int config_input(AVFilterLink *inlink)
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)
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)
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 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)
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)
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)
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 query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static int activate(AVFilterContext *ctx)
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)
static av_cold void uninit(AVFilterContext *ctx)
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)
static int config_output(AVFilterLink *outlink)
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 int premultiply_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int process_frame(FFFrameSync *fs)
static int filter_frame(AVFilterContext *ctx, AVFrame **out, AVFrame *base, AVFrame *alpha)
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)
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)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)