Go to the documentation of this file.
   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];
 
   71     const int slice_start = (
height * jobnr) / nb_jobs;
 
   73     const int ulinesize = 
frame->linesize[1];
 
   74     const int 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;
 
   79     for (
int y = slice_start; y < 
slice_end; y++) {
 
   80         for (
int x = 0; x < 
width; x++) {
 
   89     s->analyzeret[jobnr][0] = 
s->analyzeret[jobnr][2] = imax * sum_u / (float)((
slice_end - slice_start) * 
width) - 0.5
f;
 
   90     s->analyzeret[jobnr][1] = 
s->analyzeret[jobnr][3] = imax * sum_v / (float)((
slice_end - slice_start) * 
width) - 0.5
f;
 
   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;
 
  104     const int ulinesize = 
frame->linesize[1] / 2;
 
  105     const int 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;
 
  110     for (
int y = slice_start; y < 
slice_end; y++) {
 
  111         for (
int x = 0; x < 
width; x++) {
 
  120     s->analyzeret[jobnr][0] = 
s->analyzeret[jobnr][2] = imax * sum_u / (float)((
slice_end - slice_start) * 
width) - 0.5
f;
 
  121     s->analyzeret[jobnr][1] = 
s->analyzeret[jobnr][3] = imax * sum_v / (float)((
slice_end - slice_start) * 
width) - 0.5
f;
 
  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;
 
  135     const int ulinesize = 
frame->linesize[1];
 
  136     const int 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;
 
  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]);
 
  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];
 
  169     const int slice_start = (
height * jobnr) / nb_jobs;
 
  171     const int ulinesize = 
frame->linesize[1] / 2;
 
  172     const int 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;
 
  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]);
 
  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 int ulinesize = 
frame->linesize[1];
 
  206     const int 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 int ulinesize = 
frame->linesize[1] / 2;
 
  260     const int 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];
 
  325     const int slice_start = (
height * jobnr) / nb_jobs;
 
  327     const int ylinesize = 
frame->linesize[0];
 
  328     const int ulinesize = 
frame->linesize[1];
 
  329     const int 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;
 
  339     for (
int y = slice_start; y < 
slice_end; y++) {
 
  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];
 
  366     const int slice_start = (
height * jobnr) / nb_jobs;
 
  368     const int ylinesize = 
frame->linesize[0] / 2;
 
  369     const int ulinesize = 
frame->linesize[1] / 2;
 
  370     const int 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;
 
  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));
 
  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;
 
  520 #define OFFSET(x) offsetof(ColorCorrectContext, x) 
  521 #define VF AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM 
  540     .
name          = 
"colorcorrect",
 
  541     .description   = 
NULL_IF_CONFIG_SMALL(
"Adjust color white balance selectively for blacks and whites."),
 
  543     .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
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 ...
#define AV_PIX_FMT_YUV422P16
@ 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
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
#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)
static const AVFilterPad colorcorrect_outputs[]
@ 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.
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.