@@ -206,12 +206,22 @@ namespace p
206206 }
207207 else if constexpr (to == ColorMode::Linear && from == ColorMode::HSV )
208208 {
209- const float hDiv60 = this ->h / 60 .0f ;
209+ float hue = Mod (this ->h , 360 .f );
210+ if ( hue < 0 .f ) hue += 360 .f ;
211+ const float saturation = p::Clamp (this ->s ,0 .f ,1 .f );
212+ const float value = this ->v ;
213+
214+ const float hDiv60 = hue / 60 .0f ;
210215 const float hDiv60Floor = Floor (hDiv60);
211216 const float hDiv60Fraction = hDiv60 - hDiv60Floor;
212-
213217 const u32 swizzleIndex = u32 (hDiv60Floor) % 6 ;
214218
219+ const float rgbValues[4 ] = {
220+ value,
221+ value * (1 .0f - saturation),
222+ value * (1 .0f - (hDiv60Fraction * saturation)),
223+ value * (1 .0f - ((1 .0f - hDiv60Fraction) * saturation)),
224+ };
215225 constexpr u32 rgbSwizzle[6 ][3 ] = {
216226 {0 , 3 , 1 },
217227 {2 , 0 , 1 },
@@ -220,20 +230,20 @@ namespace p
220230 {3 , 1 , 0 },
221231 {0 , 1 , 2 }
222232 };
223- const float rgbValues[4 ] = {
224- this ->v ,
225- this ->v * (1 .0f - this ->h ),
226- this ->v * (1 .0f - (hDiv60Fraction * this ->h )),
227- this ->v * (1 .0f - ((1 .0f - hDiv60Fraction) * this ->h )),
228- };
229- return {rgbValues[rgbSwizzle[swizzleIndex][0 ]],
230- rgbValues[rgbSwizzle[swizzleIndex][1 ]], rgbValues[rgbSwizzle[swizzleIndex][2 ]],
233+ return {
234+ rgbValues[rgbSwizzle[swizzleIndex][0 ]],
235+ rgbValues[rgbSwizzle[swizzleIndex][1 ]],
236+ rgbValues[rgbSwizzle[swizzleIndex][2 ]],
231237 this ->a };
232238 }
233239 else if constexpr (to == ColorMode::RGBA && from == ColorMode::HSV )
234240 {
235241 return Convert<ColorMode::Linear>().template Convert <to>();
236242 }
243+ else if constexpr (to == ColorMode::HSV && from == ColorMode::RGBA )
244+ {
245+ return Convert<ColorMode::Linear>().template Convert <to>();
246+ }
237247 else
238248 {
239249 P_CheckMsg (false , " Not supported color conversion" );
@@ -409,7 +419,10 @@ namespace p
409419 P_CheckMsg (false , " operator*(scalar) is not allowed on HSV" );
410420 return {};
411421 }
412- return {this ->r * scalar, this ->g * scalar, this ->b * scalar, this ->a * scalar};
422+ else
423+ {
424+ return {this ->r * scalar, this ->g * scalar, this ->b * scalar, this ->a * scalar};
425+ }
413426 }
414427 constexpr TColor& operator *=(float scalar)
415428 {
0 commit comments