Coverage Report

Created: 2026-07-24 07:44

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.53M
{
28
2.53M
    return (big_endian ? (p[0] << 8) + p[1] : (p[1] << 8) + p[0]);
29
2.53M
}
30
int
31
sint16at(const byte * p, bool big_endian)
32
209k
{
33
209k
    return ((int)uint16at(p, big_endian) ^ 0x8000) - 0x8000;
34
209k
}
35
int32_t
36
uint32at(const byte * p, bool big_endian)
37
3.47k
{
38
3.47k
    return
39
3.47k
        (big_endian ?
40
33
         ((int32_t) ((p[0] << 8) + p[1]) << 16) + (p[2] << 8) + p[3] :
41
3.47k
         ((int32_t) ((p[3] << 8) + p[2]) << 16) + (p[1] << 8) + p[0]);
42
3.47k
}
43
int32_t
44
sint32at(const byte * p, bool big_endian)
45
13
{
46
13
    return (uint32at(p, big_endian) ^ 0x80000000) - 0x80000000;
47
13
}
48
real
49
real32at(const byte * p, bool big_endian)
50
1.29k
{
51
1.29k
    union
52
1.29k
    {
53
1.29k
        float f;
54
1.29k
        int32_t d;
55
1.29k
    } df;
56
57
1.29k
    df.d = uint32at(p, big_endian);
58
1.29k
    return (real) df.f;
59
1.29k
}
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
210k
{
66
210k
    px_data_type_t type = pav->type;
67
210k
    const byte *base = pav->value.array.data;
68
210k
    bool big_endian;
69
70
210k
    if (type & pxd_ubyte)
71
210k
        return base[index];
72
962
    big_endian = (type & pxd_big_endian) != 0;
73
962
    if (type & pxd_uint16)
74
962
        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
962
}
82
real
83
real_elt(const px_value_t * pav, uint index)
84
199k
{
85
199k
    return
86
199k
        (pav->type & pxd_real32 ?
87
0
         real32at(pav->value.array.data + (index << 2),
88
0
                  (pav->type & pxd_big_endian) != 0) :
89
199k
         (real) integer_elt(pav, index));
90
199k
}