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