1 /******************************************************************************
2 * $Id: hfatest.cpp 27044 2014-03-16 23:41:27Z rouault $
3 *
4 * Project: Erdas Imagine (.img) Translator
5 * Purpose: Testing mainline for HFA services - transitory.
6 * Author: Frank Warmerdam, warmerdam@pobox.com
7 *
8 ******************************************************************************
9 * Copyright (c) 1999, Intergraph Corporation
10 * Copyright (c) 2009-2011, Even Rouault <even dot rouault at mines-paris dot org>
11 *
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the "Software"),
14 * to deal in the Software without restriction, including without limitation
15 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 * and/or sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following conditions:
18 *
19 * The above copyright notice and this permission notice shall be included
20 * in all copies or substantial portions of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 * DEALINGS IN THE SOFTWARE.
29 ****************************************************************************/
30
31 #include "hfa_p.h"
32 #include "cpl_multiproc.h"
33
34 CPL_CVSID("$Id: hfatest.cpp 27044 2014-03-16 23:41:27Z rouault $");
35
36 /************************************************************************/
37 /* Usage() */
38 /************************************************************************/
39
Usage()40 static void Usage()
41
42 {
43 printf( "hfatest [-dd] [-dt] [-dr] filename\n" );
44 }
45
46 /************************************************************************/
47 /* Stub for HFAPCSStructToWKT, defined in hfadataset.cpp but used by */
48 /* hfaopen.cpp */
49 /************************************************************************/
50 #ifndef WIN32
51 char *
HFAPCSStructToWKT(const Eprj_Datum * psDatum,const Eprj_ProParameters * psPro,const Eprj_MapInfo * psMapInfo,HFAEntry * poMapInformation)52 HFAPCSStructToWKT( const Eprj_Datum *psDatum,
53 const Eprj_ProParameters *psPro,
54 const Eprj_MapInfo *psMapInfo,
55 HFAEntry *poMapInformation )
56 {
57 return NULL;
58 }
59 #endif
60
61 /************************************************************************/
62 /* main() */
63 /************************************************************************/
64
main(int argc,char ** argv)65 int main( int argc, char ** argv )
66
67 {
68 const char *pszFilename = NULL;
69 int nDumpTree = FALSE;
70 int nDumpDict = FALSE;
71 int nRastReport = FALSE;
72 int i, nXSize, nYSize, nBands;
73 HFAHandle hHFA;
74 const Eprj_MapInfo *psMapInfo;
75 const Eprj_ProParameters *psProParameters;
76 const Eprj_Datum *psDatum;
77
78 /* -------------------------------------------------------------------- */
79 /* Handle arguments. */
80 /* -------------------------------------------------------------------- */
81 for( i = 1; i < argc; i++ )
82 {
83 if( EQUAL(argv[i],"-dd") )
84 nDumpDict = TRUE;
85 else if( EQUAL(argv[i],"-dt") )
86 nDumpTree = TRUE;
87 else if( EQUAL(argv[i],"-dr") )
88 nRastReport = TRUE;
89 else if( pszFilename == NULL )
90 pszFilename = argv[i];
91 else
92 {
93 Usage();
94 exit( 1 );
95 }
96 }
97
98 if( pszFilename == NULL )
99 {
100 Usage();
101 exit( 1 );
102 }
103
104 /* -------------------------------------------------------------------- */
105 /* Open the file. */
106 /* -------------------------------------------------------------------- */
107 hHFA = HFAOpen( pszFilename, "r" );
108
109 if( hHFA == NULL )
110 {
111 printf( "HFAOpen() failed.\n" );
112 exit( 100 );
113 }
114
115 /* -------------------------------------------------------------------- */
116 /* Do we want to walk the tree dumping out general information? */
117 /* -------------------------------------------------------------------- */
118 if( nDumpDict )
119 {
120 HFADumpDictionary( hHFA, stdout );
121 }
122
123 /* -------------------------------------------------------------------- */
124 /* Do we want to walk the tree dumping out general information? */
125 /* -------------------------------------------------------------------- */
126 if( nDumpTree )
127 {
128 HFADumpTree( hHFA, stdout );
129 }
130
131 /* -------------------------------------------------------------------- */
132 /* Dump indirectly collected data about bands. */
133 /* -------------------------------------------------------------------- */
134 HFAGetRasterInfo( hHFA, &nXSize, &nYSize, &nBands );
135
136 if( nRastReport )
137 {
138 printf( "Raster Size = %d x %d\n", nXSize, nYSize );
139
140 for( i = 1; i <= nBands; i++ )
141 {
142 int nDataType, nColors, nOverviews, iOverview;
143 double *padfRed, *padfGreen, *padfBlue, *padfAlpha, *padfBins;
144 int nBlockXSize, nBlockYSize, nCompressionType;
145
146 HFAGetBandInfo( hHFA, i, &nDataType, &nBlockXSize, &nBlockYSize,
147 &nCompressionType );
148 nOverviews = HFAGetOverviewCount( hHFA, i );
149
150 printf( "Band %d: %dx%d tiles, type = %d\n",
151 i, nBlockXSize, nBlockYSize, nDataType );
152
153 for( iOverview=0; iOverview < nOverviews; iOverview++ )
154 {
155 HFAGetOverviewInfo( hHFA, i, iOverview,
156 &nXSize, &nYSize,
157 &nBlockXSize, &nBlockYSize, NULL );
158 printf( " Overview: %dx%d (blocksize %dx%d)\n",
159 nXSize, nYSize, nBlockXSize, nBlockYSize );
160 }
161
162 if( HFAGetPCT( hHFA, i, &nColors, &padfRed, &padfGreen,
163 &padfBlue, &padfAlpha, &padfBins )
164 == CE_None )
165 {
166 int j;
167
168 for( j = 0; j < nColors; j++ )
169 {
170 printf( "PCT[%d] = %f,%f,%f %f\n",
171 (padfBins != NULL) ? (int) padfBins[j] : j,
172 padfRed[j], padfGreen[j],
173 padfBlue[j], padfAlpha[j]);
174 }
175 }
176
177 /* -------------------------------------------------------------------- */
178 /* Report statistics. We need to dig directly into the C++ API. */
179 /* -------------------------------------------------------------------- */
180 HFABand *poBand = hHFA->papoBand[i-1];
181 HFAEntry *poStats = poBand->poNode->GetNamedChild( "Statistics" );
182
183 if( poStats != NULL )
184 {
185 printf( " Min: %g Max: %g Mean: %g\n",
186 poStats->GetDoubleField( "minimum" ),
187 poStats->GetDoubleField( "maximum" ),
188 poStats->GetDoubleField( "mean" ) );
189 printf( " Median: %g Mode: %g Stddev: %g\n",
190 poStats->GetDoubleField( "median" ),
191 poStats->GetDoubleField( "mode" ),
192 poStats->GetDoubleField( "stddev" ) );
193 }
194 else
195 printf( " No Statistics found.\n" );
196 }
197
198 /* -------------------------------------------------------------------- */
199 /* Dump the map info structure. */
200 /* -------------------------------------------------------------------- */
201 psMapInfo = HFAGetMapInfo( hHFA );
202
203 if( psMapInfo != NULL )
204 {
205 printf( "MapInfo.proName = %s\n", psMapInfo->proName );
206 printf( "MapInfo.upperLeftCenter.x = %.2f\n",
207 psMapInfo->upperLeftCenter.x );
208 printf( "MapInfo.upperLeftCenter.y = %.2f\n",
209 psMapInfo->upperLeftCenter.y );
210 }
211 else
212 {
213 printf( "No Map Info found\n" );
214 }
215
216 }
217
218 psProParameters = HFAGetProParameters( hHFA );
219
220 psDatum = HFAGetDatum( hHFA );
221
222 HFAClose( hHFA );
223
224 VSICleanupFileManager();
225 CPLCleanupTLS();
226
227 #ifdef DBMALLOC
228 malloc_dump(1);
229 #endif
230
231 exit( 0 );
232 }
233