• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OSGeo / gdal / 15885686134

25 Jun 2025 07:44PM UTC coverage: 71.084%. Remained the same
15885686134

push

github

rouault
gdal_priv.h: fix C++11 compatibility

573814 of 807237 relevant lines covered (71.08%)

250621.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.28
/frmts/raw/gscdataset.cpp
1
/******************************************************************************
2
 *
3
 * Project:  GSC Geogrid format driver.
4
 * Purpose:  Implements support for reading and writing GSC Geogrid format.
5
 * Author:   Frank Warmerdam <warmerdam@pobox.com>
6
 *
7
 ******************************************************************************
8
 * Copyright (c) 2002, Frank Warmerdam <warmerdam@pobox.com>
9
 * Copyright (c) 2009-2011, Even Rouault <even dot rouault at spatialys.com>
10
 *
11
 * SPDX-License-Identifier: MIT
12
 ****************************************************************************/
13

14
#include "cpl_string.h"
15
#include "gdal_frmts.h"
16
#include "rawdataset.h"
17

18
#include <algorithm>
19

20
/************************************************************************/
21
/* ==================================================================== */
22
/*                              GSCDataset                              */
23
/* ==================================================================== */
24
/************************************************************************/
25

26
class GSCDataset final : public RawDataset
27
{
28
    VSILFILE *fpImage = nullptr;  // image data file.
29

30
    GDALGeoTransform m_gt{};
31

32
    CPL_DISALLOW_COPY_ASSIGN(GSCDataset)
33

34
    CPLErr Close() override;
35

36
  public:
37
    GSCDataset() = default;
2✔
38
    ~GSCDataset();
39

40
    CPLErr GetGeoTransform(GDALGeoTransform &gt) const override;
41

42
    static GDALDataset *Open(GDALOpenInfo *);
43
};
44

45
/************************************************************************/
46
/*                            ~GSCDataset()                             */
47
/************************************************************************/
48

49
GSCDataset::~GSCDataset()
4✔
50

51
{
52
    GSCDataset::Close();
2✔
53
}
4✔
54

55
/************************************************************************/
56
/*                              Close()                                 */
57
/************************************************************************/
58

59
CPLErr GSCDataset::Close()
4✔
60
{
61
    CPLErr eErr = CE_None;
4✔
62
    if (nOpenFlags != OPEN_FLAGS_CLOSED)
4✔
63
    {
64
        if (GSCDataset::FlushCache(true) != CE_None)
2✔
65
            eErr = CE_Failure;
×
66

67
        if (fpImage)
2✔
68
        {
69
            if (VSIFCloseL(fpImage) != 0)
2✔
70
            {
71
                CPLError(CE_Failure, CPLE_FileIO, "I/O error");
×
72
                eErr = CE_Failure;
×
73
            }
74
        }
75

76
        if (GDALPamDataset::Close() != CE_None)
2✔
77
            eErr = CE_Failure;
×
78
    }
79
    return eErr;
4✔
80
}
81

82
/************************************************************************/
83
/*                          GetGeoTransform()                           */
84
/************************************************************************/
85

86
CPLErr GSCDataset::GetGeoTransform(GDALGeoTransform &gt) const
×
87

88
{
89
    gt = m_gt;
×
90

91
    return CE_None;
×
92
}
93

94
/************************************************************************/
95
/*                                Open()                                */
96
/************************************************************************/
97

98
GDALDataset *GSCDataset::Open(GDALOpenInfo *poOpenInfo)
33,277✔
99

