opj_includes.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. /*
  57. Use fseeko() and ftello() if they are available since they use
  58. 'off_t' rather than 'long'. It is wrong to use fseeko() and
  59. ftello() only on systems with special LFS support since some systems
  60. (e.g. FreeBSD) support a 64-bit off_t by default.
  61. */
  62. #if defined(OPJ_HAVE_FSEEKO) && !defined(fseek)
  63. # define fseek fseeko
  64. # define ftell ftello
  65. #endif
  66. #if defined(WIN32) && !defined(Windows95) && !defined(__BORLANDC__) && \
  67. !(defined(_MSC_VER) && _MSC_VER < 1400) && \
  68. !(defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x800)
  69. /*
  70. Windows '95 and Borland C do not support _lseeki64
  71. Visual Studio does not support _fseeki64 and _ftelli64 until the 2005 release.
  72. Without these interfaces, files over 2GB in size are not supported for Windows.
  73. */
  74. # define OPJ_FSEEK(stream,offset,whence) _fseeki64(stream,/* __int64 */ offset,whence)
  75. # define OPJ_FSTAT(fildes,stat_buff) _fstati64(fildes,/* struct _stati64 */ stat_buff)
  76. # define OPJ_FTELL(stream) /* __int64 */ _ftelli64(stream)
  77. # define OPJ_STAT_STRUCT_T struct _stati64
  78. # define OPJ_STAT(path,stat_buff) _stati64(path,/* struct _stati64 */ stat_buff)
  79. #else
  80. # define OPJ_FSEEK(stream,offset,whence) fseek(stream,offset,whence)
  81. # define OPJ_FSTAT(fildes,stat_buff) fstat(fildes,stat_buff)
  82. # define OPJ_FTELL(stream) ftell(stream)
  83. # define OPJ_STAT_STRUCT_T struct stat
  84. # define OPJ_STAT(path,stat_buff) stat(path,stat_buff)
  85. #endif
  86. /*
  87. ==========================================================
  88. OpenJPEG interface
  89. ==========================================================
  90. */
  91. #include "openjpeg.h"
  92. /*
  93. ==========================================================
  94. OpenJPEG modules
  95. ==========================================================
  96. */
  97. /* Are restricted pointers available? (C99) */
  98. #if (__STDC_VERSION__ >= 199901L)
  99. #define OPJ_RESTRICT restrict
  100. #else
  101. /* Not a C99 compiler */
  102. #if defined(__GNUC__)
  103. #define OPJ_RESTRICT __restrict__
  104. /*
  105. vc14 (2015) outputs wrong results.
  106. Need to check OPJ_RESTRICT usage (or a bug in vc14)
  107. #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
  108. #define OPJ_RESTRICT __restrict
  109. */
  110. #else
  111. #define OPJ_RESTRICT /* restrict */
  112. #endif
  113. #endif
  114. #ifdef __has_attribute
  115. #if __has_attribute(no_sanitize)
  116. #define OPJ_NOSANITIZE(kind) __attribute__((no_sanitize(kind)))
  117. #endif
  118. #endif
  119. #ifndef OPJ_NOSANITIZE
  120. #define OPJ_NOSANITIZE(kind)
  121. #endif
  122. /* MSVC before 2013 and Borland C do not have lrintf */
  123. #if defined(_MSC_VER)
  124. #include <intrin.h>
  125. static INLINE long opj_lrintf(float f)
  126. {
  127. #ifdef _M_X64
  128. return _mm_cvt_ss2si(_mm_load_ss(&f));
  129. /* commented out line breaks many tests */
  130. /* return (long)((f>0.0f) ? (f + 0.5f):(f -0.5f)); */
  131. #elif defined(_M_IX86)
  132. int i;
  133. _asm{
  134. fld f
  135. fistp i
  136. };
  137. return i;
  138. #else
  139. return (long)((f>0.0f) ? (f + 0.5f) : (f - 0.5f));
  140. #endif
  141. }
  142. #elif defined(__BORLANDC__)
  143. static INLINE long opj_lrintf(float f)
  144. {
  145. #ifdef _M_X64
  146. return (long)((f > 0.0f) ? (f + 0.5f) : (f - 0.5f));
  147. #else
  148. int i;
  149. _asm {
  150. fld f
  151. fistp i
  152. };
  153. return i;
  154. #endif
  155. }
  156. #else
  157. static INLINE long opj_lrintf(float f)
  158. {
  159. return lrintf(f);
  160. }
  161. #endif
  162. #if defined(_MSC_VER) && (_MSC_VER < 1400)
  163. #define vsnprintf _vsnprintf
  164. #endif
  165. /* MSVC x86 is really bad at doing int64 = int32 * int32 on its own. Use intrinsic. */
  166. #if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86)
  167. # include <intrin.h>
  168. # pragma intrinsic(__emul)
  169. #endif
  170. /* Apparently Visual Studio doesn't define __SSE__ / __SSE2__ macros */
  171. #if defined(_M_X64)
  172. /* Intel 64bit support SSE and SSE2 */
  173. # ifndef __SSE__
  174. # define __SSE__ 1
  175. # endif
  176. # ifndef __SSE2__
  177. # define __SSE2__ 1
  178. # endif
  179. #endif
  180. /* For x86, test the value of the _M_IX86_FP macro. */
  181. /* See https://msdn.microsoft.com/en-us/library/b0084kay.aspx */
  182. #if defined(_M_IX86_FP)
  183. # if _M_IX86_FP >= 1
  184. # ifndef __SSE__
  185. # define __SSE__ 1
  186. # endif
  187. # endif
  188. # if _M_IX86_FP >= 2
  189. # ifndef __SSE2__
  190. # define __SSE2__ 1
  191. # endif
  192. # endif
  193. #endif
  194. /* Type to use for bit-fields in internal headers */
  195. typedef unsigned int OPJ_BITFIELD;
  196. #define OPJ_UNUSED(x) (void)x
  197. #include "opj_inttypes.h"
  198. #include "opj_clock.h"
  199. #include "opj_malloc.h"
  200. #include "event.h"
  201. #include "function_list.h"
  202. #include "bio.h"
  203. #include "cio.h"
  204. #include "thread.h"
  205. #include "tls_keys.h"
  206. #include "image.h"
  207. #include "invert.h"
  208. #include "j2k.h"
  209. #include "jp2.h"
  210. #include "mqc.h"
  211. #include "bio.h"
  212. #include "pi.h"
  213. #include "tgt.h"
  214. #include "tcd.h"
  215. #include "t1.h"
  216. #include "dwt.h"
  217. #include "t2.h"
  218. #include "mct.h"
  219. #include "opj_intmath.h"
  220. #include "sparse_array.h"
  221. #ifdef USE_JPIP
  222. #error #include "cidx_manager.h"
  223. #error #include "indexbox_manager.h"
  224. #endif
  225. /* JPWL>> */
  226. #ifdef USE_JPWL
  227. #error #include "openjpwl/jpwl.h"
  228. #endif /* USE_JPWL */
  229. /* <<JPWL */
  230. /* V2 */
  231. #include "opj_codec.h"
  232. #endif /* OPJ_INCLUDES_H */