iipsrv 1.3
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-2025 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 MAX_METADATA_CACHE_SIZE 1000
31#define FILENAME_PATTERN "_pyr_"
32#define JPEG_QUALITY 75
33#define PNG_QUALITY 1
34#define WEBP_QUALITY 50
35#define AVIF_QUALITY 50
36#define AVIF_CODEC 0 // 0 = auto, 1 = aom, 2 = rav2e, 3 = svt
37#define TIFF_COMPRESSION 2 // 0=None, 1=LZW, 2=Deflate, 3=JPEG, 4=WebP, 5=ZStandard
38#define TIFF_QUALITY 1
39#define MAX_CVT 5000
40#define MAX_LAYERS 0
41#define FILESYSTEM_PREFIX ""
42#define FILESYSTEM_SUFFIX ""
43#define WATERMARK ""
44#define WATERMARK_PROBABILITY 1.0
45#define WATERMARK_OPACITY 1.0
46#define LIBMEMCACHED_SERVERS "localhost"
47#define LIBMEMCACHED_TIMEOUT 86400 // 24 hours
48#define INTERPOLATION 1 // 1: Bilinear
49#define CORS "";
50#define BASE_URL "";
51#define CACHE_CONTROL "max-age=86400"; // 24 hours
52#define ALLOW_UPSCALING true
53#define URI_MAP ""
54#define MAX_ICC 65536 // Max ICC profile size of 65k
55#define CODEC_PASSTHROUGH true
56#define KAKADU_READMODE 0
57#define IIIF_VERSION 3
58#define IIIF_DELIMITER ""
59#define IIIF_EXTRA_INFO ""
60#define IIIF_EXTENSIONS false
61#define COPYRIGHT ""
62
63
64#include <string>
65
66
69
70 public:
71
72 static int getVerbosity(){
73 int loglevel = VERBOSITY;
74 const char *envpara = getenv( "VERBOSITY" );
75 if( envpara ){
76 loglevel = atoi( envpara );
77 // If not a realistic level, set to zero
78 if( loglevel < 0 ) loglevel = 0;
79 }
80 return loglevel;
81 }
82
83
84 static std::string getLogFile(){
85 const char* envpara = getenv( "LOGFILE" );
86 if( envpara ) return std::string( envpara );
87 else return LOGFILE;
88 }
89
90
91 static float getMaxImageCacheSize(){
92 float max_image_cache_size = MAX_IMAGE_CACHE_SIZE;
93 const char* envpara = getenv( "MAX_IMAGE_CACHE_SIZE" );
94 if( envpara ){
95 max_image_cache_size = atof( envpara );
96 }
97 return max_image_cache_size;
98 }
99
100
101 static long getMaxMetadataCacheSize(){
102 long max_metadata_cache_size = MAX_METADATA_CACHE_SIZE;
103 const char* envpara = getenv( "MAX_METADATA_CACHE_SIZE" );
104 if( envpara ){
105 max_metadata_cache_size = atol( envpara );
106 }
107 return max_metadata_cache_size;
108 }
109
110
111 static std::string getFileNamePattern(){
112 const char* envpara = getenv( "FILENAME_PATTERN" );
113 std::string filename_pattern;
114 if( envpara ){
115 filename_pattern = std::string( envpara );
116 }
117 else filename_pattern = FILENAME_PATTERN;
118
119 return filename_pattern;
120 }
121
122
123 static int getJPEGQuality(){
124 const char* envpara = getenv( "JPEG_QUALITY" );
125 int jpeg_quality;
126 if( envpara ){
127 jpeg_quality = atoi( envpara );
128 if( jpeg_quality > 100 ) jpeg_quality = 100;
129 if( jpeg_quality < 1 ) jpeg_quality = 1;
130 }
131 else jpeg_quality = JPEG_QUALITY;
132
133 return jpeg_quality;
134 }
135
136
137 static int getPNGQuality(){
138 const char* envpara = getenv( "PNG_QUALITY" );
139 int quality;
140 if( envpara ){
141 quality = atoi( envpara );
142 if( quality > 9 ) quality = 9;
143 if( quality < 0 ) quality = 0;
144 }
145 else quality = PNG_QUALITY;
146
147 return quality;
148 }
149
150
151 static int getWebPQuality(){
152 const char* envpara = getenv( "WEBP_QUALITY" );
153 int quality;
154 if( envpara ){
155 quality = atoi( envpara );
156 if( quality > 100 ) quality = 100;
157 if( quality < -1 ) quality = -1; // Allow -1 = lossless
158 }
159 else quality = WEBP_QUALITY;
160
161 return quality;
162 }
163
164
165 static int getAVIFQuality(){
166 const char* envpara = getenv( "AVIF_QUALITY" );
167 int quality;
168 if( envpara ){
169 quality = atoi( envpara );
170 if( quality > 100 ) quality = 100;
171 if( quality < -1 ) quality = -1; // Allow -1 = lossless
172 }
173 else quality = AVIF_QUALITY;
174
175 return quality;
176 }
177
178
180 static int getTIFFCompression(){
181 const char* envpara = getenv( "TIFF_COMPRESSION" );
182 int compression;
183 if( envpara ){
184 compression = atoi( envpara );
185 if( compression < 0 || compression > 4 ) compression = 0;
186 }
187 else compression = TIFF_COMPRESSION;
188
189 return compression;
190 }
191
192
193 static int getTIFFQuality(){
194 const char* envpara = getenv( "TIFF_QUALITY" );
195 int quality;
196 if( envpara ){
197 quality = atoi( envpara );
198 if( quality < 0 ) quality = 0;
199 if( quality > 100 ) quality = 100;
200 }
201 else quality = TIFF_QUALITY;
202
203 return quality;
204 }
205
206
207 static unsigned int getAVIFCodec(){
208 unsigned int codec;
209 const char* envpara = getenv( "AVIF_CODEC" );
210 if( envpara ){
211 codec = atoi( envpara );
212 if( codec > 3 ) codec = 0;
213 }
214 else codec = AVIF_CODEC;
215 return codec;
216 }
217
218
219 static int getMaxCVT(){
220 const char* envpara = getenv( "MAX_CVT" );
221 int max_CVT;
222 if( envpara ){
223 max_CVT = atoi( envpara );
224 // -1 indicates no maximum. Otherwise minimum is 1
225 if( max_CVT < -1 ) max_CVT = 1;
226 // If zero, use default
227 else if( max_CVT == 0 ) max_CVT = MAX_CVT;
228 }
229 else max_CVT = MAX_CVT;
230
231 return max_CVT;
232 }
233
234
235 static int getMaxLayers(){
236 const char* envpara = getenv( "MAX_LAYERS" );
237 int layers;
238 if( envpara ) layers = atoi( envpara );
239 else layers = MAX_LAYERS;
240
241 return layers;
242 }
243
244
245 static std::string getFileSystemPrefix(){
246 const char* envpara = getenv( "FILESYSTEM_PREFIX" );
247 std::string filesystem_prefix;
248 if( envpara ){
249 filesystem_prefix = std::string( envpara );
250 }
251 else filesystem_prefix = FILESYSTEM_PREFIX;
252 return filesystem_prefix;
253 }
254
255
256 static std::string getFileSystemSuffix(){
257 const char* envpara = getenv( "FILESYSTEM_SUFFIX" );
258 std::string filesystem_suffix;
259 if( envpara ){
260 filesystem_suffix = std::string( envpara );
261 }
262 else filesystem_suffix = FILESYSTEM_SUFFIX;
263
264 return filesystem_suffix;
265 }
266
267
268 static std::string getWatermark(){
269 const char* envpara = getenv( "WATERMARK" );
270 std::string watermark;
271 if( envpara ){
272 watermark = std::string( envpara );
273 }
274 else watermark = WATERMARK;
275
276 return watermark;
277 }
278
279
280 static float getWatermarkProbability(){
281 float watermark_probability = WATERMARK_PROBABILITY;
282 const char* envpara = getenv( "WATERMARK_PROBABILITY" );
283
284 if( envpara ){
285 watermark_probability = atof( envpara );
286 if( watermark_probability > 1.0 ) watermark_probability = 1.0;
287 if( watermark_probability < 0 ) watermark_probability = 0.0;
288 }
289
290 return watermark_probability;
291 }
292
293
294 static float getWatermarkOpacity(){
295 float watermark_opacity = WATERMARK_OPACITY;
296 const char* envpara = getenv( "WATERMARK_OPACITY" );
297
298 if( envpara ){
299 watermark_opacity = atof( envpara );
300 if( watermark_opacity > 1.0 ) watermark_opacity = 1.0;
301 if( watermark_opacity < 0 ) watermark_opacity = 0.0;
302 }
303
304 return watermark_opacity;
305 }
306
307
308 static std::string getMemcachedServers(){
309 const char* envpara = getenv( "MEMCACHED_SERVERS" );
310 std::string memcached_servers;
311 if( envpara ){
312 memcached_servers = std::string( envpara );
313 }
314 else memcached_servers = LIBMEMCACHED_SERVERS;
315
316 return memcached_servers;
317 }
318
319
320 static unsigned int getMemcachedTimeout(){
321 const char* envpara = getenv( "MEMCACHED_TIMEOUT" );
322 unsigned int memcached_timeout;
323 if( envpara ) memcached_timeout = atoi( envpara );
324 else memcached_timeout = LIBMEMCACHED_TIMEOUT;
325
326 return memcached_timeout;
327 }
328
329
330 static unsigned int getInterpolation(){
331 const char* envpara = getenv( "INTERPOLATION" );
332 unsigned int interpolation;
333 if( envpara ) interpolation = atoi( envpara );
334 else interpolation = INTERPOLATION;
335
336 return interpolation;
337 }
338
339
340 static std::string getCORS(){
341 const char* envpara = getenv( "CORS" );
342 std::string cors;
343 if( envpara ) cors = std::string( envpara );
344 else cors = CORS;
345 return cors;
346 }
347
348
349 static std::string getBaseURL(){
350 const char* envpara = getenv( "BASE_URL" );
351 std::string base_url;
352 if( envpara ) base_url = std::string( envpara );
353 else base_url = BASE_URL;
354 return base_url;
355 }
356
357
358 static std::string getCacheControl(){
359 const char* envpara = getenv( "CACHE_CONTROL" );
360 std::string cache_control;
361 if( envpara ) cache_control = std::string( envpara );
362 else cache_control = CACHE_CONTROL;
363 return cache_control;
364 }
365
366
367 static bool getAllowUpscaling(){
368 const char* envpara = getenv( "ALLOW_UPSCALING" );
369 bool allow_upscaling;
370 if( envpara ) allow_upscaling = atoi( envpara ); // Implicit cast to boolean, all values other than '0' treated as true
371 else allow_upscaling = ALLOW_UPSCALING;
372 return allow_upscaling;
373 }
374
375
376 static std::string getURIMap(){
377 const char* envpara = getenv( "URI_MAP" );
378 std::string uri_map;
379 if( envpara ) uri_map = std::string( envpara );
380 else uri_map = URI_MAP;
381 return uri_map;
382 }
383
384
385 static int getMaxICC(){
386 const char* envpara = getenv( "MAX_ICC" );
387 int max_icc;
388 if( envpara ){
389 max_icc = atoi( envpara );
390 }
391 else max_icc = MAX_ICC;
392 return max_icc;
393 }
394
395
396 static bool getCodecPassthrough(){
397 const char* envpara = getenv( "CODEC_PASSTHROUGH" );
398 bool codec_passthrough;
399 if( envpara ) codec_passthrough = atoi( envpara ); // Implicit cast to boolean, all values other than '0' treated as true
400 else codec_passthrough = CODEC_PASSTHROUGH;
401 return codec_passthrough;
402 }
403
404
405 static unsigned int getKduReadMode(){
406 unsigned int readmode;
407 const char* envpara = getenv( "KAKADU_READMODE" );
408 if( envpara ){
409 readmode = atoi( envpara );
410 if( readmode > 2 ) readmode = 2;
411 }
412 else readmode = KAKADU_READMODE;
413 return readmode;
414 }
415
416
417 static unsigned int getIIIFVersion(){
418 unsigned int version;
419 const char* envpara = getenv( "IIIF_VERSION" );
420 if( envpara ){
421 version = atoi( envpara );
422 if( version < 1 ) version = IIIF_VERSION;
423 }
424 else version = IIIF_VERSION;
425 return version;
426 }
427
428
429 static std::string getIIIFDelimiter(){
430 const char* envpara = getenv( "IIIF_DELIMITER" );
431 if( envpara ) return std::string( envpara );
432 else return IIIF_DELIMITER;
433 }
434
435
436 static std::string getIIIFExtraInfo(){
437 const char* envpara = getenv( "IIIF_EXTRA_INFO" );
438 if( envpara ) return std::string( envpara );
439 else return IIIF_EXTRA_INFO;
440 }
441
442
443 static bool getIIIFExtensions(){
444 const char* envpara = getenv( "IIIF_EXTENSIONS" );
445 bool extensions;
446 if( envpara ) extensions = atoi( envpara ); // Implicit cast to boolean, all values other than '0' treated as true
447 else extensions = IIIF_EXTENSIONS;
448 return extensions;
449 }
450
451
452 static std::string getCopyright(){
453 const char* envpara = getenv( "COPYRIGHT" );
454 if( envpara ) return std::string( envpara );
455 else return COPYRIGHT;
456 }
457
458};
459
460
461#endif
Class to obtain environment variables.
Definition Environment.h:68
static int getTIFFCompression()
0: None, 1: LZW, 2: Deflate, 3: JPEG, 4: WebP
Definition Environment.h:180