Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

7.7 KB
Raw Blame
diff --git a/thirdparty/misc/ok_color.h b/thirdparty/misc/ok_color.h
index 608ee56538..1e4c713a1d 100644
--- a/thirdparty/misc/ok_color.h
+++ b/thirdparty/misc/ok_color.h
@@ -20,8 +20,9 @@
 #include <cmath>
 #include <cfloat>
 
-namespace ok_color
+class ok_color
 {
+public:
 
 struct Lab { float L; float a; float b; };
 struct RGB { float r; float g; float b; };
@@ -34,9 +35,9 @@ struct LC { float L; float C; };
 // The maximum value for C in the triangle is then found as fmin(S*L, T*(1-L)), for a given L
 struct ST { float S; float T; };
 
-constexpr float pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062f;
+static constexpr float pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062f;
 
-float clamp(float x, float min, float max)
+static float clamp(float x, float min, float max)
 {
 	if (x < min)
 		return min;
@@ -46,22 +47,22 @@ float clamp(float x, float min, float max)
 	return x;
 }
 
-float sgn(float x)
+static float sgn(float x)
 {
 	return (float)(0.f < x) - (float)(x < 0.f);
 }
 
-float srgb_transfer_function(float a)
+static float srgb_transfer_function(float a)
 {
 	return .0031308f >= a ? 12.92f * a : 1.055f * powf(a, .4166666666666667f) - .055f;
 }
 
-float srgb_transfer_function_inv(float a)
+static float srgb_transfer_function_inv(float a)
 {
 	return .04045f < a ? powf((a + .055f) / 1.055f, 2.4f) : a / 12.92f;
 }
 
-Lab linear_srgb_to_oklab(RGB c)
+static Lab linear_srgb_to_oklab(RGB c)
 {
 	float l = 0.4122214708f * c.r + 0.5363325363f * c.g + 0.0514459929f * c.b;
 	float m = 0.2119034982f * c.r + 0.6806995451f * c.g + 0.1073969566f * c.b;
@@ -78,7 +79,7 @@ Lab linear_srgb_to_oklab(RGB c)
 	};
 }
 
