Visual Servoing Platform version 3.5.0
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)
49typedef 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__) && !defined(__FreeBSD__) && defined(__BYTE_ORDER__))
59#include <endian.h>
60#if (__BYTE_ORDER == __LITTLE_ENDIAN)
61#define VISP_LITTLE_ENDIAN
62#elif (__BYTE_ORDER == __BIG_ENDIAN)
63#define VISP_BIG_ENDIAN
64#elif (__BYTE_ORDER == __PDP_ENDIAN)
65// Currently not supported when reading / writing binary file
66#define VISP_PDP_ENDIAN
67//#error PDP endian is not supported. //Uncomment if needed/happens
68#else
69#error Unknown machine endianness detected.
70#endif
71#elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN) || defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
72#define VISP_BIG_ENDIAN
73#elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN) || defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
74#define VISP_LITTLE_ENDIAN
75#elif defined(__sparc) || defined(__sparc__) || defined(_POWER) || defined(__powerpc__) || defined(__ppc__) || \
76 defined(__hpux) || defined(_MIPSEB) || defined(_POWER) || defined(__s390__)
77
78#define VISP_BIG_ENDIAN
79#elif defined(__i386__) || defined(__alpha__) || defined(__ia64) || defined(__ia64__) || defined(_M_IX86) || \
80 defined(_M_IA64) || defined(_M_ALPHA) || defined(__amd64) || defined(__amd64__) || defined(_M_AMD64) || \
81 defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || defined(__ANDROID__)
82 // It appears that all Android systems are little endian.
83 // Refer https://stackoverflow.com/questions/6212951/endianness-of-android-ndk
84#define VISP_LITTLE_ENDIAN
85#elif defined(WINRT) // For UWP
86// Refer https://social.msdn.microsoft.com/Forums/en-US/04c92ef9-e38e-415f-8958-ec9f7c196fd3/arm-endianess-under-windows-mobile?forum=windowsmobiledev
87#define VISP_LITTLE_ENDIAN
88#else
89#error Cannot detect host machine endianness.
90#endif
91
92namespace vpEndian
93{
94VISP_EXPORT uint16_t swap16bits(uint16_t val);
95
96VISP_EXPORT uint32_t swap32bits(uint32_t val);
97
98VISP_EXPORT float swapFloat(float f);
99
100VISP_EXPORT double swapDouble(double d);
101
102VISP_EXPORT uint16_t reinterpret_cast_uchar_to_uint16_LE(unsigned char * const ptr);
103}
104
105#endif
106
VISP_EXPORT float swapFloat(float f)
Definition: vpEndian.cpp:68
VISP_EXPORT uint32_t swap32bits(uint32_t val)
Definition: vpEndian.cpp:58
VISP_EXPORT uint16_t reinterpret_cast_uchar_to_uint16_LE(unsigned char *const ptr)
Definition: vpEndian.cpp:111
VISP_EXPORT double swapDouble(double d)
Definition: vpEndian.cpp:87
VISP_EXPORT uint16_t swap16bits(uint16_t val)
Definition: vpEndian.cpp:49