100
{
101

102
    /* -------------------------------------------------------------------- */
103
    /*      Does this plausible look like a GSC Geogrid file?               */
104
    /* -------------------------------------------------------------------- */
105
    if (poOpenInfo->nHeaderBytes < 20)
33,277✔
106
        return nullptr;
29,955✔
107

108
    if (poOpenInfo->pabyHeader[12] != 0x02 ||
3,322✔
109
        poOpenInfo->pabyHeader[13] != 0x00 ||
19✔
110
        poOpenInfo->pabyHeader[14] != 0x00 ||
2✔
111
        poOpenInfo->pabyHeader[15] != 0x00)
2✔
112
        return nullptr;
3,320✔
113

114
    int nRecordLen =
2✔
115
        CPL_LSBWORD32(reinterpret_cast<GInt32 *>(poOpenInfo->pabyHeader)[0]);
2✔
116
    const int nPixels =
2✔
117
        CPL_LSBWORD32(reinterpret_cast<GInt32 *>(poOpenInfo->pabyHeader)[1]);
2✔
118
    const int nLines =
2✔
119
        CPL_LSBWORD32(reinterpret_cast<GInt32 *>(poOpenInfo->pabyHeader)[2]);
2✔
120

121
    if (nPixels < 1 || nLines < 1 || nPixels > 100000 || nLines > 100000)
2✔
122
        return nullptr;
×
123

124
    if (nRecordLen != nPixels * 4)
2✔
125
        return nullptr;
×
126

127
    /* -------------------------------------------------------------------- */
128
    /*      Confirm the requested access is supported.                      */
129
    /* -------------------------------------------------------------------- */
130
    if (poOpenInfo->eAccess == GA_Update)
2✔
131
    {
132
        ReportUpdateNotSupportedByDriver("GSC");
×
133
        return nullptr;
×
134
    }
135

136
    nRecordLen += 8;  // For record length markers.
2✔
137

138
    /* -------------------------------------------------------------------- */
139
    /*      Create a corresponding GDALDataset.                             */
140
    /* -------------------------------------------------------------------- */
141
    auto poDS = std::make_unique<GSCDataset>();
4✔
142

143
    poDS->nRasterXSize = nPixels;
2✔
144
    poDS->nRasterYSize = nLines;
2✔
145
    std::swap(poDS->fpImage, poOpenInfo->fpL);
2✔
146

147
    /* -------------------------------------------------------------------- */
148
    /*      Read the header information in the second record.               */
149
    /* -------------------------------------------------------------------- */
150
    float afHeaderInfo[8] = {0.0};
2✔
151

152
    if (VSIFSeekL(poDS->fpImage, nRecordLen + 12, SEEK_SET) != 0 ||
4✔
153
        VSIFReadL(afHeaderInfo, sizeof(float), 8, poDS->fpImage) != 8)
2✔
154
    {
155
        CPLError(
×
156
            CE_Failure, CPLE_FileIO,
157
            "Failure reading second record of GSC file with %d record length.",
158
            nRecordLen);
159
        return nullptr;
×
160
    }
161

162
    for (int i = 0; i < 8; i++)
18✔
163
    {
164
        CPL_LSBPTR32(afHeaderInfo + i);
16✔
165
    }
166

167
    poDS->m_gt[0] = afHeaderInfo[2];
2✔
168
    poDS->m_gt[1] = afHeaderInfo[0];
2✔
169
    poDS->m_gt[2] = 0.0;
2✔
170
    poDS->m_gt[3] = afHeaderInfo[5];
2✔
171
    poDS->m_gt[4] = 0.0;
2✔
172
    poDS->m_gt[5] = -afHeaderInfo[1];
2✔
173

174
    /* -------------------------------------------------------------------- */
175
    /*      Create band information objects.                                */
176
    /* -------------------------------------------------------------------- */
177
    auto poBand = RawRasterBand::Create(
178
        poDS.get(), 1, poDS->fpImage, nRecordLen * 2 + 4, sizeof(float),
4✔
179
        nRecordLen, GDT_Float32, RawRasterBand::ByteOrder::ORDER_LITTLE_ENDIAN,
180
        RawRasterBand::OwnFP::NO);
4✔
181
    if (!poBand)
2✔
182
        return nullptr;
×
183
    poBand->SetNoDataValue(-1.0000000150474662199e+30);
2✔
184
    poDS->SetBand(1, std::move(poBand));
2✔
185

186
    /* -------------------------------------------------------------------- */
187
    /*      Initialize any PAM information.                                 */
188
    /* -------------------------------------------------------------------- */
189
    poDS->SetDescription(poOpenInfo->pszFilename);
2✔
190
    poDS->TryLoadXML();
2✔
191

192
    /* -------------------------------------------------------------------- */
193
    /*      Check for overviews.                                            */
194
    /* -------------------------------------------------------------------- */
195
    poDS->oOvManager.Initialize(poDS.get(), poOpenInfo->pszFilename);
2✔
196

197
    return poDS.release();
2✔
198
}
199

200
/************************************************************************/
201
/*                          GDALRegister_GSC()                          */
202
/************************************************************************/
203

204
void GDALRegister_GSC()
1,911✔
205

206
{
207
    if (GDALGetDriverByName("GSC") != nullptr)
1,911✔
208
        return;
282✔
209

210
    GDALDriver *poDriver = new GDALDriver();
1,629✔
211

212
    poDriver->SetDescription("GSC");
1,629✔
213
    poDriver->SetMetadataItem(GDAL_DCAP_RASTER, "YES");
1,629✔
214
    poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "GSC Geogrid");
1,629✔
215
    poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/raster/gsc.html");
1,629✔
216
    poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES");
1,629✔
217

218
    poDriver->pfnOpen = GSCDataset::Open;
1,629✔
219

220
    GetGDALDriverManager()->RegisterDriver(poDriver);
1,629✔
221
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc