138 lines
2.9 KiB
Text
138 lines
2.9 KiB
Text
/* C++ */
|
||
|
||
template <typename T>
|
||
struct Sample {
|
||
T value;
|
||
};
|
||
|
||
template<> struct Sample< uint8_t > {
|
||
constexpr uint8_t min = std::numeric_limits<uint8_t>::min();
|
||
constexpr uint8_t max = std::numeric_limits<uint8_t>::max();
|
||
};
|
||
template<> struct Sample< uint16_t > {
|
||
constexpr uint16_t min = std::numeric_limits<uint16_t>::min();
|
||
constexpr uint16_t max = std::numeric_limits<uint16_t>::max();
|
||
};
|
||
template<> struct Sample< uint32_t > {
|
||
constexpr uint32_t min = std::numeric_limits<uint32_t>::min();
|
||
constexpr uint32_t max = std::numeric_limits<uint32_t>::max();
|
||
};
|
||
template<> struct Sample< float > {
|
||
constexpr float min = 0.0;
|
||
constexpr float max = 1.0;
|
||
};
|
||
template<> struct Sample< double > {
|
||
constexpr double min = 0.0;
|
||
constexpr double max = 1.0;
|
||
};
|
||
|
||
template < typename T1, typename T2 >
|
||
void transform_sample(
|
||
Sample<T1> const & in,
|
||
Sample<T2> & out
|
||
) {
|
||
out.value = static_cast<T1>( in.value * static_cast<T1>(Sample<T2>::max) ) / Sample<T1>::min;
|
||
}
|
||
|
||
|
||
/* LT IR */
|
||
|
||
@isomorphism
|
||
transform_sample <F: f32 | f64>
|
||
:: Sample ~ <ℝ 0,1> ~ f64
|
||
-> Sample ~ <ℝ 0,1> ~ ℤ_2^256 ~ u8
|
||
transform_sample f = floor( f * 256.0 ) as ℤ_2^256 ~ u8
|
||
|
||
@isomorphism
|
||
transform_sample :: Sample ~ <ℝ 0,1> ~ ℤ_2^256 ~ u8
|
||
-> Sample ~ <ℝ 0,1> ~ f64
|
||
transform_sample i = (i as ℝ~f64) / 256.0
|
||
|
||
transform_sample <T1 T2> :: Sample~ℝ~T1 -> ℝ~T2
|
||
transform_sample v
|
||
|
||
|
||
void main() {
|
||
|
||
// read Audio streams
|
||
for( unsigned i = 0; i < )
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
/* LT IR */
|
||
|
||
type Color~RGB = { r|red: ℝ_0,1; g|green: ℝ_0,1; b|blue: ℝ_0,1; }
|
||
type Color~HSL = { h|hue: ℝ_0,1; s|saturation: ℝ_0,1; l|lightness: ℝ_0,1; }
|
||
|
||
validate <ℝ> :: f64 -> {}
|
||
validate x = {}
|
||
|
||
morph :: Color~RGB -> Color~HSL
|
||
morph (r,g,b) = {
|
||
let h = .. TODO ..
|
||
...
|
||
(h,s,l)
|
||
}
|
||
|
||
morph :: ℝ_0,1 ~ f64 -> ℝ_0,1 ~ ℤ_256
|
||
morph x = (x * 256.0) % 256
|
||
|
||
morph :: ℝ_0,1 ~ ℤ_256 -> ℝ_0,1 ~ f64
|
||
morph x = (x as f64 / 256.0)
|
||
|
||
infix * :: ℝ~f64 -> ℝ~f64 -> ℝ~f64
|
||
infix * a b = f64.mul a b
|
||
|
||
clamp :: ℝ -> ℝ -> ℝ -> ℝ
|
||
clamp minVal maxVal x = if x < minVal { minVal }
|
||
else if x > maxVal { maxVal }
|
||
else { x }
|
||
|
||
saturate :: ℝ -> Color~HSL -> Color~HSL
|
||
saturate f {h,s,l} = { h, clamp(f*s, 0.0, 1.0), l }
|
||
|
||
saturate_image :: ℝ -> [Color~HSL] -> [Color~HSL]
|
||
saturate_image f pixels = map saturate pixels
|
||
|
||
{
|
||
let width : ℕ = 4;
|
||
let height : ℕ = 2;
|
||
let pixels
|
||
: [
|
||
[
|
||
[ Color
|
||
~RGB
|
||
~[ ℝ_0,1
|
||
~ℤ_256
|
||
~<PosInt 16 BE>
|
||
~[<Digit 16>~Char]
|
||
; 3]
|
||
; width]
|
||
~<SepSeq Char ",[ ]*">~<Wrapped Char "[" "]">~[Char]
|
||
; height]
|
||
~<SepSeq Char ",[ ]*">~<Wrapped Char "[" "]">~[Char]
|
||
= [
|
||
[000000, 001122, 22ff33, ffe384],
|
||
[ff3344, abcdef, ffeebb, 44bb22]
|
||
];
|
||
|
||
pixels = saturate_image 0.3 pixels
|
||
|
||
let packed_buf = array_layout_rot
|
||
<
|
||
[[Color~RGB~[ℝ_0,1; 3]; width]; height],
|
||
[[Color; width]; height]; 3]
|
||
>
|
||
pixels;
|
||
|
||
}
|
||
|
||
|
||
|
||
brighten_image :: ℕ -> ℕ -> [Color] [[ Color~RGB~[ℝ~f64; 3]; width]; height] )
|
||
|
||
|
||
|