63 lines
1.8 KiB
Text
63 lines
1.8 KiB
Text
export {
|
||
/* todo: allow machine.UInt8 in the VM
|
||
*/
|
||
let morph-rgb-to-hsv = λ{
|
||
{
|
||
red: ℝ_[0,1] ~ ℤ_256 ~ machine.UInt64;
|
||
green: ℝ_[0,1] ~ ℤ_256 ~ machine.UInt64;
|
||
blue: ℝ_[0,1] ~ ℤ_256 ~ machine.UInt64;
|
||
} : <Color sRGB>
|
||
~ RGB
|
||
~ <Vec3 ℝ_[0,1] ~ ℤ_256 ~ machine.UInt64>;
|
||
}
|
||
/*
|
||
-> <Color sRGB>
|
||
~ HSV
|
||
~ {
|
||
hue: Angle ~ Degrees ~ ℝ_0,360 ~ ℤ_360 ~ machine.UInt64 ;
|
||
sat: ℝ_[0,1] ~ ℤ_256 ~ machine.UInt64;
|
||
val: ℝ_[0,1] ~ ℤ_256 ~ machine.UInt64;
|
||
}
|
||
~ <Vec3 machine.UInt64>
|
||
*/
|
||
↦ {
|
||
let channel_max = int-max (int-max red green) blue;
|
||
let channel_min = int-min (int-min red green) blue;
|
||
let channel_delta = i- channel_max channel_min;
|
||
|
||
/* value */
|
||
channel_max;
|
||
|
||
/* saturation */
|
||
i/ (i* 255 channel_delta) channel_max;
|
||
|
||
/* hue */
|
||
i% (i/ (i* 60
|
||
if( int-eq channel_max red ) { i+ (i* 0 255) (i- green blue); }
|
||
else {
|
||
if( int-eq channel_max green ) { i+ (i* 2 255) (i- blue red); }
|
||
else { i+ (i* 4 255) (i- red green); };
|
||
}
|
||
)
|
||
channel_delta
|
||
)
|
||
360;
|
||
};
|
||
|
||
/*
|
||
let get-srgb-luminance =
|
||
-> ℝ_[0,1] ~ machine.Float64
|
||
λ{r:ℝ,g:ℝ,b:ℝ} : <Color sRGB> ~ RGB ~ <Vec3 ℝ_[0,1] ~ machine.Float64>
|
||
↦
|
||
{
|
||
machine.Float64.mul red 0.22248840;
|
||
machine.Float64.mul green 0.71690369;
|
||
machine.Float64.mul blue 0.06060791;
|
||
machine.Float64.add;
|
||
machine.Float64.add;
|
||
|
||
// add (add (mul r 0.2) (mul g 0.7)) (mul b 0.6)
|
||
};
|
||
*/
|
||
}
|
||
|