92#define OFFSET(x) offsetof(CurvesContext, x)
93#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
133 "0.129/1 0.466/0.498 0.725/0",
134 "0.109/1 0.301/0.498 0.517/0",
135 "0.098/1 0.235/0.498 0.423/0",
138 "0/0 0.25/0.156 0.501/0.501 0.686/0.745 1/1",
139 "0/0 0.25/0.188 0.38/0.501 0.745/0.815 1/0.815",
140 "0/0 0.231/0.094 0.709/0.874 1/1",
150 "0/0.11 0.42/0.51 1/0.95",
152 "0/0.22 0.49/0.44 1/0.8",
173 const int scale = lut_size - 1;
180 point->
x =
av_strtod(p, &p);
if (p && *p) p++;
181 point->
y =
av_strtod(p, &p);
if (p && *p) p++;
182 if (point->
x < 0 || point->
x > 1 || point->
y < 0 || point->
y > 1) {
184 "x and y must be in the [0;1] range.\n", point->
x, point->
y);
189 if ((
int)(last->
x *
scale) >= (
int)(point->
x *
scale)) {
191 "and (%f;%f) are too close from each other or not "
192 "strictly increasing on the x-axis\n",
193 last->
x, last->
y, point->
x, point->
y);
204 if (*points && !(*points)->
next) {
206 "this is unlikely to behave as you expect. You probably want"
207 "at least 2 points.",
208 (*points)->x, (*points)->y);
230#define CLIP(v) (nbits == 8 ? av_clip_uint8(v) : av_clip_uintp2_c(v, nbits))
233 const struct keypoint *points,
int nbits)
236 const struct keypoint *point = points;
238 const int lut_size = 1<<nbits;
239 const int scale = lut_size - 1;
246 for (
i = 0;
i < lut_size;
i++)
252 for (
i = 0;
i < lut_size;
i++)
268 for (point = points; point; point = point->
next) {
270 h[
i] = point->
x - xprev;
277 for (
i = 1;
i < n - 1;
i++) {
278 const double yp = point->
y;
279 const double yc = point->
next->
y;
281 r[
i] = 6 * ((yn-yc)/
h[
i] - (yc-yp)/
h[
i-1]);
291 for (
i = 1;
i < n - 1;
i++) {
298 for (
i = 1;
i < n;
i++) {
300 const double k = den ? 1./den : 1.;
304 for (
i = n - 2;
i >= 0;
i--)
310 for (
i = 0;
i < (int)(point->
x *
scale);
i++)
316 while (point->
next) {
317 const double yc = point->
y;
318 const double yn = point->
next->
y;
321 const double b = (yn-yc)/
h[
i] -
h[
i]*
r[
i]/2. -
h[
i]*(
r[
i+1]-
r[
i])/6.;
322 const double c =
r[
i] / 2.;
323 const double d = (
r[
i+1] -
r[
i]) / (6.*
h[
i]);
326 const int x_start = point->
x *
scale;
329 av_assert0(x_start >= 0 && x_start < lut_size &&
330 x_end >= 0 && x_end < lut_size);
332 for (
x = x_start;
x <= x_end;
x++) {
333 const double xx = (
x - x_start) * 1./
scale;
334 const double yy =
a +
b*xx +
c*xx*xx + d*xx*xx*xx;
344 for (
i = (
int)(point->
x *
scale);
i < lut_size;
i++)
355#define SIGN(x) (x > 0.0 ? 1 : x < 0.0 ? -1 : 0)
376 d = ((2 *
h0 + h1) * m0 -
h0 * m1) / (
h0 + h1);
382 else if (mask2) d = 3.0 * m0;
413 for (
int i = 0;
i < n;
i++) smk[
i] =
SIGN(mk[
i]);
416 for (
int i = 0;
i < m;
i++) {
417 int8_t condition = (smk[
i + 1] != smk[
i]) || (mk[
i + 1] == 0) || (mk[
i] == 0);
421 double w1 = 2 * hk[
i + 1] + hk[
i];
422 double w2 = hk[
i + 1] + 2 * hk[
i];
423 dk[
i + 1] = (w1 + w2) / (w1 / mk[
i] + w2 / mk[
i + 1]);
447 double x2 =
x *
x, x3 = x2 *
x;
448 return f * (3.0 * x2 - 2.0 * x3) + d * (x3 - x2);
466 const struct keypoint *points,
int nbits)
468 const struct keypoint *point = points;
469 const int lut_size = 1<<nbits;
471 double *
xi, *fi, *di, *hi, *
mi;
472 const int scale = lut_size - 1;
479 for (
int i = 0;
i < lut_size;
i++)
y[
i] =
i;
486 for (
int i = 0;
i < lut_size;
i++)
y[
i] = yval;
502 for (
int i = 0;
i < n;
i++) {
509 for (
int i = 0;
i < n - 1;
i++) {
517 const double m =
mi[0],
b = fi[0] -
xi[0]*m;
518 for (
int i = 0;
i < lut_size;
i++)
y[
i] =
CLIP(
i*m +
b);
531 const double xi0 =
xi[0];
532 const double yi0 = fi[0];
533 const uint16_t yval =
CLIP(yi0);
534 for (;
x < xi0;
x++) {
542 for (
int i = 0, x0 =
x;
i < n-1;
i++, x0 =
x) {
543 const double xi0 =
xi[
i];
544 const double xi1 =
xi[
i + 1];
545 const double h = hi[
i];
546 const double f0 = fi[
i];
547 const double f1 = fi[
i + 1];
548 const double d0 = di[
i];
549 const double d1 = di[
i + 1];
552 for (;
x < xi1;
x++) {
553 const double xx = (
x - xi0) /
h;
562 i, x0,
x-1,
y[x0],
y[
x-1]);
567 if (
x &&
x < lut_size) {
569 const double xi1 =
xi[n - 1];
570 const double yi1 = fi[n - 1];
571 const uint16_t yval =
CLIP(yi1);
573 n-1,
x, lut_size - 1, yval);
574 for (;
x &&
x < lut_size;
x++) {
593 static const int comp_ids[] = {3, 0, 1, 2};
601#define READ16(dst) do { \
603 ret = AVERROR_INVALIDDATA; \
606 dst = AV_RB16(buf); \
617 for (n = 0; n < nb_points; n++) {
624 char **
pts = &
curves->comp_points_str[comp_ids[
i]];
628 i, comp_ids[
i], nb_points, *
pts);
644 int lut_size,
void *log_ctx)
648 const double scale = 1. / (lut_size - 1);
649 static const char *
const colors[] = {
"red",
"green",
"blue",
"#404040", };
669 av_bprintf(&buf,
"%s'-' using 1:2 with lines lc '%s' title ''",
670 i ?
", " :
"plot ", colors[
i]);
672 av_bprintf(&buf,
", '-' using 1:2 with points pointtype 3 lc '%s' title ''",
681 for (
x = 0;
x < lut_size;
x++)
686 if (comp_points[
i]) {
687 const struct keypoint *point = comp_points[
i];
697 fwrite(buf.str, 1, buf.len,
f);
708 const char *allp =
curves->comp_points_str_all;
726 curves->parsed_psfile = 1;
730#define SET_COMP_IF_NOT_SET(n, name) do { \
731 if (!pts[n] && curves_presets[curves->preset].name) { \
732 pts[n] = av_strdup(curves_presets[curves->preset].name); \
734 return AVERROR(ENOMEM); \
754 const int direct =
out == in;
755 const int step =
curves->step;
756 const uint8_t
r =
curves->rgba_map[
R];
757 const uint8_t
g =
curves->rgba_map[
G];
758 const uint8_t
b =
curves->rgba_map[
B];
759 const uint8_t
a =
curves->rgba_map[
A];
765 uint16_t *dstp = ( uint16_t *)(
out->data[0] +
y *
out->linesize[0]);
766 const uint16_t *srcp = (
const uint16_t *)(in ->
data[0] +
y * in->
linesize[0]);
768 for (
x = 0;
x < in->
width * step;
x += step) {
772 if (!direct && step == 4)
773 dstp[
x +
a] = srcp[
x +
a];
781 for (
x = 0;
x < in->
width * step;
x += step) {
785 if (!direct && step == 4)
802 const int direct =
out == in;
803 const int step =
curves->step;
804 const uint8_t
r =
curves->rgba_map[
R];
805 const uint8_t
g =
curves->rgba_map[
G];
806 const uint8_t
b =
curves->rgba_map[
B];
807 const uint8_t
a =
curves->rgba_map[
A];
813 uint16_t *dstrp = ( uint16_t *)(
out->data[
r] +
y *
out->linesize[
r]);
814 uint16_t *dstgp = ( uint16_t *)(
out->data[
g] +
y *
out->linesize[
g]);
815 uint16_t *dstbp = ( uint16_t *)(
out->data[
b] +
y *
out->linesize[
b]);
816 uint16_t *dstap = ( uint16_t *)(step == 4 ?
out->data[
a] +
y *
out->linesize[
a] :
NULL);
817 const uint16_t *srcrp = (
const uint16_t *)(in ->
data[
r] +
y * in->
linesize[
r]);
818 const uint16_t *srcgp = (
const uint16_t *)(in ->
data[
g] +
y * in->
linesize[
g]);
819 const uint16_t *srcbp = (
const uint16_t *)(in ->
data[
b] +
y * in->
linesize[
b]);
820 const uint16_t *srcap = (
const uint16_t *)(step == 4 ? in ->
data[
a] +
y * in->
linesize[
a] :
NULL);
826 if (!direct && step == 4)
834 uint8_t *dsta = step == 4 ?
out->data[
a]
839 const uint8_t *srca = step == 4 ? in->
data[
a]
847 if (!direct && step == 4)
850 dstr +=
out->linesize[
r];
851 dstg +=
out->linesize[
g];
852 dstb +=
out->linesize[
b];
857 dsta +=
out->linesize[
a];
899 for (j = 0; j <
curves->lut_size; j++)
905 const struct keypoint *point = comp_points[
i];
962 char *res,
int res_len,
int flags)
967 if (!strcmp(cmd,
"plot")) {
969 }
else if (!strcmp(cmd,
"all") || !strcmp(cmd,
"preset") || !strcmp(cmd,
"psfile") || !strcmp(cmd,
"interp")) {
970 if (!strcmp(cmd,
"psfile"))
971 curves->parsed_psfile = 0;
977 }
else if (!strcmp(cmd,
"red") || !strcmp(cmd,
"r")) {
979 }
else if (!strcmp(cmd,
"green") || !strcmp(cmd,
"g")) {
981 }
else if (!strcmp(cmd,
"blue") || !strcmp(cmd,
"b")) {
983 }
else if (!strcmp(cmd,
"master") || !strcmp(cmd,
"m")) {
1018 .p.priv_class = &curves_class,
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static double val(void *priv, double ch)
static int config_input(AVFilterLink *inlink)
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
const FFFilter ff_vf_curves
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
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_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Main libavfilter public API header.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define AV_BPRINT_SIZE_UNLIMITED
#define AV_BPRINT_SIZE_AUTOMATIC
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
#define xi(width, name, var, range_min, range_max, subs,...)
static __device__ float fabs(float a)
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
int(* init)(AVBSFContext *ctx)
double av_strtod(const char *numstr, char **tail)
Parse the string in numstr and return its value as a double.
simple arithmetic expression evaluator
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
#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_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
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.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_log_get_level(void)
Get the current log level.
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
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 FILTER_PIXFMTS(...)
#define AVFILTER_DEFINE_CLASS(fname)
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, int log_offset, void *log_ctx)
Read the file with name filename, and put its content in a newly allocated buffer or map it with mmap...
FILE * avpriv_fopen_utf8(const char *path, const char *mode)
Open a file using a UTF-8 filename.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static const uint16_t mask[17]
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
static int slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output)
Handle slice ends.
int av_get_padded_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel for the pixel format described by pixdesc, including any padding ...
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
#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
@ 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
#define FF_ARRAY_ELEMS(a)
static const float h0[64]
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 * dst
dest filter
int format
agreed upon media format
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
char * comp_points_str_all
uint16_t * graph[NB_COMP+1]
char * comp_points_str[NB_COMP+1]
int(* filter_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Used for passing data between threads.
static AVFormatContext * ctx
static int pchip_find_derivatives(const int n, const double *hk, const double *mk, double *dk)
Evalaute the piecewise polynomial derivatives at endpoints.
static int interpolate(void *log_ctx, uint16_t *y, const struct keypoint *points, int nbits)
static double pchip_edge_case(double h0, double h1, double m0, double m1)
Evalaute the derivative of an edge endpoint.
static int parse_points_str(AVFilterContext *ctx, struct keypoint **points, const char *s, int lut_size)
static double interp_cubic_hermite_half(const double x, const double f, const double d)
Evalaute half of the cubic hermite interpolation expression, wrt one interval endpoint.
static av_cold int curves_init(AVFilterContext *ctx)
static int dump_curves(const char *fname, uint16_t *graph[NB_COMP+1], struct keypoint *comp_points[NB_COMP+1], int lut_size, void *log_ctx)
static struct keypoint * make_point(double x, double y, struct keypoint *next)
static int filter_slice_packed(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int get_nb_points(const struct keypoint *d)
static int config_input(AVFilterLink *inlink)
static int filter_slice_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
@ PRESET_INCREASE_CONTRAST
static const struct @360350104051211213322115217272171043060164323034 curves_presets[]
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static int parse_psfile(AVFilterContext *ctx, const char *fname)
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
#define CLIP(v)
Natural cubic spline interpolation Finding curves using Cubic Splines notes by Steven Rauch and John ...
static const AVFilterPad curves_inputs[]
static const AVOption curves_options[]
static int interpolate_pchip(void *log_ctx, uint16_t *y, const struct keypoint *points, int nbits)
Prepare the lookup table by piecewise monotonic cubic interpolation (PCHIP)
#define SET_COMP_IF_NOT_SET(n, name)
static av_cold void curves_uninit(AVFilterContext *ctx)
static const Curve curves[]
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)