/src/gdal/third_party/LercLib/BitMask.h
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /*  | 
2  |  | Copyright 2015 Esri  | 
3  |  |  | 
4  |  | Licensed under the Apache License, Version 2.0 (the "License");  | 
5  |  | you may not use this file except in compliance with the License.  | 
6  |  | You may obtain a copy of the License at  | 
7  |  |  | 
8  |  | http://www.apache.org/licenses/LICENSE-2.0  | 
9  |  |  | 
10  |  | Unless required by applicable law or agreed to in writing, software  | 
11  |  | distributed under the License is distributed on an "AS IS" BASIS,  | 
12  |  | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
13  |  | See the License for the specific language governing permissions and  | 
14  |  | limitations under the License.  | 
15  |  |  | 
16  |  | A local copy of the license and additional notices are located with the  | 
17  |  | source distribution at:  | 
18  |  |  | 
19  |  | http://github.com/Esri/lerc/  | 
20  |  |  | 
21  |  | Contributors:  Thomas Maurer  | 
22  |  | */  | 
23  |  |  | 
24  |  | #ifndef BITMASK_H  | 
25  |  | #define BITMASK_H  | 
26  |  |  | 
27  |  | #include "Defines.h"  | 
28  |  |  | 
29  |  | NAMESPACE_LERC_START  | 
30  |  |  | 
31  |  |   typedef unsigned char Byte;  | 
32  |  |  | 
33  |  |   /** BitMask - Convenient and fast access to binary mask bits  | 
34  |  |   *  | 
35  |  |   */  | 
36  |  |  | 
37  |  |   class BitMask  | 
38  |  |   { | 
39  |  |   public:  | 
40  | 0  |     BitMask() = default;  | 
41  | 0  |     BitMask(int nCols, int nRows) { SetSize(nCols, nRows); } | 
42  |  |     BitMask(const BitMask& src);  | 
43  | 0  |     ~BitMask()                        { Clear(); } | 
44  |  |  | 
45  |  |     BitMask& operator= (const BitMask& src);  | 
46  |  |  | 
47  |  |     // 1: valid, 0: not valid  | 
48  | 0  |     Byte IsValid(int k) const                 { return (m_pBits[k >> 3] & Bit(k)) > 0; } | 
49  | 0  |     Byte IsValid(int row, int col) const      { return IsValid(row * m_nCols + col); } | 
50  |  |  | 
51  | 0  |     void SetValid(int k) const                { m_pBits[k >> 3] |= Bit(k); } | 
52  | 0  |     void SetValid(int row, int col) const     { SetValid(row * m_nCols + col); } | 
53  |  |  | 
54  | 0  |     void SetInvalid(int k) const              { m_pBits[k >> 3] &= ~Bit(k); } | 
55  | 0  |     void SetInvalid(int row, int col) const   { SetInvalid(row * m_nCols + col); } | 
56  |  |  | 
57  |  |     void SetAllValid() const;  | 
58  |  |     void SetAllInvalid() const;  | 
59  |  |  | 
60  |  |     bool SetSize(int nCols, int nRows);  | 
61  |  |  | 
62  | 0  |     int GetWidth() const                      { return m_nCols; } | 
63  | 0  |     int GetHeight() const                     { return m_nRows; } | 
64  | 0  |     int Size() const                          { return (m_nCols * m_nRows + 7) >> 3; } | 
65  | 0  |     const Byte* Bits() const                  { return m_pBits; } | 
66  | 0  |     Byte* Bits()                              { return m_pBits; } | 
67  | 0  |     static Byte Bit(int k)                    { return (1 << 7) >> (k & 7); } | 
68  |  |  | 
69  |  |     int CountValidBits() const;  | 
70  |  |     void Clear();  | 
71  |  |  | 
72  |  |   private:  | 
73  |  |     Byte*  m_pBits = nullptr;  | 
74  |  |     int    m_nCols = 0, m_nRows = 0;  | 
75  |  |   };  | 
76  |  | NAMESPACE_LERC_END  | 
77  |  |  | 
78  |  | #endif  |