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
IIPImage.h
1 // IIPImage class
2 
3 /* IIP fcgi server module
4 
5  Copyright (C) 2000-2019 Ruven Pillay.
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software Foundation,
19  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21 
22 
23 #ifndef _IIPIMAGE_H
24 #define _IIPIMAGE_H
25 
26 
27 // Fix missing snprintf in Windows
28 #if defined _MSC_VER && _MSC_VER<1900
29 #define snprintf _snprintf
30 #endif
31 
32 
33 #include <string>
34 #include <list>
35 #include <vector>
36 #include <map>
37 #include <stdexcept>
38 
39 #include "RawTile.h"
40 
41 
43 class file_error : public std::runtime_error {
44  public:
46  file_error(std::string s) : std::runtime_error(s) { }
47 };
48 
49 
50 // Supported image formats
51 enum ImageFormat { TIF, JPEG2000, UNSUPPORTED };
52 
53 
54 
56 
62 class IIPImage {
63 
64  private:
65 
67  std::string imagePath;
68 
70  std::string fileSystemPrefix;
71 
73  std::string fileNamePattern;
74 
76  bool isFile;
77 
79  std::string suffix;
80 
82  void testImageType();
83 
85  void measureHorizontalAngles();
86 
88  void measureVerticalAngles();
89 
91  std::list <int> horizontalAnglesList;
92 
94  std::list <int> verticalAnglesList;
95 
96 
97  protected:
98 
100  std::vector <int> lut;
101 
103  unsigned int virtual_levels;
104 
106  ImageFormat format;
107 
108 
109  public:
110 
112  std::vector <unsigned int> image_widths, image_heights;
113 
115  unsigned int tile_width, tile_height;
116 
118  ColourSpaces colourspace;
119 
121  unsigned int numResolutions;
122 
124  unsigned int bpc;
125 
127  unsigned int channels;
128 
130  SampleType sampleType;
131 
133  std::vector <float> min, max;
134 
136  unsigned int quality_layers;
137 
139  bool isSet;
140 
142  int currentX, currentY;
143 
145  std::vector<unsigned int> histogram;
146 
148  std::map <const std::string, std::string> metadata;
149 
151  time_t timestamp;
152 
153 
154  public:
155 
158  : isFile( false ),
159  virtual_levels( 0 ),
160  format( UNSUPPORTED ),
161  tile_width( 0 ),
162  tile_height( 0 ),
163  colourspace( NONE ),
164  numResolutions( 0 ),
165  bpc( 0 ),
166  channels( 0 ),
167  sampleType( FIXEDPOINT ),
168  quality_layers( 0 ),
169  isSet( false ),
170  currentX( 0 ),
171  currentY( 90 ),
172  timestamp( 0 ) {};
173 
175 
177  IIPImage( const std::string& s )
178  : imagePath( s ),
179  isFile( false ),
180  virtual_levels( 0 ),
181  format( UNSUPPORTED ),
182  tile_width( 0 ),
183  tile_height( 0 ),
184  colourspace( NONE ),
185  numResolutions( 0 ),
186  bpc( 0 ),
187  channels( 0 ),
188  sampleType( FIXEDPOINT ),
189  quality_layers( 0 ),
190  isSet( false ),
191  currentX( 0 ),
192  currentY( 90 ),
193  timestamp( 0 ) {};
194 
196 
198  IIPImage( const IIPImage& image )
199  : imagePath( image.imagePath ),
200  fileSystemPrefix( image.fileSystemPrefix ),
201  fileNamePattern( image.fileNamePattern ),
202  isFile( image.isFile ),
203  suffix( image.suffix ),
204  horizontalAnglesList( image.horizontalAnglesList ),
205  verticalAnglesList( image.verticalAnglesList ),
206  lut( image.lut ),
208  format( image.format ),
209  image_widths( image.image_widths ),
210  image_heights( image.image_heights ),
211  tile_width( image.tile_width ),
212  tile_height( image.tile_height ),
213  colourspace( image.colourspace ),
215  bpc( image.bpc ),
216  channels( image.channels ),
217  sampleType( image.sampleType ),
218  min( image.min ),
219  max( image.max ),
221  isSet( image.isSet ),
222  currentX( image.currentX ),
223  currentY( image.currentY ),
224  histogram( image.histogram ),
225  metadata( image.metadata ),
226  timestamp( image.timestamp ) {};
227 
229  virtual ~IIPImage() { ; };
230 
232  void Initialise();
233 
235 
238  void swap( IIPImage& a, IIPImage& b );
239 
241  std::list <int> getVerticalViewsList(){ return verticalAnglesList; };
242 
244  std::list <int> getHorizontalViewsList(){ return horizontalAnglesList; };
245 
247  const std::string& getImagePath() { return imagePath; };
248 
250 
253  const std::string getFileName( int x, int y );
254 
256  // const std::string& getImageFormat() { return format; };
257  ImageFormat getImageFormat() { return format; };
258 
260 
262  void updateTimestamp( const std::string& s );
263 
265  const std::string getTimestamp();
266 
268  bool set() { return isSet; };
269 
271  void setFileSystemPrefix( const std::string& prefix ) { fileSystemPrefix = prefix; };
272 
274  void setFileNamePattern( const std::string& pattern ) { fileNamePattern = pattern; };
275 
277  unsigned int getNumResolutions() { return numResolutions; };
278 
280  unsigned int getNumBitsPerPixel() { return bpc; };
281 
283  unsigned int getNumChannels() { return channels; };
284 
286 
288  float getMinValue( int n=0 ) { return min[n]; };
289 
291 
293  float getMaxValue( int n=0 ) { return max[n]; };
294 
296  SampleType getSampleType(){ return sampleType; };
297 
299 
301  unsigned int getImageWidth( int n=0 ) { return image_widths[n]; };
302 
304 
306  unsigned int getImageHeight( int n=0 ) { return image_heights[n]; };
307 
309  unsigned int getTileHeight() { return tile_height; };
310 
312  unsigned int getTileWidth() { return tile_width; };
313 
315  ColourSpaces getColourSpace() { return colourspace; };
316 
318 
319  const std::string& getMetadata( const std::string& index ) {
320  return metadata[index];
321  };
322 
324  virtual bool regionDecoding(){ return false; };
325 
327 
330  virtual void Load( const std::string& module ) {;};
331 
333  virtual const std::string getDescription() { return std::string( "IIPImage Base Class" ); };
334 
336  virtual void openImage() { throw file_error( "IIPImage openImage called" ); };
337 
339 
342  virtual void loadImageInfo( int x, int y ) { ; };
343 
345  virtual void closeImage() {;};
346 
347 
349 
356  virtual RawTile getTile( int h, int v, unsigned int r, int l, unsigned int t ) { return RawTile(); };
357 
358 
360 
371  virtual RawTile getRegion( int ha, int va, unsigned int r, int layers, int x, int y, unsigned int w, unsigned int h ){ return RawTile(); };
372 
374 
376  swap( *this, image );
377  return *this;
378  };
379 
381  friend int operator == ( const IIPImage&, const IIPImage& );
382 
384  friend int operator != ( const IIPImage&, const IIPImage& );
385 
386 };
387 
388 
389 #endif
IIPImage::timestamp
time_t timestamp
Image modification timestamp.
Definition: IIPImage.h:151
IIPImage::setFileNamePattern
void setFileNamePattern(const std::string &pattern)
Set the file name pattern used in image sequences.
Definition: IIPImage.h:274
IIPImage::getHorizontalViewsList
std::list< int > getHorizontalViewsList()
Return a list of horizontal angles.
Definition: IIPImage.h:244
IIPImage::format
ImageFormat format
Return the image format e.g. tif.
Definition: IIPImage.h:106
IIPImage::sampleType
SampleType sampleType
The sample format type (fixed or floating point)
Definition: IIPImage.h:130
IIPImage::getTimestamp
const std::string getTimestamp()
Get a HTTP RFC 1123 formatted timestamp.
IIPImage::IIPImage
IIPImage(const IIPImage &image)
Copy Constructor taking reference to another IIPImage object.
Definition: IIPImage.h:198
IIPImage::operator==
friend int operator==(const IIPImage &, const IIPImage &)
Comparison equality operator.
IIPImage
Main class to handle the pyramidal image source.
Definition: IIPImage.h:62
IIPImage::metadata
std::map< const std::string, std::string > metadata
STL map to hold string metadata.
Definition: IIPImage.h:148
IIPImage::tile_width
unsigned int tile_width
The base tile pixel dimensions.
Definition: IIPImage.h:115
IIPImage::getFileName
const std::string getFileName(int x, int y)
Return the full file path for a particular horizontal and vertical angle.
IIPImage::currentX
int currentX
If we have an image sequence, the current X and Y position.
Definition: IIPImage.h:142
IIPImage::updateTimestamp
void updateTimestamp(const std::string &s)
Get the image timestamp.
IIPImage::Load
virtual void Load(const std::string &module)
Load the appropriate codec module for this image type.
Definition: IIPImage.h:330
IIPImage::IIPImage
IIPImage(const std::string &s)
Constructer taking the image path as parameter.
Definition: IIPImage.h:177
IIPImage::getColourSpace
ColourSpaces getColourSpace()
Return the colour space for this image.
Definition: IIPImage.h:315
IIPImage::getImageHeight
unsigned int getImageHeight(int n=0)
Return the image height in pixels for a given resolution.
Definition: IIPImage.h:306
IIPImage::swap
void swap(IIPImage &a, IIPImage &b)
Swap function.
IIPImage::~IIPImage
virtual ~IIPImage()
Virtual Destructor.
Definition: IIPImage.h:229
IIPImage::operator!=
friend int operator!=(const IIPImage &, const IIPImage &)
Comparison non-equality operator.
IIPImage::closeImage
virtual void closeImage()
Close the image: Overloaded by child class.
Definition: IIPImage.h:345
IIPImage::channels
unsigned int channels
The number of channels for this image.
Definition: IIPImage.h:127
IIPImage::colourspace
ColourSpaces colourspace
The colour space of the image.
Definition: IIPImage.h:118
IIPImage::getNumResolutions
unsigned int getNumResolutions()
Return the number of available resolutions in the image.
Definition: IIPImage.h:277
IIPImage::getNumBitsPerPixel
unsigned int getNumBitsPerPixel()
Return the number of bits per pixel for this image.
Definition: IIPImage.h:280
IIPImage::min
std::vector< float > min
The min and max sample value for each channel.
Definition: IIPImage.h:133
IIPImage::getMetadata
const std::string & getMetadata(const std::string &index)
Return image metadata.
Definition: IIPImage.h:319
file_error
Define our own derived exception class for file errors.
Definition: IIPImage.h:43
IIPImage::getImageFormat
ImageFormat getImageFormat()
Get the image format.
Definition: IIPImage.h:257
IIPImage::getMaxValue
float getMaxValue(int n=0)
Return the minimum sample value for each channel.
Definition: IIPImage.h:293
IIPImage::bpc
unsigned int bpc
The bits per channel for this image.
Definition: IIPImage.h:124
IIPImage::isSet
bool isSet
Indicate whether we have opened and initialised some parameters for this image.
Definition: IIPImage.h:139
IIPImage::loadImageInfo
virtual void loadImageInfo(int x, int y)
Load information about the image eg. number of channels, tile size etc.
Definition: IIPImage.h:342
IIPImage::Initialise
void Initialise()
Test the image and initialise some parameters.
IIPImage::getImageWidth
unsigned int getImageWidth(int n=0)
Return the image width in pixels for a given resolution.
Definition: IIPImage.h:301
IIPImage::getTile
virtual RawTile getTile(int h, int v, unsigned int r, int l, unsigned int t)
Return an individual tile for a given angle and resolution.
Definition: IIPImage.h:356
IIPImage::operator=
IIPImage & operator=(IIPImage image)
Assignment operator.
Definition: IIPImage.h:375
IIPImage::numResolutions
unsigned int numResolutions
The number of available resolutions in this image.
Definition: IIPImage.h:121
IIPImage::openImage
virtual void openImage()
Open the image: Overloaded by child class.
Definition: IIPImage.h:336
IIPImage::setFileSystemPrefix
void setFileSystemPrefix(const std::string &prefix)
Set a file system prefix for added security.
Definition: IIPImage.h:271
IIPImage::set
bool set()
Check whether this object has been initialised.
Definition: IIPImage.h:268
IIPImage::lut
std::vector< int > lut
LUT.
Definition: IIPImage.h:100
RawTile
Class to represent a single image tile.
Definition: RawTile.h:45
IIPImage::image_widths
std::vector< unsigned int > image_widths
The image pixel dimensions.
Definition: IIPImage.h:112
file_error::file_error
file_error(std::string s)
Definition: IIPImage.h:46
IIPImage::histogram
std::vector< unsigned int > histogram
Image histogram.
Definition: IIPImage.h:145
IIPImage::quality_layers
unsigned int quality_layers
Quality layers.
Definition: IIPImage.h:136
IIPImage::virtual_levels
unsigned int virtual_levels
Number of resolution levels that don't physically exist in file.
Definition: IIPImage.h:103
IIPImage::getDescription
virtual const std::string getDescription()
Return codec description: Overloaded by child class.
Definition: IIPImage.h:333
IIPImage::getTileHeight
unsigned int getTileHeight()
Return the base tile height in pixels for a given resolution.
Definition: IIPImage.h:309
IIPImage::getSampleType
SampleType getSampleType()
Return the sample format type.
Definition: IIPImage.h:296
IIPImage::regionDecoding
virtual bool regionDecoding()
Return whether this image type directly handles region decoding.
Definition: IIPImage.h:324
IIPImage::getTileWidth
unsigned int getTileWidth()
Return the base tile width in pixels.
Definition: IIPImage.h:312
IIPImage::getImagePath
const std::string & getImagePath()
Return the image path.
Definition: IIPImage.h:247
IIPImage::getNumChannels
unsigned int getNumChannels()
Return the number of channels for this image.
Definition: IIPImage.h:283
IIPImage::getMinValue
float getMinValue(int n=0)
Return the minimum sample value for each channel.
Definition: IIPImage.h:288
IIPImage::getRegion
virtual RawTile getRegion(int ha, int va, unsigned int r, int layers, int x, int y, unsigned int w, unsigned int h)
Return a region for a given angle and resolution.
Definition: IIPImage.h:371
IIPImage::IIPImage
IIPImage()
Default Constructor.
Definition: IIPImage.h:157
IIPImage::getVerticalViewsList
std::list< int > getVerticalViewsList()
Return a list of available vertical angles.
Definition: IIPImage.h:241