|
@@ -8,13 +8,22 @@ namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.FilterNodes;
|
|
[NodeInfo("Sepia")]
|
|
[NodeInfo("Sepia")]
|
|
public class SepiaFilterNode : FilterNode
|
|
public class SepiaFilterNode : FilterNode
|
|
{
|
|
{
|
|
|
|
+ public InputProperty<double> Intensity { get; }
|
|
|
|
+
|
|
private ColorMatrix srgbSepiaMatrix;
|
|
private ColorMatrix srgbSepiaMatrix;
|
|
private ColorMatrix linearSepiaMatrix;
|
|
private ColorMatrix linearSepiaMatrix;
|
|
private ColorFilter linearSepiaFilter;
|
|
private ColorFilter linearSepiaFilter;
|
|
private ColorFilter sepiaColorFilter;
|
|
private ColorFilter sepiaColorFilter;
|
|
|
|
|
|
|
|
+ protected override bool ExecuteOnlyOnCacheChange => true;
|
|
|
|
+ protected override CacheTriggerFlags CacheTrigger => CacheTriggerFlags.Inputs;
|
|
|
|
+
|
|
|
|
+ private ColorFilter lastFilter;
|
|
|
|
+
|
|
public SepiaFilterNode()
|
|
public SepiaFilterNode()
|
|
{
|
|
{
|
|
|
|
+ Intensity = CreateInput("Intensity", "INTENSITY", 1d);
|
|
|
|
+
|
|
srgbSepiaMatrix = new ColorMatrix(
|
|
srgbSepiaMatrix = new ColorMatrix(
|
|
[
|
|
[
|
|
0.393f, 0.769f, 0.189f, 0.0f, 0.0f,
|
|
0.393f, 0.769f, 0.189f, 0.0f, 0.0f,
|
|
@@ -32,12 +41,14 @@ public class SepiaFilterNode : FilterNode
|
|
|
|
|
|
protected override ColorFilter? GetColorFilter(ColorSpace colorSpace)
|
|
protected override ColorFilter? GetColorFilter(ColorSpace colorSpace)
|
|
{
|
|
{
|
|
- if (colorSpace.IsSrgb)
|
|
|
|
- {
|
|
|
|
- return sepiaColorFilter;
|
|
|
|
- }
|
|
|
|
|
|
+ var targetMatrix = colorSpace.IsSrgb ? srgbSepiaMatrix : linearSepiaMatrix;
|
|
|
|
+
|
|
|
|
+ lastFilter?.Dispose();
|
|
|
|
+
|
|
|
|
+ var lerped = ColorMatrix.Lerp(ColorMatrix.Identity, targetMatrix, (float)Intensity.Value);
|
|
|
|
+ lastFilter = ColorFilter.CreateColorMatrix(lerped);
|
|
|
|
|
|
- return linearSepiaFilter;
|
|
|
|
|
|
+ return lastFilter;
|
|
}
|
|
}
|
|
|
|
|
|
public override Node CreateCopy()
|
|
public override Node CreateCopy()
|