Coverage Report

Created: 2025-08-29 06:57

/src/qpdf/libqpdf/BitWriter.cc
Line
Count
Source
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
24.0k
    pl(pl)
9
24.0k
{
10
24.0k
}
11
12
void
13
BitWriter::writeBits(unsigned long long val, size_t bits)
14
1.40M
{
15
1.40M
    write_bits(this->ch, this->bit_offset, val, bits, this->pl);
16
1.40M
}
17
18
void
19
BitWriter::writeBitsSigned(long long val, size_t bits)
20
975k
{
21
975k
    unsigned long long uval = 0;
22
975k
    if (val < 0) {
23
894k
        uval = (1ULL << bits) + static_cast<unsigned long long>(val);
24
894k
    } else {
25
81.6k
        uval = static_cast<unsigned long long>(val);
26
81.6k
    }
27
975k
    writeBits(uval, bits);
28
975k
}
29
30
void
31
BitWriter::writeBitsInt(int val, size_t bits)
32
124k
{
33
124k
    writeBits(static_cast<unsigned long long>(val), bits);
34
124k
}
35
36
void
37
BitWriter::flush()
38
89.6k
{
39
89.6k
    if (bit_offset < 7) {
40
29.3k
        size_t bits_to_write = bit_offset + 1;
41
29.3k
        write_bits(this->ch, this->bit_offset, 0, bits_to_write, this->pl);
42
29.3k
    }
43
89.6k
}