• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OSGeo / gdal / 15899162844

26 Jun 2025 10:14AM UTC coverage: 71.088% (+0.004%) from 71.084%
15899162844

Pull #12623

github

web-flow
Merge c704a8392 into f5cb024d4
Pull Request #12623: gdal raster overview add: add a --overview-src option

209 of 244 new or added lines in 5 files covered. (85.66%)

96 existing lines in 44 files now uncovered.

574014 of 807474 relevant lines covered (71.09%)

250815.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.05
/third_party/LercLib/BitStuffer2.h
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 BITSTUFFER2_H
25
#define BITSTUFFER2_H
26

27
#include <vector>
28
#include <cstring>
29
#include <utility>
30
#include "Defines.h"
31

32
NAMESPACE_LERC_START
33

34
/** Bit stuffer, for writing unsigned int arrays compressed lossless
35
 *
36
 */
37

38
class BitStuffer2
39
{
40
public:
41
  BitStuffer2()           {}
12,489✔
42
  ~BitStuffer2()          {}
12,489✔
43

44
  // dst buffer is already allocated. byte ptr is moved like a file pointer.
45
  bool EncodeSimple(Byte** ppByte, const std::vector<unsigned int>& dataVec, int lerc2Version) const;
46
  bool EncodeLut(Byte** ppByte, const std::vector<std::pair<unsigned int, unsigned int> >& sortedDataVec, int lerc2Version) const;
47
  bool Decode(const Byte** ppByte, size_t& nBytesRemaining, std::vector<unsigned int>& dataVec, size_t maxElementCount, int lerc2Version) const;
48

49
  static unsigned int ComputeNumBytesNeededSimple(unsigned int numElem, unsigned int maxElem);
50
  static unsigned int ComputeNumBytesNeededLut(const std::vector<std::pair<unsigned int, unsigned int> >& sortedDataVec, bool& doLut);
51

52
private:
53
  mutable std::vector<unsigned int>  m_tmpLutVec, m_tmpIndexVec, m_tmpBitStuffVec;
54

55
  static void BitStuff_Before_Lerc2v3(Byte** ppByte, const std::vector<unsigned int>& dataVec, int numBits);
56
  bool BitUnStuff_Before_Lerc2v3(const Byte** ppByte, size_t& nBytesRemaining, std::vector<unsigned int>& dataVec, unsigned int numElements, int numBits) const;
57
  void BitStuff(Byte** ppByte, const std::vector<unsigned int>& dataVec, int numBits) const;
58
  bool BitUnStuff(const Byte** ppByte, size_t& nBytesRemaining, std::vector<unsigned int>& dataVec, unsigned int numElements, int numBits) const;
59

60
  static bool EncodeUInt(Byte** ppByte, unsigned int k, int numBytes);     // numBytes = 1, 2, or 4
61
  static bool DecodeUInt(const Byte** ppByte, size_t& nBytesRemaining, unsigned int& k, int numBytes);
62
  static int NumBytesUInt(unsigned int k)  { return (k < 256) ? 1 : (k < (1 << 16)) ? 2 : 4; }
1,747,160✔
63
  static unsigned int NumTailBytesNotNeeded(unsigned int numElem, int numBits);
64
};
65

66
// -------------------------------------------------------------------------- ;
67

68
inline unsigned int BitStuffer2::ComputeNumBytesNeededSimple(unsigned int numElem, unsigned int maxElem)
64,556✔
69
{
70
  int numBits = 0;
64,556✔
71
  while ((numBits < 32) && (maxElem >> numBits))
426,583✔
72
    numBits++;
362,027✔
73
  return 1 + NumBytesUInt(numElem) + ((numElem * numBits + 7) >> 3);
64,556✔
74
}
75

76
// -------------------------------------------------------------------------- ;
77

78
inline bool BitStuffer2::EncodeUInt(Byte** ppByte, unsigned int k, int numBytes)
263,465✔
79
{
80
  Byte* ptr = *ppByte;
263,465✔
81

82
  if (numBytes == 1)
263,465✔
83
    *ptr = (Byte)k;
258,238✔
84
  else if (numBytes == 2)
5,227✔
85
  {
86
    unsigned short kShort = (unsigned short)k;
5,227✔
87
    memcpy(ptr, &kShort, sizeof(unsigned short));
5,227✔
88
  }
89
  else if (numBytes == 4)
×
90
    memcpy(ptr, &k, sizeof(unsigned int));
×
91
  else
92
    return false;
×
93

94
  *ppByte += numBytes;
263,465✔
95
  return true;
263,465✔
96
}
97

98
// -------------------------------------------------------------------------- ;
99

100
inline bool BitStuffer2::DecodeUInt(const Byte** ppByte, size_t& nBytesRemaining, unsigned int& k, int numBytes)
116,862✔
101
{
102
  if (nBytesRemaining < (size_t)numBytes)
116,862✔
103
    return false;
×
104

105
  const Byte* ptr = *ppByte;
116,862✔
106

107
  if (numBytes == 1)
116,862✔
108
    k = *ptr;
115,103✔
109
  else if (numBytes == 2)
1,759✔
110
  {
111
    unsigned short s;
112
    memcpy(&s, ptr, sizeof(unsigned short));
1,759✔
113
    k = s;
1,759✔
114
  }
UNCOV
115
  else if (numBytes == 4)
×
116
    memcpy(&k, ptr, sizeof(unsigned int));
×
117
  else
UNCOV
118
    return false;
×
119

120
  *ppByte += numBytes;
116,862✔
121
  nBytesRemaining -= numBytes;
116,862✔
122
  return true;
116,862✔
123
}
124

125
// -------------------------------------------------------------------------- ;
126

127
inline unsigned int BitStuffer2::NumTailBytesNotNeeded(unsigned int numElem, int numBits)
677,718✔
128
{
129
  int numBitsTail = ((unsigned long long)numElem * numBits) & 31;
677,718✔
130
  int numBytesTail = (numBitsTail + 7) >> 3;
677,718✔
131
  return (numBytesTail > 0) ? 4 - numBytesTail : 0;
677,718✔
132
}
133

134
// -------------------------------------------------------------------------- ;
135

136
NAMESPACE_LERC_END
137
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc