@@ -46,29 +46,84 @@ namespace glm
46
46
}
47
47
48
48
template <typename T, precision P>
49
- GLM_FUNC_QUALIFIER tvec3<T, P> rgb2YCoCgR
49
+ GLM_FUNC_QUALIFIER tvec3<T, P> YCoCg2rgb
50
50
(
51
- tvec3<T, P> const & rgbColor
51
+ tvec3<T, P> const & YCoCgColor
52
52
)
53
53
{
54
54
tvec3<T, P> result;
55
- result.x /* Y */ = rgbColor. g / T ( 2 ) + (rgbColor. r + rgbColor. b ) / T ( 4 ) ;
56
- result.y /* Co */ = rgbColor. r - rgbColor. b ;
57
- result.z /* Cg */ = rgbColor. g - (rgbColor. r + rgbColor. b ) / T ( 2 ) ;
55
+ result.r = YCoCgColor. x + YCoCgColor. y - YCoCgColor. z ;
56
+ result.g = YCoCgColor. x + YCoCgColor. z ;
57
+ result.b = YCoCgColor. x - YCoCgColor. y - YCoCgColor. z ;
58
58
return result;
59
59
}
60
60
61
+ template <typename T, precision P, bool isInteger>
62
+ class compute_YCoCgR {
63
+ public:
64
+ static GLM_FUNC_QUALIFIER tvec3<T, P> rgb2YCoCgR
65
+ (
66
+ tvec3<T, P> const & rgbColor
67
+ )
68
+ {
69
+ tvec3<T, P> result;
70
+ result.x /* Y */ = rgbColor.g / T (2 ) + (rgbColor.r + rgbColor.b ) / T (4 );
71
+ result.y /* Co*/ = rgbColor.r - rgbColor.b ;
72
+ result.z /* Cg*/ = rgbColor.g - (rgbColor.r + rgbColor.b ) / T (2 );
73
+ return result;
74
+ }
75
+
76
+ static GLM_FUNC_QUALIFIER tvec3<T, P> YCoCgR2rgb
77
+ (
78
+ tvec3<T, P> const & YCoCgRColor
79
+ )
80
+ {
81
+ tvec3<T, P> result;
82
+ T tmp = YCoCgRColor.x - (YCoCgRColor.z / T (2 ));
83
+ result.g = YCoCgRColor.z + tmp;
84
+ result.b = tmp - (YCoCgRColor.y / T (2 ));
85
+ result.r = result.b + YCoCgRColor.y ;
86
+ return result;
87
+ }
88
+ };
89
+
61
90
template <typename T, precision P>
62
- GLM_FUNC_QUALIFIER tvec3<T, P> YCoCg2rgb
91
+ class compute_YCoCgR <T, P, true > {
92
+ public:
93
+ static GLM_FUNC_QUALIFIER tvec3<T, P> rgb2YCoCgR
94
+ (
95
+ tvec3<T, P> const & rgbColor
96
+ )
97
+ {
98
+ tvec3<T, P> result;
99
+ result.y /* Co*/ = rgbColor.r - rgbColor.b ;
100
+ T tmp = rgbColor.b + (result.y >> 1 );
101
+ result.z /* Cg*/ = rgbColor.g - tmp;
102
+ result.x /* Y */ = tmp + (result.z >> 1 );
103
+ return result;
104
+ }
105
+
106
+ static GLM_FUNC_QUALIFIER tvec3<T, P> YCoCgR2rgb
107
+ (
108
+ tvec3<T, P> const & YCoCgRColor
109
+ )
110
+ {
111
+ tvec3<T, P> result;
112
+ T tmp = YCoCgRColor.x - (YCoCgRColor.z >> 1 );
113
+ result.g = YCoCgRColor.z + tmp;
114
+ result.b = tmp - (YCoCgRColor.y >> 1 );
115
+ result.r = result.b + YCoCgRColor.y ;
116
+ return result;
117
+ }
118
+ };
119
+
120
+ template <typename T, precision P>
121
+ GLM_FUNC_QUALIFIER tvec3<T, P> rgb2YCoCgR
63
122
(
64
- tvec3<T, P> const & YCoCgColor
123
+ tvec3<T, P> const & rgbColor
65
124
)
66
125
{
67
- tvec3<T, P> result;
68
- result.r = YCoCgColor.x + YCoCgColor.y - YCoCgColor.z ;
69
- result.g = YCoCgColor.x + YCoCgColor.z ;
70
- result.b = YCoCgColor.x - YCoCgColor.y - YCoCgColor.z ;
71
- return result;
126
+ return compute_YCoCgR<T, P, std::numeric_limits<T>::is_integer>::rgb2YCoCgR (rgbColor);
72
127
}
73
128
74
129
template <typename T, precision P>
@@ -77,11 +132,6 @@ namespace glm
77
132
tvec3<T, P> const & YCoCgRColor
78
133
)
79
134
{
80
- tvec3<T, P> result;
81
- T tmp = YCoCgRColor.x - (YCoCgRColor.z / T (2 ));
82
- result.g = YCoCgRColor.z + tmp;
83
- result.b = tmp - (YCoCgRColor.y / T (2 ));
84
- result.r = result.b + YCoCgRColor.y ;
85
- return result;
135
+ return compute_YCoCgR<T, P, std::numeric_limits<T>::is_integer>::YCoCgR2rgb (YCoCgRColor);
86
136
}
87
137
}// namespace glm
0 commit comments