-
Notifications
You must be signed in to change notification settings - Fork 2
/
ContrastSaturationBrightness.uno
92 lines (83 loc) · 1.73 KB
/
ContrastSaturationBrightness.uno
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using Uno;
using Uno.Graphics;
using Uno.UX;
using Fuse.Effects;
using Fuse;
// Based on https://mouaif.wordpress.com/2009/01/05/photoshop-math-with-glsl-shaders/
public sealed class ContrastSaturationBrightness : BasicEffect
{
float _brightness = 1.0f;
public float Brightness
{
get
{
return _brightness;
}
set
{
if(value!=_brightness)
{
_brightness = value;
OnRenderingChanged();
}
}
}
float _saturation = 1.0f;
public float Saturation
{
get
{
return _saturation;
}
set
{
if(value!=_saturation)
{
_saturation = value;
OnRenderingChanged();
}
}
}
float3 _contrast = float3(1.0f);
public float3 Contrast
{
get
{
return _contrast;
}
set
{
if(value!=_contrast)
{
_contrast = value;
OnRenderingChanged();
}
}
}
public ContrastSaturationBrightness() : base(EffectType.Composition)
{
}
protected override void OnRender(DrawContext dc, Rect elementRect)
{
var original = Element.CaptureRegion(dc, elementRect, int2(0));
if (original == null)
return;
draw Fuse.Drawing.Planar.Image
{
DrawContext: dc;
Visual: Element;
Position: elementRect.Minimum;
Invert: true;
Size: elementRect.Size;
Texture: original.ColorBuffer;
float3 lumCoeff: float3(0.2125f, 0.7154f, 0.0721f);
float3 brightnessColor: TextureColor.XYZ * _brightness;
float intensityf: Uno.Vector.Dot(brightnessColor, lumCoeff);
float3 intensity: float3(intensityf, intensityf, intensityf);
float3 satColor: Uno.Math.Lerp(intensity, brightnessColor, _saturation);
float3 conColor: Uno.Math.Lerp(float3(0.5f,0.5f,0.5f), satColor, _contrast);
PixelColor: float4(conColor.XYZ, TextureColor.W);
};
FramebufferPool.Release(original);
}
}