TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
unorm8.h
Go to the documentation of this file.
1 
12 #ifndef G3D_unorm8_h
13 #define G3D_unorm8_h
14 
15 #include "G3D/platform.h"
16 #include "G3D/g3dmath.h"
17 
18 namespace G3D {
19 
20 
34 private:
35  uint8 m_bits;
36 
39  explicit unorm8(uint8 b) : m_bits(b) {}
40 
41 public:
42 
44  static unorm8 fromBits(uint8 b) {
45  return unorm8(b);
46  }
47 
50  return unorm8(b);
51  }
52 
53  unorm8() : m_bits(0) {}
54 
55  unorm8(const unorm8& other) : m_bits(other.m_bits) {}
56 
58  explicit unorm8(float f) {
59  m_bits = (uint8)(clamp(f, 0.0f, 1.0f) * 255.0f + 0.5f);
60  }
61 
62  explicit unorm8(double f) {
63  m_bits = iClamp(int(f * 255.0f + 0.5f), 0, 255);
64  }
65 
67  operator float() const {
68  return float(m_bits) * (1.0f / 255.0f);
69  }
70 
71  operator double() const {
72  return double(m_bits) * (1.0 / 255.0);
73  }
74 
75  static unorm8 one() {
76  return fromBits(255);
77  }
78 
79  static unorm8 zero() {
80  return fromBits(0);
81  }
82 
86  uint8 bits() const {
87  return m_bits;
88  }
89 
92  return m_bits;
93  }
94 
95  bool operator>(const unorm8 other) const {
96  return m_bits > other.m_bits;
97  }
98 
99  bool operator<(const unorm8 other) const {
100  return m_bits < other.m_bits;
101  }
102 
103  bool operator>=(const unorm8 other) const {
104  return m_bits >= other.m_bits;
105  }
106 
107  bool operator<=(const unorm8 other) const {
108  return m_bits <= other.m_bits;
109  }
110 
111  bool operator==(const unorm8 other) const {
112  return m_bits <= other.m_bits;
113  }
114 
115  bool operator!=(const unorm8 other) const {
116  return m_bits != other.m_bits;
117  }
118 
119  unorm8 operator+(const unorm8 other) const {
120  return unorm8(uint8(m_bits + other.m_bits));
121  }
122 
123  unorm8& operator+=(const unorm8 other) {
124  m_bits += other.m_bits;
125  return *this;
126  }
127 
128  unorm8 operator-(const unorm8 other) const {
129  return unorm8(uint8(m_bits - other.m_bits));
130  }
131 
132  unorm8& operator-=(const unorm8 other) {
133  m_bits -= other.m_bits;
134  return *this;
135  }
136 
137  unorm8 operator*(const int i) const {
138  return unorm8(uint8(m_bits * i));
139  }
140 
141  unorm8& operator*=(const int i) {
142  m_bits *= i;
143  return *this;
144  }
145 
146  unorm8 operator/(const int i) const {
147  return unorm8(uint8(m_bits / i));
148  }
149 
150  unorm8& operator/=(const int i) {
151  m_bits /= i;
152  return *this;
153  }
154 
155  unorm8 operator<<(const int i) const {
156  return unorm8((uint8)(m_bits << i));
157  }
158 
159  unorm8& operator<<=(const int i) {
160  m_bits <<= i;
161  return *this;
162  }
163 
164  unorm8 operator>>(const int i) const {
165  return unorm8(uint8(m_bits >> i));
166  }
167 
168  unorm8& operator>>=(const int i) {
169  m_bits >>= i;
170  return *this;
171  }
172 }
174 
175 } // namespace G3D
176 
177 #endif // G3D_unorm8
unorm8
Definition: unorm8.h:33
unorm16 & operator>>=(const int i)
Definition: unorm16.h:171
unorm16 operator-(const unorm16 other) const
Definition: unorm16.h:131
uint8 reinterpretAsUInt8() const
Returns the underlying bits in this representation. Equivalent to:
Definition: unorm8.h:91
unorm16 & operator+=(const unorm16 other)
Definition: unorm16.h:126
unorm16 & operator<<=(const int i)
Definition: unorm16.h:162
unorm16 & operator/=(const int i)
Definition: unorm16.h:153
bool operator!=(const NetAddress &a, const NetAddress &b)
Definition: NetAddress.h:128
bool operator<=(const unorm16 other) const
Definition: unorm16.h:110
static unorm16 fromBits(uint16 b)
Definition: unorm16.h:43
Definition: AABox.h:25
unorm16 operator+(const unorm16 other) const
Definition: unorm16.h:122
static unorm16 reinterpretFrom(uint16 b)
Definition: unorm16.h:48
bool operator<(const unorm16 other) const
Definition: unorm16.h:102
double clamp(double val, double low, double hi)
Definition: g3dmath.h:571
G3D::Color3 operator/(float s, const G3D::Color3 &c)
Definition: Color3.h:287
bool operator==(const NetAddress &a, const NetAddress &b)
Definition: NetAddress.h:123
static unorm16 one()
Definition: unorm16.h:78
unorm16 & operator-=(const unorm16 other)
Definition: unorm16.h:135
#define G3D_END_PACKED_CLASS(byteAlign)
Definition: platform.h:357
unorm16 & operator*=(const int i)
Definition: unorm16.h:144
uint16 bits() const
Returns the underlying bits in this representation. Equivalent to:
Definition: unorm16.h:89
bool operator>=(const unorm16 other) const
Definition: unorm16.h:106
uint8_t uint8
Definition: g3dmath.h:164
bool operator>(const unorm16 other) const
Definition: unorm16.h:98
#define G3D_BEGIN_PACKED_CLASS(byteAlign)
Definition: platform.h:345
std::ostream & operator<<(std::ostream &os, const NetAddress &)
Definition: NetworkDevice.cpp:26
unorm16 operator>>(const int i) const
Definition: unorm16.h:167
static unorm16 zero()
Definition: unorm16.h:82
uint8_t uint8
Definition: Define.h:152
int iClamp(int val, int low, int hi)
Definition: g3dmath.h:545
G3D::Color3 operator*(float s, const G3D::Color3 &c)
Definition: Color3.h:275