diff --git a/test/ColorTest.cpp b/test/ColorTest.cpp index 2ae3cca..35b9d7e 100644 --- a/test/ColorTest.cpp +++ b/test/ColorTest.cpp @@ -9,16 +9,16 @@ TEST(ColorTest, LimitedRange) { using namespace avif::img; - using converter = avif::img::color::ConverterFactory; + using Converter = avif::img::color::ColorConverter; { // Red color uint16_t y = 0; uint16_t u = 0; uint16_t v = 0; - detail::calcYUV(255, 0, 0, &y, &u, &v); + detail::calcYUV(255, 0, 0, &y, &u, &v); uint8_t r = 0; uint8_t g = 0; uint8_t b = 0; - std::tie(r,g,b) = detail::calcRGB(&y, &u, &v); + std::tie(r,g,b) = detail::calcRGB(&y, &u, &v); ASSERT_EQ(255, r); ASSERT_EQ(0, g); ASSERT_EQ(0, b); @@ -27,7 +27,7 @@ TEST(ColorTest, LimitedRange) { uint8_t y = 0; uint8_t u = 0; uint8_t v = 0; - detail::calcYUV(255, 255, 255, &y, &u, &v); + detail::calcYUV(255, 255, 255, &y, &u, &v); ASSERT_EQ(235, y); ASSERT_EQ(128, u); ASSERT_EQ(128, v); @@ -36,13 +36,13 @@ TEST(ColorTest, LimitedRange) { TEST(ColorTest, FullRange) { using namespace avif::img; - using converter = avif::img::color::ConverterFactory; + using Converter = avif::img::color::ColorConverter; { // Red color uint16_t y = 0; uint16_t u = 0; uint16_t v = 0; - detail::calcYUV(255, 0, 0, &y, &u, &v); - auto [r,g,b] = detail::calcRGB(&y, &u, &v); + detail::calcYUV(255, 0, 0, &y, &u, &v); + auto [r,g,b] = detail::calcRGB(&y, &u, &v); ASSERT_EQ(255, r); ASSERT_EQ(0, g); ASSERT_EQ(0, b); @@ -51,7 +51,31 @@ TEST(ColorTest, FullRange) { uint8_t y = 0; uint8_t u = 0; uint8_t v = 0; - detail::calcYUV(255, 255, 255, &y, &u, &v); + detail::calcYUV(255, 255, 255, &y, &u, &v); + ASSERT_EQ(255, y); + ASSERT_EQ(128, u); + ASSERT_EQ(128, v); + } +} + +TEST(ColorTest, FullRangeIsBijection) { + using namespace avif::img; + using Converter = avif::img::color::ColorConverter; + for(uint8_t r = 0; r <= 255; ++r) { // Red color + uint16_t y = 0; + uint16_t u = 0; + uint16_t v = 0; + detail::calcYUV(255, 0, 0, &y, &u, &v); + auto [r,g,b] = detail::calcRGB(&y, &u, &v); + ASSERT_EQ(255, r); + ASSERT_EQ(0, g); + ASSERT_EQ(0, b); + } + { // White must have max luma and no chroma. + uint8_t y = 0; + uint8_t u = 0; + uint8_t v = 0; + detail::calcYUV(255, 255, 255, &y, &u, &v); ASSERT_EQ(255, y); ASSERT_EQ(128, u); ASSERT_EQ(128, v);