RawTile.h
// RawTile class
/* IIP Image Server
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 _RAWTILE_H
#define _RAWTILE_H
#include <cstring>
#include <string>
#include <cstdlib>
#include <ctime>
enum ColourSpaces { NONE, GREYSCALE, sRGB, CIELAB, BINARY };
enum CompressionType { UNCOMPRESSED, JPEG, DEFLATE, PNG };
enum SampleType { FIXEDPOINT, FLOATINGPOINT };
class RawTile{
public:
int tileNum;
int resolution;
int hSequence;
int vSequence;
CompressionType compressionType;
int quality;
std::string filename;
time_t timestamp;
void *data;
int memoryManaged;
unsigned int dataLength;
unsigned int width;
unsigned int height;
int channels;
int bpc;
SampleType sampleType;
bool padded;
RawTile( int tn = 0, int res = 0, int hs = 0, int vs = 0,
int w = 0, int h = 0, int c = 0, int b = 0 ) {
width = w; height = h; bpc = b; dataLength = 0; data = NULL;
tileNum = tn; resolution = res; hSequence = hs ; vSequence = vs;
memoryManaged = 1; channels = c; compressionType = UNCOMPRESSED; quality = 0;
timestamp = 0; sampleType = FIXEDPOINT; padded = false;
};
~RawTile() {
if( data && memoryManaged ){
switch( bpc ){
case 32:
if( sampleType == FLOATINGPOINT ) delete[] (float*) data;
else delete[] (unsigned int*) data;
break;
case 16:
delete[] (unsigned short*) data;
break;
default:
delete[] (unsigned char*) data;
break;
}
}
}
RawTile( const RawTile& tile ) {
tileNum = tile.tileNum;
resolution = tile.resolution;
hSequence = tile.hSequence;
vSequence = tile.vSequence;
compressionType = tile.compressionType;
quality = tile.quality;
filename = tile.filename;
timestamp = tile.timestamp;
memoryManaged = tile.memoryManaged;
dataLength = tile.dataLength;
width = tile.width;
height = tile.height;
channels = tile.channels;
bpc = tile.bpc;
sampleType = tile.sampleType;
padded = tile.padded;
switch( bpc ){
case 32:
if( sampleType == FLOATINGPOINT ) data = new float[dataLength/4];
else data = new unsigned int[dataLength/4];
break;
case 16:
data = new unsigned short[dataLength/2];
break;
default:
data = new unsigned char[dataLength];
break;
}
if( data && (dataLength > 0) && tile.data ){
memcpy( data, tile.data, dataLength );
memoryManaged = 1;
}
}
RawTile& operator= ( const RawTile& tile ) {
tileNum = tile.tileNum;
resolution = tile.resolution;
hSequence = tile.hSequence;
vSequence = tile.vSequence;
compressionType = tile.compressionType;
quality = tile.quality;
filename = tile.filename;
timestamp = tile.timestamp;
memoryManaged = tile.memoryManaged;
dataLength = tile.dataLength;
width = tile.width;
height = tile.height;
channels = tile.channels;
bpc = tile.bpc;
sampleType = tile.sampleType;
padded = tile.padded;
switch( bpc ){
case 32:
if( sampleType == FLOATINGPOINT ) data = new float[dataLength/4];
else data = new int[dataLength/4];
break;
case 16:
data = new unsigned short[dataLength/2];
break;
default:
data = new unsigned char[dataLength];
break;
}
if( data && (dataLength > 0) && tile.data ){
memcpy( data, tile.data, dataLength );
memoryManaged = 1;
}
return *this;
}
unsigned int size() { return dataLength; }
friend int operator == ( const RawTile& A, const RawTile& B ) {
if( (A.tileNum == B.tileNum) &&
(A.resolution == B.resolution) &&
(A.hSequence == B.hSequence) &&
(A.vSequence == B.vSequence) &&
(A.compressionType == B.compressionType) &&
(A.quality == B.quality) &&
(A.filename == B.filename) ){
return( 1 );
}
else return( 0 );
}
friend int operator != ( const RawTile& A, const RawTile& B ) {
if( (A.tileNum == B.tileNum) &&
(A.resolution == B.resolution) &&
(A.hSequence == B.hSequence) &&
(A.vSequence == B.vSequence) &&
(A.compressionType == B.compressionType) &&
(A.quality == B.quality) &&
(A.filename == B.filename) ){
return( 0 );
}
else return( 1 );
}
};
#endif
RawTile::RawTile
RawTile(int tn=0, int res=0, int hs=0, int vs=0, int w=0, int h=0, int c=0, int b=0)
Main constructor.
Definition RawTile.h:113
RawTile::width
unsigned int width
The width in pixels of this tile.
Definition RawTile.h:85
RawTile::padded
bool padded
Padded.
Definition RawTile.h:100
RawTile::filename
std::string filename
Name of the file from which this tile comes.
Definition RawTile.h:68
RawTile::bpc
int bpc
The number of bits per channel for this tile.
Definition RawTile.h:94
RawTile::operator!=
friend int operator!=(const RawTile &A, const RawTile &B)
Overloaded non-equality operator.
Definition RawTile.h:243
RawTile::size
unsigned int size()
Return the size of the data.
Definition RawTile.h:224
RawTile::timestamp
time_t timestamp
Tile timestamp.
Definition RawTile.h:71
RawTile::vSequence
int vSequence
The vertical angle to which this tile belongs.
Definition RawTile.h:59
RawTile::operator=
RawTile & operator=(const RawTile &tile)
Copy assignment constructor.
Definition RawTile.h:182
RawTile::operator==
friend int operator==(const RawTile &A, const RawTile &B)
Overloaded equality operator.
Definition RawTile.h:228
RawTile::~RawTile
~RawTile()
Destructor to free the data array if is has previously be allocated locally.
Definition RawTile.h:123
RawTile::tileNum
int tileNum
The tile number for this tile.
Definition RawTile.h:50
RawTile::resolution
int resolution
The resolution to which this tile belongs.
Definition RawTile.h:53
RawTile::dataLength
unsigned int dataLength
The size of the data pointed to by data.
Definition RawTile.h:82
RawTile::data
void * data
Pointer to the image data.
Definition RawTile.h:74
RawTile::RawTile
RawTile(const RawTile &tile)
Copy constructor - handles copying of data buffer.
Definition RawTile.h:142
RawTile::sampleType
SampleType sampleType
Sample format type (fixed or floating point).
Definition RawTile.h:97
RawTile::compressionType
CompressionType compressionType
Compression type.
Definition RawTile.h:62
RawTile::memoryManaged
int memoryManaged
Definition RawTile.h:79
RawTile::channels
int channels
The number of channels for this tile.
Definition RawTile.h:91
RawTile::quality
int quality
Compression rate or quality.
Definition RawTile.h:65
RawTile::hSequence
int hSequence
The horizontal angle to which this tile belongs.
Definition RawTile.h:56
RawTile::height
unsigned int height
The height in pixels of this tile.
Definition RawTile.h:88