File indexing completed on 2024-05-12 15:59:36

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_GRAY_COLORSPACE_TRAITS_H_
0008 #define _KO_GRAY_COLORSPACE_TRAITS_H_
0009 
0010 /** 
0011  * Base class for graya traits, it provides some convenient functions to
0012  * access gray channels through an explicit API.
0013  */
0014 template<typename _channels_type_>
0015 struct KoGrayTraits : public KoColorSpaceTrait<_channels_type_, 2, 1> {
0016     
0017     typedef _channels_type_ channels_type;
0018     typedef KoColorSpaceTrait<_channels_type_, 2, 1> parent;
0019     
0020     static const qint32 gray_pos = 0;
0021     
0022     /**
0023      * An grayscale pixel
0024      */
0025     struct Pixel {
0026         channels_type gray;
0027         channels_type alpha;
0028     };
0029 
0030     /// @return the gray component
0031     inline static channels_type gray(const quint8 *data)
0032     {
0033         const channels_type *d = parent::nativeArray(data);
0034         return d[gray_pos];
0035     }
0036 
0037     /// Set the gray component
0038     inline static void setGray(quint8* data, channels_type nv) {
0039         channels_type* d = parent::nativeArray(data);
0040         d[gray_pos] = nv;
0041     }
0042 };
0043 
0044 
0045 struct KoGrayU8Traits : public KoGrayTraits<quint8> {
0046 };
0047 
0048 struct KoGrayU16Traits : public KoGrayTraits<quint16> {
0049 };
0050 
0051 struct KoGrayU32Traits : public KoGrayTraits<quint32> {
0052 };
0053 
0054 
0055 #include <KoConfig.h>
0056 #ifdef HAVE_OPENEXR
0057 #include <half.h>
0058 
0059 struct KoGrayF16Traits : public KoGrayTraits<half> {
0060 };
0061 
0062 #endif
0063 
0064 struct KoGrayF32Traits : public KoGrayTraits<float> {
0065 };
0066 
0067 struct KoGrayF64Traits : public KoGrayTraits<double> {
0068 };
0069 
0070 #endif