summaryrefslogtreecommitdiff
path: root/indra/llmath
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llmath')
-rw-r--r--indra/llmath/llmath.h20
-rw-r--r--indra/llmath/v3color.h8
-rw-r--r--indra/llmath/v4color.h11
-rw-r--r--indra/llmath/v4math.h12
4 files changed, 51 insertions, 0 deletions
diff --git a/indra/llmath/llmath.h b/indra/llmath/llmath.h
index e508c9a199..bb19248f1f 100644
--- a/indra/llmath/llmath.h
+++ b/indra/llmath/llmath.h
@@ -537,6 +537,26 @@ inline void ll_remove_outliers(std::vector<VEC_TYPE>& data, F32 k)
}
}
+// This converts from a non-linear sRGB floating point value (0..1) to a linear value.
+// Useful for gamma correction and such. Note: any values passed through this should not be serialized. You should also ideally cache the output of this.
+inline float sRGBtoLinear(const float val) {
+ if (val < 0.0031308f) {
+ return val * 12.92f;
+ }
+ else {
+ return 1.055f * pow(val, 1.0f / 2.4f) - 0.055f;
+ }
+}
+
+inline float linearTosRGB(const float val) {
+ if (val < 0.04045f) {
+ return val / 12.92f;
+ }
+ else {
+ return pow((val + 0.055f) / 1.055f, 2.4f);
+ }
+}
+
// Include simd math header
#include "llsimdmath.h"
diff --git a/indra/llmath/v3color.h b/indra/llmath/v3color.h
index 43910a1bbe..ac78197510 100644
--- a/indra/llmath/v3color.h
+++ b/indra/llmath/v3color.h
@@ -475,5 +475,13 @@ inline LLColor3 lerp(const LLColor3 &a, const LLColor3 &b, F32 u)
a.mV[VZ] + (b.mV[VZ] - a.mV[VZ]) * u);
}
+inline const LLColor3 srgbColor3(const LLColor3 &a) {
+ LLColor3 srgbColor;
+ srgbColor.mV[0] = linearTosRGB(a.mV[0]);
+ srgbColor.mV[1] = linearTosRGB(a.mV[1]);
+ srgbColor.mV[2] = linearTosRGB(a.mV[2]);
+
+ return srgbColor;
+}
#endif
diff --git a/indra/llmath/v4color.h b/indra/llmath/v4color.h
index 614cdc9f3e..d9dd28ec54 100644
--- a/indra/llmath/v4color.h
+++ b/indra/llmath/v4color.h
@@ -656,5 +656,16 @@ void LLColor4::clamp()
}
}
+inline const LLColor4 srgbColor4(const LLColor4 &a) {
+ LLColor4 srgbColor;
+
+ srgbColor.mV[0] = linearTosRGB(a.mV[0]);
+ srgbColor.mV[1] = linearTosRGB(a.mV[1]);
+ srgbColor.mV[2] = linearTosRGB(a.mV[2]);
+ srgbColor.mV[3] = a.mV[3];
+
+ return srgbColor;
+}
+
#endif
diff --git a/indra/llmath/v4math.h b/indra/llmath/v4math.h
index 3f6d480ed9..00baeefa5c 100644
--- a/indra/llmath/v4math.h
+++ b/indra/llmath/v4math.h
@@ -534,6 +534,18 @@ inline F32 LLVector4::normVec(void)
return (mag);
}
+// Because apparently some parts of the viewer use this for color info.
+inline const LLVector4 srgbVector4(const LLVector4 &a) {
+ LLVector4 srgbColor;
+
+ srgbColor.mV[0] = linearTosRGB(a.mV[0]);
+ srgbColor.mV[1] = linearTosRGB(a.mV[1]);
+ srgbColor.mV[2] = linearTosRGB(a.mV[2]);
+ srgbColor.mV[3] = a.mV[3];
+
+ return srgbColor;
+}
+
#endif