aimsdata  5.1.2
Neuroimaging data handling
converter_rgb.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 #ifndef AIMS_UTILITY_CONVERTER_RGB_H
35 #define AIMS_UTILITY_CONVERTER_RGB_H
36 
38 #include <aims/rgb/rgb.h>
39 
40 namespace carto
41 {
42 
43  template <class INP>
44  class RawConverter<INP, AimsRGB>
45  {
46  public :
47  void convert( const INP &in, AimsRGB & out ) const;
48  };
49 
50  template<class INP>
51  inline void
52  RawConverter<INP,AimsRGB>::convert( const INP &in, AimsRGB & out ) const
53  {
54  out = AimsRGB( (::byte) in, (::byte) in, (::byte) in );
55  }
56 
57  template <class INP>
58  class RawConverter<INP, AimsRGBA>
59  {
60  public :
61  void convert( const INP &in, AimsRGBA & out ) const;
62  };
63 
64  template<class INP>
65  inline void
66  RawConverter<INP,AimsRGBA>::convert( const INP &in, AimsRGBA & out ) const
67  {
68  out = AimsRGBA( (::byte) in, (::byte) in, (::byte) in, 255 );
69  }
70 
71  template <class OUTP>
72  class RawConverter<AimsRGB, OUTP>
73  {
74  public :
75  void convert( const AimsRGB &in, OUTP & out ) const;
76  };
77 
78  template<class OUTP>
79  inline void
80  RawConverter<AimsRGB,OUTP>::convert( const AimsRGB &in, OUTP & out ) const
81  {
82  out = (OUTP) ( sqrt( ( (double) in.red() ) * in.red()
83  + ( (double) in.green() ) * in.green()
84  + ( (double) in.blue() ) * in.blue() ) );
85  }
86 
87  template <class OUTP>
88  class RawConverter<AimsRGBA, OUTP>
89  {
90  public :
91  void convert( const AimsRGBA &in, OUTP & out ) const;
92  };
93 
94  template<class OUTP>
95  inline void
96  RawConverter<AimsRGBA,OUTP>::convert( const AimsRGBA &in, OUTP & out ) const
97  {
98  out = (OUTP) ( sqrt( ( (double) in.red() ) * in.red()
99  + ( (double) in.green() ) * in.green()
100  + ( (double) in.blue() ) * in.blue() ) );
101  }
102 
103  template <>
105  {
106  public :
107  void convert( const AimsRGB &in, AimsRGBA & out ) const
108  {
109  out = in;
110  }
111  };
112 
113 
114  template <>
116  {
117  public :
118  void convert( const AimsRGBA &in, AimsRGB & out ) const
119  {
120  out = in;
121  }
122  };
123 
124 }
125 
126 //--- Vector/RGB conversion --------------------------------------------------
127 #include <aims/vector/vector.h>
128 #include <limits>
129 
130 namespace carto {
131 
132  template <typename T, int D>
134  {
135  public:
136  void convert( const AimsVector<T,D> &in, AimsRGB &out ) const
137  {
138  for( uint8_t i=0; i<3 && i<in.size(); ++i )
139  out[i] = in[i];
140  }
141  };
142 
143 
144  template <typename T, int D>
146  {
147  public:
148  void convert( const AimsRGB &in, AimsVector<T,D> &out ) const
149  {
150  for( uint8_t i=0; i<3 && i<out.size(); ++i )
151  out[i] = in[i];
152  }
153  };
154 
155 
156  template <typename T, int D>
158  {
159  public:
160  void convert( const AimsVector<T,D> &in, AimsRGBA &out ) const
161  {
162  for( uint8_t i=0; i<4 && i<in.size(); ++i )
163  out[i] = in[i];
164  }
165  };
166 
167 
168  template <typename T, int D>
170  {
171  public:
172  void convert( const AimsRGBA &in, AimsVector<T,D> &out ) const
173  {
174  for( uint8_t i=0; i<4 && i<out.size(); ++i )
175  out[i] = in[i];
176  }
177  };
178 
179 }
180 
181 
182 #endif
183 
184 
int size() const
void convert(const AimsRGBA &in, AimsRGB &out) const
void convert(const AimsRGBA &in, AimsVector< T, D > &out) const
void convert(const AimsRGB &in, AimsRGBA &out) const
void convert(const AimsRGB &in, AimsVector< T, D > &out) const
void convert(const AimsVector< T, D > &in, AimsRGBA &out) const
void convert(const AimsVector< T, D > &in, AimsRGB &out) const
void convert(const INP &in, OUTP &out) const
const uint8_t & green() const
const uint8_t & blue() const
const uint8_t & red() const
const uint8_t & red() const
const uint8_t & blue() const
const uint8_t & green() const
carto::VoxelRGBA AimsRGBA
Definition: rgb.h:44
carto::VoxelRGB AimsRGB
Definition: rgb.h:43