1 /******************************************************************************
2  *
3  * Project:  GDAL Core
4  * Purpose:  Implementation of GDALAllValidMaskBand, a class implementing all
5  *           a default 'all valid' band mask.
6  * Author:   Frank Warmerdam, warmerdam@pobox.com
7  *
8  ******************************************************************************
9  * Copyright (c) 2007, Frank Warmerdam
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included
19  * in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  ****************************************************************************/
29 
30 #include "cpl_port.h"
31 #include "gdal_priv.h"
32 
33 #include <cstring>
34 
35 #include "gdal.h"
36 #include "cpl_error.h"
37 
38 CPL_CVSID("$Id: gdalallvalidmaskband.cpp bcf6af1006f48771999512f1bfed906e3c509edf 2018-07-09 00:07:02 +0200 Even Rouault $")
39 
40 //! @cond Doxygen_Suppress
41 /************************************************************************/
42 /*                        GDALAllValidMaskBand()                        */
43 /************************************************************************/
44 
GDALAllValidMaskBand(GDALRasterBand * poParent)45 GDALAllValidMaskBand::GDALAllValidMaskBand( GDALRasterBand *poParent ) :
46     GDALRasterBand(FALSE)
47 {
48     poDS = nullptr;
49     nBand = 0;
50 
51     nRasterXSize = poParent->GetXSize();
52     nRasterYSize = poParent->GetYSize();
53 
54     eDataType = GDT_Byte;
55     poParent->GetBlockSize( &nBlockXSize, &nBlockYSize );
56 }
57 
58 /************************************************************************/
59 /*                       ~GDALAllValidMaskBand()                        */
60 /************************************************************************/
61 
62 GDALAllValidMaskBand::~GDALAllValidMaskBand() = default;
63 
64 /************************************************************************/
65 /*                             IReadBlock()                             */
66 /************************************************************************/
67 
IReadBlock(int,int,void * pImage)68 CPLErr GDALAllValidMaskBand::IReadBlock( int /* nXBlockOff */,
69                                          int /* nYBlockOff */,
70                                          void *pImage )
71 {
72     memset( pImage, 255, nBlockXSize * nBlockYSize );
73 
74     return CE_None;
75 }
76 
77 /************************************************************************/
78 /*                            GetMaskBand()                             */
79 /************************************************************************/
80 
GetMaskBand()81 GDALRasterBand *GDALAllValidMaskBand::GetMaskBand()
82 
83 {
84     return this;
85 }
86 
87 /************************************************************************/
88 /*                            GetMaskFlags()                            */
89 /************************************************************************/
90 
GetMaskFlags()91 int GDALAllValidMaskBand::GetMaskFlags()
92 
93 {
94     return GMF_ALL_VALID;
95 }
96 
97 /************************************************************************/
98 /*                           ComputeStatistics()                        */
99 /************************************************************************/
100 
ComputeStatistics(int,double * pdfMin,double * pdfMax,double * pdfMean,double * pdfStdDev,GDALProgressFunc,void *)101 CPLErr GDALAllValidMaskBand::ComputeStatistics( int /* bApproxOK */,
102                             double *pdfMin, double *pdfMax,
103                             double *pdfMean, double *pdfStdDev,
104                             GDALProgressFunc, void * /*pProgressData*/ )
105 {
106     if( pdfMin )
107         *pdfMin = 255.0;
108     if( pdfMax )
109         *pdfMax = 255.0;
110     if( pdfMean )
111         *pdfMean = 255.0;
112     if( pdfStdDev )
113         *pdfStdDev = 0.0;
114     return CE_None;
115 }
116 
117 //! @endcond
118