From 7b4cc899e0d72a444dc6856e299c9a45896c76a7 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 26 Feb 2024 17:06:50 +0100 Subject: [PATCH] JPEG: use gdal::GCP --- frmts/jpeg/jpgdataset.cpp | 23 +++++++++++------------ frmts/jpeg/jpgdataset.h | 3 +-- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/frmts/jpeg/jpgdataset.cpp b/frmts/jpeg/jpgdataset.cpp index d50d3cc0332f..3256371402d1 100644 --- a/frmts/jpeg/jpgdataset.cpp +++ b/frmts/jpeg/jpgdataset.cpp @@ -1643,9 +1643,9 @@ int JPGRasterBand::GetOverviewCount() JPGDatasetCommon::JPGDatasetCommon() : nScaleFactor(1), bHasInitInternalOverviews(false), nInternalOverviewsCurrent(0), nInternalOverviewsToFree(0), - papoInternalOverviews(nullptr), bGeoTransformValid(false), nGCPCount(0), - pasGCPList(nullptr), m_fpImage(nullptr), nSubfileOffset(0), - nLoadedScanline(-1), m_pabyScanline(nullptr), bHasReadEXIFMetadata(false), + papoInternalOverviews(nullptr), bGeoTransformValid(false), + m_fpImage(nullptr), nSubfileOffset(0), nLoadedScanline(-1), + m_pabyScanline(nullptr), bHasReadEXIFMetadata(false), bHasReadXMPMetadata(false), bHasReadICCMetadata(false), papszMetadata(nullptr), nExifOffset(-1), nInterOffset(-1), nGPSOffset(-1), bSwabflag(false), nTiffDirStart(-1), nTIFFHEADER(-1), @@ -1678,12 +1678,6 @@ JPGDatasetCommon::~JPGDatasetCommon() if (papszMetadata != nullptr) CSLDestroy(papszMetadata); - if (nGCPCount > 0) - { - GDALDeinitGCPs(nGCPCount, pasGCPList); - CPLFree(pasGCPList); - } - CPLFree(pabyBitMask); CPLFree(pabyCMask); delete poMaskBand; @@ -2499,7 +2493,7 @@ int JPGDatasetCommon::GetGCPCount() LoadWorldFileOrTab(); - return nGCPCount; + return static_cast(m_aoGCPs.size()); } /************************************************************************/ @@ -2516,7 +2510,7 @@ const OGRSpatialReference *JPGDatasetCommon::GetGCPSpatialRef() const const_cast(this)->LoadWorldFileOrTab(); - if (!m_oSRS.IsEmpty() && nGCPCount > 0) + if (!m_oSRS.IsEmpty() && !m_aoGCPs.empty()) return &m_oSRS; return nullptr; @@ -2535,7 +2529,7 @@ const GDAL_GCP *JPGDatasetCommon::GetGCPs() LoadWorldFileOrTab(); - return pasGCPList; + return gdal::GCP::c_ptr(m_aoGCPs); } /************************************************************************/ @@ -3151,12 +3145,17 @@ void JPGDatasetCommon::LoadWorldFileOrTab() if (!bGeoTransformValid) { char *pszProjection = nullptr; + int nGCPCount = 0; + GDAL_GCP *pasGCPList = nullptr; const bool bTabFileOK = CPL_TO_BOOL(GDALReadTabFile2( GetDescription(), adfGeoTransform, &pszProjection, &nGCPCount, &pasGCPList, oOvManager.GetSiblingFiles(), &pszWldFilename)); if (pszProjection) m_oSRS.importFromWkt(pszProjection); CPLFree(pszProjection); + m_aoGCPs = gdal::GCP::fromC(pasGCPList, nGCPCount); + GDALDeinitGCPs(nGCPCount, pasGCPList); + CPLFree(pasGCPList); if (bTabFileOK && nGCPCount == 0) bGeoTransformValid = true; diff --git a/frmts/jpeg/jpgdataset.h b/frmts/jpeg/jpgdataset.h index 2c4b690056de..ed8ff651f999 100644 --- a/frmts/jpeg/jpgdataset.h +++ b/frmts/jpeg/jpgdataset.h @@ -173,8 +173,7 @@ class JPGDatasetCommon CPL_NON_FINAL : public GDALPamDataset OGRSpatialReference m_oSRS{}; bool bGeoTransformValid; double adfGeoTransform[6]; - int nGCPCount; - GDAL_GCP *pasGCPList; + std::vector m_aoGCPs{}; VSILFILE *m_fpImage; GUIntBig nSubfileOffset;