79 #define OFFSET(x) offsetof(CurvesContext, x)
80 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
110 static const struct {
117 "0.129/1 0.466/0.498 0.725/0",
118 "0.109/1 0.301/0.498 0.517/0",
119 "0.098/1 0.235/0.498 0.423/0",
122 "0/0 0.25/0.156 0.501/0.501 0.686/0.745 1/1",
123 "0/0 0.25/0.188 0.38/0.501 0.745/0.815 1/0.815",
124 "0/0 0.231/0.094 0.709/0.874 1/1",
134 "0/0.11 0.42/0.51 1/0.95",
136 "0/0.22 0.49/0.44 1/0.8",
157 const int scale = lut_size - 1;
164 point->
x =
av_strtod(p, &p);
if (p && *p) p++;
165 point->
y =
av_strtod(p, &p);
if (p && *p) p++;
166 if (point->
x < 0 || point->
x > 1 || point->
y < 0 || point->
y > 1) {
168 "x and y must be in the [0;1] range.\n", point->
x, point->
y);
174 if ((
int)(last->
x * scale) >= (
int)(point->
x * scale)) {
176 "and (%f;%f) are too close from each other or not "
177 "strictly increasing on the x-axis\n",
178 last->
x, last->
y, point->
x, point->
y);
186 if (*points && !(*points)->
next) {
188 "this is unlikely to behave as you expect. You probably want"
189 "at least 2 points.",
190 (*points)->x, (*points)->y);
212 #define CLIP(v) (nbits == 8 ? av_clip_uint8(v) : av_clip_uint16(v))
215 const struct keypoint *points,
int nbits)
218 const struct keypoint *point = points;
220 const int lut_size = 1<<nbits;
221 const int scale = lut_size - 1;
228 for (i = 0; i < lut_size; i++)
234 for (i = 0; i < lut_size; i++)
235 y[i] =
CLIP(point->
y * scale);
243 if (!matrix || !h || !r) {
250 for (point = points; point; point = point->
next) {
252 h[i] = point->
x - xprev;
259 for (i = 1; i < n - 1; i++) {
260 const double yp = point->
y;
261 const double yc = point->
next->
y;
263 r[i] = 6 * ((yn-yc)/h[i] - (yc-yp)/h[i-1]);
272 matrix[0][
MD] = matrix[n - 1][
MD] = 1;
273 for (i = 1; i < n - 1; i++) {
274 matrix[i][
BD] = h[i-1];
275 matrix[i][
MD] = 2 * (h[i-1] + h[i]);
276 matrix[i][
AD] = h[i];
280 for (i = 1; i <
n; i++) {
281 const double den = matrix[i][
MD] - matrix[i][
BD] * matrix[i-1][
AD];
282 const double k = den ? 1./den : 1.;
284 r[i] = (r[i] - matrix[i][
BD] * r[i - 1]) * k;
286 for (i = n - 2; i >= 0; i--)
287 r[i] = r[i] - matrix[i][
AD] * r[i + 1];
292 for (i = 0; i < (
int)(point->
x * scale); i++)
293 y[i] =
CLIP(point->
y * scale);
298 while (point->
next) {
299 const double yc = point->
y;
300 const double yn = point->
next->
y;
303 const double b = (yn-yc)/h[i] - h[i]*r[i]/2. - h[i]*(r[i+1]-r[i])/6.;
304 const double c = r[i] / 2.;
305 const double d = (r[i+1] - r[i]) / (6.*h[i]);
308 const int x_start = point->
x * scale;
309 const int x_end = point->
next->
x * scale;
311 av_assert0(x_start >= 0 && x_start < lut_size &&
312 x_end >= 0 && x_end < lut_size);
314 for (x = x_start; x <= x_end; x++) {
315 const double xx = (x - x_start) * 1./scale;
316 const double yy = a + b*xx + c*xx*xx + d*xx*xx*xx;
317 y[
x] =
CLIP(yy * scale);
326 for (i = (
int)(point->
x * scale); i < lut_size; i++)
327 y[i] =
CLIP(point->
y * scale);
336 #define DECLARE_INTERPOLATE_FUNC(nbits) \
337 static int interpolate##nbits(void *log_ctx, uint16_t *y, \
338 const struct keypoint *points) \
340 return interpolate(log_ctx, y, points, nbits); \
353 static const int comp_ids[] = {3, 0, 1, 2};
361 #define READ16(dst) do { \
363 ret = AVERROR_INVALIDDATA; \
366 dst = AV_RB16(buf); \
377 for (n = 0; n < nb_points; n++) {
381 av_bprintf(&ptstr,
"%f/%f ", x / 255., y / 255.);
388 i, comp_ids[i], nb_points, *pts);
408 const double scale = 1. / (lut_size - 1);
409 static const char *
const colors[] = {
"red",
"green",
"blue",
"#404040", };
429 av_bprintf(&buf,
"%s'-' using 1:2 with lines lc '%s' title ''",
430 i ?
", " :
"plot ", colors[i]);
432 av_bprintf(&buf,
", '-' using 1:2 with points pointtype 3 lc '%s' title ''",
441 for (x = 0; x < lut_size; x++)
442 av_bprintf(&buf,
"%f %f\n", x * scale, graph[i][x] * scale);
446 if (comp_points[i]) {
447 const struct keypoint *point = comp_points[i];
457 fwrite(buf.str, 1, buf.len, f);
474 for (i = 0; i <
NB_COMP; i++) {
489 #define SET_COMP_IF_NOT_SET(n, name) do { \
490 if (!pts[n] && curves_presets[curves->preset].name) { \
491 pts[n] = av_strdup(curves_presets[curves->preset].name); \
493 return AVERROR(ENOMEM); \
537 for (i = 0; i <
NB_COMP + 1; i++) {
539 if (!curves->
graph[i])
544 if (curves->
is_16bit) ret = interpolate16(ctx, curves->
graph[i], comp_points[i]);
545 else ret = interpolate8(ctx, curves->
graph[i], comp_points[i]);
552 for (j = 0; j < curves->
lut_size; j++)
557 for (i = 0; i <
NB_COMP; i++) {
558 const struct keypoint *point = comp_points[i];
570 for (i = 0; i < NB_COMP + 1; i++) {
571 struct keypoint *point = comp_points[i];
589 const int direct = out ==
in;
590 const int step = curves->
step;
595 const int slice_start = (in->
height * jobnr ) / nb_jobs;
599 for (y = slice_start; y <
slice_end; y++) {
601 const uint16_t *
srcp = (
const uint16_t *)(in ->
data[0] + y * in->
linesize[0]);
603 for (x = 0; x < in->
width * step; x += step) {
604 dstp[x +
r] = curves->
graph[
R][srcp[x +
r]];
605 dstp[x +
g] = curves->
graph[
G][srcp[x +
g]];
606 dstp[x +
b] = curves->
graph[
B][srcp[x +
b]];
607 if (!direct && step == 4)
608 dstp[x +
a] = srcp[x +
a];
615 for (y = slice_start; y <
slice_end; y++) {
616 for (x = 0; x < in->
width * step; x += step) {
617 dst[x +
r] = curves->
graph[
R][src[x +
r]];
618 dst[x +
g] = curves->
graph[
G][src[x +
g]];
619 dst[x +
b] = curves->
graph[
B][src[x +
b]];
620 if (!direct && step == 4)
621 dst[x +
a] = src[x +
a];
663 for (i = 0; i <
NB_COMP + 1; i++)
694 .priv_class = &curves_class,
void av_bprintf(AVBPrint *buf, const char *fmt,...)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
#define AV_LOG_WARNING
Something somehow does not look correct.
Main libavfilter public API header.
packed RGB 8:8:8, 24bpp, RGBRGB...
static av_cold int init(AVCodecContext *avctx)
#define AV_PIX_FMT_RGBA64
int h
agreed upon image height
FILE * av_fopen_utf8(const char *path, const char *mode)
Open a file using a UTF-8 filename.
#define CLIP(v)
Natural cubic spline interpolation Finding curves using Cubic Splines notes by Steven Rauch and John ...
static struct keypoint * make_point(double x, double y, struct keypoint *next)
#define AV_PIX_FMT_BGRA64
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
BYTE int const BYTE * srcp
const char * name
Pad name.
#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.
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
static const AVOption curves_options[]
static av_cold int uninit(AVCodecContext *avctx)
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
static av_cold int end(AVCodecContext *avctx)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
static av_cold int curves_init(AVFilterContext *ctx)
#define AV_LOG_VERBOSE
Detailed information.
static int parse_points_str(AVFilterContext *ctx, struct keypoint **points, const char *s, int lut_size)
char * comp_points_str_all
A filter pad used for either input or output.
A link between two filters.
#define SET_COMP_IF_NOT_SET(n, name)
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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...
#define AV_BPRINT_SIZE_UNLIMITED
#define DECLARE_INTERPOLATE_FUNC(nbits)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
void * priv
private data for use by the filter
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 ...
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
simple assert() macros that are a bit more flexible than ISO C assert().
int av_log_get_level(void)
Get the current log level.
static void * av_mallocz_array(size_t nmemb, size_t size)
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
static int config_input(AVFilterLink *inlink)
int w
agreed upon image width
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
char * comp_points_str[NB_COMP+1]
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
packed RGB 8:8:8, 24bpp, BGRBGR...
static const AVFilterPad outputs[]
int format
agreed upon media format
#define FF_ARRAY_ELEMS(a)
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
double av_strtod(const char *numstr, char **tail)
Parse the string in numstr and return its value as a double.
static const AVFilterPad inputs[]
#define AV_BPRINT_SIZE_AUTOMATIC
char * av_strdup(const char *s)
Duplicate a string.
static int parse_psfile(AVFilterContext *ctx, const char *fname)
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
static int dump_curves(const char *fname, uint16_t *graph[NB_COMP+1], struct keypoint *comp_points[NB_COMP+1], int lut_size)
static const struct @179 curves_presets[]
static int get_nb_points(const struct keypoint *d)
Describe the class of an AVClass context structure.
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
const char * name
Filter name.
static const AVFilterPad curves_inputs[]
AVFilterLink ** outputs
array of pointers to output links
static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static enum AVPixelFormat pix_fmts[]
static int64_t pts
Global timestamp for the audio frames.
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
AVFILTER_DEFINE_CLASS(curves)
uint16_t * graph[NB_COMP+1]
avfilter_execute_func * execute
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
AVFilterContext * dst
dest filter
static int query_formats(AVFilterContext *ctx)
static int interpolate(void *log_ctx, uint16_t *y, const struct keypoint *points, int nbits)
int depth
Number of bits in the component.
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
static av_cold void curves_uninit(AVFilterContext *ctx)
AVPixelFormat
Pixel format.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
static const AVFilterPad curves_outputs[]
simple arithmetic expression evaluator