Skip to content

Commit

Permalink
JPEG: use gdal::GCP
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Feb 26, 2024
1 parent 513264f commit 7b4cc89
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
23 changes: 11 additions & 12 deletions frmts/jpeg/jpgdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2499,7 +2493,7 @@ int JPGDatasetCommon::GetGCPCount()

LoadWorldFileOrTab();

return nGCPCount;
return static_cast<int>(m_aoGCPs.size());
}

/************************************************************************/
Expand All @@ -2516,7 +2510,7 @@ const OGRSpatialReference *JPGDatasetCommon::GetGCPSpatialRef() const

const_cast<JPGDatasetCommon *>(this)->LoadWorldFileOrTab();

if (!m_oSRS.IsEmpty() && nGCPCount > 0)
if (!m_oSRS.IsEmpty() && !m_aoGCPs.empty())
return &m_oSRS;

return nullptr;
Expand All @@ -2535,7 +2529,7 @@ const GDAL_GCP *JPGDatasetCommon::GetGCPs()

LoadWorldFileOrTab();

return pasGCPList;
return gdal::GCP::c_ptr(m_aoGCPs);
}

/************************************************************************/
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions frmts/jpeg/jpgdataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<gdal::GCP> m_aoGCPs{};

VSILFILE *m_fpImage;
GUIntBig nSubfileOffset;
Expand Down

0 comments on commit 7b4cc89

Please sign in to comment.