FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/vf_eq.h
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 14 14 100.0%
Functions: 2 2 100.0%
Branches: 6 6 100.0%

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 #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 {
42 VAR_N,
43 #if FF_API_FRAME_PKT
44 VAR_POS,
45 #endif
46 VAR_R,
47 VAR_T,
48 VAR_NB
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
57 double brightness, contrast, gamma, gamma_weight;
58 int lut_clean;
59
60 } EQParameters;
61
62 typedef struct EQContext {
63 const AVClass *class;
64
65 EQParameters param[3];
66
67 char *contrast_expr;
68 AVExpr *contrast_pexpr;
69 double contrast;
70
71 char *brightness_expr;
72 AVExpr *brightness_pexpr;
73 double brightness;
74
75 char *saturation_expr;
76 AVExpr *saturation_pexpr;
77 double saturation;
78
79 char *gamma_expr;
80 AVExpr *gamma_pexpr;
81 double gamma;
82
83 char *gamma_weight_expr;
84 AVExpr *gamma_weight_pexpr;
85 double gamma_weight;
86
87 char *gamma_r_expr;
88 AVExpr *gamma_r_pexpr;
89 double gamma_r;
90
91 char *gamma_g_expr;
92 AVExpr *gamma_g_pexpr;
93 double gamma_g;
94
95 char *gamma_b_expr;
96 AVExpr *gamma_b_pexpr;
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
104 enum EvalMode { EVAL_MODE_INIT, EVAL_MODE_FRAME, EVAL_MODE_NB } eval_mode;
105 } EQContext;
106
107 3 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 3 int contrast = (int) (param->contrast * 256 * 16);
111 3 int brightness = ((int) (100.0 * param->brightness + 100.0) * 511) / 200 - 128 - contrast / 32;
112
113
2/2
✓ Branch 0 taken 768 times.
✓ Branch 1 taken 3 times.
771 for (int y = 0; y < h; y++) {
114
2/2
✓ Branch 0 taken 196608 times.
✓ Branch 1 taken 768 times.
197376 for (int x = 0; x < w; x++) {
115 196608 int pel = ((src[y * src_stride + x] * contrast) >> 12) + brightness;
116
117
2/2
✓ Branch 0 taken 153197 times.
✓ Branch 1 taken 43411 times.
196608 if (pel & ~255)
118 153197 pel = (-pel) >> 31;
119
120 196608 dst[y * dst_stride + x] = pel;
121 }
122 }
123 3 }
124
125 void ff_eq_init_x86(EQContext *eq);
126
127 13 static av_unused void ff_eq_init(EQContext *eq)
128 {
129 13 eq->process = process_c;
130 #if ARCH_X86
131 13 ff_eq_init_x86(eq);
132 #endif
133 13 }
134
135 #endif /* AVFILTER_EQ_H */
136