mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
ColorTransform functions added to repo
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
# Needed for testing non-public components
|
||||
include_directories(../libsrc)
|
||||
|
||||
# Add the simple test executable 'TestSpi'
|
||||
add_executable(TestSpi
|
||||
@@ -25,15 +27,19 @@ add_executable(TestRgbImage
|
||||
target_link_libraries(TestRgbImage
|
||||
hyperion-utils)
|
||||
|
||||
add_executable(TestColorTransform
|
||||
TestColorTransform.cpp)
|
||||
target_link_libraries(TestColorTransform
|
||||
hyperion)
|
||||
|
||||
# Find the libPNG
|
||||
find_package(PNG REQUIRED QUIET)
|
||||
|
||||
# Add additional includes dirs
|
||||
include_directories(${PNG_INCLUDE_DIR})
|
||||
|
||||
#if(PNG_FOUND)
|
||||
# Add additional includes dirs
|
||||
include_directories(${PNG_INCLUDE_DIR})
|
||||
|
||||
add_executable(TestHyperionPng
|
||||
add_executable(TestHyperionPng
|
||||
TestHyperionPng.cpp)
|
||||
|
||||
target_link_libraries(TestHyperionPng
|
||||
|
93
test/TestColorTransform.cpp
Normal file
93
test/TestColorTransform.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
#include <hyperion/ColorTransform.h>
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
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());
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
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));
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user