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_XYZ_COLORSPACE_TRAITS_H_
0008 #define _KO_XYZ_COLORSPACE_TRAITS_H_
0009 
0010 
0011 
0012 /** 
0013  * Base class for Xyz traits, it provides some convenient functions to
0014  * access Xyz channels through an explicit API.
0015  */
0016 template<typename _channels_type_>
0017 struct KoXyzTraits : public KoColorSpaceTrait<_channels_type_, 4, 3> {
0018     
0019     typedef _channels_type_ channels_type;
0020     typedef KoColorSpaceTrait<_channels_type_, 4, 3> parent;
0021     
0022     static const qint32 x_pos = 0;
0023     static const qint32 y_pos = 1;
0024     static const qint32 z_pos = 2;
0025     
0026     /**
0027      * An Xyz pixel
0028      */
0029     struct Pixel {
0030         channels_type x;
0031         channels_type y;
0032         channels_type z;
0033         channels_type alpha;
0034     };
0035 
0036     /// @return the x component
0037     inline static channels_type x(quint8* data) {
0038         channels_type* d = parent::nativeArray(data);
0039         return d[x_pos];
0040     }
0041     /// Set the x component
0042     inline static void setX(quint8* data, channels_type nv) {
0043         channels_type* d = parent::nativeArray(data);
0044         d[x_pos] = nv;
0045     }
0046     /// @return the y component
0047     inline static channels_type y(quint8* data) {
0048         channels_type* d = parent::nativeArray(data);
0049         return d[y_pos];
0050     }
0051     /// Set the y component
0052     inline static void setY(quint8* data, channels_type nv) {
0053         channels_type* d = parent::nativeArray(data);
0054         d[y_pos] = nv;
0055     }
0056     /// @return the z component
0057     inline static channels_type z(quint8* data) {
0058         channels_type* d = parent::nativeArray(data);
0059         return d[z_pos];
0060     }
0061     /// Set the z component
0062     inline static void setZ(quint8* data, channels_type nv) {
0063         channels_type* d = parent::nativeArray(data);
0064         d[z_pos] = nv;
0065     }
0066 };
0067 
0068 
0069 struct KoXyzU8Traits : public KoXyzTraits<quint8> {
0070 };
0071 
0072 struct KoXyzU16Traits : public KoXyzTraits<quint16> {
0073 };
0074 
0075 #include <KoConfig.h>
0076 #ifdef HAVE_OPENEXR
0077 #include <half.h>
0078 
0079 struct KoXyzF16Traits : public KoXyzTraits<half> {
0080 };
0081 
0082 #endif
0083 
0084 struct KoXyzF32Traits : public KoXyzTraits<float> {
0085 };
0086 
0087 struct KoXyzF64Traits : public KoXyzTraits<double> {
0088 };
0089 
0090 #endif