blob: 0a8628c96b3043f2d1635f32dca2be7b08340881 [file] [log] [blame]
John Abd-El-Malek5110c472014-05-17 22:33:34 -07001/*
Nicolas Pena088ca032017-09-01 13:25:16 -04002 * 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
John Abd-El-Malek5110c472014-05-17 22:33:34 -07004 * 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
Nicolas Pena088ca032017-09-01 13:25:16 -04008 * Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR
John Abd-El-Malek5110c472014-05-17 22:33:34 -07009 * 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/*
37 * This must be included before any system headers,
38 * since they can react to macro defined there
39 */
40#include "opj_config_private.h"
41
42/*
43 ==========================================================
44 Standard includes used by the library
45 ==========================================================
46*/
47#include <memory.h>
48#include <stdlib.h>
49#include <string.h>
50#include <math.h>
51#include <float.h>
52#include <time.h>
53#include <stdio.h>
54#include <stdarg.h>
55#include <ctype.h>
56#include <assert.h>
Nicolas Pena088ca032017-09-01 13:25:16 -040057#include <limits.h>
John Abd-El-Malek5110c472014-05-17 22:33:34 -070058
59/*
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.
64*/
65#if defined(OPJ_HAVE_FSEEKO) && !defined(fseek)
66# define fseek fseeko
67# define ftell ftello
68#endif
69
70
71#if defined(WIN32) && !defined(Windows95) && !defined(__BORLANDC__) && \
72 !(defined(_MSC_VER) && _MSC_VER < 1400) && \
73 !(defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x800)
Nicolas Pena088ca032017-09-01 13:25:16 -040074/*
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.
78*/
John Abd-El-Malek5110c472014-05-17 22:33:34 -070079# 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)
84#else
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)
90#endif
91
92
93/*
94 ==========================================================
95 OpenJPEG interface
96 ==========================================================
97 */
98#include "openjpeg.h"
99
100/*
101 ==========================================================
102 OpenJPEG modules
103 ==========================================================
104*/
105
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700106/* Are restricted pointers available? (C99) */
Nicolas Pena088ca032017-09-01 13:25:16 -0400107#if (__STDC_VERSION__ >= 199901L)
108#define OPJ_RESTRICT restrict
109#else
110/* Not a C99 compiler */
111#if defined(__GNUC__)
112#define OPJ_RESTRICT __restrict__
113
114/*
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
119*/
120#else
121#define OPJ_RESTRICT /* restrict */
122#endif
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700123#endif
124
Nicolas Pena088ca032017-09-01 13:25:16 -0400125#ifdef __has_attribute
126#if __has_attribute(no_sanitize)
127#define OPJ_NOSANITIZE(kind) __attribute__((no_sanitize(kind)))
128#endif
129#endif
130#ifndef OPJ_NOSANITIZE
131#define OPJ_NOSANITIZE(kind)
132#endif
Jun Fange865ed12015-10-13 15:28:55 +0800133
134
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700135/* MSVC before 2013 and Borland C do not have lrintf */
Jun Fange865ed12015-10-13 15:28:55 +0800136#if defined(_MSC_VER)
137#include <intrin.h>
Nicolas Pena088ca032017-09-01 13:25:16 -0400138static INLINE long opj_lrintf(float f)
139{
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700140#ifdef _M_X64
Nicolas Pena088ca032017-09-01 13:25:16 -0400141 return _mm_cvt_ss2si(_mm_load_ss(&f));
Jun Fange865ed12015-10-13 15:28:55 +0800142
Nicolas Pena088ca032017-09-01 13:25:16 -0400143 /* commented out line breaks many tests */
144 /* return (long)((f>0.0f) ? (f + 0.5f):(f -0.5f)); */
Jun Fange865ed12015-10-13 15:28:55 +0800145#elif defined(_M_IX86)
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700146 int i;
Nicolas Pena088ca032017-09-01 13:25:16 -0400147 _asm{
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700148 fld f
149 fistp i
150 };
Nicolas Pena088ca032017-09-01 13:25:16 -0400151
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700152 return i;
Nicolas Pena088ca032017-09-01 13:25:16 -0400153#else
154 return (long)((f>0.0f) ? (f + 0.5f) : (f - 0.5f));
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700155#endif
156}
Jun Fange865ed12015-10-13 15:28:55 +0800157#elif defined(__BORLANDC__)
Nicolas Pena088ca032017-09-01 13:25:16 -0400158static INLINE long opj_lrintf(float f)
159{
Jun Fange865ed12015-10-13 15:28:55 +0800160#ifdef _M_X64
Nicolas Pena088ca032017-09-01 13:25:16 -0400161 return (long)((f > 0.0f) ? (f + 0.5f) : (f - 0.5f));
Jun Fange865ed12015-10-13 15:28:55 +0800162#else
Nicolas Pena088ca032017-09-01 13:25:16 -0400163 int i;
Jun Fange865ed12015-10-13 15:28:55 +0800164
Nicolas Pena088ca032017-09-01 13:25:16 -0400165 _asm {
166 fld f
167 fistp i
168 };
Jun Fange865ed12015-10-13 15:28:55 +0800169
Nicolas Pena088ca032017-09-01 13:25:16 -0400170 return i;
Jun Fange865ed12015-10-13 15:28:55 +0800171#endif
172}
173#else
Nicolas Pena088ca032017-09-01 13:25:16 -0400174static INLINE long opj_lrintf(float f)
175{
176 return lrintf(f);
Jun Fange865ed12015-10-13 15:28:55 +0800177}
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700178#endif
179
JUN FANG7dba9862015-02-27 10:00:00 -0800180#if defined(_MSC_VER) && (_MSC_VER < 1400)
Nicolas Pena088ca032017-09-01 13:25:16 -0400181#define vsnprintf _vsnprintf
JUN FANG7dba9862015-02-27 10:00:00 -0800182#endif
183
Jun Fange865ed12015-10-13 15:28:55 +0800184/* 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)
Nicolas Pena088ca032017-09-01 13:25:16 -0400186# include <intrin.h>
187# pragma intrinsic(__emul)
Jun Fange865ed12015-10-13 15:28:55 +0800188#endif
189
Nicolas Pena088ca032017-09-01 13:25:16 -0400190/* Apparently Visual Studio doesn't define __SSE__ / __SSE2__ macros */
191#if defined(_M_X64)
192/* Intel 64bit support SSE and SSE2 */
193# ifndef __SSE__
194# define __SSE__ 1
195# endif
196# ifndef __SSE2__
197# define __SSE2__ 1
198# endif
199#endif
200
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)
204# if _M_IX86_FP >= 1
205# ifndef __SSE__
206# define __SSE__ 1
207# endif
208# endif
209# if _M_IX86_FP >= 2
210# ifndef __SSE2__
211# define __SSE2__ 1
212# endif
213# endif
214#endif
215
216/* Type to use for bit-fields in internal headers */
217typedef unsigned int OPJ_BITFIELD;
218
Nicolas Pena826480c2017-10-23 10:30:46 -0400219#define OPJ_UNUSED(x) (void)x
220
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700221#include "opj_inttypes.h"
222#include "opj_clock.h"
223#include "opj_malloc.h"
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700224#include "event.h"
Jun Fange865ed12015-10-13 15:28:55 +0800225#include "function_list.h"
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700226#include "bio.h"
227#include "cio.h"
228
Nicolas Pena088ca032017-09-01 13:25:16 -0400229#include "thread.h"
230#include "tls_keys.h"
231
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700232#include "image.h"
233#include "invert.h"
234#include "j2k.h"
235#include "jp2.h"
236
237#include "mqc.h"
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700238#include "bio.h"
239
240#include "pi.h"
241#include "tgt.h"
242#include "tcd.h"
243#include "t1.h"
244#include "dwt.h"
245#include "t2.h"
246#include "mct.h"
247#include "opj_intmath.h"
Nicolas Pena826480c2017-10-23 10:30:46 -0400248#include "sparse_array.h"
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700249
250#ifdef USE_JPIP
251#include "cidx_manager.h"
252#include "indexbox_manager.h"
253#endif
254
255/* JPWL>> */
256#ifdef USE_JPWL
257#include "openjpwl/jpwl.h"
258#endif /* USE_JPWL */
259/* <<JPWL */
260
261/* V2 */
262#include "opj_codec.h"
263
264
265#endif /* OPJ_INCLUDES_H */