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
RawTile.h
1// RawTile class
2
3/* IIP Image Server
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 _RAWTILE_H
24#define _RAWTILE_H
25
26#include <cstring>
27#include <string>
28#include <cstdlib>
29#include <ctime>
30
31
32
34enum ColourSpaces { NONE, GREYSCALE, sRGB, CIELAB, BINARY };
35
37enum CompressionType { UNCOMPRESSED, JPEG, DEFLATE, PNG };
38
40enum SampleType { FIXEDPOINT, FLOATINGPOINT };
41
42
44
45class RawTile{
46
47 public:
48
51
54
57
60
62 CompressionType compressionType;
63
66
68 std::string filename;
69
71 time_t timestamp;
72
74 void *data;
75
78
80
82 unsigned int dataLength;
83
85 unsigned int width;
86
88 unsigned int height;
89
92
94 int bpc;
95
97 SampleType sampleType;
98
100 bool padded;
101
102
104
113 RawTile( int tn = 0, int res = 0, int hs = 0, int vs = 0,
114 int w = 0, int h = 0, int c = 0, int b = 0 ) {
115 width = w; height = h; bpc = b; dataLength = 0; data = NULL;
116 tileNum = tn; resolution = res; hSequence = hs ; vSequence = vs;
117 memoryManaged = 1; channels = c; compressionType = UNCOMPRESSED; quality = 0;
118 timestamp = 0; sampleType = FIXEDPOINT; padded = false;
119 };
120
121
124 if( data && memoryManaged ){
125 switch( bpc ){
126 case 32:
127 if( sampleType == FLOATINGPOINT ) delete[] (float*) data;
128 else delete[] (unsigned int*) data;
129 break;
130 case 16:
131 delete[] (unsigned short*) data;
132 break;
133 default:
134 delete[] (unsigned char*) data;
135 break;
136 }
137 }
138 }
139
140
142 RawTile( const RawTile& tile ) {
143
144 tileNum = tile.tileNum;
145 resolution = tile.resolution;
146 hSequence = tile.hSequence;
147 vSequence = tile.vSequence;
149 quality = tile.quality;
150 filename = tile.filename;
151 timestamp = tile.timestamp;
153 dataLength = tile.dataLength;
154 width = tile.width;
155 height = tile.height;
156 channels = tile.channels;
157 bpc = tile.bpc;
158 sampleType = tile.sampleType;
159 padded = tile.padded;
160
161 switch( bpc ){
162 case 32:
163 if( sampleType == FLOATINGPOINT ) data = new float[dataLength/4];
164 else data = new unsigned int[dataLength/4];
165 break;
166 case 16:
167 data = new unsigned short[dataLength/2];
168 break;
169 default:
170 data = new unsigned char[dataLength];
171 break;
172 }
173
174 if( data && (dataLength > 0) && tile.data ){
175 memcpy( data, tile.data, dataLength );
176 memoryManaged = 1;
177 }
178 }
179
180
182 RawTile& operator= ( const RawTile& tile ) {
183
184 tileNum = tile.tileNum;
185 resolution = tile.resolution;
186 hSequence = tile.hSequence;
187 vSequence = tile.vSequence;
189 quality = tile.quality;
190 filename = tile.filename;
191 timestamp = tile.timestamp;
193 dataLength = tile.dataLength;
194 width = tile.width;
195 height = tile.height;
196 channels = tile.channels;
197 bpc = tile.bpc;
198 sampleType = tile.sampleType;
199 padded = tile.padded;
200
201 switch( bpc ){
202 case 32:
203 if( sampleType == FLOATINGPOINT ) data = new float[dataLength/4];
204 else data = new int[dataLength/4];
205 break;
206 case 16:
207 data = new unsigned short[dataLength/2];
208 break;
209 default:
210 data = new unsigned char[dataLength];
211 break;
212 }
213
214 if( data && (dataLength > 0) && tile.data ){
215 memcpy( data, tile.data, dataLength );
216 memoryManaged = 1;
217 }
218
219 return *this;
220 }
221
222
224 unsigned int size() { return dataLength; }
225
226
228 friend int operator == ( const RawTile& A, const RawTile& B ) {
229 if( (A.tileNum == B.tileNum) &&
230 (A.resolution == B.resolution) &&
231 (A.hSequence == B.hSequence) &&
232 (A.vSequence == B.vSequence) &&
234 (A.quality == B.quality) &&
235 (A.filename == B.filename) ){
236 return( 1 );
237 }
238 else return( 0 );
239 }
240
241
243 friend int operator != ( const RawTile& A, const RawTile& B ) {
244 if( (A.tileNum == B.tileNum) &&
245 (A.resolution == B.resolution) &&
246 (A.hSequence == B.hSequence) &&
247 (A.vSequence == B.vSequence) &&
249 (A.quality == B.quality) &&
250 (A.filename == B.filename) ){
251 return( 0 );
252 }
253 else return( 1 );
254 }
255
256
257};
258
259
260#endif
Class to represent a single image tile.
Definition: RawTile.h:45
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
unsigned int width
The width in pixels of this tile.
Definition: RawTile.h:85
bool padded
Padded.
Definition: RawTile.h:100
std::string filename
Name of the file from which this tile comes.
Definition: RawTile.h:68
int bpc
The number of bits per channel for this tile.
Definition: RawTile.h:94
friend int operator!=(const RawTile &A, const RawTile &B)
Overloaded non-equality operator.
Definition: RawTile.h:243
unsigned int size()
Return the size of the data.
Definition: RawTile.h:224
time_t timestamp
Tile timestamp.
Definition: RawTile.h:71
int vSequence
The vertical angle to which this tile belongs.
Definition: RawTile.h:59
RawTile & operator=(const RawTile &tile)
Copy assignment constructor.
Definition: RawTile.h:182
friend int operator==(const RawTile &A, const RawTile &B)
Overloaded equality operator.
Definition: RawTile.h:228
~RawTile()
Destructor to free the data array if is has previously be allocated locally.
Definition: RawTile.h:123
int tileNum
The tile number for this tile.
Definition: RawTile.h:50
int resolution
The resolution to which this tile belongs.
Definition: RawTile.h:53
unsigned int dataLength
The size of the data pointed to by data.
Definition: RawTile.h:82
void * data
Pointer to the image data.
Definition: RawTile.h:74
RawTile(const RawTile &tile)
Copy constructor - handles copying of data buffer.
Definition: RawTile.h:142
SampleType sampleType
Sample format type (fixed or floating point)
Definition: RawTile.h:97
CompressionType compressionType
Compression type.
Definition: RawTile.h:62
int memoryManaged
Definition: RawTile.h:79
int channels
The number of channels for this tile.
Definition: RawTile.h:91
int quality
Compression rate or quality.
Definition: RawTile.h:65
int hSequence
The horizontal angle to which this tile belongs.
Definition: RawTile.h:56
unsigned int height
The height in pixels of this tile.
Definition: RawTile.h:88