48 ptrdiff_t mlinesize, ptrdiff_t alinesize,
54 #define OFFSET(x) offsetof(PreMultiplyContext, x) 55 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM 63 #define premultiply_options options 94 ptrdiff_t mlinesize, ptrdiff_t alinesize,
101 for (y = 0; y <
h; y++) {
102 for (x = 0; x <
w; x++) {
103 dst[x] = ((msrc[x] * (((asrc[x] >> 1) & 1) + asrc[x])) + 128) >> 8;
114 ptrdiff_t mlinesize, ptrdiff_t alinesize,
121 for (y = 0; y <
h; y++) {
122 for (x = 0; x <
w; x++) {
123 dst[x] = ((((msrc[x] - 128) * (((asrc[x] >> 1) & 1) + asrc[x]))) >> 8) + 128;
134 ptrdiff_t mlinesize, ptrdiff_t alinesize,
141 for (y = 0; y <
h; y++) {
142 for (x = 0; x <
w; x++) {
143 dst[x] = ((((msrc[x] -
offset) * (((asrc[x] >> 1) & 1) + asrc[x])) + 128) >> 8) +
offset;
154 ptrdiff_t mlinesize, ptrdiff_t alinesize,
159 const uint16_t *msrc = (
const uint16_t *)mmsrc;
160 const uint16_t *asrc = (
const uint16_t *)aasrc;
161 uint16_t *
dst = (uint16_t *)ddst;
164 for (y = 0; y <
h; y++) {
165 for (x = 0; x <
w; x++) {
166 dst[x] = ((msrc[x] * (((asrc[x] >> 1) & 1) + asrc[x])) +
half) >> shift;
169 dst += dlinesize / 2;
170 msrc += mlinesize / 2;
171 asrc += alinesize / 2;
177 ptrdiff_t mlinesize, ptrdiff_t alinesize,
182 const uint16_t *msrc = (
const uint16_t *)mmsrc;
183 const uint16_t *asrc = (
const uint16_t *)aasrc;
184 uint16_t *
dst = (uint16_t *)ddst;
187 for (y = 0; y <
h; y++) {
188 for (x = 0; x <
w; x++) {
189 dst[x] = ((((msrc[x] -
half) * (int64_t)(((asrc[x] >> 1) & 1) + asrc[x]))) >> shift) +
half;
192 dst += dlinesize / 2;
193 msrc += mlinesize / 2;
194 asrc += alinesize / 2;
200 ptrdiff_t mlinesize, ptrdiff_t alinesize,
205 const uint16_t *msrc = (
const uint16_t *)mmsrc;
206 const uint16_t *asrc = (
const uint16_t *)aasrc;
207 uint16_t *
dst = (uint16_t *)ddst;
210 for (y = 0; y <
h; y++) {
211 for (x = 0; x <
w; x++) {
212 dst[x] = ((((msrc[x] -
offset) * (int64_t)(((asrc[x] >> 1) & 1) + asrc[x])) +
half) >> shift) +
offset;
215 dst += dlinesize / 2;
216 msrc += mlinesize / 2;
217 asrc += alinesize / 2;
223 ptrdiff_t mlinesize, ptrdiff_t alinesize,
228 const float *msrc = (
const float *)mmsrc;
229 const float *asrc = (
const float *)aasrc;
230 float *
dst = (
float *)ddst;
233 for (y = 0; y <
h; y++) {
234 for (x = 0; x <
w; x++) {
235 dst[x] = msrc[x] * asrc[x];
238 dst += dlinesize / 4;
239 msrc += mlinesize / 4;
240 asrc += alinesize / 4;
246 ptrdiff_t mlinesize, ptrdiff_t alinesize,
251 const float *msrc = (
const float *)mmsrc;
252 const float *asrc = (
const float *)aasrc;
253 float *
dst = (
float *)ddst;
256 float offsetf = offset / 65535.0f;
258 for (y = 0; y <
h; y++) {
259 for (x = 0; x <
w; x++) {
260 dst[x] = ((msrc[x] - offsetf) * asrc[x]) + offsetf;
263 dst += dlinesize / 4;
264 msrc += mlinesize / 4;
265 asrc += alinesize / 4;
271 ptrdiff_t mlinesize, ptrdiff_t alinesize,
278 for (y = 0; y <
h; y++) {
279 for (x = 0; x <
w; x++) {
280 if (asrc[x] > 0 && asrc[x] < 255)
281 dst[x] =
FFMIN(msrc[x] * 255 / asrc[x], 255);
294 ptrdiff_t mlinesize, ptrdiff_t alinesize,
301 for (y = 0; y <
h; y++) {
302 for (x = 0; x <
w; x++) {
303 if (asrc[x] > 0 && asrc[x] < 255)
304 dst[x] =
FFMIN((msrc[x] - 128) * 255 / asrc[x] + 128, 255);
317 ptrdiff_t mlinesize, ptrdiff_t alinesize,
324 for (y = 0; y <
h; y++) {
325 for (x = 0; x <
w; x++) {
326 if (asrc[x] > 0 && asrc[x] < 255)
327 dst[x] =
FFMIN(
FFMAX(msrc[x] - offset, 0) * 255 / asrc[x] + offset, 255);
340 ptrdiff_t mlinesize, ptrdiff_t alinesize,
345 const uint16_t *msrc = (
const uint16_t *)mmsrc;
346 const uint16_t *asrc = (
const uint16_t *)aasrc;
347 uint16_t *
dst = (uint16_t *)ddst;
350 for (y = 0; y <
h; y++) {
351 for (x = 0; x <
w; x++) {
352 if (asrc[x] > 0 && asrc[x] < max)
353 dst[x] =
FFMIN(msrc[x] * (
unsigned)max / asrc[x], max);
358 dst += dlinesize / 2;
359 msrc += mlinesize / 2;
360 asrc += alinesize / 2;
366 ptrdiff_t mlinesize, ptrdiff_t alinesize,
371 const uint16_t *msrc = (
const uint16_t *)mmsrc;
372 const uint16_t *asrc = (
const uint16_t *)aasrc;
373 uint16_t *
dst = (uint16_t *)ddst;
376 for (y = 0; y <
h; y++) {
377 for (x = 0; x <
w; x++) {
378 if (asrc[x] > 0 && asrc[x] < max)
379 dst[x] =
FFMAX(
FFMIN((msrc[x] - half) * max / asrc[x], half - 1), -half) +
half;
384 dst += dlinesize / 2;
385 msrc += mlinesize / 2;
386 asrc += alinesize / 2;
392 ptrdiff_t mlinesize, ptrdiff_t alinesize,
397 const uint16_t *msrc = (
const uint16_t *)mmsrc;
398 const uint16_t *asrc = (
const uint16_t *)aasrc;
399 uint16_t *
dst = (uint16_t *)ddst;
402 for (y = 0; y <
h; y++) {
403 for (x = 0; x <
w; x++) {
404 if (asrc[x] > 0 && asrc[x] < max)
405 dst[x] =
FFMAX(
FFMIN(
FFMAX(msrc[x] - offset, 0) * (
unsigned)max / asrc[x] + offset, max), 0);
410 dst += dlinesize / 2;
411 msrc += mlinesize / 2;
412 asrc += alinesize / 2;
418 ptrdiff_t mlinesize, ptrdiff_t alinesize,
423 const float *msrc = (
const float *)mmsrc;
424 const float *asrc = (
const float *)aasrc;
426 float *
dst = (
float *)ddst;
429 for (y = 0; y <
h; y++) {
430 for (x = 0; x <
w; x++) {
432 dst[x] = msrc[x] / asrc[x];
437 dst += dlinesize / 4;
438 msrc += mlinesize / 4;
439 asrc += alinesize / 4;
445 ptrdiff_t mlinesize, ptrdiff_t alinesize,
450 const float *msrc = (
const float *)mmsrc;
451 const float *asrc = (
const float *)aasrc;
453 float *
dst = (
float *)ddst;
456 float offsetf = offset / 65535.0f;
458 for (y = 0; y <
h; y++) {
459 for (x = 0; x <
w; x++) {
461 dst[x] = (msrc[x] - offsetf) / asrc[x] + offsetf;
466 dst += dlinesize / 4;
467 msrc += mlinesize / 4;
468 asrc += alinesize / 4;
482 const int slice_start = (s->
height[
p] * jobnr) / nb_jobs;
485 if (!((1 << p) & s->
planes) || p == 3) {
490 s->
linesize[p], slice_end - slice_start);
500 s->
width[
p], slice_end - slice_start,
530 switch (outlink->
format) {
582 switch (outlink->
format) {
708 if (base->
w != alpha->
w ||
709 base->
h != alpha->
h) {
711 "(size %dx%d) do not match the corresponding " 712 "second input link %s parameters (%dx%d) ",
719 outlink->
w = base->
w;
720 outlink->
h = base->
h;
786 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."),
836 .
outputs = premultiply_outputs,
837 .priv_class = &premultiply_class,
845 #if CONFIG_UNPREMULTIPLY_FILTER 847 #define unpremultiply_options options 851 .
name =
"unpremultiply",
852 .description =
NULL_IF_CONFIG_SMALL(
"UnPreMultiply first stream with first plane of second stream."),
859 .
outputs = premultiply_outputs,
860 .priv_class = &unpremultiply_class,
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
static int shift(int a, int b)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
static int activate(AVFilterContext *ctx)
This structure describes decoded (raw) audio or video data.
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)
#define AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_GBRAP10
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
#define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter)
Forward the status on an output link to all input links.
Main libavfilter public API header.
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)
int h
agreed upon image height
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
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[]
#define AV_PIX_FMT_GBRP10
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)
enum AVMediaType type
AVFilterPad type.
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)
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
static const struct @322 planes[]
int is_disabled
the enabled state from the last expression evaluation
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
AVFILTER_DEFINE_CLASS(premultiply)
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
enum FFFrameSyncExtMode before
Extrapolation mode for timestamps before the first frame.
#define AV_PIX_FMT_GRAY10
const char * name
Pad name.
AVFilterContext * parent
Parent filter context.
#define AV_PIX_FMT_GRAY12
AVFilterLink ** inputs
array of pointers to input links
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
#define fs(width, name, subs,...)
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
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
FFFrameSyncIn * in
Pointer to array of inputs.
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)
#define AV_PIX_FMT_YUV444P16
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
A filter pad used for either input or output.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
A link between two filters.
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
AVFilterPad * input_pads
array of input pads
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0, will be automatically copied from the first input of the source filter if it exists.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void(* premultiply[4])(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)
void * priv
private data for use by the filter
enum AVColorRange color_range
MPEG vs JPEG YUV range.
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
#define AV_PIX_FMT_YUVA444P16
AVFilter ff_vf_premultiply
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
#define AV_PIX_FMT_GBRAP12
AVRational time_base
Time base for the incoming frames.
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
#define AV_PIX_FMT_YUV444P10
int(* on_event)(struct FFFrameSync *fs)
Callback called when a frame event is ready.
#define AV_PIX_FMT_GBRAP16
int w
agreed upon image width
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
int(* config_props)(AVFilterLink *link)
Link configuration callback.
#define AV_PIX_FMT_GBRP16
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
#define AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_YUVA444P12
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
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)
AVRational time_base
Time base for the output events.
static const AVFilterPad premultiply_outputs[]
AVFilterContext * src
source filter
#define AV_PIX_FMT_YUVA444P10
static av_cold void uninit(AVFilterContext *ctx)
void * opaque
Opaque pointer, not used by the API.
#define AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_GBRP14
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
static const AVFilterPad outputs[]
int format
agreed upon media format
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 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)
Extend the frame to infinity.
static int process_frame(FFFrameSync *fs)
Used for passing data between threads.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
int ff_framesync_init(FFFrameSync *fs, AVFilterContext *parent, unsigned nb_in)
Initialize a frame sync structure.
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static const int16_t alpha[]
#define AV_PIX_FMT_GRAY14
AVFilter ff_vf_unpremultiply
static int query_formats(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
unsigned sync
Synchronization level: frames on input at the highest sync level will generate output frame events...
Describe the class of an AVClass context structure.
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 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)
they must not be accessed directly The fifo field contains the frames that are queued in the input for processing by the filter The status_in and status_out fields contains the queued status(EOF or error) of the link
static int config_output(AVFilterLink *outlink)
const char * name
Filter name.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
AVFilterLink ** outputs
array of pointers to output links
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 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)
#define AV_PIX_FMT_GBRP12
#define flags(name, subs,...)
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
#define AV_PIX_FMT_YUV444P12
static int config_input(AVFilterLink *inlink)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Narrow or limited range content.
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)
#define AV_PIX_FMT_GBRPF32
#define AV_PIX_FMT_GBRAPF32
planar GBRA 4:4:4:4 32bpp
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 int premultiply_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_frame(AVFilterContext *ctx, AVFrame **out, AVFrame *base, AVFrame *alpha)
#define AV_PIX_FMT_YUVA444P9
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
avfilter_execute_func * execute
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
Completely stop all streams with this one.
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)
AVFilterContext * dst
dest filter
const AVPixFmtDescriptor * desc
static uint8_t half(int a, int b)
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)
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.
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
int ff_framesync_get_frame(FFFrameSync *fs, unsigned in, AVFrame **rframe, unsigned get)
Get the current frame in an input.
int depth
Number of bits in the component.
AVPixelFormat
Pixel format.
const AVFilter * filter
the AVFilter of which this is an instance
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
static av_cold int init(AVFilterContext *ctx)
static enum AVPixelFormat alpha_pix_fmts[]
#define AV_CEIL_RSHIFT(a, b)
static int ff_insert_inpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new input pad for the filter.