iipsrv 1.1
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-2018 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 MAX_CVT 5000
33#define MAX_LAYERS 0
34#define FILESYSTEM_PREFIX ""
35#define WATERMARK ""
36#define WATERMARK_PROBABILITY 1.0
37#define WATERMARK_OPACITY 1.0
38#define LIBMEMCACHED_SERVERS "localhost"
39#define LIBMEMCACHED_TIMEOUT 86400 // 24 hours
40#define INTERPOLATION 1 // 1: Bilinear
41#define CORS "";
42#define BASE_URL "";
43#define CACHE_CONTROL "max-age=86400"; // 24 hours
44#define ALLOW_UPSCALING true
45#define URI_MAP ""
46#define EMBED_ICC true
47#define KAKADU_READMODE 0
48
49
50#include <string>
51
52
55
56
57 public:
58
59 static int getVerbosity(){
60 int loglevel = VERBOSITY;
61 char *envpara = getenv( "VERBOSITY" );
62 if( envpara ){
63 loglevel = atoi( envpara );
64 // If not a realistic level, set to zero
65 if( loglevel < 0 ) loglevel = 0;
66 }
67 return loglevel;
68 }
69
70
71 static std::string getLogFile(){
72 char* envpara = getenv( "LOGFILE" );
73 if( envpara ) return std::string( envpara );
74 else return LOGFILE;
75 }
76
77
78 static float getMaxImageCacheSize(){
79 float max_image_cache_size = MAX_IMAGE_CACHE_SIZE;
80 char* envpara = getenv( "MAX_IMAGE_CACHE_SIZE" );
81 if( envpara ){
82 max_image_cache_size = atof( envpara );
83 }
84 return max_image_cache_size;
85 }
86
87
88 static std::string getFileNamePattern(){
89 char* envpara = getenv( "FILENAME_PATTERN" );
90 std::string filename_pattern;
91 if( envpara ){
92 filename_pattern = std::string( envpara );
93 }
94 else filename_pattern = FILENAME_PATTERN;
95
96 return filename_pattern;
97 }
98
99
100 static int getJPEGQuality(){
101 char* envpara = getenv( "JPEG_QUALITY" );
102 int jpeg_quality;
103 if( envpara ){
104 jpeg_quality = atoi( envpara );
105 if( jpeg_quality > 100 ) jpeg_quality = 100;
106 if( jpeg_quality < 1 ) jpeg_quality = 1;
107 }
108 else jpeg_quality = JPEG_QUALITY;
109
110 return jpeg_quality;
111 }
112
113
114 static int getMaxCVT(){
115 char* envpara = getenv( "MAX_CVT" );
116 int max_CVT;
117 if( envpara ){
118 max_CVT = atoi( envpara );
119 if( max_CVT < 64 ) max_CVT = 64;
120 }
121 else max_CVT = MAX_CVT;
122
123 return max_CVT;
124 }
125
126
127 static int getMaxLayers(){
128 char* envpara = getenv( "MAX_LAYERS" );
129 int layers;
130 if( envpara ) layers = atoi( envpara );
131 else layers = MAX_LAYERS;
132
133 return layers;
134 }
135
136
137 static std::string getFileSystemPrefix(){
138 char* envpara = getenv( "FILESYSTEM_PREFIX" );
139 std::string filesystem_prefix;
140 if( envpara ){
141 filesystem_prefix = std::string( envpara );
142 }
143 else filesystem_prefix = FILESYSTEM_PREFIX;
144
145 return filesystem_prefix;
146 }
147
148
149 static std::string getWatermark(){
150 char* envpara = getenv( "WATERMARK" );
151 std::string watermark;
152 if( envpara ){
153 watermark = std::string( envpara );
154 }
155 else watermark = WATERMARK;
156
157 return watermark;
158 }
159
160
161 static float getWatermarkProbability(){
162 float watermark_probability = WATERMARK_PROBABILITY;
163 char* envpara = getenv( "WATERMARK_PROBABILITY" );
164
165 if( envpara ){
166 watermark_probability = atof( envpara );
167 if( watermark_probability > 1.0 ) watermark_probability = 1.0;
168 if( watermark_probability < 0 ) watermark_probability = 0.0;
169 }
170
171 return watermark_probability;
172 }
173
174
175 static float getWatermarkOpacity(){
176 float watermark_opacity = WATERMARK_OPACITY;
177 char* envpara = getenv( "WATERMARK_OPACITY" );
178
179 if( envpara ){
180 watermark_opacity = atof( envpara );
181 if( watermark_opacity > 1.0 ) watermark_opacity = 1.0;
182 if( watermark_opacity < 0 ) watermark_opacity = 0.0;
183 }
184
185 return watermark_opacity;
186 }
187
188
189 static std::string getMemcachedServers(){
190 char* envpara = getenv( "MEMCACHED_SERVERS" );
191 std::string memcached_servers;
192 if( envpara ){
193 memcached_servers = std::string( envpara );
194 }
195 else memcached_servers = LIBMEMCACHED_SERVERS;
196
197 return memcached_servers;
198 }
199
200
201 static unsigned int getMemcachedTimeout(){
202 char* envpara = getenv( "MEMCACHED_TIMEOUT" );
203 unsigned int memcached_timeout;
204 if( envpara ) memcached_timeout = atoi( envpara );
205 else memcached_timeout = LIBMEMCACHED_TIMEOUT;
206
207 return memcached_timeout;
208 }
209
210
211 static unsigned int getInterpolation(){
212 char* envpara = getenv( "INTERPOLATION" );
213 unsigned int interpolation;
214 if( envpara ) interpolation = atoi( envpara );
215 else interpolation = INTERPOLATION;
216
217 return interpolation;
218 }
219
220
221 static std::string getCORS(){
222 char* envpara = getenv( "CORS" );
223 std::string cors;
224 if( envpara ) cors = std::string( envpara );
225 else cors = CORS;
226 return cors;
227 }
228
229
230 static std::string getBaseURL(){
231 char* envpara = getenv( "BASE_URL" );
232 std::string base_url;
233 if( envpara ) base_url = std::string( envpara );
234 else base_url = BASE_URL;
235 return base_url;
236 }
237
238
239 static std::string getCacheControl(){
240 char* envpara = getenv( "CACHE_CONTROL" );
241 std::string cache_control;
242 if( envpara ) cache_control = std::string( envpara );
243 else cache_control = CACHE_CONTROL;
244 return cache_control;
245 }
246
247
248 static bool getAllowUpscaling(){
249 char* envpara = getenv( "ALLOW_UPSCALING" );
250 bool allow_upscaling;
251 if( envpara ) allow_upscaling = atoi( envpara ); // Implicit cast to boolean, all values other than '0' treated as true
252 else allow_upscaling = ALLOW_UPSCALING;
253 return allow_upscaling;
254 }
255
256
257 static std::string getURIMap(){
258 char* envpara = getenv( "URI_MAP" );
259 std::string uri_map;
260 if( envpara ) uri_map = std::string( envpara );
261 else uri_map = URI_MAP;
262 return uri_map;
263 }
264
265
266 static unsigned int getEmbedICC(){
267 char* envpara = getenv( "EMBED_ICC" );
268 bool embed;
269 if( envpara ) embed = atoi( envpara );
270 else embed = EMBED_ICC;
271 return embed;
272 }
273
274
275 static unsigned int getKduReadMode(){
276 unsigned int readmode;
277 char* envpara = getenv( "KAKADU_READMODE" );
278 if( envpara ){
279 readmode = atoi( envpara );
280 if( readmode > 2 ) readmode = 2;
281 }
282 else readmode = KAKADU_READMODE;
283 return readmode;
284 }
285
286};
287
288
289#endif
Class to obtain environment variables.
Definition: Environment.h:54