Coverage Report

Created: 2025-07-14 06:15

/src/qpdf/libqpdf/BitWriter.cc
Line
Count
Source (jump to first uncovered line)
1
#include <qpdf/BitWriter.hh>
2
3
// See comments in bits_functions.hh
4
#define BITS_WRITE 1
5
#include <qpdf/bits_functions.hh>
6
7
BitWriter::BitWriter(Pipeline* pl) :
8
3.29k
    pl(pl)
9
3.29k
{
10
3.29k
}
11
12
void
13
BitWriter::writeBits(unsigned long long val, size_t bits)
14
68.8k
{
15
68.8k
    write_bits(this->ch, this->bit_offset, val, bits, this->pl);
16
68.8k
}
17
18
void
19
BitWriter::writeBitsSigned(long long val, size_t bits)
20
68.8k
{
21
68.8k
    unsigned long long uval = 0;
22
68.8k
    if (val < 0) {
23
2.87k
        uval = (1ULL << bits) + static_cast<unsigned long long>(val);
24
65.9k
    } else {
25
65.9k
        uval = static_cast<unsigned long long>(val);
26
65.9k
    }
27
68.8k
    writeBits(uval, bits);
28
68.8k
}
29
30
void
31
BitWriter::writeBitsInt(int val, size_t bits)
32
0
{
33
0
    writeBits(static_cast<unsigned long long>(val), bits);
34
0
}
35
36
void
37
BitWriter::flush()
38
3.27k
{
39
3.27k
    if (bit_offset < 7) {
40
2.11k
        size_t bits_to_write = bit_offset + 1;
41
2.11k
        write_bits(this->ch, this->bit_offset, 0, bits_to_write, this->pl);
42
2.11k
    }
43
3.27k
}