58 #define OFFSET(x) offsetof(ColorChannelMixerContext, x)
59 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
111 return v0 + (v1 -
v0) *
f;
114 static void preservel(
float *
r,
float *
g,
float *
b,
float lin,
float lout)
122 int have_alpha,
int pl)
128 const float l =
s->preserve_lightness;
129 const float sr =
s->sr;
130 const float sg =
s->sg;
131 const float sb =
s->sb;
132 const int slice_start = (
out->height * jobnr) / nb_jobs;
133 const int slice_end = (
out->height * (jobnr+1)) / nb_jobs;
134 const uint8_t *srcg =
in->data[0] + slice_start *
in->linesize[0];
135 const uint8_t *srcb =
in->data[1] + slice_start *
in->linesize[1];
136 const uint8_t *srcr =
in->data[2] + slice_start *
in->linesize[2];
137 const uint8_t *srca =
in->data[3] + slice_start *
in->linesize[3];
138 uint8_t *dstg =
out->data[0] + slice_start *
out->linesize[0];
139 uint8_t *dstb =
out->data[1] + slice_start *
out->linesize[1];
140 uint8_t *dstr =
out->data[2] + slice_start *
out->linesize[2];
141 uint8_t *dsta =
out->data[3] + slice_start *
out->linesize[3];
145 for (j = 0; j <
out->width; j++) {
149 const uint8_t ain = have_alpha ? srca[j] : 0;
150 int rout, gout, bout;
156 rout =
s->lut[
R][
R][rin] +
159 (have_alpha == 1 ?
s->lut[
R][
A][ain] : 0);
160 gout =
s->lut[
G][
R][rin] +
163 (have_alpha == 1 ?
s->lut[
G][
A][ain] : 0);
164 bout =
s->lut[
B][
R][rin] +
167 (have_alpha == 1 ?
s->lut[
B][
A][ain] : 0);
170 float frout = rout / sr;
171 float fgout = gout / sg;
172 float fbout = bout / sb;
173 float lout =
FFMAX3(frout, fgout, fbout) +
FFMIN3(frout, fgout, fbout);
175 preservel(&frout, &fgout, &fbout, lin, lout);
186 if (have_alpha == 1) {
194 srcg +=
in->linesize[0];
195 srcb +=
in->linesize[1];
196 srcr +=
in->linesize[2];
197 srca +=
in->linesize[3];
198 dstg +=
out->linesize[0];
199 dstb +=
out->linesize[1];
200 dstr +=
out->linesize[2];
201 dsta +=
out->linesize[3];
208 int have_alpha,
int depth,
int pl)
214 const float l =
s->preserve_lightness;
215 const float sr =
s->sr;
216 const float sg =
s->sg;
217 const float sb =
s->sb;
218 const int slice_start = (
out->height * jobnr) / nb_jobs;
219 const int slice_end = (
out->height * (jobnr+1)) / nb_jobs;
220 const uint16_t *srcg = (
const uint16_t *)(
in->data[0] + slice_start *
in->linesize[0]);
221 const uint16_t *srcb = (
const uint16_t *)(
in->data[1] + slice_start *
in->linesize[1]);
222 const uint16_t *srcr = (
const uint16_t *)(
in->data[2] + slice_start *
in->linesize[2]);
223 const uint16_t *srca = (
const uint16_t *)(
in->data[3] + slice_start *
in->linesize[3]);
224 uint16_t *dstg = (uint16_t *)(
out->data[0] + slice_start *
out->linesize[0]);
225 uint16_t *dstb = (uint16_t *)(
out->data[1] + slice_start *
out->linesize[1]);
226 uint16_t *dstr = (uint16_t *)(
out->data[2] + slice_start *
out->linesize[2]);
227 uint16_t *dsta = (uint16_t *)(
out->data[3] + slice_start *
out->linesize[3]);
231 for (j = 0; j <
out->width; j++) {
232 const uint16_t rin = srcr[j];
233 const uint16_t gin = srcg[j];
234 const uint16_t bin = srcb[j];
235 const uint16_t ain = have_alpha ? srca[j] : 0;
236 int rout, gout, bout;
242 rout =
s->lut[
R][
R][rin] +
245 (have_alpha == 1 ?
s->lut[
R][
A][ain] : 0);
246 gout =
s->lut[
G][
R][rin] +
249 (have_alpha == 1 ?
s->lut[
G][
A][ain] : 0);
250 bout =
s->lut[
B][
R][rin] +
253 (have_alpha == 1 ?
s->lut[
B][
A][ain] : 0);
256 float frout = rout / sr;
257 float fgout = gout / sg;
258 float fbout = bout / sb;
259 float lout =
FFMAX3(frout, fgout, fbout) +
FFMIN3(frout, fgout, fbout);
261 preservel(&frout, &fgout, &fbout, lin, lout);
272 if (have_alpha == 1) {
276 s->lut[
A][
A][ain], depth);
280 srcg +=
in->linesize[0] / 2;
281 srcb +=
in->linesize[1] / 2;
282 srcr +=
in->linesize[2] / 2;
283 srca +=
in->linesize[3] / 2;
284 dstg +=
out->linesize[0] / 2;
285 dstb +=
out->linesize[1] / 2;
286 dstr +=
out->linesize[2] / 2;
287 dsta +=
out->linesize[3] / 2;
394 int have_alpha,
int step,
int pl)
400 const float l =
s->preserve_lightness;
401 const float sr =
s->sr;
402 const float sg =
s->sg;
403 const float sb =
s->sb;
404 const int slice_start = (
out->height * jobnr) / nb_jobs;
405 const int slice_end = (
out->height * (jobnr+1)) / nb_jobs;
410 const uint8_t *srcrow =
in->data[0] + slice_start *
in->linesize[0];
411 uint8_t *dstrow =
out->data[0] + slice_start *
out->linesize[0];
418 for (j = 0; j <
out->width * step; j += step) {
423 int rout, gout, bout;
429 rout =
s->lut[
R][
R][rin] +
432 (have_alpha == 1 ?
s->lut[
R][
A][ain] : 0);
433 gout =
s->lut[
G][
R][rin] +
436 (have_alpha == 1 ?
s->lut[
G][
A][ain] : 0);
437 bout =
s->lut[
B][
R][rin] +
440 (have_alpha == 1 ?
s->lut[
B][
A][ain] : 0);
443 float frout = rout / sr;
444 float fgout = gout / sg;
445 float fbout = bout / sb;
446 float lout =
FFMAX3(frout, fgout, fbout) +
FFMIN3(frout, fgout, fbout);
448 preservel(&frout, &fgout, &fbout, lin, lout);
459 if (have_alpha == 1) {
464 }
else if (have_alpha == -1 &&
in !=
out)
465 dst[j + aoffset] = 0;
468 srcrow +=
in->linesize[0];
469 dstrow +=
out->linesize[0];
476 int have_alpha,
int step,
int pl)
482 const float l =
s->preserve_lightness;
483 const float sr =
s->sr;
484 const float sg =
s->sg;
485 const float sb =
s->sb;
486 const int slice_start = (
out->height * jobnr) / nb_jobs;
487 const int slice_end = (
out->height * (jobnr+1)) / nb_jobs;
492 const uint8_t *srcrow =
in->data[0] + slice_start *
in->linesize[0];
493 uint8_t *dstrow =
out->data[0] + slice_start *
out->linesize[0];
497 const uint16_t *
src = (
const uint16_t *)srcrow;
498 uint16_t *dst = (uint16_t *)dstrow;
500 for (j = 0; j <
out->width * step; j += step) {
501 const uint16_t rin =
src[j + roffset];
502 const uint16_t gin =
src[j + goffset];
503 const uint16_t bin =
src[j + boffset];
504 const uint16_t ain =
src[j + aoffset];
505 int rout, gout, bout;
511 rout =
s->lut[
R][
R][rin] +
514 (have_alpha == 1 ?
s->lut[
R][
A][ain] : 0);
515 gout =
s->lut[
G][
R][rin] +
518 (have_alpha == 1 ?
s->lut[
G][
A][ain] : 0);
519 bout =
s->lut[
B][
R][rin] +
522 (have_alpha == 1 ?
s->lut[
B][
A][ain] : 0);
525 float frout = rout / sr;
526 float fgout = gout / sg;
527 float fbout = bout / sb;
528 float lout =
FFMAX3(frout, fgout, fbout) +
FFMIN3(frout, fgout, fbout);
530 preservel(&frout, &fgout, &fbout, lin, lout);
541 if (have_alpha == 1) {
549 srcrow +=
in->linesize[0];
550 dstrow +=
out->linesize[0];
611 const int depth =
desc->comp[0].depth;
622 for (
i = 0;
i < 4;
i++)
627 s->sr =
s->rr +
s->rg +
s->rb +
s->ra;
628 s->sg =
s->gr +
s->gg +
s->gb +
s->ga;
629 s->sb =
s->br +
s->bg +
s->bb +
s->ba;
631 if (
fabs(
s->sr) <= DBL_EPSILON)
634 if (
fabs(
s->sg) <= DBL_EPSILON)
637 if (
fabs(
s->sb) <= DBL_EPSILON)
662 switch (outlink->
format) {
742 const int pl =
s->preserve_lightness > 0.;
767 char *res,
int res_len,
int flags)
803 .
name =
"colorchannelmixer",
806 .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)
#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.