FFmpeg
vf_eq.h
Go to the documentation of this file.
1 /*
2  * Original MPlayer filters by Richard Felker, Hampa Hug, Daniel Moreno,
3  * and Michael Niedermeyer.
4  *
5  * Copyright (c) 2014 James Darnley <james.darnley@gmail.com>
6  * Copyright (c) 2015 Arwa Arif <arwaarif1994@gmail.com>
7  *
8  * This file is part of FFmpeg.
9  *
10  * FFmpeg is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * FFmpeg is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License along
21  * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24 
25 #ifndef AVFILTER_EQ_H
26 #define AVFILTER_EQ_H
27 
28 #include "avfilter.h"
29 #include "libavutil/eval.h"
30 
31 static const char *const var_names[] = {
32  "n", // frame count
33 #if FF_API_FRAME_PKT
34  "pos", // frame position
35 #endif
36  "r", // frame rate
37  "t", // timestamp expressed in seconds
38  NULL
39 };
40 
41 enum var_name {
43 #if FF_API_FRAME_PKT
44  VAR_POS,
45 #endif
49 };
50 
51 typedef struct EQParameters {
52  void (*adjust)(struct EQParameters *eq, uint8_t *dst, int dst_stride,
53  const uint8_t *src, int src_stride, int w, int h);
54 
55  uint8_t lut[256];
56 
58  int lut_clean;
59 
60 } EQParameters;
61 
62 typedef struct EQContext {
63  const AVClass *class;
64 
66 
69  double contrast;
70 
73  double brightness;
74 
77  double saturation;
78 
79  char *gamma_expr;
81  double gamma;
82 
85  double gamma_weight;
86 
87  char *gamma_r_expr;
89  double gamma_r;
90 
91  char *gamma_g_expr;
93  double gamma_g;
94 
95  char *gamma_b_expr;
97  double gamma_b;
98 
99  double var_values[VAR_NB];
100 
101  void (*process)(struct EQParameters *par, uint8_t *dst, int dst_stride,
102  const uint8_t *src, int src_stride, int w, int h);
103 
105 } EQContext;
106 
107 static void process_c(EQParameters *param, uint8_t *dst, int dst_stride,
108  const uint8_t *src, int src_stride, int w, int h)
109 {
110  int contrast = (int) (param->contrast * 256 * 16);
111  int brightness = ((int) (100.0 * param->brightness + 100.0) * 511) / 200 - 128 - contrast / 32;
112 
113  for (int y = 0; y < h; y++) {
114  for (int x = 0; x < w; x++) {
115  int pel = ((src[y * src_stride + x] * contrast) >> 12) + brightness;
116 
117  if (pel & ~255)
118  pel = (-pel) >> 31;
119 
120  dst[y * dst_stride + x] = pel;
121  }
122  }
123 }
124 
126 
128 {
129  eq->process = process_c;
130 #if ARCH_X86
132 #endif
133 }
134 
135 #endif /* AVFILTER_EQ_H */
EQParameters::gamma_weight
double gamma_weight
Definition: vf_eq.h:57
EQContext::gamma_expr
char * gamma_expr
Definition: vf_eq.h:79
EQParameters::gamma
double gamma
Definition: vf_eq.h:57
var_name
var_name
Definition: noise.c:46
EQContext::gamma_pexpr
AVExpr * gamma_pexpr
Definition: vf_eq.h:80
av_unused
#define av_unused
Definition: attributes.h:131
w
uint8_t w
Definition: llviddspenc.c:38
EQContext::EvalMode
EvalMode
Definition: vf_eq.h:104
EQContext::gamma_weight
double gamma_weight
Definition: vf_eq.h:85
EQContext::param
EQParameters param[3]
Definition: vf_eq.h:65
ff_eq_init
static av_unused void ff_eq_init(EQContext *eq)
Definition: vf_eq.h:127
EQContext::brightness_expr
char * brightness_expr
Definition: vf_eq.h:71
eq
#define eq(A, B)
Definition: vf_xbr.c:91
VAR_NB
@ VAR_NB
Definition: vf_eq.h:48
VAR_R
@ VAR_R
Definition: vf_eq.h:46
EQContext::saturation_pexpr
AVExpr * saturation_pexpr
Definition: vf_eq.h:76
EQParameters
Definition: vf_eq.h:51
AVExpr
Definition: eval.c:159
EQContext::gamma_g_expr
char * gamma_g_expr
Definition: vf_eq.h:91
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
EQContext::brightness
double brightness
Definition: vf_eq.h:73
EQContext::saturation
double saturation
Definition: vf_eq.h:77
NULL
#define NULL
Definition: coverity.c:32
VAR_POS
@ VAR_POS
Definition: noise.c:55
ff_eq_init_x86
void ff_eq_init_x86(EQContext *eq)
Definition: vf_eq_init.c:47
EQContext::gamma_weight_expr
char * gamma_weight_expr
Definition: vf_eq.h:83
EQContext::gamma_weight_pexpr
AVExpr * gamma_weight_pexpr
Definition: vf_eq.h:84
EQContext::eval_mode
enum EQContext::EvalMode eval_mode
var_names
static const char *const var_names[]
Definition: vf_eq.h:31
VAR_N
@ VAR_N
Definition: vf_eq.h:42
EQContext::gamma_r
double gamma_r
Definition: vf_eq.h:89
eval.h
EQContext
Definition: vf_eq.h:62
EQParameters::contrast
double contrast
Definition: vf_eq.h:57
EQContext::saturation_expr
char * saturation_expr
Definition: vf_eq.h:75
EQContext::contrast
double contrast
Definition: vf_eq.h:69
EQContext::gamma_b_expr
char * gamma_b_expr
Definition: vf_eq.h:95
EQContext::contrast_pexpr
AVExpr * contrast_pexpr
Definition: vf_eq.h:68
VAR_T
@ VAR_T
Definition: vf_eq.h:47
EQParameters::adjust
void(* adjust)(struct EQParameters *eq, uint8_t *dst, int dst_stride, const uint8_t *src, int src_stride, int w, int h)
Definition: vf_eq.h:52
EQContext::EVAL_MODE_NB
@ EVAL_MODE_NB
Definition: vf_eq.h:104
EQContext::gamma_b
double gamma_b
Definition: vf_eq.h:97
EQParameters::brightness
double brightness
Definition: vf_eq.h:57
EQParameters::lut
uint8_t lut[256]
Definition: vf_eq.h:55
avfilter.h
EQContext::var_values
double var_values[VAR_NB]
Definition: vf_eq.h:99
EQContext::contrast_expr
char * contrast_expr
Definition: vf_eq.h:67
EQContext::brightness_pexpr
AVExpr * brightness_pexpr
Definition: vf_eq.h:72
EQContext::gamma_g
double gamma_g
Definition: vf_eq.h:93
EQContext::EVAL_MODE_FRAME
@ EVAL_MODE_FRAME
Definition: vf_eq.h:104
EQParameters::lut_clean
int lut_clean
Definition: vf_eq.h:58
process_c
static void process_c(EQParameters *param, uint8_t *dst, int dst_stride, const uint8_t *src, int src_stride, int w, int h)
Definition: vf_eq.h:107
EQContext::EVAL_MODE_INIT
@ EVAL_MODE_INIT
Definition: vf_eq.h:104
EQContext::gamma_g_pexpr
AVExpr * gamma_g_pexpr
Definition: vf_eq.h:92
EQContext::gamma_r_expr
char * gamma_r_expr
Definition: vf_eq.h:87
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
EQContext::gamma
double gamma
Definition: vf_eq.h:81
EQContext::gamma_b_pexpr
AVExpr * gamma_b_pexpr
Definition: vf_eq.h:96
EQContext::process
void(* process)(struct EQParameters *par, uint8_t *dst, int dst_stride, const uint8_t *src, int src_stride, int w, int h)
Definition: vf_eq.h:101
h
h
Definition: vp9dsp_template.c:2038
int
int
Definition: ffmpeg_filter.c:409
EQContext::gamma_r_pexpr
AVExpr * gamma_r_pexpr
Definition: vf_eq.h:88