Go to the documentation of this file.
36 typedef struct Range {
58 #define OFFSET(x) offsetof(ColorLevelsContext, x)
59 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
106 #define DO_COMMON(type, ptype, clip, preserve, planar) \
107 const ThreadData *td = arg; \
108 const int linesize = s->linesize; \
109 const int step = s->step; \
110 const int process_h = td->h; \
111 const int slice_start = (process_h * jobnr ) / nb_jobs; \
112 const int slice_end = (process_h * (jobnr+1)) / nb_jobs; \
113 const int src_linesize = td->src_linesize / sizeof(type); \
114 const int dst_linesize = td->dst_linesize / sizeof(type); \
115 const type *src_r = (const type *)(td->srcrow[R]) + src_linesize * slice_start; \
116 const type *src_g = (const type *)(td->srcrow[G]) + src_linesize * slice_start; \
117 const type *src_b = (const type *)(td->srcrow[B]) + src_linesize * slice_start; \
118 const type *src_a = (const type *)(td->srcrow[A]) + src_linesize * slice_start; \
119 type *dst_r = (type *)(td->dstrow[R]) + src_linesize * slice_start; \
120 type *dst_g = (type *)(td->dstrow[G]) + src_linesize * slice_start; \
121 type *dst_b = (type *)(td->dstrow[B]) + src_linesize * slice_start; \
122 type *dst_a = (type *)(td->dstrow[A]) + src_linesize * slice_start; \
123 const ptype imin_r = s->depth == 32 ? td->fimin[R] : td->imin[R]; \
124 const ptype imin_g = s->depth == 32 ? td->fimin[G] : td->imin[G]; \
125 const ptype imin_b = s->depth == 32 ? td->fimin[B] : td->imin[B]; \
126 const ptype imin_a = s->depth == 32 ? td->fimin[A] : td->imin[A]; \
127 const ptype omin_r = s->depth == 32 ? td->fomin[R] : td->omin[R]; \
128 const ptype omin_g = s->depth == 32 ? td->fomin[G] : td->omin[G]; \
129 const ptype omin_b = s->depth == 32 ? td->fomin[B] : td->omin[B]; \
130 const ptype omin_a = s->depth == 32 ? td->fomin[A] : td->omin[A]; \
131 const float coeff_r = td->coeff[R]; \
132 const float coeff_g = td->coeff[G]; \
133 const float coeff_b = td->coeff[B]; \
134 const float coeff_a = td->coeff[A]; \
136 for (int y = slice_start; y < slice_end; y++) { \
137 for (int x = 0; x < linesize; x += step) { \
138 ptype ir, ig, ib, or, og, ob; \
143 float ratio, icolor, ocolor, max = s->depth==32 ? 1.f : s->max; \
145 or = (ir - imin_r) * coeff_r + omin_r; \
146 og = (ig - imin_g) * coeff_g + omin_g; \
147 ob = (ib - imin_b) * coeff_b + omin_b; \
149 preserve_color(s->preserve_color, ir, ig, ib, or, og, ob, max, \
151 if (ocolor > 0.f) { \
152 ratio = icolor / ocolor; \
159 dst_r[x] = clip(or, depth); \
160 dst_g[x] = clip(og, depth); \
161 dst_b[x] = clip(ob, depth); \
163 dst_r[x] = clip((ir - imin_r) * coeff_r + omin_r, depth); \
164 dst_g[x] = clip((ig - imin_g) * coeff_g + omin_g, depth); \
165 dst_b[x] = clip((ib - imin_b) * coeff_b + omin_b, depth); \
169 for (int x = 0; x < linesize && s->nb_comp == 4; x += step) \
170 dst_a[x] = clip((src_a[x] - imin_a) * coeff_a + omin_a, depth); \
172 src_r += src_linesize; \
173 src_g += src_linesize; \
174 src_b += src_linesize; \
175 src_a += src_linesize; \
177 dst_r += dst_linesize; \
178 dst_g += dst_linesize; \
179 dst_b += dst_linesize; \
180 dst_a += dst_linesize; \
183 #define CLIP8(x, depth) av_clip_uint8(x)
184 #define CLIP16(x, depth) av_clip_uint16(x)
185 #define NOCLIP(x, depth) (x)
197 DO_COMMON(uint16_t,
int,
CLIP16, 0, 0)
233 const int depth = 10;
241 const int depth = 12;
249 const int depth = 14;
286 const int depth = 10;
294 const int depth = 12;
302 const int depth = 14;
327 s->nb_comp =
desc->nb_components;
329 s->depth =
desc->comp[0].depth;
330 s->max = (1 <<
s->depth) - 1;
331 s->bpp = (
desc->comp[0].depth + 7) >> 3;
384 const int step =
s->step;
400 td.dst_linesize =
out->linesize[0];
404 td.dstrow[
R] =
out->data[2];
406 td.dstrow[
G] =
out->data[0];
408 td.dstrow[
B] =
out->data[1];
410 td.dstrow[
A] =
out->data[3];
412 td.srcrow[
R] = in->
data[0] +
s->rgba_map[
R] *
s->bpp;
413 td.dstrow[
R] =
out->data[0] +
s->rgba_map[
R] *
s->bpp;
414 td.srcrow[
G] = in->
data[0] +
s->rgba_map[
G] *
s->bpp;
415 td.dstrow[
G] =
out->data[0] +
s->rgba_map[
G] *
s->bpp;
416 td.srcrow[
B] = in->
data[0] +
s->rgba_map[
B] *
s->bpp;
417 td.dstrow[
B] =
out->data[0] +
s->rgba_map[
B] *
s->bpp;
418 td.srcrow[
A] = in->
data[0] +
s->rgba_map[
A] *
s->bpp;
419 td.dstrow[
A] =
out->data[0] +
s->rgba_map[
A] *
s->bpp;
424 for (
int i = 0;
i <
s->nb_comp;
i++) {
426 const uint8_t
offset =
s->rgba_map[
i];
427 const uint8_t *srcrow = in->
data[0];
428 int imin =
lrint(
r->in_min * UINT8_MAX);
429 int imax =
lrint(
r->in_max * UINT8_MAX);
430 int omin =
lrint(
r->out_min * UINT8_MAX);
431 int omax =
lrint(
r->out_max * UINT8_MAX);
436 for (
int y = 0; y <
inlink->h; y++) {
437 const uint8_t *
src = srcrow;
439 for (
int x = 0; x <
s->linesize; x +=
step)
445 srcrow = in->
data[0];
447 for (
int y = 0; y <
inlink->h; y++) {
448 const uint8_t *
src = srcrow;
450 for (
int x = 0; x <
s->linesize; x +=
step)
456 coeff = (omax - omin) / (
double)(imax - imin);
464 for (
int i = 0;
i <
s->nb_comp;
i++) {
466 const uint8_t
offset =
s->rgba_map[
i];
467 const uint8_t *srcrow = in->
data[0];
468 int imin =
lrint(
r->in_min * UINT16_MAX);
469 int imax =
lrint(
r->in_max * UINT16_MAX);
470 int omin =
lrint(
r->out_min * UINT16_MAX);
471 int omax =
lrint(
r->out_max * UINT16_MAX);
476 for (
int y = 0; y <
inlink->h; y++) {
477 const uint16_t *
src = (
const uint16_t *)srcrow;
479 for (
int x = 0; x <
s->linesize; x +=
step)
485 srcrow = in->
data[0];
487 for (
int y = 0; y <
inlink->h; y++) {
488 const uint16_t *
src = (
const uint16_t *)srcrow;
490 for (
int x = 0; x <
s->linesize; x +=
step)
496 coeff = (omax - omin) / (
double)(imax - imin);
504 for (
int i = 0;
i <
s->nb_comp;
i++) {
506 const uint8_t
offset =
s->rgba_map[
i];
507 const uint8_t *srcrow = in->
data[0];
508 float imin =
r->in_min;
509 float imax =
r->in_max;
510 float omin =
r->out_min;
511 float omax =
r->out_max;
516 for (
int y = 0; y <
inlink->h; y++) {
517 const float *
src = (
const float *)srcrow;
519 for (
int x = 0; x <
s->linesize; x +=
step)
525 srcrow = in->
data[0];
527 for (
int y = 0; y <
inlink->h; y++) {
528 const float *
src = (
const float *)srcrow;
530 for (
int x = 0; x <
s->linesize; x +=
step)
536 coeff = (omax - omin) / (
double)(imax - imin);
570 .
name =
"colorlevels",
573 .priv_class = &colorlevels_class,
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
static int colorlevels_slice_8_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
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
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)
static int colorlevels_slice_16_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int colorlevels_preserve_slice_16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
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
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
const uint8_t * srcrow[4]
This structure describes decoded (raw) audio or video data.
static const AVFilterPad colorlevels_inputs[]
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 void preserve_color(int preserve_color, float ir, float ig, float ib, float r, float g, float b, float max, float *icolor, float *ocolor)
static int colorlevels_slice_32_planar(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...
static int colorlevels_slice_9_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
const char * name
Filter name.
A link between two filters.
static int colorlevels_preserve_slice_12_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int config_input(AVFilterLink *inlink)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
const AVFilter ff_vf_colorlevels
#define AV_PIX_FMT_GBRP14
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
#define AV_PIX_FMT_GBRP10
static int colorlevels_preserve_slice_8_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
A filter pad used for either input or output.
static int colorlevels_slice_10_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP12
static int colorlevels_preserve_slice_8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int colorlevels_slice_16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
float fminf(float, float)
static int colorlevels_preserve_slice_14_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define FILTER_INPUTS(array)
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
#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 colorlevels_preserve_slice_16_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
static int colorlevels_preserve_slice_32_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
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 FILTER_PIXFMTS(...)
float fmaxf(float, float)
#define AV_PIX_FMT_GBRPF32
#define DO_COMMON(type, ptype, clip, preserve, planar)
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
AVFILTER_DEFINE_CLASS(colorlevels)
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.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
@ 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...
static int colorlevels_slice_8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AV_PIX_FMT_BGRA64
#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 int colorlevels_preserve_slice_9_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
static const AVFilterPad colorlevels_outputs[]
int(* colorlevels_slice[2])(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
int h
agreed upon image height
static const AVOption colorlevels_options[]
#define AV_PIX_FMT_GBRAPF32
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
@ 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 colorlevels_slice_12_planar(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...
static int colorlevels_preserve_slice_10_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define FILTER_OUTPUTS(array)
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
static const double coeff[2][5]
static int colorlevels_slice_14_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)