59 int jobnr,
int nb_jobs);
61 int jobnr,
int nb_jobs);
68 const float imax =
s->imax;
69 const int width =
s->planewidth[1];
70 const int height =
s->planeheight[1];
73 const ptrdiff_t ulinesize =
frame->linesize[1];
74 const ptrdiff_t vlinesize =
frame->linesize[2];
75 const uint8_t *uptr = (
const uint8_t *)
frame->data[1] +
slice_start * ulinesize;
76 const uint8_t *vptr = (
const uint8_t *)
frame->data[2] +
slice_start * vlinesize;
77 int sum_u = 0, sum_v = 0;
80 for (
int x = 0; x <
width; x++) {
99 const float imax =
s->imax;
100 const int width =
s->planewidth[1];
101 const int height =
s->planeheight[1];
104 const ptrdiff_t ulinesize =
frame->linesize[1] / 2;
105 const ptrdiff_t vlinesize =
frame->linesize[2] / 2;
106 const uint16_t *uptr = (
const uint16_t *)
frame->data[1] +
slice_start * ulinesize;
107 const uint16_t *vptr = (
const uint16_t *)
frame->data[2] +
slice_start * vlinesize;
111 for (
int x = 0; x <
width; x++) {
130 const float imax =
s->imax;
131 const int width =
s->planewidth[1];
132 const int height =
s->planeheight[1];
135 const ptrdiff_t ulinesize =
frame->linesize[1];
136 const ptrdiff_t vlinesize =
frame->linesize[2];
137 const uint8_t *uptr = (
const uint8_t *)
frame->data[1] +
slice_start * ulinesize;
138 const uint8_t *vptr = (
const uint8_t *)
frame->data[2] +
slice_start * vlinesize;
139 int min_u = 255, min_v = 255;
140 int max_u = 0, max_v = 0;
143 for (
int x = 0; x <
width; x++) {
144 min_u =
FFMIN(min_u, uptr[x]);
145 min_v =
FFMIN(min_v, vptr[x]);
146 max_u =
FFMAX(max_u, uptr[x]);
147 max_v =
FFMAX(max_v, vptr[x]);
154 s->analyzeret[jobnr][0] =
imax * min_u - 0.5f;
155 s->analyzeret[jobnr][1] =
imax * min_v - 0.5f;
156 s->analyzeret[jobnr][2] =
imax * max_u - 0.5f;
157 s->analyzeret[jobnr][3] =
imax * max_v - 0.5f;
166 const float imax =
s->imax;
167 const int width =
s->planewidth[1];
168 const int height =
s->planeheight[1];
171 const ptrdiff_t ulinesize =
frame->linesize[1] / 2;
172 const ptrdiff_t vlinesize =
frame->linesize[2] / 2;
173 const uint16_t *uptr = (
const uint16_t *)
frame->data[1] +
slice_start * ulinesize;
174 const uint16_t *vptr = (
const uint16_t *)
frame->data[2] +
slice_start * vlinesize;
175 int min_u = INT_MAX, min_v = INT_MAX;
176 int max_u = INT_MIN, max_v = INT_MIN;
179 for (
int x = 0; x <
width; x++) {
180 min_u =
FFMIN(min_u, uptr[x]);
181 min_v =
FFMIN(min_v, vptr[x]);
182 max_u =
FFMAX(max_u, uptr[x]);
183 max_v =
FFMAX(max_v, vptr[x]);
190 s->analyzeret[jobnr][0] =
imax * min_u - 0.5f;
191 s->analyzeret[jobnr][1] =
imax * min_v - 0.5f;
192 s->analyzeret[jobnr][2] =
imax * max_u - 0.5f;
193 s->analyzeret[jobnr][3] =
imax * max_v - 0.5f;
202 const float imax =
s->imax;
203 const int width =
s->planewidth[1];
204 const int height =
s->planeheight[1];
205 const ptrdiff_t ulinesize =
frame->linesize[1];
206 const ptrdiff_t vlinesize =
frame->linesize[2];
207 const uint8_t *uptr = (
const uint8_t *)
frame->data[1];
208 const uint8_t *vptr = (
const uint8_t *)
frame->data[2];
209 unsigned *uhistogram =
s->uhistogram;
210 unsigned *vhistogram =
s->vhistogram;
212 int umedian =
s->max, vmedian =
s->max;
213 unsigned ucnt = 0, vcnt = 0;
215 memset(uhistogram, 0,
sizeof(*uhistogram) * (
s->max + 1));
216 memset(vhistogram, 0,
sizeof(*vhistogram) * (
s->max + 1));
218 for (
int y = 0; y <
height; y++) {
219 for (
int x = 0; x <
width; x++) {
220 uhistogram[uptr[x]]++;
221 vhistogram[vptr[x]]++;
228 for (
int i = 0;
i <
s->max + 1;
i++) {
229 ucnt += uhistogram[
i];
230 if (ucnt >= half_size) {
236 for (
int i = 0;
i <
s->max + 1;
i++) {
237 vcnt += vhistogram[
i];
238 if (vcnt >= half_size) {
244 s->analyzeret[0][0] =
imax * umedian - 0.5f;
245 s->analyzeret[0][1] =
imax * vmedian - 0.5f;
246 s->analyzeret[0][2] =
imax * umedian - 0.5f;
247 s->analyzeret[0][3] =
imax * vmedian - 0.5f;
256 const float imax =
s->imax;
257 const int width =
s->planewidth[1];
258 const int height =
s->planeheight[1];
259 const ptrdiff_t ulinesize =
frame->linesize[1] / 2;
260 const ptrdiff_t vlinesize =
frame->linesize[2] / 2;
261 const uint16_t *uptr = (
const uint16_t *)
frame->data[1];
262 const uint16_t *vptr = (
const uint16_t *)
frame->data[2];
263 unsigned *uhistogram =
s->uhistogram;
264 unsigned *vhistogram =
s->vhistogram;
266 int umedian =
s->max, vmedian =
s->max;
267 unsigned ucnt = 0, vcnt = 0;
269 memset(uhistogram, 0,
sizeof(*uhistogram) * (
s->max + 1));
270 memset(vhistogram, 0,
sizeof(*vhistogram) * (
s->max + 1));
272 for (
int y = 0; y <
height; y++) {
273 for (
int x = 0; x <
width; x++) {
274 uhistogram[uptr[x]]++;
275 vhistogram[vptr[x]]++;
282 for (
int i = 0;
i <
s->max + 1;
i++) {
283 ucnt += uhistogram[
i];
284 if (ucnt >= half_size) {
290 for (
int i = 0;
i <
s->max + 1;
i++) {
291 vcnt += vhistogram[
i];
292 if (vcnt >= half_size) {
298 s->analyzeret[0][0] =
imax * umedian - 0.5f;
299 s->analyzeret[0][1] =
imax * vmedian - 0.5f;
300 s->analyzeret[0][2] =
imax * umedian - 0.5f;
301 s->analyzeret[0][3] =
imax * vmedian - 0.5f;
307 float y = yptr[x * chroma_w] * imax; \
308 float u = uptr[x] * imax - .5f; \
309 float v = vptr[x] * imax - .5f; \
312 nu = saturation * (u + y * bd + bl); \
313 nv = saturation * (v + y * rd + rl);
319 const float max =
s->max;
320 const float imax =
s->imax;
321 const int chroma_w =
s->chroma_w;
322 const int chroma_h =
s->chroma_h;
323 const int width =
s->planewidth[1];
324 const int height =
s->planeheight[1];
327 const ptrdiff_t ylinesize =
frame->linesize[0];
328 const ptrdiff_t ulinesize =
frame->linesize[1];
329 const ptrdiff_t vlinesize =
frame->linesize[2];
334 const float bl =
s->bl;
335 const float rl =
s->rl;
336 const float bd =
s->bh - bl;
337 const float rd =
s->rh - rl;
340 for (
int x = 0; x <
width; x++) {
347 yptr += ylinesize * chroma_h;
359 const int depth =
s->depth;
360 const float max =
s->max;
361 const float imax =
s->imax;
362 const int chroma_w =
s->chroma_w;
363 const int chroma_h =
s->chroma_h;
364 const int width =
s->planewidth[1];
365 const int height =
s->planeheight[1];
368 const ptrdiff_t ylinesize =
frame->linesize[0] / 2;
369 const ptrdiff_t ulinesize =
frame->linesize[1] / 2;
370 const ptrdiff_t vlinesize =
frame->linesize[2] / 2;
371 uint16_t *yptr = (uint16_t *)
frame->data[0] +
slice_start * chroma_h * ylinesize;
375 const float bl =
s->bl;
376 const float rl =
s->rl;
377 const float bd =
s->bh - bl;
378 const float rd =
s->rh - rl;
381 for (
int x = 0; x <
width; x++) {
388 yptr += ylinesize * chroma_h;
403 const int nb_athreads =
s->analyze ==
MEDIAN ? 1 : nb_threads;
404 float bl = 0.f, rl = 0.f, bh = 0.f, rh = 0.f;
408 for (
int i = 0;
i < nb_athreads;
i++) {
409 bl +=
s->analyzeret[
i][0];
410 rl +=
s->analyzeret[
i][1];
411 bh +=
s->analyzeret[
i][2];
412 rh +=
s->analyzeret[
i][3];
453 s->depth =
desc->comp[0].depth;
454 s->max = (1 <<
s->depth) - 1;
455 s->imax = 1.f /
s->max;
458 s->uhistogram =
av_calloc(
s->max == 255 ? 256 : 65536,
sizeof(*
s->uhistogram));
462 s->vhistogram =
av_calloc(
s->max == 255 ? 256 : 65536,
sizeof(*
s->vhistogram));
466 s->analyzeret =
av_calloc(inlink->
h,
sizeof(*
s->analyzeret));
470 switch (
s->analyze) {
486 s->chroma_w = 1 <<
desc->log2_chroma_w;
487 s->chroma_h = 1 <<
desc->log2_chroma_h;
489 s->planeheight[0] =
s->planeheight[3] = inlink->
h;
491 s->planewidth[0] =
s->planewidth[3] = inlink->
w;
515#define OFFSET(x) offsetof(ColorCorrectContext, x)
516#define VF AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
535 .p.name =
"colorcorrect",
536 .p.description =
NULL_IF_CONFIG_SMALL(
"Adjust color white balance selectively for blacks and whites."),
537 .p.priv_class = &colorcorrect_class,
static int config_input(AVFilterLink *inlink)
const FFFilter ff_vf_colorcorrect
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.
#define i(width, name, range_min, range_max)
static IPT saturation(const CmsCtx *ctx, IPT ipt)
#define AV_CEIL_RSHIFT(a, b)
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.
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
#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...
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
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 AVFILTERPAD_FLAG_NEEDS_WRITABLE
The filter expects writable frames from its input link, duplicating data buffers if needed.
#define FILTER_PIXFMTS_ARRAY(array)
#define AVFILTER_DEFINE_CLASS(fname)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
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.
static int analyze(const uint8_t *buf, int size, int packet_size, int probe)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUV420P14
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
@ 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_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
@ 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_YUVA422P12
#define AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P10
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.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
int(* do_analyze)(AVFilterContext *s, void *arg, int jobnr, int nb_jobs)
int(* do_slice)(AVFilterContext *s, void *arg, int jobnr, int nb_jobs)
static int imax(const int a, const int b)
static AVFormatContext * ctx
static enum AVPixelFormat pixel_fmts[]
static int minmax_slice16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int colorcorrect_slice16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static const AVOption colorcorrect_options[]
static int average_slice8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
static int median_8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static const AVFilterPad colorcorrect_inputs[]
static int minmax_slice8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static av_cold int config_input(AVFilterLink *inlink)
static av_cold void uninit(AVFilterContext *ctx)
static int median_16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int colorcorrect_slice8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int average_slice16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)