File indexing completed on 2024-05-12 15:59:38
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_YCbCr_COLORSPACE_TRAITS_H_ 0008 #define _KO_YCbCr_COLORSPACE_TRAITS_H_ 0009 0010 /** 0011 * YCbCr traits, it provides some convenient functions to 0012 * access YCbCr channels through an explicit API. 0013 */ 0014 template<typename _channels_type_> 0015 struct KoYCbCrTraits : public KoColorSpaceTrait<_channels_type_, 4, 3> { 0016 0017 typedef _channels_type_ channels_type; 0018 typedef KoColorSpaceTrait<_channels_type_, 4, 3> parent; 0019 0020 static const qint32 Y_pos = 0; 0021 static const qint32 Cb_pos = 1; 0022 static const qint32 Cr_pos = 2; 0023 0024 /** 0025 * An YCbCr pixel 0026 */ 0027 struct Pixel { 0028 channels_type Y; 0029 channels_type Cb; 0030 channels_type Cr; 0031 channels_type alpha; 0032 }; 0033 0034 /// @return the Y component 0035 inline static channels_type Y(quint8* data) { 0036 channels_type* d = parent::nativeArray(data); 0037 return d[Y_pos]; 0038 } 0039 /// Set the Y component 0040 inline static void setY(quint8* data, channels_type nv) { 0041 channels_type* d = parent::nativeArray(data); 0042 d[Y_pos] = nv; 0043 } 0044 /// @return the Cb component 0045 inline static channels_type Cb(quint8* data) { 0046 channels_type* d = parent::nativeArray(data); 0047 return d[Cb_pos]; 0048 } 0049 /// Set the Cb component 0050 inline static void setCb(quint8* data, channels_type nv) { 0051 channels_type* d = parent::nativeArray(data); 0052 d[Cb_pos] = nv; 0053 } 0054 /// @return the Cr component 0055 inline static channels_type Cr(quint8* data) { 0056 channels_type* d = parent::nativeArray(data); 0057 return d[Cr_pos]; 0058 } 0059 /// Set the Cr component 0060 inline static void setCr(quint8* data, channels_type nv) { 0061 channels_type* d = parent::nativeArray(data); 0062 d[Cr_pos] = nv; 0063 } 0064 }; 0065 0066 struct KoYCbCrU8Traits : public KoYCbCrTraits<quint8> { 0067 }; 0068 0069 struct KoYCbCrU16Traits : public KoYCbCrTraits<quint16> { 0070 }; 0071 0072 #include <KoConfig.h> 0073 #ifdef HAVE_OPENEXR 0074 #include <half.h> 0075 0076 struct KoYCbCrF16Traits : public KoYCbCrTraits<half> { 0077 }; 0078 0079 #endif 0080 0081 struct KoYCbCrF32Traits : public KoYCbCrTraits<float> { 0082 }; 0083 0084 struct KoYCbCrF64Traits : public KoYCbCrTraits<double> { 0085 }; 0086 0087 0088 #endif