Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

Commit

Permalink
Improve color accuracy in extended appearance
Browse files Browse the repository at this point in the history
  • Loading branch information
Exter-N authored and Yuki-Codes committed Aug 8, 2023
1 parent d4be64b commit 45a65ed
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions Anamnesis/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<BooleanToVisibilityConverter x:Key="B2V" />
<converters:Vector2DRadiansToDegreesConverter x:Key="Vec2DRad2Deg" />
<converters:ImageReferenceConverter x:Key="Img" />
<converters:SquaredRgbConverter x:Key="SquaredRgb" />

<!-- Atkinson-Hyperlegible font -->
<FontFamily x:Key="Atkinson-Hyperlegible">pack://application:,,,/Assets/Fonts/#Atkinson Hyperlegible</FontFamily>
Expand Down
46 changes: 46 additions & 0 deletions Anamnesis/Styles/Converters/SquaredRgbConverter.cs
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;
}
}
}

0 comments on commit 45a65ed

Please sign in to comment.