From f125847e25c709240207fb70d047365e3f444e99 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sun, 7 Aug 2016 19:38:24 +1000 Subject: [PATCH] Missed file [skip ci] Former-commit-id: c579b2c9e4dae194b89b2f5e49b45999d56fc3a1 Former-commit-id: 6598d7c8ee36bb29bdda1f4b0733a9c3a5442b2e Former-commit-id: ea3870e6c90e92573c3a12fe80bf38fe0e17d149 --- .../Processors/ResamplingWeightedProcessor.cs | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/ImageProcessorCore/Samplers/Processors/ResamplingWeightedProcessor.cs b/src/ImageProcessorCore/Samplers/Processors/ResamplingWeightedProcessor.cs index 5630ec431f..ab41466cd9 100644 --- a/src/ImageProcessorCore/Samplers/Processors/ResamplingWeightedProcessor.cs +++ b/src/ImageProcessorCore/Samplers/Processors/ResamplingWeightedProcessor.cs @@ -9,6 +9,7 @@ namespace ImageProcessorCore.Processors /// /// Provides methods that allow the resizing of images using various algorithms. + /// Adapted from /// /// The pixel format. /// The packed format. long, float. @@ -77,8 +78,8 @@ namespace ImageProcessorCore.Processors float scale = (float)destinationSize / sourceSize; IResampler sampler = this.Sampler; float radius = sampler.Radius; - double left; - double right; + int left; + int right; float weight; int index; int sum; @@ -87,37 +88,37 @@ namespace ImageProcessorCore.Processors // When shrinking, broaden the effective kernel support so that we still // visit every source pixel. - if (scale < 1) + if (scale < 1F) { float width = radius / scale; - float filterScale = 1 / scale; + float filterScale = 1F / scale; // Make the weights slices, one source for each column or row. for (int i = 0; i < destinationSize; i++) { float centre = i / scale; - left = Math.Ceiling(centre - width); - right = Math.Floor(centre + width); + left = (int)Math.Ceiling(centre - width); + right = (int)Math.Floor(centre + width); result[i] = new Weights { - Values = new Weight[(int)(right - left + 1)] + Values = new Weight[(right - left + 1)] }; - for (double j = left; j <= right; j++) + for (int j = left; j <= right; j++) { - weight = sampler.GetValue((float)((centre - j) / filterScale)) / filterScale; + weight = sampler.GetValue((centre - j) / filterScale) / filterScale; if (j < 0) { - index = (int)-j; + index = -j; } else if (j >= sourceSize) { - index = (int)((sourceSize - j) + sourceSize - 1); + index = (int)((sourceSize - (float)j) + sourceSize - 1); } else { - index = (int)j; + index = j; } sum = (int)result[i].Sum++; @@ -131,27 +132,27 @@ namespace ImageProcessorCore.Processors for (int i = 0; i < destinationSize; i++) { float centre = i / scale; - left = Math.Ceiling(centre - radius); - right = Math.Floor(centre + radius); + left = (int)Math.Ceiling(centre - radius); + right = (int)Math.Floor(centre + radius); result[i] = new Weights { - Values = new Weight[(int)(right - left + 1)] + Values = new Weight[(right - left + 1)] }; - for (double j = left; j <= right; j++) + for (int j = left; j <= right; j++) { - weight = sampler.GetValue((float)(centre - j)); + weight = sampler.GetValue(centre - (float)j); if (j < 0) { - index = (int)-j; + index = -j; } else if (j >= sourceSize) { - index = (int)((sourceSize - j) + sourceSize - 1); + index = (sourceSize - j) + sourceSize - 1; } else { - index = (int)j; + index = j; } sum = (int)result[i].Sum++;