Browse Source

Optimize BackgroundColor

af/merge-core
James Jackson-South 9 years ago
parent
commit
7c529d7ff8
  1. 12
      src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs

12
src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs

@ -6,7 +6,6 @@
namespace ImageSharp.Processing.Processors namespace ImageSharp.Processing.Processors
{ {
using System; using System;
using System.Numerics;
using System.Threading.Tasks; using System.Threading.Tasks;
using ImageSharp.Memory; using ImageSharp.Memory;
@ -64,9 +63,8 @@ namespace ImageSharp.Processing.Processors
int width = maxX - minX; int width = maxX - minX;
using (Buffer<TPixel> colors = new Buffer<TPixel>(width)) using (var colors = new Buffer<TPixel>(width))
using (Buffer<float> amount = new Buffer<float>(width)) using (var amount = new Buffer<float>(width))
using (PixelAccessor<TPixel> sourcePixels = source.Lock())
{ {
for (int i = 0; i < width; i++) for (int i = 0; i < width; i++)
{ {
@ -81,11 +79,9 @@ namespace ImageSharp.Processing.Processors
this.ParallelOptions, this.ParallelOptions,
y => y =>
{ {
int offsetY = y - startY; Span<TPixel> destination = source.GetRowSpan(y - startY).Slice(minX - startX, width);
Span<TPixel> destination = sourcePixels.GetRowSpan(offsetY).Slice(minX - startX, width); // This switched color & destination in the 2nd and 3rd places because we are applying the target colour under the current one
// this switched color & destination in the 2nd and 3rd places because we are applying the target colour under the current one
blender.Blend(destination, colors, destination, amount); blender.Blend(destination, colors, destination, amount);
}); });
} }

Loading…
Cancel
Save