File indexing completed on 2024-05-12 15:59:33
0001 /* 0002 * SPDX-FileCopyrightText: 2017 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef KOCOLORMODELSTANDARDIDSUTILS_H 0008 #define KOCOLORMODELSTANDARDIDSUTILS_H 0009 0010 #include <KoColorModelStandardIds.h> 0011 0012 #include <KoConfig.h> 0013 #ifdef HAVE_OPENEXR 0014 #include <half.h> 0015 #endif 0016 0017 0018 template <typename channel_type> 0019 KoID colorDepthIdForChannelType(); 0020 0021 template<> inline KoID colorDepthIdForChannelType<quint8>() { 0022 return Integer8BitsColorDepthID; 0023 } 0024 0025 template<> inline KoID colorDepthIdForChannelType<quint16>() { 0026 return Integer16BitsColorDepthID; 0027 } 0028 0029 #ifdef HAVE_OPENEXR 0030 template<> inline KoID colorDepthIdForChannelType<half>() { 0031 return Float16BitsColorDepthID; 0032 } 0033 #endif 0034 0035 template<> inline KoID colorDepthIdForChannelType<float>() { 0036 return Float32BitsColorDepthID; 0037 } 0038 0039 template<> inline KoID colorDepthIdForChannelType<double>() { 0040 return Float64BitsColorDepthID; 0041 } 0042 0043 template <template <typename T> class Functor, 0044 typename... Args, 0045 typename Result = decltype(std::declval<Functor<quint8>>()(std::declval<Args>()...))> 0046 Result channelTypeForColorDepthId(const KoID &depthId, Args... args) 0047 { 0048 if (depthId == Integer8BitsColorDepthID) { 0049 return Functor<quint8>()(args...); 0050 } else if (depthId == Integer16BitsColorDepthID) { 0051 return Functor<quint16>()(args...); 0052 #ifdef HAVE_OPENEXR 0053 } else if (depthId == Float16BitsColorDepthID) { 0054 return Functor<half>()(args...); 0055 #endif 0056 } else if (depthId == Float32BitsColorDepthID) { 0057 return Functor<float>()(args...); 0058 } 0059 0060 throw std::runtime_error("Invalid bit depth!"); 0061 } 0062 0063 0064 #endif // KOCOLORMODELSTANDARDIDSUTILS_H 0065