mirror of https://github.com/SixLabors/ImageSharp
4 changed files with 2414 additions and 2645 deletions
File diff suppressed because it is too large
@ -1,237 +1,191 @@ |
|||||
<# |
<# |
||||
// Copyright (c) Six Labors and contributors. |
// Copyright (c) Six Labors and contributors. |
||||
// Licensed under the Apache License, Version 2.0. |
// Licensed under the Apache License, Version 2.0. |
||||
#> |
#> |
||||
<#@ template debug="false" hostspecific="false" language="C#" #> |
<#@ template debug="false" hostspecific="false" language="C#" #> |
||||
<#@ assembly name="System.Core" #> |
<#@ assembly name="System.Core" #> |
||||
<#@ import namespace="System.Linq" #> |
<#@ import namespace="System.Linq" #> |
||||
<#@ import namespace="System.Text" #> |
<#@ import namespace="System.Text" #> |
||||
<#@ import namespace="System.Collections.Generic" #> |
<#@ import namespace="System.Collections.Generic" #> |
||||
<#@ output extension=".cs" #> |
<#@ output extension=".cs" #> |
||||
// Copyright (c) Six Labors and contributors. |
// Copyright (c) Six Labors and contributors. |
||||
// Licensed under the Apache License, Version 2.0. |
// Licensed under the Apache License, Version 2.0. |
||||
|
|
||||
// <auto-generated /> |
// <auto-generated /> |
||||
|
|
||||
using System; |
using System; |
||||
using System.Numerics; |
using System.Numerics; |
||||
using System.Runtime.CompilerServices; |
using System.Runtime.CompilerServices; |
||||
|
|
||||
namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders |
namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders |
||||
{ |
{ |
||||
internal static partial class PorterDuffFunctions |
internal static partial class PorterDuffFunctions |
||||
{ |
{ |
||||
|
|
||||
|
<# void GeneratePixelBlenders(string blender) { #> |
||||
<# void GenerateVectorCompositor(string name, string sourceVar, string destVar, string blendVar) |
|
||||
{ |
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
int a_s = sourceVar == "Vector4.Zero" ? 0 : 1; |
public static Vector4 <#=blender#>_Src(Vector4 backdrop, Vector4 source, float opacity) |
||||
int a_b = destVar == "Vector4.Zero" ? 0 : 1; |
{ |
||||
int a_x = blendVar == "Vector4.Zero" ? 0 : 1; |
opacity = opacity.Clamp(0, 1); |
||||
#> |
source.W *= opacity; |
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
||||
public static Vector4 <#=name#>(Vector4 backdrop, Vector4 source, Vector4 xform) |
return source; |
||||
{ |
} |
||||
// calculate weights |
|
||||
float xw = backdrop.W * source.W; |
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
float bw = backdrop.W - xw; |
public static Vector4 <#=blender#>_SrcAtop(Vector4 backdrop, Vector4 source, float opacity) |
||||
float sw = source.W - xw; |
{ |
||||
|
opacity = opacity.Clamp(0, 1); |
||||
// calculate final alpha |
source.W *= opacity; |
||||
float fw = (sw * <#=a_s#>) + (bw * <#=a_b#>) + (xw * <#=a_x#>); |
|
||||
|
return Atop(backdrop, source, <#=blender#>(backdrop, source)); |
||||
// calculate final value |
} |
||||
xform = ((<#=blendVar#> * xw) + (<#=destVar#> * bw) + (<#=sourceVar#> * sw)) / MathF.Max(fw, Constants.Epsilon); |
|
||||
xform.W = fw; |
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
public static Vector4 <#=blender#>_SrcOver(Vector4 backdrop, Vector4 source, float opacity) |
||||
return xform; |
{ |
||||
} |
opacity = opacity.Clamp(0, 1); |
||||
<# } #> |
source.W *= opacity; |
||||
|
|
||||
|
return Over(backdrop, source, <#=blender#>(backdrop, source)); |
||||
|
} |
||||
|
|
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
<# void GeneratePixelBlenders(string blender) { #> |
public static Vector4 <#=blender#>_SrcIn(Vector4 backdrop, Vector4 source, float opacity) |
||||
|
{ |
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
opacity = opacity.Clamp(0, 1); |
||||
public static Vector4 <#=blender#>_Src(Vector4 backdrop, Vector4 source, float opacity) |
source.W *= opacity; |
||||
{ |
|
||||
opacity = opacity.Clamp(0, 1); |
return In(backdrop, source, <#=blender#>(backdrop, source)); |
||||
source.W *= opacity; |
} |
||||
|
|
||||
return Src(backdrop, source, <#=blender#>(backdrop, source)); |
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
} |
public static Vector4 <#=blender#>_SrcOut(Vector4 backdrop, Vector4 source, float opacity) |
||||
|
{ |
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
opacity = opacity.Clamp(0, 1); |
||||
public static Vector4 <#=blender#>_SrcAtop(Vector4 backdrop, Vector4 source, float opacity) |
source.W *= opacity; |
||||
{ |
|
||||
opacity = opacity.Clamp(0, 1); |
return Out(backdrop, source); |
||||
source.W *= opacity; |
} |
||||
|
|
||||
return SrcAtop(backdrop, source, <#=blender#>(backdrop, source)); |
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
} |
public static Vector4 <#=blender#>_Dest(Vector4 backdrop, Vector4 source, float opacity) |
||||
|
{ |
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
return backdrop; |
||||
public static Vector4 <#=blender#>_SrcOver(Vector4 backdrop, Vector4 source, float opacity) |
} |
||||
{ |
|
||||
opacity = opacity.Clamp(0, 1); |
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
source.W *= opacity; |
public static Vector4 <#=blender#>_DestAtop(Vector4 backdrop, Vector4 source, float opacity) |
||||
|
{ |
||||
return SrcOver(backdrop, source, <#=blender#>(backdrop, source)); |
opacity = opacity.Clamp(0, 1); |
||||
} |
source.W *= opacity; |
||||
|
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
return Atop(source, backdrop, <#=blender#>(source, backdrop)); |
||||
public static Vector4 <#=blender#>_SrcIn(Vector4 backdrop, Vector4 source, float opacity) |
} |
||||
{ |
|
||||
opacity = opacity.Clamp(0, 1); |
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
source.W *= opacity; |
public static Vector4 <#=blender#>_DestOver(Vector4 backdrop, Vector4 source, float opacity) |
||||
|
{ |
||||
return SrcIn(backdrop, source, <#=blender#>(backdrop, source)); |
opacity = opacity.Clamp(0, 1); |
||||
} |
source.W *= opacity; |
||||
|
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
return Over(source, backdrop, <#=blender#>(source, backdrop)); |
||||
public static Vector4 <#=blender#>_SrcOut(Vector4 backdrop, Vector4 source, float opacity) |
} |
||||
{ |
|
||||
opacity = opacity.Clamp(0, 1); |
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
source.W *= opacity; |
public static Vector4 <#=blender#>_DestIn(Vector4 backdrop, Vector4 source, float opacity) |
||||
|
{ |
||||
return SrcOut(backdrop, source, <#=blender#>(backdrop, source)); |
opacity = opacity.Clamp(0, 1); |
||||
} |
source.W *= opacity; |
||||
|
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
return In(source, backdrop, <#=blender#>(source, backdrop)); |
||||
public static Vector4 <#=blender#>_Dest(Vector4 backdrop, Vector4 source, float opacity) |
} |
||||
{ |
|
||||
opacity = opacity.Clamp(0, 1); |
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
source.W *= opacity; |
public static Vector4 <#=blender#>_DestOut(Vector4 backdrop, Vector4 source, float opacity) |
||||
|
{ |
||||
return Dest(backdrop, source, <#=blender#>(backdrop, source)); |
opacity = opacity.Clamp(0, 1); |
||||
} |
source.W *= opacity; |
||||
|
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
return Out(source, backdrop); |
||||
public static Vector4 <#=blender#>_DestAtop(Vector4 backdrop, Vector4 source, float opacity) |
} |
||||
{ |
|
||||
opacity = opacity.Clamp(0, 1); |
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
source.W *= opacity; |
public static Vector4 <#=blender#>_Xor(Vector4 backdrop, Vector4 source, float opacity) |
||||
|
{ |
||||
return DestAtop(backdrop, source, <#=blender#>(backdrop, source)); |
opacity = opacity.Clamp(0, 1); |
||||
} |
source.W *= opacity; |
||||
|
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
return Xor(backdrop, source); |
||||
public static Vector4 <#=blender#>_DestOver(Vector4 backdrop, Vector4 source, float opacity) |
} |
||||
{ |
|
||||
opacity = opacity.Clamp(0, 1); |
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
source.W *= opacity; |
public static Vector4 <#=blender#>_Clear(Vector4 backdrop, Vector4 source, float opacity) |
||||
|
{ |
||||
return DestOver(backdrop, source, <#=blender#>(backdrop, source)); |
opacity = opacity.Clamp(0, 1); |
||||
} |
source.W *= opacity; |
||||
|
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
return Clear(backdrop, source); |
||||
public static Vector4 <#=blender#>_DestIn(Vector4 backdrop, Vector4 source, float opacity) |
} |
||||
{ |
<# } #> |
||||
opacity = opacity.Clamp(0, 1); |
|
||||
source.W *= opacity; |
|
||||
|
<# void GenerateGenericPixelBlender(string blender, string composer) { #> |
||||
return DestIn(backdrop, source, <#=blender#>(backdrop, source)); |
|
||||
} |
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
public static TPixel <#=blender#>_<#=composer#><TPixel>(TPixel backdrop, TPixel source, float opacity) |
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
where TPixel : struct, IPixel<TPixel> |
||||
public static Vector4 <#=blender#>_DestOut(Vector4 backdrop, Vector4 source, float opacity) |
{ |
||||
{ |
TPixel dest = default; |
||||
opacity = opacity.Clamp(0, 1); |
dest.PackFromVector4(<#=blender#>_<#=composer#>(backdrop.ToVector4(),source.ToVector4(),opacity)); |
||||
source.W *= opacity; |
return dest; |
||||
|
} |
||||
return DestOut(backdrop, source, <#=blender#>(backdrop, source)); |
|
||||
} |
<# } #> |
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
||||
public static Vector4 <#=blender#>_Clear(Vector4 backdrop, Vector4 source, float opacity) |
#region Blenders |
||||
{ |
<# |
||||
opacity = opacity.Clamp(0, 1); |
|
||||
source.W *= opacity; |
string[] composers = new []{ |
||||
|
"Src" , |
||||
return Clear(backdrop, source, source); |
"SrcAtop" , |
||||
} |
"SrcOver" , |
||||
|
"SrcIn" , |
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
"SrcOut" , |
||||
public static Vector4 <#=blender#>_Xor(Vector4 backdrop, Vector4 source, float opacity) |
"Dest" , |
||||
{ |
"DestAtop" , |
||||
opacity = opacity.Clamp(0, 1); |
"DestOver" , |
||||
source.W *= opacity; |
"DestIn" , |
||||
|
"DestOut" , |
||||
return Xor(backdrop, source, source); |
"Clear" , |
||||
} |
"Xor" , |
||||
|
}; |
||||
<# } #> |
|
||||
|
string[] blenders = new []{ |
||||
|
"Normal" , |
||||
<# void GenerateGenericPixelBlender(string blender, string composer) { #> |
"Multiply" , |
||||
|
"Add" , |
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
"Subtract" , |
||||
public static TPixel <#=blender#>_<#=composer#><TPixel>(TPixel backdrop, TPixel source, float opacity) |
"Screen" , |
||||
where TPixel : struct, IPixel<TPixel> |
"Darken" , |
||||
{ |
"Lighten" , |
||||
TPixel dest = default; |
"Overlay" , |
||||
dest.PackFromVector4(<#=blender#>_<#=composer#>(backdrop.ToVector4(),source.ToVector4(),opacity)); |
"HardLight" |
||||
return dest; |
}; |
||||
} |
|
||||
|
foreach(var blender in blenders) |
||||
<# } #> |
{ |
||||
|
GeneratePixelBlenders(blender); |
||||
#region Blenders |
|
||||
<# |
foreach(var composer in composers) |
||||
|
{ |
||||
// GenerateVectorCompositor("Src", "source", "Vector4.Zero", "xform"); |
GenerateGenericPixelBlender(blender,composer); |
||||
GenerateVectorCompositor("SrcAtop", "Vector4.Zero", "backdrop", "xform"); |
} |
||||
GenerateVectorCompositor("SrcOver", "source", "backdrop", "xform"); |
} |
||||
// GenerateVectorCompositor("SrcIn", "Vector4.Zero", "Vector4.Zero", "xform"); |
|
||||
// GenerateVectorCompositor("SrcOut", "source", "Vector4.Zero", "Vector4.Zero"); |
#> |
||||
GenerateVectorCompositor("Dest", "Vector4.Zero", "backdrop", "backdrop"); |
|
||||
// GenerateVectorCompositor("DestAtop", "source", "Vector4.Zero", "backdrop"); |
#endregion |
||||
// GenerateVectorCompositor("DestOver", "source", "backdrop", "backdrop"); |
} |
||||
// GenerateVectorCompositor("DestIn", "Vector4.Zero", "Vector4.Zero", "backdrop"); |
|
||||
GenerateVectorCompositor("DestOut", "Vector4.Zero", "backdrop", "Vector4.Zero"); |
|
||||
// GenerateVectorCompositor("Clear", "Vector4.Zero", "Vector4.Zero", "Vector4.Zero"); |
|
||||
GenerateVectorCompositor("Xor", "source", "backdrop", "Vector4.Zero"); |
|
||||
|
|
||||
string[] composers = new []{ |
|
||||
"Src" , |
|
||||
"SrcAtop" , |
|
||||
"SrcOver" , |
|
||||
"SrcIn" , |
|
||||
"SrcOut" , |
|
||||
"Dest" , |
|
||||
"DestAtop" , |
|
||||
"DestOver" , |
|
||||
"DestIn" , |
|
||||
"DestOut" , |
|
||||
"Clear" , |
|
||||
"Xor" , |
|
||||
}; |
|
||||
|
|
||||
string[] blenders = new []{ |
|
||||
"Normal" , |
|
||||
"Multiply" , |
|
||||
"Add" , |
|
||||
"Subtract" , |
|
||||
"Screen" , |
|
||||
"Darken" , |
|
||||
"Lighten" , |
|
||||
"Overlay" , |
|
||||
"HardLight" |
|
||||
}; |
|
||||
|
|
||||
foreach(var blender in blenders) |
|
||||
{ |
|
||||
GeneratePixelBlenders(blender); |
|
||||
|
|
||||
foreach(var composer in composers) |
|
||||
{ |
|
||||
GenerateGenericPixelBlender(blender,composer); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
#> |
|
||||
|
|
||||
#endregion |
|
||||
} |
|
||||
} |
} |
||||
Loading…
Reference in new issue