From a56be055a559ea439de85d10bfbd0040497f9d25 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 6 Jun 2016 02:15:52 +1000 Subject: [PATCH] Fix 1D resize + performance tweaks Former-commit-id: 6a3854cdfd8fa47b3e49dfdd5a4a116a7eace69d Former-commit-id: 620f3c76756cfc7176d05fe20ae108b2a7f0da6e Former-commit-id: 9829703cea2c316e5a6800b844450b0a9c14f301 --- .../Samplers/ImageSamplerExtensions.cs | 2 ++ src/ImageProcessorCore/Samplers/Resampler.cs | 15 +++++---------- .../ImageProcessorCore.Benchmarks/Program.cs | 15 +++++++++++++-- .../project.json | 3 ++- .../MVC/Properties/launchSettings.json | 19 ------------------- 5 files changed, 22 insertions(+), 32 deletions(-) delete mode 100644 tests/TestWebsites/MVC/Properties/launchSettings.json diff --git a/src/ImageProcessorCore/Samplers/ImageSamplerExtensions.cs b/src/ImageProcessorCore/Samplers/ImageSamplerExtensions.cs index 09e059263..4fe463cc1 100644 --- a/src/ImageProcessorCore/Samplers/ImageSamplerExtensions.cs +++ b/src/ImageProcessorCore/Samplers/ImageSamplerExtensions.cs @@ -199,11 +199,13 @@ namespace ImageProcessorCore.Samplers if (width == 0 && height > 0) { width = source.Width * height / source.Height; + targetRectangle.Width = width; } if (height == 0 && width > 0) { height = source.Height * width / source.Width; + targetRectangle.Height = height; } Guard.MustBeGreaterThan(width, 0, nameof(width)); diff --git a/src/ImageProcessorCore/Samplers/Resampler.cs b/src/ImageProcessorCore/Samplers/Resampler.cs index a59c25644..656b45780 100644 --- a/src/ImageProcessorCore/Samplers/Resampler.cs +++ b/src/ImageProcessorCore/Samplers/Resampler.cs @@ -2,7 +2,6 @@ // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // - namespace ImageProcessorCore.Samplers { using System; @@ -57,7 +56,7 @@ namespace ImageProcessorCore.Samplers float radius = sampler.Radius; double left; double right; - double weight; + float weight; int index; int sum; @@ -79,14 +78,12 @@ namespace ImageProcessorCore.Samplers result[i] = new Weights { - Sum = 0, Values = new Weight[(int)(right - left + 1)] }; for (double j = left; j <= right; j++) { - weight = centre - j; - weight = sampler.GetValue((float)(weight / filterScale)) / filterScale; + weight = sampler.GetValue((float)((centre - j) / filterScale)) / filterScale; if (j < 0) { index = (int)-j; @@ -101,7 +98,7 @@ namespace ImageProcessorCore.Samplers } 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); result[i] = new Weights { - Sum = 0, Values = new Weight[(int)(right - left + 1)] }; for (double j = left; j <= right; j++) { - weight = centre - j; - weight = sampler.GetValue((float)weight); + weight = sampler.GetValue((float)(centre - j)); if (j < 0) { index = (int)-j; @@ -137,7 +132,7 @@ namespace ImageProcessorCore.Samplers } sum = (int)result[i].Sum++; - result[i].Values[sum] = new Weight(index, (float)weight); + result[i].Values[sum] = new Weight(index, weight); } } } diff --git a/tests/ImageProcessorCore.Benchmarks/Program.cs b/tests/ImageProcessorCore.Benchmarks/Program.cs index 07b512c8f..9e743dd02 100644 --- a/tests/ImageProcessorCore.Benchmarks/Program.cs +++ b/tests/ImageProcessorCore.Benchmarks/Program.cs @@ -1,25 +1,36 @@ namespace ImageProcessorCore.Benchmarks { using System; + using System.Collections.Generic; + using System.Linq; using System.Reflection; using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Running; - using System.Linq; public class Program { + /// + /// The main. + /// + /// + /// The arguments to pas to the program. + /// public static void Main(string[] args) { // Use reflection for a more maintainable way of creating the benchmark switcher, Type[] benchmarks = typeof(Program).Assembly.GetTypes() .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) .ThenBy(t => t.Name) .ToArray(); + // TODO: This throws an exception. + // List x = new List(args) { "diagnosers=MemoryDiagnoser,InliningDiagnoser" }; BenchmarkSwitcher benchmarkSwitcher = new BenchmarkSwitcher(benchmarks); + + // benchmarkSwitcher.Run(x.ToArray()); benchmarkSwitcher.Run(args); } } diff --git a/tests/ImageProcessorCore.Benchmarks/project.json b/tests/ImageProcessorCore.Benchmarks/project.json index 15244e5ca..6b3d780b5 100644 --- a/tests/ImageProcessorCore.Benchmarks/project.json +++ b/tests/ImageProcessorCore.Benchmarks/project.json @@ -13,7 +13,8 @@ "emitEntryPoint": true }, "dependencies": { - "BenchmarkDotNet": "0.9.6", + "BenchmarkDotNet": "0.9.7", + "BenchmarkDotNet.Diagnostics.Windows": "0.9.7", "ImageProcessorCore": "1.0.0-*" }, "commands": { diff --git a/tests/TestWebsites/MVC/Properties/launchSettings.json b/tests/TestWebsites/MVC/Properties/launchSettings.json deleted file mode 100644 index 0ce7c413b..000000000 --- a/tests/TestWebsites/MVC/Properties/launchSettings.json +++ /dev/null @@ -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" - } - } - } -} \ No newline at end of file