FFmpeg
Data Structures | Macros | Functions | Variables
vf_grayworld.c File Reference
#include "libavutil/imgutils.h"
#include "libavutil/opt.h"
#include "avfilter.h"
#include "internal.h"
#include "video.h"

Go to the source code of this file.

Data Structures

struct  ThreadData
 Used for passing data between threads. More...
 
struct  GrayWorldContext
 

Macros

#define OFFSET(x)   offsetof(GrayWorldContext, x)
 
#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_RUNTIME_PARAM
 

Functions

 AVFILTER_DEFINE_CLASS (grayworld)
 
static void apply_matrix (const float matrix[3][3], const float input[3], float output[3])
 
static void rgb2lab (const float rgb[3], float lab[3])
 Convert from Linear RGB to logspace LAB. More...
 
static void lab2rgb (const float lab[3], float rgb[3])
 Convert from Logspace LAB to Linear RGB. More...
 
static int convert_frame (AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 Convert a frame from linear RGB to logspace LAB, and accumulate channel totals for each row Convert from RGB -> lms using equation 4 in color transfer paper. More...
 
static void compute_correction (GrayWorldContext *s, ThreadData *td)
 Sum the channel totals and compute the mean for each channel. More...
 
static int correct_frame (AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 Subtract the mean logspace AB values from each pixel. More...
 
static int config_input (AVFilterLink *inlink)
 
static av_cold void uninit (AVFilterContext *ctx)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *in)
 

Variables

static const AVOption grayworld_options []
 
static const float lms2lab [3][3]
 
static const float lab2lms [3][3]
 
static const float rgb2lms [3][3]
 
static const float lms2rgb [3][3]
 
static const AVFilterPad grayworld_inputs []
 
const AVFilter ff_vf_grayworld
 

Detailed Description

Color correction filter based on https://www.researchgate.net/publication/275213614_A_New_Color_Correction_Method_for_Underwater_Imaging

Definition in file vf_grayworld.c.

Macro Definition Documentation

◆ OFFSET

#define OFFSET (   x)    offsetof(GrayWorldContext, x)

Definition at line 49 of file vf_grayworld.c.

◆ FLAGS

Definition at line 50 of file vf_grayworld.c.

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( grayworld  )

◆ apply_matrix()

static void apply_matrix ( const float  matrix[3][3],
const float  input[3],
float  output[3] 
)
static

Definition at line 57 of file vf_grayworld.c.

Referenced by lab2rgb(), and rgb2lab().

◆ rgb2lab()

static void rgb2lab ( const float  rgb[3],
float  lab[3] 
)
static

Convert from Linear RGB to logspace LAB.

Parameters
rgbInput array of rgb components
laboutput array of lab components

Definition at line 94 of file vf_grayworld.c.

Referenced by convert_frame().

◆ lab2rgb()

static void lab2rgb ( const float  lab[3],
float  rgb[3] 
)
static

Convert from Logspace LAB to Linear RGB.

Parameters
labinput array of lab components
rgboutput array of rgb components

Definition at line 111 of file vf_grayworld.c.

Referenced by correct_frame().

◆ convert_frame()

static int convert_frame ( AVFilterContext ctx,
void *  arg,
int  jobnr,
int  nb_jobs 
)
static

Convert a frame from linear RGB to logspace LAB, and accumulate channel totals for each row Convert from RGB -> lms using equation 4 in color transfer paper.

Parameters
ctxFilter context
argThread data pointer
jobnrjob number
nb_jobsnumber of jobs

Definition at line 131 of file vf_grayworld.c.

Referenced by filter_frame().

◆ compute_correction()

static void compute_correction ( GrayWorldContext s,
ThreadData td 
)
static

Sum the channel totals and compute the mean for each channel.

Parameters
sFrame context
tdthread data

Definition at line 176 of file vf_grayworld.c.

Referenced by filter_frame().

◆ correct_frame()

static int correct_frame ( AVFilterContext ctx,
void *  arg,
int  jobnr,
int  nb_jobs 
)
static

Subtract the mean logspace AB values from each pixel.

Parameters
ctxFilter context
argThread data pointer
jobnrjob number
nb_jobsnumber of jobs

Definition at line 199 of file vf_grayworld.c.

Referenced by filter_frame().

◆ config_input()

static int config_input ( AVFilterLink inlink)
static

Definition at line 236 of file vf_grayworld.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 249 of file vf_grayworld.c.

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame in 
)
static

Definition at line 258 of file vf_grayworld.c.

Variable Documentation

◆ grayworld_options

const AVOption grayworld_options[]
static
Initial value:
= {
{ NULL }
}

Definition at line 51 of file vf_grayworld.c.

◆ lms2lab

const float lms2lab[3][3]
static
Initial value:
= {
{0.5774, 0.5774, 0.5774},
{0.40825, 0.40825, -0.816458},
{0.707, -0.707, 0}
}

Definition at line 64 of file vf_grayworld.c.

Referenced by rgb2lab().

◆ lab2lms

const float lab2lms[3][3]
static
Initial value:
= {
{0.57735, 0.40825, 0.707},
{0.57735, 0.40825, -0.707},
{0.57735, -0.8165, 0}
}

Definition at line 70 of file vf_grayworld.c.

Referenced by lab2rgb().

◆ rgb2lms

const float rgb2lms[3][3]
static
Initial value:
= {
{0.3811, 0.5783, 0.0402},
{0.1967, 0.7244, 0.0782},
{0.0241, 0.1288, 0.8444}
}

Definition at line 76 of file vf_grayworld.c.

Referenced by rgb2lab().

◆ lms2rgb

const float lms2rgb[3][3]
static
Initial value:
= {
{4.4679, -3.5873, 0.1193},
{-1.2186, 2.3809, -0.1624},
{0.0497, -0.2439, 1.2045}
}

Definition at line 82 of file vf_grayworld.c.

Referenced by lab2rgb().

◆ grayworld_inputs

const AVFilterPad grayworld_inputs[]
static
Initial value:
= {
{
.name = "default",
.filter_frame = filter_frame,
.config_props = config_input,
}
}

Definition at line 300 of file vf_grayworld.c.

◆ ff_vf_grayworld

const AVFilter ff_vf_grayworld
Initial value:
= {
.name = "grayworld",
.description = NULL_IF_CONFIG_SMALL("Adjust white balance using LAB gray world algorithm"),
.priv_size = sizeof(GrayWorldContext),
.priv_class = &grayworld_class,
.uninit = uninit,
}

Definition at line 309 of file vf_grayworld.c.

uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_grayworld.c:249
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_grayworld.c:258
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:36
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:192
NULL
#define NULL
Definition: coverity.c:32
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:106
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_grayworld.c:236
FILTER_PIXFMTS
#define FILTER_PIXFMTS(...)
Definition: internal.h:178
AV_PIX_FMT_GBRPF32
#define AV_PIX_FMT_GBRPF32
Definition: pixfmt.h:498
GrayWorldContext
Definition: vf_grayworld.c:42
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:147
AV_PIX_FMT_GBRAPF32
#define AV_PIX_FMT_GBRAPF32
Definition: pixfmt.h:499
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:117
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:193
grayworld_inputs
static const AVFilterPad grayworld_inputs[]
Definition: vf_grayworld.c:300