Coverage Report

Created: 2026-09-26 08:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/frmts/safe/safedataset.h
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Project:  Sentinel SAFE products
4
 * Purpose:  Sentinel Products (manifest.safe) driver
5
 * Author:   Delfim Rego, delfimrego@gmail.com
6
 *
7
 ******************************************************************************
8
 * Copyright (c) 2015, Delfim Rego <delfimrego@gmail.com>
9
 *
10
 * SPDX-License-Identifier: MIT
11
 ****************************************************************************/
12
13
#ifndef SAFEDATASET_H_INCLUDED
14
#define SAFEDATASET_H_INCLUDED
15
16
#include "cpl_minixml.h"
17
#include "cpl_string.h"
18
#include "gdal_frmts.h"
19
#include "gdal_pam.h"
20
#include "ogr_spatialref.h"
21
#include <set>
22
#include <map>
23
#include <chrono>
24
#include <ctime>
25
#include <iostream>
26
#include <thread>
27
#include <vector>
28
29
/************************************************************************/
30
/* ==================================================================== */
31
/*                               SAFEDataset                            */
32
/* ==================================================================== */
33
/************************************************************************/
34
35
class SAFEDataset final : public GDALPamDataset
36
{
37
    CPLXMLTreeCloser psManifest{nullptr};
38
39
    int nGCPCount = 0;
40
    GDAL_GCP *pasGCPList = nullptr;
41
    OGRSpatialReference m_oGCPSRS{};
42
    char **papszSubDatasets = nullptr;
43
    char **papszExtraFiles = nullptr;
44
    int m_nSubDSNum = 0;
45
46
  protected:
47
    int CloseDependentDatasets() override;
48
49
    static const CPLXMLNode *GetMetaDataObject(const CPLXMLNode *,
50
                                               const char *);
51
52
    static const CPLXMLNode *GetDataObject(const CPLXMLNode *, const char *);
53
    static const CPLXMLNode *GetDataObject(const CPLXMLNode *,
54
                                           const CPLXMLNode *, const char *);
55
56
    void AddSubDataset(const CPLString &osName, const CPLString &osDesc);
57
58
  public:
59
    SAFEDataset();
60
    ~SAFEDataset() override;
61
62
    int GetGCPCount() override;
63
    const OGRSpatialReference *GetGCPSpatialRef() const override;
64
    const GDAL_GCP *GetGCPs() override;
65
66
    char **GetMetadataDomainList() override;
67
    CSLConstList GetMetadata(const char *pszDomain = "") override;
68
69
    char **GetFileList(void) override;
70
71
    static GDALDataset *Open(GDALOpenInfo *);
72
    static int Identify(GDALOpenInfo *);
73
74
    const CPLXMLNode *GetManifest()
75
0
    {
76
0
        return psManifest.get();
77
0
    }
78
};
79
80
/************************************************************************/
81
/* ==================================================================== */
82
/*                    SAFERasterBand                                    */
83
/* ==================================================================== */
84
/************************************************************************/
85
86
class SAFERasterBand final : public GDALPamRasterBand
87
{
88
    std::unique_ptr<GDALDataset> poBandFile{};
89
90
  public:
91
    SAFERasterBand(SAFEDataset *poDSIn, GDALDataType eDataTypeIn,
92
                   const CPLString &osSwath, const CPLString &osPol,
93
                   std::unique_ptr<GDALDataset> &&poBandFileIn);
94
95
    CPLErr IReadBlock(int, int, void *) override;
96
97
    static GDALDataset *Open(GDALOpenInfo *);
98
};
99
100
/************************************************************************/
101
/* ==================================================================== */
102
/*                    SAFESLCRasterBand                                 */
103
/* ==================================================================== */
104
/************************************************************************/
105
106
class SAFESLCRasterBand final : public GDALPamRasterBand
107
{
108
  public:
109
    typedef enum BandType
110
    {
111
        COMPLEX = 0,
112
        INTENSITY
113
    } BandType;
114
115
    SAFESLCRasterBand(SAFEDataset *poDSIn, GDALDataType eDataTypeIn,
116
                      const CPLString &osSwath, const CPLString &osPol,
117
                      std::unique_ptr<GDALDataset> &&poBandFileIn,
118
                      BandType eBandType);
119
120
    CPLErr IReadBlock(int, int, void *) override;
121
    static GDALDataset *Open(GDALOpenInfo *);
122
123
  private:
124
    std::unique_ptr<GDALDataset> poBandFile{};
125
    BandType m_eBandType = COMPLEX;
126
    GDALDataType m_eInputDataType = GDT_Unknown;
127
};
128
129
/************************************************************************/
130
/* ==================================================================== */
131
/*                   SAFECalibratedRasterBand                           */
132
/* ==================================================================== */
133
/************************************************************************/
134
135
class SAFECalibratedRasterBand final : public GDALPamRasterBand
136
{
137
  public:
138
    typedef enum CalibrationType
139
    {
140
        SIGMA_NOUGHT = 0,
141
        BETA_NOUGHT,
142
        GAMMA
143
    } CalibrationType;
144
145
    SAFECalibratedRasterBand(SAFEDataset *poDSIn, GDALDataType eDataTypeIn,
146
                             const CPLString &osSwath,
147
                             const CPLString &osPolarization,
148
                             std::unique_ptr<GDALDataset> &&poBandDatasetIn,
149
                             const char *pszCalibrationFilename,
150
                             CalibrationType eCalibrationType);
151
152
    CPLErr IReadBlock(int, int, void *) override;
153
154
    bool ReadLUT();
155
156
    static GDALDataset *Open(GDALOpenInfo *);
157
158
  private:
159
    typedef std::chrono::system_clock::time_point TimePoint;
160
161
    std::unique_ptr<GDALDataset> poBandDataset{};
162
    GDALDataType m_eInputDataType = GDT_Unknown;
163
    std::vector<float> m_afTable;
164
    CPLString m_osCalibrationFilename;
165
    std::vector<int> m_anLineLUT;
166
    std::vector<int> m_anPixelLUT;
167
    TimePoint m_oStartTimePoint;
168
    TimePoint m_oStopTimePoint;
169
    int m_nNumPixels = 0;
170
    CPLStringList m_oAzimuthList;
171
    CalibrationType m_eCalibrationType = SIGMA_NOUGHT;
172
173
    static TimePoint getTimePoint(const char *pszTime);
174
    static double getTimeDiff(TimePoint oT1, TimePoint oT2);
175
    static TimePoint getazTime(TimePoint oStart, TimePoint oStop,
176
                               long nNumOfLines, int nOffset);
177
178
    int getCalibrationVectorIndex(int nLineNo);
179
    int getPixelIndex(int nPixelNo);
180
};
181
182
#endif