Browse Source

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 21de86c82f.
af/merge-core
Simon Cropp 7 years ago
committed by James Jackson-South
parent
commit
e23d8df485
  1. 2
      src/ImageSharp/Advanced/AotCompilerTools.cs
  2. 10
      src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs
  3. 15
      src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationProcessor{TPixel}.cs
  4. 2
      tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs
  5. 10
      tests/ImageSharp.Tests/Image/ImageSaveTests.cs

2
src/ImageSharp/Advanced/AotCompilerTools.cs

@ -133,7 +133,7 @@ namespace SixLabors.ImageSharp.Advanced
{
var test = new FloydSteinbergDiffuser();
TPixel pixel = default;
test.Dither<TPixel>(new ImageFrame<TPixel>(Configuration.Default, 1, 1), pixel, pixel, 0, 0, 0, 0, 0, 0);
test.Dither(new ImageFrame<TPixel>(Configuration.Default, 1, 1), pixel, pixel, 0, 0, 0, 0, 0, 0);
}
/// <summary>

10
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<Block8x8> 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<Block8x8> 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<Block8x8> 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();
}
}

15
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++;

2
tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs

@ -150,7 +150,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif
outStream.Position = 0;
var clone = Image.Load<Rgba32>(outStream);
GifMetadata cloneMetaData = clone.Metadata.GetFormatMetadata<GifMetadata>(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.

10
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<Rgba32>(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<Rgba32>(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<Rgba32>(this.Image, It.IsAny<Stream>()));
this.encoder.Verify(x => x.Encode(this.Image, It.IsAny<Stream>()));
}
[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<Rgba32>(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<Rgba32>(this.Image, stream));
this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream));
}
public void Dispose()

Loading…
Cancel
Save