1 /*
2 * Copyright (C) 2024 Niklas Haas
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #ifndef SWSCALE_CSPUTILS_H
22 #define SWSCALE_CSPUTILS_H
23
24 #include <stdint.h>
25 #include <stdbool.h>
26 #include <math.h>
27
32
33 /* Shared constants and helpers for colorspace mapping */
34
35 #define fmixf(a, b, x) ((b) * (x) + (a) * (1 - (x)))
36
37 static inline float smoothstepf(
float edge0,
float edge1,
float x)
38 {
39 if (edge0 == edge1)
40 return x >= edge0;
41 x = (x - edge0) / (edge1 - edge0);
43 return x * x * (3.0f - 2.0f * x);
44 }
45
46 /* 3x3 matrix math */
50
54
57
58 /* Converts to/from XYZ (relative to the given white point, no adaptation) */
61
62 /* Returns an RGB -> RGB adaptation matrix */
66
67 /* Integer math definitions / helpers */
71
75
79
80 /* Fast perceptual quantizer */
81 static const float PQ_M1 = 2610./4096 * 1./4,
86
89
91 {
94 float fpart = idxf - ipart;
96 }
97
99 {
103 }
104
105 /* Misc colorspace math / helpers */
106
107 /**
108 * Returns true if 'b' is entirely contained in 'a'. Useful for figuring out if
109 * colorimetric clipping will occur or not.
110 */
112
113 #endif /* SWSCALE_CSPUTILS_H */