Coverage Report

Created: 2025-06-24 07:01

/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
84.3M
{
29
337M
#define cb(n) ((byte)(cw >> (n * 8)))
30
84.3M
    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
84.3M
    } else {
38
84.3M
#if hc_bits_size > 16
39
84.3M
        q[-3] = cb(3);
40
84.3M
        q[-2] = cb(2);
41
84.3M
#endif
42
84.3M
        q[-1] = cb(1);
43
84.3M
        q[0] = cb(0);
44
84.3M
    }
45
84.3M
#undef cb
46
84.3M
}
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
2.14M
{
53
7.46M
    while (bits_left < hc_bits_size) {
54
5.31M
        byte c = (byte) (bits >> (hc_bits_size - 8));
55
56
5.31M
        if (ss->FirstBitLowOrder)
57
0
            c = byte_reverse_bits[c];
58
5.31M
        *++q = c;
59
5.31M
        bits <<= 8;
60
5.31M
        bits_left += 8;
61
5.31M
    }
62
2.14M
    ss->bits = bits;
63
2.14M
    ss->bits_left = bits_left;
64
2.14M
    return q;
65
2.14M
}