OTB  6.7.0
Orfeo Toolbox
otbRGBAPixelConverter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 
22 #ifndef otbRGBAPixelConverter_hxx
23 #define otbRGBAPixelConverter_hxx
24 
25 #include "otbRGBAPixelConverter.h"
26 
27 namespace otb
28 {
29 
30 //Base
31 template <class TInternalInputPixelType, class TOutputPixelType>
32 typename RGBAPixelConverter<TInternalInputPixelType,
33  TOutputPixelType>
34 ::OutputPixelType
35 RGBAPixelConverter<TInternalInputPixelType,
36  TOutputPixelType>
37 ::Convert(InputPixelType input)
38 {
39  double result;
40 
41  result = (
42  ( 2125.0 * static_cast<double>(input[0]) +
43  7154.0 * static_cast<double>(input[1]) +
44  0721.0 * static_cast<double>(input[2])) / 10000.0); //alpha not supported yet
45 
46  return (static_cast<OutputPixelType>(result));
47 }
48 
49 //RGBA to RGBA
50 template <class TInternalInputPixelType, class TInternalOutputPixelType>
51 typename RGBAPixelConverter<TInternalInputPixelType,
53 ::OutputPixelType
54 RGBAPixelConverter<TInternalInputPixelType,
56 ::Convert(InputPixelType input)
57 {
58  OutputPixelType result;
59 
60  result[0] = static_cast<TInternalOutputPixelType>(input[0]);
61  result[1] = static_cast<TInternalOutputPixelType>(input[1]);
62  result[2] = static_cast<TInternalOutputPixelType>(input[2]);
63  result[3] = static_cast<TInternalOutputPixelType>(input[3]);
64 
65  return result;
66 }
67 
68 //RGBA to RGB
69 template <class TInternalInputPixelType, class TInternalOutputPixelType>
70 typename RGBAPixelConverter<TInternalInputPixelType,
72 ::OutputPixelType
73 RGBAPixelConverter<TInternalInputPixelType,
75 ::Convert(InputPixelType input)
76 {
77  OutputPixelType result;
78 
79  result[0] = static_cast<TInternalOutputPixelType>(input[0]);
80  result[1] = static_cast<TInternalOutputPixelType>(input[1]);
81  result[2] = static_cast<TInternalOutputPixelType>(input[2]);
82 
83  return result;
84 }
85 
86 
87 } // end namespace otb
88 
89 
90 #endif
Convert an itk::RGBApixel<InternalType> into another pixel type.