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

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_BGR_COLORSPACE_TRAITS_H_
0008 #define _KO_BGR_COLORSPACE_TRAITS_H_
0009 
0010 /** 
0011  * Base class for bgr traits, it provides some convenient functions to
0012  * access BGR channels through an explicit API.
0013  */
0014 template<typename _channels_type_>
0015 struct KoBgrTraits : 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 = 2;
0019     static const qint32 green_pos = 1;
0020     static const qint32 blue_pos = 0;
0021     /**
0022      * An BGR pixel
0023      */
0024     struct Pixel {
0025         channels_type blue;
0026         channels_type green;
0027         channels_type red;
0028         channels_type alpha;
0029     };
0030 
0031     /// @return the red component
0032     inline static channels_type red(const quint8 *data)
0033     {
0034         const channels_type *d = parent::nativeArray(data);
0035         return d[red_pos];
0036     }
0037     /// Set the red component
0038     inline static void setRed(quint8 *data, channels_type nv)
0039     {
0040         channels_type* d = parent::nativeArray(data);
0041         d[red_pos] = nv;
0042     }
0043     /// @return the green component
0044     inline static channels_type green(const quint8 *data)
0045     {
0046         const channels_type *d = parent::nativeArray(data);
0047         return d[green_pos];
0048     }
0049     /// Set the green component
0050     inline static void setGreen(quint8* data, channels_type nv) {
0051         channels_type* d = parent::nativeArray(data);
0052         d[green_pos] = nv;
0053     }
0054     /// @return the blue component
0055     inline static channels_type blue(const quint8 *data)
0056     {
0057         const channels_type *d = parent::nativeArray(data);
0058         return d[blue_pos];
0059     }
0060     /// Set the blue component
0061     inline static void setBlue(quint8* data, channels_type nv) {
0062         channels_type* d = parent::nativeArray(data);
0063         d[blue_pos] = nv;
0064     }
0065 };
0066 
0067 
0068 struct KoBgrU8Traits : public KoBgrTraits<quint8> {
0069 };
0070 
0071 struct KoBgrU16Traits : public KoBgrTraits<quint16> {
0072 };
0073 
0074 struct KoBgrU32Traits : public KoBgrTraits<quint32> {
0075 };
0076 
0077 #include <KoConfig.h>
0078 #ifdef HAVE_OPENEXR
0079 #include <half.h>
0080 
0081 struct KoBgrF16Traits : public KoBgrTraits<half> {
0082 };
0083 
0084 #endif
0085 
0086 struct KoBgrF32Traits : public KoBgrTraits<float> {
0087 };
0088 
0089 struct KoBgrF64Traits : public KoBgrTraits<double> {
0090 };
0091 
0092 
0093 #endif