diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs
index e97eaed58..498ae578c 100644
--- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs
+++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs
@@ -544,7 +544,7 @@ namespace ImageSharp.Formats
///
/// The pixel format.
/// The containing image data.
- /// The image base.
+ /// The image.
private void WritePhysicalChunk(Stream stream, Image image)
where TColor : struct, IPixel
{
diff --git a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs
index db9686f3d..03994bc94 100644
--- a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs
+++ b/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> brush = new Mock>();
Mock region = new Mock();
diff --git a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs
index 16906c1fa..31b14601a 100644
--- a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs
+++ b/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
{
using (Image 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(TestImageProvider provider)
- where TColor : struct, IPixel
- {
- using (Image 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(Image img, IEncoderOptions options)
- where TColor : struct, IPixel
- {
- MemoryStream stream = new MemoryStream();
- new PngEncoder().Encode(img, stream, null);
- stream.Position = 0;
- return new EndianBinaryReader(Endianness.BigEndian, stream);
- }
}
}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs
index 7a15e30e9..d4e8534a7 100644
--- a/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs
+++ b/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(TestImageProvider provider)
+ public void GeneralTest(TestImageProvider provider)
where TColor : struct, IPixel
{
// does saving a file then repoening mean both files are identical???
using (Image 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(TestImageProvider provider)
+ where TColor : struct, IPixel
+ {
+ // does saving a file then repoening mean both files are identical???
+ using (Image 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);
}
}
diff --git a/tests/ImageSharp.Tests/ImageComparer.cs b/tests/ImageSharp.Tests/ImageComparer.cs
index 091edd343..ee9359c2a 100644
--- a/tests/ImageSharp.Tests/ImageComparer.cs
+++ b/tests/ImageSharp.Tests/ImageComparer.cs
@@ -17,7 +17,7 @@
where TColorA : struct, IPixel
where TColorB : struct, IPixel
{
- var percentage = expected.PercentageDifference(actual, segmentThreshold, scalingFactor);
+ float percentage = expected.PercentageDifference(actual, segmentThreshold, scalingFactor);
Assert.InRange(percentage, 0, imageTheshold);
}
diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs
index 8d5e77554..7e4401635 100644
--- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs
+++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs
@@ -34,7 +34,7 @@ namespace ImageSharp.Tests
{
if (!testImages.ContainsKey(this.SourceFileOrDescription))
{
- var image = new Image(this.Width, this.Height);
+ Image image = new Image(this.Width, this.Height);
DrawTestPattern(image);
testImages.Add(this.SourceFileOrDescription, image);
}
@@ -46,7 +46,7 @@ namespace ImageSharp.Tests
private static void DrawTestPattern(Image image)
{
// first lets split the image into 4 quadrants
- using (var pixels = image.Lock())
+ using (PixelAccessor pixels = image.Lock())
{
BlackWhiteChecker(pixels); // top left
HorizontalLines(pixels); // top right
@@ -68,9 +68,9 @@ namespace ImageSharp.Tests
NamedColors.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;