iipsrv  0.9.9
RawTile.h
1 // RawTile class
2 
3 /* IIP Image Server
4 
5  Copyright (C) 2000-2009 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 2 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
19  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21 
22 
23 #ifndef _RAWTILE_H
24 #define _RAWTILE_H
25 
26 #include <cstring>
27 #include <string>
28 #include <cstdlib>
29 #include <ctime>
30 
31 
32 
34 enum ColourSpaces { GREYSCALE, sRGB, CIELAB };
35 
37 enum CompressionType { UNCOMPRESSED, JPEG, DEFLATE };
38 
39 
40 
42 
43 class RawTile{
44 
45  public:
46 
48  int tileNum;
49 
52 
54  int hSequence;
55 
57  int vSequence;
58 
60  CompressionType compressionType;
61 
63  int quality;
64 
66  std::string filename;
67 
69  time_t timestamp;
70 
71 
72  public:
73 
74 
76  void *data;
77 
80 
82 
85 
87  unsigned int width;
88 
90  unsigned int height;
91 
93  int channels;
94 
96  int bpc;
97 
99  bool padded;
100 
101 
103 
112  RawTile( int tn = 0, int res = 0, int hs = 0, int vs = 0,
113  int w = 0, int h = 0, int c = 0, int b = 0 ) {
114  width = w; height = h; bpc = b; dataLength = 0; data = NULL;
115  tileNum = tn; resolution = res; hSequence = hs ; vSequence = vs;
116  memoryManaged = 1; channels = c; compressionType = UNCOMPRESSED; quality = 0;
117  timestamp = 0; padded = 0;
118  };
119 
120 
123  if( data && memoryManaged ){
124  if(bpc==16) delete[] (unsigned short*) data;
125  else delete[] (unsigned char*) data;
126  }
127  }
128 
129 
131  RawTile( const RawTile& tile ) {
132 
133  dataLength = tile.dataLength;
134  width = tile.width;
135  height = tile.height;
136  channels = tile.channels;
137  bpc = tile.bpc;
138  tileNum = tile.tileNum;
139  resolution = tile.resolution;
140  hSequence = tile.hSequence;
141  vSequence = tile.vSequence;
143  quality = tile.quality;
144  filename = tile.filename;
145  timestamp = tile.timestamp;
146  padded = tile.padded;
147 
148  if( bpc == 16 ) data = new unsigned short[dataLength/2];
149  else data = new unsigned char[dataLength];
150 
151  if( data && (dataLength > 0) && tile.data ){
152  memcpy( data, tile.data, dataLength );
153  memoryManaged = 1;
154  }
155  }
156 
157 
159  RawTile& operator= ( const RawTile& tile ) {
160 
161  dataLength = tile.dataLength;
162  width = tile.width;
163  height = tile.height;
164  channels = tile.channels;
165  bpc = tile.bpc;
166  tileNum = tile.tileNum;
167  resolution = tile.resolution;
168  hSequence = tile.hSequence;
169  vSequence = tile.vSequence;
171  quality = tile.quality;
172  filename = tile.filename;
173  timestamp = tile.timestamp;
174  padded = tile.padded;
175 
176  if( bpc == 16 ) data = new unsigned short[dataLength/2];
177  else data = new unsigned char[dataLength];
178 
179  if( data && (dataLength > 0) && tile.data ){
180  memcpy( data, tile.data, dataLength );
181  memoryManaged = 1;
182  }
183 
184  return *this;
185  }
186 
187 
189  int size() { return dataLength; }
190 
191 
193  friend int operator == ( const RawTile& A, const RawTile& B ) {
194  if( (A.tileNum == B.tileNum) &&
195  (A.resolution == B.resolution) &&
196  (A.hSequence == B.hSequence) &&
197  (A.vSequence == B.vSequence) &&
198  (A.compressionType == B.compressionType) &&
199  (A.quality == B.quality) &&
200  (A.filename == B.filename) ){
201  return( 1 );
202  }
203  else return( 0 );
204  }
205 
206 
208  friend int operator != ( const RawTile& A, const RawTile& B ) {
209  if( (A.tileNum == B.tileNum) &&
210  (A.resolution == B.resolution) &&
211  (A.hSequence == B.hSequence) &&
212  (A.vSequence == B.vSequence) &&
213  (A.compressionType == B.compressionType) &&
214  (A.quality == B.quality) &&
215  (A.filename == B.filename) ){
216  return( 0 );
217  }
218  else return( 1 );
219  }
220 
221 
222 };
223 
224 
225 #endif
int vSequence
The vertical angle to which this tile belongs.
Definition: RawTile.h:57
bool padded
Padded.
Definition: RawTile.h:99
int resolution
The resolution to which this tile belongs.
Definition: RawTile.h:51
RawTile(const RawTile &tile)
Copy constructor - handles copying of data buffer.
Definition: RawTile.h:131
void * data
Pointer to the image data.
Definition: RawTile.h:76
unsigned int height
The height in pixels of this tile.
Definition: RawTile.h:90
int hSequence
The horizontal angle to which this tile belongs.
Definition: RawTile.h:54
int tileNum
The tile number for this tile.
Definition: RawTile.h:48
RawTile & operator=(const RawTile &tile)
Copy assignment constructor.
Definition: RawTile.h:159
CompressionType compressionType
Compression type.
Definition: RawTile.h:60
int bpc
The number of bits per channel for this tile.
Definition: RawTile.h:96
int memoryManaged
Definition: RawTile.h:81
std::string filename
Name of the file from which this tile comes.
Definition: RawTile.h:66
unsigned int width
The width in pixels of this tile.
Definition: RawTile.h:87
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:112
~RawTile()
Destructor to free the data array if is has previously be allocated locally.
Definition: RawTile.h:122
int channels
The number of channels for this tile.
Definition: RawTile.h:93
int quality
Compression rate or quality.
Definition: RawTile.h:63
friend int operator!=(const RawTile &A, const RawTile &B)
Overloaded non-equality operator.
Definition: RawTile.h:208
friend int operator==(const RawTile &A, const RawTile &B)
Overloaded equality operator.
Definition: RawTile.h:193
time_t timestamp
Tile timestamp.
Definition: RawTile.h:69
Class to represent a single image tile.
Definition: RawTile.h:43
int size()
Return the size of the data.
Definition: RawTile.h:189
int dataLength
The size of the data pointed to by data.
Definition: RawTile.h:84