This repository has been archived by the owner on Sep 25, 2023. It is now read-only.
forked from imchillin/Anamnesis
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve color accuracy in extended appearance
- Loading branch information
1 parent
d4be64b
commit 45a65ed
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// © Anamnesis. | ||
// Licensed under the MIT license. | ||
|
||
namespace Anamnesis.Styles.Converters; | ||
|
||
using System; | ||
using System.Globalization; | ||
using System.Windows.Data; | ||
using Anamnesis.Memory; | ||
|
||
[ValueConversion(typeof(Color), typeof(Color))] | ||
[ValueConversion(typeof(Color4), typeof(Color4))] | ||
public class SquaredRgbConverter : IValueConverter | ||
{ | ||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
if (value is Color rgb) | ||
{ | ||
return new Color(MathF.Sqrt(rgb.R), MathF.Sqrt(rgb.G), MathF.Sqrt(rgb.B)); | ||
} | ||
else if (value is Color4 rgba) | ||
{ | ||
return new Color4(MathF.Sqrt(rgba.R), MathF.Sqrt(rgba.G), MathF.Sqrt(rgba.B), rgba.A); | ||
} | ||
else | ||
{ | ||
return value; | ||
} | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
if (value is Color rgb) | ||
{ | ||
return new Color(rgb.R * rgb.R, rgb.G * rgb.G, rgb.B * rgb.B); | ||
} | ||
else if (value is Color4 rgba) | ||
{ | ||
return new Color4(rgba.R * rgba.R, rgba.G * rgba.G, rgba.B * rgba.B, rgba.A); | ||
} | ||
else | ||
{ | ||
return value; | ||
} | ||
} | ||
} |