Coverage Report

Created: 2022-10-31 07:00

/src/ghostpdl/base/shc.c
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (C) 2001-2021 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.,  1305 Grant Avenue - Suite 200, Novato,
13
   CA 94945, U.S.A., +1(415)492-9861, 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
10.3M
{
29
41.3M
#define cb(n) ((byte)(cw >> (n * 8)))
30
10.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
10.3M
    } else {
38
10.3M
#if hc_bits_size > 16
39
10.3M
        q[-3] = cb(3);
40
10.3M
        q[-2] = cb(2);
41
10.3M
#endif
42
10.3M
        q[-1] = cb(1);
43
10.3M
        q[0] = cb(0);
44
10.3M
    }
45
10.3M
#undef cb
46
10.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
613k
{
53
2.15M
    while (bits_left < hc_bits_size) {
54
1.53M
        byte c = (byte) (bits >> (hc_bits_size - 8));
55
56
1.53M
        if (ss->FirstBitLowOrder)
57
0
            c = byte_reverse_bits[c];
58
1.53M
        *++q = c;
59
1.53M
        bits <<= 8;
60
1.53M
        bits_left += 8;
61
1.53M
    }
62
613k
    ss->bits = bits;
63
613k
    ss->bits_left = bits_left;
64
613k
    return q;
65
613k
}