Grok  7.6.6
grk_includes.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016-2021 Grok Image Compression Inc.
3  *
4  * This source code is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero General Public License, version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This source code is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Affero General Public License for more details.
12  *
13  * You should have received a copy of the GNU Affero General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  *
17  * This source code incorporates work covered by the BSD 2-clause license.
18  * Please see the LICENSE file in the root directory for details.
19  *
20  */
21 
22 #pragma once
23 
24 
25 /*
26  * This must be included before any system headers,
27  * since they can react to macro defined there
28  */
29 #include "grk_config_private.h"
30 
31 /*
32  ==========================================================
33  Standard includes used by the library
34  ==========================================================
35  */
36 #include <memory.h>
37 #include <stdlib.h>
38 #include <string>
39 #ifdef _MSC_VER
40 #define _USE_MATH_DEFINES // for C++
41 #endif
42 #include <cmath>
43 #include <float.h>
44 #include <time.h>
45 #include <stdio.h>
46 #include <stdarg.h>
47 #include <ctype.h>
48 #include <assert.h>
49 #include <inttypes.h>
50 #include <climits>
51 #include <algorithm>
52 #include <sstream>
53 #include <iostream>
54 #include <vector>
55 #include <algorithm>
56 #include <numeric>
57 
58 /*
59  Use fseeko() and ftello() if they are available since they use
60  'int64_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 int64_t by default.
63  */
64 #if defined(GROK_HAVE_FSEEKO) && !defined(fseek)
65 # define fseek fseeko
66 # define ftell ftello
67 #endif
68 
69 #if defined(_WIN32)
70 # define GROK_FSEEK(stream,offset,whence) _fseeki64(stream,/* __int64 */ offset,whence)
71 # define GROK_FSTAT(fildes,stat_buff) _fstati64(fildes,/* struct _stati64 */ stat_buff)
72 # define GROK_FTELL(stream) /* __int64 */ _ftelli64(stream)
73 # define GROK_STAT_STRUCT_T struct _stati64
74 # define GROK_STAT(path,stat_buff) _stati64(path,/* struct _stati64 */ stat_buff)
75 #else
76 # define GROK_FSEEK(stream,offset,whence) fseek(stream,offset,whence)
77 # define GROK_FSTAT(fildes,stat_buff) fstat(fildes,stat_buff)
78 # define GROK_FTELL(stream) ftell(stream)
79 # define GROK_STAT_STRUCT_T struct stat
80 # define GROK_STAT(path,stat_buff) stat(path,stat_buff)
81 #endif
82 
83 /*
84  ==========================================================
85  Grok interface
86  ==========================================================
87  */
88 
89 #include "minpf_plugin_manager.h"
90 #include "plugin_interface.h"
91 
92 /*
93  ==========================================================
94  Grok modules
95  ==========================================================
96  */
97 
98 #if defined(__GNUC__)
99 #define GRK_RESTRICT __restrict__
100 #else
101 #define GRK_RESTRICT /* GRK_RESTRICT */
102 #endif
103 
104 
105 #ifdef __has_attribute
106 #if __has_attribute(no_sanitize)
107 #define GROK_NOSANITIZE(kind) __attribute__((no_sanitize(kind)))
108 #endif
109 #endif
110 #ifndef GROK_NOSANITIZE
111 #define GROK_NOSANITIZE(kind)
112 #endif
113 
114 #include "simd.h"
115 
116 #if defined(_MSC_VER)
117 #include <intrin.h>
118 static inline long grk_lrintf(float f)
119 {
120 #ifdef _M_X64
121  return _mm_cvt_ss2si(_mm_load_ss(&f));
122 #elif defined(_M_IX86)
123  int i;
124  _asm{
125  fld f
126  fistp i
127  };
128 
129  return i;
130 #else
131  return (long)((f>0.0f) ? (f + 0.5f) : (f - 0.5f));
132 #endif
133 }
134 #else
135 static inline long grk_lrintf(float f) {
136  return lrintf(f);
137 }
138 #endif
139 
140 #if defined(_MSC_VER) && (_MSC_VER < 1400)
141 #define vsnprintf _vsnprintf
142 #endif
143 
144 /* MSVC x86 is really bad at doing int64 = int32 * int32 on its own. Use intrinsic. */
145 #if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86)
146 # include <intrin.h>
147 # pragma intrinsic(__emul)
148 #endif
149 
150 #define GRK_UNUSED(x) (void)x
151 
152 #include "logger.h"
153 #include "testing.h"
154 #include "ThreadPool.hpp"
155 #include "IOpenable.h"
156 #include <MemStream.h>
157 #include "GrkMappedFile.h"
158 #include "MemManager.h"
159 #include "util.h"
160 #include "GrkImage.h"
161 #include "grk_exceptions.h"
162 #include "ChunkBuffer.h"
163 #include "BitIO.h"
164 #include "BufferedStream.h"
165 #include "Quantizer.h"
166 #include <Profile.h>
167 #include "LengthMarkers.h"
168 #include "SIZMarker.h"
169 #include "PPMMarker.h"
170 #include "SOTMarker.h"
171 #include "CodeStream.h"
172 #include "markers.h"
173 #include <Dump.h>
174 #include "FileFormat.h"
175 #include "BitIO.h"
176 #include "TagTree.h"
177 #include "T1Structs.h"
178 #include <WaveletReverse.h>
180 #include "PacketIter.h"
181 #include <SparseBuffer.h>
182 #include "TileComponent.h"
183 #include "TileProcessor.h"
184 #include "TileCache.h"
185 #include <WaveletFwdImpl.h>
186 #include "t1_common.h"
187 #include <SparseBuffer.h>
188 #include <T2Compress.h>
189 #include <T2Decompress.h>
190 #include "mct.h"
191 #include "grk_intmath.h"
192 #include "plugin_bridge.h"
193 #include "RateControl.h"
194 #include "RateInfo.h"
195 #include "T1Interface.h"
196 #include "T1Factory.h"
197 #include <T1DecompressScheduler.h>
198 #include <T1CompressScheduler.h>
The JPEG 2000 file format Reader/Writer (JP2)
Implementation of a packet iterator (PI)
Sparse buffer management.
static long grk_lrintf(float f)
Definition: grk_includes.h:135