From bdabe09b063ca50ca65014404d344362f079d316 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 28 Jan 2025 22:13:46 +0100 Subject: [PATCH] RawDataset: add a enum class Interleave, and use it in CPG and ENVI drivers, to fix issue with unity builds --- frmts/raw/cpgdataset.cpp | 45 ++++++++++++++++++--------------------- frmts/raw/envidataset.cpp | 17 +++++++-------- frmts/raw/envidataset.h | 9 ++------ gcore/rawdataset.h | 7 ++++++ 4 files changed, 38 insertions(+), 40 deletions(-) diff --git a/frmts/raw/cpgdataset.cpp b/frmts/raw/cpgdataset.cpp index 9e65d4334f3f..d0207bf8b3e2 100644 --- a/frmts/raw/cpgdataset.cpp +++ b/frmts/raw/cpgdataset.cpp @@ -18,13 +18,6 @@ #include -enum Interleave -{ - BSQ, - BIL, - BIP -}; - /************************************************************************/ /* ==================================================================== */ /* CPGDataset */ @@ -53,7 +46,7 @@ class CPGDataset final : public RawDataset int nLoadedStokesLine; float *padfStokesMatrix; - int nInterleave; + Interleave eInterleave = Interleave::BSQ; static int AdjustFilename(char **, const char *, const char *); static int FindType1(const char *pszWorkname); static int FindType2(const char *pszWorkname); @@ -101,7 +94,7 @@ class CPGDataset final : public RawDataset CPGDataset::CPGDataset() : nGCPCount(0), pasGCPList(nullptr), nLoadedStokesLine(-1), - padfStokesMatrix(nullptr), nInterleave(0) + padfStokesMatrix(nullptr) { m_oSRS.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER); m_oGCPSRS.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER); @@ -377,7 +370,7 @@ CPLErr CPGDataset::LoadStokesLine(int iLine, int bNativeOrder) /* Load all the pixel data associated with this scanline. */ /* Retains same interleaving as original dataset. */ /* -------------------------------------------------------------------- */ - if (nInterleave == BIP) + if (eInterleave == Interleave::BIP) { const int offset = nRasterXSize * iLine * nDataSize * 16; const int nBytesToRead = nDataSize * nRasterXSize * 16; @@ -396,7 +389,7 @@ CPLErr CPGDataset::LoadStokesLine(int iLine, int bNativeOrder) return CE_Failure; } } - else if (nInterleave == BIL) + else if (eInterleave == Interleave::BIL) { for (int band_index = 0; band_index < 16; band_index++) { @@ -810,7 +803,8 @@ GDALDataset *CPGDataset::InitializeType1Or2Dataset(const char *pszFilename) GDALDataset *CPGDataset::InitializeType3Dataset(const char *pszFilename) { int iBytesPerPixel = 0; - int iInterleave = -1; + Interleave::eInterleave = Interleave::BSQ; + bool bInterleaveSpecified = false; int nLines = 0; int nSamples = 0; int nBands = 0; @@ -845,11 +839,20 @@ GDALDataset *CPGDataset::InitializeType3Dataset(const char *pszFilename) { if (STARTS_WITH_CI(papszTokens[2], "BSQ")) - iInterleave = BSQ; + { + bInterleaveSpecified = true; + eInterleave = Interleave::BSQ; + } else if (STARTS_WITH_CI(papszTokens[2], "BIL")) - iInterleave = BIL; + { + bInterleaveSpecified = true; + eInterleave = Interleave::BIL; + } else if (STARTS_WITH_CI(papszTokens[2], "BIP")) - iInterleave = BIP; + { + bInterleaveSpecified = true; + eInterleave = Interleave::BIP; + } else { CPLError( @@ -979,7 +982,7 @@ GDALDataset *CPGDataset::InitializeType3Dataset(const char *pszFilename) } if (!GDALCheckDatasetDimensions(nSamples, nLines) || - !GDALCheckBandCount(nBands, FALSE) || iInterleave == -1 || + !GDALCheckBandCount(nBands, FALSE) || !bInterleaveSpecified || iBytesPerPixel == 0) { CPLError(CE_Failure, CPLE_AppDefined, @@ -998,13 +1001,7 @@ GDALDataset *CPGDataset::InitializeType3Dataset(const char *pszFilename) poDS->nRasterXSize = nSamples; poDS->nRasterYSize = nLines; - - if (iInterleave == BSQ) - poDS->nInterleave = BSQ; - else if (iInterleave == BIL) - poDS->nInterleave = BIL; - else - poDS->nInterleave = BIP; + poDS->eInterleave = eInterleave; /* -------------------------------------------------------------------- */ /* Open the 16 bands. */ @@ -1395,7 +1392,7 @@ CPLErr CPG_STOKESRasterBand::IReadBlock(CPL_UNUSED int nBlockXOff, float *M = poGDS->padfStokesMatrix; float *pafLine = reinterpret_cast(pImage); - if (poGDS->nInterleave == BIP) + if (poGDS->eInterleave == RawDataset::Interleave::BIP) { step = 16; m11 = M11; diff --git a/frmts/raw/envidataset.cpp b/frmts/raw/envidataset.cpp index 184682e29b62..f63c82f1fb44 100644 --- a/frmts/raw/envidataset.cpp +++ b/frmts/raw/envidataset.cpp @@ -85,8 +85,7 @@ static int ITTVISToUSGSZone(int nITTVISZone) ENVIDataset::ENVIDataset() : fpImage(nullptr), fp(nullptr), pszHDRFilename(nullptr), - bFoundMapinfo(false), bHeaderDirty(false), bFillFile(false), - interleave(BSQ) + bFoundMapinfo(false), bHeaderDirty(false), bFillFile(false) { adfGeoTransform[0] = 0.0; adfGeoTransform[1] = 1.0; @@ -217,15 +216,15 @@ CPLErr ENVIDataset::FlushCache(bool bAtClosing) const int iENVIType = GetEnviType(band->GetRasterDataType()); bOK &= VSIFPrintfL(fp, "data type = %d\n", iENVIType) >= 0; const char *pszInterleaving = nullptr; - switch (interleave) + switch (eInterleave) { - case BIP: + case Interleave::BIP: pszInterleaving = "bip"; // Interleaved by pixel. break; - case BIL: + case Interleave::BIL: pszInterleaving = "bil"; // Interleaved by line. break; - case BSQ: + case Interleave::BSQ: pszInterleaving = "bsq"; // Band sequential by default. break; default: @@ -2294,7 +2293,7 @@ ENVIDataset *ENVIDataset::Open(GDALOpenInfo *poOpenInfo, bool bFileSizeCheck) if (STARTS_WITH_CI(osInterleave, "bil")) { - poDS->interleave = BIL; + poDS->eInterleave = Interleave::BIL; poDS->SetMetadataItem("INTERLEAVE", "LINE", "IMAGE_STRUCTURE"); if (nSamples > std::numeric_limits::max() / (nDataSize * nBands)) { @@ -2307,7 +2306,7 @@ ENVIDataset *ENVIDataset::Open(GDALOpenInfo *poOpenInfo, bool bFileSizeCheck) } else if (STARTS_WITH_CI(osInterleave, "bip")) { - poDS->interleave = BIP; + poDS->eInterleave = Interleave::BIP; poDS->SetMetadataItem("INTERLEAVE", "PIXEL", "IMAGE_STRUCTURE"); if (nSamples > std::numeric_limits::max() / (nDataSize * nBands)) { @@ -2320,7 +2319,7 @@ ENVIDataset *ENVIDataset::Open(GDALOpenInfo *poOpenInfo, bool bFileSizeCheck) } else { - poDS->interleave = BSQ; + poDS->eInterleave = Interleave::BSQ; poDS->SetMetadataItem("INTERLEAVE", "BAND", "IMAGE_STRUCTURE"); if (nSamples > std::numeric_limits::max() / nDataSize) { diff --git a/frmts/raw/envidataset.h b/frmts/raw/envidataset.h index b42b50f5759d..6e7588b05eeb 100644 --- a/frmts/raw/envidataset.h +++ b/frmts/raw/envidataset.h @@ -65,6 +65,8 @@ class ENVIDataset final : public RawDataset std::vector m_asGCPs{}; + Interleave eInterleave = Interleave::BSQ; + bool ReadHeader(VSILFILE *); bool ProcessMapinfo(const char *); void ProcessRPCinfo(const char *, int, int); @@ -88,13 +90,6 @@ class ENVIDataset final : public RawDataset static char **SplitList(const char *); - enum Interleave - { - BSQ, - BIL, - BIP - } interleave; - static int GetEnviType(GDALDataType eType); CPL_DISALLOW_COPY_ASSIGN(ENVIDataset) diff --git a/gcore/rawdataset.h b/gcore/rawdataset.h index 77e92c646ff3..2773ace6c6e5 100644 --- a/gcore/rawdataset.h +++ b/gcore/rawdataset.h @@ -46,6 +46,13 @@ class CPL_DLL RawDataset : public GDALPamDataset RawDataset(); virtual ~RawDataset() = 0; + enum class Interleave + { + BSQ, + BIL, + BIP, + }; + bool GetRawBinaryLayout(GDALDataset::RawBinaryLayout &) override; void ClearCachedConfigOption(void);