File indexing completed on 2024-05-12 15:59:37
0001 /* 0002 * SPDX-FileCopyrightText: 2006-2007 Cyrille Berger <cberger@cberger.net> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #ifndef _KO_RGB_COLORSPACE_TRAITS_H_ 0008 #define _KO_RGB_COLORSPACE_TRAITS_H_ 0009 0010 /** 0011 * Base class for rgb traits, it provides some convenient functions to 0012 * access RGB channels through an explicit API. 0013 */ 0014 template<typename _channels_type_> 0015 struct KoRgbTraits : public KoColorSpaceTrait<_channels_type_, 4, 3> { 0016 typedef _channels_type_ channels_type; 0017 typedef KoColorSpaceTrait<_channels_type_, 4, 3> parent; 0018 static const qint32 red_pos = 0; 0019 static const qint32 green_pos = 1; 0020 static const qint32 blue_pos = 2; 0021 /** 0022 * An RGB pixel 0023 */ 0024 struct Pixel { 0025 channels_type red; 0026 channels_type green; 0027 channels_type blue; 0028 channels_type alpha; 0029 }; 0030 0031 /// @return the red component 0032 inline static channels_type red(quint8* data) { 0033 channels_type* d = parent::nativeArray(data); 0034 return d[red_pos]; 0035 } 0036 /// Set the red component 0037 inline static void setRed(quint8* data, channels_type nv) { 0038 channels_type* d = parent::nativeArray(data); 0039 d[red_pos] = nv; 0040 } 0041 /// @return the green component 0042 inline static channels_type green(quint8* data) { 0043 channels_type* d = parent::nativeArray(data); 0044 return d[green_pos]; 0045 } 0046 /// Set the green component 0047 inline static void setGreen(quint8* data, channels_type nv) { 0048 channels_type* d = parent::nativeArray(data); 0049 d[green_pos] = nv; 0050 } 0051 /// @return the blue component 0052 inline static channels_type blue(quint8* data) { 0053 channels_type* d = parent::nativeArray(data); 0054 return d[blue_pos]; 0055 } 0056 /// Set the blue component 0057 inline static void setBlue(quint8* data, channels_type nv) { 0058 channels_type* d = parent::nativeArray(data); 0059 d[blue_pos] = nv; 0060 } 0061 }; 0062 0063 struct KoRgbU8Traits : public KoRgbTraits<quint8> { 0064 }; 0065 0066 struct KoRgbU16Traits : public KoRgbTraits<quint16> { 0067 }; 0068 0069 struct KoRgbU32Traits : public KoRgbTraits<quint32> { 0070 }; 0071 0072 0073 #include <KoConfig.h> 0074 #ifdef HAVE_OPENEXR 0075 #include <half.h> 0076 0077 struct KoRgbF16Traits : public KoRgbTraits<half> { 0078 }; 0079 0080 #endif 0081 0082 struct KoRgbF32Traits : public KoRgbTraits<float> { 0083 }; 0084 0085 struct KoRgbF64Traits : public KoRgbTraits<double> { 0086 }; 0087 0088 0089 #endif