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.
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.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
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.
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.
33 #ifndef OPJ_INCLUDES_H
34 #define OPJ_INCLUDES_H
37 * This must be included before any system headers,
38 * since they can react to macro defined there
40 #include "opj_config_private.h"
43 ==========================================================
44 Standard includes used by the library
45 ==========================================================
60 Use fseeko() and ftello() if they are available since they use
61 'off_t' rather than 'long'. It is wrong to use fseeko() and
62 ftello() only on systems with special LFS support since some systems
63 (e.g. FreeBSD) support a 64-bit off_t by default.
65 #if defined(OPJ_HAVE_FSEEKO) && !defined(fseek)
71 #if defined(WIN32) && !defined(Windows95) && !defined(__BORLANDC__) && \
72 !(defined(_MSC_VER) && _MSC_VER < 1400) && \
73 !(defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x800)
75 Windows '95 and Borland C do not support _lseeki64
76 Visual Studio does not support _fseeki64 and _ftelli64 until the 2005 release.
77 Without these interfaces, files over 2GB in size are not supported for Windows.
79 # define OPJ_FSEEK(stream,offset,whence) _fseeki64(stream,/* __int64 */ offset,whence)
80 # define OPJ_FSTAT(fildes,stat_buff) _fstati64(fildes,/* struct _stati64 */ stat_buff)
81 # define OPJ_FTELL(stream) /* __int64 */ _ftelli64(stream)
82 # define OPJ_STAT_STRUCT_T struct _stati64
83 # define OPJ_STAT(path,stat_buff) _stati64(path,/* struct _stati64 */ stat_buff)
85 # define OPJ_FSEEK(stream,offset,whence) fseek(stream,offset,whence)
86 # define OPJ_FSTAT(fildes,stat_buff) fstat(fildes,stat_buff)
87 # define OPJ_FTELL(stream) ftell(stream)
88 # define OPJ_STAT_STRUCT_T struct stat
89 # define OPJ_STAT(path,stat_buff) stat(path,stat_buff)
94 ==========================================================
96 ==========================================================
101 ==========================================================
103 ==========================================================
106 /* Are restricted pointers available? (C99) */
107 #if (__STDC_VERSION__ >= 199901L)
108 #define OPJ_RESTRICT restrict
110 /* Not a C99 compiler */
111 #if defined(__GNUC__)
112 #define OPJ_RESTRICT __restrict__
115 vc14 (2015) outputs wrong results.
116 Need to check OPJ_RESTRICT usage (or a bug in vc14)
117 #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
118 #define OPJ_RESTRICT __restrict
121 #define OPJ_RESTRICT /* restrict */
125 #ifdef __has_attribute
126 #if __has_attribute(no_sanitize)
127 #define OPJ_NOSANITIZE(kind) __attribute__((no_sanitize(kind)))
130 #ifndef OPJ_NOSANITIZE
131 #define OPJ_NOSANITIZE(kind)
135 /* MSVC before 2013 and Borland C do not have lrintf */
136 #if defined(_MSC_VER)
138 static INLINE long opj_lrintf(float f)
141 return _mm_cvt_ss2si(_mm_load_ss(&f));
143 /* commented out line breaks many tests */
144 /* return (long)((f>0.0f) ? (f + 0.5f):(f -0.5f)); */
145 #elif defined(_M_IX86)
154 return (long)((f>0.0f) ? (f + 0.5f) : (f - 0.5f));
157 #elif defined(__BORLANDC__)
158 static INLINE long opj_lrintf(float f)
161 return (long)((f > 0.0f) ? (f + 0.5f) : (f - 0.5f));
174 static INLINE long opj_lrintf(float f)
180 #if defined(_MSC_VER) && (_MSC_VER < 1400)
181 #define vsnprintf _vsnprintf
184 /* MSVC x86 is really bad at doing int64 = int32 * int32 on its own. Use intrinsic. */
185 #if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86)
187 # pragma intrinsic(__emul)
190 /* Apparently Visual Studio doesn't define __SSE__ / __SSE2__ macros */
192 /* Intel 64bit support SSE and SSE2 */
201 /* For x86, test the value of the _M_IX86_FP macro. */
202 /* See https://msdn.microsoft.com/en-us/library/b0084kay.aspx */
203 #if defined(_M_IX86_FP)
216 /* Type to use for bit-fields in internal headers */
217 typedef unsigned int OPJ_BITFIELD;
219 #define OPJ_UNUSED(x) (void)x
221 #include "opj_inttypes.h"
222 #include "opj_clock.h"
223 #include "opj_malloc.h"
225 #include "function_list.h"
230 #include "tls_keys.h"
247 #include "opj_intmath.h"
248 #include "sparse_array.h"
251 #include "cidx_manager.h"
252 #include "indexbox_manager.h"
257 #include "openjpwl/jpwl.h"
258 #endif /* USE_JPWL */
262 #include "opj_codec.h"
265 #endif /* OPJ_INCLUDES_H */