Coverage Report

Created: 2025-10-10 06:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
9.60k
    pl(pl)
9
9.60k
{
10
9.60k
}
11
12
void
13
BitWriter::writeBits(unsigned long long val, size_t bits)
14
640k
{
15
640k
    write_bits(this->ch, this->bit_offset, val, bits, this->pl);
16
640k
}
17
18
void
19
BitWriter::writeBitsSigned(long long val, size_t bits)
20
283k
{
21
283k
    unsigned long long uval = 0;
22
283k
    if (val < 0) {
23
1.13k
        uval = (1ULL << bits) + static_cast<unsigned long long>(val);
24
282k
    } else {
25
282k
        uval = static_cast<unsigned long long>(val);
26
282k
    }
27
283k
    writeBits(uval, bits);
28
283k
}
29
30
void
31
BitWriter::writeBitsInt(int val, size_t bits)
32
135k
{
33
135k
    writeBits(static_cast<unsigned long long>(val), bits);
34
135k
}
35
36
void
37
BitWriter::flush()
38
81.1k
{
39
81.1k
    if (bit_offset < 7) {
40
14.7k
        size_t bits_to_write = bit_offset + 1;
41
14.7k
        write_bits(this->ch, this->bit_offset, 0, bits_to_write, this->pl);
42
14.7k
    }
43
81.1k
}