Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
ColorConverter.cs
Go to the documentation of this file.
1using System;
2using UnityEngine;
3
4public class ColorConverter
5{
6 private const float Epsilon = 0.008856f;
7
8 private const float Kappa = 903.3f;
9
10 private static readonly Xyz WhiteReference = new Xyz
11 {
12 X = 95.047f,
13 Y = 100f,
14 Z = 108.883f
15 };
16
17 public static Lab RgbToLab(Color rgb)
18 {
19 return XyzToLab(RgbToXyz(rgb));
20 }
21
22 public static Lab XyzToLab(Xyz xyz)
23 {
24 Xyz whiteReference = WhiteReference;
25 float num = PivotXyz(xyz.X / whiteReference.X);
26 float num2 = PivotXyz(xyz.Y / whiteReference.Y);
27 float num3 = PivotXyz(xyz.Z / whiteReference.Z);
28 return new Lab
29 {
30 L = Math.Max(0f, 116f * num2 - 16f),
31 A = 500f * (num - num2),
32 B = 200f * (num2 - num3)
33 };
34 }
35
36 private static float PivotXyz(float n)
37 {
38 if (!(n > 0.008856f))
39 {
40 return (903.3f * n + 16f) / 116f;
41 }
42 return CubicRoot(n);
43 }
44
45 private static float CubicRoot(float n)
46 {
47 return Mathf.Pow(n, 1f / 3f);
48 }
49
50 public static Xyz RgbToXyz(Color rgb)
51 {
52 float num = PivotRgb(rgb.r);
53 float num2 = PivotRgb(rgb.g);
54 float num3 = PivotRgb(rgb.b);
55 return new Xyz
56 {
57 X = num * 0.4124f + num2 * 0.3576f + num3 * 0.1805f,
58 Y = num * 0.2126f + num2 * 0.7152f + num3 * 0.0722f,
59 Z = num * 0.0193f + num2 * 0.1192f + num3 * 0.9505f
60 };
61 }
62
63 private static float PivotRgb(float n)
64 {
65 return ((n > 0.04045f) ? Mathf.Pow((n + 0.055f) / 1.055f, 2.4f) : (n / 12.92f)) * 100f;
66 }
67}
static Lab XyzToLab(Xyz xyz)
static Xyz RgbToXyz(Color rgb)
static Lab RgbToLab(Color rgb)
static float PivotXyz(float n)
static float CubicRoot(float n)
const float Epsilon
const float Kappa
static readonly Xyz WhiteReference
static float PivotRgb(float n)
Definition: Lab.cs:2
Definition: Xyz.cs:2
float Y
Definition: Xyz.cs:5
float Z
Definition: Xyz.cs:7
float X
Definition: Xyz.cs:3