Browse Source

Fix 1D resize + performance tweaks

Former-commit-id: 6a3854cdfd8fa47b3e49dfdd5a4a116a7eace69d
Former-commit-id: 620f3c76756cfc7176d05fe20ae108b2a7f0da6e
Former-commit-id: 9829703cea2c316e5a6800b844450b0a9c14f301
af/merge-core
James Jackson-South 10 years ago
parent
commit
5f411a99ba
  1. 2
      src/ImageProcessorCore/Samplers/ImageSamplerExtensions.cs
  2. 15
      src/ImageProcessorCore/Samplers/Resampler.cs
  3. 15
      tests/ImageProcessorCore.Benchmarks/Program.cs
  4. 3
      tests/ImageProcessorCore.Benchmarks/project.json
  5. 19
      tests/TestWebsites/MVC/Properties/launchSettings.json

2
src/ImageProcessorCore/Samplers/ImageSamplerExtensions.cs

@ -199,11 +199,13 @@ namespace ImageProcessorCore.Samplers
if (width == 0 && height > 0) if (width == 0 && height > 0)
{ {
width = source.Width * height / source.Height; width = source.Width * height / source.Height;
targetRectangle.Width = width;
} }
if (height == 0 && width > 0) if (height == 0 && width > 0)
{ {
height = source.Height * width / source.Width; height = source.Height * width / source.Width;
targetRectangle.Height = height;
} }
Guard.MustBeGreaterThan(width, 0, nameof(width)); Guard.MustBeGreaterThan(width, 0, nameof(width));

15
src/ImageProcessorCore/Samplers/Resampler.cs

@ -2,7 +2,6 @@
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
namespace ImageProcessorCore.Samplers namespace ImageProcessorCore.Samplers
{ {
using System; using System;
@ -57,7 +56,7 @@ namespace ImageProcessorCore.Samplers
float radius = sampler.Radius; float radius = sampler.Radius;
double left; double left;
double right; double right;
double weight; float weight;
int index; int index;
int sum; int sum;
@ -79,14 +78,12 @@ namespace ImageProcessorCore.Samplers
result[i] = new Weights result[i] = new Weights
{ {
Sum = 0,
Values = new Weight[(int)(right - left + 1)] Values = new Weight[(int)(right - left + 1)]
}; };
for (double j = left; j <= right; j++) for (double j = left; j <= right; j++)
{ {
weight = centre - j; weight = sampler.GetValue((float)((centre - j) / filterScale)) / filterScale;
weight = sampler.GetValue((float)(weight / filterScale)) / filterScale;
if (j < 0) if (j < 0)
{ {
index = (int)-j; index = (int)-j;
@ -101,7 +98,7 @@ namespace ImageProcessorCore.Samplers
} }
sum = (int)result[i].Sum++; sum = (int)result[i].Sum++;
result[i].Values[sum] = new Weight(index, (float)weight); result[i].Values[sum] = new Weight(index, weight);
} }
} }
} }
@ -115,14 +112,12 @@ namespace ImageProcessorCore.Samplers
right = Math.Floor(centre + radius); right = Math.Floor(centre + radius);
result[i] = new Weights result[i] = new Weights
{ {
Sum = 0,
Values = new Weight[(int)(right - left + 1)] Values = new Weight[(int)(right - left + 1)]
}; };
for (double j = left; j <= right; j++) for (double j = left; j <= right; j++)
{ {
weight = centre - j; weight = sampler.GetValue((float)(centre - j));
weight = sampler.GetValue((float)weight);
if (j < 0) if (j < 0)
{ {
index = (int)-j; index = (int)-j;
@ -137,7 +132,7 @@ namespace ImageProcessorCore.Samplers
} }
sum = (int)result[i].Sum++; sum = (int)result[i].Sum++;
result[i].Values[sum] = new Weight(index, (float)weight); result[i].Values[sum] = new Weight(index, weight);
} }
} }
} }

15
tests/ImageProcessorCore.Benchmarks/Program.cs

@ -1,25 +1,36 @@
namespace ImageProcessorCore.Benchmarks namespace ImageProcessorCore.Benchmarks
{ {
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection; using System.Reflection;
using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running; using BenchmarkDotNet.Running;
using System.Linq;
public class Program public class Program
{ {
/// <summary>
/// The main.
/// </summary>
/// <param name="args">
/// The arguments to pas to the program.
/// </param>
public static void Main(string[] args) public static void Main(string[] args)
{ {
// Use reflection for a more maintainable way of creating the benchmark switcher, // Use reflection for a more maintainable way of creating the benchmark switcher,
Type[] benchmarks = typeof(Program).Assembly.GetTypes() Type[] benchmarks = typeof(Program).Assembly.GetTypes()
.Where(t => t.GetMethods(BindingFlags.Instance | BindingFlags.Public) .Where(t => t.GetMethods(BindingFlags.Instance | BindingFlags.Public)
.Any(m => m.GetCustomAttributes(typeof(BenchmarkAttribute), false).Any())) .Any(m => m.GetCustomAttributes(typeof(BenchmarkAttribute), false).Any()))
.OrderBy(t => t.Namespace) .OrderBy(t => t.Namespace)
.ThenBy(t => t.Name) .ThenBy(t => t.Name)
.ToArray(); .ToArray();
// TODO: This throws an exception.
// List<string> x = new List<string>(args) { "diagnosers=MemoryDiagnoser,InliningDiagnoser" };
BenchmarkSwitcher benchmarkSwitcher = new BenchmarkSwitcher(benchmarks); BenchmarkSwitcher benchmarkSwitcher = new BenchmarkSwitcher(benchmarks);
// benchmarkSwitcher.Run(x.ToArray());
benchmarkSwitcher.Run(args); benchmarkSwitcher.Run(args);
} }
} }

3
tests/ImageProcessorCore.Benchmarks/project.json

@ -13,7 +13,8 @@
"emitEntryPoint": true "emitEntryPoint": true
}, },
"dependencies": { "dependencies": {
"BenchmarkDotNet": "0.9.6", "BenchmarkDotNet": "0.9.7",
"BenchmarkDotNet.Diagnostics.Windows": "0.9.7",
"ImageProcessorCore": "1.0.0-*" "ImageProcessorCore": "1.0.0-*"
}, },
"commands": { "commands": {

19
tests/TestWebsites/MVC/Properties/launchSettings.json

@ -1,19 +0,0 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:55993/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Loading…
Cancel
Save