Coverage Report

Created: 2025-08-28 06:38

/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
12.0k
    pl(pl)
9
12.0k
{
10
12.0k
}
11
12
void
13
BitWriter::writeBits(unsigned long long val, size_t bits)
14
3.95M
{
15
3.95M
    write_bits(this->ch, this->bit_offset, val, bits, this->pl);
16
3.95M
}
17
18
void
19
BitWriter::writeBitsSigned(long long val, size_t bits)
20
3.45M
{
21
3.45M
    unsigned long long uval = 0;
22
3.45M
    if (val < 0) {
23
1.21M
        uval = (1ULL << bits) + static_cast<unsigned long long>(val);
24
2.24M
    } else {
25
2.24M
        uval = static_cast<unsigned long long>(val);
26
2.24M
    }
27
3.45M
    writeBits(uval, bits);
28
3.45M
}
29
30
void
31
BitWriter::writeBitsInt(int val, size_t bits)
32
133k
{
33
133k
    writeBits(static_cast<unsigned long long>(val), bits);
34
133k
}
35
36
void
37
BitWriter::flush()
38
82.0k
{
39
82.0k
    if (bit_offset < 7) {
40
15.0k
        size_t bits_to_write = bit_offset + 1;
41
15.0k
        write_bits(this->ch, this->bit_offset, 0, bits_to_write, this->pl);
42
15.0k
    }
43
82.0k
}