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|AV_OPT_FLAG_RUNTIME_PARAM
111 const int slice_start = (
out->height * jobnr) / nb_jobs;
112 const int slice_end = (
out->height * (jobnr+1)) / nb_jobs;
113 const uint8_t *srcg =
in->data[0] + slice_start *
in->linesize[0];
114 const uint8_t *srcb =
in->data[1] + slice_start *
in->linesize[1];
115 const uint8_t *srcr =
in->data[2] + slice_start *
in->linesize[2];
116 const uint8_t *srca =
in->data[3] + slice_start *
in->linesize[3];
117 uint8_t *dstg =
out->data[0] + slice_start *
out->linesize[0];
118 uint8_t *dstb =
out->data[1] + slice_start *
out->linesize[1];
119 uint8_t *dstr =
out->data[2] + slice_start *
out->linesize[2];
120 uint8_t *dsta =
out->data[3] + slice_start *
out->linesize[3];
124 for (j = 0; j <
out->width; j++) {
128 const uint8_t ain = have_alpha ? srca[j] : 0;
130 dstr[j] = av_clip_uint8(
s->lut[
R][
R][rin] +
133 (have_alpha == 1 ?
s->lut[
R][
A][ain] : 0));
134 dstg[j] = av_clip_uint8(
s->lut[
G][
R][rin] +
137 (have_alpha == 1 ?
s->lut[
G][
A][ain] : 0));
138 dstb[j] = av_clip_uint8(
s->lut[
B][
R][rin] +
141 (have_alpha == 1 ?
s->lut[
B][
A][ain] : 0));
142 if (have_alpha == 1) {
143 dsta[j] = av_clip_uint8(
s->lut[
A][
R][rin] +
150 srcg +=
in->linesize[0];
151 srcb +=
in->linesize[1];
152 srcr +=
in->linesize[2];
153 srca +=
in->linesize[3];
154 dstg +=
out->linesize[0];
155 dstb +=
out->linesize[1];
156 dstr +=
out->linesize[2];
157 dsta +=
out->linesize[3];
164 int have_alpha,
int depth)
170 const int slice_start = (
out->height * jobnr) / nb_jobs;
171 const int slice_end = (
out->height * (jobnr+1)) / nb_jobs;
172 const uint16_t *srcg = (
const uint16_t *)(
in->data[0] + slice_start *
in->linesize[0]);
173 const uint16_t *srcb = (
const uint16_t *)(
in->data[1] + slice_start *
in->linesize[1]);
174 const uint16_t *srcr = (
const uint16_t *)(
in->data[2] + slice_start *
in->linesize[2]);
175 const uint16_t *srca = (
const uint16_t *)(
in->data[3] + slice_start *
in->linesize[3]);
176 uint16_t *dstg = (uint16_t *)(
out->data[0] + slice_start *
out->linesize[0]);
177 uint16_t *dstb = (uint16_t *)(
out->data[1] + slice_start *
out->linesize[1]);
178 uint16_t *dstr = (uint16_t *)(
out->data[2] + slice_start *
out->linesize[2]);
179 uint16_t *dsta = (uint16_t *)(
out->data[3] + slice_start *
out->linesize[3]);
183 for (j = 0; j <
out->width; j++) {
184 const uint16_t rin = srcr[j];
185 const uint16_t gin = srcg[j];
186 const uint16_t bin = srcb[j];
187 const uint16_t ain = have_alpha ? srca[j] : 0;
189 dstr[j] = av_clip_uintp2(
s->lut[
R][
R][rin] +
192 (have_alpha == 1 ?
s->lut[
R][
A][ain] : 0), depth);
193 dstg[j] = av_clip_uintp2(
s->lut[
G][
R][rin] +
196 (have_alpha == 1 ?
s->lut[
G][
A][ain] : 0), depth);
197 dstb[j] = av_clip_uintp2(
s->lut[
B][
R][rin] +
200 (have_alpha == 1 ?
s->lut[
B][
A][ain] : 0), depth);
201 if (have_alpha == 1) {
202 dsta[j] = av_clip_uintp2(
s->lut[
A][
R][rin] +
205 s->lut[
A][
A][ain], depth);
209 srcg +=
in->linesize[0] / 2;
210 srcb +=
in->linesize[1] / 2;
211 srcr +=
in->linesize[2] / 2;
212 srca +=
in->linesize[3] / 2;
213 dstg +=
out->linesize[0] / 2;
214 dstb +=
out->linesize[1] / 2;
215 dstr +=
out->linesize[2] / 2;
216 dsta +=
out->linesize[3] / 2;
273 int have_alpha,
int step)
279 const int slice_start = (
out->height * jobnr) / nb_jobs;
280 const int slice_end = (
out->height * (jobnr+1)) / nb_jobs;
285 const uint8_t *srcrow =
in->data[0] + slice_start *
in->linesize[0];
286 uint8_t *dstrow =
out->data[0] + slice_start *
out->linesize[0];
299 dst[j + roffset] = av_clip_uint8(
s->lut[
R][
R][rin] +
302 (have_alpha == 1 ?
s->lut[
R][
A][ain] : 0));
303 dst[j + goffset] = av_clip_uint8(
s->lut[
G][
R][rin] +
306 (have_alpha == 1 ?
s->lut[
G][
A][ain] : 0));
307 dst[j + boffset] = av_clip_uint8(
s->lut[
B][
R][rin] +
310 (have_alpha == 1 ?
s->lut[
B][
A][ain] : 0));
311 if (have_alpha == 1) {
312 dst[j + aoffset] = av_clip_uint8(
s->lut[
A][
R][rin] +
316 }
else if (have_alpha == -1 &&
in !=
out)
317 dst[j + aoffset] = 0;
320 srcrow +=
in->linesize[0];
321 dstrow +=
out->linesize[0];
328 int have_alpha,
int step)
334 const int slice_start = (
out->height * jobnr) / nb_jobs;
335 const int slice_end = (
out->height * (jobnr+1)) / nb_jobs;
340 const uint8_t *srcrow =
in->data[0] + slice_start *
in->linesize[0];
341 uint8_t *dstrow =
out->data[0] + slice_start *
out->linesize[0];
345 const uint16_t *
src = (
const uint16_t *)srcrow;
346 uint16_t *dst = (uint16_t *)dstrow;
349 const uint16_t rin =
src[j + roffset];
350 const uint16_t gin =
src[j + goffset];
351 const uint16_t bin =
src[j + boffset];
352 const uint16_t ain =
src[j + aoffset];
354 dst[j + roffset] = av_clip_uint16(
s->lut[
R][
R][rin] +
357 (have_alpha == 1 ?
s->lut[
R][
A][ain] : 0));
358 dst[j + goffset] = av_clip_uint16(
s->lut[
G][
R][rin] +
361 (have_alpha == 1 ?
s->lut[
G][
A][ain] : 0));
362 dst[j + boffset] = av_clip_uint16(
s->lut[
B][
R][rin] +
365 (have_alpha == 1 ?
s->lut[
B][
A][ain] : 0));
366 if (have_alpha == 1) {
367 dst[j + aoffset] = av_clip_uint16(
s->lut[
A][
R][rin] +
374 srcrow +=
in->linesize[0];
375 dstrow +=
out->linesize[0];
411 const int depth =
desc->comp[0].depth;
422 for (
i = 0;
i < 4;
i++)
449 switch (outlink->
format) {
538 char *res,
int res_len,
int flags)
574 .
name =
"colorchannelmixer",
577 .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 ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
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 int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static const AVFilterPad colorchannelmixer_inputs[]