Skip to content

Commit

Permalink
Merge pull request #7 from brisklib/colorspace-tests
Browse files Browse the repository at this point in the history
Color space tests
  • Loading branch information
dancazarin authored Dec 3, 2024
2 parents 85b94e7 + 6357c4e commit 4aa943b
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 3 deletions.
68 changes: 68 additions & 0 deletions src/graphics/ColorSpace_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Catch2Utils.hpp"
#include <brisk/graphics/ColorSpace.hpp>
#include <brisk/core/Reflection.hpp>
#include "VisualTests.hpp"
#include <random>

namespace Catch {
Expand Down Expand Up @@ -125,4 +126,71 @@ TEST_CASE("ColorSpaces") {
Catch::Matchers::ColorWithinMatcher(ColorSRGBGamma{ 0.79200876, 0.52818274, 0 }));
}

TEST_CASE("Colorspace Gradients") {
visualTest("oklch-radient", { 512, 512 }, [&](RC<Image> image) {
auto wr = image->mapWrite<ImageFormat::RGBA_U8Gamma>();
for (size_t y = 0; y < wr.height(); ++y) {
auto line = wr.line(y);
for (size_t x = 0; x < wr.width(); ++x) {
ColorF color = convertColorSpace<ColorSpace::sRGBLinear>(
ColorOKLCH{
100.f * (1.f - float(y) / (wr.height() - 1)),
10.f,
360.f * (float(x) / (wr.width() - 1) - 0.5f),
},
ColorConversionMode::Nearest);
colorToPixel(line[x], color);
}
}
});
visualTest("cielab-radient", { 512, 512 }, [&](RC<Image> image) {
auto wr = image->mapWrite<ImageFormat::RGBA_U8Gamma>();
for (size_t y = 0; y < wr.height(); ++y) {
auto line = wr.line(y);
for (size_t x = 0; x < wr.width(); ++x) {
ColorF color = convertColorSpace<ColorSpace::sRGBLinear>(
ColorCIELAB{
50.f,
200.f * (float(x) / (wr.width() - 1) - 0.5f),
200.f * (float(y) / (wr.height() - 1) - 0.5f),
},
ColorConversionMode::Nearest);
colorToPixel(line[x], color);
}
}
});
visualTest("lms-radient0", { 512, 512 }, [&](RC<Image> image) {
auto wr = image->mapWrite<ImageFormat::RGBA_U8Gamma>();
for (size_t y = 0; y < wr.height(); ++y) {
auto line = wr.line(y);
for (size_t x = 0; x < wr.width(); ++x) {
ColorF color = convertColorSpace<ColorSpace::sRGBLinear>(
ColorLMS{
0.f,
float(x) / (wr.width() - 1),
float(y) / (wr.height() - 1),
},
ColorConversionMode::Nearest);
colorToPixel(line[x], color);
}
}
});
visualTest("lms-radient1", { 512, 512 }, [&](RC<Image> image) {
auto wr = image->mapWrite<ImageFormat::RGBA_U8Gamma>();
for (size_t y = 0; y < wr.height(); ++y) {
auto line = wr.line(y);
for (size_t x = 0; x < wr.width(); ++x) {
ColorF color = convertColorSpace<ColorSpace::sRGBLinear>(
ColorLMS{
1.f,
float(x) / (wr.width() - 1),
float(y) / (wr.height() - 1),
},
ColorConversionMode::Nearest);
colorToPixel(line[x], color);
}
}
});
}

} // namespace Brisk
14 changes: 11 additions & 3 deletions src/graphics/Renderer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,18 @@ TEST_CASE("Atlas overflow", "[gpu]") {
template <typename Fn>
static void blendingTest(std::string s, Size size, Fn&& fn) {
linearColor = false;
renderTest(s + "_sRGB", size, fn);
SECTION("sRGB") {
renderTest(s + "_sRGB", size, fn, Palette::transparent, 0.06f);
}
linearColor = true;
renderTest(s + "_Linear", size, fn);
SECTION("Linear") {
renderTest(s + "_Linear", size, fn, Palette::transparent, 0.06f);
}
linearColor = false;
}

TEST_CASE("Blending", "[gpu]") {
constexpr Size canvasSize{ 1000, 1000 };
constexpr Size canvasSize{ 1200, 1200 };
constexpr int rowHeight = 100;
blendingTest("blending1", canvasSize, [&](RenderContext& context) {
RawCanvas canvas(context);
Expand Down Expand Up @@ -385,6 +389,10 @@ TEST_CASE("Blending", "[gpu]") {
bands(5, 50, Palette::red, Palette::green);
gradient(6, Palette::red, Palette::transparent, Palette::green);
gradient(7, Palette::red, Palette::red, Palette::green);
bands(8, 10, Palette::cyan, Palette::red);
bands(9, 50, Palette::cyan, Palette::red);
gradient(10, Palette::cyan, Palette::transparent, Palette::red);
gradient(11, Palette::cyan, Palette::cyan, Palette::red);
});
}

Expand Down
Binary file modified src/graphics/testdata/blending1_Linear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/graphics/testdata/blending1_sRGB.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/graphics/testdata/cielab-radient.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/graphics/testdata/lms-radient0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/graphics/testdata/lms-radient1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/graphics/testdata/oklch-radient.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4aa943b

Please sign in to comment.