mirror of
https://github.com/cyanfish/naps2.git
synced 2024-09-21 04:37:47 +03:00
Add PixelColors image assert
This commit is contained in:
parent
f66ea1cb05
commit
f69ca91d1f
@ -1,4 +1,8 @@
|
||||
using Xunit;
|
||||
using System.Collections;
|
||||
using System.Drawing;
|
||||
using NAPS2.Images.Gdi;
|
||||
using Xunit;
|
||||
using Xunit.Sdk;
|
||||
|
||||
namespace NAPS2.Sdk.Tests.Asserts;
|
||||
|
||||
@ -77,4 +81,45 @@ public static class ImageAsserts
|
||||
second.Unlock(lock2);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PixelColors(IMemoryImage image, PixelColorData colorData)
|
||||
{
|
||||
var bitmap = ((GdiImage) image).Bitmap;
|
||||
foreach (var data in colorData)
|
||||
{
|
||||
var (x, y) = data.Item1;
|
||||
var (r, g, b) = data.Item2;
|
||||
var color = bitmap.GetPixel(x, y);
|
||||
var expected = Color.FromArgb(r, g, b);
|
||||
if (color != expected)
|
||||
{
|
||||
throw new AssertActualExpectedException(expected, color, $"Mismatched color at ({x}, {y})");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class PixelColorData : IEnumerable<((int x, int y), (int r, int g, int b))>
|
||||
{
|
||||
private readonly List<((int x, int y), (int r, int g, int b))> _colors = new();
|
||||
|
||||
public void Add((int x, int y) pos, (int r, int g, int b) color)
|
||||
{
|
||||
_colors.Add((pos, color));
|
||||
}
|
||||
|
||||
public void Add((int x, int y) pos, Color color)
|
||||
{
|
||||
_colors.Add((pos, (color.R, color.G, color.B)));
|
||||
}
|
||||
|
||||
public IEnumerator<((int x, int y), (int r, int g, int b))> GetEnumerator()
|
||||
{
|
||||
return _colors.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
@ -33,6 +33,7 @@ public class TwainMemoryBufferReaderTests
|
||||
};
|
||||
var imageData = CreateColorImageData(2, 2);
|
||||
var image = Create24BitImage(2, 2);
|
||||
|
||||
TwainMemoryBufferReader.CopyBufferToImage(buffer, imageData, image);
|
||||
|
||||
ImageAsserts.PixelColors(image, new()
|
||||
@ -60,6 +61,7 @@ public class TwainMemoryBufferReaderTests
|
||||
};
|
||||
var imageData = CreateGrayscaleImageData(2, 2);
|
||||
var image = Create24BitImage(2, 2);
|
||||
|
||||
TwainMemoryBufferReader.CopyBufferToImage(buffer, imageData, image);
|
||||
|
||||
ImageAsserts.PixelColors(image, new()
|
||||
@ -87,6 +89,7 @@ public class TwainMemoryBufferReaderTests
|
||||
};
|
||||
var imageData = CreateBlackWhiteImageData(2, 2);
|
||||
var image = Create1BitImage(2, 2);
|
||||
|
||||
TwainMemoryBufferReader.CopyBufferToImage(buffer, imageData, image);
|
||||
|
||||
ImageAsserts.PixelColors(image, new()
|
||||
|
Loading…
Reference in New Issue
Block a user