Coverage Report

Created: 2026-09-26 08:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/third_party/LercLib/BitMask.cpp
Line
Count
Source
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
#include "Defines.h"
25
#include "BitMask.h"
26
#include <cstring>
27
28
USING_NAMESPACE_LERC
29
30
// -------------------------------------------------------------------------- ;
31
32
BitMask::BitMask(const BitMask& src)
33
0
{
34
0
  SetSize(src.m_nCols, src.m_nRows);
35
0
  if (m_pBits && src.m_pBits)
36
0
    memcpy(m_pBits, src.m_pBits, Size());
37
0
}
38
39
// -------------------------------------------------------------------------- ;
40
41
BitMask& BitMask::operator= (const BitMask& src)
42
0
{
43
0
  if (this == &src) return *this;
44
45
0
  SetSize(src.m_nCols, src.m_nRows);
46
0
  if (m_pBits && src.m_pBits)
47
0
    memcpy(m_pBits, src.m_pBits, Size());
48
49
0
  return *this;
50
0
}
51
52
// -------------------------------------------------------------------------- ;
53
54
void BitMask::SetAllValid() const
55
2.53k
{
56
2.53k
  memset(m_pBits, 255, Size());
57
2.53k
}
58
59
void BitMask::SetAllInvalid() const
60
640
{
61
640
  memset(m_pBits, 0, Size());
62
640
}
63
64
// -------------------------------------------------------------------------- ;
65
66
bool BitMask::SetSize(int nCols, int nRows)
67
5.67k
{
68
5.67k
  if (nCols != m_nCols || nRows != m_nRows)
69
5.67k
  {
70
5.67k
    Clear();
71
5.67k
    m_pBits = new Byte[(nCols * nRows + 7) >> 3];
72
5.67k
    m_nCols = nCols;
73
5.67k
    m_nRows = nRows;
74
5.67k
  }
75
5.67k
  return m_pBits != nullptr;
76
5.67k
}
77
78
// -------------------------------------------------------------------------- ;
79
80
int BitMask::CountValidBits() const
81
98
{
82
98
  const Byte numBitsHB[16] = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
83
98
  const Byte* ptr = m_pBits;
84
98
  int sum = 0;
85
98
  size_t i = Size();
86
8.16M
  while (i)
87
8.16M
  {
88
8.16M
    --i;
89
8.16M
    sum += numBitsHB[*ptr & 15] + numBitsHB[*ptr >> 4];
90
8.16M
    ptr++;
91
8.16M
  }
92
93
  // subtract undefined bits potentially contained in the last byte
94
116
  for (int k = m_nCols * m_nRows; static_cast<size_t>(k) < Size() * 8; k++)
95
18
    if (IsValid(k))
96
0
      sum--;
97
98
98
  return sum;
99
98
}
100
101
// -------------------------------------------------------------------------- ;
102
103
void BitMask::Clear()
104
15.9k
{
105
15.9k
  delete[] m_pBits;
106
15.9k
  m_pBits = nullptr;
107
15.9k
  m_nCols = 0;
108
15.9k
  m_nRows = 0;
109
15.9k
}
110
111
// -------------------------------------------------------------------------- ;
112