2 * Original MPlayer filters by Richard Felker, Hampa Hug, Daniel Moreno,
3 * and Michael Niedermeyer.
5 * Copyright (c) 2014 James Darnley <james.darnley@gmail.com>
6 * Copyright (c) 2015 Arwa Arif <arwaarif1994@gmail.com>
8 * This file is part of FFmpeg.
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.
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.
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.
29 #include "libavutil/eval.h"
31 static const char *const var_names[] = {
34 "pos", // frame position
37 "t", // timestamp expressed in seconds
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);
57 double brightness, contrast, gamma, gamma_weight;
62 typedef struct EQContext {
65 EQParameters param[3];
68 AVExpr *contrast_pexpr;
71 char *brightness_expr;
72 AVExpr *brightness_pexpr;
75 char *saturation_expr;
76 AVExpr *saturation_pexpr;
83 char *gamma_weight_expr;
84 AVExpr *gamma_weight_pexpr;
88 AVExpr *gamma_r_pexpr;
92 AVExpr *gamma_g_pexpr;
96 AVExpr *gamma_b_pexpr;
99 double var_values[VAR_NB];
101 void (*process)(struct EQParameters *par, uint8_t *dst, int dst_stride,
102 const uint8_t *src, int src_stride, int w, int h);
104 enum EvalMode { EVAL_MODE_INIT, EVAL_MODE_FRAME, EVAL_MODE_NB } eval_mode;
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)
110 int contrast = (int) (param->contrast * 256 * 16);
111 int brightness = ((int) (100.0 * param->brightness + 100.0) * 511) / 200 - 128 - contrast / 32;
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;
120 dst[y * dst_stride + x] = pel;
125 void ff_eq_init_x86(EQContext *eq);
127 static av_unused void ff_eq_init(EQContext *eq)
129 eq->process = process_c;
135 #endif /* AVFILTER_EQ_H */