mirror of
https://github.com/DarthAffe/HPPH.git
synced 2025-12-12 13:28:37 +00:00
Compare commits
4 Commits
2a26c4404f
...
15981f82d6
| Author | SHA1 | Date | |
|---|---|---|---|
| 15981f82d6 | |||
| 60d24e7d0d | |||
| db218e0e8d | |||
| 9f3fbc7473 |
55
.github/workflows/release.yml
vendored
Normal file
55
.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
name: release
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
description: 'version'
|
||||
required: true
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: windows-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install .NET Core
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: 8.0.x
|
||||
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore HPPH
|
||||
|
||||
- name: Build
|
||||
run: dotnet build HPPH --no-restore --configuration Release /p:Version=${{ github.event.inputs.version }}
|
||||
|
||||
- name: Test
|
||||
run: dotnet test HPPH --no-build --verbosity normal --configuration Release
|
||||
|
||||
- name: Upload Nuget Build Artifact
|
||||
uses: actions/upload-artifact@v4.3.1
|
||||
with:
|
||||
name: HPPH-Nuget
|
||||
path: HPPH\bin\Release\*.nupkg
|
||||
if-no-files-found: error
|
||||
|
||||
- name: List files
|
||||
run: tree
|
||||
|
||||
- name: Release
|
||||
uses: softprops/action-gh-release@v2.0.4
|
||||
with:
|
||||
tag_name: ${{ github.event.inputs.version }}
|
||||
generate_release_notes: true
|
||||
files: HPPH/bin/Release/net8.0/*.dll
|
||||
|
||||
- name: Nuget Push
|
||||
id: nuget_push
|
||||
run: dotnet nuget push **\*.nupkg --skip-duplicate --api-key ${{ secrets.NUGET_TOKEN }} --source https://api.nuget.org/v3/index.json
|
||||
|
||||
@ -5,8 +5,61 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
|
||||
<Authors>Darth Affe</Authors>
|
||||
<Company>Wyrez</Company>
|
||||
<Language>en-US</Language>
|
||||
<NeutralLanguage>en-US</NeutralLanguage>
|
||||
<Title>HPPH.SkiaSharp</Title>
|
||||
<AssemblyName>HPPH.SkiaSharp</AssemblyName>
|
||||
<AssemblyTitle>HPPH.SkiaSharp</AssemblyTitle>
|
||||
<PackageId>HPPH.SkiaSharp</PackageId>
|
||||
<RootNamespace>HPPH.SkiaSharp</RootNamespace>
|
||||
<Description>SkiaSharp extensions for HPPH</Description>
|
||||
<Summary>SkiaSharp extensions for HPPH</Summary>
|
||||
<Copyright>Copyright © Darth Affe 2024</Copyright>
|
||||
<PackageCopyright>Copyright © Darth Affe 2024</PackageCopyright>
|
||||
<PackageIcon>hpph.png</PackageIcon>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<PackageProjectUrl>https://github.com/DarthAffe/HPPH</PackageProjectUrl>
|
||||
<PackageLicenseExpression>LGPL-2.1-only</PackageLicenseExpression>
|
||||
<RepositoryType>Github</RepositoryType>
|
||||
<RepositoryUrl>https://github.com/DarthAffe/HPPH</RepositoryUrl>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
|
||||
<PackageReleaseNotes>
|
||||
</PackageReleaseNotes>
|
||||
|
||||
<Version>0.0.1</Version>
|
||||
<AssemblyVersion>0.0.1</AssemblyVersion>
|
||||
<FileVersion>0.0.1</FileVersion>
|
||||
|
||||
<OutputPath>..\bin\</OutputPath>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<IncludeSource>True</IncludeSource>
|
||||
<IncludeSymbols>True</IncludeSymbols>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<DefineConstants>$(DefineConstants);TRACE;DEBUG</DefineConstants>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
||||
<DebugType>portable</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<NoWarn>$(NoWarn);CS1591;CS1572;CS1573</NoWarn>
|
||||
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="hpph.png" Link="hpph.png" Pack="true" PackagePath="\" />
|
||||
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SkiaSharp" Version="2.88.8" />
|
||||
</ItemGroup>
|
||||
|
||||
BIN
HPPH.SkiaSharp/hpph.png
Normal file
BIN
HPPH.SkiaSharp/hpph.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 202 KiB |
@ -5,8 +5,61 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
|
||||
<Authors>Darth Affe</Authors>
|
||||
<Company>Wyrez</Company>
|
||||
<Language>en-US</Language>
|
||||
<NeutralLanguage>en-US</NeutralLanguage>
|
||||
<Title>HPPH.System.Drawing</Title>
|
||||
<AssemblyName>HPPH.System.Drawing</AssemblyName>
|
||||
<AssemblyTitle>HPPH.System.Drawing</AssemblyTitle>
|
||||
<PackageId>HPPH.System.Drawing</PackageId>
|
||||
<RootNamespace>HPPH.System.Drawing</RootNamespace>
|
||||
<Description>System.Drawing extensions for HPPH</Description>
|
||||
<Summary>System.Drawing extensions for HPPH</Summary>
|
||||
<Copyright>Copyright © Darth Affe 2024</Copyright>
|
||||
<PackageCopyright>Copyright © Darth Affe 2024</PackageCopyright>
|
||||
<PackageIcon>hpph.png</PackageIcon>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<PackageProjectUrl>https://github.com/DarthAffe/HPPH</PackageProjectUrl>
|
||||
<PackageLicenseExpression>LGPL-2.1-only</PackageLicenseExpression>
|
||||
<RepositoryType>Github</RepositoryType>
|
||||
<RepositoryUrl>https://github.com/DarthAffe/HPPH</RepositoryUrl>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
|
||||
<PackageReleaseNotes>
|
||||
</PackageReleaseNotes>
|
||||
|
||||
<Version>0.0.1</Version>
|
||||
<AssemblyVersion>0.0.1</AssemblyVersion>
|
||||
<FileVersion>0.0.1</FileVersion>
|
||||
|
||||
<OutputPath>..\bin\</OutputPath>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<IncludeSource>True</IncludeSource>
|
||||
<IncludeSymbols>True</IncludeSymbols>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<DefineConstants>$(DefineConstants);TRACE;DEBUG</DefineConstants>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
||||
<DebugType>portable</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<NoWarn>$(NoWarn);CS1591;CS1572;CS1573</NoWarn>
|
||||
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="hpph.png" Link="hpph.png" Pack="true" PackagePath="\" />
|
||||
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.7" />
|
||||
</ItemGroup>
|
||||
|
||||
BIN
HPPH.System.Drawing/hpph.png
Normal file
BIN
HPPH.System.Drawing/hpph.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 202 KiB |
@ -15,11 +15,12 @@
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.6" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<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" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,5 @@
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace HPPH.Test.Image;
|
||||
|
||||
@ -7,8 +8,7 @@ public class RefImageTest
|
||||
{
|
||||
#region Constants
|
||||
|
||||
private const int TEST_WIDTH = 1920;
|
||||
private const int TEST_HEIGHT = 1080;
|
||||
private readonly List<(int width, int height)> SIZES = [(1920, 1080), (1920, 1), (1, 1080), (200, 500), (1, 1)];
|
||||
|
||||
#endregion
|
||||
|
||||
@ -17,50 +17,61 @@ public class RefImageTest
|
||||
[TestMethod]
|
||||
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(TEST_HEIGHT, image.Height);
|
||||
Assert.AreEqual(width, image.Width);
|
||||
Assert.AreEqual(height, image.Height);
|
||||
|
||||
for (int y = 0; y < image.Height; y++)
|
||||
for (int x = 0; x < image.Width; x++)
|
||||
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), image[x, y]);
|
||||
for (int y = 0; y < image.Height; y++)
|
||||
for (int x = 0; x < image.Width; x++)
|
||||
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), image[x, y]);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ImageInnerFull()
|
||||
{
|
||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(TEST_WIDTH, TEST_HEIGHT).AsRefImage();
|
||||
image = image[0, 0, image.Width, image.Height];
|
||||
foreach ((int width, int height) in SIZES)
|
||||
{
|
||||
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 x = 0; x < image.Width; x++)
|
||||
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), image[x, y]);
|
||||
for (int y = 0; y < image.Height; y++)
|
||||
for (int x = 0; x < image.Width; x++)
|
||||
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), image[x, y]);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ImageEnumerator()
|
||||
{
|
||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(TEST_WIDTH, TEST_HEIGHT).AsRefImage();
|
||||
|
||||
int counter = 0;
|
||||
foreach (ColorARGB color in image)
|
||||
foreach ((int width, int height) in SIZES)
|
||||
{
|
||||
int x = counter % image.Width;
|
||||
int y = counter / image.Width;
|
||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(width, height).AsRefImage();
|
||||
|
||||
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]
|
||||
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];
|
||||
|
||||
Assert.AreEqual(720, image.Width);
|
||||
@ -74,7 +85,9 @@ public class RefImageTest
|
||||
[TestMethod]
|
||||
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[15, 2, 47, 8];
|
||||
|
||||
@ -89,92 +102,112 @@ public class RefImageTest
|
||||
[TestMethod]
|
||||
public void ImageRowIndexer()
|
||||
{
|
||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(TEST_WIDTH, TEST_HEIGHT).AsRefImage();
|
||||
|
||||
Assert.AreEqual(image.Height, image.Rows.Count);
|
||||
|
||||
for (int y = 0; y < image.Height; y++)
|
||||
foreach ((int width, int height) in SIZES)
|
||||
{
|
||||
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]);
|
||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(width, height).AsRefImage();
|
||||
|
||||
Assert.AreEqual(image.Height, image.Rows.Count);
|
||||
|
||||
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]
|
||||
public void ImageRowEnumerator()
|
||||
{
|
||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(TEST_WIDTH, TEST_HEIGHT).AsRefImage();
|
||||
|
||||
int y = 0;
|
||||
foreach (ImageRow<ColorARGB> row in image.Rows)
|
||||
foreach ((int width, int height) in SIZES)
|
||||
{
|
||||
for (int x = 0; x < row.Length; x++)
|
||||
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), row[x]);
|
||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(width, height).AsRefImage();
|
||||
|
||||
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]
|
||||
public void ImageColumnIndexer()
|
||||
{
|
||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(TEST_WIDTH, TEST_HEIGHT).AsRefImage();
|
||||
|
||||
Assert.AreEqual(image.Width, image.Columns.Count);
|
||||
|
||||
for (int x = 0; x < image.Width; x++)
|
||||
foreach ((int width, int height) in SIZES)
|
||||
{
|
||||
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]);
|
||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(width, height).AsRefImage();
|
||||
|
||||
Assert.AreEqual(image.Width, image.Columns.Count);
|
||||
|
||||
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]
|
||||
public void ImageColumnEnumerator()
|
||||
{
|
||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(TEST_WIDTH, TEST_HEIGHT).AsRefImage();
|
||||
|
||||
int x = 0;
|
||||
foreach (ImageColumn<ColorARGB> column in image.Columns)
|
||||
foreach ((int width, int height) in SIZES)
|
||||
{
|
||||
for (int y = 0; y < column.Length; y++)
|
||||
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), column[y]);
|
||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(width, height).AsRefImage();
|
||||
|
||||
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]
|
||||
public void ToArray()
|
||||
{
|
||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(TEST_WIDTH, TEST_HEIGHT).AsRefImage();
|
||||
ColorARGB[] testData = image.ToArray();
|
||||
foreach ((int width, int height) in SIZES)
|
||||
{
|
||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(width, height).AsRefImage();
|
||||
ColorARGB[] testData = image.ToArray();
|
||||
|
||||
for (int y = 0; y < TEST_HEIGHT; y++)
|
||||
for (int x = 0; x < TEST_WIDTH; x++)
|
||||
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), testData[(y * TEST_WIDTH) + x]);
|
||||
for (int y = 0; y < height; y++)
|
||||
for (int x = 0; x < width; x++)
|
||||
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), testData[(y * width) + x]);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CopyTo()
|
||||
{
|
||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(TEST_WIDTH, TEST_HEIGHT).AsRefImage();
|
||||
ColorARGB[] testData = new ColorARGB[TEST_WIDTH * TEST_HEIGHT];
|
||||
image.CopyTo(testData);
|
||||
foreach ((int width, int height) in SIZES)
|
||||
{
|
||||
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 x = 0; x < TEST_WIDTH; x++)
|
||||
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), testData[(y * TEST_WIDTH) + x]);
|
||||
for (int y = 0; y < height; y++)
|
||||
for (int x = 0; x < width; x++)
|
||||
Assert.AreEqual(TestDataHelper.GetColorFromLocation<ColorARGB>(x, y), testData[(y * width) + x]);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
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];
|
||||
|
||||
for (int y = 0; y < 200; y++)
|
||||
@ -185,20 +218,252 @@ public class RefImageTest
|
||||
[TestMethod]
|
||||
public unsafe void Pin()
|
||||
{
|
||||
RefImage<ColorARGB> image = TestDataHelper.CreateTestImage<ColorARGB>(TEST_WIDTH, TEST_HEIGHT).AsRefImage();
|
||||
ColorARGB[] reference = TestDataHelper.GetPixelData<ColorARGB>(TEST_WIDTH, TEST_HEIGHT);
|
||||
|
||||
fixed (byte* ptr = image)
|
||||
foreach ((int width, int height) in SIZES)
|
||||
{
|
||||
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]);
|
||||
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]);
|
||||
for (int i = 0; i < reference.Length; i++)
|
||||
{
|
||||
Assert.AreEqual(reference[i].A, ptr[(i * 4) + 0]);
|
||||
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
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -7,8 +7,61 @@
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
|
||||
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
|
||||
|
||||
<Authors>Darth Affe</Authors>
|
||||
<Company>Wyrez</Company>
|
||||
<Language>en-US</Language>
|
||||
<NeutralLanguage>en-US</NeutralLanguage>
|
||||
<Title>HPPH</Title>
|
||||
<AssemblyName>HPPH</AssemblyName>
|
||||
<AssemblyTitle>HPPH</AssemblyTitle>
|
||||
<PackageId>HPPH</PackageId>
|
||||
<RootNamespace>HPPH</RootNamespace>
|
||||
<Description>Some optimized things to perform on color-data</Description>
|
||||
<Summary>High Performance Pixel Handling</Summary>
|
||||
<Copyright>Copyright © Darth Affe 2024</Copyright>
|
||||
<PackageCopyright>Copyright © Darth Affe 2024</PackageCopyright>
|
||||
<PackageIcon>hpph.png</PackageIcon>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<PackageProjectUrl>https://github.com/DarthAffe/HPPH</PackageProjectUrl>
|
||||
<PackageLicenseExpression>LGPL-2.1-only</PackageLicenseExpression>
|
||||
<RepositoryType>Github</RepositoryType>
|
||||
<RepositoryUrl>https://github.com/DarthAffe/HPPH</RepositoryUrl>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
|
||||
<PackageReleaseNotes>
|
||||
</PackageReleaseNotes>
|
||||
|
||||
<Version>0.0.1</Version>
|
||||
<AssemblyVersion>0.0.1</AssemblyVersion>
|
||||
<FileVersion>0.0.1</FileVersion>
|
||||
|
||||
<OutputPath>..\bin\</OutputPath>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<IncludeSource>True</IncludeSource>
|
||||
<IncludeSymbols>True</IncludeSymbols>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<DefineConstants>$(DefineConstants);TRACE;DEBUG</DefineConstants>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
||||
<DebugType>portable</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<NoWarn>$(NoWarn);CS1591;CS1572;CS1573</NoWarn>
|
||||
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="hpph.png" Link="hpph.png" Pack="true" PackagePath="\" />
|
||||
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\HPPH.Generators\HPPH.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -4,9 +4,9 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace HPPH;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <inheritdoc cref="IImage{T}" />
|
||||
[SkipLocalsInit]
|
||||
public sealed class Image<T> : IImage<T>
|
||||
public sealed class Image<T> : IImage<T>, IEquatable<Image<T>>
|
||||
where T : struct, IColor
|
||||
{
|
||||
#region Properties & Fields
|
||||
@ -37,6 +37,7 @@ public sealed class Image<T> : IImage<T>
|
||||
|
||||
#region Indexer
|
||||
|
||||
/// <inheritdoc />
|
||||
IColor IImage.this[int x, int y] => this[x, y];
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -51,6 +52,7 @@ public sealed class Image<T> : IImage<T>
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
IImage IImage.this[int x, int y, int width, int height]
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@ -74,6 +76,7 @@ public sealed class Image<T> : IImage<T>
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
IImageRows IImage.Rows => new IColorImageRows<T>(_buffer, _x, _y, Width, Height, _stride);
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -122,6 +125,7 @@ public sealed class Image<T> : IImage<T>
|
||||
return new Image<T>(data, 0, 0, width, height, stride);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IImage<TColor> ConvertTo<TColor>()
|
||||
where TColor : struct, IColor
|
||||
{
|
||||
@ -141,6 +145,7 @@ public sealed class Image<T> : IImage<T>
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void CopyTo(Span<T> destination) => CopyTo(MemoryMarshal.AsBytes(destination));
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -167,6 +172,7 @@ public sealed class Image<T> : IImage<T>
|
||||
return array;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public T[] ToArray()
|
||||
{
|
||||
T[] colors = new T[Width * Height];
|
||||
@ -175,6 +181,7 @@ public sealed class Image<T> : IImage<T>
|
||||
}
|
||||
|
||||
//TODO DarthAffe 11.07.2024: This has some potential for optimization
|
||||
/// <inheritdoc />
|
||||
IColor[] IImage.ToArray()
|
||||
{
|
||||
IColor[] colors = new IColor[Width * Height];
|
||||
@ -187,8 +194,10 @@ public sealed class Image<T> : IImage<T>
|
||||
return colors;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public RefImage<T> AsRefImage() => new(_buffer, _x, _y, Width, Height, _stride);
|
||||
|
||||
/// <inheritdoc />
|
||||
public RefImage<TColor> AsRefImage<TColor>()
|
||||
where TColor : struct, IColor
|
||||
{
|
||||
@ -208,6 +217,7 @@ public sealed class Image<T> : IImage<T>
|
||||
return ref Unsafe.Add(ref MemoryMarshal.GetReference(_buffer.AsSpan()), (_y * _stride) + (_x * ColorFormat.BytesPerPixel));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
for (int y = 0; y < Height; y++)
|
||||
@ -215,6 +225,7 @@ public sealed class Image<T> : IImage<T>
|
||||
yield return this[x, y];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
IEnumerator<IColor> IEnumerable<IColor>.GetEnumerator()
|
||||
{
|
||||
for (int y = 0; y < Height; y++)
|
||||
@ -222,7 +233,61 @@ public sealed class Image<T> : IImage<T>
|
||||
yield return this[x, y];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
|
||||
//TODO DarthAffe 20.07.2024: All of those equals can be optimized
|
||||
/// <inheritdoc />
|
||||
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;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool Equals(object? obj) => Equals(obj as Image<T>);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int GetHashCode() => HashCode.Combine(ColorFormat, Width, Height, _buffer.GetHashCode());
|
||||
|
||||
#endregion
|
||||
}
|
||||
@ -56,15 +56,10 @@ public readonly ref struct ImageColumn<T>
|
||||
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 (_step == 1)
|
||||
_buffer.Slice(_start, SizeInBytes).CopyTo(destination);
|
||||
else
|
||||
{
|
||||
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));
|
||||
}
|
||||
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()
|
||||
@ -129,14 +124,17 @@ internal class IColorImageColumn<T> : IImageColumn
|
||||
private readonly int _length;
|
||||
private readonly int _step;
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Length => _length;
|
||||
|
||||
/// <inheritdoc />
|
||||
public int SizeInBytes => Length * T.ColorFormat.BytesPerPixel;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Indexer
|
||||
|
||||
/// <inheritdoc />
|
||||
public IColor this[int y]
|
||||
{
|
||||
get
|
||||
@ -163,6 +161,7 @@ internal class IColorImageColumn<T> : IImageColumn
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public void CopyTo(Span<IColor> destination)
|
||||
{
|
||||
if (destination == null) throw new ArgumentNullException(nameof(destination));
|
||||
@ -172,22 +171,19 @@ internal class IColorImageColumn<T> : IImageColumn
|
||||
destination[i] = this[i];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void CopyTo(Span<byte> 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 (_step == 1)
|
||||
_buffer.AsSpan().Slice(_start, SizeInBytes).CopyTo(destination);
|
||||
else
|
||||
{
|
||||
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));
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IColor[] ToArray()
|
||||
{
|
||||
IColor[] array = new IColor[Length];
|
||||
@ -195,12 +191,14 @@ internal class IColorImageColumn<T> : IImageColumn
|
||||
return array;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerator<IColor> GetEnumerator()
|
||||
{
|
||||
for (int i = 0; i < Length; i++)
|
||||
yield return this[i];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
|
||||
#endregion
|
||||
|
||||
@ -28,7 +28,7 @@ public readonly ref struct ImageColumns<T>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
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);
|
||||
}
|
||||
@ -113,18 +113,20 @@ internal class IColorImageColumns<T> : IImageColumns
|
||||
private readonly int _stride;
|
||||
private readonly int _bpp;
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Count => _width;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Indexer
|
||||
|
||||
/// <inheritdoc />
|
||||
public IImageColumn this[int column]
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
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);
|
||||
}
|
||||
@ -151,12 +153,14 @@ internal class IColorImageColumns<T> : IImageColumns
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerator<IImageColumn> GetEnumerator()
|
||||
{
|
||||
for (int i = 0; i < _width; i++)
|
||||
yield return this[i];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
|
||||
#endregion
|
||||
|
||||
@ -117,14 +117,17 @@ internal class IColorImageRow<T> : IImageRow
|
||||
private readonly int _start;
|
||||
private readonly int _length;
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Length => _length;
|
||||
|
||||
/// <inheritdoc />
|
||||
public int SizeInBytes => Length * T.ColorFormat.BytesPerPixel;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Indexer
|
||||
|
||||
/// <inheritdoc />
|
||||
public IColor this[int x]
|
||||
{
|
||||
get
|
||||
@ -150,12 +153,17 @@ internal class IColorImageRow<T> : IImageRow
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
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++)
|
||||
destination[i] = this[i];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void CopyTo(Span<byte> destination)
|
||||
{
|
||||
if (destination == null) throw new ArgumentNullException(nameof(destination));
|
||||
@ -164,6 +172,7 @@ internal class IColorImageRow<T> : IImageRow
|
||||
_buffer.AsSpan().Slice(_start, SizeInBytes).CopyTo(destination);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IColor[] ToArray()
|
||||
{
|
||||
IColor[] array = new IColor[Length];
|
||||
@ -171,12 +180,14 @@ internal class IColorImageRow<T> : IImageRow
|
||||
return array;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerator<IColor> GetEnumerator()
|
||||
{
|
||||
for (int i = 0; i < _length; i++)
|
||||
yield return this[i];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
|
||||
#endregion
|
||||
|
||||
@ -27,7 +27,7 @@ public readonly ref struct ImageRows<T>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
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);
|
||||
}
|
||||
@ -111,18 +111,20 @@ internal class IColorImageRows<T> : IImageRows
|
||||
private readonly int _height;
|
||||
private readonly int _stride;
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Count => _height;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Indexer
|
||||
|
||||
/// <inheritdoc />
|
||||
public IImageRow this[int row]
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
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);
|
||||
}
|
||||
@ -147,12 +149,14 @@ internal class IColorImageRows<T> : IImageRows
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerator<IImageRow> GetEnumerator()
|
||||
{
|
||||
for (int i = 0; i < _height; i++)
|
||||
yield return this[i];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
|
||||
#endregion
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
/// <summary>
|
||||
/// Represents an image.
|
||||
/// </summary>
|
||||
public interface IImage : IEnumerable<IColor>
|
||||
public interface IImage : IEnumerable<IColor>, IEquatable<IImage>
|
||||
{
|
||||
/// <summary>
|
||||
/// 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;
|
||||
|
||||
IImage<TColor> ConvertTo<TColor>() where TColor : struct, IColor;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Copies the contents of this <see cref="IImage"/> into a destination <see cref="Span{T}"/> instance.
|
||||
/// </summary>
|
||||
@ -83,7 +83,7 @@ public interface IImage : IEnumerable<IColor>
|
||||
/// <summary>
|
||||
/// Represents an image.
|
||||
/// </summary>
|
||||
public interface IImage<T> : IImage
|
||||
public interface IImage<T> : IImage, IEquatable<IImage<T>>
|
||||
where T : struct, IColor
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
BIN
HPPH/hpph.png
Normal file
BIN
HPPH/hpph.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 202 KiB |
Loading…
x
Reference in New Issue
Block a user