From e23d8df4854abd731b2ad3835f88a980645df539 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Tue, 13 Aug 2019 09:33:39 +1000 Subject: [PATCH] remove some redundant variables and type params (#971) * remove redundant variable init * redundant variables * remove redundant tileY variable * remove redundant sum variable * redundant mcu variable * redundant type params * Revert "remove redundant sum variable" This reverts commit 21de86c82fb03d5ffd13928bbd82aaf5abf77d7f. --- src/ImageSharp/Advanced/AotCompilerTools.cs | 2 +- .../Jpeg/Components/Decoder/HuffmanScanDecoder.cs | 10 ---------- ...ptiveHistogramEqualizationProcessor{TPixel}.cs | 15 +++------------ .../Formats/Gif/GifEncoderTests.cs | 2 +- tests/ImageSharp.Tests/Image/ImageSaveTests.cs | 10 +++++----- 5 files changed, 10 insertions(+), 29 deletions(-) diff --git a/src/ImageSharp/Advanced/AotCompilerTools.cs b/src/ImageSharp/Advanced/AotCompilerTools.cs index c263aaa13f..084f2403e5 100644 --- a/src/ImageSharp/Advanced/AotCompilerTools.cs +++ b/src/ImageSharp/Advanced/AotCompilerTools.cs @@ -133,7 +133,7 @@ namespace SixLabors.ImageSharp.Advanced { var test = new FloydSteinbergDiffuser(); TPixel pixel = default; - test.Dither(new ImageFrame(Configuration.Default, 1, 1), pixel, pixel, 0, 0, 0, 0, 0, 0); + test.Dither(new ImageFrame(Configuration.Default, 1, 1), pixel, pixel, 0, 0, 0, 0, 0, 0); } /// diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs index e8a298c5ab..fbb2b52727 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs @@ -209,7 +209,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder dcHuffmanTable.Configure(); acHuffmanTable.Configure(); - int mcu = 0; for (int j = 0; j < h; j++) { Span blockSpan = component.SpectralBlocks.GetRowSpan(j); @@ -228,9 +227,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder ref dcHuffmanTable, ref acHuffmanTable); - // Every data block is an MCU, so countdown the restart interval - mcu++; - this.HandleRestart(); } } @@ -379,7 +375,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder ref HuffmanTable dcHuffmanTable = ref this.dcHuffmanTables[component.DCHuffmanTableId]; dcHuffmanTable.Configure(); - int mcu = 0; for (int j = 0; j < h; j++) { Span blockSpan = component.SpectralBlocks.GetRowSpan(j); @@ -397,8 +392,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder ref Unsafe.Add(ref blockRef, i), ref dcHuffmanTable); - // Every data block is an MCU, so countdown the restart interval - mcu++; this.HandleRestart(); } } @@ -408,7 +401,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder ref HuffmanTable acHuffmanTable = ref this.acHuffmanTables[component.ACHuffmanTableId]; acHuffmanTable.Configure(); - int mcu = 0; for (int j = 0; j < h; j++) { Span blockSpan = component.SpectralBlocks.GetRowSpan(j); @@ -425,8 +417,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder ref Unsafe.Add(ref blockRef, i), ref acHuffmanTable); - // Every data block is an MCU, so countdown the restart interval - mcu++; this.HandleRestart(); } } diff --git a/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationProcessor{TPixel}.cs index dd2f09bcd9..537a3089ec 100644 --- a/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationProcessor{TPixel}.cs @@ -77,25 +77,22 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization new ParallelOptions { MaxDegreeOfParallelism = configuration.MaxDegreeOfParallelism }, index => { - int cdfX = 0; - int tileX = 0; - int tileY = 0; int y = tileYStartPositions[index].y; int cdfYY = tileYStartPositions[index].cdfY; // It's unfortunate that we have to do this per iteration. ref TPixel sourceBase = ref source.GetPixelReference(0, 0); - cdfX = 0; + int cdfX = 0; for (int x = halfTileWidth; x < sourceWidth - halfTileWidth; x += tileWidth) { - tileY = 0; + int tileY = 0; int yEnd = Math.Min(y + tileHeight, sourceHeight); int xEnd = Math.Min(x + tileWidth, sourceWidth); for (int dy = y; dy < yEnd; dy++) { int dyOffSet = dy * sourceWidth; - tileX = 0; + int tileX = 0; for (int dx = x; dx < xEnd; dx++) { ref TPixel pixel = ref Unsafe.Add(ref sourceBase, dyOffSet + dx); @@ -221,7 +218,6 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization int xEnd, int luminanceLevels) { - int halfTileWidth = tileWidth / 2; int halfTileHeight = tileHeight / 2; int cdfY = 0; @@ -232,13 +228,11 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization for (int dy = y; dy < yLimit; dy++) { int dyOffSet = dy * sourceWidth; - int tileX = halfTileWidth; for (int dx = xStart; dx < xEnd; dx++) { ref TPixel pixel = ref Unsafe.Add(ref pixelBase, dyOffSet + dx); float luminanceEqualized = InterpolateBetweenTwoTiles(pixel, cdfData, cdfX, cdfY, cdfX, cdfY + 1, tileY, tileHeight, luminanceLevels); pixel.FromVector4(new Vector4(luminanceEqualized, luminanceEqualized, luminanceEqualized, pixel.ToVector4().W)); - tileX++; } tileY++; @@ -277,7 +271,6 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization int cdfX = 0; for (int x = halfTileWidth; x < sourceWidth - halfTileWidth; x += tileWidth) { - int tileY = 0; for (int dy = yStart; dy < yEnd; dy++) { int dyOffSet = dy * sourceWidth; @@ -290,8 +283,6 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization pixel.FromVector4(new Vector4(luminanceEqualized, luminanceEqualized, luminanceEqualized, pixel.ToVector4().W)); tileX++; } - - tileY++; } cdfX++; diff --git a/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs index 38cd5bc95e..d6d58eae7a 100644 --- a/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs @@ -150,7 +150,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif outStream.Position = 0; var clone = Image.Load(outStream); - GifMetadata cloneMetaData = clone.Metadata.GetFormatMetadata(GifFormat.Instance); + GifMetadata cloneMetaData = clone.Metadata.GetFormatMetadata(GifFormat.Instance); Assert.Equal(metaData.ColorTableMode, cloneMetaData.ColorTableMode); // Gifiddle and Cyotek GifInfo say this image has 64 colors. diff --git a/tests/ImageSharp.Tests/Image/ImageSaveTests.cs b/tests/ImageSharp.Tests/Image/ImageSaveTests.cs index 6236d296e3..f5504fac26 100644 --- a/tests/ImageSharp.Tests/Image/ImageSaveTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageSaveTests.cs @@ -52,7 +52,7 @@ namespace SixLabors.ImageSharp.Tests this.fileSystem.Setup(x => x.Create("path.png")).Returns(stream); this.Image.Save("path.png"); - this.encoder.Verify(x => x.Encode(this.Image, stream)); + this.encoder.Verify(x => x.Encode(this.Image, stream)); } @@ -64,7 +64,7 @@ namespace SixLabors.ImageSharp.Tests this.Image.Save("path.jpg", this.encoderNotInFormat.Object); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream)); } [Fact] @@ -72,7 +72,7 @@ namespace SixLabors.ImageSharp.Tests { string str = this.Image.ToBase64String(this.localImageFormat.Object); - this.encoder.Verify(x => x.Encode(this.Image, It.IsAny())); + this.encoder.Verify(x => x.Encode(this.Image, It.IsAny())); } [Fact] @@ -81,7 +81,7 @@ namespace SixLabors.ImageSharp.Tests Stream stream = new MemoryStream(); this.Image.Save(stream, this.localImageFormat.Object); - this.encoder.Verify(x => x.Encode(this.Image, stream)); + this.encoder.Verify(x => x.Encode(this.Image, stream)); } [Fact] @@ -91,7 +91,7 @@ namespace SixLabors.ImageSharp.Tests this.Image.Save(stream, this.encoderNotInFormat.Object); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream)); } public void Dispose()