21 #ifndef GR_COLOURSPACE_TYPES__H
22 #define GR_COLOURSPACE_TYPES__H
37 static g__constexpr
int scale__ = 1000 ;
38 explicit fp_1000(
int i ) g__noexcept : m_i(int_t(i)*scale__) {}
39 fp_1000(
int i_scaled ,
int ) g__noexcept : m_i(i_scaled) {}
40 static fp_1000 value__(
int i_scaled ) g__noexcept {
return fp_1000(i_scaled,0) ; }
41 int to_builtin()
const g__noexcept {
return int( m_i / scale__ ) ; }
46 return fp_1000::value__( ( a.m_i * b.m_i ) / fp_1000::scale__ ) ;
48 inline fp_1000 operator/(
const fp_1000 & a ,
const fp_1000 & b ) g__noexcept
50 return fp_1000::value__( ( a.m_i * fp_1000::scale__ ) / b.m_i ) ;
52 inline fp_1000 operator+(
const fp_1000 & a ,
const fp_1000 & b ) g__noexcept
54 return fp_1000::value__( a.m_i + b.m_i ) ;
56 inline fp_1000 operator-(
const fp_1000 & a ,
const fp_1000 & b ) g__noexcept
58 return fp_1000::value__( a.m_i - b.m_i ) ;
60 inline bool operator<(
const fp_1000 & a ,
const fp_1000 & b ) g__noexcept
62 return a.m_i < b.m_i ;
64 inline bool operator>(
const fp_1000 & a ,
const fp_1000 & b ) g__noexcept
66 return a.m_i > b.m_i ;
76 static g__constexpr
int scale__ = 256 ;
77 explicit fp_256(
int i ) g__noexcept : m_i(i>0?(int_t(i)<<8):-(int_t(-i)<<8)) {}
78 fp_256(
int i_scaled ,
int ) g__noexcept : m_i(i_scaled) {}
79 static fp_256 value__(
int i_scaled ) g__noexcept {
return fp_256(i_scaled,0) ; }
80 int to_builtin()
const g__noexcept {
return int(m_i>0?(m_i>>8):-((-m_i)>>8)) ; }
85 return fp_256::value__( ( a.m_i * b.m_i ) >> 8 ) ;
87 inline fp_256 operator/( fp_256 a , fp_256 b ) g__noexcept
89 return fp_256::value__( ( a.m_i << 8 ) / b.m_i ) ;
91 inline fp_256 operator+( fp_256 a , fp_256 b ) g__noexcept
93 return fp_256::value__( a.m_i + b.m_i ) ;
95 inline fp_256 operator-( fp_256 a , fp_256 b ) g__noexcept
97 return fp_256::value__( a.m_i - b.m_i ) ;
99 inline bool operator<( fp_256 a , fp_256 b ) g__noexcept
101 return a.m_i < b.m_i ;
103 inline bool operator>( fp_256 a , fp_256 b ) g__noexcept
105 return a.m_i > b.m_i ;
113 typedef double fp_type ;
114 static double make_fp(
int i ,
int s ) g__noexcept
116 return double(i) / double(s) ;
118 static double make_half() g__noexcept
122 static unsigned char to_range(
double d ) g__noexcept
124 return static_cast<unsigned char>(d) ;
131 template <
typename T>
135 static fp_type make_fp(
int i ,
int ) g__noexcept
137 return fp_type::value__( i ) ;
139 static g__constexpr fp_type make_half() g__noexcept
141 return fp_type::value__( fp_type::scale__ >> 1 ) ;
143 static unsigned char to_range( fp_type n ) g__noexcept
145 return static_cast<unsigned char>( n.to_builtin() ) ;
A simple fixed-point number class with a scale factor of 256.
A simple fixed-point number class with a scale factor of 1000.