-RGB oklab_to_linear_srgb(Lab c)
+static RGB oklab_to_linear_srgb(Lab c)
 {
 	float l_ = c.L + 0.3963377774f * c.a + 0.2158037573f * c.b;
 	float m_ = c.L - 0.1055613458f * c.a - 0.0638541728f * c.b;
@@ -98,7 +99,7 @@ RGB oklab_to_linear_srgb(Lab c)
 // Finds the maximum saturation possible for a given hue that fits in sRGB
 // Saturation here is defined as S = C/L
 // a and b must be normalized so a^2 + b^2 == 1
-float compute_max_saturation(float a, float b)
+static float compute_max_saturation(float a, float b)
 {
 	// Max saturation will be when one of r, g or b goes below zero.
 
@@ -164,7 +165,7 @@ float compute_max_saturation(float a, float b)
 
 // finds L_cusp and C_cusp for a given hue
 // a and b must be normalized so a^2 + b^2 == 1
-LC find_cusp(float a, float b)
+static LC find_cusp(float a, float b)
 {
 	// First, find the maximum saturation (saturation S = C/L)
 	float S_cusp = compute_max_saturation(a, b);
@@ -181,7 +182,7 @@ LC find_cusp(float a, float b)
 // L = L0 * (1 - t) + t * L1;
 // C = t * C1;
 // a and b must be normalized so a^2 + b^2 == 1
-float find_gamut_intersection(float a, float b, float L1, float C1, float L0, LC cusp)
+static float find_gamut_intersection(float a, float b, float L1, float C1, float L0, LC cusp)
 {
 	// Find the intersection for upper and lower half seprately
 	float t;
@@ -247,7 +248,7 @@ float find_gamut_intersection(float a, float b, float L1, float C1, float L0, LC
 				float u_g = g1 / (g1 * g1 - 0.5f * g * g2);
 				float t_g = -g * u_g;
 
-				float b = -0.0041960863f * l - 0.7034186147f * m + 1.7076147010f * s - 1;
+				b = -0.0041960863f * l - 0.7034186147f * m + 1.7076147010f * s - 1;
 				float b1 = -0.0041960863f * ldt - 0.7034186147f * mdt + 1.7076147010f * sdt;
 				float b2 = -0.0041960863f * ldt2 - 0.7034186147f * mdt2 + 1.7076147010f * sdt2;
 
@@ -266,7 +267,7 @@ float find_gamut_intersection(float a, float b, float L1, float C1, float L0, LC
 	return t;
 }
 
-float find_gamut_intersection(float a, float b, float L1, float C1, float L0)
+static float find_gamut_intersection(float a, float b, float L1, float C1, float L0)
 {
 	// Find the cusp of the gamut triangle
 	LC cusp = find_cusp(a, b);
@@ -274,7 +275,7 @@ float find_gamut_intersection(float a, float b, float L1, float C1, float L0)
 	return find_gamut_intersection(a, b, L1, C1, L0, cusp);
 }
 
-RGB gamut_clip_preserve_chroma(RGB rgb)
+static RGB gamut_clip_preserve_chroma(RGB rgb)
 {
 	if (rgb.r < 1 && rgb.g < 1 && rgb.b < 1 && rgb.r > 0 && rgb.g > 0 && rgb.b > 0)
 		return rgb;
@@ -296,7 +297,7 @@ RGB gamut_clip_preserve_chroma(RGB rgb)
 	return oklab_to_linear_srgb({ L_clipped, C_clipped * a_, C_clipped * b_ });
 }
 
-RGB gamut_clip_project_to_0_5(RGB rgb)
+static RGB gamut_clip_project_to_0_5(RGB rgb)
 {
 	if (rgb.r < 1 && rgb.g < 1 && rgb.b < 1 && rgb.r > 0 && rgb.g > 0 && rgb.b > 0)
 		return rgb;
@@ -318,7 +319,7 @@ RGB gamut_clip_project_to_0_5(RGB rgb)
 	return oklab_to_linear_srgb({ L_clipped, C_clipped * a_, C_clipped * b_ });
 }
 
-RGB gamut_clip_project_to_L_cusp(RGB rgb)
+static RGB gamut_clip_project_to_L_cusp(RGB rgb)
 {
 	if (rgb.r < 1 && rgb.g < 1 && rgb.b < 1 && rgb.r > 0 && rgb.g > 0 && rgb.b > 0)
 		return rgb;
@@ -344,7 +345,7 @@ RGB gamut_clip_project_to_L_cusp(RGB rgb)
 	return oklab_to_linear_srgb({ L_clipped, C_clipped * a_, C_clipped * b_ });
 }
 
-RGB gamut_clip_adaptive_L0_0_5(RGB rgb, float alpha = 0.05f)
+static RGB gamut_clip_adaptive_L0_0_5(RGB rgb, float alpha = 0.05f)
 {
 	if (rgb.r < 1 && rgb.g < 1 && rgb.b < 1 && rgb.r > 0 && rgb.g > 0 && rgb.b > 0)
 		return rgb;
@@ -368,7 +369,7 @@ RGB gamut_clip_adaptive_L0_0_5(RGB rgb, float alpha = 0.05f)
 	return oklab_to_linear_srgb({ L_clipped, C_clipped * a_, C_clipped * b_ });
 }
 
-RGB gamut_clip_adaptive_L0_L_cusp(RGB rgb, float alpha = 0.05f)
+static RGB gamut_clip_adaptive_L0_L_cusp(RGB rgb, float alpha = 0.05f)
 {
 	if (rgb.r < 1 && rgb.g < 1 && rgb.b < 1 && rgb.r > 0 && rgb.g > 0 && rgb.b > 0)
 		return rgb;
@@ -397,7 +398,7 @@ RGB gamut_clip_adaptive_L0_L_cusp(RGB rgb, float alpha = 0.05f)
 	return oklab_to_linear_srgb({ L_clipped, C_clipped * a_, C_clipped * b_ });
 }
 
-float toe(float x)
+static float toe(float x)
 {
 	constexpr float k_1 = 0.206f;
 	constexpr float k_2 = 0.03f;
@@ -405,7 +406,7 @@ float toe(float x)
 	return 0.5f * (k_3 * x - k_1 + sqrtf((k_3 * x - k_1) * (k_3 * x - k_1) + 4 * k_2 * k_3 * x));
 }
 
-float toe_inv(float x)
+static float toe_inv(float x)
 {
 	constexpr float k_1 = 0.206f;
 	constexpr float k_2 = 0.03f;
@@ -413,7 +414,7 @@ float toe_inv(float x)
 	return (x * x + k_1 * x) / (k_3 * (x + k_2));
 }
 
-ST to_ST(LC cusp)
+static ST to_ST(LC cusp)
 {
 	float L = cusp.L;
 	float C = cusp.C;
@@ -423,7 +424,7 @@ ST to_ST(LC cusp)
 // Returns a smooth approximation of the location of the cusp
 // This polynomial was created by an optimization process
 // It has been designed so that S_mid < S_max and T_mid < T_max
-ST get_ST_mid(float a_, float b_)
+static ST get_ST_mid(float a_, float b_)
 {
 	float S = 0.11516993f + 1.f / (
 		+7.44778970f + 4.15901240f * b_
@@ -445,7 +446,7 @@ ST get_ST_mid(float a_, float b_)
 }
 
 struct Cs { float C_0; float C_mid; float C_max; };
-Cs get_Cs(float L, float a_, float b_)
+static Cs get_Cs(float L, float a_, float b_)
 {
 	LC cusp = find_cusp(a_, b_);
 
@@ -478,7 +479,7 @@ Cs get_Cs(float L, float a_, float b_)
 	return { C_0, C_mid, C_max };
 }
 
-RGB okhsl_to_srgb(HSL hsl)
+static RGB okhsl_to_srgb(HSL hsl)
 {
 	float h = hsl.h;
 	float s = hsl.s;
@@ -536,7 +537,7 @@ RGB okhsl_to_srgb(HSL hsl)
 	};
 }
 
-HSL srgb_to_okhsl(RGB rgb)
+static HSL srgb_to_okhsl(RGB rgb)
 {
 	Lab lab = linear_srgb_to_oklab({
 		srgb_transfer_function_inv(rgb.r),
@@ -585,7 +586,7 @@ HSL srgb_to_okhsl(RGB rgb)
 }
 
 
-RGB okhsv_to_srgb(HSV hsv)
+static RGB okhsv_to_srgb(HSV hsv)
 {
 	float h = hsv.h;
 	float s = hsv.s;
@@ -632,7 +633,7 @@ RGB okhsv_to_srgb(HSV hsv)
 	};
 }
 
-HSV srgb_to_okhsv(RGB rgb)
+static HSV srgb_to_okhsv(RGB rgb)
 {
 	Lab lab = linear_srgb_to_oklab({
 		srgb_transfer_function_inv(rgb.r),
@@ -681,4 +682,4 @@ HSV srgb_to_okhsv(RGB rgb)
 	return { h, s, v };
 }
 
-} // namespace ok_color
+};