Skip to content

Commit

Permalink
RawDataset: add a enum class Interleave, and use it in CPG and ENVI d…
Browse files Browse the repository at this point in the history
…rivers, to fix issue with unity builds
  • Loading branch information
rouault committed Jan 28, 2025
1 parent ea92451 commit 1202f05
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 40 deletions.
45 changes: 21 additions & 24 deletions frmts/raw/cpgdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@

#include <vector>

enum Interleave
{
BSQ,
BIL,
BIP
};

/************************************************************************/
/* ==================================================================== */
/* CPGDataset */
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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++)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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. */
Expand Down Expand Up @@ -1395,7 +1392,7 @@ CPLErr CPG_STOKESRasterBand::IReadBlock(CPL_UNUSED int nBlockXOff,
float *M = poGDS->padfStokesMatrix;
float *pafLine = reinterpret_cast<float *>(pImage);

if (poGDS->nInterleave == BIP)
if (poGDS->eInterleave == RawDataset::Interleave::BIP)
{
step = 16;
m11 = M11;
Expand Down
17 changes: 8 additions & 9 deletions frmts/raw/envidataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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<int>::max() / (nDataSize * nBands))
{
Expand All @@ -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<int>::max() / (nDataSize * nBands))
{
Expand All @@ -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<int>::max() / nDataSize)
{
Expand Down
9 changes: 2 additions & 7 deletions frmts/raw/envidataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class ENVIDataset final : public RawDataset

std::vector<GDAL_GCP> m_asGCPs{};

Interleave eInterleave = Interleave::BSQ;

bool ReadHeader(VSILFILE *);
bool ProcessMapinfo(const char *);
void ProcessRPCinfo(const char *, int, int);
Expand All @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions gcore/rawdataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 1202f05

Please sign in to comment.