Skip to content

Commit

Permalink
feat(composition): Implement GammaTransferEffect + Sample
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed605 committed Mar 2, 2024
1 parent 3f976ba commit 57bcce9
Show file tree
Hide file tree
Showing 3 changed files with 442 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
<Grid x:Name="crossfadeGrid" Width="200" Height="200" VerticalAlignment="Top" HorizontalAlignment="Left" ToolTipService.ToolTip="CrossFadeEffect"/>
<Grid x:Name="lumaGrid" Width="200" Height="200" VerticalAlignment="Top" HorizontalAlignment="Left" ToolTipService.ToolTip="LuminanceToAlphaEffect"/>
<Grid x:Name="linearXferGrid" Width="200" Height="200" VerticalAlignment="Top" HorizontalAlignment="Left" ToolTipService.ToolTip="LinearTransferEffect"/>
<Grid x:Name="gammaXferGrid" Width="200" Height="200" VerticalAlignment="Top" HorizontalAlignment="Left" ToolTipService.ToolTip="GammaTransferEffect"/>
</GridView>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ private void EffectBrushTests_Loaded(object sender, RoutedEventArgs e)
var effectBrush15 = factory15.CreateBrush();

linearXferGrid.Background = new EffectTesterBrush(effectBrush15);

var effect16 = new SimpleGammaTransferEffect() { Source = new CompositionEffectSourceParameter("sourceBrush"), RedExponent = 0.25f, GreenExponent = 0.25f, BlueExponent = 0.25f };
var factory16 = compositor.CreateEffectFactory(effect16);
var effectBrush16 = factory16.CreateBrush();

gammaXferGrid.Background = new EffectTesterBrush(effectBrush16);
#endif
}

Expand Down Expand Up @@ -1020,6 +1026,224 @@ public object GetProperty(uint index)
public IGraphicsEffectSource GetSource(uint index) => Source;
public uint GetSourceCount() => 1;
}

[Guid("409444C4-C419-41A0-B0C1-8CD0C0A18E42")]
private class SimpleGammaTransferEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop
{
private string _name = "SimpleGammaTransferEffect";
private Guid _id = new Guid("409444C4-C419-41A0-B0C1-8CD0C0A18E42");

public string Name
{
get => _name;
set => _name = value;
}

public float RedAmplitude { get; set; } = 1.0f;

public float RedExponent { get; set; } = 1.0f;

public float RedOffset { get; set; } = 0.0f;

public bool RedDisable { get; set; } = false;


public float GreenAmplitude { get; set; } = 1.0f;

public float GreenExponent { get; set; } = 1.0f;

public float GreenOffset { get; set; } = 0.0f;

public bool GreenDisable { get; set; } = false;


public float BlueAmplitude { get; set; } = 1.0f;

public float BlueExponent { get; set; } = 1.0f;

public float BlueOffset { get; set; } = 0.0f;

public bool BlueDisable { get; set; } = false;


public float AlphaAmplitude { get; set; } = 1.0f;

public float AlphaExponent { get; set; } = 1.0f;

public float AlphaOffset { get; set; } = 0.0f;

public bool AlphaDisable { get; set; } = false;


public bool ClampOutput { get; set; } = false;


public IGraphicsEffectSource Source { get; set; }

public Guid GetEffectId() => _id;

public void GetNamedPropertyMapping(string name, out uint index, out GraphicsEffectPropertyMapping mapping)
{
switch (name)
{
case "RedAmplitude":
{
index = 0;
mapping = GraphicsEffectPropertyMapping.Direct;
break;
}
case "RedExponent":
{
index = 1;
mapping = GraphicsEffectPropertyMapping.Direct;
break;
}
case "RedOffset":
{
index = 2;
mapping = GraphicsEffectPropertyMapping.Direct;
break;
}
case "RedDisable":
{
index = 3;
mapping = GraphicsEffectPropertyMapping.Direct;
break;
}
case "GreenAmplitude":
{
index = 4;
mapping = GraphicsEffectPropertyMapping.Direct;
break;
}
case "GreenExponent":
{
index = 5;
mapping = GraphicsEffectPropertyMapping.Direct;
break;
}
case "GreenOffset":
{
index = 6;
mapping = GraphicsEffectPropertyMapping.Direct;
break;
}
case "GreenDisable":
{
index = 7;
mapping = GraphicsEffectPropertyMapping.Direct;
break;
}
case "BlueAmplitude":
{
index = 8;
mapping = GraphicsEffectPropertyMapping.Direct;
break;
}
case "BlueExponent":
{
index = 9;
mapping = GraphicsEffectPropertyMapping.Direct;
break;
}
case "BlueOffset":
{
index = 10;
mapping = GraphicsEffectPropertyMapping.Direct;
break;
}
case "BlueDisable":
{
index = 11;
mapping = GraphicsEffectPropertyMapping.Direct;
break;
}
case "AlphaAmplitude":
{
index = 12;
mapping = GraphicsEffectPropertyMapping.Direct;
break;
}
case "AlphaExponent":
{
index = 13;
mapping = GraphicsEffectPropertyMapping.Direct;
break;
}
case "AlphaOffset":
{
index = 14;
mapping = GraphicsEffectPropertyMapping.Direct;
break;
}
case "AlphaDisable":
{
index = 15;
mapping = GraphicsEffectPropertyMapping.Direct;
break;
}
case "ClampOutput":
{
index = 16;
mapping = GraphicsEffectPropertyMapping.Direct;
break;
}
default:
{
index = 0xFF;
mapping = (GraphicsEffectPropertyMapping)0xFF;
break;
}
}
}

public object GetProperty(uint index)
{
switch (index)
{
case 0:
return RedAmplitude;
case 1:
return RedExponent;
case 2:
return RedOffset;
case 3:
return RedDisable;
case 4:
return GreenAmplitude;
case 5:
return GreenExponent;
case 6:
return GreenOffset;
case 7:
return GreenDisable;
case 8:
return BlueAmplitude;
case 9:
return BlueExponent;
case 10:
return BlueOffset;
case 11:
return BlueDisable;
case 12:
return AlphaAmplitude;
case 13:
return AlphaExponent;
case 14:
return AlphaOffset;
case 15:
return AlphaDisable;
case 16:
return ClampOutput;
default:
return null;
}
}

public uint GetPropertyCount() => 17;
public IGraphicsEffectSource GetSource(uint index) => Source;
public uint GetSourceCount() => 1;
}
#endif
}
}
Loading

0 comments on commit 57bcce9

Please sign in to comment.