1 /*
2  *  Copyright 2011 The LibYuv Project Authors. All rights reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS. All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef INCLUDE_LIBYUV_BASIC_TYPES_H_
12 #define INCLUDE_LIBYUV_BASIC_TYPES_H_
13 
14 #include <stddef.h>  // for NULL, size_t
15 
16 #if defined(_MSC_VER) && (_MSC_VER < 1600)
17 #if _MSC_VER==1400
18 #   include <stdint.h>  // for uint8_t
19 #endif
20 #include <sys/types.h>  // for uintptr_t on x86
21 #else
22 #include <stdint.h>  // for uintptr_t
23 #endif
24 
25 #if defined(_MSC_VER)
26 #  pragma warning(disable:4996) // This function or variable may be unsafe.
27 #endif
28 
29 #ifndef GG_LONGLONG
30 #ifndef INT_TYPES_DEFINED
31 #define INT_TYPES_DEFINED
32 #ifdef COMPILER_MSVC
33 typedef unsigned __int64 uint64;
34 typedef __int64 int64;
35 #ifndef INT64_C
36 #define INT64_C(x) x##I64
37 #endif
38 #ifndef UINT64_C
39 #define UINT64_C(x) x##UI64
40 #endif
41 #define INT64_F "I64"
42 #else  // COMPILER_MSVC
43 #if defined(__LP64__) && !defined(__OpenBSD__) && !defined(__APPLE__)
44 typedef unsigned long uint64;  // NOLINT
45 typedef long int64;            // NOLINT
46 #ifndef INT64_C
47 #define INT64_C(x) x##L
48 #endif
49 #ifndef UINT64_C
50 #define UINT64_C(x) x##UL
51 #endif
52 #define INT64_F "l"
53 #else  // defined(__LP64__) && !defined(__OpenBSD__) && !defined(__APPLE__)
54 typedef unsigned long long uint64;  // NOLINT
55 typedef long long int64;            // NOLINT
56 #ifndef INT64_C
57 #define INT64_C(x) x##LL
58 #endif
59 #ifndef UINT64_C
60 #define UINT64_C(x) x##ULL
61 #endif
62 #define INT64_F "ll"
63 #endif  // __LP64__
64 #endif  // COMPILER_MSVC
65 typedef unsigned int uint32;
66 typedef int int32;
67 typedef unsigned short uint16;  // NOLINT
68 typedef short int16;            // NOLINT
69 typedef unsigned char uint8;
70 typedef signed char int8;
71 #endif  // INT_TYPES_DEFINED
72 #endif  // GG_LONGLONG
73 
74 // Detect compiler is for x86 or x64.
75 #if defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || \
76     defined(_M_IX86)
77 #define CPU_X86 1
78 #endif
79 // Detect compiler is for ARM.
80 #if defined(__arm__) || defined(_M_ARM)
81 #define CPU_ARM 1
82 #endif
83 
84 #ifndef ALIGNP
85 #ifdef __cplusplus
86 #define ALIGNP(p, t)        \
87   reinterpret_cast<uint8*>( \
88       ((reinterpret_cast<uintptr_t>(p) + ((t)-1)) & ~((t)-1)))
89 #else
90 #define ALIGNP(p, t) \
91   (uint8*)((((uintptr_t)(p) + ((t)-1)) & ~((t)-1))) /* NOLINT */
92 #endif
93 #endif
94 
95 #if !defined(LIBYUV_API)
96 #if defined(_WIN32) || defined(__CYGWIN__)
97 #if defined(LIBYUV_BUILDING_SHARED_LIBRARY)
98 #define LIBYUV_API __declspec(dllexport)
99 #elif defined(LIBYUV_USING_SHARED_LIBRARY)
100 #define LIBYUV_API __declspec(dllimport)
101 #else
102 #define LIBYUV_API
103 #endif  // LIBYUV_BUILDING_SHARED_LIBRARY
104 #elif defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__APPLE__) && \
105     (defined(LIBYUV_BUILDING_SHARED_LIBRARY) ||                      \
106      defined(LIBYUV_USING_SHARED_LIBRARY))
107 #define LIBYUV_API __attribute__((visibility("default")))
108 #else
109 #define LIBYUV_API
110 #endif  // __GNUC__
111 #endif  // LIBYUV_API
112 
113 #define LIBYUV_BOOL int
114 #define LIBYUV_FALSE 0
115 #define LIBYUV_TRUE 1
116 
117 // Visual C x86 or GCC little endian.
118 #if defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || \
119     defined(_M_IX86) || defined(__arm__) || defined(_M_ARM) ||     \
120     (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
121 #define LIBYUV_LITTLE_ENDIAN
122 #endif
123 
124 #endif  // INCLUDE_LIBYUV_BASIC_TYPES_H_
125