FFmpeg
Loading...
Searching...
No Matches
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
26enum {
35};
36
37static 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
45static 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
53static 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 */
#define ib(width, name)
Definition cbs_h264.c:65
static __device__ float sqrtf(float a)
#define max(a, b)
#define r
Definition input.c:42
#define b
Definition input.c:43
static av_always_inline float cbrtf(float x)
Definition libm.h:63
Utility Preprocessor macros.
#define FFMAX3(a, b, c)
Definition macros.h:48
#define FFMIN3(a, b, c)
Definition macros.h:50
static float power(float r, float g, float b, float max)
@ P_NONE
@ P_SUM
@ P_NRM
@ NB_PRESERVE
@ P_MAX
@ P_AVG
@ P_PWR
@ P_LUM
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)
const char * g
Definition vf_curves.c:128