Coverage Report

Created: 2025-07-11 07:02

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