59 #define OFFSET(x) offsetof(ColorChannelMixerContext, x)
60 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
112 return v0 + (v1 -
v0) *
f;
115 static void preservel(
float *
r,
float *
g,
float *
b,
float lin,
float lout)
123 int have_alpha,
int pl)
129 const float l =
s->preserve_lightness;
130 const float sr =
s->sr;
131 const float sg =
s->sg;
132 const float sb =
s->sb;
135 const uint8_t *srcg =
in->data[0] + slice_start *
in->linesize[0];
136 const uint8_t *srcb =
in->data[1] + slice_start *
in->linesize[1];
137 const uint8_t *srcr =
in->data[2] + slice_start *
in->linesize[2];
138 const uint8_t *srca =
in->data[3] + slice_start *
in->linesize[3];
139 uint8_t *dstg =
out->data[0] + slice_start *
out->linesize[0];
140 uint8_t *dstb =
out->data[1] + slice_start *
out->linesize[1];
141 uint8_t *dstr =
out->data[2] + slice_start *
out->linesize[2];
142 uint8_t *dsta =
out->data[3] + slice_start *
out->linesize[3];
146 for (j = 0; j <
out->width; j++) {
150 const uint8_t ain = have_alpha ? srca[j] : 0;
151 int rout, gout, bout;
157 rout =
s->lut[
R][
R][rin] +
160 (have_alpha == 1 ?
s->lut[
R][
A][ain] : 0);
161 gout =
s->lut[
G][
R][rin] +
164 (have_alpha == 1 ?
s->lut[
G][
A][ain] : 0);
165 bout =
s->lut[
B][
R][rin] +
168 (have_alpha == 1 ?
s->lut[
B][
A][ain] : 0);
171 float frout = rout / sr;
172 float fgout = gout / sg;
173 float fbout = bout / sb;
174 float lout =
FFMAX3(frout, fgout, fbout) +
FFMIN3(frout, fgout, fbout);
176 preservel(&frout, &fgout, &fbout, lin, lout);
187 if (have_alpha == 1) {
195 srcg +=
in->linesize[0];
196 srcb +=
in->linesize[1];
197 srcr +=
in->linesize[2];
198 srca +=
in->linesize[3];
199 dstg +=
out->linesize[0];
200 dstb +=
out->linesize[1];
201 dstr +=
out->linesize[2];
202 dsta +=
out->linesize[3];
209 int have_alpha,
int depth,
int pl)
215 const float l =
s->preserve_lightness;
216 const float sr =
s->sr;
217 const float sg =
s->sg;
218 const float sb =
s->sb;
221 const uint16_t *srcg = (
const uint16_t *)(
in->data[0] + slice_start *
in->linesize[0]);
222 const uint16_t *srcb = (
const uint16_t *)(
in->data[1] + slice_start *
in->linesize[1]);
223 const uint16_t *srcr = (
const uint16_t *)(
in->data[2] + slice_start *
in->linesize[2]);
224 const uint16_t *srca = (
const uint16_t *)(
in->data[3] + slice_start *
in->linesize[3]);
225 uint16_t *dstg = (uint16_t *)(
out->data[0] + slice_start *
out->linesize[0]);
226 uint16_t *dstb = (uint16_t *)(
out->data[1] + slice_start *
out->linesize[1]);
227 uint16_t *dstr = (uint16_t *)(
out->data[2] + slice_start *
out->linesize[2]);
228 uint16_t *dsta = (uint16_t *)(
out->data[3] + slice_start *
out->linesize[3]);
232 for (j = 0; j <
out->width; j++) {
233 const uint16_t rin = srcr[j];
234 const uint16_t gin = srcg[j];
235 const uint16_t bin = srcb[j];
236 const uint16_t ain = have_alpha ? srca[j] : 0;
237 int rout, gout, bout;
243 rout =
s->lut[
R][
R][rin] +
246 (have_alpha == 1 ?
s->lut[
R][
A][ain] : 0);
247 gout =
s->lut[
G][
R][rin] +
250 (have_alpha == 1 ?
s->lut[
G][
A][ain] : 0);
251 bout =
s->lut[
B][
R][rin] +
254 (have_alpha == 1 ?
s->lut[
B][
A][ain] : 0);
257 float frout = rout / sr;
258 float fgout = gout / sg;
259 float fbout = bout / sb;
260 float lout =
FFMAX3(frout, fgout, fbout) +
FFMIN3(frout, fgout, fbout);
262 preservel(&frout, &fgout, &fbout, lin, lout);
273 if (have_alpha == 1) {
277 s->lut[
A][
A][ain], depth);
281 srcg +=
in->linesize[0] / 2;
282 srcb +=
in->linesize[1] / 2;
283 srcr +=
in->linesize[2] / 2;
284 srca +=
in->linesize[3] / 2;
285 dstg +=
out->linesize[0] / 2;
286 dstb +=
out->linesize[1] / 2;
287 dstr +=
out->linesize[2] / 2;
288 dsta +=
out->linesize[3] / 2;
395 int have_alpha,
int step,
int pl)
401 const float l =
s->preserve_lightness;
402 const float sr =
s->sr;
403 const float sg =
s->sg;
404 const float sb =
s->sb;
411 const uint8_t *srcrow =
in->data[0] + slice_start *
in->linesize[0];
412 uint8_t *dstrow =
out->data[0] + slice_start *
out->linesize[0];
419 for (j = 0; j <
out->width * step; j += step) {
424 int rout, gout, bout;
430 rout =
s->lut[
R][
R][rin] +
433 (have_alpha == 1 ?
s->lut[
R][
A][ain] : 0);
434 gout =
s->lut[
G][
R][rin] +
437 (have_alpha == 1 ?
s->lut[
G][
A][ain] : 0);
438 bout =
s->lut[
B][
R][rin] +
441 (have_alpha == 1 ?
s->lut[
B][
A][ain] : 0);
444 float frout = rout / sr;
445 float fgout = gout / sg;
446 float fbout = bout / sb;
447 float lout =
FFMAX3(frout, fgout, fbout) +
FFMIN3(frout, fgout, fbout);
449 preservel(&frout, &fgout, &fbout, lin, lout);
460 if (have_alpha == 1) {
465 }
else if (have_alpha == -1 &&
in !=
out)
466 dst[j + aoffset] = 0;
469 srcrow +=
in->linesize[0];
470 dstrow +=
out->linesize[0];
477 int have_alpha,
int step,
int pl)
483 const float l =
s->preserve_lightness;
484 const float sr =
s->sr;
485 const float sg =
s->sg;
486 const float sb =
s->sb;
493 const uint8_t *srcrow =
in->data[0] + slice_start *
in->linesize[0];
494 uint8_t *dstrow =
out->data[0] + slice_start *
out->linesize[0];
498 const uint16_t *
src = (
const uint16_t *)srcrow;
499 uint16_t *dst = (uint16_t *)dstrow;
501 for (j = 0; j <
out->width * step; j += step) {
502 const uint16_t rin =
src[j + roffset];
503 const uint16_t gin =
src[j + goffset];
504 const uint16_t bin =
src[j + boffset];
505 const uint16_t ain =
src[j + aoffset];
506 int rout, gout, bout;
512 rout =
s->lut[
R][
R][rin] +
515 (have_alpha == 1 ?
s->lut[
R][
A][ain] : 0);
516 gout =
s->lut[
G][
R][rin] +
519 (have_alpha == 1 ?
s->lut[
G][
A][ain] : 0);
520 bout =
s->lut[
B][
R][rin] +
523 (have_alpha == 1 ?
s->lut[
B][
A][ain] : 0);
526 float frout = rout / sr;
527 float fgout = gout / sg;
528 float fbout = bout / sb;
529 float lout =
FFMAX3(frout, fgout, fbout) +
FFMIN3(frout, fgout, fbout);
531 preservel(&frout, &fgout, &fbout, lin, lout);
542 if (have_alpha == 1) {
550 srcrow +=
in->linesize[0];
551 dstrow +=
out->linesize[0];
612 const int depth =
desc->comp[0].depth;
623 for (
i = 0;
i < 4;
i++)
628 s->sr =
s->rr +
s->rg +
s->rb +
s->ra;
629 s->sg =
s->gr +
s->gg +
s->gb +
s->ga;
630 s->sb =
s->br +
s->bg +
s->bb +
s->ba;
632 if (
fabs(
s->sr) <= DBL_EPSILON)
635 if (
fabs(
s->sg) <= DBL_EPSILON)
638 if (
fabs(
s->sb) <= DBL_EPSILON)
663 switch (outlink->
format) {
743 const int pl =
s->preserve_lightness > 0.;
768 char *res,
int res_len,
int flags)
804 .
name =
"colorchannelmixer",
807 .priv_class = &colorchannelmixer_class,
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
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
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next 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 ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Main libavfilter public API header.
#define flags(name, subs,...)
static __device__ float fabs(float a)
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
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.
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
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.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_GBRP12
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
#define AV_PIX_FMT_BGRA64
#define AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP14
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
AVFilterContext * dst
dest filter
int format
agreed upon media format
A filter pad used for either input or output.
const char * name
Pad name.
const char * name
Filter name.
AVFormatInternal * internal
An opaque field for libavformat internal usage.
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...
double preserve_lightness
int(* filter_slice[2])(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Used for passing data between threads.
static int filter_slice_gbrap12(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static av_always_inline int filter_slice_rgba_packed(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs, int have_alpha, int step, int pl)
static int filter_slice_gbrp9_pl(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, int pl)
static const AVFilterPad colorchannelmixer_outputs[]
static const AVFilterPad colorchannelmixer_inputs[]
static int filter_slice_gbrap(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_slice_gbrap10(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_slice_rgb24_pl(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_slice_rgb24(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_slice_gbrap_pl(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
AVFilter ff_vf_colorchannelmixer
static int filter_slice_gbrp9(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_slice_gbrap12_pl(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_slice_rgb0(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int query_formats(AVFilterContext *ctx)
static int filter_slice_rgba64_pl(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_slice_rgba_pl(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_slice_gbrp(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_slice_rgba64(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_slice_gbrp14_pl(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_slice_gbrp10(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
AVFILTER_DEFINE_CLASS(colorchannelmixer)
static int filter_slice_rgb48(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_slice_gbrp12_pl(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static int filter_slice_gbrap16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_slice_rgb0_pl(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static av_always_inline int filter_slice_rgba16_packed(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs, int have_alpha, int step, int pl)
static float lerpf(float v0, float v1, float f)
static int filter_slice_gbrp10_pl(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static const AVOption colorchannelmixer_options[]
static int filter_slice_gbrp16_pl(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_slice_rgb48_pl(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 av_always_inline int filter_slice_rgba_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs, int have_alpha, int pl)
static void preservel(float *r, float *g, float *b, float lin, float lout)
static av_cold void uninit(AVFilterContext *ctx)
static int filter_slice_gbrap10_pl(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int config_output(AVFilterLink *outlink)
static int filter_slice_gbrap16_pl(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_slice_gbrp_pl(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_slice_gbrp16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_slice_rgba(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_slice_gbrp14(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_slice_gbrp12(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.