FFmpeg
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 {
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 */
P_NONE
@ P_NONE
Definition: preserve_color.h:27
r
const char * r
Definition: vf_curves.c:116
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
b
#define b
Definition: input.c:40
max
#define max(a, b)
Definition: cuda_runtime.h:33
NB_PRESERVE
@ NB_PRESERVE
Definition: preserve_color.h:34
macros.h
normalize
static float normalize(float r, float g, float b, float max)
Definition: preserve_color.h:37
P_AVG
@ P_AVG
Definition: preserve_color.h:30
g
const char * g
Definition: vf_curves.c:117
f
#define f(width, name)
Definition: cbs_vp9.c:255
P_MAX
@ P_MAX
Definition: preserve_color.h:29
P_LUM
@ P_LUM
Definition: preserve_color.h:28
P_NRM
@ P_NRM
Definition: preserve_color.h:32
P_SUM
@ P_SUM
Definition: preserve_color.h:31
FFMIN3
#define FFMIN3(a, b, c)
Definition: macros.h:50
cbrtf
static av_always_inline float cbrtf(float x)
Definition: libm.h:61
P_PWR
@ P_PWR
Definition: preserve_color.h:33
power
static float power(float r, float g, float b, float max)
Definition: preserve_color.h:45
ib
#define ib(width, name)
Definition: cbs_h2645.c:273
FFMAX3
#define FFMAX3(a, b, c)
Definition: macros.h:48