aboutsummaryrefslogtreecommitdiff
path: root/sys/gio/gim
diff options
context:
space:
mode:
authorJoe Hunkeler <jhunkeler@gmail.com>2015-08-11 16:51:37 -0400
committerJoe Hunkeler <jhunkeler@gmail.com>2015-08-11 16:51:37 -0400
commit40e5a5811c6ffce9b0974e93cdd927cbcf60c157 (patch)
tree4464880c571602d54f6ae114729bf62a89518057 /sys/gio/gim
downloadiraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'sys/gio/gim')
-rw-r--r--sys/gio/gim/README215
-rw-r--r--sys/gio/gim/gimcpras.x56
-rw-r--r--sys/gio/gim/gimcrras.x26
-rw-r--r--sys/gio/gim/gimderas.x17
-rw-r--r--sys/gio/gim/gimdsmap.x21
-rw-r--r--sys/gio/gim/gimenmap.x21
-rw-r--r--sys/gio/gim/gimfcmap.x17
-rw-r--r--sys/gio/gim/gimfmap.x17
-rw-r--r--sys/gio/gim/gimgetmap.x85
-rw-r--r--sys/gio/gim/gimimap.x13
-rw-r--r--sys/gio/gim/gimlcmap.x51
-rw-r--r--sys/gio/gim/gimqras.x46
-rw-r--r--sys/gio/gim/gimrasini.x14
-rw-r--r--sys/gio/gim/gimrcmap.x68
-rw-r--r--sys/gio/gim/gimref.x18
-rw-r--r--sys/gio/gim/gimrefpix.x38
-rw-r--r--sys/gio/gim/gimriomap.x56
-rw-r--r--sys/gio/gim/gimrpix.x62
-rw-r--r--sys/gio/gim/gimsetmap.x80
-rw-r--r--sys/gio/gim/gimsetpix.x41
-rw-r--r--sys/gio/gim/gimsetras.x28
-rw-r--r--sys/gio/gim/gimwcmap.x42
-rw-r--r--sys/gio/gim/gimwiomap.x37
-rw-r--r--sys/gio/gim/gimwpix.x47
-rw-r--r--sys/gio/gim/mkpkg32
25 files changed, 1148 insertions, 0 deletions
diff --git a/sys/gio/gim/README b/sys/gio/gim/README
new file mode 100644
index 00000000..3c98b736
--- /dev/null
+++ b/sys/gio/gim/README
@@ -0,0 +1,215 @@
+GIM -- GIO graphics imaging library. This is a developmental library based
+on GIO escapes, providing IRAF applications with access to the Gterm widget
+imaging functions. This library is tied directly to the Gterm widget and is
+expected to be replaced by a more general imaging library in the future.
+
+This library is intended only for clients that need to directly access the
+imaging functions in the Gterm widget for full control over the imaging
+capabilities of the Gterm widget. Applications which merely need to display
+an image as part of a more complex graphic would probably be better off
+using the more device independent gpcell (put cell-array) and gpcmap (put
+colormap) calls.
+
+
+The following functions are direct RPC calls to the corresponding Gt-prefixed
+imaging functions in the Gterm widget.
+
+ gim_rasterinit (gp)
+ gim_createraster (gp, raster, type, width, height, depth)
+ gim_destroyraster (gp, raster)
+ exists = gim_queryraster (gp, raster, type, width, height, depth)
+ gim_setraster (gp, raster) # see gseti(gp,G_RASTER,n)
+
+ gim_writepixels (gp, raster, data, nbits, x1, y1, nx, ny)
+ gim_readpixels (gp, raster, data, nbits, x1, y1, nx, ny)
+ gim_refreshpix (gp, raster, ct, x1, y1, nx, ny)
+ gim_setpixels (gp, raster, ct, x1, y1, nx, ny, color, rop)
+
+ gim_writecolormap (gp, colormap, first, nelem, r, g, b)
+ nelem = gim_readcolormap (gp, colormap, first, maxelem, r, g, b)
+ gim_loadcolormap (gp, colormap, offset, slope)
+ gim_freecolormap (gp, colormap)
+ gim_iomapwrite (gp, iomap, first, nelem)
+ gim_iomapread (gp, iomap, first, nelem)
+
+ gim_initmappings (gp)
+ gim_freemapping (gp, mapping)
+ gim_copyraster (gp, rop, src,st,sx,sy,sw,sh, dst,dt,dx,dy,dw,dh)
+ gim_setmapping (gp, mapping, rop,
+ src,st,sx,sy,sw,sh, dst,dt,dx,dy,dw,dh)
+ status = gim_getmapping (gp, mapping, rop,
+ src,st,sx,sy,sw,sh, dst,dt,dx,dy,dw,dh)
+ gim_enablemapping (gp, mapping, refresh)
+ gim_disablemapping (gp, mapping, erase)
+ gim_refreshmapping (gp, mapping)
+
+The following Gterm widget imaging functions have no analogue in the GIM
+imaging interface, but can be called from within GUI code. These functions
+are not implemented at the GIM level either because they are not essential
+and would be too inefficient to be worth using via RPC, or because they
+access resources available only to GUI code.
+
+ GtAssignRaster (gt, raster, drawable)
+ pixmap = GtExtractPixmap (gt, src, ct, x, y, width, height)
+ GtInsertPixmap (gt, pixmap, dst, ct, x, y, width, height)
+ raster = GtSelectRaster (gt, dras, dt, dx, dy, rt, rx, ry, mapping)
+ raster = GtNextRaster (gt)
+ raster = GtGetRaster (gt)
+ n = GtNRasters (gt)
+ pixel = GtGetClientPixel (gt, gterm_pixel)
+ mapping = GtNextMapping (gt)
+ active = GtActiveMapping (gt, mapping)
+
+
+The following messaging routines are also defined by the GIO interface.
+These are used to set the values of UI parameters (i.e., send messages to
+the user interface).
+
+ gmsg (gp, object, message)
+ gmsg[bcsilrdx] (gp, object, value)
+ gmprintf (gp, object, format)
+
+
+The imaging model of the Gterm widget defines the following key object or
+data types: rasters, mappings, and colors.
+
+ raster A raster is a MxN array of pixels. At present pixels are 8
+ bits deep but hooks are built in to the interface to expand
+ this in the future. Pixel values are indices into the Gterm
+ virtual colormap, with values starting at zero. A raster
+ may be any size. A raster is merely a two-dimensional array
+ in the graphics server; it is not displayed unless mapped.
+ An exception is raster zero, which is the graphics window.
+ Rasters are referred to by number, starting with zero.
+ Initially only raster zero exists; new rasters are created
+ with gim_createraster. Space for rasters may be allocated
+ either in the graphics server, or in the X server. This has
+ implications on performance but is otherwise transparent to
+ the client. By default rasters are allocated in the
+ graphics server, i.e., in the X client.
+
+ mapping A mapping defines a projection of a rectangle of the source
+ raster onto a rectangle of the destination raster. Mappings
+ may be either enabled (active) or disabled. When a mapping
+ is enabled, any change to a pixel in the source rect will
+ cause the corresponding pixels in the destination rect to be
+ updated. Mappings are referred to by number starting with
+ one. Initially no mappings are defined. If the size of the
+ input and output rect is not the same the input rect will be
+ scaled by pixel replication or subsampling to fill the
+ output rect. If the argument DW or DH of the destination
+ rect is negative, the image will be flipped around the
+ corresponding axis when copied to the destination; the
+ region of the destination drawn into is the same in either
+ case. Multiple mappings may reference the same source or
+ destination raster. Mappings are refreshed in order by the
+ mapping number. Modifying a mapping causes the changed
+ regions of the destination rect to be refreshed.
+
+ color The gterm widget provides a fixed number of preassigned colors
+ corresponding to pixel values 0 through 9. 0 is the background
+ color, 1 is the foreground color, and 2-9 (8 colors) are
+ arbitrary colors defined by Gterm widget resources. These
+ static colors are normally used to draw the background, frame,
+ axes, titles, etc. of a plot, or to draw color graphics within
+ the drawing area. The advantage of static colors is that they
+ are shared with other X clients, and the values of these
+ colors may be assigned by the user to personalize the way
+ plots look.
+
+ The gterm widget also allows any number (up to about 200 or
+ so) additional colors to be defined at runtime by the client
+ application. These color values start at pixel value 10 and
+ go up to the maximum pixel value assigned by the client. The
+ client application allocates colors with gim_writecolormap.
+ Attempts to overwrite the values of the static colors are
+ ignored. The values of already allocated colors may be
+ changed dynamically at runtime using gim_writecolormap to
+ write the desired range of color values.
+
+ Applications should not assume that there are 10 static
+ colors and 200 or so allocatable colors. The graphcap entry
+ for the logical device in use defines these parameters for
+ the device. Alternatively, the readcolormap call may be
+ used to dynamically determine how many colors the server has
+ preallocated when the application starts up.
+
+ An image may use either static and dyamic pixel values or
+ both types of values, but in most cases imaging applications
+ involve smoothly shaded surfaces hence will require
+ dyamically assigned private colors.
+
+ If for some reason the client application cannot use the
+ gterm widget color model, the IOMAP feature can be used to
+ make the widget appear to have some externally defined
+ (i.e., client defined) color model.
+
+
+The maximum number of rasters and maximum number of mappings is defined by
+Gterm widget resources (e.g. in the GUI file) when the graphics application
+starts up. The maximum values should be much larger than most applications
+require. Applications should allocate raster or mapping numbers
+sequentially starting at 1 (more or less) to avoid running out of raster or
+mapping descriptors.
+
+The {read|write}pixels routines in the GIM interface operate directly on
+raster pixels. The mapping routines support two alternative coordinate
+systems, raster pixels and NDC (normalized device coordinates), as indicated
+by the ST or DT argument (source or destination coordinate type). Note
+that the origin of the pixel coordinate system is the upper left corner of
+the display window (consistent with most graphics systems), whereas the origin
+of the NDC coordinate system is the lower left corner (consistent with IRAF).
+
+Pixel coordinates allow precise control of imaging but require the
+application to know the window size, and may result in complications e.g. if
+the window is resized. NDC coordinates pretty much guarantee that a mapping
+will involve sampling, hence are not the most efficient, but the graphics
+will be drawn correctly no matter how the window is resized and for most
+applications the performance difference is negligible. Most applications
+should use NDC coordinates for raster 0 (the display window), and pixel
+coordinates for rasters 1-N.
+
+Although the size of rasters 1 and higher are defined by the client
+application, the size of raster zero, the actual gterm display window, is
+subject to the constraints of the window system. The client can attempt to
+reset the size of the gterm window using gim_createraster with raster=0,
+however the Gterm widget, UI containing the gterm widget, and the window
+manager are all free to deny such a request. gim_queryraster should be
+called to determine the actual size of the window one will be drawing into.
+
+
+EXAMPLE
+
+ A simple example of an imaging application might download an image and
+display it in the gterm window, filling the window. This could be done as
+follows (following a GOPEN and other GIO calls to prepare the drawing surface).
+
+ gim_createraster Create raster 1 the size of the pixel array
+ to be displayed. This need not be the same
+ as the size of the gterm display window.
+
+ gim_setmapping Define a mapping between raster 1 and raster 0,
+ the display window, using NDC coordinates to
+ define the region of the display window to be
+ filled. The mapping number is arbitrary but
+ mappings should normally be allocated starting
+ with 1. The mapping is automatically enabled
+ when first defined.
+
+ gim_writecolormap (Optional). Define the pixel value to RGB
+ color assignments for the image pixels.
+
+ gim_writepixels This routine is called one or more times to
+ write pixels into raster 1. At most 32K
+ pixels (minus a bit for the GKI headers) can
+ be written in each call. As each write is
+ made the affected region of the display
+ window will be updated.
+
+Alternatively, one could write the pixels and then define the mapping, to
+cause the entire image to be displayed at once.
+
+Note that the GIM calls can be combined with normal GIO graphics to draw text
+and graphics around or on top of an image region. The order in which drawing
+operations occur is important, e.g., to draw graphics or text on top of an
+image the image should be drawn first.
diff --git a/sys/gio/gim/gimcpras.x b/sys/gio/gim/gimcpras.x
new file mode 100644
index 00000000..ea1ab32f
--- /dev/null
+++ b/sys/gio/gim/gimcpras.x
@@ -0,0 +1,56 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <gescape.h>
+include <gki.h>
+include <gim.h>
+
+# GIM_COPYRASTER -- Copy a portion of the source raster to a rectangular
+# region of the destination raster.
+
+procedure gim_copyraster (gp, rop, src,st,sx,sy,sw,sh, dst,dt,dx,dy,dw,dh)
+
+pointer gp #I graphics descriptor
+int rop #I rasterop
+int src #I source raster
+int st #I coordinate type for source raster
+real sx,sy,sw,sh #I source rect
+int dst #I destination raster
+int dt #I coordinate type for destination raster
+real dx,dy,dw,dh #I destination rect
+
+short gim[GIM_COPYRASTER_LEN]
+
+begin
+ gim[GIM_COPYRASTER_OP] = rop
+ gim[GIM_COPYRASTER_SR] = src
+ gim[GIM_COPYRASTER_ST] = st
+
+ if (st == CT_PIXEL) {
+ gim[GIM_COPYRASTER_SX] = sx
+ gim[GIM_COPYRASTER_SY] = sy
+ gim[GIM_COPYRASTER_SW] = sw
+ gim[GIM_COPYRASTER_SH] = sh
+ } else {
+ gim[GIM_COPYRASTER_SX] = sx * GKI_MAXNDC
+ gim[GIM_COPYRASTER_SY] = sy * GKI_MAXNDC
+ gim[GIM_COPYRASTER_SW] = nint (sw * GKI_MAXNDC)
+ gim[GIM_COPYRASTER_SH] = nint (sh * GKI_MAXNDC)
+ }
+
+ gim[GIM_COPYRASTER_DR] = dst
+ gim[GIM_COPYRASTER_DT] = dt
+
+ if (dt == CT_PIXEL) {
+ gim[GIM_COPYRASTER_DX] = dx
+ gim[GIM_COPYRASTER_DY] = dy
+ gim[GIM_COPYRASTER_DW] = dw
+ gim[GIM_COPYRASTER_DH] = dh
+ } else {
+ gim[GIM_COPYRASTER_DX] = dx * GKI_MAXNDC
+ gim[GIM_COPYRASTER_DY] = dy * GKI_MAXNDC
+ gim[GIM_COPYRASTER_DW] = nint (dw * GKI_MAXNDC)
+ gim[GIM_COPYRASTER_DH] = nint (dh * GKI_MAXNDC)
+ }
+
+ call gescape (gp, GIM_COPYRASTER, gim, GIM_COPYRASTER_LEN)
+end
diff --git a/sys/gio/gim/gimcrras.x b/sys/gio/gim/gimcrras.x
new file mode 100644
index 00000000..9372f85f
--- /dev/null
+++ b/sys/gio/gim/gimcrras.x
@@ -0,0 +1,26 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <gescape.h>
+
+# GIM_CREATERASTER -- Create, recreate, or resize a raster.
+
+procedure gim_createraster (gp, raster, type, width, height, depth)
+
+pointer gp #I graphics descriptor
+int raster #I raster number (0 is display window)
+int type #I raster type (normal,ximage,pixmap)
+int width #I raster width in pixels
+int height #I raster height in pixels
+int depth #I raster depth, bits per pixel
+
+short gim[GIM_CREATERASTER_LEN]
+
+begin
+ gim[GIM_CREATERASTER_RN] = raster
+ gim[GIM_CREATERASTER_RT] = type
+ gim[GIM_CREATERASTER_NX] = width
+ gim[GIM_CREATERASTER_NY] = height
+ gim[GIM_CREATERASTER_BP] = depth
+
+ call gescape (gp, GIM_CREATERASTER, gim, GIM_CREATERASTER_LEN)
+end
diff --git a/sys/gio/gim/gimderas.x b/sys/gio/gim/gimderas.x
new file mode 100644
index 00000000..9a492759
--- /dev/null
+++ b/sys/gio/gim/gimderas.x
@@ -0,0 +1,17 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <gescape.h>
+
+# GIM_DESTROYRASTER -- Destroy a raster.
+
+procedure gim_destroyraster (gp, raster)
+
+pointer gp #I graphics descriptor
+int raster #I raster number (0 is display window)
+
+short gim[GIM_DESTROYRASTER_LEN]
+
+begin
+ gim[GIM_DESTROYRASTER_RN] = raster
+ call gescape (gp, GIM_DESTROYRASTER, gim, GIM_DESTROYRASTER_LEN)
+end
diff --git a/sys/gio/gim/gimdsmap.x b/sys/gio/gim/gimdsmap.x
new file mode 100644
index 00000000..a1618413
--- /dev/null
+++ b/sys/gio/gim/gimdsmap.x
@@ -0,0 +1,21 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <gescape.h>
+
+# GIM_DISABLEMAPPING -- Disable a previously defined mapping. Disabling a
+# mapping does not automatically erase the mapping unless the erase flag
+# is set.
+
+procedure gim_disablemapping (gp, mapping, erase)
+
+pointer gp #I graphics descriptor
+int mapping #I mapping to be defined or edited
+int erase #I erase flag
+
+short gim[GIM_DISABLEMAPPING_LEN]
+
+begin
+ gim[GIM_DISABLEMAPPING_MP] = mapping
+ gim[GIM_DISABLEMAPPING_FL] = erase
+ call gescape (gp, GIM_DISABLEMAPPING, gim, GIM_DISABLEMAPPING_LEN)
+end
diff --git a/sys/gio/gim/gimenmap.x b/sys/gio/gim/gimenmap.x
new file mode 100644
index 00000000..02e9af3b
--- /dev/null
+++ b/sys/gio/gim/gimenmap.x
@@ -0,0 +1,21 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <gescape.h>
+
+# GIM_ENABLEMAPPING -- Enable a previously defined mapping. Enabling a
+# mapping does not automatically refresh the destination unless the refresh
+# flag is set (refresh=YES).
+
+procedure gim_enablemapping (gp, mapping, refresh)
+
+pointer gp #I graphics descriptor
+int mapping #I mapping to be defined or edited
+int refresh #I refresh flag
+
+short gim[GIM_ENABLEMAPPING_LEN]
+
+begin
+ gim[GIM_ENABLEMAPPING_MP] = mapping
+ gim[GIM_ENABLEMAPPING_FL] = refresh
+ call gescape (gp, GIM_ENABLEMAPPING, gim, GIM_ENABLEMAPPING_LEN)
+end
diff --git a/sys/gio/gim/gimfcmap.x b/sys/gio/gim/gimfcmap.x
new file mode 100644
index 00000000..9194e9bf
--- /dev/null
+++ b/sys/gio/gim/gimfcmap.x
@@ -0,0 +1,17 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <gescape.h>
+
+# GIM_FREECOLORMAP -- Free a colormap.
+
+procedure gim_freecolormap (gp, colormap)
+
+pointer gp #I graphics descriptor
+int colormap #I colormap number
+
+short gim[GIM_FREECMAP_LEN]
+
+begin
+ gim[GIM_FREECMAP_MP] = colormap
+ call gescape (gp, GIM_FREECMAP, gim, GIM_FREECMAP_LEN)
+end
diff --git a/sys/gio/gim/gimfmap.x b/sys/gio/gim/gimfmap.x
new file mode 100644
index 00000000..f69355a4
--- /dev/null
+++ b/sys/gio/gim/gimfmap.x
@@ -0,0 +1,17 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <gescape.h>
+
+# GIM_FREEMAPPING -- Free a mapping.
+
+procedure gim_freemapping (gp, mapping)
+
+pointer gp #I graphics descriptor
+int mapping #I mapping number
+
+short gim[GIM_FREEMAPPING_LEN]
+
+begin
+ gim[GIM_FREEMAPPING_MP] = mapping
+ call gescape (gp, GIM_FREEMAPPING, gim, GIM_FREEMAPPING_LEN)
+end
diff --git a/sys/gio/gim/gimgetmap.x b/sys/gio/gim/gimgetmap.x
new file mode 100644
index 00000000..c58bae0d
--- /dev/null
+++ b/sys/gio/gim/gimgetmap.x
@@ -0,0 +1,85 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <syserr.h>
+include <gescape.h>
+include <fset.h>
+include <gio.h>
+include <gki.h>
+include <gim.h>
+
+# GIM_GETMAPPING -- Get the parameters defining a mapping. The function value
+# is YES if the mapping is defined and enabled and NO if the mapping is
+# defined but not enabled. If the mapping is not defined ERR is returned.
+
+int procedure gim_getmapping (gp, mapping, rop,
+ src,st,sx,sy,sw,sh, dst,dt,dx,dy,dw,dh)
+
+pointer gp #I graphics descriptor
+int mapping #I mapping to be queried
+int rop #O rasterop
+int src #O source raster
+int st #O coordinate type for source raster
+int sx,sy,sw,sh #O source rect
+int dst #O destination raster
+int dt #O coordinate type for destination raster
+int dx,dy,dw,dh #O destination rect
+
+int nchars, nread
+short gim[GIM_GETMAPPING_LEN]
+short retval[GIM_RET_GMAP_LEN]
+errchk gescape, flush, read, syserrs
+int read(), btoi()
+
+begin
+ call gpl_flush()
+ gim[GIM_GETMAPPING_MP] = mapping
+ call gescape (gp, GIM_GETMAPPING, gim, GIM_GETMAPPING_LEN)
+ call flush (GP_FD(gp))
+
+ # This assumes a normal stream type GKI connection.
+ nchars = GIM_RET_GMAP_LEN * SZ_SHORT
+ nread = read (GP_FD(gp), retval, nchars)
+ call fseti (GP_FD(gp), F_CANCEL, OK)
+ if (nread != nchars)
+ call syserrs (SYS_FREAD, "gim_getmapping")
+
+ # EN=0 not defined, EN=1 defined not enabled, EN=2 defined enabled.
+ if (retval[GIM_RET_GMAP_EN] == 0)
+ return (ERR)
+ else {
+ rop = retval[GIM_RET_GMAP_OP]
+
+ src = retval[GIM_RET_GMAP_SR]
+ st = retval[GIM_RET_GMAP_ST]
+
+ if (st == CT_PIXEL) {
+ sx = retval[GIM_RET_GMAP_SX]
+ sy = retval[GIM_RET_GMAP_SY]
+ sw = retval[GIM_RET_GMAP_SW]
+ sh = retval[GIM_RET_GMAP_SH]
+ } else {
+ sx = real (retval[GIM_RET_GMAP_SX]) / GKI_MAXNDC
+ sy = real (retval[GIM_RET_GMAP_SY]) / GKI_MAXNDC
+ sw = real (retval[GIM_RET_GMAP_SW]) / GKI_MAXNDC
+ sh = real (retval[GIM_RET_GMAP_SH]) / GKI_MAXNDC
+ }
+
+ dst = retval[GIM_RET_GMAP_SR]
+ dt = retval[GIM_RET_GMAP_DT]
+
+ if (dt == CT_PIXEL) {
+ dx = retval[GIM_RET_GMAP_DX]
+ dy = retval[GIM_RET_GMAP_DY]
+ dw = retval[GIM_RET_GMAP_DW]
+ dh = retval[GIM_RET_GMAP_DH]
+ } else {
+ dx = real (retval[GIM_RET_GMAP_DX]) / GKI_MAXNDC
+ dy = real (retval[GIM_RET_GMAP_DY]) / GKI_MAXNDC
+ dw = real (retval[GIM_RET_GMAP_DW]) / GKI_MAXNDC
+ dh = real (retval[GIM_RET_GMAP_DH]) / GKI_MAXNDC
+ }
+
+ }
+
+ return (btoi (retval[GIM_RET_GMAP_EN] == 2))
+end
diff --git a/sys/gio/gim/gimimap.x b/sys/gio/gim/gimimap.x
new file mode 100644
index 00000000..2c4a5d28
--- /dev/null
+++ b/sys/gio/gim/gimimap.x
@@ -0,0 +1,13 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <gescape.h>
+
+# GIM_INITMAPPINGS -- Initialize the Gterm widget raster mappings.
+
+procedure gim_initmappings (gp)
+
+pointer gp #I graphics descriptor
+
+begin
+ call gescape (gp, GIM_INITMAPPINGS, 0, GIM_INITMAPPINGS_LEN)
+end
diff --git a/sys/gio/gim/gimlcmap.x b/sys/gio/gim/gimlcmap.x
new file mode 100644
index 00000000..afcd9045
--- /dev/null
+++ b/sys/gio/gim/gimlcmap.x
@@ -0,0 +1,51 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <gescape.h>
+include <mach.h>
+include <gim.h>
+include <gki.h>
+
+# GIM_LOADCOLORMAP -- Load a colormap into the display (hardware) colormap.
+# Any number of colormaps may be defined, but only one may be loaded at a
+# time. A linear transformation may optionally be applied to the (normalized)
+# colormap when it is loaded. Set offset=0.5, slope=1.0 to load the colormap
+# without scaling. A negative slope inverts the image.
+#
+# The offset refers to the center of the mapped region of the transfer
+# function, which is why the center value is at 0.5. For example, if the
+# range of raster pixel intensities is normalized to the range 0.0 to 1.0,
+# then a transfer function of [offset=0.3,slope=3.0] will display the region
+# of intenstities centered around the normalized intenstity of 0.3, with a
+# contrast of 3.0 (the screen intensity changes 3 units for a unit change in
+# raster pixel intensity). The transfer function [offset=0.3,slope=-3.0]
+# will display the same range of pixel intensitites, but with a negative
+# contrast. The transfer function [offset=0.5,slope=1.0] has intercepts
+# of [0,0] and [1,1] hence it displays the full range of raster pixel
+# intensities - the input colormap is used as is, without resampling.
+
+procedure gim_loadcolormap (gp, colormap, offset, slope)
+
+pointer gp #I graphics descriptor
+int colormap #I colormap number (0 is display colormap)
+real offset, slope #I linear transformation on colormap
+
+real veclen, scale
+short gim[GIM_LOADCMAP_LEN]
+
+begin
+ scale = GIM_LOADCMAP_SCALE
+ gim[GIM_LOADCMAP_MP] = colormap
+ gim[GIM_LOADCMAP_OF] = ((GKI_MAXNDC + 1) / scale) *
+ max(-scale, min(scale, offset))
+
+ if (abs(slope) < EPSILONR)
+ veclen = GKI_MAXNDC
+ else {
+ veclen = GKI_MAXNDC + 1
+ veclen = min (veclen / 2, veclen / abs(slope) / 2)
+ }
+ gim[GIM_LOADCMAP_DX] = veclen
+ gim[GIM_LOADCMAP_DY] = veclen * slope
+
+ call gescape (gp, GIM_LOADCMAP, gim, GIM_LOADCMAP_LEN)
+end
diff --git a/sys/gio/gim/gimqras.x b/sys/gio/gim/gimqras.x
new file mode 100644
index 00000000..fa8f5909
--- /dev/null
+++ b/sys/gio/gim/gimqras.x
@@ -0,0 +1,46 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <syserr.h>
+include <gescape.h>
+include <fset.h>
+include <gio.h>
+
+# GIM_QUERYRASTER -- Query a raster. The function value (YES/NO) indicates
+# whether or not the raster exists. If the raster exists, the raster type
+# and size are returned as output arguments.
+
+int procedure gim_queryraster (gp, raster, type, width, height, depth)
+
+pointer gp #I graphics descriptor
+int raster #I raster number (0 is display window)
+int type #O raster type (ximage,pixmap)
+int width #O raster width in pixels
+int height #O raster height in pixels
+int depth #O raster depth, bits per pixel
+
+int nchars, nread
+short gim[GIM_QUERYRASTER_LEN]
+short retval[GIM_RET_QRAS_LEN]
+errchk gescape, flush, read, syserrs
+int read()
+
+begin
+ call gpl_flush()
+ gim[GIM_QUERYRASTER_RN] = raster
+ call gescape (gp, GIM_QUERYRASTER, gim, GIM_QUERYRASTER_LEN)
+ call flush (GP_FD(gp))
+
+ # This assumes a normal stream type GKI connection.
+ nchars = GIM_RET_QRAS_LEN * SZ_SHORT
+ nread = read (GP_FD(gp), retval, nchars)
+ call fseti (GP_FD(gp), F_CANCEL, OK)
+ if (nread != nchars)
+ call syserrs (SYS_FREAD, "gim_queryraster")
+
+ type = retval[GIM_RET_QRAS_RT]
+ width = retval[GIM_RET_QRAS_NX]
+ height = retval[GIM_RET_QRAS_NY]
+ depth = retval[GIM_RET_QRAS_BP]
+
+ return (retval[GIM_RET_QRAS_EX])
+end
diff --git a/sys/gio/gim/gimrasini.x b/sys/gio/gim/gimrasini.x
new file mode 100644
index 00000000..56914746
--- /dev/null
+++ b/sys/gio/gim/gimrasini.x
@@ -0,0 +1,14 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <gescape.h>
+
+# GIM_RASTERINIT -- Initialize the Gterm widget imaging subsystem. Destroys
+# any existing rasters, mappings, and dynamic colors.
+
+procedure gim_rasterinit (gp)
+
+pointer gp #I graphics descriptor
+
+begin
+ call gescape (gp, GIM_RASTERINIT, 0, GIM_RASTERINIT_LEN)
+end
diff --git a/sys/gio/gim/gimrcmap.x b/sys/gio/gim/gimrcmap.x
new file mode 100644
index 00000000..8fb9f4d2
--- /dev/null
+++ b/sys/gio/gim/gimrcmap.x
@@ -0,0 +1,68 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <syserr.h>
+include <gescape.h>
+include <fset.h>
+include <gio.h>
+
+# GIM_READCOLORMAP -- Read a segment of a colormap. The number of cells
+# read is returned. The number of cells read may be less than the request
+# size if the cells have not yet been allocated.
+
+int procedure gim_readcolormap (gp, colormap, first, maxelem, r, g, b)
+
+pointer gp #I graphics descriptor
+int colormap #I colormap number (0=screen)
+int first #I first colormap entry to be read
+int maxelem #I number of elements to read
+int r[ARB],g[ARB],b[ARB] #O RGB color values (0-255)
+
+pointer sp, cm, ip
+int ncells, nret, nchars, i
+short gim[GIM_READCMAP_LEN]
+short retval[GIM_RET_RCMAP_LEN]
+int read()
+
+string s_readcmap "gim_readcolormap"
+errchk flush, read, syserrs
+
+begin
+ call smark (sp)
+ call gpl_flush()
+
+ gim[GIM_READCMAP_MP] = colormap
+ gim[GIM_READCMAP_FC] = first
+ gim[GIM_READCMAP_NC] = maxelem
+ call gescape (gp, GIM_READCMAP, gim, GIM_READCMAP_LEN)
+ call flush (GP_FD(gp))
+
+ # Get return value instruction header.
+ nchars = GIM_RET_RCMAP_LEN * SZ_SHORT
+ if (read (GP_FD(gp), retval, nchars) != nchars) {
+ call fseti (GP_FD(gp), F_CANCEL, OK)
+ call syserrs (SYS_FREAD, s_readcmap)
+ }
+
+ ncells = retval[GIM_RET_RCMAP_NC]
+ call salloc (cm, ncells * 3, TY_SHORT)
+ nret = min (ncells, maxelem)
+
+ # Get the colormap data.
+ nchars = (ncells * 3) * SZ_SHORT
+ if (read (GP_FD(gp), Mems[cm], nchars) != nchars) {
+ call fseti (GP_FD(gp), F_CANCEL, OK)
+ call syserrs (SYS_FREAD, s_readcmap)
+ }
+
+ do i = 1, nret {
+ ip = cm + (i - 1) * 3
+ r[i] = Mems[ip+0]
+ g[i] = Mems[ip+1]
+ b[i] = Mems[ip+2]
+ }
+
+ call fseti (GP_FD(gp), F_CANCEL, OK)
+ call sfree (sp)
+
+ return (nret)
+end
diff --git a/sys/gio/gim/gimref.x b/sys/gio/gim/gimref.x
new file mode 100644
index 00000000..dd3085d4
--- /dev/null
+++ b/sys/gio/gim/gimref.x
@@ -0,0 +1,18 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <gescape.h>
+
+# GIM_REFRESHMAPPING -- Refresh a previously defined mapping, i.e., repaint
+# the destination rect.
+
+procedure gim_refreshmapping (gp, mapping)
+
+pointer gp #I graphics descriptor
+int mapping #I mapping to be defined or edited
+
+short gim[GIM_REFRESHMAPPING_LEN]
+
+begin
+ gim[GIM_REFRESHMAPPING_MP] = mapping
+ call gescape (gp, GIM_REFRESHMAPPING, gim, GIM_REFRESHMAPPING_LEN)
+end
diff --git a/sys/gio/gim/gimrefpix.x b/sys/gio/gim/gimrefpix.x
new file mode 100644
index 00000000..1d906a1a
--- /dev/null
+++ b/sys/gio/gim/gimrefpix.x
@@ -0,0 +1,38 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <gescape.h>
+include <gim.h>
+include <gki.h>
+
+# GIM_REFRESHPIX -- Update any mappings defined upon the given region of
+# the given source raster, as if the pixel values had been set with a write
+# pixels call.
+
+procedure gim_refreshpix (gp, raster, ct, x1, y1, width, height)
+
+pointer gp #I graphics descriptor
+int raster #I raster number (0 is display window)
+int ct #I coordinate type
+real x1, y1 #I region to be refreshed
+real width, height #I region to be refreshed
+
+short gim[GIM_REFRESHPIXELS_LEN]
+
+begin
+ gim[GIM_REFRESHPIXELS_RN] = raster
+ gim[GIM_REFRESHPIXELS_CT] = ct
+
+ if (ct == CT_PIXEL) {
+ gim[GIM_REFRESHPIXELS_X1] = x1
+ gim[GIM_REFRESHPIXELS_Y1] = y1
+ gim[GIM_REFRESHPIXELS_NX] = width
+ gim[GIM_REFRESHPIXELS_NY] = height
+ } else {
+ gim[GIM_REFRESHPIXELS_X1] = x1 * GKI_MAXNDC
+ gim[GIM_REFRESHPIXELS_Y1] = y1 * GKI_MAXNDC
+ gim[GIM_REFRESHPIXELS_NX] = nint (width * GKI_MAXNDC)
+ gim[GIM_REFRESHPIXELS_NY] = nint (height * GKI_MAXNDC)
+ }
+
+ call gescape (gp, GIM_REFRESHPIXELS, gim, GIM_REFRESHPIXELS_LEN)
+end
diff --git a/sys/gio/gim/gimriomap.x b/sys/gio/gim/gimriomap.x
new file mode 100644
index 00000000..0f152ca5
--- /dev/null
+++ b/sys/gio/gim/gimriomap.x
@@ -0,0 +1,56 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <syserr.h>
+include <gescape.h>
+include <fset.h>
+include <gio.h>
+
+# GIM_IOMAPREAD -- Read a segment of the gterm widget iomap.
+
+procedure gim_iomapread (gp, iomap, first, nelem)
+
+pointer gp #I graphics descriptor
+int iomap[ARB] #o iomap data
+int first #I first iomap cell to be read
+int nelem #I number of elements to read
+
+int nchars
+pointer sp, data
+short gim[GIM_READIOMAP_LEN]
+short retval[GIM_RET_RIOMAP_LEN]
+int read()
+
+string s_readiomap "gim_iomapread"
+errchk flush, read, syserrs
+
+begin
+ call smark (sp)
+ call gpl_flush()
+
+ gim[GIM_READIOMAP_FC] = first
+ gim[GIM_READIOMAP_NC] = nelem
+ call gescape (gp, GIM_READIOMAP, gim, GIM_READIOMAP_LEN)
+ call flush (GP_FD(gp))
+
+ # Get return value instruction header.
+ nchars = GIM_RET_RIOMAP_LEN * SZ_SHORT
+ if (read (GP_FD(gp), retval, nchars) != nchars) {
+ call fseti (GP_FD(gp), F_CANCEL, OK)
+ call syserrs (SYS_FREAD, s_readiomap)
+ }
+
+ if (retval[GIM_RET_RIOMAP_NC] != nelem)
+ call syserrs (SYS_FREAD, s_readiomap)
+
+ # Get the iomap data.
+ call salloc (data, nelem, TY_SHORT)
+ nchars = nelem * SZ_SHORT
+ if (read (GP_FD(gp), Mems[data], nchars) != nchars) {
+ call fseti (GP_FD(gp), F_CANCEL, OK)
+ call syserrs (SYS_FREAD, s_readiomap)
+ } else
+ call achtsi (Mems[data], iomap, nelem)
+
+ call fseti (GP_FD(gp), F_CANCEL, OK)
+ call sfree (sp)
+end
diff --git a/sys/gio/gim/gimrpix.x b/sys/gio/gim/gimrpix.x
new file mode 100644
index 00000000..4b6c7e9b
--- /dev/null
+++ b/sys/gio/gim/gimrpix.x
@@ -0,0 +1,62 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <syserr.h>
+include <mach.h>
+include <gio.h>
+include <fset.h>
+include <gescape.h>
+
+# GIM_READPIXELS -- Read from a rectangular region of a raster.
+
+procedure gim_readpixels (gp, raster, data, nbits, x1, y1, nx, ny)
+
+pointer gp #I graphics descriptor
+int raster #I raster number (0 is display window)
+short data[ARB] #O returned pixel data
+int nbits #I nbits per raster pixel (1,8,16,32)
+int x1, y1 #I first pixel to be written
+int nx, ny #I size of region to be written
+
+int npix, nchars, nwords
+short gim[GIM_READPIXELS_LEN]
+short retval[GIM_RET_RPIX_LEN]
+errchk gpl_flush, gflush, read, syserrs
+string s_readpixels "gim_readpixels"
+int read()
+
+begin
+ call gpl_flush()
+ npix = nx * ny
+ nchars = (npix * nbits / NBITS_BYTE + SZB_CHAR-1) / SZB_CHAR
+ nwords = (nchars + SZ_SHORT-1) / SZ_SHORT
+
+ gim[GIM_READPIXELS_RN] = raster
+ gim[GIM_READPIXELS_EC] = 0
+ gim[GIM_READPIXELS_X1] = x1
+ gim[GIM_READPIXELS_Y1] = y1
+ gim[GIM_READPIXELS_NX] = nx
+ gim[GIM_READPIXELS_NY] = ny
+ gim[GIM_READPIXELS_BP] = nbits
+
+ call gki_escape (gp, GIM_READPIXELS, gim, GIM_READPIXELS_LEN)
+ call flush (GP_FD(gp))
+
+ # Get return value instruction header.
+ nchars = GIM_RET_RPIX_LEN * SZ_SHORT
+ if (read (GP_FD(gp), retval, nchars) != nchars) {
+ call fseti (GP_FD(gp), F_CANCEL, OK)
+ call syserrs (SYS_FREAD, s_readpixels)
+ }
+
+ # Get the pixel data.
+ npix = retval[GIM_RET_RPIX_NP]
+ nchars = (npix * nbits / NBITS_BYTE + SZB_CHAR-1) / SZB_CHAR
+ if (read (GP_FD(gp), data, nchars) != nchars) {
+ call fseti (GP_FD(gp), F_CANCEL, OK)
+ call syserrs (SYS_FREAD, s_readpixels)
+ }
+
+ call fseti (GP_FD(gp), F_CANCEL, OK)
+ if (npix != nx * ny)
+ call syserrs (SYS_IMNOPIX, s_readpixels)
+end
diff --git a/sys/gio/gim/gimsetmap.x b/sys/gio/gim/gimsetmap.x
new file mode 100644
index 00000000..2cf5f7b6
--- /dev/null
+++ b/sys/gio/gim/gimsetmap.x
@@ -0,0 +1,80 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <gio.h>
+include <gescape.h>
+include <gki.h>
+include <gim.h>
+
+# GIM_SETMAPPING -- Define a mapping between a source rect and a destination
+# rect. While the mapping is enabled, any changes to the source rect will
+# be automatically propagated to the destination rect. If the source and
+# destination rects are not the same size the source rect will be scaled to
+# fit the output rect. A negative DW or DH causes the X or Y axis to be
+# flipped during the mapping. Setmapping automatically enables a new
+# mapping, but no data is copied until the source rect is subsequently
+# modified or the mapping is modified or refreshed. Setmapping may be called
+# on an already existing mapping to edit the mapping. If the mapping is
+# enabled the effect of the edit will be visible immediately. Only the
+# modified regions of the destination rect will be updated by a mapping.
+
+procedure gim_setmapping (gp, mapping, rop,
+ src,st,sx,sy,sw,sh, dst,dt,dx,dy,dw,dh)
+
+pointer gp #I graphics descriptor
+int mapping #I mapping to be defined or edited
+int rop #I rasterop
+int src #I source raster
+int st #I coordinate type for source raster
+real sx,sy,sw,sh #I source rect
+int dst #I destination raster
+int dt #I coordinate type for destination raster
+real dx,dy,dw,dh #I destination rect
+
+short gim[GIM_SETMAPPING_LEN]
+errchk gpl_flush, gpl_cache
+include "../gpl.com"
+
+begin
+ # Flush any buffered polyline output. Make sure the wcs transformation
+ # in the cache is up to date.
+
+ if (op > 1)
+ call gpl_flush()
+ else if (gp != gp_out || GP_WCS(gp) != wcs)
+ call gpl_cache (gp)
+
+ # Output the setmapping escape.
+ gim[GIM_SETMAPPING_MP] = mapping
+ gim[GIM_SETMAPPING_OP] = rop
+ gim[GIM_SETMAPPING_SR] = src
+ gim[GIM_SETMAPPING_ST] = st
+
+ if (st == CT_PIXEL) {
+ gim[GIM_SETMAPPING_SX] = sx
+ gim[GIM_SETMAPPING_SY] = sy
+ gim[GIM_SETMAPPING_SW] = sw
+ gim[GIM_SETMAPPING_SH] = sh
+ } else {
+ gim[GIM_SETMAPPING_SX] = sx * GKI_MAXNDC
+ gim[GIM_SETMAPPING_SY] = sy * GKI_MAXNDC
+ gim[GIM_SETMAPPING_SW] = nint (sw * GKI_MAXNDC)
+ gim[GIM_SETMAPPING_SH] = nint (sh * GKI_MAXNDC)
+ }
+
+ gim[GIM_SETMAPPING_DR] = dst
+ gim[GIM_SETMAPPING_DT] = dt
+
+ if (dt == CT_PIXEL) {
+ gim[GIM_SETMAPPING_DX] = dx
+ gim[GIM_SETMAPPING_DY] = dy
+ gim[GIM_SETMAPPING_DW] = dw
+ gim[GIM_SETMAPPING_DH] = dh
+ } else {
+ gim[GIM_SETMAPPING_DX] = dx * GKI_MAXNDC
+ gim[GIM_SETMAPPING_DY] = dy * GKI_MAXNDC
+ gim[GIM_SETMAPPING_DW] = nint (dw * GKI_MAXNDC)
+ gim[GIM_SETMAPPING_DH] = nint (dh * GKI_MAXNDC)
+ }
+
+ call gescape (gp, GIM_SETMAPPING, gim, GIM_SETMAPPING_LEN)
+end
diff --git a/sys/gio/gim/gimsetpix.x b/sys/gio/gim/gimsetpix.x
new file mode 100644
index 00000000..09250221
--- /dev/null
+++ b/sys/gio/gim/gimsetpix.x
@@ -0,0 +1,41 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <gescape.h>
+include <gim.h>
+include <gki.h>
+
+# GIM_SETPIX -- Set the pixels in a region of a raster to a solid color.
+# If width=height=0 the entire raster will be written.
+
+procedure gim_setpix (gp, raster, ct, x1, y1, width, height, color, rop)
+
+pointer gp #I graphics descriptor
+int raster #I raster number (0 is display window)
+int ct #I coordinate type
+real x1, y1 #I region to be refreshed
+real width, height #I region to be refreshed
+int color #I pixel value
+int rop #I rasterop
+
+short gim[GIM_SETPIXELS_LEN]
+
+begin
+ gim[GIM_SETPIXELS_RN] = raster
+ gim[GIM_SETPIXELS_CT] = ct
+ gim[GIM_SETPIXELS_CO] = color
+ gim[GIM_SETPIXELS_OP] = rop
+
+ if (ct == CT_PIXEL) {
+ gim[GIM_SETPIXELS_X1] = x1
+ gim[GIM_SETPIXELS_Y1] = y1
+ gim[GIM_SETPIXELS_NX] = width
+ gim[GIM_SETPIXELS_NY] = height
+ } else {
+ gim[GIM_SETPIXELS_X1] = x1 * GKI_MAXNDC
+ gim[GIM_SETPIXELS_Y1] = y1 * GKI_MAXNDC
+ gim[GIM_SETPIXELS_NX] = nint (width * GKI_MAXNDC)
+ gim[GIM_SETPIXELS_NY] = nint (height * GKI_MAXNDC)
+ }
+
+ call gescape (gp, GIM_SETPIXELS, gim, GIM_SETPIXELS_LEN)
+end
diff --git a/sys/gio/gim/gimsetras.x b/sys/gio/gim/gimsetras.x
new file mode 100644
index 00000000..efb5add5
--- /dev/null
+++ b/sys/gio/gim/gimsetras.x
@@ -0,0 +1,28 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <gescape.h>
+
+# GIM_SETRASTER -- Set the raster to be used as the coordinate system for
+# graphics drawing operations. A setraster for raster N causes subsequent
+# drawing operations to be drawn using any raster-to-screen mappings defined
+# for raster N. A setraster to raster=0 restores the normal semantics of
+# drawing directly to the screen with no additional transformations.
+# Applications which use gim_setraster to draw graphics or text overlays on
+# a raster should always restore the raster to zero when done so that
+# subsequent drawing operations (e.g., in cursor mode) behave normally.
+# The setraster is not reset automatically except in a screen clear.
+#
+# NOTE - Most applications should use gseti(gp,G_RASTER,n) instead of the
+# lower level gim_setraster.
+
+procedure gim_setraster (gp, raster)
+
+pointer gp #I graphics descriptor
+int raster #I raster number
+
+short gim[GIM_SETRASTER_LEN]
+
+begin
+ gim[GIM_SETRASTER_RN] = raster
+ call gescape (gp, GIM_SETRASTER, gim, GIM_SETRASTER_LEN)
+end
diff --git a/sys/gio/gim/gimwcmap.x b/sys/gio/gim/gimwcmap.x
new file mode 100644
index 00000000..54a6d3f2
--- /dev/null
+++ b/sys/gio/gim/gimwcmap.x
@@ -0,0 +1,42 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <gio.h>
+include <gescape.h>
+
+# GIM_WRITECOLORMAP -- Write to a colormap.
+
+procedure gim_writecolormap (gp, colormap, first, nelem, r, g, b)
+
+pointer gp #I graphics descriptor
+int colormap #I colormap number (0=screen)
+int first #I first colormap entry to be written
+int nelem #I number of elements to write
+int r[ARB],g[ARB],b[ARB] #I RGB color values (0-255)
+
+int i
+pointer sp, cm, op
+short gim[GIM_WRITECMAP_LEN]
+errchk gpl_flush
+
+begin
+ call gpl_flush()
+
+ call smark (sp)
+ call salloc (cm, nelem * 3, TY_SHORT)
+
+ gim[GIM_WRITECMAP_MP] = colormap
+ gim[GIM_WRITECMAP_FC] = first
+ gim[GIM_WRITECMAP_NC] = nelem
+
+ do i = 1, nelem {
+ op = cm + (i - 1) * 3
+ Mems[op+0] = r[i]
+ Mems[op+1] = g[i]
+ Mems[op+2] = b[i]
+ }
+
+ call gki_wescape (GP_FD(gp), GIM_WRITECMAP,
+ gim, GIM_WRITECMAP_LEN, Mems[cm], nelem * 3)
+
+ call sfree (sp)
+end
diff --git a/sys/gio/gim/gimwiomap.x b/sys/gio/gim/gimwiomap.x
new file mode 100644
index 00000000..a756a235
--- /dev/null
+++ b/sys/gio/gim/gimwiomap.x
@@ -0,0 +1,37 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <gio.h>
+include <gescape.h>
+
+# GIM_IOMAPWRITE -- Write to the iomap. The iomap maps client pixel values
+# (colors) to gterm widget pixel value (widget colormap indices). The iomap
+# should be set only if the client application does not use the gterm widget
+# color model. iomap[i] gives the widget colormap index corresponding to
+# client pixel I.
+
+procedure gim_iomapwrite (gp, iomap, first, nelem)
+
+pointer gp #I graphics descriptor
+int iomap[ARB] #I iomap data
+int first #I first iomap entry to be written
+int nelem #I number of elements to write
+
+pointer sp, data
+short gim[GIM_WRITEIOMAP_LEN]
+errchk gpl_flush
+
+begin
+ call gpl_flush()
+
+ call smark (sp)
+ call salloc (data, nelem, TY_SHORT)
+
+ gim[GIM_WRITEIOMAP_FC] = first
+ gim[GIM_WRITEIOMAP_NC] = nelem
+
+ call achtis (iomap, Mems[data], nelem)
+ call gki_wescape (GP_FD(gp), GIM_WRITEIOMAP,
+ gim, GIM_WRITEIOMAP_LEN, Mems[data], nelem)
+
+ call sfree (sp)
+end
diff --git a/sys/gio/gim/gimwpix.x b/sys/gio/gim/gimwpix.x
new file mode 100644
index 00000000..fc55a55b
--- /dev/null
+++ b/sys/gio/gim/gimwpix.x
@@ -0,0 +1,47 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <mach.h>
+include <gio.h>
+include <gescape.h>
+
+# GIM_WRITEPIXELS -- Write to a rectangular region of a raster.
+
+procedure gim_writepixels (gp, raster, data, nbits, x1, y1, nx, ny)
+
+pointer gp #I graphics descriptor
+int raster #I raster number (0 is display window)
+short data[ARB] #I output pixel data
+int nbits #I nbits per raster pixel (1,8,16,32)
+int x1, y1 #I first pixel to be written
+int nx, ny #I size of region to be written
+
+int npix, nchars, nwords
+short gim[GIM_WRITEPIXELS_LEN]
+errchk gpl_flush, gpl_cache
+include "../gpl.com"
+
+begin
+ # Flush any buffered polyline output. Make sure the wcs transformation
+ # in the cache is up to date.
+
+ if (op > 1)
+ call gpl_flush()
+ else if (gp != gp_out || GP_WCS(gp) != wcs)
+ call gpl_cache (gp)
+
+ # Output the writepixels escape.
+ npix = nx * ny
+ nchars = (npix * nbits / NBITS_BYTE + SZB_CHAR-1) / SZB_CHAR
+ nwords = (nchars + SZ_SHORT-1) / SZ_SHORT
+
+ gim[GIM_WRITEPIXELS_RN] = raster
+ gim[GIM_WRITEPIXELS_EC] = 0
+ gim[GIM_WRITEPIXELS_X1] = x1
+ gim[GIM_WRITEPIXELS_Y1] = y1
+ gim[GIM_WRITEPIXELS_NX] = nx
+ gim[GIM_WRITEPIXELS_NY] = ny
+ gim[GIM_WRITEPIXELS_BP] = nbits
+
+ call gki_wescape (GP_FD(gp), GIM_WRITEPIXELS,
+ gim, GIM_WRITEPIXELS_LEN, data, nwords)
+end
diff --git a/sys/gio/gim/mkpkg b/sys/gio/gim/mkpkg
new file mode 100644
index 00000000..9aab719b
--- /dev/null
+++ b/sys/gio/gim/mkpkg
@@ -0,0 +1,32 @@
+# Make the GIM (graphics imaging) interface.
+
+$checkout libex.a lib$
+$update libex.a
+$checkin libex.a lib$
+$exit
+
+libex.a:
+ gimcpras.x <gescape.h> <gim.h> <gki.h>
+ gimcrras.x <gescape.h>
+ gimderas.x <gescape.h>
+ gimdsmap.x <gescape.h>
+ gimenmap.x <gescape.h>
+ gimfcmap.x <gescape.h>
+ gimfmap.x <gescape.h>
+ gimgetmap.x <fset.h> <gescape.h> <gim.h> <gio.h> <gki.h>
+ gimimap.x <gescape.h>
+ gimlcmap.x <gescape.h> <gim.h> <gki.h> <mach.h>
+ gimqras.x <fset.h> <gescape.h> <gio.h>
+ gimrasini.x <gescape.h>
+ gimrcmap.x <fset.h> <gescape.h> <gio.h>
+ gimref.x <gescape.h>
+ gimrefpix.x <gescape.h> <gim.h> <gki.h>
+ gimriomap.x <fset.h> <gescape.h> <gio.h>
+ gimrpix.x <fset.h> <gescape.h> <gio.h> <mach.h>
+ gimsetmap.x <gescape.h> <gim.h> <gio.h> <gki.h> ../gpl.com
+ gimsetpix.x <gescape.h> <gim.h> <gki.h>
+ gimsetras.x <gescape.h>
+ gimwcmap.x <gescape.h> <gio.h>
+ gimwiomap.x <gescape.h> <gio.h>
+ gimwpix.x <gescape.h> <gio.h> <mach.h> ../gpl.com
+ ;