LCOV - code coverage report
Current view: top level - third_party/LercLib - BitMask.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 10 10 100.0 %
Date: 2024-11-21 22:18:42 Functions: 10 11 90.9 %

          Line data    Source code
       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        7323 :     BitMask() = default;
      41             :     BitMask(int nCols, int nRows) { SetSize(nCols, nRows); }
      42             :     BitMask(const BitMask& src);
      43       14646 :     virtual ~BitMask()                        { Clear(); }
      44             : 
      45             :     BitMask& operator= (const BitMask& src);
      46             : 
      47             :     // 1: valid, 0: not valid
      48    39900700 :     Byte IsValid(int k) const                 { return (m_pBits[k >> 3] & Bit(k)) > 0; }
      49             :     Byte IsValid(int row, int col) const      { return IsValid(row * m_nCols + col); }
      50             : 
      51             :     void SetValid(int k) const                { m_pBits[k >> 3] |= Bit(k); }
      52             :     void SetValid(int row, int col) const     { SetValid(row * m_nCols + col); }
      53             : 
      54        1781 :     void SetInvalid(int k) const              { m_pBits[k >> 3] &= ~Bit(k); }
      55             :     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          69 :     int GetWidth() const                      { return m_nCols; }
      63          69 :     int GetHeight() const                     { return m_nRows; }
      64        7711 :     int Size() const                          { return (m_nCols * m_nRows + 7) >> 3; }
      65          27 :     const Byte* Bits() const                  { return m_pBits; }
      66         138 :     Byte* Bits()                              { return m_pBits; }
      67    39902100 :     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

Generated by: LCOV version 1.14