From a3d5a424ddc77c152b0c3e5b9b6cf790109de0db Mon Sep 17 00:00:00 2001 From: lisyarus Date: Mon, 16 May 2022 23:25:34 +0300 Subject: [PATCH] Add sRGB <-> linear conversion for pixmaps --- libs/gfx/include/psemek/gfx/pixmap.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libs/gfx/include/psemek/gfx/pixmap.hpp b/libs/gfx/include/psemek/gfx/pixmap.hpp index 788cb429..1a1e9b56 100644 --- a/libs/gfx/include/psemek/gfx/pixmap.hpp +++ b/libs/gfx/include/psemek/gfx/pixmap.hpp @@ -27,4 +27,18 @@ namespace psemek::gfx pixmap_rgba read_png(io::istream && is); pixmap_monochrome read_png_monochrome(io::istream && is); + template + auto to_srgb(util::array pm, float g = 1.f / 2.2f) + { + for (auto & c : pm) + c = to_srgb(c, g); + return pm; + } + + template + auto to_linear(util::array pm, float g = 1.f / 2.2f) + { + return to_srgb(std::move(pm), 1.f / g); + } + }