OTB  9.0.0
Orfeo Toolbox
otbRGBAPixelConverter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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>
34 {
35  double result;
36 
37  result = ((2125.0 * static_cast<double>(input[0]) + 7154.0 * static_cast<double>(input[1]) + 0721.0 * static_cast<double>(input[2])) /
38  10000.0); // alpha not supported yet
39 
40  return (static_cast<OutputPixelType>(result));
41 }
42 
43 // RGBA to RGBA
44 template <class TInternalInputPixelType, class TInternalOutputPixelType>
47 {
48  OutputPixelType result;
49 
50  result[0] = static_cast<TInternalOutputPixelType>(input[0]);
51  result[1] = static_cast<TInternalOutputPixelType>(input[1]);
52  result[2] = static_cast<TInternalOutputPixelType>(input[2]);
53  result[3] = static_cast<TInternalOutputPixelType>(input[3]);
54 
55  return result;
56 }
57 
58 // RGBA to RGB
59 template <class TInternalInputPixelType, class TInternalOutputPixelType>
60 typename RGBAPixelConverter<TInternalInputPixelType, typename itk::RGBPixel<TInternalOutputPixelType>>::OutputPixelType
61 RGBAPixelConverter<TInternalInputPixelType, typename itk::RGBPixel<TInternalOutputPixelType>>::Convert(InputPixelType input)
62 {
63  OutputPixelType result;
64 
65  result[0] = static_cast<TInternalOutputPixelType>(input[0]);
66  result[1] = static_cast<TInternalOutputPixelType>(input[1]);
67  result[2] = static_cast<TInternalOutputPixelType>(input[2]);
68 
69  return result;
70 }
71 
72 
73 } // end namespace otb
74 
75 
76 #endif
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::RGBAPixelConverter
Convert an itk::RGBApixel<InternalType> into another pixel type.
Definition: otbRGBAPixelConverter.h:46
otb::RGBAPixelConverter::InputPixelType
itk::RGBAPixel< TInternalInputPixelType > InputPixelType
Definition: otbRGBAPixelConverter.h:59
otbRGBAPixelConverter.h
otb::RGBAPixelConverter::Convert
OutputPixelType Convert(InputPixelType input)
Definition: otbRGBAPixelConverter.hxx:33
otb::RGBAPixelConverter::OutputPixelType
TOutputPixelType OutputPixelType
Definition: otbRGBAPixelConverter.h:62