Go to the documentation of this file.
36 typedef struct Range {
55 #define OFFSET(x) offsetof(ColorLevelsContext, x)
56 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
101 #define DO_COMMON(type, clip, preserve) \
102 ColorLevelsContext *s = ctx->priv; \
103 const ThreadData *td = arg; \
104 const int linesize = s->linesize; \
105 const int step = s->step; \
106 const int process_h = td->h; \
107 const int slice_start = (process_h * jobnr ) / nb_jobs; \
108 const int slice_end = (process_h * (jobnr+1)) / nb_jobs; \
109 const int src_linesize = td->src_linesize / sizeof(type); \
110 const int dst_linesize = td->dst_linesize / sizeof(type); \
111 const type *srcrow = (const type *)td->srcrow + src_linesize * slice_start; \
112 type *dstrow = (type *)td->dstrow + dst_linesize * slice_start; \
113 const uint8_t offset_r = s->rgba_map[R]; \
114 const uint8_t offset_g = s->rgba_map[G]; \
115 const uint8_t offset_b = s->rgba_map[B]; \
116 const uint8_t offset_a = s->rgba_map[A]; \
117 const int imin_r = td->imin[R]; \
118 const int imin_g = td->imin[G]; \
119 const int imin_b = td->imin[B]; \
120 const int imin_a = td->imin[A]; \
121 const int omin_r = td->omin[R]; \
122 const int omin_g = td->omin[G]; \
123 const int omin_b = td->omin[B]; \
124 const int omin_a = td->omin[A]; \
125 const float coeff_r = td->coeff[R]; \
126 const float coeff_g = td->coeff[G]; \
127 const float coeff_b = td->coeff[B]; \
128 const float coeff_a = td->coeff[A]; \
129 const type *src_r = srcrow + offset_r; \
130 const type *src_g = srcrow + offset_g; \
131 const type *src_b = srcrow + offset_b; \
132 const type *src_a = srcrow + offset_a; \
133 type *dst_r = dstrow + offset_r; \
134 type *dst_g = dstrow + offset_g; \
135 type *dst_b = dstrow + offset_b; \
136 type *dst_a = dstrow + offset_a; \
138 for (int y = slice_start; y < slice_end; y++) { \
139 for (int x = 0; x < linesize; x += step) { \
140 int ir, ig, ib, or, og, ob; \
145 float ratio, icolor, ocolor, max = (1<<(8*sizeof(type)))-1; \
147 or = (ir - imin_r) * coeff_r + omin_r; \
148 og = (ig - imin_g) * coeff_g + omin_g; \
149 ob = (ib - imin_b) * coeff_b + omin_b; \
151 preserve_color(s->preserve_color, ir, ig, ib, or, og, ob, max, \
153 if (ocolor > 0.f) { \
154 ratio = icolor / ocolor; \
161 dst_r[x] = clip(or); \
162 dst_g[x] = clip(og); \
163 dst_b[x] = clip(ob); \
165 dst_r[x] = clip((ir - imin_r) * coeff_r + omin_r); \
166 dst_g[x] = clip((ig - imin_g) * coeff_g + omin_g); \
167 dst_b[x] = clip((ib - imin_b) * coeff_b + omin_b); \
171 for (int x = 0; x < linesize && s->nb_comp == 4; x += step) \
172 dst_a[x] = clip((src_a[x] - imin_a) * coeff_a + omin_a); \
174 src_r += src_linesize; \
175 src_g += src_linesize; \
176 src_b += src_linesize; \
177 src_a += src_linesize; \
179 dst_r += dst_linesize; \
180 dst_g += dst_linesize; \
181 dst_b += dst_linesize; \
182 dst_a += dst_linesize; \
219 s->nb_comp =
desc->nb_components;
220 s->bpp =
desc->comp[0].depth >> 3;
240 const int step =
s->step;
256 td.dst_linesize =
out->linesize[0];
259 td.dstrow =
out->data[0];
263 for (
int i = 0;
i <
s->nb_comp;
i++) {
265 const uint8_t
offset =
s->rgba_map[
i];
266 const uint8_t *srcrow = in->
data[0];
267 int imin =
lrint(
r->in_min * UINT8_MAX);
268 int imax =
lrint(
r->in_max * UINT8_MAX);
269 int omin =
lrint(
r->out_min * UINT8_MAX);
270 int omax =
lrint(
r->out_max * UINT8_MAX);
275 for (
int y = 0; y <
inlink->h; y++) {
276 const uint8_t *
src = srcrow;
278 for (
int x = 0; x <
s->linesize; x +=
step)
284 srcrow = in->
data[0];
286 for (
int y = 0; y <
inlink->h; y++) {
287 const uint8_t *
src = srcrow;
289 for (
int x = 0; x <
s->linesize; x +=
step)
295 coeff = (omax - omin) / (
double)(imax - imin);
303 for (
int i = 0;
i <
s->nb_comp;
i++) {
305 const uint8_t
offset =
s->rgba_map[
i];
306 const uint8_t *srcrow = in->
data[0];
307 int imin =
lrint(
r->in_min * UINT16_MAX);
308 int imax =
lrint(
r->in_max * UINT16_MAX);
309 int omin =
lrint(
r->out_min * UINT16_MAX);
310 int omax =
lrint(
r->out_max * UINT16_MAX);
315 for (
int y = 0; y <
inlink->h; y++) {
316 const uint16_t *
src = (
const uint16_t *)srcrow;
318 for (
int x = 0; x <
s->linesize; x +=
step)
324 srcrow = in->
data[0];
326 for (
int y = 0; y <
inlink->h; y++) {
327 const uint16_t *
src = (
const uint16_t *)srcrow;
329 for (
int x = 0; x <
s->linesize; x +=
step)
335 coeff = (omax - omin) / (
double)(imax - imin);
369 .
name =
"colorlevels",
372 .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.
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_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.
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)
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
const char * name
Filter name.
A link between two filters.
static int config_input(AVFilterLink *inlink)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
const AVFilter ff_vf_colorlevels
A filter pad used for either input or output.
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)
#define FILTER_INPUTS(array)
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
#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.
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
@ 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(...)
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
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.
@ 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 DO_COMMON(type, clip, preserve)
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
#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 av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)