My Project
|
00001 /****************************************************************************** 00002 * $Id: gdal_pcidsk.h 20996 2010-10-28 18:38:15Z rouault $ 00003 * 00004 * Project: PCIDSK Database File 00005 * Purpose: PCIDSK driver declarations. 00006 * Author: Andrey Kiselev, dron@remotesensing.org 00007 * 00008 ****************************************************************************** 00009 * Copyright (c) 2003, Andrey Kiselev <dron@remotesensing.org> 00010 * 00011 * Permission is hereby granted, free of charge, to any person obtaining a 00012 * copy of this software and associated documentation files (the "Software"), 00013 * to deal in the Software without restriction, including without limitation 00014 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00015 * and/or sell copies of the Software, and to permit persons to whom the 00016 * Software is furnished to do so, subject to the following conditions: 00017 * 00018 * The above copyright notice and this permission notice shall be included 00019 * in all copies or substantial portions of the Software. 00020 * 00021 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00022 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00023 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00024 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00025 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00026 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 00027 * DEALINGS IN THE SOFTWARE. 00028 ****************************************************************************/ 00029 00030 #include "cpl_conv.h" 00031 #include "cpl_string.h" 00032 #include "ogr_spatialref.h" 00033 #include "rawdataset.h" 00034 00035 typedef enum 00036 { 00037 PDI_PIXEL, 00038 PDI_BAND, 00039 PDI_FILE 00040 } PCIDSKInterleaving; 00041 00042 /************************************************************************/ 00043 /* PCIDSKDataset */ 00044 /************************************************************************/ 00045 00046 class PCIDSKDataset : public RawDataset 00047 { 00048 friend class PCIDSKRawRasterBand; 00049 friend class PCIDSKTiledRasterBand; 00050 00051 const char *pszFilename; 00052 VSILFILE *fp; 00053 00054 vsi_l_offset nFileSize; 00055 00056 char *pszCreatTime; // Date/time of the database creation 00057 00058 vsi_l_offset nGeoPtrOffset; // Offset in bytes to the pointer 00059 // to GEO segment 00060 vsi_l_offset nGeoOffset; // Offset in bytes to the GEO segment 00061 vsi_l_offset nGcpPtrOffset; // Offset in bytes to the pointer 00062 // to GCP segment 00063 vsi_l_offset nGcpOffset; // Offset in bytes to the GCP segment 00064 00065 int bGeoSegmentDirty; 00066 int bGeoTransformValid; 00067 00068 int nBlockMapSeg; 00069 00070 GDAL_GCP *pasGCPList; 00071 long nGCPCount; 00072 00073 double adfGeoTransform[6]; 00074 char *pszProjection; 00075 char *pszGCPProjection; 00076 00077 GDALDataType PCIDSKTypeToGDAL( const char *); 00078 void WriteGeoSegment(); 00079 00080 void CollectPCIDSKMetadata( int nSegment ); 00081 00082 // Segment map 00083 int nSegCount; 00084 int *panSegType; 00085 char **papszSegName; 00086 vsi_l_offset *panSegOffset; 00087 vsi_l_offset *panSegSize; 00088 00089 int nBandFileCount; 00090 VSILFILE **pafpBandFiles; 00091 00092 public: 00093 PCIDSKDataset(); 00094 ~PCIDSKDataset(); 00095 00096 static int Identify( GDALOpenInfo * ); 00097 static GDALDataset *Open( GDALOpenInfo * ); 00098 static GDALDataset *Create( const char * pszFilename, 00099 int nXSize, int nYSize, int nBands, 00100 GDALDataType eType, char **papszParmList ); 00101 static GDALDataset *CreateCopy( const char * pszFilename, 00102 GDALDataset *poSrcDS, 00103 int bStrict, char ** papszOptions, 00104 GDALProgressFunc pfnProgress, 00105 void * pProgressData ); 00106 00107 virtual void FlushCache( void ); 00108 00109 CPLErr GetGeoTransform( double * padfTransform ); 00110 virtual CPLErr SetGeoTransform( double * ); 00111 const char *GetProjectionRef(); 00112 virtual CPLErr SetProjection( const char * ); 00113 virtual int GetGCPCount(); 00114 virtual const char *GetGCPProjection(); 00115 virtual const GDAL_GCP *GetGCPs(); 00116 00117 // pcidsk specific 00118 int SegRead( int nSegment, 00119 vsi_l_offset nOffset, 00120 int nSize, 00121 void *pBuffer ); 00122 }; 00123 00124 /************************************************************************/ 00125 /* PCIDSKTiledRasterBand */ 00126 /************************************************************************/ 00127 00128 class PCIDSKTiledRasterBand : public GDALPamRasterBand 00129 { 00130 friend class PCIDSKDataset; 00131 00132 PCIDSKDataset *poPDS; 00133 00134 int nImage; 00135 00136 int nBlocks; 00137 vsi_l_offset *panBlockOffset;// offset in physical file. 00138 00139 int nTileCount; 00140 vsi_l_offset *panTileOffset; // offset in "image" virtual file. 00141 int *panTileSize; 00142 00143 int nOverviewCount; 00144 GDALRasterBand **papoOverviews; 00145 00146 char szCompression[9]; 00147 00148 void AttachOverview( GDALRasterBand *poOvBand ) { 00149 00150 nOverviewCount++; 00151 papoOverviews = (GDALRasterBand **) 00152 CPLRealloc(papoOverviews,sizeof(void*) * nOverviewCount); 00153 papoOverviews[nOverviewCount-1] = poOvBand; 00154 } 00155 00156 int BuildBlockMap(); 00157 int BuildTileMap(); 00158 00159 public: 00160 PCIDSKTiledRasterBand( PCIDSKDataset *, int, int ); 00161 ~PCIDSKTiledRasterBand(); 00162 00163 virtual CPLErr IReadBlock( int, int, void * ); 00164 00165 int SysRead( vsi_l_offset nOffset, int nSize, void * ); 00166 00167 virtual int GetOverviewCount() { return nOverviewCount; } 00168 virtual GDALRasterBand *GetOverview(int iOverview) 00169 { return papoOverviews[iOverview]; } 00170 }; 00171 00172 /************************************************************************/ 00173 /* PCIDSKRawRasterBand */ 00174 /************************************************************************/ 00175 00176 class PCIDSKRawRasterBand : public RawRasterBand 00177 { 00178 friend class PCIDSKDataset; 00179 00180 int nOverviewCount; 00181 GDALRasterBand **papoOverviews; 00182 00183 void AttachOverview( GDALRasterBand *poOvBand ) { 00184 nOverviewCount++; 00185 papoOverviews = (GDALRasterBand **) 00186 CPLRealloc(papoOverviews,sizeof(void*) * nOverviewCount); 00187 papoOverviews[nOverviewCount-1] = poOvBand; 00188 } 00189 00190 public: 00191 PCIDSKRawRasterBand( GDALDataset *poDS, int nBand, VSILFILE * fpRaw, 00192 vsi_l_offset nImgOffset, int nPixelOffset, 00193 int nLineOffset, 00194 GDALDataType eDataType, int bNativeOrder ) 00195 : RawRasterBand( poDS, nBand, fpRaw, nImgOffset, nPixelOffset, 00196 nLineOffset, eDataType, bNativeOrder, TRUE ) { 00197 nOverviewCount = 0; 00198 papoOverviews = NULL; 00199 } 00200 ~PCIDSKRawRasterBand() { 00201 FlushCache(); 00202 for( int i = 0; i < nOverviewCount; i++ ) 00203 delete papoOverviews[i]; 00204 CPLFree( papoOverviews ); 00205 } 00206 00207 virtual int GetOverviewCount() { 00208 if (nOverviewCount > 0) 00209 return nOverviewCount; 00210 00211 return RawRasterBand::GetOverviewCount(); 00212 } 00213 virtual GDALRasterBand *GetOverview(int iOverview) { 00214 if (iOverview < nOverviewCount) 00215 return papoOverviews[iOverview]; 00216 00217 return RawRasterBand::GetOverview(iOverview); 00218 } 00219 }; 00220 00221