+ introducing colorspaces

This commit is contained in:
Vovanium 2023-09-08 01:59:08 +03:00
parent c8d700cf27
commit 11cbeee069
3 changed files with 75 additions and 0 deletions

View File

@ -0,0 +1,28 @@
with Ada.Numerics.Elementary_Functions;
use Ada.Numerics.Elementary_Functions;
package body Video.Colorspaces.Float_RGB is
package body sRGB is
function To_sRGB (C_L : Float) return Float
is (if C_L <= 0.0031308 then
12.92 * C_L
else
1.055 * C_L**(1.0 / 2.4) - 0.055);
function From_sRGB (C_S : Float) return Float
is (if C_S <= 0.04045 then
(1.0 / 12.92) * C_S
else
((1.0 / 1.055) * (C_S + 0.055))**2.4);
end sRGB;
package body With_Gamma is
function From_Linear (C : Linear_Color) return Gamma_Color
is (R => C.R**Inverse_Gamma, G => C.G**Inverse_Gamma, B => C.B**Inverse_Gamma, A => C.A);
function To_Linear (C : Gamma_Color) return Linear_Color
is (R => C.R**Gamma, G => C.G**Gamma, B => C.B**Gamma, A => C.A);
end With_Gamma;
end Video.Colorspaces.Float_RGB;

View File

@ -0,0 +1,45 @@
package Video.Colorspaces.Float_RGB with Pure is
subtype Color_Component is Float;
subtype Opacity is Color_Component;
Opaque : constant Opacity := 1.0;
Transparent : constant Opacity := 0.0;
type Color is record
R : Color_Component;
G : Color_Component;
B : Color_Component;
A : Opacity := Opaque;
end record;
subtype Linear_Color is Color;
package sRGB is
function To_sRGB (C_L : Float) return Float;
function From_sRGB (C_S : Float) return Float;
subtype sRGB_Color is Color;
function From_Linear (C : Linear_Color) return sRGB_Color
is (R => To_sRGB (C.R), G => To_sRGB (C.G), B => To_sRGB (C.B), A => C.A);
function To_Linear (C : sRGB_Color) return Linear_Color
is (R => From_sRGB (C.R), G => From_sRGB (C.G), B => From_sRGB (C.B), A => C.A);
end sRGB;
generic
Gamma : in Float;
package With_Gamma is
Inverse_Gamma : constant Float := 1.0 / Gamma;
subtype Gamma_Color is Color;
function From_Linear (C : Linear_Color) return Gamma_Color;
function To_Linear (C : Gamma_Color) return Linear_Color;
end With_Gamma;
end Video.Colorspaces.Float_RGB;

View File

@ -0,0 +1,2 @@
package Video.Colorspaces with Pure is
end Video.Colorspaces;