Browse Source

Slight resampler improvements.

Former-commit-id: 09a687a857ede5d383c0ea75355f14ef7b3af3ad
Former-commit-id: ed7170e5e7240e94ab430bf08dc0af8c43ad30c0
Former-commit-id: d5ef91507e6a9503d4ec469282e6f1d0799f7224
pull/17/head
James Jackson-South 11 years ago
parent
commit
958a5933bf
  1. 27
      src/ImageProcessor/Samplers/Resampler.cs

27
src/ImageProcessor/Samplers/Resampler.cs

@ -17,12 +17,12 @@ namespace ImageProcessor.Samplers
/// <summary> /// <summary>
/// The epsilon for comparing floating point numbers. /// The epsilon for comparing floating point numbers.
/// </summary> /// </summary>
private const float Epsilon = 0.0001f; private const float Epsilon = 0.000001f;
/// <summary> /// <summary>
/// The angle of rotation. /// The angle of rotation.
/// </summary> /// </summary>
private double angle = 45; private double angle;
/// <summary> /// <summary>
/// The horizontal weights. /// The horizontal weights.
@ -95,10 +95,6 @@ namespace ImageProcessor.Samplers
Point centre = Rectangle.Center(sourceRectangle); Point centre = Rectangle.Center(sourceRectangle);
bool rotate = this.angle > 0 && this.angle < 360; bool rotate = this.angle > 0 && this.angle < 360;
int sourceBottom = sourceRectangle.Bottom;
int maxY = sourceBottom - 1;
int maxX = endX - 1;
Parallel.For( Parallel.For(
startY, startY,
endY, endY,
@ -135,8 +131,6 @@ namespace ImageProcessor.Samplers
int rotatedX = rotated.X; int rotatedX = rotated.X;
int rotatedY = rotated.Y; int rotatedY = rotated.Y;
// TODO: This can't work. We're not normalising properly since weights are skipped.
// Also... This is so slow!
if (sourceRectangle.Contains(rotatedX, rotatedY)) if (sourceRectangle.Contains(rotatedX, rotatedY))
{ {
sourceColor = Color.InverseCompand(source[rotatedX, rotatedY]); sourceColor = Color.InverseCompand(source[rotatedX, rotatedY]);
@ -161,10 +155,17 @@ namespace ImageProcessor.Samplers
} }
} }
destination = Color.Compand(destination); // Restrict alpha values in an attempt to prevent bleed.
// This is a baaaaaaad hack!!!
// Ensure are alpha values only reflect possible values to prevent bleed. if (destination.A <= 0.03)
destination.A = (float)Math.Round(destination.A, 2); {
destination = Color.Empty;
}
else
{
destination = Color.Compand(destination);
destination.A = (float)Math.Round(destination.A, 2);
}
target[x, y] = destination; target[x, y] = destination;
} }
@ -222,7 +223,7 @@ namespace ImageProcessor.Samplers
{ {
float w = sampler.GetValue((a - fu) / scale); float w = sampler.GetValue((a - fu) / scale);
if (Math.Abs(w) > Epsilon) if (w < 0 || w > 0)
{ {
sum += w; sum += w;
builder.Add(new Weight(a, w)); builder.Add(new Weight(a, w));

Loading…
Cancel
Save