Max 5 API Reference
00001 #ifndef _BYTEORDER_H_ 00002 #define _BYTEORDER_H_ 00003 00004 #ifdef MAC_VERSION 00005 #if TARGET_RT_LITTLE_ENDIAN 00006 #define C74_LITTLE_ENDIAN 1 00007 #define C74_BIG_ENDIAN 0 00008 #else 00009 #define C74_LITTLE_ENDIAN 0 00010 #define C74_BIG_ENDIAN 1 00011 #endif 00012 00013 #else // WIN_VERSION 00014 00015 /** 00016 A macro that indicates whether or not the current architecture uses Litte-endian byte ordering 00017 (such as is used on an i386 processor). 00018 Note that this macro is always defined; it will be either a 0 or a 1. 00019 @ingroup byteorder 00020 */ 00021 #define C74_LITTLE_ENDIAN 1 00022 00023 /** 00024 A macro that indicates whether or not the current architecture uses Big-endian byte ordering 00025 (such as is used on a PPC processor). 00026 Note that this macro is always defined; it will be either a 0 or a 1. 00027 @ingroup byteorder 00028 */ 00029 #define C74_BIG_ENDIAN 0 00030 00031 #endif // WIN_VERSION 00032 00033 00034 /** 00035 Switch the byte ordering of a short integer. 00036 @ingroup byteorder 00037 @param x A short integer. 00038 @return A short integer with the byte-ordering swapped. 00039 */ 00040 #define BYTEORDER_SWAPW16(x) ((short)(((((unsigned short)(x))>>8)&0x00ff)+((((unsigned short)(x))<<8)&0xff00))) 00041 00042 /** 00043 Switch the byte ordering of an integer. 00044 @ingroup byteorder 00045 @param x An integer. 00046 @return An integer with the byte-ordering swapped. 00047 */ 00048 #define BYTEORDER_SWAPW32(x) ((long)(((((unsigned long)(x))>>24L)&0x000000ff)+((((unsigned long)(x))>>8L)&0x0000ff00)+ \ 00049 ((((unsigned long)(x))<<24L)&0xff000000)+((((unsigned long)(x))<<8L)&0x00ff0000))) 00050 /** 00051 Switch the byte ordering of a float. 00052 @ingroup byteorder 00053 @param x A float. 00054 @return A float with the byte-ordering swapped. 00055 */ 00056 #define BYTEORDER_SWAPF32 byteorder_swapf32 00057 00058 /** 00059 Switch the byte ordering of a double. 00060 @ingroup byteorder 00061 @param x A double. 00062 @return A double. 00063 */ 00064 #define BYTEORDER_SWAPF64 byteorder_swapf64 00065 00066 00067 // Undocumented, use the above macros. 00068 float byteorder_swapf32(float f); 00069 double byteorder_swapf64(double f); 00070 00071 00072 #if C74_BIG_ENDIAN 00073 #define BYTEORDER_LSBW16(x) BYTEORDER_SWAPW16(x) 00074 #define BYTEORDER_LSBW32(x) BYTEORDER_SWAPW32(x) 00075 #define BYTEORDER_LSBF32(x) BYTEORDER_SWAPF32(x) 00076 #define BYTEORDER_LSBF64(x) BYTEORDER_SWAPF64(x) 00077 #define BYTEORDER_MSBW16(x) (x) 00078 #define BYTEORDER_MSBW32(x) (x) 00079 #define BYTEORDER_MSBF32(x) (x) 00080 #define BYTEORDER_MSBF64(x) (x) 00081 #else 00082 00083 /** 00084 Switch the byte ordering of a short integer from the native swapping to Little-endian (Least Significant Byte). 00085 If the current environment is already Little-endian, then the returned value is not byteswapped. 00086 00087 @ingroup byteorder 00088 @param x A short integer. 00089 @return A short integer with the byte-ordering swapped if neccessary. 00090 */ 00091 #define BYTEORDER_LSBW16(x) (x) 00092 00093 /** 00094 Switch the byte ordering of an integer from the native swapping to Little-endian (Least Significant Byte). 00095 If the current environment is already Little-endian, then the returned value is not byteswapped. 00096 00097 @ingroup byteorder 00098 @param x An integer. 00099 @return An integer with the byte-ordering swapped if neccessary. 00100 */ 00101 #define BYTEORDER_LSBW32(x) (x) 00102 00103 /** 00104 Switch the byte ordering of a float from the native swapping to Little-endian (Least Significant Byte). 00105 If the current environment is already Little-endian, then the returned value is not byteswapped. 00106 00107 @ingroup byteorder 00108 @param x A float. 00109 @return A float with the byte-ordering swapped if neccessary. 00110 */ 00111 #define BYTEORDER_LSBF32(x) (x) 00112 00113 /** 00114 Switch the byte ordering of a double from the native swapping to Little-endian (Least Significant Byte). 00115 If the current environment is already Little-endian, then the returned value is not byteswapped. 00116 00117 @ingroup byteorder 00118 @param x A double. 00119 @return A double with the byte-ordering swapped if neccessary. 00120 */ 00121 #define BYTEORDER_LSBF64(x) (x) 00122 00123 /** 00124 Switch the byte ordering of a short integer from the native swapping to Big-endian (Most Significant Byte). 00125 If the current environment is already Big-endian, then the returned value is not byteswapped. 00126 00127 @ingroup byteorder 00128 @param x A short integer. 00129 @return A short integer with the byte-ordering swapped if neccessary. 00130 */ 00131 #define BYTEORDER_MSBW16(x) BYTEORDER_SWAPW16(x) 00132 00133 /** 00134 Switch the byte ordering of an integer from the native swapping to Big-endian (Most Significant Byte). 00135 If the current environment is already Big-endian, then the returned value is not byteswapped. 00136 00137 @ingroup byteorder 00138 @param x An integer. 00139 @return An integer with the byte-ordering swapped if neccessary. 00140 */ 00141 #define BYTEORDER_MSBW32(x) BYTEORDER_SWAPW32(x) 00142 00143 /** 00144 Switch the byte ordering of a float from the native swapping to Big-endian (Most Significant Byte). 00145 If the current environment is already Big-endian, then the returned value is not byteswapped. 00146 00147 @ingroup byteorder 00148 @param x A float. 00149 @return A float with the byte-ordering swapped if neccessary. 00150 */ 00151 #define BYTEORDER_MSBF32(x) BYTEORDER_SWAPF32(x) 00152 00153 /** 00154 Switch the byte ordering of a double from the native swapping to Big-endian (Most Significant Byte). 00155 If the current environment is already Big-endian, then the returned value is not byteswapped. 00156 00157 @ingroup byteorder 00158 @param x A double. 00159 @return A double with the byte-ordering swapped if neccessary. 00160 */ 00161 #define BYTEORDER_MSBF64(x) BYTEORDER_SWAPF64(x) 00162 00163 #endif 00164 00165 00166 #if C74_LITTLE_ENDIAN 00167 #define STR_TO_FOURCC(x) ((x) = \ 00168 (((unsigned long) ((x) & 0x000000FF)) << 24) | \ 00169 (((unsigned long) ((x) & 0x0000FF00)) << 8) | \ 00170 (((unsigned long) ((x) & 0x00FF0000)) >> 8) | \ 00171 (((unsigned long) ((x) & 0xFF000000)) >> 24))\ 00172 00173 #else 00174 /* 00175 Swap the byte ordering, if neccessary, for a Four Character Code. 00176 The bytes are swapped in-place, thus there is no return value. 00177 00178 @ingroup byteorder 00179 @param x An integer (32bit) containing the four char code. 00180 If byte-swapping is needed, it will be byte-swapped in-place. 00181 */ 00182 #define STR_TO_FOURCC(x) (x) 00183 #endif // C74_LITTLE_ENDIAN 00184 00185 00186 #endif // _BYTEORDER_H
Copyright © 2008, Cycling '74