Go to the documentation of this file.
51 #define OFFSET(x) offsetof(GrayWorldContext, x)
52 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_RUNTIME_PARAM
67 {0.5774, 0.5774, 0.5774},
68 {0.40825, 0.40825, -0.816458},
73 {0.57735, 0.40825, 0.707},
74 {0.57735, 0.40825, -0.707},
79 {0.3811, 0.5783, 0.0402},
80 {0.1967, 0.7244, 0.0782},
81 {0.0241, 0.1288, 0.8444}
85 {4.4679, -3.5873, 0.1193},
86 {-1.2186, 2.3809, -0.1624},
87 {0.0497, -0.2439, 1.2045}
101 lms[0] = lms[0] > 0.f ? logf(lms[0]) : -1024.f;
102 lms[1] = lms[1] > 0.f ? logf(lms[1]) : -1024.f;
103 lms[2] = lms[2] > 0.f ? logf(lms[2]) : -1024.f;
118 lms[0] =
expf(lms[0]);
119 lms[1] =
expf(lms[1]);
120 lms[2] =
expf(lms[2]);
140 const int slice_start = (
out->height * jobnr) / nb_jobs;
141 const int slice_end = (
out->height * (jobnr + 1)) / nb_jobs;
142 float rgb[3], lab[3];
145 float *b_in_row = (
float *)(in->
data[1] +
i * in->
linesize[1]);
146 float *g_in_row = (
float *)(in->
data[0] +
i * in->
linesize[0]);
147 float *r_in_row = (
float *)(in->
data[2] +
i * in->
linesize[2]);
148 float *acur =
s->tmpplab +
i * outlink->
w + outlink->
w * outlink->
h;
149 float *bcur =
s->tmpplab +
i * outlink->
w + 2 * outlink->
w * outlink->
h;
150 float *lcur =
s->tmpplab +
i * outlink->
w;
152 s->line_sum[
i] = 0.f;
153 s->line_sum[
i + outlink->
h] = 0.f;
154 s->line_count_pels[
i] = 0;
156 for (
int j = 0; j < outlink->
w; j++) {
157 rgb[0] = r_in_row[j];
158 rgb[1] = g_in_row[j];
159 rgb[2] = b_in_row[j];
164 s->line_sum[
i] += lab[1];
165 s->line_sum[
i + outlink->
h] += lab[2];
166 s->line_count_pels[
i]++;
180 float asum = 0.f, bsum = 0.f;
183 for (
int y = 0; y <
td->out->height; y++) {
184 asum +=
s->line_sum[y];
185 bsum +=
s->line_sum[y +
td->out->height];
186 pixels +=
s->line_count_pels[y];
189 td->a_avg = asum / pixels;
190 td->b_avg = bsum / pixels;
207 const int slice_start = (
out->height * jobnr) / nb_jobs;
208 const int slice_end = (
out->height * (jobnr + 1)) / nb_jobs;
209 float rgb[3], lab[3];
212 float *g_out_row = (
float *)(
out->data[0] +
i *
out->linesize[0]);
213 float *b_out_row = (
float *)(
out->data[1] +
i *
out->linesize[1]);
214 float *r_out_row = (
float *)(
out->data[2] +
i *
out->linesize[2]);
215 float *lcur =
s->tmpplab +
i * outlink->
w;
216 float *acur =
s->tmpplab +
i * outlink->
w + outlink->
w * outlink->
h;
217 float *bcur =
s->tmpplab +
i * outlink->
w + 2 * outlink->
w * outlink->
h;
219 for (
int j = 0; j < outlink->
w; j++) {
230 r_out_row[j] =
rgb[0];
231 g_out_row[j] =
rgb[1];
232 b_out_row[j] =
rgb[2];
245 if (!
s->tmpplab || !
s->line_count_pels || !
s->line_sum)
322 .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.
static const AVFilterPad grayworld_outputs[]
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]
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[]