Visual Servoing Platform  version 3.5.1 under development (2022-11-29)
vpEndian.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Image handling.
33  *
34  * Authors:
35  * Eric Marchand
36  *
37  *****************************************************************************/
38 
44 #ifndef vpEndian_h
45 #define vpEndian_h
46 
47 // Visual Studio 2010 or previous is missing inttypes.h
48 #if defined(_MSC_VER) && (_MSC_VER < 1700)
49 typedef unsigned short uint16_t;
50 #else
51 #include <inttypes.h>
52 #endif
53 #include <stdint.h> //for uint32_t related types ; works also with >= VS2010 / _MSC_VER >= 1600
54 #include <visp3/core/vpConfig.h>
55 
56 // Detect endianness of the host machine
57 // Reference: http://www.boost.org/doc/libs/1_36_0/boost/detail/endian.hpp
58 #if defined(__GLIBC__) || (defined(__GNUC__) && !defined(__llvm__) && !defined(__MINGW32__) && \
59  !defined(__FreeBSD__) && defined(__BYTE_ORDER__))
60 #include <endian.h>
61 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
62 #define VISP_LITTLE_ENDIAN
63 #elif (__BYTE_ORDER == __BIG_ENDIAN)
64 #define VISP_BIG_ENDIAN
65 #elif (__BYTE_ORDER == __PDP_ENDIAN)
66 // Currently not supported when reading / writing binary file
67 #define VISP_PDP_ENDIAN
68 //#error PDP endian is not supported. //Uncomment if needed/happens
69 #else
70 #error Unknown machine endianness detected.
71 #endif
72 #elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN) || defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
73 #define VISP_BIG_ENDIAN
74 #elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN) || defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
75 #define VISP_LITTLE_ENDIAN
76 #elif defined(__sparc) || defined(__sparc__) || defined(_POWER) || defined(__powerpc__) || defined(__ppc__) || \
77  defined(__hpux) || defined(_MIPSEB) || defined(_POWER) || defined(__s390__)
78 
79 #define VISP_BIG_ENDIAN
80 #elif defined(__i386__) || defined(__alpha__) || defined(__ia64) || defined(__ia64__) || defined(_M_IX86) || \
81  defined(_M_IA64) || defined(_M_ALPHA) || defined(__amd64) || defined(__amd64__) || defined(_M_AMD64) || \
82  defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || defined(__ANDROID__)
83 // It appears that all Android systems are little endian.
84 // Refer https://stackoverflow.com/questions/6212951/endianness-of-android-ndk
85 #define VISP_LITTLE_ENDIAN
86 #elif defined(WINRT) // For UWP
87 // Refer
88 // https://social.msdn.microsoft.com/Forums/en-US/04c92ef9-e38e-415f-8958-ec9f7c196fd3/arm-endianess-under-windows-mobile?forum=windowsmobiledev
89 #define VISP_LITTLE_ENDIAN
90 #else
91 #error Cannot detect host machine endianness.
92 #endif
93 
94 namespace vpEndian
95 {
96 VISP_EXPORT uint16_t swap16bits(uint16_t val);
97 
98 VISP_EXPORT uint32_t swap32bits(uint32_t val);
99 
100 VISP_EXPORT float swapFloat(float f);
101 
102 VISP_EXPORT double swapDouble(double d);
103 
104 VISP_EXPORT uint16_t reinterpret_cast_uchar_to_uint16_LE(unsigned char *const ptr);
105 } // namespace vpEndian
106 
107 #endif
VISP_EXPORT float swapFloat(float f)
Definition: vpEndian.cpp:65
VISP_EXPORT uint32_t swap32bits(uint32_t val)
Definition: vpEndian.cpp:55
VISP_EXPORT uint16_t reinterpret_cast_uchar_to_uint16_LE(unsigned char *const ptr)
Definition: vpEndian.cpp:108
VISP_EXPORT double swapDouble(double d)
Definition: vpEndian.cpp:84
VISP_EXPORT uint16_t swap16bits(uint16_t val)
Definition: vpEndian.cpp:49