Coverage Report

Created: 2025-06-09 07:43

/src/gdal/frmts/pcraster/pcrasterutil.h
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Project:  PCRaster Integration
4
 * Purpose:  PCRaster driver support declarations.
5
 * Author:   Kor de Jong, Oliver Schmitz
6
 *
7
 ******************************************************************************
8
 * Copyright (c) PCRaster owners
9
 *
10
 * SPDX-License-Identifier: MIT
11
 ****************************************************************************/
12
13
#ifndef INCLUDED_PCRASTERUTIL
14
#define INCLUDED_PCRASTERUTIL
15
16
#include "csf.h"
17
#include "gdal_priv.h"
18
#include "pcrtypes.h"
19
20
GDALDataType cellRepresentation2GDALType(CSF_CR cellRepresentation);
21
22
CSF_VS string2ValueScale(const std::string &string);
23
24
std::string valueScale2String(CSF_VS valueScale);
25
26
std::string cellRepresentation2String(CSF_CR cellRepresentation);
27
28
CSF_VS GDALType2ValueScale(GDALDataType type);
29
30
/*
31
CSF_CR             string2PCRasterCellRepresentation(
32
                                        const std::string& string);
33
                                        */
34
35
CSF_CR GDALType2CellRepresentation(GDALDataType type, bool exact);
36
37
void *createBuffer(size_t size, CSF_CR type);
38
39
void deleteBuffer(void *buffer, CSF_CR type);
40
41
bool isContinuous(CSF_VS valueScale);
42
43
double missingValue(CSF_CR type);
44
45
void alterFromStdMV(void *buffer, size_t size, CSF_CR cellRepresentation,
46
                    double missingValue);
47
48
void alterToStdMV(void *buffer, size_t size, CSF_CR cellRepresentation,
49
                  double missingValue);
50
51
MAP *mapOpen(std::string const &filename, MOPEN_PERM mode);
52
53
CSF_VS fitValueScale(CSF_VS valueScale, CSF_CR cellRepresentation);
54
55
void castValuesToBooleanRange(void *buffer, size_t size,
56
                              CSF_CR cellRepresentation);
57
58
void castValuesToDirectionRange(void *buffer, size_t size);
59
60
void castValuesToLddRange(void *buffer, size_t size);
61
62
template <typename T> struct CastToBooleanRange
63
{
64
    void operator()(T &value) const
65
0
    {
66
0
        if (!pcr::isMV(value))
67
0
        {
68
0
            if (value != 0)
69
0
            {
70
0
                value = T(value > T(0));
71
0
            }
72
0
            else
73
0
            {
74
0
                pcr::setMV(value);
75
0
            }
76
0
        }
77
0
    }
Unexecuted instantiation: CastToBooleanRange<int>::operator()(int&) const
Unexecuted instantiation: CastToBooleanRange<float>::operator()(float&) const
Unexecuted instantiation: CastToBooleanRange<double>::operator()(double&) const
Unexecuted instantiation: CastToBooleanRange<signed char>::operator()(signed char&) const
Unexecuted instantiation: CastToBooleanRange<short>::operator()(short&) const
78
};
79
80
template <> struct CastToBooleanRange<UINT1>
81
{
82
    void operator()(UINT1 &value) const
83
0
    {
84
0
        if (!pcr::isMV(value))
85
0
        {
86
0
            value = UINT1(value > UINT1(0));
87
0
        }
88
0
    }
89
};
90
91
template <> struct CastToBooleanRange<UINT2>
92
{
93
    void operator()(UINT2 &value) const
94
0
    {
95
0
        if (!pcr::isMV(value))
96
0
        {
97
0
            value = UINT2(value > UINT2(0));
98
0
        }
99
0
    }
100
};
101
102
template <> struct CastToBooleanRange<UINT4>
103
{
104
    void operator()(UINT4 &value) const
105
0
    {
106
0
        if (!pcr::isMV(value))
107
0
        {
108
0
            value = UINT4(value > UINT4(0));
109
0
        }
110
0
    }
111
};
112
113
struct CastToDirection
114
{
115
    void operator()(REAL4 &value) const
116
0
    {
117
0
        REAL4 factor = static_cast<REAL4>(M_PI / 180.0);
118
0
        if (!pcr::isMV(value))
119
0
        {
120
0
            value = REAL4(value * factor);
121
0
        }
122
0
    }
123
};
124
125
struct CastToLdd
126
{
127
    void operator()(UINT1 &value) const
128
0
    {
129
0
        if (!pcr::isMV(value))
130
0
        {
131
0
            if ((value < 1) || (value > 9))
132
0
            {
133
0
                CPLError(CE_Warning, CPLE_IllegalArg,
134
0
                         "PCRaster driver: incorrect LDD value used, assigned "
135
0
                         "MV instead");
136
0
                pcr::setMV(value);
137
0
            }
138
0
            else
139
0
            {
140
0
                value = UINT1(value);
141
0
            }
142
0
        }
143
0
    }
144
};
145
146
#endif  // INCLUDED_PCRASTERUTIL