My Project
gdal_pcidsk.h
1 /******************************************************************************
2  * $Id: gdal_pcidsk.h 20996 2010-10-28 18:38:15Z rouault $
3  *
4  * Project: PCIDSK Database File
5  * Purpose: PCIDSK driver declarations.
6  * Author: Andrey Kiselev, dron@remotesensing.org
7  *
8  ******************************************************************************
9  * Copyright (c) 2003, Andrey Kiselev <dron@remotesensing.org>
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included
19  * in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  ****************************************************************************/
29 
30 #include "cpl_conv.h"
31 #include "cpl_string.h"
32 #include "ogr_spatialref.h"
33 #include "rawdataset.h"
34 
35 typedef enum
36 {
37  PDI_PIXEL,
38  PDI_BAND,
39  PDI_FILE
40 } PCIDSKInterleaving;
41 
42 /************************************************************************/
43 /* PCIDSKDataset */
44 /************************************************************************/
45 
46 class PCIDSKDataset : public RawDataset
47 {
48  friend class PCIDSKRawRasterBand;
49  friend class PCIDSKTiledRasterBand;
50 
51  const char *pszFilename;
52  VSILFILE *fp;
53 
54  vsi_l_offset nFileSize;
55 
56  char *pszCreatTime; // Date/time of the database creation
57 
58  vsi_l_offset nGeoPtrOffset; // Offset in bytes to the pointer
59  // to GEO segment
60  vsi_l_offset nGeoOffset; // Offset in bytes to the GEO segment
61  vsi_l_offset nGcpPtrOffset; // Offset in bytes to the pointer
62  // to GCP segment
63  vsi_l_offset nGcpOffset; // Offset in bytes to the GCP segment
64 
65  int bGeoSegmentDirty;
66  int bGeoTransformValid;
67 
68  int nBlockMapSeg;
69 
70  GDAL_GCP *pasGCPList;
71  long nGCPCount;
72 
73  double adfGeoTransform[6];
74  char *pszProjection;
75  char *pszGCPProjection;
76 
77  GDALDataType PCIDSKTypeToGDAL( const char *);
78  void WriteGeoSegment();
79 
80  void CollectPCIDSKMetadata( int nSegment );
81 
82  // Segment map
83  int nSegCount;
84  int *panSegType;
85  char **papszSegName;
86  vsi_l_offset *panSegOffset;
87  vsi_l_offset *panSegSize;
88 
89  int nBandFileCount;
90  VSILFILE **pafpBandFiles;
91 
92  public:
93  PCIDSKDataset();
94  ~PCIDSKDataset();
95 
96  static int Identify( GDALOpenInfo * );
97  static GDALDataset *Open( GDALOpenInfo * );
98  static GDALDataset *Create( const char * pszFilename,
99  int nXSize, int nYSize, int nBands,
100  GDALDataType eType, char **papszParmList );
101  static GDALDataset *CreateCopy( const char * pszFilename,
102  GDALDataset *poSrcDS,
103  int bStrict, char ** papszOptions,
104  GDALProgressFunc pfnProgress,
105  void * pProgressData );
106 
107  virtual void FlushCache( void );
108 
109  CPLErr GetGeoTransform( double * padfTransform );
110  virtual CPLErr SetGeoTransform( double * );
111  const char *GetProjectionRef();
112  virtual CPLErr SetProjection( const char * );
113  virtual int GetGCPCount();
114  virtual const char *GetGCPProjection();
115  virtual const GDAL_GCP *GetGCPs();
116 
117  // pcidsk specific
118  int SegRead( int nSegment,
119  vsi_l_offset nOffset,
120  int nSize,
121  void *pBuffer );
122 };
123 
124 /************************************************************************/
125 /* PCIDSKTiledRasterBand */
126 /************************************************************************/
127 
128 class PCIDSKTiledRasterBand : public GDALPamRasterBand
129 {
130  friend class PCIDSKDataset;
131 
132  PCIDSKDataset *poPDS;
133 
134  int nImage;
135 
136  int nBlocks;
137  vsi_l_offset *panBlockOffset;// offset in physical file.
138 
139  int nTileCount;
140  vsi_l_offset *panTileOffset; // offset in "image" virtual file.
141  int *panTileSize;
142 
143  int nOverviewCount;
144  GDALRasterBand **papoOverviews;
145 
146  char szCompression[9];
147 
148  void AttachOverview( GDALRasterBand *poOvBand ) {
149 
150  nOverviewCount++;
151  papoOverviews = (GDALRasterBand **)
152  CPLRealloc(papoOverviews,sizeof(void*) * nOverviewCount);
153  papoOverviews[nOverviewCount-1] = poOvBand;
154  }
155 
156  int BuildBlockMap();
157  int BuildTileMap();
158 
159  public:
160  PCIDSKTiledRasterBand( PCIDSKDataset *, int, int );
162 
163  virtual CPLErr IReadBlock( int, int, void * );
164 
165  int SysRead( vsi_l_offset nOffset, int nSize, void * );
166 
167  virtual int GetOverviewCount() { return nOverviewCount; }
168  virtual GDALRasterBand *GetOverview(int iOverview)
169  { return papoOverviews[iOverview]; }
170 };
171 
172 /************************************************************************/
173 /* PCIDSKRawRasterBand */
174 /************************************************************************/
175 
176 class PCIDSKRawRasterBand : public RawRasterBand
177 {
178  friend class PCIDSKDataset;
179 
180  int nOverviewCount;
181  GDALRasterBand **papoOverviews;
182 
183  void AttachOverview( GDALRasterBand *poOvBand ) {
184  nOverviewCount++;
185  papoOverviews = (GDALRasterBand **)
186  CPLRealloc(papoOverviews,sizeof(void*) * nOverviewCount);
187  papoOverviews[nOverviewCount-1] = poOvBand;
188  }
189 
190  public:
191  PCIDSKRawRasterBand( GDALDataset *poDS, int nBand, VSILFILE * fpRaw,
192  vsi_l_offset nImgOffset, int nPixelOffset,
193  int nLineOffset,
194  GDALDataType eDataType, int bNativeOrder )
195  : RawRasterBand( poDS, nBand, fpRaw, nImgOffset, nPixelOffset,
196  nLineOffset, eDataType, bNativeOrder, TRUE ) {
197  nOverviewCount = 0;
198  papoOverviews = NULL;
199  }
201  FlushCache();
202  for( int i = 0; i < nOverviewCount; i++ )
203  delete papoOverviews[i];
204  CPLFree( papoOverviews );
205  }
206 
207  virtual int GetOverviewCount() {
208  if (nOverviewCount > 0)
209  return nOverviewCount;
210 
211  return RawRasterBand::GetOverviewCount();
212  }
213  virtual GDALRasterBand *GetOverview(int iOverview) {
214  if (iOverview < nOverviewCount)
215  return papoOverviews[iOverview];
216 
217  return RawRasterBand::GetOverview(iOverview);
218  }
219 };
220 
221 
Definition: gdal_pcidsk.h:176
Definition: gdal_pcidsk.h:128
Definition: gdal_pcidsk.h:46