Browse Source

Optimize dither

af/merge-core
James Jackson-South 9 years ago
parent
commit
49a95e4ba0
  1. 2
      README.md
  2. 33
      src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs
  3. 3
      src/ImageSharp/Processing/Processors/Binarization/OrderedDitherProcessor.cs

2
README.md

@ -119,7 +119,7 @@ using (Image<Rgba32> image = new Image<Rgba32>(400, 400)
For optimized access within a loop it is recommended that the following methods are used.
1. `image.GetRowSpan(y)`
2. `image.GetRowSPan(x, y)`
2. `image.GetRowSpan(x, y)`
For advanced pixel format usage there are multiple [PixelFormat implementations](https://github.com/JimBobSquarePants/ImageSharp/tree/master/src/ImageSharp/PixelFormats) available allowing developers to implement their own color models in the same manner as Microsoft XNA Game Studio and MonoGame.

33
src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs

@ -83,25 +83,22 @@ namespace ImageSharp.Processing.Processors
startY = 0;
}
using (PixelAccessor<TPixel> sourcePixels = source.Lock())
{
Parallel.For(
minY,
maxY,
this.ParallelOptions,
y =>
Parallel.For(
minY,
maxY,
this.ParallelOptions,
y =>
{
Span<TPixel> row = source.GetRowSpan(y - startY);
for (int x = minX; x < maxX; x++)
{
int offsetY = y - startY;
for (int x = minX; x < maxX; x++)
{
int offsetX = x - startX;
TPixel color = sourcePixels[offsetX, offsetY];
// Any channel will do since it's Grayscale.
sourcePixels[offsetX, offsetY] = color.ToVector4().X >= threshold ? upper : lower;
}
});
}
ref TPixel color = ref row[x - startX];
// Any channel will do since it's Grayscale.
color = color.ToVector4().X >= threshold ? upper : lower;
}
});
}
}
}

3
src/ImageSharp/Processing/Processors/Binarization/OrderedDitherProcessor.cs

@ -97,11 +97,12 @@ namespace ImageSharp.Processing.Processors
for (int y = minY; y < maxY; y++)
{
int offsetY = y - startY;
Span<TPixel> row = source.GetRowSpan(offsetY);
for (int x = minX; x < maxX; x++)
{
int offsetX = x - startX;
TPixel sourceColor = source[offsetX, offsetY];
TPixel sourceColor = row[offsetX];
this.Dither.Dither(source, sourceColor, this.UpperColor, this.LowerColor, bytes, this.Index, offsetX, offsetY, maxX, maxY);
}
}

Loading…
Cancel
Save