/* * Copyright (C) 2021 Christopher J. Howard * * This file is part of Antkeeper source code. * * Antkeeper source code is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Antkeeper source code is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Antkeeper source code. If not, see . */ #ifndef ANTKEEPER_ACES_HPP #define ANTKEEPER_ACES_HPP #include "math/vector-type.hpp" /** * Transforms a linear sRGB color into the ACEScg colorspace, using the Bradford chromatic adaption transform. * * @param x Linear sRGB color. * @return Linear ACEScg color. * * @see https://www.colour-science.org/apps/ */ template math::vector srgb_to_acescg(const math::vector& x) { static const math::matrix matrix {{ {0.6131324224, 0.0701243808, 0.0205876575}, {0.3395380158, 0.9163940113, 0.1095745716}, {0.0474166960, 0.0134515240, 0.8697854040} }}; return matrix * x; } /** * Transforms an ACEScg color into the linear sRGB colorspace, using the Bradford chromatic adaption transform. * * @param x Linear ACEScg color. * @param return Linear sRGB color. * * @see https://www.colour-science.org/apps/ */ template math::vector acescg_to_srgb(const math::vector& x) { static const math::matrix matrix {{ { 1.7048586763, -0.1300768242, -0.0239640729}, {-0.6217160219, 1.1407357748, -0.1289755083}, {-0.0832993717, -0.0105598017, 1.1530140189} }}; return matrix * x; } /** * Calculates the luminance of an ACEScg color. * * @param x Linear ACEScg color. * @param return Luminance of @p x. */ template T acescg_to_luminance(const math::vector& x) { static const math::vector luma = {0.2722287168, 0.6740817658, 0.0536895174}; return math::dot(x, luma); } #endif // ANTKEEPER_ACES_HPP