Specialize template for integer YCoCgR conversion to use bitshifts

master
Pavel Krajcevski ago%!(EXTRA string=11 years)
parent 387df50459
commit a53696a2dc
  1. 70
      glm/gtx/color_space_YCoCg.inl

@ -46,7 +46,22 @@ namespace glm
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> rgb2YCoCgR GLM_FUNC_QUALIFIER tvec3<T, P> YCoCg2rgb
(
tvec3<T, P> const & YCoCgColor
)
{
tvec3<T, P> result;
result.r = YCoCgColor.x + YCoCgColor.y - YCoCgColor.z;
result.g = YCoCgColor.x + YCoCgColor.z;
result.b = YCoCgColor.x - YCoCgColor.y - YCoCgColor.z;
return result;
}
template <typename T, precision P, bool isInteger>
class compute_YCoCgR {
public:
static GLM_FUNC_QUALIFIER tvec3<T, P> rgb2YCoCgR
( (
tvec3<T, P> const & rgbColor tvec3<T, P> const & rgbColor
) )
@ -58,30 +73,65 @@ namespace glm
return result; return result;
} }
static GLM_FUNC_QUALIFIER tvec3<T, P> YCoCgR2rgb
(
tvec3<T, P> const & YCoCgRColor
)
{
tvec3<T, P> result;
T tmp = YCoCgRColor.x - (YCoCgRColor.z / T(2));
result.g = YCoCgRColor.z + tmp;
result.b = tmp - (YCoCgRColor.y / T(2));
result.r = result.b + YCoCgRColor.y;
return result;
}
};
#if 0
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> YCoCg2rgb class compute_YCoCgR<T, P, true> {
public:
static GLM_FUNC_QUALIFIER tvec3<T, P> rgb2YCoCgR
( (
tvec3<T, P> const & YCoCgColor tvec3<T, P> const & rgbColor
) )
{ {
tvec3<T, P> result; tvec3<T, P> result;
result.r = YCoCgColor.x + YCoCgColor.y - YCoCgColor.z; result.y/*Co*/ = rgbColor.r - rgbColor.b;
result.g = YCoCgColor.x + YCoCgColor.z; T tmp = rgbColor.b + (result.y >> 1);
result.b = YCoCgColor.x - YCoCgColor.y - YCoCgColor.z; result.z/*Cg*/ = rgbColor.g - tmp;
result.x/*Y */ = tmp + (result.z >> 1);
return result; return result;
} }
template <typename T, precision P> static GLM_FUNC_QUALIFIER tvec3<T, P> YCoCgR2rgb
GLM_FUNC_QUALIFIER tvec3<T, P> YCoCgR2rgb
( (
tvec3<T, P> const & YCoCgRColor tvec3<T, P> const & YCoCgRColor
) )
{ {
tvec3<T, P> result; tvec3<T, P> result;
T tmp = YCoCgRColor.x - (YCoCgRColor.z / T(2)); T tmp = YCoCgRColor.x - (YCoCgRColor.z >> 1);
result.g = YCoCgRColor.z + tmp; result.g = YCoCgRColor.z + tmp;
result.b = tmp - (YCoCgRColor.y / T(2)); result.b = tmp - (YCoCgRColor.y >> 1);
result.r = result.b + YCoCgRColor.y; result.r = result.b + YCoCgRColor.y;
return result; return result;
} }
};
#endif
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> rgb2YCoCgR
(
tvec3<T, P> const & rgbColor
)
{
return compute_YCoCgR<T, P, std::numeric_limits<T>::is_integer>::rgb2YCoCgR(rgbColor);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> YCoCgR2rgb
(
tvec3<T, P> const & YCoCgRColor
)
{
return compute_YCoCgR<T, P, std::numeric_limits<T>::is_integer>::YCoCgR2rgb(YCoCgRColor);
}
}//namespace glm }//namespace glm

Loading…
Cancel
Save