PVRTGlobal.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /******************************************************************************
  2. @File PVRTGlobal.h
  3. @Title PVRTGlobal
  4. @Version
  5. @Copyright Copyright (C) Imagination Technologies Limited.
  6. @Platform ANSI compatible
  7. @Description Global defines and typedefs for PVRTools
  8. ******************************************************************************/
  9. #ifndef _PVRTGLOBAL_H_
  10. #define _PVRTGLOBAL_H_
  11. /*!***************************************************************************
  12. Macros
  13. *****************************************************************************/
  14. #define PVRT_MIN(a,b) (((a) < (b)) ? (a) : (b))
  15. #define PVRT_MAX(a,b) (((a) > (b)) ? (a) : (b))
  16. #define PVRT_CLAMP(x, l, h) (PVRT_MIN((h), PVRT_MAX((x), (l))))
  17. // avoid warning about unused parameter
  18. #define PVRT_UNREFERENCED_PARAMETER(x) ((void) x)
  19. #if defined(_WIN32) && !defined(UNDER_CE) && !defined(__SYMBIAN32__) && !defined(__BADA__) && !defined(__QT__) /* Windows desktop */
  20. #define _CRTDBG_MAP_ALLOC
  21. #include <windows.h>
  22. #include <crtdbg.h>
  23. #include <tchar.h>
  24. #endif
  25. #if defined(UNDER_CE)
  26. #include <windows.h>
  27. #ifndef _ASSERT
  28. #ifdef _DEBUG
  29. #define _ASSERT(X) { (X) ? 0 : DebugBreak(); }
  30. #else
  31. #define _ASSERT(X)
  32. #endif
  33. #endif
  34. #ifndef _ASSERTE
  35. #ifdef _DEBUG
  36. #define _ASSERTE _ASSERT
  37. #else
  38. #define _ASSERTE(X)
  39. #endif
  40. #endif
  41. #define _RPT0(a,b)
  42. #define _RPT1(a,b,c)
  43. #define _RPT2(a,b,c,d)
  44. #define _RPT3(a,b,c,d,e)
  45. #define _RPT4(a,b,c,d,e,f)
  46. #else
  47. #if defined(_WIN32) && !defined(__WINSCW__) && !defined(__BADA__) && !defined(__QT__)
  48. #else
  49. #if defined(__linux__) || defined(__APPLE__)
  50. #define _ASSERT(a)((void)0)
  51. #define _ASSERTE(a)((void)0)
  52. #ifdef _DEBUG
  53. #ifndef _RPT0
  54. #define _RPT0(a,b) printf(b)
  55. #endif
  56. #ifndef _RPT1
  57. #define _RPT1(a,b,c) printf(b,c)
  58. #endif
  59. #else
  60. #ifndef _RPT0
  61. #define _RPT0(a,b)((void)0)
  62. #endif
  63. #ifndef _RPT1
  64. #define _RPT1(a,b,c)((void)0)
  65. #endif
  66. #endif
  67. #define _RPT2(a,b,c,d)((void)0)
  68. #define _RPT3(a,b,c,d,e)((void)0)
  69. #define _RPT4(a,b,c,d,e,f)((void)0)
  70. #include <stdlib.h>
  71. #include <string.h>
  72. #define BYTE unsigned char
  73. #define WORD unsigned short
  74. #define DWORD unsigned long
  75. typedef struct tagRGBQUAD {
  76. BYTE rgbBlue;
  77. BYTE rgbGreen;
  78. BYTE rgbRed;
  79. BYTE rgbReserved;
  80. } RGBQUAD;
  81. #define BOOL int
  82. #define TRUE 1
  83. #define FALSE 0
  84. #else
  85. #define _CRT_WARN 0
  86. #define _RPT0(a,b)
  87. #define _RPT1(a,b,c)
  88. #define _RPT2(a,b,c,d)
  89. #define _RPT3(a,b,c,d,e)
  90. #define _RPT4(a,b,c,d,e,f)
  91. #define _ASSERT(X)
  92. #define _ASSERTE(X)
  93. #endif
  94. #endif
  95. #endif
  96. #include <stdio.h>
  97. #define FREE(X) { if(X) { free(X); (X) = 0; } }
  98. // This macro is used to check at compile time that types are of a certain size
  99. // If the size does not equal the expected size, this typedefs an array of size 0
  100. // which causes a compile error
  101. #define PVRTSIZEASSERT(T, size) typedef int (sizeof_##T)[sizeof(T) == (size)]
  102. /****************************************************************************
  103. ** Integer types
  104. ****************************************************************************/
  105. typedef signed char PVRTint8;
  106. typedef signed short PVRTint16;
  107. typedef signed int PVRTint32;
  108. typedef unsigned char PVRTuint8;
  109. typedef unsigned short PVRTuint16;
  110. typedef unsigned int PVRTuint32;
  111. #if !defined(__BADA__) && (defined(__int64) || defined(_WIN32))
  112. typedef signed __int64 PVRTint64;
  113. typedef unsigned __int64 PVRTuint64;
  114. #elif defined(TInt64)
  115. typedef TInt64 PVRTint64;
  116. typedef TUInt64 PVRTuint64;
  117. #else
  118. typedef signed long long PVRTint64;
  119. typedef unsigned long long PVRTuint64;
  120. #endif
  121. PVRTSIZEASSERT(PVRTint8, 1);
  122. PVRTSIZEASSERT(PVRTuint8, 1);
  123. PVRTSIZEASSERT(PVRTint16, 2);
  124. PVRTSIZEASSERT(PVRTuint16, 2);
  125. PVRTSIZEASSERT(PVRTint32, 4);
  126. PVRTSIZEASSERT(PVRTuint32, 4);
  127. PVRTSIZEASSERT(PVRTint64, 8);
  128. PVRTSIZEASSERT(PVRTuint64, 8);
  129. /****************************************************************************
  130. ** swap template function
  131. ****************************************************************************/
  132. /*!***************************************************************************
  133. @Function PVRTswap
  134. @Input a Type a
  135. @Input b Type b
  136. @Description A swap template function that swaps a and b
  137. *****************************************************************************/
  138. template <typename T>
  139. inline void PVRTswap(T& a, T& b)
  140. {
  141. T temp = a;
  142. a = b;
  143. b = temp;
  144. }
  145. #ifdef _UITRON_
  146. template void PVRTswap<unsigned char>(unsigned char& a, unsigned char& b);
  147. #endif
  148. /*!***************************************************************************
  149. @Function PVRTByteSwap
  150. @Input pBytes A number
  151. @Input i32ByteNo Number of bytes in pBytes
  152. @Description Swaps the endianness of pBytes in place
  153. *****************************************************************************/
  154. inline void PVRTByteSwap(unsigned char* pBytes, int i32ByteNo)
  155. {
  156. int i = 0, j = i32ByteNo - 1;
  157. while(i < j)
  158. PVRTswap<unsigned char>(pBytes[i++], pBytes[j--]);
  159. }
  160. /*!***************************************************************************
  161. @Function PVRTByteSwap32
  162. @Input ui32Long A number
  163. @Returns ui32Long with its endianness changed
  164. @Description Converts the endianness of an unsigned long
  165. *****************************************************************************/
  166. inline unsigned long PVRTByteSwap32(unsigned long ui32Long)
  167. {
  168. return ((ui32Long&0x000000FF)<<24) + ((ui32Long&0x0000FF00)<<8) + ((ui32Long&0x00FF0000)>>8) + ((ui32Long&0xFF000000) >> 24);
  169. }
  170. /*!***************************************************************************
  171. @Function PVRTByteSwap16
  172. @Input ui16Short A number
  173. @Returns ui16Short with its endianness changed
  174. @Description Converts the endianness of a unsigned short
  175. *****************************************************************************/
  176. inline unsigned short PVRTByteSwap16(unsigned short ui16Short)
  177. {
  178. return (ui16Short>>8) | (ui16Short<<8);
  179. }
  180. /*!***************************************************************************
  181. @Function PVRTIsLittleEndian
  182. @Returns True if the platform the code is ran on is little endian
  183. @Description Returns true if the platform the code is ran on is little endian
  184. *****************************************************************************/
  185. inline bool PVRTIsLittleEndian()
  186. {
  187. static bool bLittleEndian;
  188. static bool bIsInit = false;
  189. if(!bIsInit)
  190. {
  191. short int word = 0x0001;
  192. char *byte = (char*) &word;
  193. bLittleEndian = byte[0] ? true : false;
  194. bIsInit = true;
  195. }
  196. return bLittleEndian;
  197. }
  198. #endif // _PVRTGLOBAL_H_
  199. /*****************************************************************************
  200. End of file (Tools.h)
  201. *****************************************************************************/