Skip to content

Commit 798923b

Browse files
committed
Fix build issues with non default programs gdalasyncread and gdalflattenmask
1 parent bbdbea6 commit 798923b

File tree

3 files changed

+39
-42
lines changed

3 files changed

+39
-42
lines changed

apps/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,9 @@ if (BUILD_APPS)
370370
# gcore/gdal_version.h
371371
target_include_directories(${UTILCMD} PRIVATE $<TARGET_PROPERTY:gcore,BINARY_DIR>/gdal_version_full)
372372
gdal_standard_includes(${UTILCMD})
373-
target_compile_options(${UTILCMD} PRIVATE ${GDAL_CXX_WARNING_FLAGS} ${WFLAG_OLD_STYLE_CAST})
373+
if (NOT "${UTILCMD}" STREQUAL "gdalflattenmask")
374+
target_compile_options(${UTILCMD} PRIVATE ${GDAL_CXX_WARNING_FLAGS} ${WFLAG_OLD_STYLE_CAST})
375+
endif()
374376
add_dependencies(${UTILCMD} generate_gdal_version_h)
375377
if (MSVC OR MINGW)
376378
target_compile_definitions(${UTILCMD} PRIVATE -DSUPPORTS_WMAIN)

apps/gdalasyncread.cpp

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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();

apps/gdalflattenmask.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ static void Usage()
4040
exit(1);
4141
}
4242

43+
static void IgnoreErr(CPLErr eErr)
44+
{
45+
(void)eErr;
46+
}
47+
4348
/************************************************************************/
4449
/* main() */
4550
/************************************************************************/
@@ -249,19 +254,20 @@ int main(int argc, char *argv[])
249254

250255
eDataType = GDALGetRasterDataType(hSrcBand);
251256
pabyBuffer =
252-
(GByte *)CPLMalloc(nXSize * GDALGetDataTypeSize(eDataType));
257+
(GByte *)CPLMalloc(nXSize * GDALGetDataTypeSizeBytes(eDataType));
253258
dfNoDataValue = GDALGetRasterNoDataValue(hSrcBand, &bHasNoData);
254259
if (!bHasNoData)
255260
dfNoDataValue = dfDstNoData;
256261

257262
for (iLine = 0; iLine < nYSize; iLine++)
258263
{
259-
GDALRasterIO(hSrcBand, GF_Read, 0, iLine, nXSize, 1, pabyBuffer,
260-
nXSize, 1, eDataType, 0, 0);
264+
IgnoreErr(GDALRasterIO(hSrcBand, GF_Read, 0, iLine, nXSize, 1,
265+
pabyBuffer, nXSize, 1, eDataType, 0, 0));
261266
if (!bSetAlpha)
262267
{
263-
GDALRasterIO(hMaskBand, GF_Read, 0, iLine, nXSize, 1,
264-
pabyMaskBuffer, nXSize, 1, GDT_UInt8, 0, 0);
268+
IgnoreErr(GDALRasterIO(hMaskBand, GF_Read, 0, iLine, nXSize, 1,
269+
pabyMaskBuffer, nXSize, 1, GDT_UInt8, 0,
270+
0));
265271
switch (eDataType)
266272
{
267273
case GDT_UInt8:
@@ -286,8 +292,8 @@ int main(int argc, char *argv[])
286292
}
287293
}
288294

289-
GDALRasterIO(hDstBand, GF_Write, 0, iLine, nXSize, 1, pabyBuffer,
290-
nXSize, 1, eDataType, 0, 0);
295+
IgnoreErr(GDALRasterIO(hDstBand, GF_Write, 0, iLine, nXSize, 1,
296+
pabyBuffer, nXSize, 1, eDataType, 0, 0));
291297
}
292298

293299
CPLFree(pabyBuffer);
@@ -307,16 +313,16 @@ int main(int argc, char *argv[])
307313
int iLine;
308314
for (iLine = 0; iLine < nYSize; iLine++)
309315
{
310-
GDALRasterIO(hMaskBand, GF_Read, 0, iLine, nXSize, 1,
311-
pabyMaskBuffer, nXSize, 1, GDT_UInt8, 0, 0);
316+
IgnoreErr(GDALRasterIO(hMaskBand, GF_Read, 0, iLine, nXSize, 1,
317+
pabyMaskBuffer, nXSize, 1, GDT_UInt8, 0, 0));
312318
for (iCol = 0; iCol < nXSize; iCol++)
313319
{
314320
/* If the mask is 1-bit, expand 1 to 255 */
315321
if (pabyMaskBuffer[iCol] == 1 && (nMaskFlag & GMF_ALPHA) == 0)
316322
pabyMaskBuffer[iCol] = 255;
317323
}
318-
GDALRasterIO(hDstAlphaBand, GF_Write, 0, iLine, nXSize, 1,
319-
pabyMaskBuffer, nXSize, 1, GDT_UInt8, 0, 0);
324+
IgnoreErr(GDALRasterIO(hDstAlphaBand, GF_Write, 0, iLine, nXSize, 1,
325+
pabyMaskBuffer, nXSize, 1, GDT_UInt8, 0, 0));
320326
}
321327
}
322328

0 commit comments

Comments
 (0)