50 #ifndef OPENMESH_COLOR_CAST_HH
51 #define OPENMESH_COLOR_CAST_HH
57 #include <OpenMesh/Core/System/config.h>
58 #include <OpenMesh/Core/Utils/vector_cast.hh>
74 #ifndef DOXY_IGNORE_THIS
77 template <
typename dst_t,
typename src_t>
80 typedef dst_t return_type;
82 inline static return_type cast(
const src_t& _src)
94 typedef Vec3uc return_type;
96 inline static return_type cast(
const Vec3f& _src)
98 return Vec3uc( (
unsigned char)(_src[0]* 255.0f + 0.5f),
99 (
unsigned char)(_src[1]* 255.0f + 0.5f),
100 (
unsigned char)(_src[2]* 255.0f + 0.5f) );
107 typedef Vec3uc return_type;
109 inline static return_type cast(
const Vec4f& _src)
111 return Vec3uc( (
unsigned char)(_src[0]* 255.0f + 0.5f),
112 (
unsigned char)(_src[1]* 255.0f + 0.5f),
113 (
unsigned char)(_src[2]* 255.0f + 0.5f) );
120 typedef Vec4uc return_type;
122 inline static return_type cast(
const Vec3f& _src)
124 return Vec4uc( (
unsigned char)(_src[0]* 255.0f + 0.5f),
125 (
unsigned char)(_src[1]* 255.0f + 0.5f),
126 (
unsigned char)(_src[2]* 255.0f + 0.5f),
127 (
unsigned char)(255) );
134 typedef Vec4f return_type;
136 inline static return_type cast(
const Vec3f& _src)
138 return Vec4f( _src[0],
148 typedef Vec4uc return_type;
150 inline static return_type cast(
const Vec4f& _src)
152 return Vec4uc( (
unsigned char)(_src[0]* 255.0f + 0.5f),
153 (
unsigned char)(_src[1]* 255.0f + 0.5f),
154 (
unsigned char)(_src[2]* 255.0f + 0.5f),
155 (
unsigned char)(_src[3]* 255.0f + 0.5f) );
162 typedef Vec4f return_type;
164 inline static return_type cast(
const Vec4i& _src)
166 const float f = 1.0f / 255.0f;
167 return Vec4f( _src[0] * f, _src[1] * f, _src[2] * f , _src[3] * f );
174 typedef Vec4uc return_type;
176 inline static return_type cast(
const Vec3uc& _src)
178 return Vec4uc( _src[0], _src[1], _src[2], 255 );
185 typedef Vec3f return_type;
187 inline static return_type cast(
const Vec3uc& _src)
189 const float f = 1.0f / 255.0f;
190 return Vec3f(_src[0] * f, _src[1] * f, _src[2] * f );
197 typedef Vec3f return_type;
199 inline static return_type cast(
const Vec4uc& _src)
201 const float f = 1.0f / 255.0f;
202 return Vec3f(_src[0] * f, _src[1] * f, _src[2] * f );
209 typedef Vec4f return_type;
211 inline static return_type cast(
const Vec3uc& _src)
213 const float f = 1.0f / 255.0f;
214 return Vec4f(_src[0] * f, _src[1] * f, _src[2] * f, 1.0f );
221 typedef Vec4f return_type;
223 inline static return_type cast(
const Vec4uc& _src)
225 const float f = 1.0f / 255.0f;
226 return Vec4f(_src[0] * f, _src[1] * f, _src[2] * f, _src[3] * f );
233 #ifndef DOXY_IGNORE_THIS
235 #if !defined(OM_CC_MSVC)
236 template <
typename dst_t>
239 typedef const dst_t& return_type;
241 inline static return_type cast(
const dst_t& _src)
253 template <
typename dst_t,
typename src_t>
255 typename color_caster<dst_t, src_t>::return_type
270 #endif // OPENMESH_COLOR_CAST_HH defined