iipsrv 1.2
iipsrv is an advanced high-performance feature-rich image server for web-based streamed viewing and zooming of ultra high-resolution images
Environment.h
1/*
2 IIP Environment Variable Class
3
4 Copyright (C) 2006-2023 Ruven Pillay.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software Foundation,
18 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19*/
20
21#ifndef _ENVIRONMENT_H
22#define _ENVIRONMENT_H
23
24
25/* Define some default values
26 */
27#define VERBOSITY 1
28#define LOGFILE "/tmp/iipsrv.log"
29#define MAX_IMAGE_CACHE_SIZE 10.0
30#define FILENAME_PATTERN "_pyr_"
31#define JPEG_QUALITY 75
32#define PNG_QUALITY 1
33#define WEBP_QUALITY 50
34#define MAX_CVT 5000
35#define MAX_LAYERS 0
36#define FILESYSTEM_PREFIX ""
37#define FILESYSTEM_SUFFIX ""
38#define WATERMARK ""
39#define WATERMARK_PROBABILITY 1.0
40#define WATERMARK_OPACITY 1.0
41#define LIBMEMCACHED_SERVERS "localhost"
42#define LIBMEMCACHED_TIMEOUT 86400 // 24 hours
43#define INTERPOLATION 1 // 1: Bilinear
44#define CORS "";
45#define BASE_URL "";
46#define CACHE_CONTROL "max-age=86400"; // 24 hours
47#define ALLOW_UPSCALING true
48#define URI_MAP ""
49#define EMBED_ICC true
50#define KAKADU_READMODE 0
51#define IIIF_VERSION 3
52
53
54#include <string>
55
56
59
60
61 public:
62
63 static int getVerbosity(){
64 int loglevel = VERBOSITY;
65 const char *envpara = getenv( "VERBOSITY" );
66 if( envpara ){
67 loglevel = atoi( envpara );
68 // If not a realistic level, set to zero
69 if( loglevel < 0 ) loglevel = 0;
70 }
71 return loglevel;
72 }
73
74
75 static std::string getLogFile(){
76 const char* envpara = getenv( "LOGFILE" );
77 if( envpara ) return std::string( envpara );
78 else return LOGFILE;
79 }
80
81
82 static float getMaxImageCacheSize(){
83 float max_image_cache_size = MAX_IMAGE_CACHE_SIZE;
84 const char* envpara = getenv( "MAX_IMAGE_CACHE_SIZE" );
85 if( envpara ){
86 max_image_cache_size = atof( envpara );
87 }
88 return max_image_cache_size;
89 }
90
91
92 static std::string getFileNamePattern(){
93 const char* envpara = getenv( "FILENAME_PATTERN" );
94 std::string filename_pattern;
95 if( envpara ){
96 filename_pattern = std::string( envpara );
97 }
98 else filename_pattern = FILENAME_PATTERN;
99
100 return filename_pattern;
101 }
102
103
104 static int getJPEGQuality(){
105 const char* envpara = getenv( "JPEG_QUALITY" );
106 int jpeg_quality;
107 if( envpara ){
108 jpeg_quality = atoi( envpara );
109 if( jpeg_quality > 100 ) jpeg_quality = 100;
110 if( jpeg_quality < 1 ) jpeg_quality = 1;
111 }
112 else jpeg_quality = JPEG_QUALITY;
113
114 return jpeg_quality;
115 }
116
117
118 static int getPNGQuality(){
119 const char* envpara = getenv( "PNG_QUALITY" );
120 int quality;
121 if( envpara ){
122 quality = atoi( envpara );
123 if( quality > 9 ) quality = 9;
124 if( quality < 0 ) quality = 0;
125 }
126 else quality = PNG_QUALITY;
127
128 return quality;
129 }
130
131
132 static int getWebPQuality(){
133 const char* envpara = getenv( "WEBP_QUALITY" );
134 int quality;
135 if( envpara ){
136 quality = atoi( envpara );
137 if( quality > 100 ) quality = 900;
138 if( quality < 0 ) quality = 0;
139 }
140 else quality = WEBP_QUALITY;
141
142 return quality;
143 }
144
145
146 static int getMaxCVT(){
147 const char* envpara = getenv( "MAX_CVT" );
148 int max_CVT;
149 if( envpara ){
150 max_CVT = atoi( envpara );
151 // -1 indicates no maximum. Otherwise minimum is 1
152 if( max_CVT < -1 ) max_CVT = 1;
153 // If zero, use default
154 else if( max_CVT == 0 ) max_CVT = MAX_CVT;
155 }
156 else max_CVT = MAX_CVT;
157
158 return max_CVT;
159 }
160
161
162 static int getMaxLayers(){
163 const char* envpara = getenv( "MAX_LAYERS" );
164 int layers;
165 if( envpara ) layers = atoi( envpara );
166 else layers = MAX_LAYERS;
167
168 return layers;
169 }
170
171
172 static std::string getFileSystemPrefix(){
173 const char* envpara = getenv( "FILESYSTEM_PREFIX" );
174 std::string filesystem_prefix;
175 if( envpara ){
176 filesystem_prefix = std::string( envpara );
177 }
178 else filesystem_prefix = FILESYSTEM_PREFIX;
179
180 return filesystem_prefix;
181 }
182
183
184 static std::string getFileSystemSuffix(){
185 const char* envpara = getenv( "FILESYSTEM_SUFFIX" );
186 std::string filesystem_suffix;
187 if( envpara ){
188 filesystem_suffix = std::string( envpara );
189 }
190 else filesystem_suffix = FILESYSTEM_SUFFIX;
191
192 return filesystem_suffix;
193 }
194
195
196 static std::string getWatermark(){
197 const char* envpara = getenv( "WATERMARK" );
198 std::string watermark;
199 if( envpara ){
200 watermark = std::string( envpara );
201 }
202 else watermark = WATERMARK;
203
204 return watermark;
205 }
206
207
208 static float getWatermarkProbability(){
209 float watermark_probability = WATERMARK_PROBABILITY;
210 const char* envpara = getenv( "WATERMARK_PROBABILITY" );
211
212 if( envpara ){
213 watermark_probability = atof( envpara );
214 if( watermark_probability > 1.0 ) watermark_probability = 1.0;
215 if( watermark_probability < 0 ) watermark_probability = 0.0;
216 }
217
218 return watermark_probability;
219 }
220
221
222 static float getWatermarkOpacity(){
223 float watermark_opacity = WATERMARK_OPACITY;
224 const char* envpara = getenv( "WATERMARK_OPACITY" );
225
226 if( envpara ){
227 watermark_opacity = atof( envpara );
228 if( watermark_opacity > 1.0 ) watermark_opacity = 1.0;
229 if( watermark_opacity < 0 ) watermark_opacity = 0.0;
230 }
231
232 return watermark_opacity;
233 }
234
235
236 static std::string getMemcachedServers(){
237 const char* envpara = getenv( "MEMCACHED_SERVERS" );
238 std::string memcached_servers;
239 if( envpara ){
240 memcached_servers = std::string( envpara );
241 }
242 else memcached_servers = LIBMEMCACHED_SERVERS;
243
244 return memcached_servers;
245 }
246
247
248 static unsigned int getMemcachedTimeout(){
249 const char* envpara = getenv( "MEMCACHED_TIMEOUT" );
250 unsigned int memcached_timeout;
251 if( envpara ) memcached_timeout = atoi( envpara );
252 else memcached_timeout = LIBMEMCACHED_TIMEOUT;
253
254 return memcached_timeout;
255 }
256
257
258 static unsigned int getInterpolation(){
259 const char* envpara = getenv( "INTERPOLATION" );
260 unsigned int interpolation;
261 if( envpara ) interpolation = atoi( envpara );
262 else interpolation = INTERPOLATION;
263
264 return interpolation;
265 }
266
267
268 static std::string getCORS(){
269 const char* envpara = getenv( "CORS" );
270 std::string cors;
271 if( envpara ) cors = std::string( envpara );
272 else cors = CORS;
273 return cors;
274 }
275
276
277 static std::string getBaseURL(){
278 const char* envpara = getenv( "BASE_URL" );
279 std::string base_url;
280 if( envpara ) base_url = std::string( envpara );
281 else base_url = BASE_URL;
282 return base_url;
283 }
284
285
286 static std::string getCacheControl(){
287 const char* envpara = getenv( "CACHE_CONTROL" );
288 std::string cache_control;
289 if( envpara ) cache_control = std::string( envpara );
290 else cache_control = CACHE_CONTROL;
291 return cache_control;
292 }
293
294
295 static bool getAllowUpscaling(){
296 const char* envpara = getenv( "ALLOW_UPSCALING" );
297 bool allow_upscaling;
298 if( envpara ) allow_upscaling = atoi( envpara ); // Implicit cast to boolean, all values other than '0' treated as true
299 else allow_upscaling = ALLOW_UPSCALING;
300 return allow_upscaling;
301 }
302
303
304 static std::string getURIMap(){
305 const char* envpara = getenv( "URI_MAP" );
306 std::string uri_map;
307 if( envpara ) uri_map = std::string( envpara );
308 else uri_map = URI_MAP;
309 return uri_map;
310 }
311
312
313 static unsigned int getEmbedICC(){
314 const char* envpara = getenv( "EMBED_ICC" );
315 bool embed;
316 if( envpara ) embed = atoi( envpara );
317 else embed = EMBED_ICC;
318 return embed;
319 }
320
321
322 static unsigned int getKduReadMode(){
323 unsigned int readmode;
324 const char* envpara = getenv( "KAKADU_READMODE" );
325 if( envpara ){
326 readmode = atoi( envpara );
327 if( readmode > 2 ) readmode = 2;
328 }
329 else readmode = KAKADU_READMODE;
330 return readmode;
331 }
332
333
334 static unsigned int getIIIFVersion(){
335 unsigned int version;
336 const char* envpara = getenv( "IIIF_VERSION" );
337 if( envpara ){
338 version = atoi( envpara );
339 if( version < 1 ) version = IIIF_VERSION;
340 }
341 else version = IIIF_VERSION;
342 return version;
343 }
344
345
346};
347
348
349#endif
Class to obtain environment variables.
Definition: Environment.h:58