libcruft-util/test/colour.cpp

31 lines
936 B
C++
Raw Normal View History

#include <cruft/util/colour.hpp>
2015-04-13 18:06:08 +10:00
#include <cruft/util/tap.hpp>
2016-07-28 13:31:52 +10:00
int
main (int, char**)
{
cruft::TAP::logger tap;
2015-04-13 16:45:56 +10:00
2015-04-09 20:45:55 +10:00
// Check casting works between intergral and floating formats
{
cruft::srgba<4,float> f {1.f};
cruft::srgba<4,uint8_t> u {255};
2015-04-13 16:45:56 +10:00
tap.expect_eq (f.cast<uint8_t> (), u, "cast float to u8");
tap.expect_eq (u.cast<float> (), f, "cast u8 to float");
2015-04-09 20:45:55 +10:00
}
2015-04-09 20:46:55 +10:00
{
cruft::srgba3f white {1, 1, 1};
cruft::srgba3f black {0, 0, 0};
cruft::srgba3f percent_50 { 0.735359f, 0.735356f, 0.735357f };
tap.expect (max (scale_luminance (white, 1.f) - white) < 1e-5f, "unit luminance scaling for white");
tap.expect (max (scale_luminance (white, 0.f) - black) < 1e-5f, "zero luminance scaling for white");
tap.expect (max (scale_luminance (white, .5f) - percent_50) < 1e-5f, "half luminance scaling for white");
}
return tap.status ();
}