1 /*
2  *  Copyright (c) 2006-2007 Cyrille Berger <cberger@cberger.net>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18 */
19 
20 #ifndef _KO_YCbCr_COLORSPACE_TRAITS_H_
21 #define _KO_YCbCr_COLORSPACE_TRAITS_H_
22 
23 /**
24  * YCbCr traits, it provides some convenient functions to
25  * access YCbCr  channels through an explicit API.
26  */
27 template<typename _channels_type_>
28 struct KoYCbCrTraits : public KoColorSpaceTrait<_channels_type_, 4, 3> {
29 
30     typedef _channels_type_ channels_type;
31     typedef KoColorSpaceTrait<_channels_type_, 4, 3> parent;
32 
33     static const qint32 Y_pos = 0;
34     static const qint32 Cb_pos = 1;
35     static const qint32 Cr_pos = 2;
36 
37     /**
38      * An YCbCr pixel
39      */
40     struct Pixel {
41         channels_type Y;
42         channels_type Cb;
43         channels_type Cr;
44         channels_type alpha;
45     };
46 
47     /// @return the Y component
YKoYCbCrTraits48     inline static channels_type Y(quint8* data) {
49         channels_type* d = parent::nativeArray(data);
50         return d[Y_pos];
51     }
52     /// Set the Y component
setYKoYCbCrTraits53     inline static void setY(quint8* data, channels_type nv) {
54         channels_type* d = parent::nativeArray(data);
55         d[Y_pos] = nv;
56     }
57     /// @return the Cb component
CbKoYCbCrTraits58     inline static channels_type Cb(quint8* data) {
59         channels_type* d = parent::nativeArray(data);
60         return d[Cb_pos];
61     }
62     /// Set the Cb component
setCbKoYCbCrTraits63     inline static void setCb(quint8* data, channels_type nv) {
64         channels_type* d = parent::nativeArray(data);
65         d[Cb_pos] = nv;
66     }
67     /// @return the Cr component
CrKoYCbCrTraits68     inline static channels_type Cr(quint8* data) {
69         channels_type* d = parent::nativeArray(data);
70         return d[Cr_pos];
71     }
72     /// Set the Cr component
setCrKoYCbCrTraits73     inline static void setCr(quint8* data, channels_type nv) {
74         channels_type* d = parent::nativeArray(data);
75         d[Cr_pos] = nv;
76     }
77 };
78 
79 struct KoYCbCrU8Traits : public KoYCbCrTraits<quint8> {
80 };
81 
82 struct KoYCbCrU16Traits : public KoYCbCrTraits<quint16> {
83 };
84 
85 #include <KoConfig.h>
86 #ifdef HAVE_OPENEXR
87 #include <half.h>
88 
89 struct KoYCbCrF16Traits : public KoYCbCrTraits<half> {
90 };
91 
92 #endif
93 
94 struct KoYCbCrF32Traits : public KoYCbCrTraits<float> {
95 };
96 
97 struct KoYCbCrF64Traits : public KoYCbCrTraits<double> {
98 };
99 
100 
101 #endif
102