Browse Source

fix stylecop issues

pull/152/head
Scott Williams 9 years ago
parent
commit
1da6833a2a
  1. 2
      src/ImageSharp/Formats/Png/PngEncoderCore.cs
  2. 2
      tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs
  3. 41
      tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs
  4. 27
      tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs
  5. 2
      tests/ImageSharp.Tests/ImageComparer.cs
  6. 32
      tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs

2
src/ImageSharp/Formats/Png/PngEncoderCore.cs

@ -544,7 +544,7 @@ namespace ImageSharp.Formats
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="stream">The <see cref="Stream"/> containing image data.</param>
/// <param name="imageBase">The image base.</param>
/// <param name="image">The image.</param>
private void WritePhysicalChunk<TColor>(Stream stream, Image<TColor> image)
where TColor : struct, IPixel<TColor>
{

2
tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs

@ -27,7 +27,7 @@ namespace ImageSharp.Tests.Drawing
[InlineData(false, 16, 4)] // we always do 4 sub=pixels when antialising is off.
public void MinimumAntialiasSubpixelDepth(bool antialias, int antialiasSubpixelDepth, int expectedAntialiasSubpixelDepth)
{
var bounds = new ImageSharp.Rectangle(0, 0, 1, 1);
ImageSharp.Rectangle bounds = new ImageSharp.Rectangle(0, 0, 1, 1);
Mock<IBrush<Color>> brush = new Mock<IBrush<Color>>();
Mock<Region> region = new Mock<Region>();

41
tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs

@ -8,6 +8,7 @@ using ImageSharp.Formats;
namespace ImageSharp.Tests
{
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using ImageSharp.IO;
using Xunit;
@ -57,10 +58,11 @@ namespace ImageSharp.Tests
where TColor : struct, IPixel<TColor>
{
using (Image<TColor> image = provider.GetImage())
using (EndianBinaryReader reader = Encode(image, null))
using (MemoryStream ms = new MemoryStream())
{
byte[] data = reader.ReadBytes(8);
image.Save(ms, new PngEncoder());
byte[] data = ms.ToArray().Take(8).ToArray();
byte[] expected = {
0x89, // Set the high bit.
0x50, // P
@ -75,38 +77,5 @@ namespace ImageSharp.Tests
Assert.Equal(expected, data);
}
}
[Theory]
[WithBlankImages(1, 1, PixelTypes.All)]
[WithBlankImages(10, 10, PixelTypes.StandardImageClass)]
public void WritesFileHeaderHasHeightAndWidth<TColor>(TestImageProvider<TColor> provider)
where TColor : struct, IPixel<TColor>
{
using (Image<TColor> image = provider.GetImage())
using (EndianBinaryReader reader = Encode(image, null))
{
reader.ReadBytes(8); // throw away the file header
uint width = reader.ReadUInt32();
uint height = reader.ReadUInt32();
byte bitDepth = reader.ReadByte();
byte colorType = reader.ReadByte();
byte compressionMethod = reader.ReadByte();
byte filterMethod = reader.ReadByte();
byte interlaceMethod = reader.ReadByte();
Assert.Equal(image.Width, (int)width);
Assert.Equal(image.Height, (int)height);
}
}
private static EndianBinaryReader Encode<TColor>(Image<TColor> img, IEncoderOptions options)
where TColor : struct, IPixel<TColor>
{
MemoryStream stream = new MemoryStream();
new PngEncoder().Encode(img, stream, null);
stream.Position = 0;
return new EndianBinaryReader(Endianness.BigEndian, stream);
}
}
}

27
tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs

@ -18,20 +18,41 @@ namespace ImageSharp.Tests.Formats.Png
{
[Theory]
[WithTestPatternImages(300, 300, PixelTypes.All)]
public void WritesFileMarker<TColor>(TestImageProvider<TColor> provider)
public void GeneralTest<TColor>(TestImageProvider<TColor> provider)
where TColor : struct, IPixel<TColor>
{
// does saving a file then repoening mean both files are identical???
using (Image<TColor> image = provider.GetImage())
using (MemoryStream ms = new MemoryStream())
{
image.Save(provider.Utility.GetTestOutputFileName("bmp"));
// image.Save(provider.Utility.GetTestOutputFileName("bmp"));
image.Save(ms, new PngEncoder());
ms.Position = 0;
using (Image img2 = new Image(ms, new Configuration(new PngFormat())))
{
img2.Save(provider.Utility.GetTestOutputFileName("bmp", "_loaded"), new BmpEncoder());
// img2.Save(provider.Utility.GetTestOutputFileName("bmp", "_loaded"), new BmpEncoder());
ImageComparer.VisualComparer(image, img2);
}
}
}
[Theory]
[WithTestPatternImages(100, 100, PixelTypes.All)]
public void CanSaveIndexedPng<TColor>(TestImageProvider<TColor> provider)
where TColor : struct, IPixel<TColor>
{
// does saving a file then repoening mean both files are identical???
using (Image<TColor> image = provider.GetImage())
using (MemoryStream ms = new MemoryStream())
{
// image.Save(provider.Utility.GetTestOutputFileName("bmp"));
image.MetaData.Quality = 256;
image.Save(ms, new PngEncoder());
ms.Position = 0;
using (Image img2 = new Image(ms, new Configuration(new PngFormat())))
{
// img2.Save(provider.Utility.GetTestOutputFileName("bmp", "_loaded"), new BmpEncoder());
ImageComparer.VisualComparer(image, img2);
}
}

2
tests/ImageSharp.Tests/ImageComparer.cs

@ -17,7 +17,7 @@
where TColorA : struct, IPixel<TColorA>
where TColorB : struct, IPixel<TColorB>
{
var percentage = expected.PercentageDifference(actual, segmentThreshold, scalingFactor);
float percentage = expected.PercentageDifference(actual, segmentThreshold, scalingFactor);
Assert.InRange(percentage, 0, imageTheshold);
}

32
tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs

@ -34,7 +34,7 @@ namespace ImageSharp.Tests
{
if (!testImages.ContainsKey(this.SourceFileOrDescription))
{
var image = new Image<TColor>(this.Width, this.Height);
Image<TColor> image = new Image<TColor>(this.Width, this.Height);
DrawTestPattern(image);
testImages.Add(this.SourceFileOrDescription, image);
}
@ -46,7 +46,7 @@ namespace ImageSharp.Tests
private static void DrawTestPattern(Image<TColor> image)
{
// first lets split the image into 4 quadrants
using (var pixels = image.Lock())
using (PixelAccessor<TColor> pixels = image.Lock())
{
BlackWhiteChecker(pixels); // top left
HorizontalLines(pixels); // top right
@ -68,9 +68,9 @@ namespace ImageSharp.Tests
NamedColors<TColor>.Blue
};
int p = 0;
for (var y = top; y < bottom; y++)
for (int y = top; y < bottom; y++)
{
for (var x = left; x < right; x++)
for (int x = left; x < right; x++)
{
if (x % stride == 0)
{
@ -96,15 +96,15 @@ namespace ImageSharp.Tests
};
int p = 0;
for (var y = top; y < bottom; y++)
for (int y = top; y < bottom; y++)
{
if (y % stride == 0)
{
p++;
p = p % c.Length;
}
var pstart = p;
for (var x = left; x < right; x++)
int pstart = p;
for (int x = left; x < right; x++)
{
if (x % stride == 0)
{
@ -132,25 +132,25 @@ namespace ImageSharp.Tests
TColor c = default(TColor);
for (var x = left; x < right; x++)
for (int x = left; x < right; x++)
{
blue.W = red.W = green.W = (float)x / (float)right;
c.PackFromVector4(red);
var topBand = top;
for (var y = topBand; y < top + height; y++)
int topBand = top;
for (int y = topBand; y < top + height; y++)
{
pixels[x, y] = c;
}
topBand = topBand + height;
c.PackFromVector4(green);
for (var y = topBand; y < topBand + height; y++)
for (int y = topBand; y < topBand + height; y++)
{
pixels[x, y] = c;
}
topBand = topBand + height;
c.PackFromVector4(blue);
for (var y = topBand; y < bottom; y++)
for (int y = topBand; y < bottom; y++)
{
pixels[x, y] = c;
}
@ -168,12 +168,12 @@ namespace ImageSharp.Tests
uint stepsPerPixel = (uint)(uint.MaxValue / pixelCount);
TColor c = default(TColor);
Color t = new Color(0);
uint inital = 0;
for (var x = left; x < right; x++)
for (var y = top; y < bottom; y++)
for (int x = left; x < right; x++)
for (int y = top; y < bottom; y++)
{
t.PackedValue += stepsPerPixel;
var v = t.ToVector4();
Vector4 v = t.ToVector4();
//v.W = (x - left) / (float)left;
c.PackFromVector4(v);
pixels[x, y] = c;

Loading…
Cancel
Save