Line | Branch | Exec | Source |
---|---|---|---|
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 | "r", // frame rate | ||
34 | "t", // timestamp expressed in seconds | ||
35 | NULL | ||
36 | }; | ||
37 | |||
38 | enum var_name { | ||
39 | VAR_N, | ||
40 | VAR_R, | ||
41 | VAR_T, | ||
42 | VAR_NB | ||
43 | }; | ||
44 | |||
45 | typedef struct EQParameters { | ||
46 | void (*adjust)(struct EQParameters *eq, uint8_t *dst, int dst_stride, | ||
47 | const uint8_t *src, int src_stride, int w, int h); | ||
48 | |||
49 | uint8_t lut[256]; | ||
50 | |||
51 | double brightness, contrast, gamma, gamma_weight; | ||
52 | int lut_clean; | ||
53 | |||
54 | } EQParameters; | ||
55 | |||
56 | typedef struct EQContext { | ||
57 | const AVClass *class; | ||
58 | |||
59 | EQParameters param[3]; | ||
60 | |||
61 | char *contrast_expr; | ||
62 | AVExpr *contrast_pexpr; | ||
63 | double contrast; | ||
64 | |||
65 | char *brightness_expr; | ||
66 | AVExpr *brightness_pexpr; | ||
67 | double brightness; | ||
68 | |||
69 | char *saturation_expr; | ||
70 | AVExpr *saturation_pexpr; | ||
71 | double saturation; | ||
72 | |||
73 | char *gamma_expr; | ||
74 | AVExpr *gamma_pexpr; | ||
75 | double gamma; | ||
76 | |||
77 | char *gamma_weight_expr; | ||
78 | AVExpr *gamma_weight_pexpr; | ||
79 | double gamma_weight; | ||
80 | |||
81 | char *gamma_r_expr; | ||
82 | AVExpr *gamma_r_pexpr; | ||
83 | double gamma_r; | ||
84 | |||
85 | char *gamma_g_expr; | ||
86 | AVExpr *gamma_g_pexpr; | ||
87 | double gamma_g; | ||
88 | |||
89 | char *gamma_b_expr; | ||
90 | AVExpr *gamma_b_pexpr; | ||
91 | double gamma_b; | ||
92 | |||
93 | double var_values[VAR_NB]; | ||
94 | |||
95 | void (*process)(struct EQParameters *par, uint8_t *dst, int dst_stride, | ||
96 | const uint8_t *src, int src_stride, int w, int h); | ||
97 | |||
98 | enum EvalMode { EVAL_MODE_INIT, EVAL_MODE_FRAME, EVAL_MODE_NB } eval_mode; | ||
99 | } EQContext; | ||
100 | |||
101 | 3 | static void process_c(EQParameters *param, uint8_t *dst, int dst_stride, | |
102 | const uint8_t *src, int src_stride, int w, int h) | ||
103 | { | ||
104 | 3 | int contrast = (int) (param->contrast * 256 * 16); | |
105 | 3 | int brightness = ((int) (100.0 * param->brightness + 100.0) * 511) / 200 - 128 - contrast / 32; | |
106 | |||
107 |
2/2✓ Branch 0 taken 768 times.
✓ Branch 1 taken 3 times.
|
771 | for (int y = 0; y < h; y++) { |
108 |
2/2✓ Branch 0 taken 196608 times.
✓ Branch 1 taken 768 times.
|
197376 | for (int x = 0; x < w; x++) { |
109 | 196608 | int pel = ((src[y * src_stride + x] * contrast) >> 12) + brightness; | |
110 | |||
111 |
2/2✓ Branch 0 taken 162561 times.
✓ Branch 1 taken 34047 times.
|
196608 | if (pel & ~255) |
112 | 162561 | pel = (-pel) >> 31; | |
113 | |||
114 | 196608 | dst[y * dst_stride + x] = pel; | |
115 | } | ||
116 | } | ||
117 | 3 | } | |
118 | |||
119 | void ff_eq_init_x86(EQContext *eq); | ||
120 | |||
121 | 13 | static av_unused void ff_eq_init(EQContext *eq) | |
122 | { | ||
123 | 13 | eq->process = process_c; | |
124 | #if ARCH_X86 | ||
125 | 13 | ff_eq_init_x86(eq); | |
126 | #endif | ||
127 | 13 | } | |
128 | |||
129 | #endif /* AVFILTER_EQ_H */ | ||
130 |