Add the stbimage test.
This commit is contained in:
parent
f0132e3459
commit
99277153d2
@ -3,10 +3,12 @@ using System;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Quik.Stb;
|
using Quik.Stb;
|
||||||
|
using Image = Quik.Stb.StbImage;
|
||||||
|
|
||||||
namespace Quik.StbImage.Tests
|
namespace Quik.StbImage.Tests
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
|
[TestCategory("Load Image")]
|
||||||
public class LoadImage
|
public class LoadImage
|
||||||
{
|
{
|
||||||
[TestMethod("Set Global Options")]
|
[TestMethod("Set Global Options")]
|
||||||
@ -16,40 +18,32 @@ namespace Quik.StbImage.Tests
|
|||||||
Quik.Stb.StbImage.UnpremultiplyOnLoad = true;
|
Quik.Stb.StbImage.UnpremultiplyOnLoad = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private StbiStreamWrapper PrepareImage(string path, out stbi_io_callbacks cb)
|
private Stream GetImage(string path)
|
||||||
{
|
{
|
||||||
Stream? str = GetType().Assembly.GetManifestResourceStream(path);
|
Stream? str = GetType().Assembly.GetManifestResourceStream(path);
|
||||||
Assert.IsNotNull(str, $"Could not find test image resource {path}.");
|
Assert.IsNotNull(str, $"Could not find test image resource {path}.");
|
||||||
|
return str;
|
||||||
StbiStreamWrapper wrapper = new StbiStreamWrapper(str);
|
|
||||||
wrapper.CreateCallbacks(out cb);
|
|
||||||
return wrapper;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod("Load a PNG")]
|
private unsafe void TestImage(string path, int width, int height)
|
||||||
public unsafe void LoadPng()
|
|
||||||
{
|
{
|
||||||
// TODO: Fill these up!
|
Image image = Image.Load(GetImage(path));
|
||||||
const int TEST_CHANNELS = 0;
|
|
||||||
const int TEST_WIDTH = 0;
|
|
||||||
const int TEST_HEIGHT = 0;
|
|
||||||
|
|
||||||
int x, y, numChannels;
|
Assert.IsNotNull(image);
|
||||||
using StbiStreamWrapper str = PrepareImage("Quik.StbImage.Tests.res.test.png", out stbi_io_callbacks cb);
|
|
||||||
byte *image = Stbi.load_from_callbacks(&cb, null, &x, &y, &numChannels, (int)StbiEnum.STBI_default);
|
|
||||||
|
|
||||||
if (image == null)
|
Assert.AreEqual(width, image.Width, "Width does not match.");
|
||||||
{
|
Assert.AreEqual(height, image.Height, "Height does not match.");
|
||||||
IntPtr reasonPtr = (IntPtr)Stbi.failure_reason();
|
|
||||||
string? reason = Marshal.PtrToStringUTF8((IntPtr)reasonPtr);
|
|
||||||
Assert.Fail("Could not load image: {0}.", reason ?? "None specified. (stbi_failure_reason() is null)");
|
|
||||||
}
|
|
||||||
|
|
||||||
Assert.AreEqual(TEST_CHANNELS, numChannels, "Channel count does not match.");
|
image.Dispose();
|
||||||
Assert.AreEqual(TEST_WIDTH, x, "Width does not match.");
|
|
||||||
Assert.AreEqual(TEST_HEIGHT, y, "Height does not match.");
|
|
||||||
|
|
||||||
Stbi.image_free(image);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const int WIDTH = 768;
|
||||||
|
const int HEIGHT = 512;
|
||||||
|
|
||||||
|
[TestMethod("Load a single frame GIF")]
|
||||||
|
public unsafe void LoadGif() => TestImage("Quik.StbImage.Tests.res.kodim.kodim23.gif", WIDTH, HEIGHT);
|
||||||
|
[TestMethod("Load a JPEG")]
|
||||||
|
public unsafe void LoadJpg() => TestImage("Quik.StbImage.Tests.res.kodim.kodim23.jpg", WIDTH, HEIGHT);
|
||||||
|
[TestMethod("Load a PNG")] public unsafe void LoadPng() => TestImage("Quik.StbImage.Tests.res.kodim.kodim23.png", WIDTH, HEIGHT);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,6 +10,10 @@
|
|||||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Include="res/**"/>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
|
||||||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
|
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
|
||||||
|
3
tests/Quik.StbImage.Tests/res/kodim/LICENSE.md
Normal file
3
tests/Quik.StbImage.Tests/res/kodim/LICENSE.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Kodak Image Suite Test Images owned by Kodak. Image 23 was taken by Steve Kelly.
|
||||||
|
The original image file kodim23.png and its derivatives are only included for
|
||||||
|
test purposes only and should not be redistributed with the software.
|
BIN
tests/Quik.StbImage.Tests/res/kodim/kodim23.gif
Normal file
BIN
tests/Quik.StbImage.Tests/res/kodim/kodim23.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 156 KiB |
BIN
tests/Quik.StbImage.Tests/res/kodim/kodim23.jpg
Normal file
BIN
tests/Quik.StbImage.Tests/res/kodim/kodim23.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 97 KiB |
BIN
tests/Quik.StbImage.Tests/res/kodim/kodim23.png
Normal file
BIN
tests/Quik.StbImage.Tests/res/kodim/kodim23.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 544 KiB |
BIN
tests/Quik.StbImage.Tests/res/kodim/kodim23.tiff
Normal file
BIN
tests/Quik.StbImage.Tests/res/kodim/kodim23.tiff
Normal file
Binary file not shown.
BIN
tests/Quik.StbImage.Tests/res/kodim/kodim23.webp
Normal file
BIN
tests/Quik.StbImage.Tests/res/kodim/kodim23.webp
Normal file
Binary file not shown.
After Width: | Height: | Size: 55 KiB |
Loading…
Reference in New Issue
Block a user