diff --git a/src/ImageProcessorCore/Common/Helpers/ImageMaths.cs b/src/ImageProcessorCore/Common/Helpers/ImageMaths.cs index 2a55286a3..384d3973a 100644 --- a/src/ImageProcessorCore/Common/Helpers/ImageMaths.cs +++ b/src/ImageProcessorCore/Common/Helpers/ImageMaths.cs @@ -55,11 +55,11 @@ namespace ImageProcessorCore /// The B-Spline curve variable. /// The Cardinal curve variable. /// - /// The . + /// The . /// - public static float GetBcValue(float x, float b, float c) + public static double GetBcValue(double x, double b, double c) { - float temp; + double temp; if (x < 0) { @@ -87,16 +87,16 @@ namespace ImageProcessorCore /// /// The value to calculate the result for. /// - /// The . + /// The . /// - public static float SinC(float x) + public static double SinC(double x) { - const float Epsilon = .00001f; + const double Epsilon = .00001d; if (Math.Abs(x) > Epsilon) { - x *= (float)Math.PI; - return Clean((float)Math.Sin(x) / x); + x *= (double)Math.PI; + return Clean((double)Math.Sin(x) / x); } return 1.0f; @@ -272,11 +272,11 @@ namespace ImageProcessorCore /// /// The value to clean. /// - /// The + /// The /// . - private static float Clean(float x) + private static double Clean(double x) { - const float Epsilon = .00001f; + const double Epsilon = .00001d; if (Math.Abs(x) < Epsilon) { diff --git a/src/ImageProcessorCore/PackedVector/Bgra32.cs b/src/ImageProcessorCore/PackedVector/Bgra32.cs index 7c0f24142..46c96bf2f 100644 --- a/src/ImageProcessorCore/PackedVector/Bgra32.cs +++ b/src/ImageProcessorCore/PackedVector/Bgra32.cs @@ -160,6 +160,15 @@ namespace ImageProcessorCore this.A = (byte)(this.A * value); } + /// + public void Multiply(double value) + { + this.B = (byte)(this.B * value); + this.G = (byte)(this.G * value); + this.R = (byte)(this.R * value); + this.A = (byte)(this.A * value); + } + /// public void Divide(Bgra32 value) { @@ -178,6 +187,15 @@ namespace ImageProcessorCore this.A = (byte)(this.A / value); } + /// + public void Divide(double value) + { + this.B = (byte)(this.B / value); + this.G = (byte)(this.G / value); + this.R = (byte)(this.R / value); + this.A = (byte)(this.A / value); + } + /// public uint PackedValue() { diff --git a/src/ImageProcessorCore/PackedVector/IPackedVector.cs b/src/ImageProcessorCore/PackedVector/IPackedVector.cs index 329cc1703..f130bd515 100644 --- a/src/ImageProcessorCore/PackedVector/IPackedVector.cs +++ b/src/ImageProcessorCore/PackedVector/IPackedVector.cs @@ -49,6 +49,12 @@ namespace ImageProcessorCore /// The value to multiply by. void Multiply(float value); + /// + /// Multiplies the given current instance by given the value. + /// + /// The value to multiply by. + void Multiply(double value); + /// /// Divides the given current instance by given the . /// @@ -60,6 +66,12 @@ namespace ImageProcessorCore /// /// The value to divide by. void Divide(float value); + + /// + /// Divides the given current instance by given the value. + /// + /// The value to divide by. + void Divide(double value); } /// diff --git a/src/ImageProcessorCore/Samplers/Processors/ResizeProcessor.cs b/src/ImageProcessorCore/Samplers/Processors/ResizeProcessor.cs index 6dcec5c57..0fd63e4b3 100644 --- a/src/ImageProcessorCore/Samplers/Processors/ResizeProcessor.cs +++ b/src/ImageProcessorCore/Samplers/Processors/ResizeProcessor.cs @@ -130,7 +130,7 @@ namespace ImageProcessorCore.Processors { // Ensure offsets are normalised for cropping and padding. int offsetX = x - startX; - float sum = this.HorizontalWeights[offsetX].Sum; + double sum = this.HorizontalWeights[offsetX].Sum; Weight[] horizontalValues = this.HorizontalWeights[offsetX].Values; // Destination color components @@ -171,7 +171,7 @@ namespace ImageProcessorCore.Processors { // Ensure offsets are normalised for cropping and padding. int offsetY = y - startY; - float sum = this.VerticalWeights[offsetY].Sum; + double sum = this.VerticalWeights[offsetY].Sum; Weight[] verticalValues = this.VerticalWeights[offsetY].Values; for (int x = 0; x < width; x++) @@ -229,12 +229,12 @@ namespace ImageProcessorCore.Processors /// protected Weights[] PrecomputeWeights(int destinationSize, int sourceSize) { - float scale = (float)destinationSize / sourceSize; + double scale = (double)destinationSize / sourceSize; IResampler sampler = this.Sampler; - float radius = sampler.Radius; + double radius = sampler.Radius; double left; double right; - float weight; + double weight; int index; int sum; @@ -244,13 +244,13 @@ namespace ImageProcessorCore.Processors // visit every source pixel. if (scale < 1) { - float width = radius / scale; - float filterScale = 1 / scale; + double width = radius / scale; + double filterScale = 1 / scale; // Make the weights slices, one source for each column or row. for (int i = 0; i < destinationSize; i++) { - float centre = i / scale; + double centre = i / scale; left = Math.Ceiling(centre - width); right = Math.Floor(centre + width); @@ -261,7 +261,7 @@ namespace ImageProcessorCore.Processors for (double 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; @@ -285,7 +285,7 @@ namespace ImageProcessorCore.Processors // Make the weights slices, one source for each column or row. for (int i = 0; i < destinationSize; i++) { - float centre = i / scale; + double centre = i / scale; left = Math.Ceiling(centre - radius); right = Math.Floor(centre + radius); result[i] = new Weights @@ -295,7 +295,7 @@ namespace ImageProcessorCore.Processors for (double j = left; j <= right; j++) { - weight = sampler.GetValue((float)(centre - j)); + weight = sampler.GetValue(centre - j); if (j < 0) { index = (int)-j; @@ -328,7 +328,7 @@ namespace ImageProcessorCore.Processors /// /// The index. /// The value. - public Weight(int index, float value) + public Weight(int index, double value) { this.Index = index; this.Value = value; @@ -342,7 +342,7 @@ namespace ImageProcessorCore.Processors /// /// Gets the result of the interpolation algorithm. /// - public float Value { get; } + public double Value { get; } } /// @@ -358,7 +358,7 @@ namespace ImageProcessorCore.Processors /// /// Gets or sets the sum. /// - public float Sum { get; set; } + public double Sum { get; set; } } } } \ No newline at end of file diff --git a/src/ImageProcessorCore/Samplers/Resamplers/BicubicResampler.cs b/src/ImageProcessorCore/Samplers/Resamplers/BicubicResampler.cs index 8aecac7a6..041434cdc 100644 --- a/src/ImageProcessorCore/Samplers/Resamplers/BicubicResampler.cs +++ b/src/ImageProcessorCore/Samplers/Resamplers/BicubicResampler.cs @@ -13,28 +13,28 @@ namespace ImageProcessorCore public class BicubicResampler : IResampler { /// - public float Radius => 2; + public double Radius => 2; /// - public float GetValue(float x) + public double GetValue(double x) { // The coefficient. - float a = -0.5f; + double a = -0.5d; if (x < 0) { x = -x; } - float result = 0; + double result = 0; if (x <= 1) { - result = (((1.5f * x) - 2.5f) * x * x) + 1; + result = (((1.5d * x) - 2.5d) * x * x) + 1; } else if (x < 2) { - result = (((((a * x) + 2.5f) * x) - 4) * x) + 2; + result = (((((a * x) + 2.5d) * x) - 4) * x) + 2; } return result; diff --git a/src/ImageProcessorCore/Samplers/Resamplers/BoxResampler.cs b/src/ImageProcessorCore/Samplers/Resamplers/BoxResampler.cs index b1234e415..89a6d8acd 100644 --- a/src/ImageProcessorCore/Samplers/Resamplers/BoxResampler.cs +++ b/src/ImageProcessorCore/Samplers/Resamplers/BoxResampler.cs @@ -12,10 +12,10 @@ namespace ImageProcessorCore public class BoxResampler : IResampler { /// - public float Radius => 0.5F; + public double Radius => 0.5d; /// - public float GetValue(float x) + public double GetValue(double x) { if (x > -0.5 && x <= 0.5) { diff --git a/src/ImageProcessorCore/Samplers/Resamplers/CatmullRomResampler.cs b/src/ImageProcessorCore/Samplers/Resamplers/CatmullRomResampler.cs index 0b5031df8..39dd56129 100644 --- a/src/ImageProcessorCore/Samplers/Resamplers/CatmullRomResampler.cs +++ b/src/ImageProcessorCore/Samplers/Resamplers/CatmullRomResampler.cs @@ -14,13 +14,13 @@ namespace ImageProcessorCore public class CatmullRomResampler : IResampler { /// - public float Radius => 2; + public double Radius => 2; /// - public float GetValue(float x) + public double GetValue(double x) { - const float B = 0; - const float C = 1 / 2f; + const double B = 0; + const double C = 0.5d; return ImageMaths.GetBcValue(x, B, C); } diff --git a/src/ImageProcessorCore/Samplers/Resamplers/HermiteResampler.cs b/src/ImageProcessorCore/Samplers/Resamplers/HermiteResampler.cs index 49193a3de..371447117 100644 --- a/src/ImageProcessorCore/Samplers/Resamplers/HermiteResampler.cs +++ b/src/ImageProcessorCore/Samplers/Resamplers/HermiteResampler.cs @@ -13,13 +13,13 @@ namespace ImageProcessorCore.Processors public class HermiteResampler : IResampler { /// - public float Radius => 2; + public double Radius => 2; /// - public float GetValue(float x) + public double GetValue(double x) { - const float B = 0; - const float C = 0; + const double B = 0; + const double C = 0; return ImageMaths.GetBcValue(x, B, C); } diff --git a/src/ImageProcessorCore/Samplers/Resamplers/IResampler.cs b/src/ImageProcessorCore/Samplers/Resamplers/IResampler.cs index 0dea58440..d72e44839 100644 --- a/src/ImageProcessorCore/Samplers/Resamplers/IResampler.cs +++ b/src/ImageProcessorCore/Samplers/Resamplers/IResampler.cs @@ -13,15 +13,15 @@ namespace ImageProcessorCore /// /// Gets the radius in which to sample pixels. /// - float Radius { get; } + double Radius { get; } /// /// Gets the result of the interpolation algorithm. /// /// The value to process. /// - /// The + /// The /// - float GetValue(float x); + double GetValue(double x); } } diff --git a/src/ImageProcessorCore/Samplers/Resamplers/Lanczos3Resampler.cs b/src/ImageProcessorCore/Samplers/Resamplers/Lanczos3Resampler.cs index a78b6c066..6240226f6 100644 --- a/src/ImageProcessorCore/Samplers/Resamplers/Lanczos3Resampler.cs +++ b/src/ImageProcessorCore/Samplers/Resamplers/Lanczos3Resampler.cs @@ -13,10 +13,10 @@ namespace ImageProcessorCore public class Lanczos3Resampler : IResampler { /// - public float Radius => 3; + public double Radius => 3; /// - public float GetValue(float x) + public double GetValue(double x) { if (x < 0) { @@ -25,7 +25,7 @@ namespace ImageProcessorCore if (x < 3) { - return ImageMaths.SinC(x) * ImageMaths.SinC(x / 3f); + return ImageMaths.SinC(x) * ImageMaths.SinC(x / 3d); } return 0; diff --git a/src/ImageProcessorCore/Samplers/Resamplers/Lanczos5Resampler.cs b/src/ImageProcessorCore/Samplers/Resamplers/Lanczos5Resampler.cs index 05af2dd7f..4cd75066e 100644 --- a/src/ImageProcessorCore/Samplers/Resamplers/Lanczos5Resampler.cs +++ b/src/ImageProcessorCore/Samplers/Resamplers/Lanczos5Resampler.cs @@ -13,10 +13,10 @@ namespace ImageProcessorCore public class Lanczos5Resampler : IResampler { /// - public float Radius => 5; + public double Radius => 5; /// - public float GetValue(float x) + public double GetValue(double x) { if (x < 0) { @@ -25,7 +25,7 @@ namespace ImageProcessorCore if (x < 5) { - return ImageMaths.SinC(x) * ImageMaths.SinC(x / 5f); + return ImageMaths.SinC(x) * ImageMaths.SinC(x / 5d); } return 0; diff --git a/src/ImageProcessorCore/Samplers/Resamplers/Lanczos8Resampler.cs b/src/ImageProcessorCore/Samplers/Resamplers/Lanczos8Resampler.cs index 8c9a9237d..3db31b1fe 100644 --- a/src/ImageProcessorCore/Samplers/Resamplers/Lanczos8Resampler.cs +++ b/src/ImageProcessorCore/Samplers/Resamplers/Lanczos8Resampler.cs @@ -13,10 +13,10 @@ namespace ImageProcessorCore public class Lanczos8Resampler : IResampler { /// - public float Radius => 8; + public double Radius => 8; /// - public float GetValue(float x) + public double GetValue(double x) { if (x < 0) { @@ -25,7 +25,7 @@ namespace ImageProcessorCore if (x < 8) { - return ImageMaths.SinC(x) * ImageMaths.SinC(x / 8f); + return ImageMaths.SinC(x) * ImageMaths.SinC(x / 8d); } return 0; diff --git a/src/ImageProcessorCore/Samplers/Resamplers/MitchellNetravaliResampler.cs b/src/ImageProcessorCore/Samplers/Resamplers/MitchellNetravaliResampler.cs index f609f2645..c3f98a9ff 100644 --- a/src/ImageProcessorCore/Samplers/Resamplers/MitchellNetravaliResampler.cs +++ b/src/ImageProcessorCore/Samplers/Resamplers/MitchellNetravaliResampler.cs @@ -12,13 +12,13 @@ namespace ImageProcessorCore public class MitchellNetravaliResampler : IResampler { /// - public float Radius => 2; + public double Radius => 2; /// - public float GetValue(float x) + public double GetValue(double x) { - const float B = 1 / 3f; - const float C = 1 / 3f; + const double B = 0.333333333333333D; + const double C = 0.333333333333333D; return ImageMaths.GetBcValue(x, B, C); } diff --git a/src/ImageProcessorCore/Samplers/Resamplers/NearestNeighborResampler.cs b/src/ImageProcessorCore/Samplers/Resamplers/NearestNeighborResampler.cs index 58b6a9d58..6cd5c53cf 100644 --- a/src/ImageProcessorCore/Samplers/Resamplers/NearestNeighborResampler.cs +++ b/src/ImageProcessorCore/Samplers/Resamplers/NearestNeighborResampler.cs @@ -12,10 +12,10 @@ namespace ImageProcessorCore public class NearestNeighborResampler : IResampler { /// - public float Radius => 1; + public double Radius => 1; /// - public float GetValue(float x) + public double GetValue(double x) { return x; } diff --git a/src/ImageProcessorCore/Samplers/Resamplers/RobidouxResampler.cs b/src/ImageProcessorCore/Samplers/Resamplers/RobidouxResampler.cs index caead12d5..200c72734 100644 --- a/src/ImageProcessorCore/Samplers/Resamplers/RobidouxResampler.cs +++ b/src/ImageProcessorCore/Samplers/Resamplers/RobidouxResampler.cs @@ -12,13 +12,13 @@ namespace ImageProcessorCore public class RobidouxResampler : IResampler { /// - public float Radius => 2; + public double Radius => 2; /// - public float GetValue(float x) + public double GetValue(double x) { - const float B = 0.3782158F; - const float C = 0.3108921F; + const double B = 0.37821575509399867D; + const double C = 0.31089212245300067D; return ImageMaths.GetBcValue(x, B, C); } diff --git a/src/ImageProcessorCore/Samplers/Resamplers/RobidouxSharpResampler.cs b/src/ImageProcessorCore/Samplers/Resamplers/RobidouxSharpResampler.cs index 633503cd1..3612d5b1d 100644 --- a/src/ImageProcessorCore/Samplers/Resamplers/RobidouxSharpResampler.cs +++ b/src/ImageProcessorCore/Samplers/Resamplers/RobidouxSharpResampler.cs @@ -12,13 +12,13 @@ namespace ImageProcessorCore public class RobidouxSharpResampler : IResampler { /// - public float Radius => 2; + public double Radius => 2; /// - public float GetValue(float x) + public double GetValue(double x) { - const float B = 0.26201451F; - const float C = 0.36899274F; + const double B = 0.2620145123990142D; + const double C = 0.3689927438004929D; return ImageMaths.GetBcValue(x, B, C); } diff --git a/src/ImageProcessorCore/Samplers/Resamplers/RobidouxSoftResampler.cs b/src/ImageProcessorCore/Samplers/Resamplers/RobidouxSoftResampler.cs deleted file mode 100644 index 8706f492b..000000000 --- a/src/ImageProcessorCore/Samplers/Resamplers/RobidouxSoftResampler.cs +++ /dev/null @@ -1,26 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageProcessorCore -{ - /// - /// The function implements the Robidoux Soft algorithm. - /// - /// - public class RobidouxSoftResampler : IResampler - { - /// - public float Radius => 2; - - /// - public float GetValue(float x) - { - const float B = 0.6796f; - const float C = 0.1602f; - - return ImageMaths.GetBcValue(x, B, C); - } - } -} diff --git a/src/ImageProcessorCore/Samplers/Resamplers/SplineResampler.cs b/src/ImageProcessorCore/Samplers/Resamplers/SplineResampler.cs index 55ef5656a..d4b498294 100644 --- a/src/ImageProcessorCore/Samplers/Resamplers/SplineResampler.cs +++ b/src/ImageProcessorCore/Samplers/Resamplers/SplineResampler.cs @@ -12,13 +12,13 @@ namespace ImageProcessorCore public class SplineResampler : IResampler { /// - public float Radius => 2; + public double Radius => 2; /// - public float GetValue(float x) + public double GetValue(double x) { - const float B = 1; - const float C = 0; + const double B = 1; + const double C = 0; return ImageMaths.GetBcValue(x, B, C); } diff --git a/src/ImageProcessorCore/Samplers/Resamplers/TriangleResampler.cs b/src/ImageProcessorCore/Samplers/Resamplers/TriangleResampler.cs index cb404b736..9a7bb1bff 100644 --- a/src/ImageProcessorCore/Samplers/Resamplers/TriangleResampler.cs +++ b/src/ImageProcessorCore/Samplers/Resamplers/TriangleResampler.cs @@ -13,10 +13,10 @@ namespace ImageProcessorCore public class TriangleResampler : IResampler { /// - public float Radius => 1; + public double Radius => 1; /// - public float GetValue(float x) + public double GetValue(double x) { if (x < 0) { diff --git a/src/ImageProcessorCore/Samplers/Resamplers/WelchResampler.cs b/src/ImageProcessorCore/Samplers/Resamplers/WelchResampler.cs index 3ecaa6a74..3bd0d36cf 100644 --- a/src/ImageProcessorCore/Samplers/Resamplers/WelchResampler.cs +++ b/src/ImageProcessorCore/Samplers/Resamplers/WelchResampler.cs @@ -12,10 +12,10 @@ namespace ImageProcessorCore public class WelchResampler : IResampler { /// - public float Radius => 3; + public double Radius => 3; /// - public float GetValue(float x) + public double GetValue(double x) { if (x < 0) { @@ -24,7 +24,7 @@ namespace ImageProcessorCore if (x < 3) { - return ImageMaths.SinC(x) * (1.0f - (x * x / 9.0f)); + return ImageMaths.SinC(x) * (1.0d - (x * x / 9.0d)); } return 0;