IIPImage.h
// IIPImage class
/* IIP fcgi server module
Copyright (C) 2000-2019 Ruven Pillay.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _IIPIMAGE_H
#define _IIPIMAGE_H
// Fix missing snprintf in Windows
#if defined _MSC_VER && _MSC_VER<1900
#define snprintf _snprintf
#endif
#include <string>
#include <list>
#include <vector>
#include <map>
#include <stdexcept>
#include "RawTile.h"
class file_error : public std::runtime_error {
public:
file_error(std::string s) : std::runtime_error(s) { }
};
// Supported image formats
enum ImageFormat { TIF, JPEG2000, UNSUPPORTED };
class IIPImage {
private:
std::string imagePath;
std::string fileSystemPrefix;
std::string fileNamePattern;
bool isFile;
std::string suffix;
void testImageType();
void measureHorizontalAngles();
void measureVerticalAngles();
std::list <int> horizontalAnglesList;
std::list <int> verticalAnglesList;
protected:
std::vector <int> lut;
unsigned int virtual_levels;
ImageFormat format;
public:
std::vector <unsigned int> image_widths, image_heights;
unsigned int tile_width, tile_height;
ColourSpaces colourspace;
unsigned int numResolutions;
unsigned int bpc;
unsigned int channels;
SampleType sampleType;
std::vector <float> min, max;
unsigned int quality_layers;
bool isSet;
int currentX, currentY;
std::vector<unsigned int> histogram;
std::map <const std::string, std::string> metadata;
time_t timestamp;
public:
IIPImage()
: isFile( false ),
virtual_levels( 0 ),
format( UNSUPPORTED ),
tile_width( 0 ),
tile_height( 0 ),
colourspace( NONE ),
numResolutions( 0 ),
bpc( 0 ),
channels( 0 ),
sampleType( FIXEDPOINT ),
quality_layers( 0 ),
isSet( false ),
currentX( 0 ),
currentY( 90 ),
timestamp( 0 ) {};
IIPImage( const std::string& s )
: imagePath( s ),
isFile( false ),
virtual_levels( 0 ),
format( UNSUPPORTED ),
tile_width( 0 ),
tile_height( 0 ),
colourspace( NONE ),
numResolutions( 0 ),
bpc( 0 ),
channels( 0 ),
sampleType( FIXEDPOINT ),
quality_layers( 0 ),
isSet( false ),
currentX( 0 ),
currentY( 90 ),
timestamp( 0 ) {};
IIPImage( const IIPImage& image )
: imagePath( image.imagePath ),
fileSystemPrefix( image.fileSystemPrefix ),
fileNamePattern( image.fileNamePattern ),
isFile( image.isFile ),
suffix( image.suffix ),
horizontalAnglesList( image.horizontalAnglesList ),
verticalAnglesList( image.verticalAnglesList ),
lut( image.lut ),
virtual_levels( image.virtual_levels ),
format( image.format ),
image_widths( image.image_widths ),
image_heights( image.image_heights ),
tile_width( image.tile_width ),
tile_height( image.tile_height ),
colourspace( image.colourspace ),
numResolutions( image.numResolutions ),
bpc( image.bpc ),
channels( image.channels ),
sampleType( image.sampleType ),
min( image.min ),
max( image.max ),
quality_layers( image.quality_layers ),
isSet( image.isSet ),
currentX( image.currentX ),
currentY( image.currentY ),
histogram( image.histogram ),
metadata( image.metadata ),
timestamp( image.timestamp ) {};
virtual ~IIPImage() { ; };
void Initialise();
void swap( IIPImage& a, IIPImage& b );
std::list <int> getVerticalViewsList(){ return verticalAnglesList; };
std::list <int> getHorizontalViewsList(){ return horizontalAnglesList; };
const std::string& getImagePath() { return imagePath; };
const std::string getFileName( int x, int y );
// const std::string& getImageFormat() { return format; };
ImageFormat getImageFormat() { return format; };
void updateTimestamp( const std::string& s );
const std::string getTimestamp();
bool set() { return isSet; };
void setFileSystemPrefix( const std::string& prefix ) { fileSystemPrefix = prefix; };
void setFileNamePattern( const std::string& pattern ) { fileNamePattern = pattern; };
unsigned int getNumResolutions() { return numResolutions; };
unsigned int getNumBitsPerPixel() { return bpc; };
unsigned int getNumChannels() { return channels; };
float getMinValue( int n=0 ) { return min[n]; };
float getMaxValue( int n=0 ) { return max[n]; };
SampleType getSampleType(){ return sampleType; };
unsigned int getImageWidth( int n=0 ) { return image_widths[n]; };
unsigned int getImageHeight( int n=0 ) { return image_heights[n]; };
unsigned int getTileHeight() { return tile_height; };
unsigned int getTileWidth() { return tile_width; };
ColourSpaces getColourSpace() { return colourspace; };
const std::string& getMetadata( const std::string& index ) {
return metadata[index];
};
virtual bool regionDecoding(){ return false; };
virtual void Load( const std::string& module ) {;};
virtual const std::string getDescription() { return std::string( "IIPImage Base Class" ); };
virtual void openImage() { throw file_error( "IIPImage openImage called" ); };
virtual void loadImageInfo( int x, int y ) { ; };
virtual void closeImage() {;};
virtual RawTile getTile( int h, int v, unsigned int r, int l, unsigned int t ) { return RawTile(); };
virtual RawTile getRegion( int ha, int va, unsigned int r, int layers, int x, int y, unsigned int w, unsigned int h ){ return RawTile(); };
IIPImage& operator = ( IIPImage image ){
swap( *this, image );
return *this;
};
friend int operator == ( const IIPImage&, const IIPImage& );
friend int operator != ( const IIPImage&, const IIPImage& );
};
#endif
IIPImage::min
std::vector< float > min
The min and max sample value for each channel.
Definition IIPImage.h:133
IIPImage::getHorizontalViewsList
std::list< int > getHorizontalViewsList()
Return a list of horizontal angles.
Definition IIPImage.h:244
IIPImage::virtual_levels
unsigned int virtual_levels
Number of resolution levels that don't physically exist in file.
Definition IIPImage.h:103
IIPImage::getTimestamp
const std::string getTimestamp()
Get a HTTP RFC 1123 formatted timestamp.
IIPImage::IIPImage
IIPImage()
Default Constructor.
Definition IIPImage.h:157
IIPImage::IIPImage
IIPImage(const std::string &s)
Constructer taking the image path as parameter.
Definition IIPImage.h:177
IIPImage::lut
std::vector< int > lut
LUT.
Definition IIPImage.h:100
IIPImage::swap
void swap(IIPImage &a, IIPImage &b)
Swap function.
IIPImage::getFileName
const std::string getFileName(int x, int y)
Return the full file path for a particular horizontal and vertical angle.
IIPImage::isSet
bool isSet
Indicate whether we have opened and initialised some parameters for this image.
Definition IIPImage.h:139
IIPImage::format
ImageFormat format
Return the image format e.g. tif.
Definition IIPImage.h:106
IIPImage::operator=
IIPImage & operator=(IIPImage image)
Assignment operator.
Definition IIPImage.h:375
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 non-equality operator.
IIPImage::updateTimestamp
void updateTimestamp(const std::string &s)
Get the image timestamp.
IIPImage::~IIPImage
virtual ~IIPImage()
Virtual Destructor.
Definition IIPImage.h:229
IIPImage::getMaxValue
float getMaxValue(int n=0)
Return the minimum sample value for each channel.
Definition IIPImage.h:293
IIPImage::image_widths
std::vector< unsigned int > image_widths
The image pixel dimensions.
Definition IIPImage.h:112
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::getColourSpace
ColourSpaces getColourSpace()
Return the colour space for this image.
Definition IIPImage.h:315
IIPImage::getNumBitsPerPixel
unsigned int getNumBitsPerPixel()
Return the number of bits per pixel for this image.
Definition IIPImage.h:280
IIPImage::timestamp
time_t timestamp
Image modification timestamp.
Definition IIPImage.h:151
IIPImage::set
bool set()
Check whether this object has been initialised.
Definition IIPImage.h:268
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::getMinValue
float getMinValue(int n=0)
Return the minimum sample value for each channel.
Definition IIPImage.h:288
IIPImage::regionDecoding
virtual bool regionDecoding()
Return whether this image type directly handles region decoding.
Definition IIPImage.h:324
IIPImage::sampleType
SampleType sampleType
The sample format type (fixed or floating point).
Definition IIPImage.h:130
IIPImage::metadata
std::map< const std::string, std::string > metadata
STL map to hold string metadata.
Definition IIPImage.h:148
IIPImage::getTileWidth
unsigned int getTileWidth()
Return the base tile width in pixels.
Definition IIPImage.h:312
IIPImage::numResolutions
unsigned int numResolutions
The number of available resolutions in this image.
Definition IIPImage.h:121
IIPImage::getMetadata
const std::string & getMetadata(const std::string &index)
Return image metadata.
Definition IIPImage.h:319
IIPImage::getImageWidth
unsigned int getImageWidth(int n=0)
Return the image width in pixels for a given resolution.
Definition IIPImage.h:301
IIPImage::getSampleType
SampleType getSampleType()
Return the sample format type.
Definition IIPImage.h:296
IIPImage::tile_width
unsigned int tile_width
The base tile pixel dimensions.
Definition IIPImage.h:115
IIPImage::closeImage
virtual void closeImage()
Close the image: Overloaded by child class.
Definition IIPImage.h:345
IIPImage::getImageFormat
ImageFormat getImageFormat()
Get the image format.
Definition IIPImage.h:257
IIPImage::getImagePath
const std::string & getImagePath()
Return the image path.
Definition IIPImage.h:247
IIPImage::Load
virtual void Load(const std::string &module)
Load the appropriate codec module for this image type.
Definition IIPImage.h:330
IIPImage::quality_layers
unsigned int quality_layers
Quality layers.
Definition IIPImage.h:136
IIPImage::getNumChannels
unsigned int getNumChannels()
Return the number of channels for this image.
Definition IIPImage.h:283
IIPImage::currentX
int currentX
If we have an image sequence, the current X and Y position.
Definition IIPImage.h:142
IIPImage::getDescription
virtual const std::string getDescription()
Return codec description: Overloaded by child class.
Definition IIPImage.h:333
IIPImage::operator==
friend int operator==(const IIPImage &, const IIPImage &)
Comparison equality operator.
IIPImage::openImage
virtual void openImage()
Open the image: Overloaded by child class.
Definition IIPImage.h:336
IIPImage::colourspace
ColourSpaces colourspace
The colour space of the image.
Definition IIPImage.h:118
IIPImage::histogram
std::vector< unsigned int > histogram
Image histogram.
Definition IIPImage.h:145
IIPImage::Initialise
void Initialise()
Test the image and initialise some parameters.
IIPImage::getImageHeight
unsigned int getImageHeight(int n=0)
Return the image height in pixels for a given resolution.
Definition IIPImage.h:306
IIPImage::getTileHeight
unsigned int getTileHeight()
Return the base tile height in pixels for a given resolution.
Definition IIPImage.h:309
IIPImage::setFileSystemPrefix
void setFileSystemPrefix(const std::string &prefix)
Set a file system prefix for added security.
Definition IIPImage.h:271
IIPImage::getNumResolutions
unsigned int getNumResolutions()
Return the number of available resolutions in the image.
Definition IIPImage.h:277
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::getVerticalViewsList
std::list< int > getVerticalViewsList()
Return a list of available vertical angles.
Definition IIPImage.h:241
IIPImage::setFileNamePattern
void setFileNamePattern(const std::string &pattern)
Set the file name pattern used in image sequences.
Definition IIPImage.h:274
IIPImage::channels
unsigned int channels
The number of channels for this image.
Definition IIPImage.h:127
IIPImage::bpc
unsigned int bpc
The bits per channel for this image.
Definition IIPImage.h:124
RawTile
Class to represent a single image tile.
Definition RawTile.h:45
file_error
Define our own derived exception class for file errors.
Definition IIPImage.h:43
file_error::file_error
file_error(std::string s)
Definition IIPImage.h:46