summaryrefslogtreecommitdiff
path: root/pxl/pxvalue.c
diff options
context:
space:
mode:
authorHenry Stiles <henry.stiles@artifex.com>1998-08-08 01:26:21 +0000
committerHenry Stiles <henry.stiles@artifex.com>1998-08-08 01:26:21 +0000
commit8fb2e6956ece4e94bd9b14eb39ffbafffc3dbc57 (patch)
tree3044ca26a648c41c9b3d5128d801a3121ee42e9f /pxl/pxvalue.c
parentfe9897e6aaa5cd9cb07d5d02928a741d7d061d32 (diff)
pxl115
git-svn-id: http://svn.ghostscript.com/ghostpcl/trunk/ghostpcl@268 06663e23-700e-0410-b217-a244a6096597
Diffstat (limited to 'pxl/pxvalue.c')
-rw-r--r--pxl/pxvalue.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/pxl/pxvalue.c b/pxl/pxvalue.c
new file mode 100644
index 000000000..6a70bbd92
--- /dev/null
+++ b/pxl/pxvalue.c
@@ -0,0 +1,66 @@
+/* Copyright (C) 1996 Aladdin Enterprises. All rights reserved.
+ Unauthorized use, copying, and/or distribution prohibited.
+ */
+
+/* pxvalue.c */
+/* Value accessing for PCL XL */
+
+#include "std.h"
+#include "gsmemory.h"
+#include "pxvalue.h"
+
+/* Get numeric values from the input or an array. */
+uint
+uint16at(const byte *p, bool big_endian)
+{ return (big_endian ? (p[0] << 8) + p[1] : (p[1] << 8) + p[0]);
+}
+int
+sint16at(const byte *p, bool big_endian)
+{ return ((int)uint16at(p, big_endian) ^ 0x8000) - 0x8000;
+}
+integer
+uint32at(const byte *p, bool big_endian)
+{ return
+ (big_endian ?
+ ((integer)((p[0] << 8) + p[1]) << 16) + (p[2] << 8) + p[3] :
+ ((integer)((p[3] << 8) + p[2]) << 16) + (p[1] << 8) + p[0]);
+}
+integer
+sint32at(const byte *p, bool big_endian)
+{ return (uint32at(p, big_endian) ^ 0x80000000) - 0x80000000;
+}
+real
+real32at(const byte *p, bool big_endian)
+{ float f;
+ *(integer *)&f = uint32at(p, big_endian);
+ return (real)f;
+}
+
+/* Get an element from an array. */
+/* The caller does all index and type checking. */
+integer
+integer_elt(const px_value_t *pav, uint index)
+{ px_data_type_t type = pav->type;
+ const byte *base = pav->value.array.data;
+ bool big_endian;
+
+ if ( type & pxd_ubyte )
+ return base[index];
+ big_endian = (type & pxd_big_endian) != 0;
+ if ( type & pxd_uint16 )
+ return uint16at(base + (index << 1), big_endian);
+ else if ( type & pxd_sint16 )
+ return sint16at(base + (index << 1), big_endian);
+ else if ( type & pxd_uint32 )
+ return uint32at(base + (index << 2), big_endian);
+ else /* ( type & pxd_sint32 ) */
+ return sint32at(base + (index << 2), big_endian);
+}
+real
+real_elt(const px_value_t *pav, uint index)
+{ return
+ (pav->type & pxd_real32 ?
+ real32at(pav->value.array.data + (index << 2),
+ (pav->type & pxd_big_endian) != 0) :
+ (real)integer_elt(pav, index));
+}