FFmpeg
vf_colorcorrect.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 Paul B Mahol
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <float.h>
22 
23 #include "libavutil/mem.h"
24 #include "libavutil/opt.h"
25 #include "libavutil/pixdesc.h"
26 #include "avfilter.h"
27 #include "filters.h"
28 #include "video.h"
29 
30 typedef enum AnalyzeMode {
36 } AnalyzeMode;
37 
38 typedef struct ColorCorrectContext {
39  const AVClass *class;
40 
41  float rl, bl;
42  float rh, bh;
43  float saturation;
44  int analyze;
45 
46  int depth;
47  float max, imax;
48 
50  int planeheight[4];
51  int planewidth[4];
52 
53  unsigned *uhistogram;
54  unsigned *vhistogram;
55 
57 
58  int (*do_analyze)(AVFilterContext *s, void *arg,
59  int jobnr, int nb_jobs);
60  int (*do_slice)(AVFilterContext *s, void *arg,
61  int jobnr, int nb_jobs);
63 
64 static int average_slice8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
65 {
66  ColorCorrectContext *s = ctx->priv;
67  AVFrame *frame = arg;
68  const float imax = s->imax;
69  const int width = s->planewidth[1];
70  const int height = s->planeheight[1];
71  const int slice_start = (height * jobnr) / nb_jobs;
72  const int slice_end = (height * (jobnr + 1)) / nb_jobs;
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;
78 
79  for (int y = slice_start; y < slice_end; y++) {
80  for (int x = 0; x < width; x++) {
81  sum_u += uptr[x];
82  sum_v += vptr[x];
83  }
84 
85  uptr += ulinesize;
86  vptr += vlinesize;
87  }
88 
89  s->analyzeret[jobnr][0] = s->analyzeret[jobnr][2] = imax * sum_u / (float)((slice_end - slice_start) * width) - 0.5f;
90  s->analyzeret[jobnr][1] = s->analyzeret[jobnr][3] = imax * sum_v / (float)((slice_end - slice_start) * width) - 0.5f;
91 
92  return 0;
93 }
94 
95 static int average_slice16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
96 {
97  ColorCorrectContext *s = ctx->priv;
98  AVFrame *frame = arg;
99  const float imax = s->imax;
100  const int width = s->planewidth[1];
101  const int height = s->planeheight[1];
102  const int slice_start = (height * jobnr) / nb_jobs;
103  const int slice_end = (height * (jobnr + 1)) / nb_jobs;
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;
108  int64_t sum_u = 0, sum_v = 0;
109 
110  for (int y = slice_start; y < slice_end; y++) {
111  for (int x = 0; x < width; x++) {
112  sum_u += uptr[x];
113  sum_v += vptr[x];
114  }
115 
116  uptr += ulinesize;
117  vptr += vlinesize;
118  }
119 
120  s->analyzeret[jobnr][0] = s->analyzeret[jobnr][2] = imax * sum_u / (float)((slice_end - slice_start) * width) - 0.5f;
121  s->analyzeret[jobnr][1] = s->analyzeret[jobnr][3] = imax * sum_v / (float)((slice_end - slice_start) * width) - 0.5f;
122 
123  return 0;
124 }
125 
126 static int minmax_slice8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
127 {
128  ColorCorrectContext *s = ctx->priv;
129  AVFrame *frame = arg;
130  const float imax = s->imax;
131  const int width = s->planewidth[1];
132  const int height = s->planeheight[1];
133  const int slice_start = (height * jobnr) / nb_jobs;
134  const int slice_end = (height * (jobnr + 1)) / nb_jobs;
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;
141 
142  for (int y = slice_start; y < slice_end; y++) {
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]);
148  }
149 
150  uptr += ulinesize;
151  vptr += vlinesize;
152  }
153 
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;
158 
159  return 0;
160 }
161 
162 static int minmax_slice16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
163 {
164  ColorCorrectContext *s = ctx->priv;
165  AVFrame *frame = arg;
166  const float imax = s->imax;
167  const int width = s->planewidth[1];
168  const int height = s->planeheight[1];
169  const int slice_start = (height * jobnr) / nb_jobs;
170  const int slice_end = (height * (jobnr + 1)) / nb_jobs;
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;
177 
178  for (int y = slice_start; y < slice_end; y++) {
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]);
184  }
185 
186  uptr += ulinesize;
187  vptr += vlinesize;
188  }
189 
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;
194 
195  return 0;
196 }
197 
198 static int median_8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
199 {
200  ColorCorrectContext *s = ctx->priv;
201  AVFrame *frame = arg;
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;
211  const int half_size = width * height / 2;
212  int umedian = s->max, vmedian = s->max;
213  unsigned ucnt = 0, vcnt = 0;
214 
215  memset(uhistogram, 0, sizeof(*uhistogram) * (s->max + 1));
216  memset(vhistogram, 0, sizeof(*vhistogram) * (s->max + 1));
217 
218  for (int y = 0; y < height; y++) {
219  for (int x = 0; x < width; x++) {
220  uhistogram[uptr[x]]++;
221  vhistogram[vptr[x]]++;
222  }
223 
224  uptr += ulinesize;
225  vptr += vlinesize;
226  }
227 
228  for (int i = 0; i < s->max + 1; i++) {
229  ucnt += uhistogram[i];
230  if (ucnt >= half_size) {
231  umedian = i;
232  break;
233  }
234  }
235 
236  for (int i = 0; i < s->max + 1; i++) {
237  vcnt += vhistogram[i];
238  if (vcnt >= half_size) {
239  vmedian = i;
240  break;
241  }
242  }
243 
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;
248 
249  return 0;
250 }
251 
252 static int median_16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
253 {
254  ColorCorrectContext *s = ctx->priv;
255  AVFrame *frame = arg;
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;
265  const int half_size = width * height / 2;
266  int umedian = s->max, vmedian = s->max;
267  unsigned ucnt = 0, vcnt = 0;
268 
269  memset(uhistogram, 0, sizeof(*uhistogram) * (s->max + 1));
270  memset(vhistogram, 0, sizeof(*vhistogram) * (s->max + 1));
271 
272  for (int y = 0; y < height; y++) {
273  for (int x = 0; x < width; x++) {
274  uhistogram[uptr[x]]++;
275  vhistogram[vptr[x]]++;
276  }
277 
278  uptr += ulinesize;
279  vptr += vlinesize;
280  }
281 
282  for (int i = 0; i < s->max + 1; i++) {
283  ucnt += uhistogram[i];
284  if (ucnt >= half_size) {
285  umedian = i;
286  break;
287  }
288  }
289 
290  for (int i = 0; i < s->max + 1; i++) {
291  vcnt += vhistogram[i];
292  if (vcnt >= half_size) {
293  vmedian = i;
294  break;
295  }
296  }
297 
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;
302 
303  return 0;
304 }
305 
306 #define PROCESS() \
307  float y = yptr[x * chroma_w] * imax; \
308  float u = uptr[x] * imax - .5f; \
309  float v = vptr[x] * imax - .5f; \
310  float nu, nv; \
311  \
312  nu = saturation * (u + y * bd + bl); \
313  nv = saturation * (v + y * rd + rl);
314 
315 static int colorcorrect_slice8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
316 {
317  ColorCorrectContext *s = ctx->priv;
318  AVFrame *frame = arg;
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];
325  const int slice_start = (height * jobnr) / nb_jobs;
326  const int slice_end = (height * (jobnr + 1)) / nb_jobs;
327  const ptrdiff_t ylinesize = frame->linesize[0];
328  const ptrdiff_t ulinesize = frame->linesize[1];
329  const ptrdiff_t vlinesize = frame->linesize[2];
330  uint8_t *yptr = frame->data[0] + slice_start * chroma_h * ylinesize;
331  uint8_t *uptr = frame->data[1] + slice_start * ulinesize;
332  uint8_t *vptr = frame->data[2] + slice_start * vlinesize;
333  const float saturation = s->saturation;
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;
338 
339  for (int y = slice_start; y < slice_end; y++) {
340  for (int x = 0; x < width; x++) {
341  PROCESS()
342 
343  uptr[x] = av_clip_uint8((nu + 0.5f) * max);
344  vptr[x] = av_clip_uint8((nv + 0.5f) * max);
345  }
346 
347  yptr += ylinesize * chroma_h;
348  uptr += ulinesize;
349  vptr += vlinesize;
350  }
351 
352  return 0;
353 }
354 
355 static int colorcorrect_slice16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
356 {
357  ColorCorrectContext *s = ctx->priv;
358  AVFrame *frame = arg;
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];
366  const int slice_start = (height * jobnr) / nb_jobs;
367  const int slice_end = (height * (jobnr + 1)) / nb_jobs;
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;
372  uint16_t *uptr = (uint16_t *)frame->data[1] + slice_start * ulinesize;
373  uint16_t *vptr = (uint16_t *)frame->data[2] + slice_start * vlinesize;
374  const float saturation = s->saturation;
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;
379 
380  for (int y = slice_start; y < slice_end; y++) {
381  for (int x = 0; x < width; x++) {
382  PROCESS()
383 
384  uptr[x] = av_clip_uintp2_c((nu + 0.5f) * max, depth);
385  vptr[x] = av_clip_uintp2_c((nv + 0.5f) * max, depth);
386  }
387 
388  yptr += ylinesize * chroma_h;
389  uptr += ulinesize;
390  vptr += vlinesize;
391  }
392 
393  return 0;
394 }
395 
397 {
398  AVFilterContext *ctx = inlink->dst;
399  ColorCorrectContext *s = ctx->priv;
400  const int nb_threads = s->analyze == MEDIAN ? 1 : FFMIN(s->planeheight[1], ff_filter_get_nb_threads(ctx));
401 
402  if (s->analyze) {
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;
405 
406  ff_filter_execute(ctx, s->do_analyze, frame, NULL, nb_athreads);
407 
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];
413  }
414 
415  bl /= nb_athreads;
416  rl /= nb_athreads;
417  bh /= nb_athreads;
418  rh /= nb_athreads;
419 
420  s->bl = -bl;
421  s->rl = -rl;
422  s->bh = -bh;
423  s->rh = -rh;
424  }
425 
426  ff_filter_execute(ctx, s->do_slice, frame, NULL, nb_threads);
427 
428  return ff_filter_frame(ctx->outputs[0], frame);
429 }
430 
431 static const enum AVPixelFormat pixel_fmts[] = {
445 };
446 
448 {
449  AVFilterContext *ctx = inlink->dst;
450  ColorCorrectContext *s = ctx->priv;
452 
453  s->depth = desc->comp[0].depth;
454  s->max = (1 << s->depth) - 1;
455  s->imax = 1.f / s->max;
456  s->do_slice = s->depth <= 8 ? colorcorrect_slice8 : colorcorrect_slice16;
457 
458  s->uhistogram = av_calloc(s->max == 255 ? 256 : 65536, sizeof(*s->uhistogram));
459  if (!s->uhistogram)
460  return AVERROR(ENOMEM);
461 
462  s->vhistogram = av_calloc(s->max == 255 ? 256 : 65536, sizeof(*s->vhistogram));
463  if (!s->vhistogram)
464  return AVERROR(ENOMEM);
465 
466  s->analyzeret = av_calloc(inlink->h, sizeof(*s->analyzeret));
467  if (!s->analyzeret)
468  return AVERROR(ENOMEM);
469 
470  switch (s->analyze) {
471  case MANUAL:
472  break;
473  case AVERAGE:
474  s->do_analyze = s->depth <= 8 ? average_slice8 : average_slice16;
475  break;
476  case MINMAX:
477  s->do_analyze = s->depth <= 8 ? minmax_slice8 : minmax_slice16;
478  break;
479  case MEDIAN:
480  s->do_analyze = s->depth <= 8 ? median_8 : median_16;
481  break;
482  default:
483  return AVERROR_BUG;
484  }
485 
486  s->chroma_w = 1 << desc->log2_chroma_w;
487  s->chroma_h = 1 << desc->log2_chroma_h;
488  s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
489  s->planeheight[0] = s->planeheight[3] = inlink->h;
490  s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
491  s->planewidth[0] = s->planewidth[3] = inlink->w;
492 
493  return 0;
494 }
495 
497 {
498  ColorCorrectContext *s = ctx->priv;
499 
500  av_freep(&s->analyzeret);
501  av_freep(&s->uhistogram);
502  av_freep(&s->vhistogram);
503 }
504 
506  {
507  .name = "default",
508  .type = AVMEDIA_TYPE_VIDEO,
510  .filter_frame = filter_frame,
511  .config_props = config_input,
512  },
513 };
514 
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
517 
518 static const AVOption colorcorrect_options[] = {
519  { "rl", "set the red shadow spot", OFFSET(rl), AV_OPT_TYPE_FLOAT, {.dbl=0}, -1, 1, VF },
520  { "bl", "set the blue shadow spot", OFFSET(bl), AV_OPT_TYPE_FLOAT, {.dbl=0}, -1, 1, VF },
521  { "rh", "set the red highlight spot", OFFSET(rh), AV_OPT_TYPE_FLOAT, {.dbl=0}, -1, 1, VF },
522  { "bh", "set the blue highlight spot", OFFSET(bh), AV_OPT_TYPE_FLOAT, {.dbl=0}, -1, 1, VF },
523  { "saturation", "set the amount of saturation", OFFSET(saturation), AV_OPT_TYPE_FLOAT, {.dbl=1}, -3, 3, VF },
524  { "analyze", "set the analyze mode", OFFSET(analyze), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_ANALYZE-1, VF, .unit = "analyze" },
525  { "manual", "manually set options", 0, AV_OPT_TYPE_CONST, {.i64=MANUAL}, 0, 0, VF, .unit = "analyze" },
526  { "average", "use average pixels", 0, AV_OPT_TYPE_CONST, {.i64=AVERAGE}, 0, 0, VF, .unit = "analyze" },
527  { "minmax", "use minmax pixels", 0, AV_OPT_TYPE_CONST, {.i64=MINMAX}, 0, 0, VF, .unit = "analyze" },
528  { "median", "use median pixels", 0, AV_OPT_TYPE_CONST, {.i64=MEDIAN}, 0, 0, VF, .unit = "analyze" },
529  { NULL }
530 };
531 
532 AVFILTER_DEFINE_CLASS(colorcorrect);
533 
535  .name = "colorcorrect",
536  .description = NULL_IF_CONFIG_SMALL("Adjust color white balance selectively for blacks and whites."),
537  .priv_size = sizeof(ColorCorrectContext),
538  .priv_class = &colorcorrect_class,
539  .uninit = uninit,
544  .process_command = ff_filter_process_command,
545 };
AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:546
VF
#define VF
Definition: vf_colorcorrect.c:516
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
ColorCorrectContext::chroma_h
int chroma_h
Definition: vf_colorcorrect.c:49
AVERROR
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
opt.h
ff_vf_colorcorrect
const AVFilter ff_vf_colorcorrect
Definition: vf_colorcorrect.c:534
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: filters.h:242
average_slice16
static int average_slice16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_colorcorrect.c:95
median_16
static int median_16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_colorcorrect.c:252
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1061
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3170
ColorCorrectContext::planeheight
int planeheight[4]
Definition: vf_colorcorrect.c:50
colorcorrect_slice16
static int colorcorrect_slice16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_colorcorrect.c:355
int64_t
long long int64_t
Definition: coverity.c:34
inlink
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
Definition: filter_design.txt:212
colorcorrect_slice8
static int colorcorrect_slice8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_colorcorrect.c:315
AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:538
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
pixdesc.h
av_clip_uintp2_c
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.
Definition: common.h:280
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:545
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:540
ColorCorrectContext::uhistogram
unsigned * uhistogram
Definition: vf_colorcorrect.c:53
AVOption
AVOption.
Definition: opt.h:429
colorcorrect_inputs
static const AVFilterPad colorcorrect_inputs[]
Definition: vf_colorcorrect.c:505
ColorCorrectContext::max
float max
Definition: vf_colorcorrect.c:47
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:502
ColorCorrectContext::analyzeret
float(* analyzeret)[4]
Definition: vf_colorcorrect.c:56
float.h
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:106
max
#define max(a, b)
Definition: cuda_runtime.h:33
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:205
video.h
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:541
colorcorrect_options
static const AVOption colorcorrect_options[]
Definition: vf_colorcorrect.c:518
ColorCorrectContext::do_slice
int(* do_slice)(AVFilterContext *s, void *arg, int jobnr, int nb_jobs)
Definition: vf_colorcorrect.c:60
config_input
static av_cold int config_input(AVFilterLink *inlink)
Definition: vf_colorcorrect.c:447
minmax_slice16
static int minmax_slice16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_colorcorrect.c:162
AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:537
slice_end
static int slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output)
Handle slice ends.
Definition: mpeg12dec.c:1720
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:547
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:500
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:38
average_slice8
static int average_slice8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_colorcorrect.c:64
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:505
AV_PIX_FMT_YUVJ411P
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:283
ColorCorrectContext
Definition: vf_colorcorrect.c:38
av_cold
#define av_cold
Definition: attributes.h:90
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:514
ff_video_default_filterpad
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
Definition: video.c:37
MEDIAN
@ MEDIAN
Definition: vf_colorcorrect.c:34
AV_PIX_FMT_YUVJ422P
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:86
float
float
Definition: af_crystalizer.c:122
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_PIX_FMT_YUVA420P
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:108
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:515
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:60
filters.h
AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:544
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:499
ColorCorrectContext::chroma_w
int chroma_w
Definition: vf_colorcorrect.c:49
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:513
ctx
AVFormatContext * ctx
Definition: movenc.c:49
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
AV_PIX_FMT_YUVJ444P
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:87
arg
const char * arg
Definition: jacosubdec.c:67
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
NULL
#define NULL
Definition: coverity.c:32
NB_ANALYZE
@ NB_ANALYZE
Definition: vf_colorcorrect.c:35
AV_PIX_FMT_YUVJ420P
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:85
AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_YUV440P10
Definition: pixfmt.h:504
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:503
AnalyzeMode
AnalyzeMode
Definition: vf_colorcorrect.c:30
median_8
static int median_8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_colorcorrect.c:198
AVERAGE
@ AVERAGE
Definition: vf_colorcorrect.c:32
pixel_fmts
static enum AVPixelFormat pixel_fmts[]
Definition: vf_colorcorrect.c:431
AVFILTERPAD_FLAG_NEEDS_WRITABLE
#define AVFILTERPAD_FLAG_NEEDS_WRITABLE
The filter expects writable frames from its input link, duplicating data buffers if needed.
Definition: filters.h:57
f
f
Definition: af_crystalizer.c:122
ColorCorrectContext::vhistogram
unsigned * vhistogram
Definition: vf_colorcorrect.c:54
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
height
#define height
Definition: dsp.h:85
ColorCorrectContext::bl
float bl
Definition: vf_colorcorrect.c:41
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:507
ColorCorrectContext::rh
float rh
Definition: vf_colorcorrect.c:42
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:509
ff_filter_process_command
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.
Definition: avfilter.c:900
AV_PIX_FMT_YUVA444P
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:174
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:542
ColorCorrectContext::planewidth
int planewidth[4]
Definition: vf_colorcorrect.c:51
AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition: avfilter.h:182
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition: opt.h:271
ColorCorrectContext::do_analyze
int(* do_analyze)(AVFilterContext *s, void *arg, int jobnr, int nb_jobs)
Definition: vf_colorcorrect.c:58
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
ColorCorrectContext::saturation
float saturation
Definition: vf_colorcorrect.c:43
ff_filter_get_nb_threads
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:840
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
Definition: vf_colorcorrect.c:396
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AV_PIX_FMT_YUVJ440P
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
Definition: pixfmt.h:107
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:44
MINMAX
@ MINMAX
Definition: vf_colorcorrect.c:33
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:501
slice_start
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)
Definition: dec.c:736
AVFilter
Filter definition.
Definition: avfilter.h:201
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:539
ColorCorrectContext::depth
int depth
Definition: vf_colorcorrect.c:46
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:506
AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:511
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_colorcorrect.c:496
ff_filter_execute
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition: avfilter.c:1666
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_PIX_FMT_YUVA422P12
#define AV_PIX_FMT_YUVA422P12
Definition: pixfmt.h:543
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
avfilter.h
av_clip_uint8
#define av_clip_uint8
Definition: common.h:106
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:78
ColorCorrectContext::imax
float imax
Definition: vf_colorcorrect.c:47
AVFilterContext
An instance of a filter.
Definition: avfilter.h:457
ColorCorrectContext::bh
float bh
Definition: vf_colorcorrect.c:42
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:152
desc
const char * desc
Definition: libsvtav1.c:79
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:77
mem.h
ColorCorrectContext::analyze
int analyze
Definition: vf_colorcorrect.c:44
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
MANUAL
@ MANUAL
Definition: vf_colorcorrect.c:31
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:80
PROCESS
#define PROCESS()
Definition: vf_colorcorrect.c:306
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(colorcorrect)
AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:508
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:512
minmax_slice8
static int minmax_slice8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_colorcorrect.c:126
analyze
static int analyze(const uint8_t *buf, int size, int packet_size, int probe)
Definition: mpegts.c:582
width
#define width
Definition: dsp.h:85
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
OFFSET
#define OFFSET(x)
Definition: vf_colorcorrect.c:515
AV_PIX_FMT_YUVA422P
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:173
AV_PIX_FMT_YUV420P14
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:510
ColorCorrectContext::rl
float rl
Definition: vf_colorcorrect.c:41