Skip to content

Commit bdabe09

Browse files
committed
RawDataset: add a enum class Interleave, and use it in CPG and ENVI drivers, to fix issue with unity builds
1 parent 537bc43 commit bdabe09

File tree

4 files changed

+38
-40
lines changed

4 files changed

+38
-40
lines changed

frmts/raw/cpgdataset.cpp

+21-24
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@
1818

1919
#include <vector>
2020

21-
enum Interleave
22-
{
23-
BSQ,
24-
BIL,
25-
BIP
26-
};
27-
2821
/************************************************************************/
2922
/* ==================================================================== */
3023
/* CPGDataset */
@@ -53,7 +46,7 @@ class CPGDataset final : public RawDataset
5346
int nLoadedStokesLine;
5447
float *padfStokesMatrix;
5548

56-
int nInterleave;
49+
Interleave eInterleave = Interleave::BSQ;
5750
static int AdjustFilename(char **, const char *, const char *);
5851
static int FindType1(const char *pszWorkname);
5952
static int FindType2(const char *pszWorkname);
@@ -101,7 +94,7 @@ class CPGDataset final : public RawDataset
10194

10295
CPGDataset::CPGDataset()
10396
: nGCPCount(0), pasGCPList(nullptr), nLoadedStokesLine(-1),
104-
padfStokesMatrix(nullptr), nInterleave(0)
97+
padfStokesMatrix(nullptr)
10598
{
10699
m_oSRS.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
107100
m_oGCPSRS.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
@@ -377,7 +370,7 @@ CPLErr CPGDataset::LoadStokesLine(int iLine, int bNativeOrder)
377370
/* Load all the pixel data associated with this scanline. */
378371
/* Retains same interleaving as original dataset. */
379372
/* -------------------------------------------------------------------- */
380-
if (nInterleave == BIP)
373+
if (eInterleave == Interleave::BIP)
381374
{
382375
const int offset = nRasterXSize * iLine * nDataSize * 16;
383376
const int nBytesToRead = nDataSize * nRasterXSize * 16;
@@ -396,7 +389,7 @@ CPLErr CPGDataset::LoadStokesLine(int iLine, int bNativeOrder)
396389
return CE_Failure;
397390
}
398391
}
399-
else if (nInterleave == BIL)
392+
else if (eInterleave == Interleave::BIL)
400393
{
401394
for (int band_index = 0; band_index < 16; band_index++)
402395
{
@@ -810,7 +803,8 @@ GDALDataset *CPGDataset::InitializeType1Or2Dataset(const char *pszFilename)
810803
GDALDataset *CPGDataset::InitializeType3Dataset(const char *pszFilename)
811804
{
812805
int iBytesPerPixel = 0;
813-
int iInterleave = -1;
806+
Interleave::eInterleave = Interleave::BSQ;
807+
bool bInterleaveSpecified = false;
814808
int nLines = 0;
815809
int nSamples = 0;
816810
int nBands = 0;
@@ -845,11 +839,20 @@ GDALDataset *CPGDataset::InitializeType3Dataset(const char *pszFilename)
845839
{
846840

847841
if (STARTS_WITH_CI(papszTokens[2], "BSQ"))
848-
iInterleave = BSQ;
842+
{
843+
bInterleaveSpecified = true;
844+
eInterleave = Interleave::BSQ;
845+
}
849846
else if (STARTS_WITH_CI(papszTokens[2], "BIL"))
850-
iInterleave = BIL;
847+
{
848+
bInterleaveSpecified = true;
849+
eInterleave = Interleave::BIL;
850+
}
851851
else if (STARTS_WITH_CI(papszTokens[2], "BIP"))
852-
iInterleave = BIP;
852+
{
853+
bInterleaveSpecified = true;
854+
eInterleave = Interleave::BIP;
855+
}
853856
else
854857
{
855858
CPLError(
@@ -979,7 +982,7 @@ GDALDataset *CPGDataset::InitializeType3Dataset(const char *pszFilename)
979982
}
980983

981984
if (!GDALCheckDatasetDimensions(nSamples, nLines) ||
982-
!GDALCheckBandCount(nBands, FALSE) || iInterleave == -1 ||
985+
!GDALCheckBandCount(nBands, FALSE) || !bInterleaveSpecified ||
983986
iBytesPerPixel == 0)
984987
{
985988
CPLError(CE_Failure, CPLE_AppDefined,
@@ -998,13 +1001,7 @@ GDALDataset *CPGDataset::InitializeType3Dataset(const char *pszFilename)
9981001

9991002
poDS->nRasterXSize = nSamples;
10001003
poDS->nRasterYSize = nLines;
1001-
1002-
if (iInterleave == BSQ)
1003-
poDS->nInterleave = BSQ;
1004-
else if (iInterleave == BIL)
1005-
poDS->nInterleave = BIL;
1006-
else
1007-
poDS->nInterleave = BIP;
1004+
poDS->eInterleave = eInterleave;
10081005

10091006
/* -------------------------------------------------------------------- */
10101007
/* Open the 16 bands. */
@@ -1395,7 +1392,7 @@ CPLErr CPG_STOKESRasterBand::IReadBlock(CPL_UNUSED int nBlockXOff,
13951392
float *M = poGDS->padfStokesMatrix;
13961393
float *pafLine = reinterpret_cast<float *>(pImage);
13971394

1398-
if (poGDS->nInterleave == BIP)
1395+
if (poGDS->eInterleave == RawDataset::Interleave::BIP)
13991396
{
14001397
step = 16;
14011398
m11 = M11;

frmts/raw/envidataset.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ static int ITTVISToUSGSZone(int nITTVISZone)
8585

8686
ENVIDataset::ENVIDataset()
8787
: fpImage(nullptr), fp(nullptr), pszHDRFilename(nullptr),
88-
bFoundMapinfo(false), bHeaderDirty(false), bFillFile(false),
89-
interleave(BSQ)
88+
bFoundMapinfo(false), bHeaderDirty(false), bFillFile(false)
9089
{
9190
adfGeoTransform[0] = 0.0;
9291
adfGeoTransform[1] = 1.0;
@@ -217,15 +216,15 @@ CPLErr ENVIDataset::FlushCache(bool bAtClosing)
217216
const int iENVIType = GetEnviType(band->GetRasterDataType());
218217
bOK &= VSIFPrintfL(fp, "data type = %d\n", iENVIType) >= 0;
219218
const char *pszInterleaving = nullptr;
220-
switch (interleave)
219+
switch (eInterleave)
221220
{
222-
case BIP:
221+
case Interleave::BIP:
223222
pszInterleaving = "bip"; // Interleaved by pixel.
224223
break;
225-
case BIL:
224+
case Interleave::BIL:
226225
pszInterleaving = "bil"; // Interleaved by line.
227226
break;
228-
case BSQ:
227+
case Interleave::BSQ:
229228
pszInterleaving = "bsq"; // Band sequential by default.
230229
break;
231230
default:
@@ -2294,7 +2293,7 @@ ENVIDataset *ENVIDataset::Open(GDALOpenInfo *poOpenInfo, bool bFileSizeCheck)
22942293

22952294
if (STARTS_WITH_CI(osInterleave, "bil"))
22962295
{
2297-
poDS->interleave = BIL;
2296+
poDS->eInterleave = Interleave::BIL;
22982297
poDS->SetMetadataItem("INTERLEAVE", "LINE", "IMAGE_STRUCTURE");
22992298
if (nSamples > std::numeric_limits<int>::max() / (nDataSize * nBands))
23002299
{
@@ -2307,7 +2306,7 @@ ENVIDataset *ENVIDataset::Open(GDALOpenInfo *poOpenInfo, bool bFileSizeCheck)
23072306
}
23082307
else if (STARTS_WITH_CI(osInterleave, "bip"))
23092308
{
2310-
poDS->interleave = BIP;
2309+
poDS->eInterleave = Interleave::BIP;
23112310
poDS->SetMetadataItem("INTERLEAVE", "PIXEL", "IMAGE_STRUCTURE");
23122311
if (nSamples > std::numeric_limits<int>::max() / (nDataSize * nBands))
23132312
{
@@ -2320,7 +2319,7 @@ ENVIDataset *ENVIDataset::Open(GDALOpenInfo *poOpenInfo, bool bFileSizeCheck)
23202319
}
23212320
else
23222321
{
2323-
poDS->interleave = BSQ;
2322+
poDS->eInterleave = Interleave::BSQ;
23242323
poDS->SetMetadataItem("INTERLEAVE", "BAND", "IMAGE_STRUCTURE");
23252324
if (nSamples > std::numeric_limits<int>::max() / nDataSize)
23262325
{

frmts/raw/envidataset.h

+2-7
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class ENVIDataset final : public RawDataset
6565

6666
std::vector<GDAL_GCP> m_asGCPs{};
6767

68+
Interleave eInterleave = Interleave::BSQ;
69+
6870
bool ReadHeader(VSILFILE *);
6971
bool ProcessMapinfo(const char *);
7072
void ProcessRPCinfo(const char *, int, int);
@@ -88,13 +90,6 @@ class ENVIDataset final : public RawDataset
8890

8991
static char **SplitList(const char *);
9092

91-
enum Interleave
92-
{
93-
BSQ,
94-
BIL,
95-
BIP
96-
} interleave;
97-
9893
static int GetEnviType(GDALDataType eType);
9994

10095
CPL_DISALLOW_COPY_ASSIGN(ENVIDataset)

gcore/rawdataset.h

+7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ class CPL_DLL RawDataset : public GDALPamDataset
4646
RawDataset();
4747
virtual ~RawDataset() = 0;
4848

49+
enum class Interleave
50+
{
51+
BSQ,
52+
BIL,
53+
BIP,
54+
};
55+
4956
bool GetRawBinaryLayout(GDALDataset::RawBinaryLayout &) override;
5057
void ClearCachedConfigOption(void);
5158

0 commit comments

Comments
 (0)