Browse Source

adjust opacity for normal blur...

feature/test-branch
Dan Walmsley 6 years ago
parent
commit
5ba822f94f
  1. 16
      src/Avalonia.Visuals/Media/ExperimentalAcrylicBrush.cs
  2. 30
      src/Skia/Avalonia.Skia/DrawingContextImpl.cs

16
src/Avalonia.Visuals/Media/ExperimentalAcrylicBrush.cs

@ -139,12 +139,18 @@ namespace Avalonia.Media
}
else
{
tintColor = new Color((byte)(Math.Round(tintColor.A * tintOpacity * tintOpacityModifier)), tintColor.R, tintColor.G, tintColor.B);
tintColor = new Color((byte)(255 * ((255.0 / tintColor.A) * tintOpacity) * tintOpacityModifier), tintColor.R, tintColor.G, tintColor.B);
}
return tintColor;
}
private static double AdjustOpacity(double opacity)
{
var result = Math.Max((1.0 - Math.Pow((1.0 - opacity), 3.85)), 0.92);
return result;
}
private static double GetTintOpacityModifier(Color tintColor)
{
// This method supresses the maximum allowable tint opacity depending on the luminosity and saturation of a color by
@ -155,9 +161,9 @@ namespace Avalonia.Media
const double midPoint = 0.5; // Mid point of HsvV range that these calculations are based on. This is here for easy tuning.
const double whiteMaxOpacity = 0.40; // 100% luminosity
const double midPointMaxOpacity = 0.50; // 50% luminosity
const double blackMaxOpacity = 0.80; // 0% luminosity
double whiteMaxOpacity = AdjustOpacity(0.45); // 100% luminosity
double midPointMaxOpacity = AdjustOpacity(0.40); // 50% luminosity
double blackMaxOpacity = AdjustOpacity(0.60); // 0% luminosity
var hsv = RgbToHsv(tintColor);
@ -189,7 +195,7 @@ namespace Avalonia.Media
if (hsv.Saturation > 0)
{
// Dampen opacity suppression based on how much saturation there is
maxOpacitySuppression *= Math.Max(1 - (hsv.Saturation * 2), 0.0);
//maxOpacitySuppression *= Math.Max(1 - (hsv.Saturation * 2), 0.0);
}
double opacitySuppression = maxOpacitySuppression * normalizedDeviation;

30
src/Skia/Avalonia.Skia/DrawingContextImpl.cs

@ -668,6 +668,27 @@ namespace Avalonia.Skia
return SKColorFilter.CreateTable(a, c, c, c);
}
static byte Blend(byte leftColor, byte leftAlpha, byte rightColor, byte rightAlpha)
{
var ca = leftColor / 255d;
var aa = leftAlpha / 255d;
var cb = rightColor / 255d;
var ab = rightAlpha / 255d;
var r = (ca * aa + cb * ab * (1 - aa)) / (aa + ab * (1 - aa));
return (byte)(r * 255);
}
static SKColor Blend(SKColor left, SKColor right)
{
var aa = left.Alpha / 255d;
var ab = right.Alpha / 255d;
return new SKColor(
Blend(left.Red, left.Alpha, right.Red, right.Alpha),
Blend(left.Green, left.Alpha, right.Green, right.Alpha),
Blend(left.Blue, left.Alpha, right.Blue, right.Alpha),
(byte)((aa + ab * (1 - aa)) * 255)
);
}
/// <summary>
/// Creates paint wrapper for given brush.
/// </summary>
@ -700,9 +721,14 @@ namespace Avalonia.Skia
const double noiseOpcity = 0.0225;
var tintColor = acrylicBrush.TintColor;
var tint = new SKColor(tintColor.R, tintColor.G, tintColor.B, (byte)(255 * ((tintColor.A / 255.0) * acrylicBrush.Opacity * tintOpacity)));
var tint = new SKColor(tintColor.R, tintColor.G, tintColor.B, tintColor.A);
var tracingPaper = new SKColor(0xaf, 0x7f, 0x7f, 0x7f);
//tint = Blend(tracingPaper, tint);
if(s_acrylicNoiseShader == null)
if (s_acrylicNoiseShader == null)
{
using(var stream = typeof(DrawingContextImpl).Assembly.GetManifestResourceStream("Avalonia.Skia.Assets.NoiseAsset_256X256_PNG.png"))
using (var bitmap = SKBitmap.Decode(stream))

Loading…
Cancel
Save