Go to the documentation of this file.
40 #define GREY_EDGE "greyedge"
42 #define SQRT3 1.73205080757
45 #define MAX_DIFF_ORD 2
46 #define MAX_META_DATA 4
53 #define INDEX_NORM INDEX_DX
90 #define OFFSET(x) offsetof(ColorConstancyContext, x)
91 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
93 #define GINDX(s, i) ( (i) - ((s) >> 2) )
110 int filtersize =
s->filtersize;
111 int difford =
s->difford;
112 double sigma =
s->sigma;
116 for (
i = 0;
i <= difford; ++
i) {
119 for (;
i >= 0; --
i) {
132 for (
i = 0;
i < filtersize; ++
i) {
133 s->gauss[0][
i] =
exp(- pow(
GINDX(filtersize,
i), 2.) / (2 * sigma * sigma)) / ( sqrt(2 *
M_PI) * sigma );
134 sum1 +=
s->gauss[0][
i];
136 for (
i = 0;
i < filtersize; ++
i) {
137 s->gauss[0][
i] /= sum1;
144 for (
i = 0;
i < filtersize; ++
i) {
145 s->gauss[1][
i] = - (
GINDX(filtersize,
i) / pow(sigma, 2)) *
s->gauss[0][
i];
146 sum1 +=
s->gauss[1][
i] *
GINDX(filtersize,
i);
149 for (
i = 0;
i < filtersize; ++
i) {
150 s->gauss[1][
i] /= sum1;
157 for (
i = 0;
i < filtersize; ++
i) {
158 s->gauss[2][
i] = ( pow(
GINDX(filtersize,
i), 2) / pow(sigma, 4) - 1/pow(sigma, 2) )
160 sum1 +=
s->gauss[2][
i];
164 for (
i = 0;
i < filtersize; ++
i) {
165 s->gauss[2][
i] -= sum1 / (filtersize);
166 sum2 += (0.5 *
GINDX(filtersize,
i) *
GINDX(filtersize,
i) *
s->gauss[2][
i]);
168 for (
i = 0;
i < filtersize ; ++
i) {
169 s->gauss[2][
i] /= sum2;
190 for (
b = 0;
b < nb_buff; ++
b) {
196 for (p = 0; p < nb_planes; ++p) {
214 int nb_buff =
s->difford + 1;
218 for (
b = 0;
b <= nb_buff; ++
b) {
221 sizeof(*
td->data[
b][p]));
222 if (!
td->data[
b][p]) {
231 #define CLAMP(x, mx) av_clip((x), 0, (mx-1))
232 #define INDX2D(r, c, w) ( (r) * (w) + (c) )
233 #define GAUSS(s, sr, sc, sls, sh, sw, g) ( (s)[ INDX2D(CLAMP((sr), (sh)), CLAMP((sc), (sw)), (sls)) ] * (g) )
257 const int filtersize =
s->filtersize;
258 const double *gauss =
s->gauss[ord];
261 for (plane = 0; plane <
NUM_PLANES; ++plane) {
262 const int height =
s->planeheight[plane];
263 const int width =
s->planewidth[plane];
264 const int in_linesize = in->
linesize[plane];
265 double *dst =
td->data[dst_index][plane];
271 const uint8_t *
src = in->
data[plane];
272 slice_start = (
height * jobnr ) / nb_jobs;
278 for (
g = 0;
g < filtersize; ++
g) {
286 const double *
src =
td->data[src_index][plane];
287 slice_start = (
width * jobnr ) / nb_jobs;
293 for (
g = 0;
g < filtersize; ++
g) {
320 const int difford =
s->difford;
323 for (plane = 0; plane <
NUM_PLANES; ++plane) {
324 const int height =
s->planeheight[plane];
325 const int width =
s->planewidth[plane];
327 const int slice_start = (numpixels * jobnr ) / nb_jobs;
328 const int slice_end = (numpixels * (jobnr+1)) / nb_jobs;
336 norm[
i] = sqrt( pow(dx[
i], 2) + pow(dy[
i], 2));
341 norm[
i] = sqrt( pow(dx[
i], 2) + 4 * pow(dxy[
i], 2) + pow(dy[
i], 2) );
363 int src,
int dst,
int dim,
int nb_threads) {
384 int nb_threads =
s->nb_threads;
385 int height =
s->planeheight[1];
386 int width =
s->planewidth[1];
442 int minknorm =
s->minknorm;
443 const uint8_t thresh = 255;
446 for (plane = 0; plane <
NUM_PLANES; ++plane) {
447 const int height =
s->planeheight[plane];
448 const int width =
s->planewidth[plane];
449 const int in_linesize = in->
linesize[plane];
450 const int slice_start = (
height * jobnr) / nb_jobs;
452 const uint8_t *img_data = in->
data[plane];
462 * (img_data[
INDX2D(
r,
c, in_linesize)] < thresh) );
469 * (img_data[
INDX2D(
r,
c, in_linesize)] < thresh) );
490 int minknorm =
s->minknorm;
491 int difford =
s->difford;
492 double *white =
s->white;
493 int nb_jobs =
FFMIN3(
s->planeheight[1],
s->planewidth[1],
s->nb_threads);
508 for (plane = 0; plane <
NUM_PLANES; ++plane) {
510 for (job = 0; job < nb_jobs; ++job) {
515 for (plane = 0; plane <
NUM_PLANES; ++plane) {
517 for (job = 0; job < nb_jobs; ++job) {
520 white[plane] = pow(white[plane], 1./minknorm);
536 double abs_val = pow( pow(light[0], 2.0) + pow(light[1], 2.0) + pow(light[2], 2.0), 0.5);
542 for (plane = 0; plane <
NUM_PLANES; ++plane) {
546 for (plane = 0; plane <
NUM_PLANES; ++plane) {
547 light[plane] = (light[plane] / abs_val);
573 s->white[0],
s->white[1],
s->white[2]);
576 s->white[0],
s->white[1],
s->white[2]);
599 for (plane = 0; plane <
NUM_PLANES; ++plane) {
600 const int height =
s->planeheight[plane];
601 const int width =
s->planewidth[plane];
603 const int slice_start = (numpixels * jobnr) / nb_jobs;
604 const int slice_end = (numpixels * (jobnr+1)) / nb_jobs;
605 const uint8_t *
src = in->
data[plane];
606 uint8_t *dst =
out->data[plane];
630 int nb_jobs =
FFMIN3(
s->planeheight[1],
s->planewidth[1],
s->nb_threads);
642 const double break_off_sigma = 3.0;
643 double sigma =
s->sigma;
646 if (!
floor(break_off_sigma * sigma + 0.5) &&
s->difford) {
651 s->filtersize = 2 *
floor(break_off_sigma * sigma + 0.5) + 1;
658 s->planewidth[0] =
s->planewidth[3] =
inlink->w;
660 s->planeheight[0] =
s->planeheight[3] =
inlink->h;
701 int difford =
s->difford;
704 for (
i = 0;
i <= difford; ++
i) {
731 .priv_class = &greyedge_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Common struct for all algorithms contexts.
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
static int filter_slice_grey_edge(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Slice function for grey edge algorithm that does partial summing/maximizing of gaussian derivatives.
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 av_cold void uninit(AVFilterContext *ctx)
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
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static int get_derivative(AVFilterContext *ctx, ThreadData *td)
Main control function for calculating gaussian derivatives.
#define GAUSS(s, sr, sc, sls, sh, sw, g)
This structure describes decoded (raw) audio or video data.
const char * name
Filter name.
static int slice_get_derivative(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Slice calculation of gaussian derivatives.
static void normalize_light(double *light)
Normalizes estimated illumination since only illumination vector direction is required for color cons...
A link between two filters.
static void chromatic_adaptation(AVFilterContext *ctx, AVFrame *in, AVFrame *out)
Main control function for correcting scene illumination based on estimated illumination.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static const AVOption greyedge_options[]
static int filter_grey_edge(AVFilterContext *ctx, AVFrame *in)
Main control function for grey edge algorithm.
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static void av_always_inline get_deriv(AVFilterContext *ctx, ThreadData *td, int ord, int dir, int src, int dst, int dim, int nb_threads)
Utility function for setting up differentiation data/metadata.
A filter pad used for either input or output.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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 config_props(AVFilterLink *inlink)
#define AV_CEIL_RSHIFT(a, b)
static __device__ float floor(float a)
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int minknorm
@minknorm = 0 : getMax instead
#define FILTER_INPUTS(array)
Describe the class of an AVClass context structure.
static __device__ float fabs(float a)
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
static int setup_derivative_buffers(AVFilterContext *ctx, ThreadData *td)
Allocates buffers used by grey edge for storing derivatives final and intermidiate results.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
static void cleanup_derivative_buffers(ThreadData *td, int nb_buff, int nb_planes)
Frees up buffers used by grey edge for storing derivatives final and intermidiate results.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
static int set_gauss(AVFilterContext *ctx)
Sets gauss filters used for calculating gauss derivatives.
#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 FILTER_SINGLE_PIXFMT(pix_fmt_)
#define i(width, name, range_min, range_max)
int w
agreed upon image width
static int illumination_estimation(AVFilterContext *ctx, AVFrame *in)
Redirects to corresponding algorithm estimation function and performs normalization after estimation.
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Used for passing data between threads.
double * data[MAX_DATA][NUM_PLANES]
static int diagonal_transformation(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Performs simple correction via diagonal transformation model.
const char * name
Pad name.
void * av_calloc(size_t nmemb, size_t size)
const AVFilter ff_vf_greyedge
int meta_data[MAX_META_DATA]
int h
agreed upon image height
static int slice_normalize(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Slice Frobius normalization of gaussian derivatives.
AVFILTER_DEFINE_CLASS(greyedge)
static const AVFilterPad colorconstancy_inputs[]
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
double * gauss[MAX_DIFF_ORD+1]
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
#define FILTER_OUTPUTS(array)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)