Go to the documentation of this file.
49 #define OFFSET(x) offsetof(GrayWorldContext, x)
50 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_RUNTIME_PARAM
65 {0.5774, 0.5774, 0.5774},
66 {0.40825, 0.40825, -0.816458},
71 {0.57735, 0.40825, 0.707},
72 {0.57735, 0.40825, -0.707},
77 {0.3811, 0.5783, 0.0402},
78 {0.1967, 0.7244, 0.0782},
79 {0.0241, 0.1288, 0.8444}
83 {4.4679, -3.5873, 0.1193},
84 {-1.2186, 2.3809, -0.1624},
85 {0.0497, -0.2439, 1.2045}
99 lms[0] = lms[0] > 0.f ? logf(lms[0]) : -1024.f;
100 lms[1] = lms[1] > 0.f ? logf(lms[1]) : -1024.f;
101 lms[2] = lms[2] > 0.f ? logf(lms[2]) : -1024.f;
116 lms[0] =
expf(lms[0]);
117 lms[1] =
expf(lms[1]);
118 lms[2] =
expf(lms[2]);
138 const int slice_start = (
out->height * jobnr) / nb_jobs;
139 const int slice_end = (
out->height * (jobnr + 1)) / nb_jobs;
140 float rgb[3], lab[3];
143 float *b_in_row = (
float *)(in->
data[1] +
i * in->
linesize[1]);
144 float *g_in_row = (
float *)(in->
data[0] +
i * in->
linesize[0]);
145 float *r_in_row = (
float *)(in->
data[2] +
i * in->
linesize[2]);
146 float *acur =
s->tmpplab +
i * outlink->
w + outlink->
w * outlink->
h;
147 float *bcur =
s->tmpplab +
i * outlink->
w + 2 * outlink->
w * outlink->
h;
148 float *lcur =
s->tmpplab +
i * outlink->
w;
150 s->line_sum[
i] = 0.f;
151 s->line_sum[
i + outlink->
h] = 0.f;
152 s->line_count_pels[
i] = 0;
154 for (
int j = 0; j < outlink->
w; j++) {
155 rgb[0] = r_in_row[j];
156 rgb[1] = g_in_row[j];
157 rgb[2] = b_in_row[j];
162 s->line_sum[
i] += lab[1];
163 s->line_sum[
i + outlink->
h] += lab[2];
164 s->line_count_pels[
i]++;
178 float asum = 0.f, bsum = 0.f;
181 for (
int y = 0; y <
td->out->height; y++) {
182 asum +=
s->line_sum[y];
183 bsum +=
s->line_sum[y +
td->out->height];
184 pixels +=
s->line_count_pels[y];
187 td->a_avg = asum / pixels;
188 td->b_avg = bsum / pixels;
205 const int slice_start = (
out->height * jobnr) / nb_jobs;
206 const int slice_end = (
out->height * (jobnr + 1)) / nb_jobs;
207 float rgb[3], lab[3];
210 float *g_out_row = (
float *)(
out->data[0] +
i *
out->linesize[0]);
211 float *b_out_row = (
float *)(
out->data[1] +
i *
out->linesize[1]);
212 float *r_out_row = (
float *)(
out->data[2] +
i *
out->linesize[2]);
213 float *lcur =
s->tmpplab +
i * outlink->
w;
214 float *acur =
s->tmpplab +
i * outlink->
w + outlink->
w * outlink->
h;
215 float *bcur =
s->tmpplab +
i * outlink->
w + 2 * outlink->
w * outlink->
h;
217 for (
int j = 0; j < outlink->
w; j++) {
228 r_out_row[j] =
rgb[0];
229 g_out_row[j] =
rgb[1];
230 b_out_row[j] =
rgb[2];
243 if (!
s->tmpplab || !
s->line_count_pels || !
s->line_sum)
313 .priv_class = &grayworld_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
enum AVColorTransferCharacteristic color_trc
#define AV_LOG_WARNING
Something somehow does not look correct.
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 f...
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
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
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.
This structure describes decoded (raw) audio or video data.
static av_cold void uninit(AVFilterContext *ctx)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
const char * name
Filter name.
A link between two filters.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
#define FF_ALLOC_TYPED_ARRAY(p, nelem)
static void compute_correction(GrayWorldContext *s, ThreadData *td)
Sum the channel totals and compute the mean for each channel.
A filter pad used for either input or output.
static const float lms2rgb[3][3]
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 slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
static void lab2rgb(const float lab[3], float rgb[3])
Convert from Logspace LAB to Linear RGB.
static void apply_matrix(const float matrix[3][3], const float input[3], float output[3])
#define FILTER_INPUTS(array)
Describe the class of an AVClass context structure.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
const AVFilter ff_vf_grayworld
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static int config_input(AVFilterLink *inlink)
#define FILTER_PIXFMTS(...)
#define AV_PIX_FMT_GBRPF32
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
AVFILTER_DEFINE_CLASS(grayworld)
#define i(width, name, range_min, range_max)
int w
agreed upon image width
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Used for passing data between threads.
const char * name
Pad name.
static const float rgb2lms[3][3]
static void rgb2lab(const float rgb[3], float lab[3])
Convert from Linear RGB to logspace LAB.
static const float lms2lab[3][3]
int h
agreed upon image height
#define AV_PIX_FMT_GBRAPF32
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
#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 const float lab2lms[3][3]
static int correct_frame(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Subtract the mean logspace AB values from each pixel.
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
static const AVFilterPad grayworld_inputs[]
static const AVOption grayworld_options[]