FFmpeg
libavfilter
preserve_color.h
Go to the documentation of this file.
1
/*
2
* This file is part of FFmpeg.
3
*
4
* FFmpeg is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2.1 of the License, or (at your option) any later version.
8
*
9
* FFmpeg is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
13
*
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with FFmpeg; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
*/
18
19
#ifndef AVFILTER_PRESERVE_COLOR_H
20
#define AVFILTER_PRESERVE_COLOR_H
21
22
#include <math.h>
23
24
#include "
libavutil/macros.h
"
25
26
enum
{
27
P_NONE
,
28
P_LUM
,
29
P_MAX
,
30
P_AVG
,
31
P_SUM
,
32
P_NRM
,
33
P_PWR
,
34
NB_PRESERVE
35
};
36
37
static
inline
float
normalize
(
float
r
,
float
g
,
float
b
,
float
max
)
38
{
39
r
/=
max
;
40
g
/=
max
;
41
b
/=
max
;
42
return
sqrtf
(
r
*
r
+
g
*
g
+
b
*
b
);
43
}
44
45
static
inline
float
power
(
float
r
,
float
g
,
float
b
,
float
max
)
46
{
47
r
/=
max
;
48
g
/=
max
;
49
b
/=
max
;
50
return
cbrtf
(
r
*
r
*
r
+
g
*
g
*
g
+
b
*
b
*
b
);
51
}
52
53
static
inline
void
preserve_color
(
int
preserve_color
,
54
float
ir,
float
ig,
float
ib
,
55
float
r
,
float
g
,
float
b
,
56
float
max
,
57
float
*icolor,
float
*ocolor)
58
{
59
switch
(
preserve_color
) {
60
case
P_LUM
:
61
*icolor =
FFMAX3
(ir, ig,
ib
) +
FFMIN3
(ir, ig,
ib
);
62
*ocolor =
FFMAX3
(
r
,
g
,
b
) +
FFMIN3
(
r
,
g
,
b
);
63
break
;
64
case
P_MAX
:
65
*icolor =
FFMAX3
(ir, ig,
ib
);
66
*ocolor =
FFMAX3
(
r
,
g
,
b
);
67
break
;
68
case
P_AVG
:
69
*icolor = (ir + ig +
ib
+ 1.f) / 3.
f
;
70
*ocolor = (
r
+
g
+
b
+ 1.f) / 3.
f
;
71
break
;
72
case
P_SUM
:
73
*icolor = ir + ig +
ib
;
74
*ocolor =
r
+
g
+
b
;
75
break
;
76
case
P_NRM
:
77
*icolor =
normalize
(ir, ig,
ib
,
max
);
78
*ocolor =
normalize
(
r
,
g
,
b
,
max
);
79
break
;
80
case
P_PWR
:
81
*icolor =
power
(ir, ig,
ib
,
max
);
82
*ocolor =
power
(
r
,
g
,
b
,
max
);
83
break
;
84
}
85
}
86
87
#endif
/* AVFILTER_PRESERVE_COLOR_H */
r
const char * r
Definition:
vf_curves.c:126
preserve_color
static void preserve_color(int preserve_color, float ir, float ig, float ib, float r, float g, float b, float max, float *icolor, float *ocolor)
Definition:
preserve_color.h:53
P_AVG
@ P_AVG
Definition:
preserve_color.h:30
b
#define b
Definition:
input.c:41
max
#define max(a, b)
Definition:
cuda_runtime.h:33
macros.h
normalize
static float normalize(float r, float g, float b, float max)
Definition:
preserve_color.h:37
g
const char * g
Definition:
vf_curves.c:127
P_PWR
@ P_PWR
Definition:
preserve_color.h:33
sqrtf
static __device__ float sqrtf(float a)
Definition:
cuda_runtime.h:184
P_LUM
@ P_LUM
Definition:
preserve_color.h:28
f
f
Definition:
af_crystalizer.c:122
NB_PRESERVE
@ NB_PRESERVE
Definition:
preserve_color.h:34
P_NONE
@ P_NONE
Definition:
preserve_color.h:27
P_NRM
@ P_NRM
Definition:
preserve_color.h:32
FFMIN3
#define FFMIN3(a, b, c)
Definition:
macros.h:50
cbrtf
static av_always_inline float cbrtf(float x)
Definition:
libm.h:61
power
static float power(float r, float g, float b, float max)
Definition:
preserve_color.h:45
P_MAX
@ P_MAX
Definition:
preserve_color.h:29
ib
#define ib(width, name)
Definition:
cbs_h2645.c:271
FFMAX3
#define FFMAX3(a, b, c)
Definition:
macros.h:48
P_SUM
@ P_SUM
Definition:
preserve_color.h:31
Generated on Tue Feb 28 2023 21:33:51 for FFmpeg by
1.8.17