21 #ifndef GR_COLOURSPACE_MAP__H
22 #define GR_COLOURSPACE_MAP__H
35 T
clamp( T min , T value , T max )
37 return value < min ? min : ( value > max ? max : value ) ;
42 template <
typename Trange,
typename Tout,
typename Tin>
46 return static_cast<Tout
>(
clamp(static_cast<Tin>(Trange::min),value,static_cast<Tin>(Trange::max))) ;
51 template <
typename Trange,
typename Tconverter>
55 typedef typename Tconverter::fp_type fp_t ;
56 return ( fp * fp_t(Trange::max-Trange::min) + fp_t(Trange::min) ) ;
61 template <
typename Trange,
typename Tconverter>
65 return map_to_range_from_unsigned<Trange,Tconverter>( fp + Tconverter::make_half() ) ;
70 template <
typename Trange,
typename Tconverter>
72 typename Tconverter::fp_type
map_to_range_imp(
typename Tconverter::fp_type fp ) g__noexcept
76 map_to_range_from_signed<Trange,Tconverter>(fp) :
77 map_to_range_from_unsigned<Trange,Tconverter>(fp) ;
82 template <
typename Trange,
typename Tconverter>
84 typename Trange::value_type
map_to_range(
typename Tconverter::fp_type fp ) g__noexcept
86 typedef typename Tconverter::fp_type fp_t ;
87 return Tconverter::to_range(
88 clamp( fp_t(Trange::min) , map_to_range_imp<Trange,Tconverter>(fp) , fp_t(Trange::max) ) ) ;
94 template <
typename Trange,
typename Tconverter>
98 typedef typename Tconverter::fp_type fp_t ;
99 return fp_t(n-Trange::min) / fp_t(Trange::max-Trange::min) - Tconverter::make_half() ;
104 template <
typename Trange,
typename Tconverter>
108 typedef typename Tconverter::fp_type fp_t ;
109 return fp_t(n-Trange::min) / fp_t(Trange::max-Trange::min) ;
114 template <
typename Trange,
typename Tconverter>
120 map_to_space_signed<Trange,Tconverter>( n ) :
121 map_to_space_unsigned<Trange,Tconverter>( n ) ;
126 template <
typename Tconverter,
typename Trange1,
typename Trange2,
typename Trange3>
130 typedef typename Tconverter::fp_type fp_t ;
132 map_to_space_imp<Trange1,Tconverter>(t.m_1) ,
133 map_to_space_imp<Trange2,Tconverter>(t.m_2) ,
134 map_to_space_imp<Trange3,Tconverter>(t.m_3) ) ;
g__constexpr T clamp(T min, T value, T max)
Does min/max clamping.
g__constexpr Tconverter::fp_type map_to_range_imp(typename Tconverter::fp_type fp) g__noexcept
Scales an fp value to another fp value in the relevant range.
g__constexpr Trange::value_type map_to_range(typename Tconverter::fp_type fp) g__noexcept
Maps an "analogue" space value to a "digial" range value.
A 3-tuple for holding rgb or yuv triples.
g__constexpr Tconverter::fp_type map_to_space_imp(typename Trange::value_type n) g__noexcept
Maps a "digital" range value to an "analogue" space value.
g__constexpr Tconverter::fp_type map_to_range_from_signed(typename Tconverter::fp_type fp) g__noexcept
Scales a signed fp value to another fp value in the relevant range.
g__constexpr Tconverter::fp_type map_to_range_from_unsigned(typename Tconverter::fp_type fp) g__noexcept
Scales an unsigned fp value to another fp value in the relevant range.
g__constexpr Tconverter::fp_type map_to_space_signed(typename Trange::value_type n) g__noexcept
Maps a "digital" range value to a signed "analogue" space value.
g__constexpr Tconverter::fp_type map_to_space_unsigned(typename Trange::value_type n) g__noexcept
Maps a "digital" range value to an unsigned "analogue" space value.
g__constexpr triple< typename Tconverter::fp_type > map_to_space(triple< typename Trange1::value_type > t) g__noexcept
Maps a "digital" range triple to an "analogue" space triple.