Browse Source

Add new test image for rewrite

Former-commit-id: 9ddf97eb0300834d945db627e4c500e67fbf1fb7
Former-commit-id: c9a893530a085724596af1054492d125dc0355ea
Former-commit-id: 3266f3ce095fd3f865d0e540e6096f794de70c4f
af/merge-core
James Jackson-South 10 years ago
parent
commit
e1a2a9b2c6
  1. 1
      src/ImageProcessor/ImageProcessor.csproj
  2. 33
      src/ImageProcessor/Samplers/Resamplers/Lanczos8Resampler.cs
  3. 8
      src/ImageProcessor/Samplers/Resize.cs
  4. 3
      tests/ImageProcessor.Tests/Processors/ProcessorTestBase.cs
  5. 3
      tests/ImageProcessor.Tests/Processors/Samplers/SamplerTests.cs
  6. 3
      tests/ImageProcessor.Tests/TestImages/Formats/Gif/rings.gif

1
src/ImageProcessor/ImageProcessor.csproj

@ -181,6 +181,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Numerics\Rectangle.cs" />
<Compile Include="Numerics\Size.cs" />
<Compile Include="Samplers\Resamplers\Lanczos8Resampler.cs" />
<Compile Include="Samplers\Resamplers\WelchResampler.cs" />
<Compile Include="Samplers\Resamplers\CatmullRomResampler.cs" />
<Compile Include="Samplers\Resamplers\RobidouxSoftResampler.cs" />

33
src/ImageProcessor/Samplers/Resamplers/Lanczos8Resampler.cs

@ -0,0 +1,33 @@
// <copyright file="Lanczos3Resampler.cs" company="James South">
// Copyright © James South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessor.Samplers
{
/// <summary>
/// The function implements the Lanczos kernel algorithm as described on
/// <see href="https://en.wikipedia.org/wiki/Lanczos_resampling#Algorithm">Wikipedia</see>
/// </summary>
public class Lanczos8Resampler : IResampler
{
/// <inheritdoc/>
public double Radius => 8;
/// <inheritdoc/>
public double GetValue(double x)
{
if (x < 0)
{
x = -x;
}
if (x < 8)
{
return ImageMaths.SinC(x) * ImageMaths.SinC(x / 8f);
}
return 0;
}
}
}

8
src/ImageProcessor/Samplers/Resize.cs

@ -48,7 +48,7 @@ namespace ImageProcessor.Samplers
int startX = targetRectangle.X;
int endX = targetRectangle.Right;
int right = (int)(this.Sampler.Radius + .5);
int left = -right;
int left = (-right) + 1;
// Scaling factors
double widthFactor = sourceWidth / (double)targetRectangle.Width;
@ -86,7 +86,7 @@ namespace ImageProcessor.Samplers
for (int yy = left; yy <= right; yy++)
{
// Get Y cooefficient
double kernel1 = this.Sampler.GetValue(dy - yy);
double kernel1 = this.Sampler.GetValue(yy - dy);
if (Math.Abs(kernel1) < Epsilon)
{
@ -126,7 +126,7 @@ namespace ImageProcessor.Samplers
}
Bgra sourceColor = source[originX2, originY2];
sourceColor = PixelOperations.ToLinear(sourceColor);
// sourceColor = PixelOperations.ToLinear(sourceColor);
r += kernel2 * sourceColor.R;
g += kernel2 * sourceColor.G;
@ -136,7 +136,7 @@ namespace ImageProcessor.Samplers
}
Bgra destinationColor = new Bgra(b.ToByte(), g.ToByte(), r.ToByte(), a.ToByte());
destinationColor = PixelOperations.ToSrgb(destinationColor);
// destinationColor = PixelOperations.ToSrgb(destinationColor);
target[x, y] = destinationColor;
}
}

3
tests/ImageProcessor.Tests/Processors/ProcessorTestBase.cs

@ -19,11 +19,12 @@ namespace ImageProcessor.Tests
/// </summary>
public static readonly List<string> Files = new List<string>
{
//"../../TestImages/Formats/Jpg/Backdrop.jpg",
"../../TestImages/Formats/Jpg/Backdrop.jpg",
"../../TestImages/Formats/Jpg/Calliphora.jpg",
//"../../TestImages/Formats/Bmp/Car.bmp",
//"../../TestImages/Formats/Png/cmyk.png",
//"../../TestImages/Formats/Gif/leaf.gif"
"../../TestImages/Formats/Gif/rings.gif"
// { "../../TestImages/Formats/Gif/ani.gif" },
// { "../../TestImages/Formats/Gif/ani2.gif" },

3
tests/ImageProcessor.Tests/Processors/Samplers/SamplerTests.cs

@ -17,6 +17,7 @@ namespace ImageProcessor.Tests
{ "Bilinear", new TriangleResampler() },
{ "NearestNeighbour", new BoxResampler() },
{ "Lanczos3", new Lanczos3Resampler() },
{ "Lanczos8", new Lanczos8Resampler() },
{ "MitchellNetravali", new MitchellNetravaliResampler() },
{ "Hermite", new HermiteResampler() },
{ "Spline", new SplineResampler() },
@ -44,7 +45,7 @@ namespace ImageProcessor.Tests
string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file);
using (FileStream output = File.OpenWrite($"Resized/{filename}"))
{
image.Resize(200, 298, sampler).Save(output);
image.Resize(100, 100, sampler).Save(output);
}
Trace.WriteLine($"{name}: {watch.ElapsedMilliseconds}ms");

3
tests/ImageProcessor.Tests/TestImages/Formats/Gif/rings.gif

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:716448da88152225767c024aac498f5b7562b6e8391907cefc9d03dba40050fd
size 53435
Loading…
Cancel
Save