59 int jobnr,
int nb_jobs);
66 const float imax =
s->imax;
67 const int width =
s->planewidth[1];
68 const int height =
s->planeheight[1];
71 const ptrdiff_t ulinesize =
frame->linesize[1];
72 const ptrdiff_t vlinesize =
frame->linesize[2];
73 const uint8_t *uptr = (
const uint8_t *)
frame->data[1] +
slice_start * ulinesize;
74 const uint8_t *vptr = (
const uint8_t *)
frame->data[2] +
slice_start * vlinesize;
75 int sum_u = 0, sum_v = 0;
78 for (
int x = 0; x <
width; x++) {
97 const float imax =
s->imax;
98 const int width =
s->planewidth[1];
99 const int height =
s->planeheight[1];
102 const ptrdiff_t ulinesize =
frame->linesize[1] / 2;
103 const ptrdiff_t vlinesize =
frame->linesize[2] / 2;
104 const uint16_t *uptr = (
const uint16_t *)
frame->data[1] +
slice_start * ulinesize;
105 const uint16_t *vptr = (
const uint16_t *)
frame->data[2] +
slice_start * vlinesize;
109 for (
int x = 0; x <
width; x++) {
128 const float imax =
s->imax;
129 const int width =
s->planewidth[1];
130 const int height =
s->planeheight[1];
133 const ptrdiff_t ulinesize =
frame->linesize[1];
134 const ptrdiff_t vlinesize =
frame->linesize[2];
135 const uint8_t *uptr = (
const uint8_t *)
frame->data[1] +
slice_start * ulinesize;
136 const uint8_t *vptr = (
const uint8_t *)
frame->data[2] +
slice_start * vlinesize;
137 int min_u = 255, min_v = 255;
138 int max_u = 0, max_v = 0;
141 for (
int x = 0; x <
width; x++) {
142 min_u =
FFMIN(min_u, uptr[x]);
143 min_v =
FFMIN(min_v, vptr[x]);
144 max_u =
FFMAX(max_u, uptr[x]);
145 max_v =
FFMAX(max_v, vptr[x]);
152 s->analyzeret[jobnr][0] =
imax * min_u - 0.5f;
153 s->analyzeret[jobnr][1] =
imax * min_v - 0.5f;
154 s->analyzeret[jobnr][2] =
imax * max_u - 0.5f;
155 s->analyzeret[jobnr][3] =
imax * max_v - 0.5f;
164 const float imax =
s->imax;
165 const int width =
s->planewidth[1];
166 const int height =
s->planeheight[1];
169 const ptrdiff_t ulinesize =
frame->linesize[1] / 2;
170 const ptrdiff_t vlinesize =
frame->linesize[2] / 2;
171 const uint16_t *uptr = (
const uint16_t *)
frame->data[1] +
slice_start * ulinesize;
172 const uint16_t *vptr = (
const uint16_t *)
frame->data[2] +
slice_start * vlinesize;
173 int min_u = INT_MAX, min_v = INT_MAX;
174 int max_u = INT_MIN, max_v = INT_MIN;
177 for (
int x = 0; x <
width; x++) {
178 min_u =
FFMIN(min_u, uptr[x]);
179 min_v =
FFMIN(min_v, vptr[x]);
180 max_u =
FFMAX(max_u, uptr[x]);
181 max_v =
FFMAX(max_v, vptr[x]);
188 s->analyzeret[jobnr][0] =
imax * min_u - 0.5f;
189 s->analyzeret[jobnr][1] =
imax * min_v - 0.5f;
190 s->analyzeret[jobnr][2] =
imax * max_u - 0.5f;
191 s->analyzeret[jobnr][3] =
imax * max_v - 0.5f;
200 const float imax =
s->imax;
201 const int width =
s->planewidth[1];
202 const int height =
s->planeheight[1];
203 const ptrdiff_t ulinesize =
frame->linesize[1];
204 const ptrdiff_t vlinesize =
frame->linesize[2];
205 const uint8_t *uptr = (
const uint8_t *)
frame->data[1];
206 const uint8_t *vptr = (
const uint8_t *)
frame->data[2];
207 unsigned *uhistogram =
s->uhistogram;
208 unsigned *vhistogram =
s->vhistogram;
210 int umedian =
s->max, vmedian =
s->max;
211 unsigned ucnt = 0, vcnt = 0;
213 memset(uhistogram, 0,
sizeof(*uhistogram) * (
s->max + 1));
214 memset(vhistogram, 0,
sizeof(*vhistogram) * (
s->max + 1));
216 for (
int y = 0; y <
height; y++) {
217 for (
int x = 0; x <
width; x++) {
218 uhistogram[uptr[x]]++;
219 vhistogram[vptr[x]]++;
226 for (
int i = 0;
i <
s->max + 1;
i++) {
227 ucnt += uhistogram[
i];
228 if (ucnt >= half_size) {
234 for (
int i = 0;
i <
s->max + 1;
i++) {
235 vcnt += vhistogram[
i];
236 if (vcnt >= half_size) {
242 s->analyzeret[0][0] =
imax * umedian - 0.5f;
243 s->analyzeret[0][1] =
imax * vmedian - 0.5f;
244 s->analyzeret[0][2] =
imax * umedian - 0.5f;
245 s->analyzeret[0][3] =
imax * vmedian - 0.5f;
254 const float imax =
s->imax;
255 const int width =
s->planewidth[1];
256 const int height =
s->planeheight[1];
257 const ptrdiff_t ulinesize =
frame->linesize[1] / 2;
258 const ptrdiff_t vlinesize =
frame->linesize[2] / 2;
259 const uint16_t *uptr = (
const uint16_t *)
frame->data[1];
260 const uint16_t *vptr = (
const uint16_t *)
frame->data[2];
261 unsigned *uhistogram =
s->uhistogram;
262 unsigned *vhistogram =
s->vhistogram;
264 int umedian =
s->max, vmedian =
s->max;
265 unsigned ucnt = 0, vcnt = 0;
267 memset(uhistogram, 0,
sizeof(*uhistogram) * (
s->max + 1));
268 memset(vhistogram, 0,
sizeof(*vhistogram) * (
s->max + 1));
270 for (
int y = 0; y <
height; y++) {
271 for (
int x = 0; x <
width; x++) {
272 uhistogram[uptr[x]]++;
273 vhistogram[vptr[x]]++;
280 for (
int i = 0;
i <
s->max + 1;
i++) {
281 ucnt += uhistogram[
i];
282 if (ucnt >= half_size) {
288 for (
int i = 0;
i <
s->max + 1;
i++) {
289 vcnt += vhistogram[
i];
290 if (vcnt >= half_size) {
296 s->analyzeret[0][0] =
imax * umedian - 0.5f;
297 s->analyzeret[0][1] =
imax * vmedian - 0.5f;
298 s->analyzeret[0][2] =
imax * umedian - 0.5f;
299 s->analyzeret[0][3] =
imax * vmedian - 0.5f;
305 float y = yptr[x * chroma_w] * imax; \
306 float u = uptr[x] * imax - .5f; \
307 float v = vptr[x] * imax - .5f; \
310 nu = saturation * (u + y * bd + bl); \
311 nv = saturation * (v + y * rd + rl);
317 const float max =
s->max;
318 const float imax =
s->imax;
319 const int chroma_w =
s->chroma_w;
320 const int chroma_h =
s->chroma_h;
321 const int width =
s->planewidth[1];
322 const int height =
s->planeheight[1];
325 const ptrdiff_t ylinesize =
frame->linesize[0];
326 const ptrdiff_t ulinesize =
frame->linesize[1];
327 const ptrdiff_t vlinesize =
frame->linesize[2];
332 const float bl =
s->bl;
333 const float rl =
s->rl;
334 const float bd =
s->bh - bl;
335 const float rd =
s->rh - rl;
338 for (
int x = 0; x <
width; x++) {
345 yptr += ylinesize * chroma_h;
357 const int depth =
s->depth;
358 const float max =
s->max;
359 const float imax =
s->imax;
360 const int chroma_w =
s->chroma_w;
361 const int chroma_h =
s->chroma_h;
362 const int width =
s->planewidth[1];
363 const int height =
s->planeheight[1];
366 const ptrdiff_t ylinesize =
frame->linesize[0] / 2;
367 const ptrdiff_t ulinesize =
frame->linesize[1] / 2;
368 const ptrdiff_t vlinesize =
frame->linesize[2] / 2;
369 uint16_t *yptr = (uint16_t *)
frame->data[0] +
slice_start * chroma_h * ylinesize;
373 const float bl =
s->bl;
374 const float rl =
s->rl;
375 const float bd =
s->bh - bl;
376 const float rd =
s->rh - rl;
379 for (
int x = 0; x <
width; x++) {
386 yptr += ylinesize * chroma_h;
395 int jobnr,
int nb_jobs) = {
408 const int nb_athreads =
s->analyze ==
MEDIAN ? 1 : nb_threads;
409 float bl = 0.f, rl = 0.f, bh = 0.f, rh = 0.f;
413 for (
int i = 0;
i < nb_athreads;
i++) {
414 bl +=
s->analyzeret[
i][0];
415 rl +=
s->analyzeret[
i][1];
416 bh +=
s->analyzeret[
i][2];
417 rh +=
s->analyzeret[
i][3];
458 s->depth =
desc->comp[0].depth;
459 s->max = (1 <<
s->depth) - 1;
460 s->imax = 1.f /
s->max;
463 s->uhistogram =
av_calloc(
s->max == 255 ? 256 : 65536,
sizeof(*
s->uhistogram));
467 s->vhistogram =
av_calloc(
s->max == 255 ? 256 : 65536,
sizeof(*
s->vhistogram));
471 s->analyzeret =
av_calloc(inlink->
h,
sizeof(*
s->analyzeret));
475 s->chroma_w = 1 <<
desc->log2_chroma_w;
476 s->chroma_h = 1 <<
desc->log2_chroma_h;
478 s->planeheight[0] =
s->planeheight[3] = inlink->
h;
480 s->planewidth[0] =
s->planewidth[3] = inlink->
w;
504#define OFFSET(x) offsetof(ColorCorrectContext, x)
505#define VF AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
524 .p.name =
"colorcorrect",
525 .p.description =
NULL_IF_CONFIG_SMALL(
"Adjust color white balance selectively for blacks and whites."),
526 .p.priv_class = &colorcorrect_class,
static int config_input(AVFilterLink *inlink)
const FFFilter ff_vf_colorcorrect
static AVFormatContext * ctx
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...
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_slice)(AVFilterContext *s, void *arg, int jobnr, int nb_jobs)
static int imax(const int a, const int b)
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(*const analyze_slice[NB_ANALYZE][2])(AVFilterContext *s, 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)