mirror of
https://github.com/DarthAffe/HPPH.git
synced 2025-12-12 13:28:37 +00:00
More tests and small fixes
This commit is contained in:
parent
2a26c4404f
commit
9f3fbc7473
@ -15,11 +15,12 @@
|
|||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||||
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
|
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
|
||||||
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
|
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
|
||||||
<PackageReference Include="System.Drawing.Common" Version="8.0.6" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\HPPH.Reference\HPPH.Reference.csproj" />
|
<ProjectReference Include="..\HPPH.Reference\HPPH.Reference.csproj" />
|
||||||
|
<ProjectReference Include="..\HPPH.SkiaSharp\HPPH.SkiaSharp.csproj" />
|
||||||
|
<ProjectReference Include="..\HPPH.System.Drawing\HPPH.System.Drawing.csproj" />
|
||||||
<ProjectReference Include="..\HPPH\HPPH.csproj" />
|
<ProjectReference Include="..\HPPH\HPPH.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,5 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace HPPH.Test.Image;
|
namespace HPPH.Test.Image;
|
||||||
|
|
||||||
@ -7,8 +8,7 @@ public class RefImageTest
|
|||||||
{
|
{
|
||||||
#region Constants
|
#region Constants
|
||||||
|
|
||||||
private const int TEST_WIDTH = 1920;
|
private readonly List<(int width, int height)> SIZES = [(1920, 1080), (1920, 1), (1, 1080), (200, 500), (1, 1)];
|
||||||
private const int TEST_HEIGHT = 1080;
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -17,50 +17,61 @@ public class RefImageTest
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ImageCreation()
|
public void ImageCreation()
|
||||||
{
|
{
|
||||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(TEST_WIDTH, TEST_HEIGHT).AsRefImage();
|
foreach ((int width, int height) in SIZES)
|
||||||
|
{
|
||||||
|
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(width, height).AsRefImage();
|
||||||
|
|
||||||
Assert.AreEqual(TEST_WIDTH, image.Width);
|
Assert.AreEqual(width, image.Width);
|
||||||
Assert.AreEqual(TEST_HEIGHT, image.Height);
|
Assert.AreEqual(height, image.Height);
|
||||||
|
|
||||||
for (int y = 0; y < image.Height; y++)
|
for (int y = 0; y < image.Height; y++)
|
||||||
for (int x = 0; x < image.Width; x++)
|
for (int x = 0; x < image.Width; x++)
|
||||||
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), image[x, y]);
|
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), image[x, y]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ImageInnerFull()
|
public void ImageInnerFull()
|
||||||
{
|
{
|
||||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(TEST_WIDTH, TEST_HEIGHT).AsRefImage();
|
foreach ((int width, int height) in SIZES)
|
||||||
image = image[0, 0, image.Width, image.Height];
|
{
|
||||||
|
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(width, height).AsRefImage();
|
||||||
|
image = image[0, 0, image.Width, image.Height];
|
||||||
|
|
||||||
for (int y = 0; y < image.Height; y++)
|
for (int y = 0; y < image.Height; y++)
|
||||||
for (int x = 0; x < image.Width; x++)
|
for (int x = 0; x < image.Width; x++)
|
||||||
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), image[x, y]);
|
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), image[x, y]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ImageEnumerator()
|
public void ImageEnumerator()
|
||||||
{
|
{
|
||||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(TEST_WIDTH, TEST_HEIGHT).AsRefImage();
|
foreach ((int width, int height) in SIZES)
|
||||||
|
|
||||||
int counter = 0;
|
|
||||||
foreach (ColorARGB color in image)
|
|
||||||
{
|
{
|
||||||
int x = counter % image.Width;
|
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(width, height).AsRefImage();
|
||||||
int y = counter / image.Width;
|
|
||||||
|
|
||||||
if (y == 1) Debugger.Break();
|
int counter = 0;
|
||||||
|
foreach (ColorARGB color in image)
|
||||||
|
{
|
||||||
|
int x = counter % image.Width;
|
||||||
|
int y = counter / image.Width;
|
||||||
|
|
||||||
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), color);
|
if (y == 1) Debugger.Break();
|
||||||
|
|
||||||
counter++;
|
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), color);
|
||||||
|
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ImageInnerPartial()
|
public void ImageInnerPartial()
|
||||||
{
|
{
|
||||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(TEST_WIDTH, TEST_HEIGHT).AsRefImage();
|
(int width, int height) = SIZES[0];
|
||||||
|
|
||||||
|
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(width, height).AsRefImage();
|
||||||
image = image[163, 280, 720, 13];
|
image = image[163, 280, 720, 13];
|
||||||
|
|
||||||
Assert.AreEqual(720, image.Width);
|
Assert.AreEqual(720, image.Width);
|
||||||
@ -74,7 +85,9 @@ public class RefImageTest
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ImageInnerInnerPartial()
|
public void ImageInnerInnerPartial()
|
||||||
{
|
{
|
||||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(TEST_WIDTH, TEST_HEIGHT).AsRefImage();
|
(int width, int height) = SIZES[0];
|
||||||
|
|
||||||
|
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(width, height).AsRefImage();
|
||||||
image = image[163, 280, 720, 13];
|
image = image[163, 280, 720, 13];
|
||||||
image = image[15, 2, 47, 8];
|
image = image[15, 2, 47, 8];
|
||||||
|
|
||||||
@ -89,92 +102,112 @@ public class RefImageTest
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ImageRowIndexer()
|
public void ImageRowIndexer()
|
||||||
{
|
{
|
||||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(TEST_WIDTH, TEST_HEIGHT).AsRefImage();
|
foreach ((int width, int height) in SIZES)
|
||||||
|
|
||||||
Assert.AreEqual(image.Height, image.Rows.Count);
|
|
||||||
|
|
||||||
for (int y = 0; y < image.Height; y++)
|
|
||||||
{
|
{
|
||||||
ImageRow<ColorARGB> row = image.Rows[y];
|
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(width, height).AsRefImage();
|
||||||
Assert.AreEqual(image.Width, row.Length);
|
|
||||||
for (int x = 0; x < row.Length; x++)
|
Assert.AreEqual(image.Height, image.Rows.Count);
|
||||||
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), row[x]);
|
|
||||||
|
for (int y = 0; y < image.Height; y++)
|
||||||
|
{
|
||||||
|
ImageRow<ColorARGB> row = image.Rows[y];
|
||||||
|
Assert.AreEqual(image.Width, row.Length);
|
||||||
|
for (int x = 0; x < row.Length; x++)
|
||||||
|
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), row[x]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ImageRowEnumerator()
|
public void ImageRowEnumerator()
|
||||||
{
|
{
|
||||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(TEST_WIDTH, TEST_HEIGHT).AsRefImage();
|
foreach ((int width, int height) in SIZES)
|
||||||
|
|
||||||
int y = 0;
|
|
||||||
foreach (ImageRow<ColorARGB> row in image.Rows)
|
|
||||||
{
|
{
|
||||||
for (int x = 0; x < row.Length; x++)
|
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(width, height).AsRefImage();
|
||||||
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), row[x]);
|
|
||||||
|
|
||||||
y++;
|
int y = 0;
|
||||||
|
foreach (ImageRow<ColorARGB> row in image.Rows)
|
||||||
|
{
|
||||||
|
for (int x = 0; x < row.Length; x++)
|
||||||
|
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), row[x]);
|
||||||
|
|
||||||
|
y++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ImageColumnIndexer()
|
public void ImageColumnIndexer()
|
||||||
{
|
{
|
||||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(TEST_WIDTH, TEST_HEIGHT).AsRefImage();
|
foreach ((int width, int height) in SIZES)
|
||||||
|
|
||||||
Assert.AreEqual(image.Width, image.Columns.Count);
|
|
||||||
|
|
||||||
for (int x = 0; x < image.Width; x++)
|
|
||||||
{
|
{
|
||||||
ImageColumn<ColorARGB> column = image.Columns[x];
|
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(width, height).AsRefImage();
|
||||||
Assert.AreEqual(image.Height, column.Length);
|
|
||||||
for (int y = 0; y < column.Length; y++)
|
Assert.AreEqual(image.Width, image.Columns.Count);
|
||||||
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), column[y]);
|
|
||||||
|
for (int x = 0; x < image.Width; x++)
|
||||||
|
{
|
||||||
|
ImageColumn<ColorARGB> column = image.Columns[x];
|
||||||
|
Assert.AreEqual(image.Height, column.Length);
|
||||||
|
for (int y = 0; y < column.Length; y++)
|
||||||
|
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), column[y]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ImageColumnEnumerator()
|
public void ImageColumnEnumerator()
|
||||||
{
|
{
|
||||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(TEST_WIDTH, TEST_HEIGHT).AsRefImage();
|
foreach ((int width, int height) in SIZES)
|
||||||
|
|
||||||
int x = 0;
|
|
||||||
foreach (ImageColumn<ColorARGB> column in image.Columns)
|
|
||||||
{
|
{
|
||||||
for (int y = 0; y < column.Length; y++)
|
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(width, height).AsRefImage();
|
||||||
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), column[y]);
|
|
||||||
|
|
||||||
x++;
|
int x = 0;
|
||||||
|
foreach (ImageColumn<ColorARGB> column in image.Columns)
|
||||||
|
{
|
||||||
|
for (int y = 0; y < column.Length; y++)
|
||||||
|
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), column[y]);
|
||||||
|
|
||||||
|
x++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ToArray()
|
public void ToArray()
|
||||||
{
|
{
|
||||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(TEST_WIDTH, TEST_HEIGHT).AsRefImage();
|
foreach ((int width, int height) in SIZES)
|
||||||
ColorARGB[] testData = image.ToArray();
|
{
|
||||||
|
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(width, height).AsRefImage();
|
||||||
|
ColorARGB[] testData = image.ToArray();
|
||||||
|
|
||||||
for (int y = 0; y < TEST_HEIGHT; y++)
|
for (int y = 0; y < height; y++)
|
||||||
for (int x = 0; x < TEST_WIDTH; x++)
|
for (int x = 0; x < width; x++)
|
||||||
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), testData[(y * TEST_WIDTH) + x]);
|
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), testData[(y * width) + x]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void CopyTo()
|
public void CopyTo()
|
||||||
{
|
{
|
||||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(TEST_WIDTH, TEST_HEIGHT).AsRefImage();
|
foreach ((int width, int height) in SIZES)
|
||||||
ColorARGB[] testData = new ColorARGB[TEST_WIDTH * TEST_HEIGHT];
|
{
|
||||||
image.CopyTo(testData);
|
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(width, height).AsRefImage();
|
||||||
|
ColorARGB[] testData = new ColorARGB[width * height];
|
||||||
|
image.CopyTo(testData);
|
||||||
|
|
||||||
for (int y = 0; y < TEST_HEIGHT; y++)
|
for (int y = 0; y < height; y++)
|
||||||
for (int x = 0; x < TEST_WIDTH; x++)
|
for (int x = 0; x < width; x++)
|
||||||
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), testData[(y * TEST_WIDTH) + x]);
|
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), testData[(y * width) + x]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void SubImage()
|
public void SubImage()
|
||||||
{
|
{
|
||||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(TEST_WIDTH, TEST_HEIGHT).AsRefImage();
|
(int width, int height) = SIZES[0];
|
||||||
|
|
||||||
|
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(width, height).AsRefImage();
|
||||||
RefImage<ColorARGB> subImage = image[10, 20, 100, 200];
|
RefImage<ColorARGB> subImage = image[10, 20, 100, 200];
|
||||||
|
|
||||||
for (int y = 0; y < 200; y++)
|
for (int y = 0; y < 200; y++)
|
||||||
@ -185,20 +218,252 @@ public class RefImageTest
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public unsafe void Pin()
|
public unsafe void Pin()
|
||||||
{
|
{
|
||||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(TEST_WIDTH, TEST_HEIGHT).AsRefImage();
|
foreach ((int width, int height) in SIZES)
|
||||||
ColorARGB[] reference = TestDataHelper.GetPixelData<ColorARGB>(TEST_WIDTH, TEST_HEIGHT);
|
|
||||||
|
|
||||||
fixed (byte* ptr = image)
|
|
||||||
{
|
{
|
||||||
for (int i = 0; i < reference.Length; i++)
|
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(width, height).AsRefImage();
|
||||||
|
ColorARGB[] reference = TestDataHelper.GetPixelData<ColorARGB>(width, height);
|
||||||
|
|
||||||
|
fixed (byte* ptr = image)
|
||||||
{
|
{
|
||||||
Assert.AreEqual(reference[i].A, ptr[(i * 4) + 0]);
|
for (int i = 0; i < reference.Length; i++)
|
||||||
Assert.AreEqual(reference[i].R, ptr[(i * 4) + 1]);
|
{
|
||||||
Assert.AreEqual(reference[i].G, ptr[(i * 4) + 2]);
|
Assert.AreEqual(reference[i].A, ptr[(i * 4) + 0]);
|
||||||
Assert.AreEqual(reference[i].B, ptr[(i * 4) + 3]);
|
Assert.AreEqual(reference[i].R, ptr[(i * 4) + 1]);
|
||||||
|
Assert.AreEqual(reference[i].G, ptr[(i * 4) + 2]);
|
||||||
|
Assert.AreEqual(reference[i].B, ptr[(i * 4) + 3]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void PinEmpty()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(0, 0).AsRefImage();
|
||||||
|
Assert.IsTrue(Unsafe.IsNullRef(in image.GetPinnableReference()));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(ArgumentNullException))]
|
||||||
|
public void CopyToColorNull()
|
||||||
|
{
|
||||||
|
TestDataHelper.CreateTestImage<ColorRGB>(10, 10).AsRefImage().CopyTo(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(ArgumentException))]
|
||||||
|
public void CopyToColorWrongSize()
|
||||||
|
{
|
||||||
|
TestDataHelper.CreateTestImage<ColorRGB>(10, 10).AsRefImage().CopyTo(new ColorRGB[(10 * 10) - 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
||||||
|
public void IndexerWrongXBig()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(10, 20).AsRefImage();
|
||||||
|
ColorRGB test = image[10, 19];
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
||||||
|
public void IndexerWrongYBig()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(10, 20).AsRefImage();
|
||||||
|
ColorRGB test = image[9, 20];
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
||||||
|
public void IndexerWrongXSmall()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(10, 20).AsRefImage();
|
||||||
|
ColorRGB test = image[-1, 19];
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
||||||
|
public void IndexerWrongYSmall()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(10, 20).AsRefImage();
|
||||||
|
ColorRGB test = image[9, -1];
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
||||||
|
public void SubImageWrongX()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(10, 20).AsRefImage();
|
||||||
|
RefImage<ColorRGB> test = image[-1, 0, 10, 20];
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
||||||
|
public void SubImageWrongY()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(10, 20).AsRefImage();
|
||||||
|
RefImage<ColorRGB> test = image[0, -1, 10, 20];
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
||||||
|
public void SubImageWrongWidth()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(10, 20).AsRefImage();
|
||||||
|
RefImage<ColorRGB> test = image[0, 0, 0, 20];
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
||||||
|
public void SubImageWrongHeight()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(10, 20).AsRefImage();
|
||||||
|
RefImage<ColorRGB> test = image[0, 0, 10, 0];
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
||||||
|
public void SubImageInvalidSizeWidth()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(10, 20).AsRefImage();
|
||||||
|
RefImage<ColorRGB> test = image[1, 0, 10, 20];
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
||||||
|
public void SubImageInvalidSizeHeight()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(10, 20).AsRefImage();
|
||||||
|
RefImage<ColorRGB> test = image[0, 1, 10, 20];
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
||||||
|
public void ColumnsIndexerToBig()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(10, 20).AsRefImage();
|
||||||
|
ImageColumn<ColorRGB> test = image.Columns[20];
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
||||||
|
public void ColumnsIndexerToSmall()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(10, 20).AsRefImage();
|
||||||
|
ImageColumn<ColorRGB> test = image.Columns[-1];
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
||||||
|
public void RowsIndexerToBig()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(10, 20).AsRefImage();
|
||||||
|
ImageRow<ColorRGB> test = image.Rows[20];
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
||||||
|
public void RowsIndexerToSmall()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(10, 20).AsRefImage();
|
||||||
|
ImageRow<ColorRGB> test = image.Rows[-1];
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
||||||
|
public void ColumnIndexerToBig()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(10, 20).AsRefImage();
|
||||||
|
IColor test = image.Columns[1][20];
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
||||||
|
public void ColumnIndexerToSmall()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(10, 20).AsRefImage();
|
||||||
|
IColor test = image.Columns[1][-1];
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
||||||
|
public void RowIndexerToBig()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(10, 20).AsRefImage();
|
||||||
|
IColor test = image.Rows[1][10];
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(IndexOutOfRangeException))]
|
||||||
|
public void RowIndexerToSmall()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(10, 20).AsRefImage();
|
||||||
|
IColor test = image.Rows[1][-1];
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(ArgumentNullException))]
|
||||||
|
public void ColumnCopyToByteNull()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(10, 20).AsRefImage();
|
||||||
|
image.Columns[1].CopyTo((Span<byte>)null);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(ArgumentNullException))]
|
||||||
|
public void ColumnCopyToColorNull()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(10, 20).AsRefImage();
|
||||||
|
image.Rows[1].CopyTo((Span<ColorRGB>)null);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(ArgumentException))]
|
||||||
|
public void ColumnCopyToByteToSmall()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(10, 20).AsRefImage();
|
||||||
|
image.Columns[1].CopyTo(new byte[(20 * 3) - 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(ArgumentException))]
|
||||||
|
public void ColumnCopyToColorToSmall()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(10, 20).AsRefImage();
|
||||||
|
image.Columns[1].CopyTo(new ColorRGB[19]);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(ArgumentNullException))]
|
||||||
|
public void RowCopyToByteNull()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(10, 20).AsRefImage();
|
||||||
|
image.Rows[1].CopyTo((Span<byte>)null);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(ArgumentNullException))]
|
||||||
|
public void RowCopyToColorNull()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(10, 20).AsRefImage();
|
||||||
|
image.Rows[1].CopyTo((Span<ColorRGB>)null);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(ArgumentException))]
|
||||||
|
public void RowCopyToByteToSmall()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(10, 20).AsRefImage();
|
||||||
|
image.Rows[1].CopyTo(new byte[(10 * 3) - 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[ExpectedException(typeof(ArgumentException))]
|
||||||
|
public void RowCopyToColorToSmall()
|
||||||
|
{
|
||||||
|
RefImage<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(10, 20).AsRefImage();
|
||||||
|
image.Rows[1].CopyTo(new ColorRGB[9]);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
@ -274,4 +274,34 @@ public class ConvertTests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Convert3ByteSameBppRGBToBGRReadOnlySpan()
|
||||||
|
{
|
||||||
|
foreach (string image in GetTestImages())
|
||||||
|
{
|
||||||
|
for (int skip = 0; skip < 4; skip++)
|
||||||
|
{
|
||||||
|
ColorRGB[] data = ImageHelper.GetColorsFromImage<ColorRGB>(image).SkipLast(skip).ToArray();
|
||||||
|
ReadOnlySpan<ColorRGB> referenceData = data;
|
||||||
|
|
||||||
|
Span<ColorRGB> sourceData = new ColorRGB[referenceData.Length];
|
||||||
|
referenceData.CopyTo(sourceData);
|
||||||
|
|
||||||
|
Span<ColorBGR> result = ((ReadOnlySpan<ColorRGB>)sourceData).Convert<ColorRGB, ColorBGR>();
|
||||||
|
|
||||||
|
Assert.AreEqual(referenceData.Length, result.Length);
|
||||||
|
for (int i = 0; i < referenceData.Length; i++)
|
||||||
|
{
|
||||||
|
ColorRGB reference = referenceData[i];
|
||||||
|
ColorBGR test = result[i];
|
||||||
|
|
||||||
|
Assert.AreEqual(reference.R, test.R, $"R differs at index {i}. Image: {image}, skip: {skip}");
|
||||||
|
Assert.AreEqual(reference.G, test.G, $"G differs at index {i}. Image: {image}, skip: {skip}");
|
||||||
|
Assert.AreEqual(reference.B, test.B, $"B differs at index {i}. Image: {image}, skip: {skip}");
|
||||||
|
Assert.AreEqual(reference.A, test.A, $"A differs at index {i}. Image: {image}, skip: {skip}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
52
HPPH.Test/Skia/SkiaTests.cs
Normal file
52
HPPH.Test/Skia/SkiaTests.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
using HPPH.SkiaSharp;
|
||||||
|
using SkiaSharp;
|
||||||
|
|
||||||
|
namespace HPPH.Test.Skia;
|
||||||
|
|
||||||
|
[TestClass]
|
||||||
|
public class SkiaTests
|
||||||
|
{
|
||||||
|
private static IEnumerable<string> GetTestImages() => Directory.EnumerateFiles(@"..\..\..\..\sample_data", "*.png", SearchOption.AllDirectories);
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ImageConversion24Bit()
|
||||||
|
{
|
||||||
|
Image<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(1920, 1080);
|
||||||
|
using SKImage bitmap = image.ToSKImage();
|
||||||
|
IImage image2 = bitmap.ToImage();
|
||||||
|
|
||||||
|
Assert.AreEqual(IColorFormat.BGRA, image2.ColorFormat);
|
||||||
|
|
||||||
|
image2 = image2.ConvertTo<ColorRGB>();
|
||||||
|
|
||||||
|
Assert.AreEqual(image, image2);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ImageConversion32Bit()
|
||||||
|
{
|
||||||
|
Image<ColorRGBA> image = TestDataHelper.CreateTestImage<ColorRGBA>(1920, 1080);
|
||||||
|
using SKImage bitmap = image.ToSKImage();
|
||||||
|
IImage image2 = bitmap.ToImage();
|
||||||
|
|
||||||
|
Assert.AreEqual(IColorFormat.BGRA, image2.ColorFormat);
|
||||||
|
|
||||||
|
image2 = image2.ConvertTo<ColorRGBA>();
|
||||||
|
|
||||||
|
Assert.AreEqual(image, image2);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void LoadFileToPngLoadStream()
|
||||||
|
{
|
||||||
|
foreach (string image in GetTestImages())
|
||||||
|
{
|
||||||
|
IImage img = SkiaSharp.ImageHelper.LoadImage(image);
|
||||||
|
byte[] png = img.ToPng();
|
||||||
|
using MemoryStream ms = new(png);
|
||||||
|
IImage img2 = SkiaSharp.ImageHelper.LoadImage(ms);
|
||||||
|
|
||||||
|
Assert.AreEqual(img, img2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
52
HPPH.Test/SystemDrawing/SystemDrawingTests.cs
Normal file
52
HPPH.Test/SystemDrawing/SystemDrawingTests.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
using System.Drawing;
|
||||||
|
using HPPH.System.Drawing;
|
||||||
|
|
||||||
|
namespace HPPH.Test.SystemDrawing;
|
||||||
|
|
||||||
|
[TestClass]
|
||||||
|
public class SystemDrawingTests
|
||||||
|
{
|
||||||
|
private static IEnumerable<string> GetTestImages() => Directory.EnumerateFiles(@"..\..\..\..\sample_data", "*.png", SearchOption.AllDirectories);
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ImageConversion24Bit()
|
||||||
|
{
|
||||||
|
Image<ColorRGB> image = TestDataHelper.CreateTestImage<ColorRGB>(1920, 1080);
|
||||||
|
using Bitmap bitmap = image.ToBitmap();
|
||||||
|
IImage image2 = bitmap.ToImage();
|
||||||
|
|
||||||
|
Assert.AreEqual(IColorFormat.BGR, image2.ColorFormat);
|
||||||
|
|
||||||
|
image2 = image2.ConvertTo<ColorRGB>();
|
||||||
|
|
||||||
|
Assert.AreEqual(image, image2);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ImageConversion32Bit()
|
||||||
|
{
|
||||||
|
Image<ColorRGBA> image = TestDataHelper.CreateTestImage<ColorRGBA>(1920, 1080);
|
||||||
|
using Bitmap bitmap = image.ToBitmap();
|
||||||
|
IImage image2 = bitmap.ToImage();
|
||||||
|
|
||||||
|
Assert.AreEqual(IColorFormat.BGRA, image2.ColorFormat);
|
||||||
|
|
||||||
|
image2 = image2.ConvertTo<ColorRGBA>();
|
||||||
|
|
||||||
|
Assert.AreEqual(image, image2);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void LoadFileToPngLoadStream()
|
||||||
|
{
|
||||||
|
foreach (string image in GetTestImages())
|
||||||
|
{
|
||||||
|
IImage img = System.Drawing.ImageHelper.LoadImage(image);
|
||||||
|
byte[] png = img.ToPng();
|
||||||
|
using MemoryStream ms = new(png);
|
||||||
|
IImage img2 = System.Drawing.ImageHelper.LoadImage(ms);
|
||||||
|
|
||||||
|
Assert.AreEqual(img, img2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -6,7 +6,7 @@ namespace HPPH;
|
|||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
[SkipLocalsInit]
|
[SkipLocalsInit]
|
||||||
public sealed class Image<T> : IImage<T>
|
public sealed class Image<T> : IImage<T>, IEquatable<Image<T>>
|
||||||
where T : struct, IColor
|
where T : struct, IColor
|
||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
@ -224,5 +224,49 @@ public sealed class Image<T> : IImage<T>
|
|||||||
|
|
||||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||||
|
|
||||||
|
//TODO DarthAffe 20.07.2024: All of those equals can be optimized
|
||||||
|
public bool Equals(IImage? other)
|
||||||
|
{
|
||||||
|
if (other == null) return false;
|
||||||
|
if (other.ColorFormat != ColorFormat) return false;
|
||||||
|
if (other.Width != Width) return false;
|
||||||
|
if (other.Height != Height) return false;
|
||||||
|
|
||||||
|
for (int y = 0; y < Height; y++)
|
||||||
|
for (int x = 0; x < Width; x++)
|
||||||
|
if (!this[x, y].Equals(other[x, y]))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Equals(IImage<T>? other)
|
||||||
|
{
|
||||||
|
if (other == null) return false;
|
||||||
|
if (other.Width != Width) return false;
|
||||||
|
if (other.Height != Height) return false;
|
||||||
|
|
||||||
|
for (int y = 0; y < Height; y++)
|
||||||
|
for (int x = 0; x < Width; x++)
|
||||||
|
if (!this[x, y].Equals(other[x, y]))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Equals(Image<T>? other)
|
||||||
|
{
|
||||||
|
if (other == null) return false;
|
||||||
|
if (other.Width != Width) return false;
|
||||||
|
if (other.Height != Height) return false;
|
||||||
|
|
||||||
|
for (int y = 0; y < Height; y++)
|
||||||
|
for (int x = 0; x < Width; x++)
|
||||||
|
if (!this[x, y].Equals(other[x, y]))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
@ -56,15 +56,10 @@ public readonly ref struct ImageColumn<T>
|
|||||||
if (destination == null) throw new ArgumentNullException(nameof(destination));
|
if (destination == null) throw new ArgumentNullException(nameof(destination));
|
||||||
if (destination.Length < SizeInBytes) throw new ArgumentException("The destination is too small to fit this image.", nameof(destination));
|
if (destination.Length < SizeInBytes) throw new ArgumentException("The destination is too small to fit this image.", nameof(destination));
|
||||||
|
|
||||||
if (_step == 1)
|
ref byte dataRef = ref Unsafe.Add(ref MemoryMarshal.GetReference(_buffer), _start);
|
||||||
_buffer.Slice(_start, SizeInBytes).CopyTo(destination);
|
Span<T> target = MemoryMarshal.Cast<byte, T>(destination);
|
||||||
else
|
for (int i = 0; i < Length; i++)
|
||||||
{
|
target[i] = Unsafe.As<byte, T>(ref Unsafe.Add(ref dataRef, i * _step));
|
||||||
ref byte dataRef = ref Unsafe.Add(ref MemoryMarshal.GetReference(_buffer), _start);
|
|
||||||
Span<T> target = MemoryMarshal.Cast<byte, T>(destination);
|
|
||||||
for (int i = 0; i < Length; i++)
|
|
||||||
target[i] = Unsafe.As<byte, T>(ref Unsafe.Add(ref dataRef, i * _step));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public T[] ToArray()
|
public T[] ToArray()
|
||||||
@ -177,15 +172,10 @@ internal class IColorImageColumn<T> : IImageColumn
|
|||||||
if (destination == null) throw new ArgumentNullException(nameof(destination));
|
if (destination == null) throw new ArgumentNullException(nameof(destination));
|
||||||
if (destination.Length < SizeInBytes) throw new ArgumentException("The destination is too small to fit this image.", nameof(destination));
|
if (destination.Length < SizeInBytes) throw new ArgumentException("The destination is too small to fit this image.", nameof(destination));
|
||||||
|
|
||||||
if (_step == 1)
|
ref byte dataRef = ref Unsafe.Add(ref MemoryMarshal.GetReference(_buffer.AsSpan()), _start);
|
||||||
_buffer.AsSpan().Slice(_start, SizeInBytes).CopyTo(destination);
|
Span<T> target = MemoryMarshal.Cast<byte, T>(destination);
|
||||||
else
|
for (int i = 0; i < Length; i++)
|
||||||
{
|
target[i] = Unsafe.As<byte, T>(ref Unsafe.Add(ref dataRef, i * _step));
|
||||||
ref byte dataRef = ref Unsafe.Add(ref MemoryMarshal.GetReference(_buffer.AsSpan()), _start);
|
|
||||||
Span<T> target = MemoryMarshal.Cast<byte, T>(destination);
|
|
||||||
for (int i = 0; i < Length; i++)
|
|
||||||
target[i] = Unsafe.As<byte, T>(ref Unsafe.Add(ref dataRef, i * _step));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IColor[] ToArray()
|
public IColor[] ToArray()
|
||||||
|
|||||||
@ -28,7 +28,7 @@ public readonly ref struct ImageColumns<T>
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if ((column < 0) || (column > _width)) throw new IndexOutOfRangeException();
|
if ((column < 0) || (column >= _width)) throw new IndexOutOfRangeException();
|
||||||
|
|
||||||
return new ImageColumn<T>(_data, (_y * _stride) + ((column + _x) * _bpp), _height, _stride);
|
return new ImageColumn<T>(_data, (_y * _stride) + ((column + _x) * _bpp), _height, _stride);
|
||||||
}
|
}
|
||||||
@ -124,7 +124,7 @@ internal class IColorImageColumns<T> : IImageColumns
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if ((column < 0) || (column > _width)) throw new IndexOutOfRangeException();
|
if ((column < 0) || (column >= _width)) throw new IndexOutOfRangeException();
|
||||||
|
|
||||||
return new IColorImageColumn<T>(_data, (_y * _stride) + ((column + _x) * _bpp), _height, _stride);
|
return new IColorImageColumn<T>(_data, (_y * _stride) + ((column + _x) * _bpp), _height, _stride);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -152,6 +152,9 @@ internal class IColorImageRow<T> : IImageRow
|
|||||||
|
|
||||||
public void CopyTo(Span<IColor> destination)
|
public void CopyTo(Span<IColor> destination)
|
||||||
{
|
{
|
||||||
|
if (destination == null) throw new ArgumentNullException(nameof(destination));
|
||||||
|
if (destination.Length < _length) throw new ArgumentException("The destination is too small to fit this image.", nameof(destination));
|
||||||
|
|
||||||
for (int i = 0; i < _length; i++)
|
for (int i = 0; i < _length; i++)
|
||||||
destination[i] = this[i];
|
destination[i] = this[i];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,7 +27,7 @@ public readonly ref struct ImageRows<T>
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if ((row < 0) || (row > _height)) throw new IndexOutOfRangeException();
|
if ((row < 0) || (row >= _height)) throw new IndexOutOfRangeException();
|
||||||
|
|
||||||
return new ImageRow<T>(_data, ((row + _y) * _stride) + _x, _width);
|
return new ImageRow<T>(_data, ((row + _y) * _stride) + _x, _width);
|
||||||
}
|
}
|
||||||
@ -122,7 +122,7 @@ internal class IColorImageRows<T> : IImageRows
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if ((row < 0) || (row > _height)) throw new IndexOutOfRangeException();
|
if ((row < 0) || (row >= _height)) throw new IndexOutOfRangeException();
|
||||||
|
|
||||||
return new IColorImageRow<T>(_data, ((row + _y) * _stride) + _x, _width);
|
return new IColorImageRow<T>(_data, ((row + _y) * _stride) + _x, _width);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents an image.
|
/// Represents an image.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IImage : IEnumerable<IColor>
|
public interface IImage : IEnumerable<IColor>, IEquatable<IImage>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the color format used in this image.
|
/// Gets the color format used in this image.
|
||||||
@ -61,7 +61,7 @@ public interface IImage : IEnumerable<IColor>
|
|||||||
RefImage<TColor> AsRefImage<TColor>() where TColor : struct, IColor;
|
RefImage<TColor> AsRefImage<TColor>() where TColor : struct, IColor;
|
||||||
|
|
||||||
IImage<TColor> ConvertTo<TColor>() where TColor : struct, IColor;
|
IImage<TColor> ConvertTo<TColor>() where TColor : struct, IColor;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Copies the contents of this <see cref="IImage"/> into a destination <see cref="Span{T}"/> instance.
|
/// Copies the contents of this <see cref="IImage"/> into a destination <see cref="Span{T}"/> instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -83,7 +83,7 @@ public interface IImage : IEnumerable<IColor>
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents an image.
|
/// Represents an image.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IImage<T> : IImage
|
public interface IImage<T> : IImage, IEquatable<IImage<T>>
|
||||||
where T : struct, IColor
|
where T : struct, IColor
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user