@@ -64,15 +64,13 @@ int main(int argc, char **argv)
6464 int nRasterXSize, nRasterYSize;
6565 const char *pszSource = nullptr , *pszDest = nullptr , *pszFormat = " GTiff" ;
6666 GDALDriverH hDriver;
67- int *panBandList = nullptr , nBandCount = 0 , bDefBands = TRUE ;
67+ int *panBandList = nullptr , nBandCount = 0 ;
6868 GDALDataType eOutputType = GDT_Unknown;
6969 int nOXSize = 0 , nOYSize = 0 ;
7070 char **papszCreateOptions = nullptr ;
7171 char **papszAsyncOptions = nullptr ;
7272 int anSrcWin[4 ];
7373 int bQuiet = FALSE ;
74- GDALProgressFunc pfnProgress = GDALTermProgress;
75- int iSrcFileArg = -1 , iDstFileArg = -1 ;
7674 int bMulti = FALSE ;
7775 double dfTimeout = -1.0 ;
7876 const char *pszOXSize = nullptr , *pszOYSize = nullptr ;
@@ -118,18 +116,18 @@ int main(int argc, char **argv)
118116 else if (EQUAL (argv[i], " -quiet" ))
119117 {
120118 bQuiet = TRUE ;
121- pfnProgress = GDALDummyProgress;
122119 }
123120
124121 else if (EQUAL (argv[i], " -ot" ) && i < argc - 1 )
125122 {
126123 for (int iType = 1 ; iType < GDT_TypeCount; iType++)
127124 {
128- if (GDALGetDataTypeName ((GDALDataType)iType) != nullptr &&
129- EQUAL (GDALGetDataTypeName ((GDALDataType)iType),
125+ if (GDALGetDataTypeName (static_cast <GDALDataType>(iType)) !=
126+ nullptr &&
127+ EQUAL (GDALGetDataTypeName (static_cast <GDALDataType>(iType)),
130128 argv[i + 1 ]))
131129 {
132- eOutputType = ( GDALDataType) iType;
130+ eOutputType = static_cast < GDALDataType>( iType) ;
133131 }
134132 }
135133
@@ -157,9 +155,6 @@ int main(int argc, char **argv)
157155 panBandList = static_cast <int *>(
158156 CPLRealloc (panBandList, sizeof (int ) * nBandCount));
159157 panBandList[nBandCount - 1 ] = atoi (argv[++i]);
160-
161- if (panBandList[nBandCount - 1 ] != nBandCount)
162- bDefBands = FALSE ;
163158 }
164159 else if (EQUAL (argv[i], " -co" ) && i < argc - 1 )
165160 {
@@ -203,13 +198,11 @@ int main(int argc, char **argv)
203198 }
204199 else if (pszSource == nullptr )
205200 {
206- iSrcFileArg = i;
207201 pszSource = argv[i];
208202 }
209203 else if (pszDest == nullptr )
210204 {
211205 pszDest = argv[i];
212- iDstFileArg = i;
213206 }
214207
215208 else
@@ -240,7 +233,7 @@ int main(int argc, char **argv)
240233 /* -------------------------------------------------------------------- */
241234
242235 hSrcDS = GDALOpenShared (pszSource, GA_ReadOnly);
243- poSrcDS = ( GDALDataset *) hSrcDS;
236+ poSrcDS = GDALDataset::FromHandle ( hSrcDS) ;
244237
245238 if (hSrcDS == nullptr )
246239 {
@@ -316,9 +309,6 @@ int main(int argc, char **argv)
316309 exit (2 );
317310 }
318311 }
319-
320- if (nBandCount != GDALGetRasterCount (hSrcDS))
321- bDefBands = FALSE ;
322312 }
323313
324314 /* -------------------------------------------------------------------- */
@@ -359,7 +349,7 @@ int main(int argc, char **argv)
359349 " writing:\n " );
360350 for (int iDr = 0 ; iDr < GDALGetDriverCount (); iDr++)
361351 {
362- GDALDriverH hDriver = GDALGetDriver (iDr);
352+ hDriver = GDALGetDriver (iDr);
363353
364354 if (GDALGetMetadataItem (hDriver, GDAL_DCAP_CREATE, nullptr ) !=
365355 nullptr )
@@ -445,28 +435,26 @@ int main(int argc, char **argv)
445435 exit (1 );
446436 }
447437
448- poDstDS = ( GDALDataset *) hDstDS;
438+ poDstDS = GDALDataset::FromHandle ( hDstDS) ;
449439
450440 /* --------------------------------------------------------------------
451441 */
452442 /* Copy georeferencing. */
453443 /* --------------------------------------------------------------------
454444 */
455- double adfGeoTransform[ 6 ] ;
445+ GDALGeoTransform gt ;
456446
457- if (poSrcDS->GetGeoTransform (adfGeoTransform ) == CE_None)
447+ if (poSrcDS->GetGeoTransform (gt ) == CE_None)
458448 {
459- adfGeoTransform[0 ] += anSrcWin[0 ] * adfGeoTransform[1 ] +
460- anSrcWin[1 ] * adfGeoTransform[2 ];
461- adfGeoTransform[3 ] += anSrcWin[0 ] * adfGeoTransform[4 ] +
462- anSrcWin[1 ] * adfGeoTransform[5 ];
449+ gt[0 ] += anSrcWin[0 ] * gt[1 ] + anSrcWin[1 ] * gt[2 ];
450+ gt[3 ] += anSrcWin[0 ] * gt[4 ] + anSrcWin[1 ] * gt[5 ];
463451
464- adfGeoTransform [1 ] *= anSrcWin[2 ] / (double ) nOXSize;
465- adfGeoTransform [2 ] *= anSrcWin[3 ] / (double ) nOYSize;
466- adfGeoTransform [4 ] *= anSrcWin[2 ] / (double ) nOXSize;
467- adfGeoTransform [5 ] *= anSrcWin[3 ] / (double ) nOYSize;
452+ gt [1 ] *= anSrcWin[2 ] / (1.0 * nOXSize) ;
453+ gt [2 ] *= anSrcWin[3 ] / (1.0 * nOYSize) ;
454+ gt [4 ] *= anSrcWin[2 ] / (1.0 * nOXSize) ;
455+ gt [5 ] *= anSrcWin[3 ] / (1.0 * nOYSize) ;
468456
469- poDstDS->SetGeoTransform (adfGeoTransform );
457+ poDstDS->SetGeoTransform (gt );
470458 }
471459
472460 poDstDS->SetProjection (poSrcDS->GetProjectionRef ());
@@ -505,7 +493,8 @@ int main(int argc, char **argv)
505493 poAsyncReq->LockBuffer ();
506494 eErr = poDstDS->RasterIO (
507495 GF_Write, nUpXOff, nUpYOff, nUpXSize, nUpYSize,
508- ((GByte *)pImage) + nUpXOff * nPixelSpace + nUpYOff * nLineSpace,
496+ static_cast <GByte *>(pImage) + nUpXOff * nPixelSpace +
497+ nUpYOff * nLineSpace,
509498 nUpXSize, nUpYSize, eOutputType, nBandCount, nullptr , nPixelSpace,
510499 nLineSpace, nBandSpace, nullptr );
511500 poAsyncReq->UnlockBuffer ();
0 commit comments