Go to the documentation of this file.
54 #define OFFSET(x) offsetof(ColorChannelMixerContext, x)
55 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
110 const int slice_start = (
out->height * jobnr) / nb_jobs;
111 const int slice_end = (
out->height * (jobnr+1)) / nb_jobs;
112 const uint8_t *srcg =
in->data[0] + slice_start *
in->linesize[0];
113 const uint8_t *srcb =
in->data[1] + slice_start *
in->linesize[1];
114 const uint8_t *srcr =
in->data[2] + slice_start *
in->linesize[2];
115 const uint8_t *srca =
in->data[3] + slice_start *
in->linesize[3];
116 uint8_t *dstg =
out->data[0] + slice_start *
out->linesize[0];
117 uint8_t *dstb =
out->data[1] + slice_start *
out->linesize[1];
118 uint8_t *dstr =
out->data[2] + slice_start *
out->linesize[2];
119 uint8_t *dsta =
out->data[3] + slice_start *
out->linesize[3];
123 for (j = 0; j <
out->width; j++) {
129 dstr[j] = av_clip_uint8(
s->lut[
R][
R][rin] +
132 (have_alpha == 1 ?
s->lut[
R][
A][ain] : 0));
133 dstg[j] = av_clip_uint8(
s->lut[
G][
R][rin] +
136 (have_alpha == 1 ?
s->lut[
G][
A][ain] : 0));
137 dstb[j] = av_clip_uint8(
s->lut[
B][
R][rin] +
140 (have_alpha == 1 ?
s->lut[
B][
A][ain] : 0));
141 if (have_alpha == 1) {
142 dsta[j] = av_clip_uint8(
s->lut[
A][
R][rin] +
149 srcg +=
in->linesize[0];
150 srcb +=
in->linesize[1];
151 srcr +=
in->linesize[2];
152 srca +=
in->linesize[3];
153 dstg +=
out->linesize[0];
154 dstb +=
out->linesize[1];
155 dstr +=
out->linesize[2];
156 dsta +=
out->linesize[3];
163 int have_alpha,
int depth)
169 const int slice_start = (
out->height * jobnr) / nb_jobs;
170 const int slice_end = (
out->height * (jobnr+1)) / nb_jobs;
171 const uint16_t *srcg = (
const uint16_t *)(
in->data[0] + slice_start *
in->linesize[0]);
172 const uint16_t *srcb = (
const uint16_t *)(
in->data[1] + slice_start *
in->linesize[1]);
173 const uint16_t *srcr = (
const uint16_t *)(
in->data[2] + slice_start *
in->linesize[2]);
174 const uint16_t *srca = (
const uint16_t *)(
in->data[3] + slice_start *
in->linesize[3]);
175 uint16_t *dstg = (uint16_t *)(
out->data[0] + slice_start *
out->linesize[0]);
176 uint16_t *dstb = (uint16_t *)(
out->data[1] + slice_start *
out->linesize[1]);
177 uint16_t *dstr = (uint16_t *)(
out->data[2] + slice_start *
out->linesize[2]);
178 uint16_t *dsta = (uint16_t *)(
out->data[3] + slice_start *
out->linesize[3]);
182 for (j = 0; j <
out->width; j++) {
183 const uint16_t rin = srcr[j];
184 const uint16_t gin = srcg[j];
185 const uint16_t bin = srcb[j];
186 const uint16_t ain = srca[j];
188 dstr[j] = av_clip_uintp2(
s->lut[
R][
R][rin] +
191 (have_alpha == 1 ?
s->lut[
R][
A][ain] : 0), depth);
192 dstg[j] = av_clip_uintp2(
s->lut[
G][
R][rin] +
195 (have_alpha == 1 ?
s->lut[
G][
A][ain] : 0), depth);
196 dstb[j] = av_clip_uintp2(
s->lut[
B][
R][rin] +
199 (have_alpha == 1 ?
s->lut[
B][
A][ain] : 0), depth);
200 if (have_alpha == 1) {
201 dsta[j] = av_clip_uintp2(
s->lut[
A][
R][rin] +
204 s->lut[
A][
A][ain], depth);
208 srcg +=
in->linesize[0] / 2;
209 srcb +=
in->linesize[1] / 2;
210 srcr +=
in->linesize[2] / 2;
211 srca +=
in->linesize[3] / 2;
212 dstg +=
out->linesize[0] / 2;
213 dstb +=
out->linesize[1] / 2;
214 dstr +=
out->linesize[2] / 2;
215 dsta +=
out->linesize[3] / 2;
272 int have_alpha,
int step)
278 const int slice_start = (
out->height * jobnr) / nb_jobs;
279 const int slice_end = (
out->height * (jobnr+1)) / nb_jobs;
284 const uint8_t *srcrow =
in->data[0] + slice_start *
in->linesize[0];
285 uint8_t *dstrow =
out->data[0] + slice_start *
out->linesize[0];
298 dst[j + roffset] = av_clip_uint8(
s->lut[
R][
R][rin] +
301 (have_alpha == 1 ?
s->lut[
R][
A][ain] : 0));
302 dst[j + goffset] = av_clip_uint8(
s->lut[
G][
R][rin] +
305 (have_alpha == 1 ?
s->lut[
G][
A][ain] : 0));
306 dst[j + boffset] = av_clip_uint8(
s->lut[
B][
R][rin] +
309 (have_alpha == 1 ?
s->lut[
B][
A][ain] : 0));
310 if (have_alpha == 1) {
311 dst[j + aoffset] = av_clip_uint8(
s->lut[
A][
R][rin] +
315 }
else if (have_alpha == -1 &&
in !=
out)
316 dst[j + aoffset] = 0;
319 srcrow +=
in->linesize[0];
320 dstrow +=
out->linesize[0];
327 int have_alpha,
int step)
333 const int slice_start = (
out->height * jobnr) / nb_jobs;
334 const int slice_end = (
out->height * (jobnr+1)) / nb_jobs;
339 const uint8_t *srcrow =
in->data[0] + slice_start *
in->linesize[0];
340 uint8_t *dstrow =
out->data[0] + slice_start *
out->linesize[0];
344 const uint16_t *
src = (
const uint16_t *)srcrow;
345 uint16_t *dst = (uint16_t *)dstrow;
348 const uint16_t rin =
src[j + roffset];
349 const uint16_t gin =
src[j + goffset];
350 const uint16_t bin =
src[j + boffset];
351 const uint16_t ain =
src[j + aoffset];
353 dst[j + roffset] = av_clip_uint16(
s->lut[
R][
R][rin] +
356 (have_alpha == 1 ?
s->lut[
R][
A][ain] : 0));
357 dst[j + goffset] = av_clip_uint16(
s->lut[
G][
R][rin] +
360 (have_alpha == 1 ?
s->lut[
G][
A][ain] : 0));
361 dst[j + boffset] = av_clip_uint16(
s->lut[
B][
R][rin] +
364 (have_alpha == 1 ?
s->lut[
B][
A][ain] : 0));
365 if (have_alpha == 1) {
366 dst[j + aoffset] = av_clip_uint16(
s->lut[
A][
R][rin] +
373 srcrow +=
in->linesize[0];
374 dstrow +=
out->linesize[0];
410 const int depth =
desc->comp[0].depth;
420 for (
i = 0;
i < 4;
i++)
446 switch (outlink->
format) {
560 .
name =
"colorchannelmixer",
563 .priv_class = &colorchannelmixer_class,
static int filter_slice_rgba64(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
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
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
AVFilter ff_vf_colorchannelmixer
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)
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
static const AVOption colorchannelmixer_options[]
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.
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
static int query_formats(AVFilterContext *ctx)
static int filter_slice_gbrp14(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
const char * name
Filter name.
static int filter_slice_rgb0(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
AVFormatInternal * internal
An opaque field for libavformat internal usage.
A link between two filters.
static int filter_slice_gbrap(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AV_PIX_FMT_GBRP14
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
static int filter_slice_rgba(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AV_PIX_FMT_GBRP10
static int filter_slice_gbrap16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
A filter pad used for either input or output.
#define AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP12
static int filter_slice_rgb48(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
static av_always_inline int filter_slice_rgba16_packed(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs, int have_alpha, int step)
static const AVFilterPad outputs[]
static enum AVPixelFormat pix_fmts[]
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
static const AVFilterPad colorchannelmixer_outputs[]
#define AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_RGBA64
Describe the class of an AVClass context structure.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
static int filter_slice_gbrp(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_slice_gbrp9(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static av_always_inline int filter_slice_rgba16_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs, int have_alpha, int depth)
static int filter_slice_gbrp10(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
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_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
AVFILTER_DEFINE_CLASS(colorchannelmixer)
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
static int filter_slice_gbrap10(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int format
agreed upon media format
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
AVFilterContext * src
source filter
int(* filter_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
#define AV_PIX_FMT_BGRA64
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
#define i(width, name, range_min, range_max)
int w
agreed upon image width
#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.
const char * name
Pad name.
static av_always_inline int filter_slice_rgba_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs, int have_alpha)
static int filter_slice_gbrp12(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static av_cold void uninit(AVFilterContext *ctx)
static int filter_slice_rgb24(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
int h
agreed upon image height
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
static int config_output(AVFilterLink *outlink)
static av_always_inline int filter_slice_rgba_packed(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs, int have_alpha, int step)
@ 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 filter_slice_gbrap12(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
#define flags(name, subs,...)
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
static int filter_slice_gbrp16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static const AVFilterPad colorchannelmixer_inputs[]