42 #define GREY_EDGE "greyedge" 44 #define SQRT3 1.73205080757 47 #define MAX_DIFF_ORD 2 48 #define MAX_META_DATA 4 55 #define INDEX_NORM INDEX_DX 92 #define OFFSET(x) offsetof(ColorConstancyContext, x) 93 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM 95 #define GINDX(s, i) ( (i) - ((s) >> 2) ) 114 double sigma = s->
sigma;
118 for (i = 0; i <= difford; ++
i) {
121 for (; i >= 0; --
i) {
135 for (i = 0; i < filtersize; ++
i) {
136 s->
gauss[0][
i] =
exp(- pow(
GINDX(filtersize, i), 2.) / (2 * sigma * sigma)) / ( sqrt(2 *
M_PI) * sigma );
139 for (i = 0; i < filtersize; ++
i) {
147 for (i = 0; i < filtersize; ++
i) {
149 sum1 += s->
gauss[1][i] *
GINDX(filtersize, i);
152 for (i = 0; i < filtersize; ++
i) {
160 for (i = 0; i < filtersize; ++
i) {
161 s->
gauss[2][
i] = ( pow(
GINDX(filtersize, i), 2) / pow(sigma, 4) - 1/pow(sigma, 2) )
163 sum1 += s->
gauss[2][i];
167 for (i = 0; i < filtersize; ++
i) {
168 s->
gauss[2][
i] -= sum1 / (filtersize);
169 sum2 += (0.5 *
GINDX(filtersize, i) *
GINDX(filtersize, i) * s->
gauss[2][
i]);
171 for (i = 0; i < filtersize ; ++
i) {
193 for (b = 0; b < nb_buff; ++
b) {
221 for (b = 0; b <= nb_buff; ++
b) {
224 if (!td->
data[b][p]) {
234 #define CLAMP(x, mx) av_clip((x), 0, (mx-1)) 235 #define INDX2D(r, c, w) ( (r) * (w) + (c) ) 236 #define GAUSS(s, sr, sc, sls, sh, sw, g) ( (s)[ INDX2D(CLAMP((sr), (sh)), CLAMP((sc), (sw)), (sls)) ] * (g) ) 261 const double *gauss = s->
gauss[ord];
275 slice_start = (height * jobnr ) / nb_jobs;
276 slice_end = (height * (jobnr + 1)) / nb_jobs;
279 for (c = 0; c <
width; ++
c) {
280 dst[
INDX2D(r, c, width)] = 0;
281 for (g = 0; g < filtersize; ++
g) {
283 in_linesize, height, width, gauss[
GINDX(filtersize, g)]);
290 slice_start = (width * jobnr ) / nb_jobs;
291 slice_end = (width * (jobnr + 1)) / nb_jobs;
295 dst[
INDX2D(r, c, width)] = 0;
296 for (g = 0; g < filtersize; ++
g) {
298 width, height, width, gauss[
GINDX(filtersize, g)]);
323 const int difford = s->
difford;
329 const int64_t numpixels = width * (int64_t)height;
330 const int slice_start = (numpixels * jobnr ) / nb_jobs;
331 const int slice_end = (numpixels * (jobnr+1)) / nb_jobs;
339 norm[
i] = sqrt( pow(dx[i], 2) + pow(dy[i], 2));
344 norm[
i] = sqrt( pow(dx[i], 2) + 4 * pow(dxy[i], 2) + pow(dy[i], 2) );
366 int src,
int dst,
int dim,
int nb_threads) {
452 const int slice_start = (height * jobnr) / nb_jobs;
453 const int slice_end = (height * (jobnr+1)) / nb_jobs;
462 for (c = 0; c <
width; ++
c) {
463 dst[jobnr] =
FFMAX( dst[jobnr], fabs(src[
INDX2D(r, c, width)])
464 * (img_data[
INDX2D(r, c, in_linesize)] < thresh) );
469 for (c = 0; c <
width; ++
c) {
470 dst[jobnr] += ( pow( fabs(src[
INDX2D(r, c, width)] / 255.), minknorm)
471 * (img_data[
INDX2D(r, c, in_linesize)] < thresh) );
494 double *white = s->
white;
512 for (job = 0; job < nb_jobs; ++job) {
519 for (job = 0; job < nb_jobs; ++job) {
522 white[
plane] = pow(white[plane], 1./minknorm);
538 double abs_val = pow( pow(light[0], 2.0) + pow(light[1], 2.0) + pow(light[2], 2.0), 0.5);
604 const int64_t numpixels = width * (int64_t)height;
605 const int slice_start = (numpixels * jobnr) / nb_jobs;
606 const int slice_end = (numpixels * (jobnr+1)) / nb_jobs;
614 dst[
i] = av_clip_uint8((
int)(temp + 0.5));
656 const double break_off_sigma = 3.0;
657 double sigma = s->
sigma;
660 if (!floor(break_off_sigma * sigma + 0.5) && s->
difford) {
661 av_log(ctx,
AV_LOG_ERROR,
"floor(%f * sigma) must be > 0 when difford > 0.\n", break_off_sigma);
665 s->
filtersize = 2 * floor(break_off_sigma * sigma + 0.5) + 1;
712 for (i = 0; i <= difford; ++
i) {
735 #if CONFIG_GREYEDGE_FILTER 737 static const AVOption greyedge_options[] = {
750 .priv_class = &greyedge_class,
753 .
inputs = colorconstancy_inputs,
754 .
outputs = colorconstancy_outputs,
static void chromatic_adaptation(AVFilterContext *ctx, AVFrame *in, AVFrame *out)
Main control function for correcting scene illumination based on estimated illumination.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
Main libavfilter public API header.
int h
agreed upon image height
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.
int minknorm
= 0 : getMax instead
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
static const AVFilterPad colorconstancy_outputs[]
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
const char * name
Pad name.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static int illumination_estimation(AVFilterContext *ctx, AVFrame *in)
Redirects to corresponding algorithm estimation function and performs normalization after estimation...
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
A filter pad used for either input or output.
static const AVFilterPad colorconstancy_inputs[]
A link between two filters.
#define i(width, name, range_min, range_max)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int w
agreed upon image width
static int set_gauss(AVFilterContext *ctx)
Sets gauss filters used for calculating gauss derivatives.
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
static int config_props(AVFilterLink *inlink)
Common struct for all algorithms contexts.
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 GAUSS(s, sr, sc, sls, sh, sw, g)
static const AVFilterPad inputs[]
double * data[MAX_DATA][NUM_PLANES]
static const AVFilterPad outputs[]
int format
agreed upon media format
static void normalize_light(double *light)
Normalizes estimated illumination since only illumination vector direction is required for color cons...
static av_cold void uninit(AVFilterContext *ctx)
static int setup_derivative_buffers(AVFilterContext *ctx, ThreadData *td)
Allocates buffers used by grey edge for storing derivatives final and intermidiate results...
static int slice_get_derivative(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Slice calculation of gaussian derivatives.
int meta_data[MAX_META_DATA]
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Used for passing data between threads.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static int diagonal_transformation(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Performs simple correction via diagonal transformation model.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Describe the class of an AVClass context structure.
double * gauss[MAX_DIFF_ORD+1]
const char * name
Filter name.
AVFilterLink ** outputs
array of pointers to output links
static enum AVPixelFormat pix_fmts[]
#define flags(name, subs,...)
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static int get_derivative(AVFilterContext *ctx, ThreadData *td)
Main control function for calculating gaussian derivatives.
avfilter_execute_func * execute
static int filter_grey_edge(AVFilterContext *ctx, AVFrame *in)
Main control function for grey edge algorithm.
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
AVFilterContext * dst
dest filter
#define AVFILTER_DEFINE_CLASS(fname)
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...
static int query_formats(AVFilterContext *ctx)
AVPixelFormat
Pixel format.
static int slice_normalize(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Slice Frobius normalization of gaussian derivatives.
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
#define AV_CEIL_RSHIFT(a, b)
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().