ClassLibraryWeiBao/QR二维码/Windows/Render/ColorContrast.cs
(开头部分) 8KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#if NETFX_CORE
using Windows.UI;
#elif SILVERLIGHT
using System.Windows.Media;
#else
using System.Drawing;
#endif
namespace Gma.QrCodeNet.Encoding.Windows.Render
{
/// <summary>
/// Port from Lea Vero's Contrast ratio javascript library.
/// Formula that's on W3C
/// http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
/// http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef
/// Even though contrast ratio is used mainly for human eye. But decoder is very similar. Highest ratio for black and white is easiest to identify and decode.
/// Where two same color is impossible, closest color is similar as well.
/// Decoder normally turn colored color to White Gray Black colors.
/// Another important to note is proper decoder won't treat lighter color as 0, they will use pattern to match. Thus inverse color is possible.
/// Pattern 1011101 << "w b w w w b w" is exactly same as "b w b b b w b"
/// </summary>
public static class ColorContrast
{
#if NETFX_CORE || SILVERLIGHT
private static double Luminance(Color color)
{
#else
private static double Luminance(GColor color)
{
#endif
double r, g, b;
r = Colorspace(color.R);
g = Colorspace(color.G);
b = Colorspace(color.B);
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
}
private static double Colorspace(byte rgb)
{
double result = Convert.ToDouble(rgb) / Convert.ToDouble(byte.MaxValue);
result = result < 0.03928 ? result / 12.92 : Math.Pow(((result + 0.055) / 1.055), 2.4);
return result;
}
#if NETFX_CORE || SILVERLIGHT
private static Color InverseColor(Color color)
{
Color result = Color.FromArgb(color.A, ConvertByte(byte.MaxValue - color.R), ConvertByte(byte.MaxValue - color.G), ConvertByte(byte.MaxValue - color.B));
return result;
}
后面还有 190 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。