GDAL

gdal_maskbands.h
1/******************************************************************************
2 *
3 * Name: gdal_maskbands.h
4 * Project: GDAL Core
5 * Purpose: Declaration of mask related subclasses of GDALRasterBand
6 * Author: Frank Warmerdam, warmerdam@pobox.com
7 *
8 ******************************************************************************
9 * Copyright (c) 1998, Frank Warmerdam
10 * Copyright (c) 2007-2014, Even Rouault <even dot rouault at spatialys.com>
11 *
12 * SPDX-License-Identifier: MIT
13 ****************************************************************************/
14
15#ifndef GDALMASKBANDS_H_INCLUDED
16#define GDALMASKBANDS_H_INCLUDED
17
18#include "cpl_port.h"
19#include "gdal_rasterband.h"
20
21#include <cstddef>
22
24/* ******************************************************************** */
25/* GDALAllValidMaskBand */
26/* ******************************************************************** */
27
28 class CPL_DLL GDALAllValidMaskBand final : public GDALRasterBand
29{
30 protected:
31 CPLErr IReadBlock(int, int, void *) override;
32
33 CPLErr IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
34 int nYSize, void *pData, int nBufXSize, int nBufYSize,
35 GDALDataType eBufType, GSpacing nPixelSpace,
36 GSpacing nLineSpace,
37 GDALRasterIOExtraArg *psExtraArg) override;
38
39 bool
40 EmitErrorMessageIfWriteNotSupported(const char *pszCaller) const override;
41
42 CPL_DISALLOW_COPY_ASSIGN(GDALAllValidMaskBand)
43
44 public:
45 explicit GDALAllValidMaskBand(GDALRasterBand *);
46 ~GDALAllValidMaskBand() override;
47
48 GDALRasterBand *GetMaskBand() override;
49 int GetMaskFlags() override;
50
51 bool IsMaskBand() const override
52 {
53 return true;
54 }
55
56 GDALMaskValueRange GetMaskValueRange() const override
57 {
58 return GMVR_0_AND_255_ONLY;
59 }
60
61 CPLErr ComputeStatistics(int bApproxOK, double *pdfMin, double *pdfMax,
62 double *pdfMean, double *pdfStdDev,
63 GDALProgressFunc, void *pProgressData) override;
64};
65
66/* ******************************************************************** */
67/* GDALNoDataMaskBand */
68/* ******************************************************************** */
69
70 class CPL_DLL GDALNoDataMaskBand final : public GDALRasterBand
71{
72 friend class GDALRasterBand;
73 double m_dfNoDataValue = 0;
74 int64_t m_nNoDataValueInt64 = 0;
75 uint64_t m_nNoDataValueUInt64 = 0;
76 GDALRasterBand *m_poParent = nullptr;
77
78 CPL_DISALLOW_COPY_ASSIGN(GDALNoDataMaskBand)
79
80 protected:
81 CPLErr IReadBlock(int, int, void *) override;
82 CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
83 GDALDataType, GSpacing, GSpacing,
84 GDALRasterIOExtraArg *psExtraArg) override;
85
86 bool
87 EmitErrorMessageIfWriteNotSupported(const char *pszCaller) const override;
88
89 public:
90 explicit GDALNoDataMaskBand(GDALRasterBand *);
91 explicit GDALNoDataMaskBand(GDALRasterBand *, double dfNoDataValue);
92 ~GDALNoDataMaskBand() override;
93
94 bool IsMaskBand() const override
95 {
96 return true;
97 }
98
99 GDALMaskValueRange GetMaskValueRange() const override
100 {
101 return GMVR_0_AND_255_ONLY;
102 }
103
104 static bool IsNoDataInRange(double dfNoDataValue, GDALDataType eDataType);
105};
106
107/* ******************************************************************** */
108/* GDALNoDataValuesMaskBand */
109/* ******************************************************************** */
110
111 class CPL_DLL GDALNoDataValuesMaskBand final : public GDALRasterBand
112{
113 double *padfNodataValues;
114
115 CPL_DISALLOW_COPY_ASSIGN(GDALNoDataValuesMaskBand)
116
117 protected:
118 CPLErr IReadBlock(int, int, void *) override;
119
120 bool
121 EmitErrorMessageIfWriteNotSupported(const char *pszCaller) const override;
122
123 public:
124 explicit GDALNoDataValuesMaskBand(GDALDataset *);
125 ~GDALNoDataValuesMaskBand() override;
126
127 bool IsMaskBand() const override
128 {
129 return true;
130 }
131
132 GDALMaskValueRange GetMaskValueRange() const override
133 {
134 return GMVR_0_AND_255_ONLY;
135 }
136};
137
138/* ******************************************************************** */
139/* GDALRescaledAlphaBand */
140/* ******************************************************************** */
141
142 class GDALRescaledAlphaBand final : public GDALRasterBand
143{
144 GDALRasterBand *poParent;
145 void *pTemp;
146
147 CPL_DISALLOW_COPY_ASSIGN(GDALRescaledAlphaBand)
148
149 protected:
150 CPLErr IReadBlock(int, int, void *) override;
151 CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
152 GDALDataType, GSpacing, GSpacing,
153 GDALRasterIOExtraArg *psExtraArg) override;
154
155 bool
156 EmitErrorMessageIfWriteNotSupported(const char *pszCaller) const override;
157
158 public:
159 explicit GDALRescaledAlphaBand(GDALRasterBand *);
160 ~GDALRescaledAlphaBand() override;
161
162 bool IsMaskBand() const override
163 {
164 return true;
165 }
166};
167
169
170#endif
GDALDataset
A set of associated raster bands, usually from one file.
Definition gdal_dataset.h:76
GDALRasterBand
A single raster band (or channel).
Definition gdal_rasterband.h:105
GDALRasterBand::GetMaskFlags
virtual int GetMaskFlags()
Return the status flags of the mask band associated with the band.
Definition gdalrasterband.cpp:9434
GDALRasterBand::IsMaskBand
virtual bool IsMaskBand() const
Returns whether a band is a mask band.
Definition gdalrasterband.cpp:9572
GDALRasterBand::GetMaskBand
virtual GDALRasterBand * GetMaskBand()
Return the mask band associated with the band.
Definition gdalrasterband.cpp:9098
GDALRasterBand::ComputeStatistics
virtual CPLErr ComputeStatistics(int bApproxOK, double *pdfMin, double *pdfMax, double *pdfMean, double *pdfStdDev, GDALProgressFunc, void *pProgressData)
Compute image statistics.
Definition gdalrasterband.cpp:6910
GDALRasterBand::EmitErrorMessageIfWriteNotSupported
virtual bool EmitErrorMessageIfWriteNotSupported(const char *pszCaller) const
Emit an error message if a write operation to this band is not supported.
Definition gdalrasterband.cpp:1302
GDALRasterBand::IReadBlock
virtual CPLErr IReadBlock(int nBlockXOff, int nBlockYOff, void *pData)=0
Default internal implementation ... to be overridden by subclasses that support reading.
GDALRasterBand::IRasterIO
virtual CPLErr IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize, int nYSize, void *pData, int nBufXSize, int nBufYSize, GDALDataType eBufType, GSpacing nPixelSpace, GSpacing nLineSpace, GDALRasterIOExtraArg *psExtraArg)
Read/write a region of image data for this band.
Definition rasterio.cpp:223
GDALRasterBand::GetMaskValueRange
virtual GDALMaskValueRange GetMaskValueRange() const
Returns the range of values that a mask band can take.
Definition gdalrasterband.cpp:9623
CPLErr
CPLErr
Error category.
Definition cpl_error.h:37
cpl_port.h
Core portability definitions for CPL.
CPL_DISALLOW_COPY_ASSIGN
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition cpl_port.h:936
GSpacing
GIntBig GSpacing
Type to express pixel, line or band spacing.
Definition gdal.h:388
GDALDataType
GDALDataType
Definition gdal.h:48
GDALRWFlag
GDALRWFlag
Definition gdal.h:127
GDALRasterIOExtraArg
Structure to pass extra arguments to RasterIO() method, must be initialized with INIT_RASTERIO_EXTRA_...
Definition gdal.h:170