From 0c33d2866736162e8054ea8df53699f3fae5ced0 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Mon, 1 Apr 2019 09:52:33 -0700 Subject: [PATCH] Use MathF --- .../Formats/Jpeg/Components/Block8x8F.Generated.cs | 4 ++-- .../Formats/Jpeg/Components/Block8x8F.Generated.tt | 4 ++-- .../Decoder/ColorConverters/JpegColorConverter.cs | 4 ++-- .../Components/Decoder/JpegBlockPostProcessor.cs | 14 +++++++------- .../Decoder/JpegComponentPostProcessor.cs | 2 +- .../PixelImplementations/NormalizedByte4.cs | 8 ++++---- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs index 1f47de594c..a9e9903a9d 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.cs @@ -97,7 +97,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components { Vector4 CMin4 = new Vector4(0F); Vector4 CMax4 = new Vector4(maximum); - Vector4 COff4 = new Vector4((float)Math.Ceiling(maximum/2)); + Vector4 COff4 = new Vector4(MathF.Ceiling(maximum / 2)); this.V0L = Vector4.Clamp(this.V0L + COff4, CMin4, CMax4); this.V0R = Vector4.Clamp(this.V0R + COff4, CMin4, CMax4); @@ -123,7 +123,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components [MethodImpl(InliningOptions.ShortMethod)] public void NormalizeColorsAndRoundInplaceAvx2(float maximum) { - Vector off = new Vector((float)Math.Ceiling(maximum/2)); + Vector off = new Vector(MathF.Ceiling(maximum / 2)); Vector max = new Vector(maximum); ref Vector row0 = ref Unsafe.As>(ref this.V0L); diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt index ec4e06e429..d6c42a802a 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Generated.tt @@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components { Vector4 CMin4 = new Vector4(0F); Vector4 CMax4 = new Vector4(maximum); - Vector4 COff4 = new Vector4((float)Math.Ceiling(maximum/2)); + Vector4 COff4 = new Vector4(MathF.Ceiling(maximum / 2)); <# @@ -86,7 +86,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components [MethodImpl(InliningOptions.ShortMethod)] public void NormalizeColorsAndRoundInplaceAvx2(float maximum) { - Vector off = new Vector((float)Math.Ceiling(maximum/2)); + Vector off = new Vector(MathF.Ceiling(maximum / 2)); Vector max = new Vector(maximum); <# diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs index c2e390c590..61e3598696 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs @@ -42,8 +42,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters { this.ColorSpace = colorSpace; this.Precision = precision; - this.MaximumValue = (float)Math.Pow(2, precision) - 1; - this.HalfValue = (float)Math.Ceiling(this.MaximumValue / 2); + this.MaximumValue = MathF.Pow(2, precision) - 1; + this.HalfValue = MathF.Ceiling(this.MaximumValue / 2); } /// diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockPostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockPostProcessor.cs index fe39f41884..c5efb812e0 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockPostProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegBlockPostProcessor.cs @@ -20,17 +20,17 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder public Block8x8F SourceBlock; /// - /// Temporal block 1 to store intermediate and/or final computation results + /// Temporal block 1 to store intermediate and/or final computation results. /// public Block8x8F WorkspaceBlock1; /// - /// Temporal block 2 to store intermediate and/or final computation results + /// Temporal block 2 to store intermediate and/or final computation results. /// public Block8x8F WorkspaceBlock2; /// - /// The quantization table as + /// The quantization table as . /// public Block8x8F DequantiazationTable; @@ -40,9 +40,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder private Size subSamplingDivisors; /// - /// Defines the maximum value derived from the bitdepth + /// Defines the maximum value derived from the bitdepth. /// - private int maximumValue; + private readonly int maximumValue; /// /// Initializes a new instance of the struct. @@ -54,7 +54,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder int qtIndex = component.QuantizationTableIndex; this.DequantiazationTable = ZigZag.CreateDequantizationTable(ref decoder.QuantizationTables[qtIndex]); this.subSamplingDivisors = component.SubSamplingDivisors; - this.maximumValue = (int)Math.Pow(2, decoder.Precision) - 1; + this.maximumValue = (int)MathF.Pow(2, decoder.Precision) - 1; this.SourceBlock = default; this.WorkspaceBlock1 = default; @@ -66,7 +66,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder /// - Dequantize /// - Applying IDCT /// - Level shift by +maximumValue/2, clip to [0, maximumValue] - /// - Copy the resulting color values into 'destArea' scaling up the block by amount defined in + /// - Copy the resulting color values into 'destArea' scaling up the block by amount defined in . /// /// The source block. /// The destination buffer area. diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs index e7f3e4fda5..e1a9380a03 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs @@ -78,7 +78,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder public void CopyBlocksToColorBuffer() { var blockPp = new JpegBlockPostProcessor(this.ImagePostProcessor.RawJpeg, this.Component); - float maximumValue = (float)Math.Pow(2, this.ImagePostProcessor.RawJpeg.Precision) - 1; + float maximumValue = MathF.Pow(2, this.ImagePostProcessor.RawJpeg.Precision) - 1; for (int y = 0; y < this.BlockRowsPerStep; y++) { diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs index 82698d5085..8a9368463f 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs @@ -164,10 +164,10 @@ namespace SixLabors.ImageSharp.PixelFormats { vector = Vector4.Clamp(vector, MinusOne, Vector4.One) * Half; - uint byte4 = ((uint)Math.Round(vector.X) & 0xFF) << 0; - uint byte3 = ((uint)Math.Round(vector.Y) & 0xFF) << 8; - uint byte2 = ((uint)Math.Round(vector.Z) & 0xFF) << 16; - uint byte1 = ((uint)Math.Round(vector.W) & 0xFF) << 24; + uint byte4 = ((uint)MathF.Round(vector.X) & 0xFF) << 0; + uint byte3 = ((uint)MathF.Round(vector.Y) & 0xFF) << 8; + uint byte2 = ((uint)MathF.Round(vector.Z) & 0xFF) << 16; + uint byte1 = ((uint)MathF.Round(vector.W) & 0xFF) << 24; return byte4 | byte3 | byte2 | byte1; }