openshot-audio  0.1.7
juce_ByteOrder.h
Go to the documentation of this file.
1 /*
2  ==============================================================================
3 
4  This file is part of the juce_core module of the JUCE library.
5  Copyright (c) 2015 - ROLI Ltd.
6 
7  Permission to use, copy, modify, and/or distribute this software for any purpose with
8  or without fee is hereby granted, provided that the above copyright notice and this
9  permission notice appear in all copies.
10 
11  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
12  TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
13  NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
15  IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 
18  ------------------------------------------------------------------------------
19 
20  NOTE! This permissive ISC license applies ONLY to files within the juce_core module!
21  All other JUCE modules are covered by a dual GPL/commercial license, so if you are
22  using any other modules, be sure to check that you also comply with their license.
23 
24  For more details, visit www.juce.com
25 
26  ==============================================================================
27 */
28 
29 #ifndef JUCE_BYTEORDER_H_INCLUDED
30 #define JUCE_BYTEORDER_H_INCLUDED
31 
32 
33 //==============================================================================
38 {
39 public:
40  //==============================================================================
42  static uint16 swap (uint16 value) noexcept;
43 
45  static uint32 swap (uint32 value) noexcept;
46 
48  static uint64 swap (uint64 value) noexcept;
49 
50  //==============================================================================
52  static uint16 swapIfBigEndian (uint16 value) noexcept;
53 
55  static uint32 swapIfBigEndian (uint32 value) noexcept;
56 
58  static uint64 swapIfBigEndian (uint64 value) noexcept;
59 
61  static uint16 swapIfLittleEndian (uint16 value) noexcept;
62 
64  static uint32 swapIfLittleEndian (uint32 value) noexcept;
65 
67  static uint64 swapIfLittleEndian (uint64 value) noexcept;
68 
69  //==============================================================================
71  static uint32 littleEndianInt (const void* bytes) noexcept;
72 
74  static uint64 littleEndianInt64 (const void* bytes) noexcept;
75 
77  static uint16 littleEndianShort (const void* bytes) noexcept;
78 
80  static uint32 bigEndianInt (const void* bytes) noexcept;
81 
83  static uint64 bigEndianInt64 (const void* bytes) noexcept;
84 
86  static uint16 bigEndianShort (const void* bytes) noexcept;
87 
88  //==============================================================================
90  static int littleEndian24Bit (const void* bytes) noexcept;
91 
93  static int bigEndian24Bit (const void* bytes) noexcept;
94 
96  static void littleEndian24BitToChars (int value, void* destBytes) noexcept;
97 
99  static void bigEndian24BitToChars (int value, void* destBytes) noexcept;
100 
101  //==============================================================================
103  static bool isBigEndian() noexcept;
104 
105 private:
107 
109 };
110 
111 
112 //==============================================================================
113 #if JUCE_USE_MSVC_INTRINSICS && ! defined (__INTEL_COMPILER)
114  #pragma intrinsic (_byteswap_ulong)
115 #endif
116 
118 {
119  #if JUCE_USE_MSVC_INTRINSICSxxx // agh - the MS compiler has an internal error when you try to use this intrinsic!
120  return static_cast<uint16> (_byteswap_ushort (n));
121  #else
122  return static_cast<uint16> ((n << 8) | (n >> 8));
123  #endif
124 }
125 
127 {
128  #if JUCE_MAC || JUCE_IOS
129  return OSSwapInt32 (n);
130  #elif JUCE_GCC && JUCE_INTEL && ! JUCE_NO_INLINE_ASM
131  asm("bswap %%eax" : "=a"(n) : "a"(n));
132  return n;
133  #elif JUCE_USE_MSVC_INTRINSICS
134  return _byteswap_ulong (n);
135  #elif JUCE_MSVC && ! JUCE_NO_INLINE_ASM
136  __asm {
137  mov eax, n
138  bswap eax
139  mov n, eax
140  }
141  return n;
142  #elif JUCE_ANDROID
143  return bswap_32 (n);
144  #else
145  return (n << 24) | (n >> 24) | ((n & 0xff00) << 8) | ((n & 0xff0000) >> 8);
146  #endif
147 }
148 
150 {
151  #if JUCE_MAC || JUCE_IOS
152  return OSSwapInt64 (value);
153  #elif JUCE_USE_MSVC_INTRINSICS
154  return _byteswap_uint64 (value);
155  #else
156  return (((uint64) swap ((uint32) value)) << 32) | swap ((uint32) (value >> 32));
157  #endif
158 }
159 
160 #if JUCE_LITTLE_ENDIAN
161  inline uint16 ByteOrder::swapIfBigEndian (const uint16 v) noexcept { return v; }
162  inline uint32 ByteOrder::swapIfBigEndian (const uint32 v) noexcept { return v; }
163  inline uint64 ByteOrder::swapIfBigEndian (const uint64 v) noexcept { return v; }
164  inline uint16 ByteOrder::swapIfLittleEndian (const uint16 v) noexcept { return swap (v); }
165  inline uint32 ByteOrder::swapIfLittleEndian (const uint32 v) noexcept { return swap (v); }
166  inline uint64 ByteOrder::swapIfLittleEndian (const uint64 v) noexcept { return swap (v); }
167  inline uint32 ByteOrder::littleEndianInt (const void* const bytes) noexcept { return *static_cast<const uint32*> (bytes); }
168  inline uint64 ByteOrder::littleEndianInt64 (const void* const bytes) noexcept { return *static_cast<const uint64*> (bytes); }
169  inline uint16 ByteOrder::littleEndianShort (const void* const bytes) noexcept { return *static_cast<const uint16*> (bytes); }
170  inline uint32 ByteOrder::bigEndianInt (const void* const bytes) noexcept { return swap (*static_cast<const uint32*> (bytes)); }
171  inline uint64 ByteOrder::bigEndianInt64 (const void* const bytes) noexcept { return swap (*static_cast<const uint64*> (bytes)); }
172  inline uint16 ByteOrder::bigEndianShort (const void* const bytes) noexcept { return swap (*static_cast<const uint16*> (bytes)); }
173  inline bool ByteOrder::isBigEndian() noexcept { return false; }
174 #else
175  inline uint16 ByteOrder::swapIfBigEndian (const uint16 v) noexcept { return swap (v); }
176  inline uint32 ByteOrder::swapIfBigEndian (const uint32 v) noexcept { return swap (v); }
177  inline uint64 ByteOrder::swapIfBigEndian (const uint64 v) noexcept { return swap (v); }
178  inline uint16 ByteOrder::swapIfLittleEndian (const uint16 v) noexcept { return v; }
179  inline uint32 ByteOrder::swapIfLittleEndian (const uint32 v) noexcept { return v; }
180  inline uint64 ByteOrder::swapIfLittleEndian (const uint64 v) noexcept { return v; }
181  inline uint32 ByteOrder::littleEndianInt (const void* const bytes) noexcept { return swap (*static_cast<const uint32*> (bytes)); }
182  inline uint64 ByteOrder::littleEndianInt64 (const void* const bytes) noexcept { return swap (*static_cast<const uint64*> (bytes)); }
183  inline uint16 ByteOrder::littleEndianShort (const void* const bytes) noexcept { return swap (*static_cast<const uint16*> (bytes)); }
184  inline uint32 ByteOrder::bigEndianInt (const void* const bytes) noexcept { return *static_cast<const uint32*> (bytes); }
185  inline uint64 ByteOrder::bigEndianInt64 (const void* const bytes) noexcept { return *static_cast<const uint64*> (bytes); }
186  inline uint16 ByteOrder::bigEndianShort (const void* const bytes) noexcept { return *static_cast<const uint16*> (bytes); }
187  inline bool ByteOrder::isBigEndian() noexcept { return true; }
188 #endif
189 
190 inline int ByteOrder::littleEndian24Bit (const void* const bytes) noexcept { return (((int) static_cast<const int8*> (bytes)[2]) << 16) | (((int) static_cast<const uint8*> (bytes)[1]) << 8) | ((int) static_cast<const uint8*> (bytes)[0]); }
191 inline int ByteOrder::bigEndian24Bit (const void* const bytes) noexcept { return (((int) static_cast<const int8*> (bytes)[0]) << 16) | (((int) static_cast<const uint8*> (bytes)[1]) << 8) | ((int) static_cast<const uint8*> (bytes)[2]); }
192 inline void ByteOrder::littleEndian24BitToChars (const int value, void* const destBytes) noexcept { static_cast<uint8*> (destBytes)[0] = (uint8) value; static_cast<uint8*> (destBytes)[1] = (uint8) (value >> 8); static_cast<uint8*> (destBytes)[2] = (uint8) (value >> 16); }
193 inline void ByteOrder::bigEndian24BitToChars (const int value, void* const destBytes) noexcept { static_cast<uint8*> (destBytes)[0] = (uint8) (value >> 16); static_cast<uint8*> (destBytes)[1] = (uint8) (value >> 8); static_cast<uint8*> (destBytes)[2] = (uint8) value; }
194 
195 
196 #endif // JUCE_BYTEORDER_H_INCLUDED
static int bigEndian24Bit(const void *bytes) noexcept
Definition: juce_ByteOrder.h:191
static int littleEndian24Bit(const void *bytes) noexcept
Definition: juce_ByteOrder.h:190
static bool isBigEndian() noexcept
Definition: juce_ByteOrder.h:187
#define noexcept
Definition: juce_CompilerSupport.h:141
unsigned short uint16
Definition: juce_MathsFunctions.h:47
static uint16 swap(uint16 value) noexcept
Definition: juce_ByteOrder.h:117
static uint64 bigEndianInt64(const void *bytes) noexcept
Definition: juce_ByteOrder.h:185
Definition: juce_ByteOrder.h:37
static uint16 littleEndianShort(const void *bytes) noexcept
Definition: juce_ByteOrder.h:183
#define JUCE_API
Definition: juce_StandardHeader.h:139
static uint64 littleEndianInt64(const void *bytes) noexcept
Definition: juce_ByteOrder.h:182
static uint16 swapIfBigEndian(uint16 value) noexcept
Definition: juce_ByteOrder.h:175
unsigned long long uint64
Definition: juce_MathsFunctions.h:62
unsigned int uint32
Definition: juce_MathsFunctions.h:51
static uint32 bigEndianInt(const void *bytes) noexcept
Definition: juce_ByteOrder.h:184
#define JUCE_DELETED_FUNCTION
Definition: juce_CompilerSupport.h:133
static uint32 littleEndianInt(const void *bytes) noexcept
Definition: juce_ByteOrder.h:181
static uint16 bigEndianShort(const void *bytes) noexcept
Definition: juce_ByteOrder.h:186
#define JUCE_DECLARE_NON_COPYABLE(className)
Definition: juce_PlatformDefs.h:191
static void littleEndian24BitToChars(int value, void *destBytes) noexcept
Definition: juce_ByteOrder.h:192
static void bigEndian24BitToChars(int value, void *destBytes) noexcept
Definition: juce_ByteOrder.h:193
static uint16 swapIfLittleEndian(uint16 value) noexcept
Definition: juce_ByteOrder.h:178
unsigned char uint8
Definition: juce_MathsFunctions.h:43