iipsrv 0.9.9

RawTile.h

00001 // RawTile class
00002 
00003 /*  IIP Image Server
00004 
00005     Copyright (C) 2000-2009 Ruven Pillay.
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 */
00021 
00022 
00023 #ifndef _RAWTILE_H
00024 #define _RAWTILE_H
00025 
00026 #include <cstring>
00027 #include <string>
00028 #include <cstdlib>
00029 #include <ctime>
00030 
00031 
00032 
00034 enum ColourSpaces { GREYSCALE, sRGB, CIELAB };
00035 
00037 enum CompressionType { UNCOMPRESSED, JPEG, DEFLATE };
00038 
00039 
00040 
00042 
00043 class RawTile{
00044 
00045  public:
00046 
00048   int tileNum;
00049 
00051   int resolution;
00052 
00054   int hSequence;
00055 
00057   int vSequence;
00058 
00060   CompressionType compressionType;
00061 
00063   int quality;
00064 
00066   std::string filename;
00067 
00069   time_t timestamp;
00070 
00071 
00072  public:
00073 
00074 
00076   void *data;
00077 
00080 
00081   int memoryManaged;
00082 
00084   int dataLength;
00085 
00087   unsigned int width;
00088 
00090   unsigned int height;
00091 
00093   int channels;
00094 
00096   int bpc;
00097 
00099   bool padded;
00100 
00101 
00103 
00112   RawTile( int tn = 0, int res = 0, int hs = 0, int vs = 0,
00113            int w = 0, int h = 0, int c = 0, int b = 0 ) {
00114     width = w; height = h; bpc = b; dataLength = 0; data = NULL;
00115     tileNum = tn; resolution = res; hSequence = hs ; vSequence = vs;
00116     memoryManaged = 1; channels = c; compressionType = UNCOMPRESSED; quality = 0;
00117     timestamp = 0; padded = 0;
00118   };
00119 
00120 
00122   ~RawTile() {
00123     if( data && memoryManaged ){
00124       if(bpc==16) delete[] (unsigned short*) data;
00125       else delete[] (unsigned char*) data;
00126     }
00127   }
00128 
00129 
00131   RawTile( const RawTile& tile ) {
00132 
00133     dataLength = tile.dataLength;
00134     width = tile.width;
00135     height = tile.height;
00136     channels = tile.channels;
00137     bpc = tile.bpc;
00138     tileNum = tile.tileNum;
00139     resolution = tile.resolution;
00140     hSequence = tile.hSequence;
00141     vSequence = tile.vSequence;
00142     compressionType = tile.compressionType;
00143     quality = tile.quality;
00144     filename = tile.filename;
00145     timestamp = tile.timestamp;
00146     padded = tile.padded;
00147 
00148     if( bpc == 16 ) data = new unsigned short[dataLength/2];
00149     else data = new unsigned char[dataLength];
00150 
00151     if( data && (dataLength > 0) && tile.data ){
00152       memcpy( data, tile.data, dataLength );
00153       memoryManaged = 1;
00154     }
00155   }
00156 
00157 
00159   RawTile& operator= ( const RawTile& tile ) {
00160 
00161     dataLength = tile.dataLength;
00162     width = tile.width;
00163     height = tile.height;
00164     channels = tile.channels;
00165     bpc = tile.bpc;
00166     tileNum = tile.tileNum;
00167     resolution = tile.resolution;
00168     hSequence = tile.hSequence;
00169     vSequence = tile.vSequence;
00170     compressionType = tile.compressionType;
00171     quality = tile.quality;
00172     filename = tile.filename;
00173     timestamp = tile.timestamp;
00174     padded = tile.padded;
00175 
00176     if( bpc == 16 ) data = new unsigned short[dataLength/2];
00177     else data = new unsigned char[dataLength];
00178 
00179     if( data && (dataLength > 0) && tile.data ){
00180       memcpy( data, tile.data, dataLength );
00181       memoryManaged = 1;
00182     }
00183 
00184     return *this;
00185   }
00186 
00187 
00189   int size() { return dataLength; }
00190 
00191 
00193   friend int operator == ( const RawTile& A, const RawTile& B ) {
00194     if( (A.tileNum == B.tileNum) &&
00195         (A.resolution == B.resolution) &&
00196         (A.hSequence == B.hSequence) &&
00197         (A.vSequence == B.vSequence) &&
00198         (A.compressionType == B.compressionType) &&
00199         (A.quality == B.quality) &&
00200         (A.filename == B.filename) ){
00201       return( 1 );
00202     }
00203     else return( 0 );
00204   }
00205 
00206 
00208   friend int operator != ( const RawTile& A, const RawTile& B ) {
00209     if( (A.tileNum == B.tileNum) &&
00210         (A.resolution == B.resolution) &&
00211         (A.hSequence == B.hSequence) &&
00212         (A.vSequence == B.vSequence) &&
00213         (A.compressionType == B.compressionType) &&
00214         (A.quality == B.quality) &&
00215         (A.filename == B.filename) ){
00216       return( 0 );
00217     }
00218     else return( 1 );
00219   }
00220 
00221 
00222 };
00223 
00224 
00225 #endif