iipsrv  1.0
IIPImage.h
1 // IIPImage class
2 
3 /* IIP fcgi server module
4 
5  Copyright (C) 2000-2016 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 _MSC_VER
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:
45  file_error(std::string s) : std::runtime_error(s) { }
46 };
47 
48 
49 // Supported image formats
50 enum ImageFormat { TIF, JPEG2000, UNSUPPORTED };
51 
52 
53 
55 
61 class IIPImage {
62 
63  private:
64 
66  std::string imagePath;
67 
69  std::string fileSystemPrefix;
70 
72  std::string fileNamePattern;
73 
75  bool isFile;
76 
78  std::string suffix;
79 
81  void testImageType() throw( file_error );
82 
84  void measureHorizontalAngles();
85 
87  void measureVerticalAngles();
88 
90  std::list <int> horizontalAnglesList;
91 
93  std::list <int> verticalAnglesList;
94 
95 
96  protected:
97 
99  std::vector <int> lut;
100 
102  unsigned int virtual_levels;
103 
105  ImageFormat format;
106 
107 
108  public:
109 
111  std::vector <unsigned int> image_widths, image_heights;
112 
114  unsigned int tile_width, tile_height;
115 
117  ColourSpaces colourspace;
118 
120  unsigned int numResolutions;
121 
123  unsigned int bpc;
124 
126  unsigned int channels;
127 
129  SampleType sampleType;
130 
132  std::vector <float> min, max;
133 
135  unsigned int quality_layers;
136 
138  bool isSet;
139 
141  int currentX, currentY;
142 
144  std::map <const std::string, std::string> metadata;
145 
147  time_t timestamp;
148 
149 
150  public:
151 
154  : isFile( false ),
155  virtual_levels( 0 ),
156  format( UNSUPPORTED ),
157  tile_width( 0 ),
158  tile_height( 0 ),
159  colourspace( NONE ),
160  numResolutions( 0 ),
161  bpc( 0 ),
162  channels( 0 ),
163  sampleType( FIXEDPOINT ),
164  quality_layers( 0 ),
165  isSet( false ),
166  currentX( 0 ),
167  currentY( 90 ),
168  timestamp( 0 ) {};
169 
171 
173  IIPImage( const std::string& s )
174  : imagePath( s ),
175  isFile( false ),
176  virtual_levels( 0 ),
177  format( UNSUPPORTED ),
178  tile_width( 0 ),
179  tile_height( 0 ),
180  colourspace( NONE ),
181  numResolutions( 0 ),
182  bpc( 0 ),
183  channels( 0 ),
184  sampleType( FIXEDPOINT ),
185  quality_layers( 0 ),
186  isSet( false ),
187  currentX( 0 ),
188  currentY( 90 ),
189  timestamp( 0 ) {};
190 
192 
194  IIPImage( const IIPImage& image )
195  : imagePath( image.imagePath ),
196  fileSystemPrefix( image.fileSystemPrefix ),
197  fileNamePattern( image.fileNamePattern ),
198  isFile( image.isFile ),
199  suffix( image.suffix ),
200  horizontalAnglesList( image.horizontalAnglesList ),
201  verticalAnglesList( image.verticalAnglesList ),
202  lut( image.lut ),
203  virtual_levels( image.virtual_levels ),
204  format( image.format ),
205  image_widths( image.image_widths ),
206  image_heights( image.image_heights ),
207  tile_width( image.tile_width ),
208  tile_height( image.tile_height ),
209  colourspace( image.colourspace ),
210  numResolutions( image.numResolutions ),
211  bpc( image.bpc ),
212  channels( image.channels ),
213  sampleType( image.sampleType ),
214  min( image.min ),
215  max( image.max ),
216  quality_layers( image.quality_layers ),
217  isSet( image.isSet ),
218  currentX( image.currentX ),
219  currentY( image.currentY ),
220  metadata( image.metadata ),
221  timestamp( image.timestamp ) {};
222 
224  virtual ~IIPImage() { ; };
225 
227  void Initialise();
228 
230 
233  void swap( IIPImage& a, IIPImage& b );
234 
236  std::list <int> getVerticalViewsList(){ return verticalAnglesList; };
237 
239  std::list <int> getHorizontalViewsList(){ return horizontalAnglesList; };
240 
242  const std::string& getImagePath() { return imagePath; };
243 
245 
248  const std::string getFileName( int x, int y );
249 
251  // const std::string& getImageFormat() { return format; };
252  ImageFormat getImageFormat() { return format; };
253 
255 
257  void updateTimestamp( const std::string& s ) throw( file_error );
258 
260  const std::string getTimestamp();
261 
263  bool set() { return isSet; };
264 
266  void setFileSystemPrefix( const std::string& prefix ) { fileSystemPrefix = prefix; };
267 
269  void setFileNamePattern( const std::string& pattern ) { fileNamePattern = pattern; };
270 
272  unsigned int getNumResolutions() { return numResolutions; };
273 
275  unsigned int getNumBitsPerPixel() { return bpc; };
276 
278  unsigned int getNumChannels() { return channels; };
279 
281 
283  float getMinValue( int n=0 ) { return min[n]; };
284 
286 
288  float getMaxValue( int n=0 ) { return max[n]; };
289 
291  SampleType getSampleType(){ return sampleType; };
292 
294 
296  unsigned int getImageWidth( int n=0 ) { return image_widths[n]; };
297 
299 
301  unsigned int getImageHeight( int n=0 ) { return image_heights[n]; };
302 
304  unsigned int getTileHeight() { return tile_height; };
305 
307  unsigned int getTileWidth() { return tile_width; };
308 
310  ColourSpaces getColourSpace() { return colourspace; };
311 
313 
314  const std::string& getMetadata( const std::string& index ) {
315  return metadata[index];
316  };
317 
319  virtual bool regionDecoding(){ return false; };
320 
322 
325  virtual void Load( const std::string& module ) {;};
326 
328  virtual const std::string getDescription() { return std::string( "IIPImage Base Class" ); };
329 
331  virtual void openImage() { throw file_error( "IIPImage openImage called" ); };
332 
334 
337  virtual void loadImageInfo( int x, int y ) { ; };
338 
340  virtual void closeImage() {;};
341 
342 
344 
351  virtual RawTile getTile( int h, int v, unsigned int r, int l, unsigned int t ) { return RawTile(); };
352 
353 
355 
366  virtual RawTile getRegion( int ha, int va, unsigned int r, int layers, int x, int y, unsigned int w, unsigned int h ){ return RawTile(); };
367 
369 
371  swap( *this, image );
372  return *this;
373  };
374 
376  friend int operator == ( const IIPImage&, const IIPImage& );
377 
379  friend int operator != ( const IIPImage&, const IIPImage& );
380 
381 };
382 
383 
384 #endif
float getMaxValue(int n=0)
Return the minimum sample value for each channel.
Definition: IIPImage.h:288
void swap(IIPImage &a, IIPImage &b)
Swap function.
friend int operator!=(const IIPImage &, const IIPImage &)
Comparison non-equality operator.
unsigned int getNumBitsPerPixel()
Return the number of bits per pixel for this image.
Definition: IIPImage.h:275
unsigned int getTileWidth()
Return the base tile width in pixels.
Definition: IIPImage.h:307
SampleType getSampleType()
Return the sample format type.
Definition: IIPImage.h:291
float getMinValue(int n=0)
Return the minimum sample value for each channel.
Definition: IIPImage.h:283
unsigned int getImageWidth(int n=0)
Return the image width in pixels for a given resolution.
Definition: IIPImage.h:296
time_t timestamp
Image modification timestamp.
Definition: IIPImage.h:147
std::map< const std::string, std::string > metadata
STL map to hold string metadata.
Definition: IIPImage.h:144
void Initialise()
Test the image and initialise some parameters.
bool set()
Check whether this object has been initialised.
Definition: IIPImage.h:263
unsigned int getNumResolutions()
Return the number of available resolutions in the image.
Definition: IIPImage.h:272
unsigned int getNumChannels()
Return the number of channels for this image.
Definition: IIPImage.h:278
unsigned int numResolutions
The number of available resolutions in this image.
Definition: IIPImage.h:120
std::vector< float > min
The min and max sample value for each channel.
Definition: IIPImage.h:132
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:351
void updateTimestamp(const std::string &s)
Get the image timestamp.
unsigned int virtual_levels
Number of resolution levels that don't physically exist in file.
Definition: IIPImage.h:102
IIPImage()
Default Constructor.
Definition: IIPImage.h:153
unsigned int getTileHeight()
Return the base tile height in pixels for a given resolution.
Definition: IIPImage.h:304
unsigned int quality_layers
Quality layers.
Definition: IIPImage.h:135
virtual bool regionDecoding()
Return whether this image type directly handles region decoding.
Definition: IIPImage.h:319
const std::string & getImagePath()
Return the image path.
Definition: IIPImage.h:242
virtual const std::string getDescription()
Return codec description: Overloaded by child class.
Definition: IIPImage.h:328
IIPImage(const std::string &s)
Constructer taking the image path as parameter.
Definition: IIPImage.h:173
friend int operator==(const IIPImage &, const IIPImage &)
Comparison equality operator.
const std::string & getMetadata(const std::string &index)
Return image metadata.
Definition: IIPImage.h:314
std::list< int > getHorizontalViewsList()
Return a list of horizontal angles.
Definition: IIPImage.h:239
std::vector< int > lut
LUT.
Definition: IIPImage.h:99
unsigned int getImageHeight(int n=0)
Return the image height in pixels for a given resolution.
Definition: IIPImage.h:301
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:366
virtual void openImage()
Open the image: Overloaded by child class.
Definition: IIPImage.h:331
const std::string getTimestamp()
Get a HTTP RFC 1123 formatted timestamp.
Define our own derived exception class for file errors.
Definition: IIPImage.h:43
std::list< int > getVerticalViewsList()
Return a list of available vertical angles.
Definition: IIPImage.h:236
Main class to handle the pyramidal image source.
Definition: IIPImage.h:61
unsigned int tile_width
The base tile pixel dimensions.
Definition: IIPImage.h:114
IIPImage(const IIPImage &image)
Copy Constructor taking reference to another IIPImage object.
Definition: IIPImage.h:194
virtual void loadImageInfo(int x, int y)
Load information about the image eg. number of channels, tile size etc.
Definition: IIPImage.h:337
ImageFormat format
Return the image format e.g. tif.
Definition: IIPImage.h:105
void setFileSystemPrefix(const std::string &prefix)
Set a file system prefix for added security.
Definition: IIPImage.h:266
bool isSet
Indicate whether we have opened and initialised some parameters for this image.
Definition: IIPImage.h:138
ColourSpaces colourspace
The colour space of the image.
Definition: IIPImage.h:117
const std::string getFileName(int x, int y)
Return the full file path for a particular horizontal and vertical angle.
unsigned int channels
The number of channels for this image.
Definition: IIPImage.h:126
virtual void closeImage()
Close the image: Overloaded by child class.
Definition: IIPImage.h:340
IIPImage & operator=(IIPImage image)
Assignment operator.
Definition: IIPImage.h:370
int currentX
If we have an image sequence, the current X and Y position.
Definition: IIPImage.h:141
SampleType sampleType
The sample format type (fixed or floating point)
Definition: IIPImage.h:129
Class to represent a single image tile.
Definition: RawTile.h:45
void setFileNamePattern(const std::string &pattern)
Set the file name pattern used in image sequences.
Definition: IIPImage.h:269
ColourSpaces getColourSpace()
Return the colour space for this image.
Definition: IIPImage.h:310
virtual void Load(const std::string &module)
Load the appropriate codec module for this image type.
Definition: IIPImage.h:325
ImageFormat getImageFormat()
Get the image format.
Definition: IIPImage.h:252
virtual ~IIPImage()
Virtual Destructor.
Definition: IIPImage.h:224
unsigned int bpc
The bits per channel for this image.
Definition: IIPImage.h:123
std::vector< unsigned int > image_widths
The image pixel dimensions.
Definition: IIPImage.h:111