Coverage Report

Created: 2026-04-09 07:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ghostpdl/pcl/pxl/pxvalue.c
Line
Count
Source
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
/* pxvalue.c */
18
/* Value accessing for PCL XL */
19
20
#include "std.h"
21
#include "gsmemory.h"
22
#include "pxvalue.h"
23
24
/* Get numeric values from the input or an array. */
25
uint
26
uint16at(const byte * p, bool big_endian)
27
2.29M
{
28
2.29M
    return (big_endian ? (p[0] << 8) + p[1] : (p[1] << 8) + p[0]);
29
2.29M
}
30
int
31
sint16at(const byte * p, bool big_endian)
32
220k
{
33
220k
    return ((int)uint16at(p, big_endian) ^ 0x8000) - 0x8000;
34
220k
}
35
int32_t
36
uint32at(const byte * p, bool big_endian)
37
3.62k
{
38
3.62k
    return
39
3.62k
        (big_endian ?
40
13
         ((int32_t) ((p[0] << 8) + p[1]) << 16) + (p[2] << 8) + p[3] :
41
3.62k
         ((int32_t) ((p[3] << 8) + p[2]) << 16) + (p[1] << 8) + p[0]);
42
3.62k
}
43
int32_t
44
sint32at(const byte * p, bool big_endian)
45
21
{
46
21
    return (uint32at(p, big_endian) ^ 0x80000000) - 0x80000000;
47
21
}
48
real
49
real32at(const byte * p, bool big_endian)
50
1.28k
{
51
1.28k
    union
52
1.28k
    {
53
1.28k
        float f;
54
1.28k
        int32_t d;
55
1.28k
    } df;
56
57
1.28k
    df.d = uint32at(p, big_endian);
58
1.28k
    return (real) df.f;
59
1.28k
}
60
61
/* Get an element from an array. */
62
/* The caller does all index and type checking. */
63
int32_t
64
integer_elt(const px_value_t * pav, uint index)
65
237k
{
66
237k
    px_data_type_t type = pav->type;
67
237k
    const byte *base = pav->value.array.data;
68
237k
    bool big_endian;
69
70
237k
    if (type & pxd_ubyte)
71
236k
        return base[index];
72
1.15k
    big_endian = (type & pxd_big_endian) != 0;
73
1.15k
    if (type & pxd_uint16)
74
1.15k
        return uint16at(base + (index << 1), big_endian);
75
0
    else if (type & pxd_sint16)
76
0
        return sint16at(base + (index << 1), big_endian);
77
0
    else if (type & pxd_uint32)
78
0
        return uint32at(base + (index << 2), big_endian);
79
0
    else                        /* ( type & pxd_sint32 ) */
80
0
        return sint32at(base + (index << 2), big_endian);
81
1.15k
}
82
real
83
real_elt(const px_value_t * pav, uint index)
84
226k
{
85
226k
    return
86
226k
        (pav->type & pxd_real32 ?
87
0
         real32at(pav->value.array.data + (index << 2),
88
0
                  (pav->type & pxd_big_endian) != 0) :
89
226k
         (real) integer_elt(pav, index));
90
226k
}