Skip to content

Commit

Permalink
Merge pull request #641 from vpenades/master
Browse files Browse the repository at this point in the history
WIP Generate all Pixel Blender/Composer possible combinations to solve #535
  • Loading branch information
JimBobSquarePants authored Aug 19, 2018
2 parents c49b031 + 74a16f1 commit 485395d
Show file tree
Hide file tree
Showing 13 changed files with 6,387 additions and 1,152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected GradientBrushApplicatorBase(
throw new ArgumentOutOfRangeException();
}

var (from, to) = this.GetGradientSegment(positionOnCompleteGradient);
(ColorStop<TPixel> from, ColorStop<TPixel> to) = this.GetGradientSegment(positionOnCompleteGradient);

if (from.Color.Equals(to.Color))
{
Expand All @@ -124,7 +124,7 @@ protected GradientBrushApplicatorBase(
float onLocalGradient = (positionOnCompleteGradient - from.Ratio) / to.Ratio;

// TODO: this should be changeble for different gradienting functions
Vector4 result = PorterDuffFunctions.Normal(
Vector4 result = PorterDuffFunctions.NormalSrcOver(
fromAsVector,
toAsVector,
onLocalGradient);
Expand Down Expand Up @@ -153,11 +153,11 @@ protected GradientBrushApplicatorBase(
private (ColorStop<TPixel> from, ColorStop<TPixel> to) GetGradientSegment(
float positionOnCompleteGradient)
{
var localGradientFrom = this.colorStops[0];
ColorStop<TPixel> localGradientFrom = this.colorStops[0];
ColorStop<TPixel> localGradientTo = default;

// TODO: ensure colorStops has at least 2 items (technically 1 would be okay, but that's no gradient)
foreach (var colorStop in this.colorStops)
foreach (ColorStop<TPixel> colorStop in this.colorStops)
{
localGradientTo = colorStop;

Expand Down
3,561 changes: 3,477 additions & 84 deletions src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,22 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
{

<#


string[] composers = new []{
"Src",
"SrcAtop",
"SrcOver",
"SrcIn",
"SrcOut",
"Dest",
"DestAtop",
"DestOver",
"DestIn",
"DestOut",
"Clear",
"Xor",
};

string[] blenders = new []{
string[] blenders = new []{
"Normal",
"Multiply",
"Add",
Expand All @@ -47,36 +59,26 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
"Darken",
"Lighten",
"Overlay",
"HardLight",
"Src" ,
"Atop" ,
"Over" ,
"In" ,
"Out" ,
"Dest" ,
"DestAtop" ,
"DestOver" ,
"DestIn" ,
"DestOut" ,
"Clear" ,
"Xor" ,
"HardLight"
};



foreach(var composer in composers) {
foreach(var blender in blenders) {

string blender_composer= $"{blender}{composer}";

#>
internal class <#=blender#> : PixelBlender<TPixel>
internal class <#= blender_composer#> : PixelBlender<TPixel>
{
/// <summary>
/// Gets the static instance of this blender.
/// </summary>
public static <#=blender#> Instance { get; } = new <#=blender#>();
public static <#=blender_composer#> Instance { get; } = new <#=blender_composer#>();

/// <inheritdoc />
public override TPixel Blend(TPixel background, TPixel source, float amount)
{
return PorterDuffFunctions.<#=blender#>(background, source, amount);
return PorterDuffFunctions.<#=blender_composer#>(background, source, amount);
}

/// <inheritdoc />
Expand All @@ -97,7 +99,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders

for (int i = 0; i < destination.Length; i++)
{
destinationSpan[i] = PorterDuffFunctions.<#=blender#>(backgroundSpan[i], sourceSpan[i], amount[i]);
destinationSpan[i] = PorterDuffFunctions.<#=blender_composer#>(backgroundSpan[i], sourceSpan[i], amount[i]);
}

PixelOperations<TPixel>.Instance.PackFromVector4(destinationSpan, destination, destination.Length);
Expand All @@ -106,7 +108,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
}

<#

}
}

#>
Expand Down
Loading

0 comments on commit 485395d

Please sign in to comment.