mirror of https://github.com/SixLabors/ImageSharp
69 changed files with 321 additions and 437 deletions
@ -1,114 +1,114 @@ |
|||
<# |
|||
// Copyright (c) Six Labors and contributors. |
|||
// Licensed under the Apache License, Version 2.0. |
|||
#> |
|||
<#@ template debug="false" hostspecific="false" language="C#" #> |
|||
<#@ assembly name="System.Core" #> |
|||
<#@ import namespace="System.Linq" #> |
|||
<#@ import namespace="System.Text" #> |
|||
<#@ import namespace="System.Collections.Generic" #> |
|||
<#@ output extension=".cs" #> |
|||
// Copyright (c) Six Labors and contributors. |
|||
// Licensed under the Apache License, Version 2.0. |
|||
|
|||
// <auto-generated /> |
|||
<# |
|||
// Copyright (c) Six Labors and contributors. |
|||
// Licensed under the Apache License, Version 2.0. |
|||
#> |
|||
<#@ template debug="false" hostspecific="false" language="C#" #> |
|||
<#@ assembly name="System.Core" #> |
|||
<#@ import namespace="System.Linq" #> |
|||
<#@ import namespace="System.Text" #> |
|||
<#@ import namespace="System.Collections.Generic" #> |
|||
<#@ output extension=".cs" #> |
|||
// Copyright (c) Six Labors and contributors. |
|||
// Licensed under the Apache License, Version 2.0. |
|||
|
|||
// <auto-generated /> |
|||
using System; |
|||
using System.Numerics; |
|||
using System.Buffers; |
|||
|
|||
using SixLabors.ImageSharp.Memory; |
|||
using SixLabors.Memory; |
|||
|
|||
namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders |
|||
{ |
|||
/// <summary> |
|||
/// Collection of Porter Duff alpha blending functions applying different composition models. |
|||
/// </summary> |
|||
/// <remarks> |
|||
/// These functions are designed to be a general solution for all color cases, |
|||
/// that is, they take in account the alpha value of both the backdrop |
|||
/// and source, and there's no need to alpha-premultiply neither the backdrop |
|||
/// nor the source. |
|||
/// Note there are faster functions for when the backdrop color is known |
|||
/// to be opaque |
|||
/// </remarks> |
|||
internal static class DefaultPixelBlenders<TPixel> |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
|
|||
<# |
|||
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 composer in composers) { |
|||
foreach(var blender in blenders) { |
|||
|
|||
string blender_composer= $"{blender}{composer}"; |
|||
|
|||
#> |
|||
internal class <#= blender_composer#> : PixelBlender<TPixel> |
|||
{ |
|||
/// <summary> |
|||
/// Gets the static instance of this blender. |
|||
/// </summary> |
|||
public static <#=blender_composer#> Instance { get; } = new <#=blender_composer#>(); |
|||
|
|||
/// <inheritdoc /> |
|||
public override TPixel Blend(TPixel background, TPixel source, float amount) |
|||
{ |
|||
using SixLabors.Memory; |
|||
|
|||
namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders |
|||
{ |
|||
/// <summary> |
|||
/// Collection of Porter Duff alpha blending functions applying different composition models. |
|||
/// </summary> |
|||
/// <remarks> |
|||
/// These functions are designed to be a general solution for all color cases, |
|||
/// that is, they take in account the alpha value of both the backdrop |
|||
/// and source, and there's no need to alpha-premultiply neither the backdrop |
|||
/// nor the source. |
|||
/// Note there are faster functions for when the backdrop color is known |
|||
/// to be opaque |
|||
/// </remarks> |
|||
internal static class DefaultPixelBlenders<TPixel> |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
|
|||
<# |
|||
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 composer in composers) { |
|||
foreach(var blender in blenders) { |
|||
|
|||
string blender_composer= $"{blender}{composer}"; |
|||
|
|||
#> |
|||
internal class <#= blender_composer#> : PixelBlender<TPixel> |
|||
{ |
|||
/// <summary> |
|||
/// Gets the static instance of this blender. |
|||
/// </summary> |
|||
public static <#=blender_composer#> Instance { get; } = new <#=blender_composer#>(); |
|||
|
|||
/// <inheritdoc /> |
|||
public override TPixel Blend(TPixel background, TPixel source, float amount) |
|||
{ |
|||
TPixel dest = default; |
|||
dest.PackFromScaledVector4(PorterDuffFunctions.<#=blender_composer#>(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); |
|||
return dest; |
|||
} |
|||
|
|||
/// <inheritdoc /> |
|||
protected override void BlendFunction(Span<Vector4> destination, ReadOnlySpan<Vector4> background, ReadOnlySpan<Vector4> source, float amount) |
|||
{ |
|||
amount = amount.Clamp(0, 1); |
|||
for (int i = 0; i < destination.Length; i++) |
|||
{ |
|||
destination[i] = PorterDuffFunctions.<#=blender_composer#>(background[i], source[i], amount); |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc /> |
|||
protected override void BlendFunction(Span<Vector4> destination, ReadOnlySpan<Vector4> background, ReadOnlySpan<Vector4> source, ReadOnlySpan<float> amount) |
|||
{ |
|||
for (int i = 0; i < destination.Length; i++) |
|||
{ |
|||
destination[i] = PorterDuffFunctions.<#=blender_composer#>(background[i], source[i], amount[i].Clamp(0, 1)); |
|||
} |
|||
} |
|||
} |
|||
|
|||
<# |
|||
} |
|||
} |
|||
|
|||
#> |
|||
} |
|||
dest.FromScaledVector4(PorterDuffFunctions.<#=blender_composer#>(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1))); |
|||
return dest; |
|||
} |
|||
|
|||
/// <inheritdoc /> |
|||
protected override void BlendFunction(Span<Vector4> destination, ReadOnlySpan<Vector4> background, ReadOnlySpan<Vector4> source, float amount) |
|||
{ |
|||
amount = amount.Clamp(0, 1); |
|||
for (int i = 0; i < destination.Length; i++) |
|||
{ |
|||
destination[i] = PorterDuffFunctions.<#=blender_composer#>(background[i], source[i], amount); |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc /> |
|||
protected override void BlendFunction(Span<Vector4> destination, ReadOnlySpan<Vector4> background, ReadOnlySpan<Vector4> source, ReadOnlySpan<float> amount) |
|||
{ |
|||
for (int i = 0; i < destination.Length; i++) |
|||
{ |
|||
destination[i] = PorterDuffFunctions.<#=blender_composer#>(background[i], source[i], amount[i].Clamp(0, 1)); |
|||
} |
|||
} |
|||
} |
|||
|
|||
<# |
|||
} |
|||
} |
|||
|
|||
#> |
|||
} |
|||
} |
|||
Loading…
Reference in new issue