Coverage Report

Created: 2025-06-10 07:15

/src/ghostpdl/base/shc.c
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (C) 2001-2023 Artifex Software, Inc.
2
   All Rights Reserved.
3
4
   This software is provided AS-IS with no warranty, either express or
5
   implied.
6
7
   This software is distributed under license and may not be copied,
8
   modified or distributed except as expressly authorized under the terms
9
   of the license contained in the file LICENSE in this distribution.
10
11
   Refer to licensing information at http://www.artifex.com or contact
12
   Artifex Software, Inc.,  39 Mesa Street, Suite 108A, San Francisco,
13
   CA 94129, USA, for further information.
14
*/
15
16
17
/* Support code for shc.h */
18
#include "std.h"
19
#include "scommon.h"
20
#include "shc.h"
21
22
/* ------ Encoding ------ */
23
24
/* Empty the 1-word buffer onto the output stream. */
25
/* q has already been incremented. */
26
void
27
hc_put_code_proc(bool reverse_bits, byte * q, uint cw)
28
470k
{
29
1.88M
#define cb(n) ((byte)(cw >> (n * 8)))
30
470k
    if (reverse_bits) {
31
0
#if hc_bits_size > 16
32
0
        q[-3] = byte_reverse_bits[cb(3)];
33
0
        q[-2] = byte_reverse_bits[cb(2)];
34
0
#endif
35
0
        q[-1] = byte_reverse_bits[cb(1)];
36
0
        q[0] = byte_reverse_bits[cb(0)];
37
470k
    } else {
38
470k
#if hc_bits_size > 16
39
470k
        q[-3] = cb(3);
40
470k
        q[-2] = cb(2);
41
470k
#endif
42
470k
        q[-1] = cb(1);
43
470k
        q[0] = cb(0);
44
470k
    }
45
470k
#undef cb
46
470k
}
47
48
/* Put out any final bytes. */
49
/* Note that this does a store_state, but not a load_state. */
50
byte *
51
hc_put_last_bits_proc(stream_hc_state * ss, byte * q, uint bits, int bits_left)
52
70.2k
{
53
246k
    while (bits_left < hc_bits_size) {
54
175k
        byte c = (byte) (bits >> (hc_bits_size - 8));
55
56
175k
        if (ss->FirstBitLowOrder)
57
0
            c = byte_reverse_bits[c];
58
175k
        *++q = c;
59
175k
        bits <<= 8;
60
175k
        bits_left += 8;
61
175k
    }
62
70.2k
    ss->bits = bits;
63
70.2k
    ss->bits_left = bits_left;
64
70.2k
    return q;
65
70.2k
}