Go to the documentation of this file.
58 int jobnr,
int nb_jobs);
60 int jobnr,
int nb_jobs);
67 const float imax =
s->imax;
68 const int width =
s->planewidth[1];
69 const int height =
s->planeheight[1];
76 int sum_u = 0, sum_v = 0;
79 for (
int x = 0; x <
width; x++) {
98 const float imax =
s->imax;
99 const int width =
s->planewidth[1];
100 const int height =
s->planeheight[1];
110 for (
int x = 0; x <
width; x++) {
129 const float imax =
s->imax;
130 const int width =
s->planewidth[1];
131 const int height =
s->planeheight[1];
138 int min_u = 255, min_v = 255;
139 int max_u = 0, max_v = 0;
142 for (
int x = 0; x <
width; x++) {
143 min_u =
FFMIN(min_u, uptr[x]);
144 min_v =
FFMIN(min_v, vptr[x]);
145 max_u =
FFMAX(max_u, uptr[x]);
146 max_v =
FFMAX(max_v, vptr[x]);
153 s->analyzeret[jobnr][0] = imax * min_u - 0.5f;
154 s->analyzeret[jobnr][1] = imax * min_v - 0.5f;
155 s->analyzeret[jobnr][2] = imax * max_u - 0.5f;
156 s->analyzeret[jobnr][3] = imax * max_v - 0.5f;
165 const float imax =
s->imax;
166 const int width =
s->planewidth[1];
167 const int height =
s->planeheight[1];
174 int min_u = INT_MAX, min_v = INT_MAX;
175 int max_u = INT_MIN, max_v = INT_MIN;
178 for (
int x = 0; x <
width; x++) {
179 min_u =
FFMIN(min_u, uptr[x]);
180 min_v =
FFMIN(min_v, vptr[x]);
181 max_u =
FFMAX(max_u, uptr[x]);
182 max_v =
FFMAX(max_v, vptr[x]);
189 s->analyzeret[jobnr][0] = imax * min_u - 0.5f;
190 s->analyzeret[jobnr][1] = imax * min_v - 0.5f;
191 s->analyzeret[jobnr][2] = imax * max_u - 0.5f;
192 s->analyzeret[jobnr][3] = imax * max_v - 0.5f;
201 const float imax =
s->imax;
202 const int width =
s->planewidth[1];
203 const int height =
s->planeheight[1];
206 const uint8_t *uptr = (
const uint8_t *)
frame->
data[1];
207 const uint8_t *vptr = (
const uint8_t *)
frame->
data[2];
208 unsigned *uhistogram =
s->uhistogram;
209 unsigned *vhistogram =
s->vhistogram;
211 int umedian =
s->max, vmedian =
s->max;
212 unsigned ucnt = 0, vcnt = 0;
214 memset(uhistogram, 0,
sizeof(*uhistogram) * (
s->max + 1));
215 memset(vhistogram, 0,
sizeof(*vhistogram) * (
s->max + 1));
217 for (
int y = 0; y <
height; y++) {
218 for (
int x = 0; x <
width; x++) {
219 uhistogram[uptr[x]]++;
220 vhistogram[vptr[x]]++;
227 for (
int i = 0;
i <
s->max + 1;
i++) {
228 ucnt += uhistogram[
i];
229 if (ucnt >= half_size) {
235 for (
int i = 0;
i <
s->max + 1;
i++) {
236 vcnt += vhistogram[
i];
237 if (vcnt >= half_size) {
243 s->analyzeret[0][0] = imax * umedian - 0.5f;
244 s->analyzeret[0][1] = imax * vmedian - 0.5f;
245 s->analyzeret[0][2] = imax * umedian - 0.5f;
246 s->analyzeret[0][3] = imax * vmedian - 0.5f;
255 const float imax =
s->imax;
256 const int width =
s->planewidth[1];
257 const int height =
s->planeheight[1];
260 const uint16_t *uptr = (
const uint16_t *)
frame->
data[1];
261 const uint16_t *vptr = (
const uint16_t *)
frame->
data[2];
262 unsigned *uhistogram =
s->uhistogram;
263 unsigned *vhistogram =
s->vhistogram;
265 int umedian =
s->max, vmedian =
s->max;
266 unsigned ucnt = 0, vcnt = 0;
268 memset(uhistogram, 0,
sizeof(*uhistogram) * (
s->max + 1));
269 memset(vhistogram, 0,
sizeof(*vhistogram) * (
s->max + 1));
271 for (
int y = 0; y <
height; y++) {
272 for (
int x = 0; x <
width; x++) {
273 uhistogram[uptr[x]]++;
274 vhistogram[vptr[x]]++;
281 for (
int i = 0;
i <
s->max + 1;
i++) {
282 ucnt += uhistogram[
i];
283 if (ucnt >= half_size) {
289 for (
int i = 0;
i <
s->max + 1;
i++) {
290 vcnt += vhistogram[
i];
291 if (vcnt >= half_size) {
297 s->analyzeret[0][0] = imax * umedian - 0.5f;
298 s->analyzeret[0][1] = imax * vmedian - 0.5f;
299 s->analyzeret[0][2] = imax * umedian - 0.5f;
300 s->analyzeret[0][3] = imax * vmedian - 0.5f;
306 float y = yptr[x * chroma_w] * imax; \
307 float u = uptr[x] * imax - .5f; \
308 float v = vptr[x] * imax - .5f; \
311 nu = saturation * (u + y * bd + bl); \
312 nv = saturation * (v + y * rd + rl);
318 const float max =
s->max;
319 const float imax =
s->imax;
320 const int chroma_w =
s->chroma_w;
321 const int chroma_h =
s->chroma_h;
322 const int width =
s->planewidth[1];
323 const int height =
s->planeheight[1];
332 const float saturation =
s->saturation;
333 const float bl =
s->bl;
334 const float rl =
s->rl;
335 const float bd =
s->bh - bl;
336 const float rd =
s->rh - rl;
339 for (
int x = 0; x <
width; x++) {
346 yptr += ylinesize * chroma_h;
358 const int depth =
s->depth;
359 const float max =
s->max;
360 const float imax =
s->imax;
361 const int chroma_w =
s->chroma_w;
362 const int chroma_h =
s->chroma_h;
363 const int width =
s->planewidth[1];
364 const int height =
s->planeheight[1];
373 const float saturation =
s->saturation;
374 const float bl =
s->bl;
375 const float rl =
s->rl;
376 const float bd =
s->bh - bl;
377 const float rd =
s->rh - rl;
380 for (
int x = 0; x <
width; x++) {
387 yptr += ylinesize * chroma_h;
402 const int nb_athreads =
s->analyze ==
MEDIAN ? 1 : nb_threads;
403 float bl = 0.f, rl = 0.f, bh = 0.f, rh = 0.f;
407 for (
int i = 0;
i < nb_athreads;
i++) {
408 bl +=
s->analyzeret[
i][0];
409 rl +=
s->analyzeret[
i][1];
410 bh +=
s->analyzeret[
i][2];
411 rh +=
s->analyzeret[
i][3];
452 s->depth =
desc->comp[0].depth;
453 s->max = (1 <<
s->depth) - 1;
454 s->imax = 1.f /
s->max;
457 s->uhistogram =
av_calloc(
s->max == 255 ? 256 : 65536,
sizeof(*
s->uhistogram));
461 s->vhistogram =
av_calloc(
s->max == 255 ? 256 : 65536,
sizeof(*
s->vhistogram));
469 switch (
s->analyze) {
485 s->chroma_w = 1 <<
desc->log2_chroma_w;
486 s->chroma_h = 1 <<
desc->log2_chroma_h;
488 s->planeheight[0] =
s->planeheight[3] =
inlink->h;
490 s->planewidth[0] =
s->planewidth[3] =
inlink->w;
514 #define OFFSET(x) offsetof(ColorCorrectContext, x)
515 #define VF AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
534 .
name =
"colorcorrect",
535 .description =
NULL_IF_CONFIG_SMALL(
"Adjust color white balance selectively for blacks and whites."),
537 .priv_class = &colorcorrect_class,
#define AV_PIX_FMT_YUVA422P16
AVPixelFormat
Pixel format.
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
const AVFilter ff_vf_colorcorrect
static int average_slice16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int median_16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
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 colorcorrect_slice16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define FILTER_PIXFMTS_ARRAY(array)
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
static int colorcorrect_slice8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AV_PIX_FMT_YUVA422P9
This structure describes decoded (raw) audio or video data.
static av_always_inline av_const unsigned av_clip_uintp2_c(int a, int p)
Clip a signed integer to an unsigned power of two range.
#define AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P10
static const AVFilterPad colorcorrect_inputs[]
#define AV_PIX_FMT_YUV420P10
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
const char * name
Filter name.
A link between two filters.
#define AV_PIX_FMT_YUVA422P10
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static const AVOption colorcorrect_options[]
int(* do_slice)(AVFilterContext *s, void *arg, int jobnr, int nb_jobs)
static av_cold int config_input(AVFilterLink *inlink)
static int minmax_slice16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUV422P9
A filter pad used for either input or output.
static int average_slice8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AV_PIX_FMT_YUV444P10
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)
#define AV_PIX_FMT_YUV422P16
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
#define AV_PIX_FMT_YUV444P16
#define AV_CEIL_RSHIFT(a, b)
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
#define AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P16
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FILTER_INPUTS(array)
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Describe the class of an AVClass context structure.
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
#define AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_YUV422P10
static int median_8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static enum AVPixelFormat pixel_fmts[]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV444P12
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.
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
#define AV_PIX_FMT_YUVA444P10
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
int(* do_analyze)(AVFilterContext *s, void *arg, int jobnr, int nb_jobs)
#define i(width, name, range_min, range_max)
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
const char * name
Pad name.
void * av_calloc(size_t nmemb, size_t size)
#define AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV422P14
static av_cold void uninit(AVFilterContext *ctx)
#define AV_PIX_FMT_YUVA422P12
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
#define FILTER_OUTPUTS(array)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
AVFILTER_DEFINE_CLASS(colorcorrect)
#define AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV444P14
static int minmax_slice8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int analyze(const uint8_t *buf, int size, int packet_size, int probe)
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
#define AV_PIX_FMT_YUV420P14
#define AVFILTERPAD_FLAG_NEEDS_WRITABLE
The filter expects writable frames from its input link, duplicating data buffers if needed.