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: 2026-07-24 18:27:47 Functions: 10 10 100.0 %

          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             : #include <cstddef>
      30             : 
      31             : NAMESPACE_LERC_START
      32             : 
      33             :   typedef unsigned char Byte;
      34             : 
      35             :   /** BitMask - Convenient and fast access to binary mask bits
      36             :   *
      37             :   */
      38             : 
      39             :   class BitMask
      40             :   {
      41             :   public:
      42        7814 :     BitMask() = default;
      43             :     BitMask(int nCols, int nRows) { SetSize(nCols, nRows); }
      44             :     BitMask(const BitMask& src);
      45       15632 :     ~BitMask()                        { Clear(); }
      46             : 
      47             :     BitMask& operator= (const BitMask& src);
      48             : 
      49             :     // 1: valid, 0: not valid
      50    40325800 :     Byte IsValid(int k) const                 { return (m_pBits[k >> 3] & Bit(k)) > 0; }
      51             :     Byte IsValid(int row, int col) const      { return IsValid(row * m_nCols + col); }
      52             : 
      53             :     void SetValid(int k) const                { m_pBits[k >> 3] |= Bit(k); }
      54             :     void SetValid(int row, int col) const     { SetValid(row * m_nCols + col); }
      55             : 
      56        1781 :     void SetInvalid(int k) const              { m_pBits[k >> 3] &= ~Bit(k); }
      57             :     void SetInvalid(int row, int col) const   { SetInvalid(row * m_nCols + col); }
      58             : 
      59             :     void SetAllValid() const;
      60             :     void SetAllInvalid() const;
      61             : 
      62             :     bool SetSize(int nCols, int nRows);
      63             : 
      64          72 :     int GetWidth() const                      { return m_nCols; }
      65          72 :     int GetHeight() const                     { return m_nRows; }
      66        8216 :     size_t Size() const                       { return ((size_t)m_nCols * m_nRows + 7) >> 3; }
      67          27 :     const Byte* Bits() const                  { return m_pBits; }
      68         147 :     Byte* Bits()                              { return m_pBits; }
      69    40327800 :     static Byte Bit(int k)                    { return (1 << 7) >> (k & 7); }
      70             : 
      71             :     int CountValidBits() const;
      72             :     void Clear();
      73             : 
      74             :   private:
      75             :     Byte*  m_pBits = nullptr;
      76             :     int    m_nCols = 0, m_nRows = 0;
      77             :   };
      78             : NAMESPACE_LERC_END
      79             : 
      80             : #endif

Generated by: LCOV version 1.14