Browse Source

Remove duplicate clamping and normalize vector scaling.

pull/686/head
James Jackson-South 8 years ago
parent
commit
0f4fcb5b3f
  1. 540
      src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs
  2. 5
      src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt
  3. 522
      src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs
  4. 25
      src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt
  5. 2
      src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs

540
src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs

File diff suppressed because it is too large

5
src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt

@ -81,13 +81,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
public override TPixel Blend(TPixel background, TPixel source, float amount) public override TPixel Blend(TPixel background, TPixel source, float amount)
{ {
TPixel dest = default; TPixel dest = default;
dest.PackFromScaledVector4(PorterDuffFunctions.<#=blender_composer#>(background.ToScaledVector4(),source.ToScaledVector4(),amount.Clamp(0,1))); dest.PackFromScaledVector4(PorterDuffFunctions.<#=blender_composer#>(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1)));
return dest; return dest;
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void BlendFunction(Span<Vector4> destination, ReadOnlySpan<Vector4> background, ReadOnlySpan<Vector4> source, float amount) 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++) for (int i = 0; i < destination.Length; i++)
{ {
destination[i] = PorterDuffFunctions.<#=blender_composer#>(background[i], source[i], amount); destination[i] = PorterDuffFunctions.<#=blender_composer#>(background[i], source[i], amount);
@ -99,7 +100,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
{ {
for (int i = 0; i < destination.Length; i++) for (int i = 0; i < destination.Length; i++)
{ {
destination[i] = PorterDuffFunctions.<#=blender_composer#>(background[i], source[i], amount[i]); destination[i] = PorterDuffFunctions.<#=blender_composer#>(background[i], source[i], amount[i].Clamp(0, 1));
} }
} }
} }

522
src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs

File diff suppressed because it is too large

25
src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt

@ -27,7 +27,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4 <#=blender#>Src(Vector4 backdrop, Vector4 source, float opacity) public static Vector4 <#=blender#>Src(Vector4 backdrop, Vector4 source, float opacity)
{ {
source.W *= opacity.Clamp(0,1); source.W *= opacity;
return source; return source;
} }
@ -35,7 +35,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4 <#=blender#>SrcAtop(Vector4 backdrop, Vector4 source, float opacity) public static Vector4 <#=blender#>SrcAtop(Vector4 backdrop, Vector4 source, float opacity)
{ {
source.W *= opacity.Clamp(0,1); source.W *= opacity;
return Atop(backdrop, source, <#=blender#>(backdrop, source)); return Atop(backdrop, source, <#=blender#>(backdrop, source));
} }
@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4 <#=blender#>SrcOver(Vector4 backdrop, Vector4 source, float opacity) public static Vector4 <#=blender#>SrcOver(Vector4 backdrop, Vector4 source, float opacity)
{ {
source.W *= opacity.Clamp(0,1); source.W *= opacity;
return Over(backdrop, source, <#=blender#>(backdrop, source)); return Over(backdrop, source, <#=blender#>(backdrop, source));
} }
@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4 <#=blender#>SrcIn(Vector4 backdrop, Vector4 source, float opacity) public static Vector4 <#=blender#>SrcIn(Vector4 backdrop, Vector4 source, float opacity)
{ {
source.W *= opacity.Clamp(0,1); source.W *= opacity;
return In(backdrop, source, <#=blender#>(backdrop, source)); return In(backdrop, source, <#=blender#>(backdrop, source));
} }
@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4 <#=blender#>SrcOut(Vector4 backdrop, Vector4 source, float opacity) public static Vector4 <#=blender#>SrcOut(Vector4 backdrop, Vector4 source, float opacity)
{ {
source.W *= opacity.Clamp(0,1); source.W *= opacity;
return Out(backdrop, source); return Out(backdrop, source);
} }
@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4 <#=blender#>DestAtop(Vector4 backdrop, Vector4 source, float opacity) public static Vector4 <#=blender#>DestAtop(Vector4 backdrop, Vector4 source, float opacity)
{ {
source.W *= opacity.Clamp(0,1); source.W *= opacity;
return Atop(source, backdrop, <#=blender#>(source, backdrop)); return Atop(source, backdrop, <#=blender#>(source, backdrop));
} }
@ -81,7 +81,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4 <#=blender#>DestOver(Vector4 backdrop, Vector4 source, float opacity) public static Vector4 <#=blender#>DestOver(Vector4 backdrop, Vector4 source, float opacity)
{ {
source.W *= opacity.Clamp(0,1); source.W *= opacity;
return Over(source, backdrop, <#=blender#>(source, backdrop)); return Over(source, backdrop, <#=blender#>(source, backdrop));
} }
@ -89,7 +89,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4 <#=blender#>DestIn(Vector4 backdrop, Vector4 source, float opacity) public static Vector4 <#=blender#>DestIn(Vector4 backdrop, Vector4 source, float opacity)
{ {
source.W *= opacity.Clamp(0,1); source.W *= opacity;
return In(source, backdrop, <#=blender#>(source, backdrop)); return In(source, backdrop, <#=blender#>(source, backdrop));
} }
@ -97,7 +97,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4 <#=blender#>DestOut(Vector4 backdrop, Vector4 source, float opacity) public static Vector4 <#=blender#>DestOut(Vector4 backdrop, Vector4 source, float opacity)
{ {
source.W *= opacity.Clamp(0,1); source.W *= opacity;
return Out(source, backdrop); return Out(source, backdrop);
} }
@ -105,7 +105,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4 <#=blender#>Xor(Vector4 backdrop, Vector4 source, float opacity) public static Vector4 <#=blender#>Xor(Vector4 backdrop, Vector4 source, float opacity)
{ {
source.W *= opacity.Clamp(0,1); source.W *= opacity;
return Xor(backdrop, source); return Xor(backdrop, source);
} }
@ -113,7 +113,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4 <#=blender#>Clear(Vector4 backdrop, Vector4 source, float opacity) public static Vector4 <#=blender#>Clear(Vector4 backdrop, Vector4 source, float opacity)
{ {
source.W *= opacity.Clamp(0,1); source.W *= opacity;
return Clear(backdrop, source); return Clear(backdrop, source);
} }
@ -126,8 +126,9 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
public static TPixel <#=blender#><#=composer#><TPixel>(TPixel backdrop, TPixel source, float opacity) public static TPixel <#=blender#><#=composer#><TPixel>(TPixel backdrop, TPixel source, float opacity)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
opacity = opacity.Clamp(0, 1);
TPixel dest = default; TPixel dest = default;
dest.PackFromVector4(<#=blender#><#=composer#>(backdrop.ToVector4(),source.ToVector4(),opacity)); dest.PackFromScaledVector4(<#=blender#><#=composer#>(backdrop.ToScaledVector4(), source.ToScaledVector4(), opacity));
return dest; return dest;
} }

2
src/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs

@ -130,7 +130,7 @@ namespace SixLabors.ImageSharp.PixelFormats
PixelOperations<TPixel>.Instance.ToScaledVector4(background, backgroundSpan, destination.Length); PixelOperations<TPixel>.Instance.ToScaledVector4(background, backgroundSpan, destination.Length);
PixelOperations<TPixelSrc>.Instance.ToScaledVector4(source, sourceSpan, destination.Length); PixelOperations<TPixelSrc>.Instance.ToScaledVector4(source, sourceSpan, destination.Length);
this.BlendFunction(destinationSpan, backgroundSpan, sourceSpan, amount.Clamp(0, 1)); this.BlendFunction(destinationSpan, backgroundSpan, sourceSpan, amount);
PixelOperations<TPixel>.Instance.PackFromScaledVector4(destinationSpan, destination, destination.Length); PixelOperations<TPixel>.Instance.PackFromScaledVector4(destinationSpan, destination, destination.Length);
} }

Loading…
Cancel
Save