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
View.h
1/*
2 Image View and Transform Parameters
3
4 Copyright (C) 2003-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
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19*/
20
21
22#ifndef _VIEW_H
23#define _VIEW_H
24
25
26#include <cstddef>
27#include <vector>
28
29#include "Transforms.h"
30
31
32
33
35
36class View{
37
38
39 private:
40
41 // Resolution independent x,y,w,h region viewport in range 0 -> 1.0
42 float view_left, view_top, view_width, view_height;
43
44 int resolution;
45 unsigned int max_resolutions;
46 unsigned int width, height;
47 unsigned int res_width, res_height;
48 unsigned int min_size;
49 int max_size;
50 unsigned int requested_width;
51 unsigned int requested_height;
52 float rotation;
53
54
57
60 void calculateResolution( unsigned int m, unsigned int r );
61
62
63 public:
64
65 int xangle;
66 int yangle;
67 bool shaded;
68 int shade[3];
69 bool cmapped;
70 enum cmap_type cmap;
71 bool inverted;
73 int layers;
74 ColorSpace colorspace;
75 std::vector< std::vector<float> > ctw;
76 int flip;
79 int max_icc;
80 ImageEncoding output_format;
81 float contrast;
82 float gamma;
83 std::vector<float> convolution;
85 bool minmax;
86
87
89 View() {
90 view_left = 0.0; view_top = 0.0; view_width = 1.0; view_height = 1.0;
91 resolution = 0; max_resolutions = 0;
92 width = 0; height = 0;
93 res_width = 0; res_height = 0;
94 min_size = 1; max_size = 0;
95 requested_width = 0; requested_height = 0;
96 contrast = 1.0; gamma = 1.0;
97 xangle = 0; yangle = 90;
98 shaded = false; shade[0] = 0; shade[1] = 0; shade[2] = 0;
99 cmapped = false; cmap = HOT; inverted = false;
100 max_layers = 0; layers = 0;
101 rotation = 0.0; flip = 0;
102 maintain_aspect = true;
103 allow_upscaling = true;
104 colorspace = ColorSpace::NONE;
105 max_icc = -1;
106 output_format = ImageEncoding::JPEG;
107 equalization = false;
108 minmax = false;
109 };
110
111
113
114 void setMaxSize( int m ){ max_size = m; };
115
116
118
119 int getMaxSize(){ return max_size; };
120
121
123
124 unsigned int getMinSize(){ return min_size; };
125
126
128
129 void setAllowUpscaling( bool upscale ){ allow_upscaling = upscale; };
130
131
133
135
136
138
140 void setMaxICC( int max ){ max_icc = max; };
141
142
144
146 int maxICC(){
147 // Disable if colour-mapping, twist, hill-shading or greyscale conversion applied
148 if( cmapped || shaded || ctw.size() || colorspace==ColorSpace::GREYSCALE ) return 0;
149 return max_icc;
150 }
151
152
154
155 void setMaxResolutions( unsigned int r ){ max_resolutions = r; resolution=r-1; };
156
157
159
160 void setRequestWidth( unsigned int w ){
161 requested_width = w;
162 };
163
164
166
167 std::vector<unsigned int> getRequestSize();
168
169
171
172 void setRequestHeight( unsigned int h ){
173 requested_height = h;
174 };
175
176
178
179 unsigned int getResolution();
180
181
183
184 float getScale();
185
186
188
189 void setViewLeft( float x );
190
191
193
194 void setViewTop( float y );
195
196
198
199 void setViewWidth( float w );
200
201
203
204 void setViewHeight( float h );
205
206
208
209 std::vector<float> getViewSize(){
210 std::vector<float> size = { width*view_width, height*view_height };
211 return size;
212 };
213
214
216
219 void setImageSize( unsigned int w, unsigned int h ){ width = w; height = h; };
220
221
223
224 void setMaxLayers( int l ){ max_layers = l; };
225
227
228 void setLayers( int l ){ layers = l; };
229
231 int getLayers();
232
234
235 unsigned int getImageWidth(){ return width; };
236
238
239 unsigned int getImageHeight(){ return height; };
240
242
243 unsigned int getViewLeft() ;
244
246
247 unsigned int getViewTop();
248
250
251 unsigned int getViewWidth();
252
254
255 unsigned int getViewHeight();
256
258
259 bool viewPortSet();
260
262
263 void setRotation( float r ){ rotation = r; };
264
266
267 float getRotation(){ return rotation; };
268
271 if( contrast != 1.0 || gamma != 1.0 || cmapped || shaded || inverted || minmax || ctw.size() || convolution.size() ){
272 return true;
273 }
274 else return false;
275 }
276
279 if( equalization || colorspace==ColorSpace::BINARY || contrast==-1 ) return true;
280 else return false;
281 }
282
283};
284
285
286#endif
Class to intelligently handle Image Transforms.
Definition View.h:36
void setMaxICC(int max)
Set the maximum ICC profile size we allow to be embedded.
Definition View.h:140
float contrast
Contrast adjustment requested by CNT command.
Definition View.h:81
bool viewPortSet()
Indicate whether the viewport has been set.
Definition View.cc:160
std::vector< unsigned int > getRequestSize()
Get requested image size.
Definition View.cc:217
unsigned int getViewWidth()
Return the pixel width of the viewport.
Definition View.cc:187
void setMaxSize(int m)
Set the maximum view port dimension.
Definition View.h:114
unsigned int getViewTop()
Return the top pixel of the viewport.
Definition View.cc:178
int yangle
Vertical View.
Definition View.h:66
unsigned int getResolution()
Return the resolution level needed for the requested view.
Definition View.cc:55
unsigned int getMinSize()
Get the minimum allowed output size.
Definition View.h:124
void setViewTop(float y)
Set the top co-ordinate of the viewport.
Definition View.cc:137
float getScale()
Return the scaling required in case our requested width or height is in between available resolutions...
Definition View.cc:101
unsigned int getViewLeft()
Return the left pixel of the viewport.
Definition View.cc:169
int max_icc
Maximum ICC profile size we allow to be embedded.
Definition View.h:79
void setViewWidth(float w)
Set the width co-ordinate of the viewport.
Definition View.cc:144
View()
Constructor.
Definition View.h:89
std::vector< float > convolution
Convolution matrix.
Definition View.h:83
bool requireHistogram()
Whether we require a histogram.
Definition View.h:278
bool minmax
Whether to perform contrast stretching using user-defined min/max.
Definition View.h:85
int flip
Flip (1=horizontal, 2=vertical)
Definition View.h:76
bool maintain_aspect
Indicate whether aspect ratio should be maintained.
Definition View.h:77
bool equalization
Whether to perform histogram equalization.
Definition View.h:84
float getRotation()
Get rotation.
Definition View.h:267
bool shaded
Whether to use shading view.
Definition View.h:67
int max_layers
Maximum number of quality layers allowed.
Definition View.h:72
float gamma
Gamma adjustment requested by GAM command.
Definition View.h:82
ColorSpace colorspace
Requested colorspace.
Definition View.h:74
int shade[3]
Shading incident light angles (x,y,z)
Definition View.h:68
int getMaxSize()
Get the maximum allowed output size.
Definition View.h:119
int maxICC()
Get the maximum ICC profile size we allow to be embedded - disable if certain processing has been car...
Definition View.h:146
void setRequestWidth(unsigned int w)
Set the size of the requested width.
Definition View.h:160
int xangle
Horizontal View.
Definition View.h:65
bool allow_upscaling
Indicate whether images may be served larger than the source file.
Definition View.h:78
std::vector< float > getViewSize()
Return the view dimensions scaled to the full resolution of the image.
Definition View.h:209
unsigned int getImageHeight()
Return the image height at our requested resolution.
Definition View.h:239
void setMaxResolutions(unsigned int r)
Set the maximum view port dimension.
Definition View.h:155
int getLayers()
Return the number of layers to decode.
Definition View.cc:268
bool cmapped
Whether to modify colormap.
Definition View.h:69
unsigned int getImageWidth()
Return the image width at our requested resolution.
Definition View.h:235
int layers
Number of quality layers.
Definition View.h:73
ImageEncoding output_format
Requested output format.
Definition View.h:80
void setImageSize(unsigned int w, unsigned int h)
Set the source image pixel size.
Definition View.h:219
void setViewHeight(float h)
Set the height co-ordinate of the viewport.
Definition View.cc:152
bool allowUpscaling()
Get the allow_upscaling flag.
Definition View.h:134
void setMaxLayers(int l)
Limit the maximum number of quality layers we are allowed to decode.
Definition View.h:224
void setAllowUpscaling(bool upscale)
Set the allow_upscaling flag.
Definition View.h:129
bool floatProcessing()
Whether view requires floating point processing.
Definition View.h:270
void setViewLeft(float x)
Set the left co-ordinate of the viewport.
Definition View.cc:130
void setRotation(float r)
Set rotation.
Definition View.h:263
enum cmap_type cmap
colormap
Definition View.h:70
void setRequestHeight(unsigned int h)
Set the size of the requested height.
Definition View.h:172
bool inverted
Whether to invert colormap.
Definition View.h:71
unsigned int getViewHeight()
Return the pixel height of the viewport.
Definition View.cc:202
void setLayers(int l)
Set the number of quality layers to decode, limiting to our max value.
Definition View.h:228
std::vector< std::vector< float > > ctw
Colour twist matrix.
Definition View.h:75