hyperion.ng/test/TestColorTransform.cpp

97 lines
2.4 KiB
C++
Raw Normal View History

// STL includes
2013-08-05 23:49:17 +02:00
#include <iostream>
#include <cmath>
#include <../../libsrc/hyperion/ColorTransform.h>
using namespace hyperion;
2013-08-05 23:49:17 +02:00
int main()
{
{
std::cout << "Testing linear transform" << std::endl;
ColorTransform t;
for (int i = 0; i < 256; ++i)
{
uint8_t input = i;
uint8_t output = t.transform(input);
uint8_t expected = input;
2013-08-05 23:49:17 +02:00
if (output != expected)
{
std::cerr << "ERROR: input (" << (int)input << ") => output (" << (int)output << ") : expected (" << (int) expected << ")" << std::endl;
return 1;
}
else
{
std::cerr << "OK: input (" << (int)input << ") => output (" << (int)output << ")" << std::endl;
}
}
}
2013-08-05 23:49:17 +02:00
{
std::cout << "Testing threshold" << std::endl;
ColorTransform t(.10, 1.0, 0.0, 1.0);
for (int i = 0; i < 256; ++i)
{
uint8_t input = i;
uint8_t output = t.transform(input);
uint8_t expected = ((i/255.0) < t.getThreshold() ? 0 : output);
2013-08-05 23:49:17 +02:00
if (output != expected)
{
std::cerr << "ERROR: input (" << (int)input << ") => output (" << (int)output << ") : expected (" << (int) expected << ")" << std::endl;
return 1;
}
else
{
std::cerr << "OK: input (" << (int)input << ") => output (" << (int)output << ")" << std::endl;
}
}
}
2013-08-05 23:49:17 +02:00
{
std::cout << "Testing blacklevel and whitelevel" << std::endl;
ColorTransform t(0, 1.0, 0.2, 0.8);
for (int i = 0; i < 256; ++i)
{
uint8_t input = i;
uint8_t output = t.transform(input);
uint8_t expected = (uint8_t)(input * (t.getWhitelevel()-t.getBlacklevel()) + 255 * t.getBlacklevel());
2013-08-05 23:49:17 +02:00
if (output != expected)
{
std::cerr << "ERROR: input (" << (int)input << ") => output (" << (int)output << ") : expected (" << (int) expected << ")" << std::endl;
return 1;
}
else
{
std::cerr << "OK: input (" << (int)input << ") => output (" << (int)output << ")" << std::endl;
}
}
}
2013-08-05 23:49:17 +02:00
{
std::cout << "Testing gamma" << std::endl;
ColorTransform t(0, 2.0, 0.0, 1.0);
for (int i = 0; i < 256; ++i)
{
uint8_t input = i;
uint8_t output = t.transform(input);
uint8_t expected = (uint8_t)(255 * std::pow(i / 255.0, 2));
2013-08-05 23:49:17 +02:00
if (output != expected)
{
std::cerr << "ERROR: input (" << (int)input << ") => output (" << (int)output << ") : expected (" << (int) expected << ")" << std::endl;
return 1;
}
else
{
std::cerr << "OK: input (" << (int)input << ") => output (" << (int)output << ")" << std::endl;
}
}
}
2013-08-05 23:49:17 +02:00
return 0;
2013-08-05 23:49:17 +02:00
}