00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
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;
00057
00058 vsi_l_offset nGeoPtrOffset;
00059
00060 vsi_l_offset nGeoOffset;
00061 vsi_l_offset nGcpPtrOffset;
00062
00063 vsi_l_offset nGcpOffset;
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
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
00118 int SegRead( int nSegment,
00119 vsi_l_offset nOffset,
00120 int nSize,
00121 void *pBuffer );
00122 };
00123
00124
00125
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;
00138
00139 int nTileCount;
00140 vsi_l_offset *panTileOffset;
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
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