mirror of
https://github.com/RPCS3/discord-bot.git
synced 2024-12-12 21:29:56 +00:00
fix color conversions
This commit is contained in:
parent
cf396a9556
commit
2194c53052
@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using CompatApiClient.Utils;
|
||||
using Microsoft.Azure.CognitiveServices.Vision.ComputerVision.Models;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.ColorSpaces;
|
||||
using SixLabors.ImageSharp.ColorSpaces.Conversion;
|
||||
@ -13,13 +11,15 @@ namespace CompatBot.Utils.Extensions
|
||||
private static readonly ColorSpaceConverter colorSpaceConverter = new ColorSpaceConverter();
|
||||
|
||||
public static Color ToStandardColor(this ColorThiefDotNet.Color c)
|
||||
=> new Argb32(c.R, c.G, c.B, c.A);
|
||||
=> new Rgba32(c.R, c.G, c.B, c.A);
|
||||
|
||||
public static Color GetComplementary(this Color src, bool preserveOpacity = false)
|
||||
{
|
||||
var c = src.ToPixel<Argb32>();
|
||||
var c = src.ToPixel<Rgba32>();
|
||||
var a = c.A;
|
||||
//if RGB values are close to each other by a diff less than 10%, then if RGB values are lighter side, decrease the blue by 50% (eventually it will increase in conversion below), if RBB values are on darker side, decrease yellow by about 50% (it will increase in conversion)
|
||||
//if RGB values are close to each other by a diff less than 10%, then if RGB values are lighter side,
|
||||
//decrease the blue by 50% (eventually it will increase in conversion below),
|
||||
//if RBB values are on darker side, decrease yellow by about 50% (it will increase in conversion)
|
||||
var avgColorValue = (c.R + c.G + c.B) / 3.0;
|
||||
var dR = Math.Abs(c.R - avgColorValue);
|
||||
var dG = Math.Abs(c.G - avgColorValue);
|
||||
@ -27,9 +27,9 @@ namespace CompatBot.Utils.Extensions
|
||||
if (dR < 20 && dG < 20 && dB < 20) //The color is a shade of gray
|
||||
{
|
||||
if (avgColorValue < 123) //color is dark
|
||||
c = new Argb32(a, 220, 230, 50);
|
||||
c = new Rgba32(220, 230, 50, a);
|
||||
else
|
||||
c = new Argb32(a, 255, 255, 50);
|
||||
c = new Rgba32(255, 255, 50, a);
|
||||
}
|
||||
if (!preserveOpacity)
|
||||
a = Math.Max(a, (byte)127); //We don't want contrast color to be more than 50% transparent ever.
|
||||
@ -37,7 +37,7 @@ namespace CompatBot.Utils.Extensions
|
||||
var h = hsb.H;
|
||||
h = h < 180 ? h + 180 : h - 180;
|
||||
var r = colorSpaceConverter.ToRgb(new Hsv(h, hsb.S, hsb.V));
|
||||
return new Argb32(a, r.R, r.G, r.B);
|
||||
return new Rgba32(r.R, r.G, r.B, a);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user