opj_includes.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * The copyright in this software is being made available under the 2-clauses
  3. * BSD License, included below. This software may be subject to other third
  4. * party and contributor rights, including patent rights, and no such rights
  5. * are granted under this license.
  6. *
  7. * Copyright (c) 2005, Herve Drolon, FreeImage Team
  8. * Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR
  9. * Copyright (c) 2012, CS Systemes d'Information, France
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. * 1. Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in the
  19. * documentation and/or other materials provided with the distribution.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  25. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  26. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  27. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  28. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  29. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  31. * POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. #ifndef OPJ_INCLUDES_H
  34. #define OPJ_INCLUDES_H
  35. /*
  36. * This must be included before any system headers,
  37. * since they can react to macro defined there
  38. */
  39. #include "opj_config_private.h"
  40. /*
  41. ==========================================================
  42. Standard includes used by the library
  43. ==========================================================
  44. */
  45. #include <memory.h>
  46. #include <stdlib.h>
  47. #include <string.h>
  48. #include <math.h>
  49. #include <float.h>
  50. #include <time.h>
  51. #include <stdio.h>
  52. #include <stdarg.h>
  53. #include <ctype.h>
  54. #include <assert.h>
  55. #include <limits.h>
  56. #include <stdint.h>
  57. #include <inttypes.h>
  58. /*
  59. Use fseeko() and ftello() if they are available since they use
  60. 'off_t' rather than 'long'. It is wrong to use fseeko() and
  61. ftello() only on systems with special LFS support since some systems
  62. (e.g. FreeBSD) support a 64-bit off_t by default.
  63. */
  64. #if defined(OPJ_HAVE_FSEEKO) && !defined(fseek)
  65. # define fseek fseeko
  66. # define ftell ftello
  67. #endif
  68. #if defined(WIN32) && !defined(Windows95) && !defined(__BORLANDC__) && \
  69. !(defined(_MSC_VER) && _MSC_VER < 1400) && \
  70. !(defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x800)
  71. /*
  72. Windows '95 and Borland C do not support _lseeki64
  73. Visual Studio does not support _fseeki64 and _ftelli64 until the 2005 release.
  74. Without these interfaces, files over 2GB in size are not supported for Windows.
  75. */
  76. # define OPJ_FSEEK(stream,offset,whence) _fseeki64(stream,/* __int64 */ offset,whence)
  77. # define OPJ_FSTAT(fildes,stat_buff) _fstati64(fildes,/* struct _stati64 */ stat_buff)
  78. # define OPJ_FTELL(stream) /* __int64 */ _ftelli64(stream)
  79. # define OPJ_STAT_STRUCT_T struct _stati64
  80. # define OPJ_STAT(path,stat_buff) _stati64(path,/* struct _stati64 */ stat_buff)
  81. #else
  82. # define OPJ_FSEEK(stream,offset,whence) fseek(stream,offset,whence)
  83. # define OPJ_FSTAT(fildes,stat_buff) fstat(fildes,stat_buff)
  84. # define OPJ_FTELL(stream) ftell(stream)
  85. # define OPJ_STAT_STRUCT_T struct stat
  86. # define OPJ_STAT(path,stat_buff) stat(path,stat_buff)
  87. #endif
  88. /*
  89. ==========================================================
  90. OpenJPEG interface
  91. ==========================================================
  92. */
  93. #include "openjpeg.h"
  94. /*
  95. ==========================================================
  96. OpenJPEG modules
  97. ==========================================================
  98. */
  99. /* Are restricted pointers available? (C99) */
  100. #if (__STDC_VERSION__ >= 199901L)
  101. #define OPJ_RESTRICT restrict
  102. #else
  103. /* Not a C99 compiler */
  104. #if defined(__GNUC__)
  105. #define OPJ_RESTRICT __restrict__
  106. /*
  107. vc14 (2015) outputs wrong results.
  108. Need to check OPJ_RESTRICT usage (or a bug in vc14)
  109. #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
  110. #define OPJ_RESTRICT __restrict
  111. */
  112. #else
  113. #define OPJ_RESTRICT /* restrict */
  114. #endif
  115. #endif
  116. #ifdef __has_attribute
  117. #if __has_attribute(no_sanitize)
  118. #define OPJ_NOSANITIZE(kind) __attribute__((no_sanitize(kind)))
  119. #endif
  120. #endif
  121. #ifndef OPJ_NOSANITIZE
  122. #define OPJ_NOSANITIZE(kind)
  123. #endif
  124. /* MSVC before 2013 and Borland C do not have lrintf */
  125. #if defined(_MSC_VER)
  126. #include <intrin.h>
  127. static INLINE long opj_lrintf(float f)
  128. {
  129. #ifdef _M_X64
  130. return _mm_cvt_ss2si(_mm_load_ss(&f));
  131. /* commented out line breaks many tests */
  132. /* return (long)((f>0.0f) ? (f + 0.5f):(f -0.5f)); */
  133. #elif defined(_M_IX86)
  134. int i;
  135. _asm{
  136. fld f
  137. fistp i
  138. };
  139. return i;
  140. #else
  141. return (long)((f>0.0f) ? (f + 0.5f) : (f - 0.5f));
  142. #endif
  143. }
  144. #elif defined(__BORLANDC__)
  145. static INLINE long opj_lrintf(float f)
  146. {
  147. #ifdef _M_X64
  148. return (long)((f > 0.0f) ? (f + 0.5f) : (f - 0.5f));
  149. #else
  150. int i;
  151. _asm {
  152. fld f
  153. fistp i
  154. };
  155. return i;
  156. #endif
  157. }
  158. #else
  159. static INLINE long opj_lrintf(float f)
  160. {
  161. return lrintf(f);
  162. }
  163. #endif
  164. #if defined(_MSC_VER) && (_MSC_VER < 1400)
  165. #define vsnprintf _vsnprintf
  166. #endif
  167. /* MSVC x86 is really bad at doing int64 = int32 * int32 on its own. Use intrinsic. */
  168. #if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86)
  169. # include <intrin.h>
  170. # pragma intrinsic(__emul)
  171. #endif
  172. /* Apparently Visual Studio doesn't define __SSE__ / __SSE2__ macros */
  173. #if defined(_M_X64)
  174. /* Intel 64bit support SSE and SSE2 */
  175. # ifndef __SSE__
  176. # define __SSE__ 1
  177. # endif
  178. # ifndef __SSE2__
  179. # define __SSE2__ 1
  180. # endif
  181. #endif
  182. /* For x86, test the value of the _M_IX86_FP macro. */
  183. /* See https://msdn.microsoft.com/en-us/library/b0084kay.aspx */
  184. #if defined(_M_IX86_FP)
  185. # if _M_IX86_FP >= 1
  186. # ifndef __SSE__
  187. # define __SSE__ 1
  188. # endif
  189. # endif
  190. # if _M_IX86_FP >= 2
  191. # ifndef __SSE2__
  192. # define __SSE2__ 1
  193. # endif
  194. # endif
  195. #endif
  196. /* Type to use for bit-fields in internal headers */
  197. typedef unsigned int OPJ_BITFIELD;
  198. #define OPJ_UNUSED(x) (void)x
  199. #include "opj_clock.h"
  200. #include "opj_malloc.h"
  201. #include "event.h"
  202. #include "function_list.h"
  203. #include "bio.h"
  204. #include "cio.h"
  205. #include "thread.h"
  206. #include "tls_keys.h"
  207. #include "image.h"
  208. #include "invert.h"
  209. #include "j2k.h"
  210. #include "jp2.h"
  211. #include "mqc.h"
  212. #include "bio.h"
  213. #include "pi.h"
  214. #include "tgt.h"
  215. #include "tcd.h"
  216. #include "t1.h"
  217. #include "dwt.h"
  218. #include "t2.h"
  219. #include "mct.h"
  220. #include "opj_intmath.h"
  221. #include "sparse_array.h"
  222. #ifdef USE_JPIP
  223. #error #include "cidx_manager.h"
  224. #error #include "indexbox_manager.h"
  225. #endif
  226. /* JPWL>> */
  227. #ifdef USE_JPWL
  228. #error #include "openjpwl/jpwl.h"
  229. #endif /* USE_JPWL */
  230. /* <<JPWL */
  231. /* V2 */
  232. #include "opj_codec.h"
  233. #endif /* OPJ_INCLUDES_H */