/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * Copyright 2010-2017 Danny Robson */ #pragma once #include "coord.hpp" #include namespace cruft { /// An abstract colour POD type componsed of S components of type T. /// /// Not to be used directly, instead the use of derived types is required. /// This exists purely to simplify generic colour code. template < size_t S, typename T, typename SelfT > struct colour : coord::base { using coord::base::base; template auto cast (void) const { ::cruft::revalue_t ret; std::transform (std::begin (*this), std::end (*this), std::begin (ret), renormalise); return ret; } }; template struct cruft::coord::store<1,T,srgba<1,T>> { union { struct { T r; }; T data[1]; }; }; template struct cruft::coord::store<2,T,srgba<2,T>> { union { struct { T r, g; }; T data[2]; }; }; template struct cruft::coord::store<3,T,srgba<3,T>> { union { struct { T r, g, b; }; T data[3]; }; }; template struct cruft::coord::store<4,T,srgba<4,T>> { union { struct { T r, g, b, a; }; T data[4]; }; }; template struct srgba : colour> { using colour>::colour; }; template using srgba1 = srgba<1,T>; using srgba1f = srgba1; using srgba2f = srgba<2,float>; using srgba3f = srgba<3,float>; using srgba4f = srgba<4,float>; using srgba3u = srgba<3,uint8_t>; using srgba4u = srgba<4,uint8_t>; srgba3f scale_luminance (srgba3f, float factor); srgba4f scale_luminance (srgba4f, float factor); template struct hsva : colour> {}; template struct redim_type< srgba > { template using type = srgba; }; template struct revalue_type> { template using type = srgba; }; template struct is_colour : public std::false_type {}; template < size_t S, typename T, template < size_t, typename > typename ColourT > struct is_colour> :std::conditional_t< std::is_base_of_v< colour>, ColourT >, std::true_type, std::false_type > {}; template constexpr auto is_colour_v = is_colour::value; }