Coverage Report

Created: 2025-07-12 06:30

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