VisionCpp  0.0.1
OP_FloatToF32C3.hpp
Go to the documentation of this file.
1 // This file is part of VisionCPP, a lightweight C++ template library
2 // for computer vision and image processing.
3 //
4 // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved.
5 //
6 // Contact: visioncpp@codeplay.com
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 /// \file OP_FloatToF32C3.hpp
21 /// \brief Converts from uchar to float and float to uchar
22 
23 namespace visioncpp {
24 
25 /// \brief It replicates one channel to 3 channels
27  /// \brief It replicates one channel to 3 channels
28  /// \param t - Float of 1 channel
29  /// \return F32C3 - Float of 3 channels
31  return visioncpp::pixel::F32C3(t, t, t);
32  }
33 };
34 
35 /// \brief It converts float to uchar converting [0.0f, 1.0f] to [0, 255]
37  /// \brief It converts float to uchar converting [0.0f, 1.0f] to [0, 255]
38  /// \param t - float of 1 channel
39  /// \return U8C1 - uchar of 1 channel
41  return visioncpp::pixel::U8C1(static_cast<unsigned char>(t * 255));
42  }
43 };
44 
45 /// \brief It converts uchar to float converting range [0, 255] to [0.0f, 1.0f]
47  /// \brief It converts uchar to float converting range [0, 255] to [0.0f, 1.0f]
48  /// \param t - uchar of 1 channel
49  /// \return float - float of 1 channels
51  return static_cast<float>(t[0]) / 255.0f;
52  }
53 };
54 
55 /// \brief It converts float to uchar
57  /// \brief It converts float to uchar
58  /// \param t - float of 1 channel
59  /// \return F32C3 - uchar of 1 channel
60  unsigned char operator()(float t) {
61  return (static_cast<unsigned char>(t * 255));
62  }
63 };
64 }
Storage< unsigned char, 1 > U8C1
Definition: pixel.hpp:126
Storage< float, 3 > F32C3
Definition: pixel.hpp:116
VisionCpp namespace.
Definition: sycl/device.hpp:24
It replicates one channel to 3 channels.
visioncpp::pixel::F32C3 operator()(float t)
It replicates one channel to 3 channels.
It converts float to uchar converting [0.0f, 1.0f] to [0, 255].
visioncpp::pixel::U8C1 operator()(float t)
It converts float to uchar converting [0.0f, 1.0f] to [0, 255].
It converts float to uchar.
unsigned char operator()(float t)
It converts float to uchar.
It converts uchar to float converting range [0, 255] to [0.0f, 1.0f].
float operator()(visioncpp::pixel::U8C1 t)
It converts uchar to float converting range [0, 255] to [0.0f, 1.0f].