Skip to content

Commit

Permalink
Merge pull request #10378 from rouault/ecw_progress
Browse files Browse the repository at this point in the history
ECW: emit error message before emitting progression, and one cleanup
  • Loading branch information
rouault committed Jul 8, 2024
2 parents 95c20a8 + bde8400 commit 22caab4
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions frmts/ecw/ecwcreatecopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1415,16 +1415,13 @@ static GDALDataset *ECWCreateCopy(const char *pszFilename, GDALDataset *poSrcDS,
oCompressor.pProgressData = pProgressData;
oCompressor.m_poSrcDS = poSrcDS;

if (!pfnProgress(0.0, nullptr, pProgressData))
return nullptr;

char **papszBandDescriptions = (char **)CPLMalloc(nBands * sizeof(char *));
CPLStringList aosBandDescriptions;
for (int i = 0; i < nBands; i++)
{
/* Make a copy since ECWGetColorInterpretationName() can return a string
* generated */
/* by CPLSPrintf(), which has just a few rotating entries. */
papszBandDescriptions[i] = CPLStrdup(ECWGetColorInterpretationName(
aosBandDescriptions.AddString(ECWGetColorInterpretationName(
poSrcDS->GetRasterBand(i + 1)->GetColorInterpretation(), i));
}

Expand All @@ -1433,39 +1430,34 @@ static GDALDataset *ECWCreateCopy(const char *pszFilename, GDALDataset *poSrcDS,
pszAreaOrPoint != nullptr && EQUAL(pszAreaOrPoint, GDALMD_AOP_POINT);

if (oCompressor.Initialize(pszFilename, papszOptions, nXSize, nYSize,
nBands, papszBandDescriptions, bRGBColorSpace,
eType, poSRS, adfGeoTransform,
nBands, aosBandDescriptions.List(),
bRGBColorSpace, eType, poSRS, adfGeoTransform,
poSrcDS->GetGCPCount(), poSrcDS->GetGCPs(),
bIsJPEG2000, bPixelIsPoint,
poSrcDS->GetMetadata("RPC"), poSrcDS) != CE_None)
{
for (int i = 0; i < nBands; i++)
CPLFree(papszBandDescriptions[i]);
CPLFree(papszBandDescriptions);
return nullptr;
}

/* -------------------------------------------------------------------- */
/* Start the compression. */
/* -------------------------------------------------------------------- */

if (!pfnProgress(0.0, nullptr, pProgressData))
return nullptr;

CNCSError oErr = oCompressor.Write();

if (oErr.GetErrorNumber() != NCS_SUCCESS)
{
ECWReportError(oErr);
for (int i = 0; i < nBands; i++)
CPLFree(papszBandDescriptions[i]);
CPLFree(papszBandDescriptions);
return nullptr;
}

/* -------------------------------------------------------------------- */
/* Cleanup, and return read-only handle. */
/* -------------------------------------------------------------------- */
oCompressor.CloseDown();
for (int i = 0; i < nBands; i++)
CPLFree(papszBandDescriptions[i]);
CPLFree(papszBandDescriptions);
pfnProgress(1.001, nullptr, pProgressData);

/* -------------------------------------------------------------------- */
Expand Down

0 comments on commit 22caab4

Please sign in to comment.