feat(core): add sRGB transfer and luminance helpers
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
2 files changed
+135
No files matched your search
@@ -0,0 +1,36 @@
|
||||
using Titano.Core.Imaging;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.Core.Tests.Foundation;
|
||||
|
||||
public sealed class ColorSpaceTests
|
||||
{
|
||||
[Test]
|
||||
public void EightBitRoundTripIsExact()
|
||||
{
|
||||
for (var i = 0; i < 256; i++) Assert.Equal((byte)i, ColorSpace.Encode8(ColorSpace.Linear8((byte)i)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SixteenBitRoundTripWithinOneCode()
|
||||
{
|
||||
for (var i = 0; i < 65536; i += 7)
|
||||
{
|
||||
var back = ColorSpace.Encode16(ColorSpace.Linear16((ushort)i));
|
||||
Assert.InRange(back, i - 1, i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FastEncodeMatchesExact()
|
||||
{
|
||||
for (var i = 1; i <= 10000; i++)
|
||||
{
|
||||
var v = i / 10000f;
|
||||
Assert.Approximately(ColorSpace.LinearToSrgb(v), ColorSpace.EncodeFast(v), 2e-5);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MiddleGreyIsAbout118() => Assert.InRange(ColorSpace.Encode8(0.18f), 117, 119);
|
||||
}
|
||||
Reference in new issue
Block a user