124#define OFFSET(x) offsetof(NormalizeContext, x)
125#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
126#define FLAGSR AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
141 for (
int c = 0;
c < 3;
c++)
143 for (
int y = 0; y < in->
height; y++) {
145 for (
int x = 0; x < in->
width; x++) {
146 for (
int c = 0;
c < 3;
c++) {
157 for (
int y = 0; y < in->
height; y++) {
159 uint8_t *outp =
out->data[0] + y *
out->linesize[0];
160 for (
int x = 0; x < in->
width; x++) {
161 for (
int c = 0;
c < 3;
c++)
162 outp[
s->co[
c]] =
s->lut[
c][inp[
s->co[
c]]];
163 if (
s->num_components == 4)
165 outp[
s->co[3]] = inp[
s->co[3]];
177 for (
int y = 0; y < in->
height; y++) {
181 for (
int x = 0; x < in->
width; x++) {
194 for (
int y = 0; y < in->
height; y++) {
199 uint8_t *outrp =
out->data[2] + y *
out->linesize[2];
200 uint8_t *outgp =
out->data[0] + y *
out->linesize[0];
201 uint8_t *outbp =
out->data[1] + y *
out->linesize[1];
202 uint8_t *outap =
out->data[3] + y *
out->linesize[3];
203 for (
int x = 0; x < in->
width; x++) {
204 outrp[x] =
s->lut[0][inrp[x]];
205 outgp[x] =
s->lut[1][ingp[x]];
206 outbp[x] =
s->lut[2][inbp[x]];
207 if (
s->num_components == 4)
215 for (
int c = 0;
c < 3;
c++)
217 for (
int y = 0; y < in->
height; y++) {
218 uint16_t *inp = (uint16_t *)(in->
data[0] + y * in->
linesize[0]);
219 for (
int x = 0; x < in->
width; x++) {
220 for (
int c = 0;
c < 3;
c++) {
231 for (
int y = 0; y < in->
height; y++) {
232 uint16_t *inp = (uint16_t *)(in->
data[0] + y * in->
linesize[0]);
233 uint16_t *outp = (uint16_t *)(
out->data[0] + y *
out->linesize[0]);
234 for (
int x = 0; x < in->
width; x++) {
235 for (
int c = 0;
c < 3;
c++)
236 outp[
s->co[
c]] =
s->lut[
c][inp[
s->co[
c]]];
237 if (
s->num_components == 4)
239 outp[
s->co[3]] = inp[
s->co[3]];
251 for (
int y = 0; y < in->
height; y++) {
252 uint16_t *inrp = (uint16_t *)(in->
data[2] + y * in->
linesize[2]);
253 uint16_t *ingp = (uint16_t *)(in->
data[0] + y * in->
linesize[0]);
254 uint16_t *inbp = (uint16_t *)(in->
data[1] + y * in->
linesize[1]);
255 for (
int x = 0; x < in->
width; x++) {
268 for (
int y = 0; y < in->
height; y++) {
269 uint16_t *inrp = (uint16_t *)(in->
data[2] + y * in->
linesize[2]);
270 uint16_t *ingp = (uint16_t *)(in->
data[0] + y * in->
linesize[0]);
271 uint16_t *inbp = (uint16_t *)(in->
data[1] + y * in->
linesize[1]);
272 uint16_t *inap = (uint16_t *)(in->
data[3] + y * in->
linesize[3]);
273 uint16_t *outrp = (uint16_t *)(
out->data[2] + y *
out->linesize[2]);
274 uint16_t *outgp = (uint16_t *)(
out->data[0] + y *
out->linesize[0]);
275 uint16_t *outbp = (uint16_t *)(
out->data[1] + y *
out->linesize[1]);
276 uint16_t *outap = (uint16_t *)(
out->data[3] + y *
out->linesize[3]);
277 for (
int x = 0; x < in->
width; x++) {
278 outrp[x] =
s->lut[0][inrp[x]];
279 outgp[x] =
s->lut[1][ingp[x]];
280 outbp[x] =
s->lut[2][inbp[x]];
281 if (
s->num_components == 4)
295 float rgb_min_smoothed;
296 float rgb_max_smoothed;
306 int history_idx =
s->frame_num %
s->history_len;
309 int num_history_vals =
s->frame_num + 1;
310 if (
s->frame_num >=
s->history_len) {
312 for (
c = 0;
c < 3;
c++) {
313 s->min[
c].history_sum -=
s->min[
c].history[history_idx];
314 s->max[
c].history_sum -=
s->max[
c].history[history_idx];
316 num_history_vals =
s->history_len;
320 for (
c = 0;
c < 3;
c++) {
321 s->min[
c].history_sum += (
s->min[
c].history[history_idx] =
min[
c].in);
322 min[
c].smoothed =
s->min[
c].history_sum / (
float)num_history_vals;
323 s->max[
c].history_sum += (
s->max[
c].history[history_idx] =
max[
c].in);
324 max[
c].smoothed =
s->max[
c].history_sum / (
float)num_history_vals;
331 rgb_min_smoothed =
FFMIN3(
min[0].smoothed,
min[1].smoothed,
min[2].smoothed);
332 rgb_max_smoothed =
FFMAX3(
max[0].smoothed,
max[1].smoothed,
max[2].smoothed);
336 for (
c = 0;
c < 3;
c++) {
341 min[
c].smoothed = (
min[
c].smoothed *
s->independence)
342 + (rgb_min_smoothed * (1.0f -
s->independence));
343 max[
c].smoothed = (
max[
c].smoothed *
s->independence)
344 + (rgb_max_smoothed * (1.0f -
s->independence));
349 min[
c].out = (
s->sblackpt[
c] *
s->strength)
350 + (
min[
c].in * (1.0f -
s->strength));
351 max[
c].out = (
s->swhitept[
c] *
s->strength)
352 + (
max[
c].in * (1.0f -
s->strength));
359 if (
min[
c].smoothed ==
max[
c].smoothed) {
361 for (in_val =
min[
c].in; in_val <=
max[
c].in; in_val++)
362 s->lut[
c][in_val] =
min[
c].out;
369 for (in_val =
min[
c].in; in_val <=
max[
c].in; in_val++) {
372 s->lut[
c][in_val] = out_val;
378 s->process(
s, in,
out);
420 s->depth =
desc->comp[0].depth;
421 scale = 1 << (
s->depth - 8);
422 s->num_components =
desc->nb_components;
429 s->history_len =
s->smoothing + 1;
433 s->history_mem =
av_malloc(
s->history_len * 6 *
sizeof(*
s->history_mem));
434 if (
s->history_mem ==
NULL)
437 for (
c = 0;
c < 3;
c++) {
438 s->min[
c].history =
s->history_mem + (
c*2) *
s->history_len;
439 s->max[
c].history =
s->history_mem + (
c*2+1) *
s->history_len;
440 s->sblackpt[
c] =
scale *
s->blackpt[
c] + (
s->blackpt[
c] & (1 << (
s->depth - 8)));
441 s->swhitept[
c] =
scale *
s->whitept[
c] + (
s->whitept[
c] & (1 << (
s->depth - 8)));
493 if (
ctx->is_disabled) {
514 .p.name =
"normalize",
516 .p.priv_class = &normalize_class,
static const AVFilterPad inputs[]
static int config_input(AVFilterLink *inlink)
const FFFilter ff_vf_normalize
static AVFormatContext * ctx
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
Main libavfilter public API header.
static av_always_inline av_const unsigned av_clip_uintp2_c(int a, int p)
Clip a signed integer to an unsigned power of two range.
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
@ AV_OPT_TYPE_COLOR
Underlying C type is uint8_t[4].
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FILTER_PIXFMTS_ARRAY(array)
#define AVFILTER_DEFINE_CLASS(fname)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Memory handling functions.
int av_get_padded_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel for the pixel format described by pixdesc, including any padding ...
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
#define AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_GBRP12
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
#define AV_PIX_FMT_BGRA64
#define AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP14
Describe the class of an AVClass context structure.
void * priv
private data for use by the filter
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * dst
dest filter
int format
agreed upon media format
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
void(* process)(struct NormalizeContext *s, AVFrame *in, AVFrame *out)
void(* find_min_max)(struct NormalizeContext *s, AVFrame *in, NormalizeLocal min[3], NormalizeLocal max[3])
static enum AVPixelFormat pixel_fmts[]
static void find_min_max_planar(NormalizeContext *s, AVFrame *in, NormalizeLocal min[3], NormalizeLocal max[3])
static const AVOption normalize_options[]
static void process_planar(NormalizeContext *s, AVFrame *in, AVFrame *out)
static void process(NormalizeContext *s, AVFrame *in, AVFrame *out)
static int config_input(AVFilterLink *inlink)
static void process_16(NormalizeContext *s, AVFrame *in, AVFrame *out)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static void find_min_max_planar_16(NormalizeContext *s, AVFrame *in, NormalizeLocal min[3], NormalizeLocal max[3])
static av_cold void uninit(AVFilterContext *ctx)
static void process_planar_16(NormalizeContext *s, AVFrame *in, AVFrame *out)
static void find_min_max_16(NormalizeContext *s, AVFrame *in, NormalizeLocal min[3], NormalizeLocal max[3])
static void find_min_max(NormalizeContext *s, AVFrame *in, NormalizeLocal min[3], NormalizeLocal max[3])
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.