8000 Specialize integer implementation of YCoCg-R to use bitshifts by Mokosha · Pull Request #310 · g-truc/glm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Specialize integer implementation of YCoCg-R to use bitshifts #310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 13, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 68 additions & 18 deletions glm/gtx/color_space_YCoCg.inl
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,84 @@ namespace glm
}

template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> rgb2YCoCgR
GLM_FUNC_QUALIFIER tvec3<T, P> YCoCg2rgb
(
tvec3<T, P> const & rgbColor
tvec3<T, P> const & YCoCgColor
)
{
tvec3<T, P> result;
result.x/*Y */ = rgbColor.g / T(2) + (rgbColor.r + rgbColor.b) / T(4);
result.y/*Co*/ = rgbColor.r - rgbColor.b;
result.z/*Cg*/ = rgbColor.g - (rgbColor.r + rgbColor.b) / T(2);
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> result;
result.x/*Y */ = rgbColor.g / T(2) + (rgbColor.r + rgbColor.b) / T(4);
result.y/*Co*/ = rgbColor.r - rgbColor.b;
result.z/*Cg*/ = rgbColor.g - (rgbColor.r + rgbColor.b) / T(2);
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;
}
};

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 & rgbColor
)
{
tvec3<T, P> result;
result.y/*Co*/ = rgbColor.r - rgbColor.b;
T tmp = rgbColor.b + (result.y >> 1);
result.z/*Cg*/ = rgbColor.g - tmp;
result.x/*Y */ = tmp + (result.z >> 1);
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 >> 1);
result.g = YCoCgRColor.z + tmp;
result.b = tmp - (YCoCgRColor.y >> 1);
result.r = result.b + YCoCgRColor.y;
return result;
}
};

template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> rgb2YCoCgR
(
tvec3<T, P> const & YCoCgColor
tvec3<T, P> const & rgbColor
)
{
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;
return compute_YCoCgR<T, P, std::numeric_limits<T>::is_integer>::rgb2YCoCgR(rgbColor);
}

template <typename T, precision P>
Expand All @@ -77,11 +132,6 @@ namespace glm
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;
return compute_YCoCgR<T, P, std::numeric_limits<T>::is_integer>::YCoCgR2rgb(YCoCgRColor);
}
}//namespace glm
0