Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 5/3/83; site ukc.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!mcvax!ukc!sk From: sk@ukc.UUCP (S.Kenyon) Newsgroups: net.sources Subject: jerq layers code (Part 4 of 4) Message-ID: <5040@ukc.UUCP> Date: Wed, 10-Apr-85 05:42:44 EST Article-I.D.: ukc.5040 Posted: Wed Apr 10 05:42:44 1985 Date-Received: Fri, 12-Apr-85 06:28:52 EST Organization: Computing Laboratory, U of Kent at Canterbury, UK Lines: 901 #!/bin/sh echo 'Start of jerq layers code, part 04 of 04:' echo 'x - man/jerq.5' sed 's/^X//' > man/jerq.5 << '/' X X.TH JERQ 5 85/03/28 "PR1ME Computer" X.SH NAME Xjerq \- jerq code data structures X.SH SYNOPSIS X.B #include "jerq/h/layers.h" X.SH DESCRIPTION XHere are the definitions of the data structures that are passed in and out Xof the layers routines. X.PP X.nf Xstruct Point { X int x; /* x and y coordinates of point */ X int y; X}; X Xstruct Rectangle { X struct Point origin; /* min x,y */ X struct Point corner; /* max x,y */ X}; X Xstruct Bitmap { X unsigned short *base; /* start of data */ X int width; /* width in words */ X struct Rectangle rect; /* image rectangle */ X struct Obscured *obs; /* linked list of obscured rectangles, X for compatability with Layer */ X struct Obscured *endobs; /* end of above linked list */ X}; X Xstruct Layer { X unsigned short *base; /* start of data */ X int width; /* width in words */ X struct Rectangle rect; /* image rectangle */ X struct Obscured *obs; /* linked list of obscured rectangles */ X struct Obscured *endobs; /* end of above linked list */ X struct Layer *front; /* adjacent layer in front */ X struct Layer *back; /* adjacent layer behind */ X}; X.fi X.SH SEE ALSO Xjerq(3X) X.SH AUTHOR XSimon Kenyon X.SH BUGS X.I XEndobs Xis not stricly necessary, Xbut it made coding a lot easier. / echo 'x - plot/addbit.c' sed 's/^X//' > plot/addbit.c << '/' X X/* X * File: addbit.c X * X * Sccs-id: @(#)addbit.c 1.5 85/03/24 X * X * Description: This file contains the one function addbit which X * adds a bit onto the end of the current plot line. X * X * Author: Simon Kenyon. X * X * History: SCK 1.1 83/10/03 Created. X * SCK 1.2 84/11/29 Made it work. X * SCK 1.3 85/03/04 Tidied up for release. X * SCK 1.4 85/03/22 Fixed up global variable declarations. X * SCK 1.5 85/03/24 Changed the include files around. X */ X X#include "../h/layers.h" X Xextern int bitptr; X Xunsigned short line[512]; Xunsigned short wordmask[] = { X 0x8000, 0x4000, 0x2000, 0x1000, X 0x0800, 0x0400, 0x0200, 0x0100, X 0x0080, 0x0040, 0x0020, 0x0010, X 0x0008, 0x0004, 0x0002, 0x0001 X}; X X/* X * Name: addbit X * X * Description: Add a bit onto the end of the current plot line. X * X * Synopsis: addbit (bit) X * int bit; X * X * Globals: bitptr (r/w) X * line (w) X * wordmask (r) X * X * Calls: Nothing. X * X * Called by: append (append.c) X */ Xaddbit (bit) Xint bit; /* 0 or 1 */ X{ X int wordidx; X int bitidx; X X wordidx = bitptr / WORDSIZE; X bitidx = bitptr % WORDSIZE; X if (bit) X line[wordidx] |= wordmask[bitidx]; X else X line[wordidx] &= ~wordmask[bitidx]; X bitptr++; X} / echo 'x - plot/append.c' sed 's/^X//' > plot/append.c << '/' X X/* X * File: append.c X * X * Sccs-id: @(#)append.c 1.4 85/03/24 X * X * Description: This file contains the one function append which X * adds some more bits to the end of the plot line. X * X * Author: Simon Kenyon. X * X * History: SCK 1.1 83/10/03 Created. X * SCK 1.2 84/11/29 Made it work. X * SCK 1.3 85/03/04 Tidied up for release. X * SCK 1.4 85/03/24 Changed the include files around. X */ X X#include "../h/layers.h" X X/* X * Name: append X * X * Description: Add some more bits to the end of the plot line. X * X * Synopsis: append (bits, start, end, size) X * unsigned short bits; X * int start; X * int end; X * int size; X * X * Globals: None. X * X * Calls: addbit (addbit.c) X * X * Called by: plot (plot.c) X */ Xappend (bits, start, end, size) Xunsigned short bits; Xint start; Xint end; Xint size; X{ X int i; X int j; X X for (i = start; i <= end; i++) X for (j = 0; j < size; j++) X if (bits & (1 << (WORDSIZE - (i + 1)))) X addbit (1); X else X addbit (0); X} / echo 'x - plot/outline.c' sed 's/^X//' > plot/outline.c << '/' X X/* X * File: outline.c X * X * Sccs-id: @(#)outline.c 1.4 85/03/24 X * X * Description: This file contains the one function outline which X * sends the next output line to the Printronix plotter. X * X * Author: Simon Kenyon. X * X * History: SCK 1.1 83/10/03 Created. X * SCK 1.2 84/11/29 Made it work. X * SCK 1.3 85/03/04 Tidied up for release. X * SCK 1.4 85/03/24 Changed the include files around. X */ X X#include X X#include "../h/layers.h" X Xextern int outptr; Xextern unsigned char outlin[]; X X/* X * Name: outline X * X * Description: Send the next output line to the Printronix plotter. X * X * Synopsis: outline () X * X * Globals: outptr (r) X * outlin (r) X * X * Calls: printf (libc) X * X * Called by: plot (plot.c) X */ Xoutline () X{ X int i; X X for (i = 0; i < (outptr / BYTESIZE); i++) X printf ("%c", outlin[i]); X printf ("\n"); X} / echo 'x - src/addpiece.c' sed 's/^X//' > src/addpiece.c << '/' X X/* X * File: addpiece.c X * X * Sccs-id: @(#)addpiece.c 1.4 85/03/24 X * X * Description: This file contains the one routine addpiece which X * adds to the obscured list the rectangles that are currently X * unobscured (i.e. that only have one layer), but that will X * be obscured by the new layer X * X * Author: Simon Kenyon. X * X * History: SCK 1.1 83/10/03 Created. X * SCK 1.2 84/11/29 Made it work. X * SCK 1.3 85/02/27 Tidied up for release. X * SCK 1.4 85/03/24 Changed the include files around. X */ X X#include "../h/layers.h" X X/* X * Name: addpiece X * X * Description: Add to the obscured list the rectangles that are currently X * unobscured (i.e. that only have one layer), but that will X * be obscured by the new layer X * X * Synopsis: addpiece (lp, r, bp, op, flp, p2, p3, p4) X * struct Layer *lp; X * struct Rectangle r; X * struct Bitmap *bp; X * struct Obscured *op; X * struct Layer *flp; X * int *p2; X * int *p3; X * int *p4; X * X * Globals: None. X * X * Calls: addrect (addrect.c) X * X * Called by: newlayer (newlayer.c) X */ Xaddpiece (lp, r, bp, op, flp, p2, p3, p4) Xstruct Layer *lp; Xstruct Rectangle r; Xstruct Bitmap *bp; Xstruct Obscured *op; Xstruct Layer *flp; Xint *p2; /* unused */ Xint *p3; /* unused */ Xint *p4; /* unused */ X{ X if (op == NULL) /* this piece is occupied by only one X layer */ X (void) addrect (r, flp); X /* X * otherwise it's already in obs list X */ X} / echo 'x - src/background.c' sed 's/^X//' > src/background.c << '/' X X/* X * File: background.c X * X * Sccs-id: @(#)background.c 1.4 85/03/24 X * X * Description: This file contains the one function background which X * paints rectangle rect of the display bitmap X * the background colour. X * X * Author: Simon Kenyon. X * X * History: SCK 1.1 83/10/03 Created. X * SCK 1.2 84/11/29 Made it work. X * SCK 1.3 85/03/04 Tidied up for release. X * SCK 1.4 85/03/24 Changed the include files around. X */ X X#include "../h/layers.h" X Xextern struct Bitmap *display; X Xunsigned short bght[] = { /* background halftone bitmap */ X 0x8888, 0x0000, 0x2222, 0x0000, X 0x8888, 0x0000, 0x2222, 0x0000, X 0x8888, 0x0000, 0x2222, 0x0000, X 0x8888, 0x0000, 0x2222, 0x0000 X}; Xstruct Bitmap back = { X bght, 1, {{ X 0, 0 X }, { X WORDSIZE, WORDSIZE X } X }, 0 X}; X X/* X * Name: background X * X * Description: Paint rectangle rect of the display bitmap X * the background colour. X * X * Synopsis: background (rect) X * struct Rectangle rect; X * X * Globals: display (r/w) X * back (r) X * X * Calls: bitblt (bitblt.c) X * X * Called by: dellayer (dellayer.c) X */ Xbackground (rect) Xstruct Rectangle rect; X{ X (void) bitblt (NULL, rect, display, rect.origin, &back, S); X} / echo 'x - src/bfree.c' sed 's/^X//' > src/bfree.c << '/' X X/* X * File: bfree.c X * X * Sccs-id: @(#)bfree.c 1.4 85/03/24 X * X * Description: This file contains the one routine bfree which X * frees the storage used by bitmap b. X * X * Author: Simon Kenyon. X * X * History: SCK 1.1 83/10/03 Created. X * SCK 1.2 84/11/29 Made it work. X * SCK 1.3 85/03/04 Tidied up for release. X * SCK 1.4 85/03/24 Changed the include files around. X */ X X#include "../h/layers.h" X X/* X * Name: bfree X * X * Description: Free the storage used by bitmap b. X * X * Synopsis: bfree (b) X * struct Bitmap *b; X * X * Globals: None. X * X * Calls: free (libc) X * X * Called by: newlayer (newlayer.c) X * dellayer (dellayer.c) X */ Xbfree (b) Xstruct Bitmap *b; X{ X /* X * return storage for bitmap b from whence it came X */ X free ((char *) b -> base); X free ((char *) b); X} / echo 'x - src/intersection.c' sed 's/^X//' > src/intersection.c << '/' X X/* X * File: intersection.c X * X * Sccs-id: @(#)intersection.c 1.5 85/03/24 X * X * Description: This file contains the one function intersect which X * calculates the intersection of the two rectangles r and s. X * X * Author: Simon Kenyon. X * X * History: SCK 1.1 83/10/03 Created. X * SCK 1.2 84/11/29 Made it work. X * SCK 1.3 85/03/04 Tidied up for release. X * SCK 1.4 85/03/22 Moved min and max definitions X * from defines.h to here. X * SCK 1.5 85/03/24 Changed the include files around. X */ X X#include "../h/layers.h" X X#define min(a, b) ((a) < (b) ? (a) : (b)) X#define max(a, b) ((a) > (b) ? (a) : (b)) X X/* X * Name: intersection X * X * Description: Calculate the intersection of the two rectangles r and s. X * X * Synopsis: struct Rectangle intersection (r, s) X * struct Rectangle r; X * struct Rectangle s; X * X * Globals: None. X * X * Calls: Nothing. X * X * Called by: layerop (layerop.c) X */ Xstruct Rectangle intersection (r, s) Xstruct Rectangle r; Xstruct Rectangle s; X{ X struct Rectangle t; X X t.origin.x = max (r.origin.x, s.origin.x); X t.origin.y = max (r.origin.y, s.origin.y); X t.corner.x = min (r.corner.x, s.corner.x); X t.corner.y = min (r.corner.y, s.corner.y); X return (t); X} / echo 'x - src/lbblt.c' sed 's/^X//' > src/lbblt.c << '/' X X/* X * File: lbblt.c X * X * Sccs-id: @(#)lbblt.c 1.4 85/03/24 X * X * Description: This file contains the one function LBblt which X * given a layer l, a rectangle r, a bitmap db, a bitmap sb, X * a function code f and an obscured list o, bitblts using X * the function code f, the rectangular area r from sb into db. X * X * Author: Simon Kenyon. X * X * History: SCK 1.1 83/10/03 Created. X * SCK 1.2 84/12/10 Made it work. X * SCK 1.3 85/02/22 Tidied up for release. X * SCK 1.4 85/03/24 Changed the include files around. X */ X X#include "../h/layers.h" X X/* X * Name: LBblt X * X * Description: Given a layer l, a rectangle r, a bitmap db, a bitmap sb, X * a function code f and an obscured list o, bitblt using X * the function code f, the rectangular area r from sb into db. X * X * Synopsis: LBblt (l, r, db, o, sb, hb, dp, f) X * struct Layer *l; X * struct Rectangle r; X * struct Bitmap *db; X * struct Obscured *o; X * struct Bitmap *sb; X * struct Bitmap *hb; X * struct Point *dp; X * int *f; X * X * Globals: None. X * X * Calls: rsubp (rsubp.c) X * bitblt (bitblt.c) X * X * Called by: Rlayerop (rlayerop.c) X */ XLBblt (l, r, db, o, sb, hb, dp, f) Xstruct Layer *l; Xstruct Rectangle r; Xstruct Bitmap *db; /* destination bitmap */ Xstruct Obscured *o; Xstruct Bitmap *sb; /* source bitmap */ Xstruct Bitmap *hb; /* halftone bitmap */ Xstruct Point *dp; Xint *f; /* function code */ X{ X struct Rectangle rsubp (); X X (void) bitblt (sb, rsubp (r, *dp), db, r.origin, hb, *f); X} / echo 'x - src/lblt.c' sed 's/^X//' > src/lblt.c << '/' X X/* X * File: lblt.c X * X * Sccs-id: @(#)lblt.c 1.4 85/03/24 X * X * Description: This file contains the one function lblt, which X * provides the bitblt function between and off-screen X * bitmap and a layer. X * X * Author: Simon Kenyon. X * X * History: SCK 1.1 83/10/03 Created. X * SCK 1.2 84/11/29 Made it work. X * SCK 1.3 85/03/04 Tidied up for release. X * SCK 1.4 85/03/24 Changed the include files around. X */ X X#include "../h/layers.h" X X/* X * Name: lblt X * X * Description: Given a layer l, a bitmap sb, a rectangle r X * and a function code f, copy the off-screen bitmap sb X * to a rectangle r within layer l, using the function code f. X * X * Synopsis: lblt (l, sb, r, hb, pt, f) X * struct Layer *l; X * struct Bitmap *sb; X * struct Rectangle r; X * struct Bitmap *hb; X * struct Point pt; X * int f; X * X * Globals: LBblt () X * X * Calls: layerop (layerop.c) X * raddp (raddp.c) X * X * Called by: This is a top-level function. X * lbitblt (lbitblt.c) X */ Xlblt (l, sb, r, hb, pt, f) Xstruct Layer *l; Xstruct Bitmap *sb; Xstruct Rectangle r; Xstruct Bitmap *hb; Xstruct Point pt; Xint f; X{ X struct Point dp; X X int LBblt (); X struct Rectangle raddp (); X X dp.x = pt.x - r.origin.x; X dp.y = pt.y - r.origin.y; X (void) layerop (l, LBblt, raddp (r, dp), sb, hb, &dp, &f); X} / echo 'x - src/lessthan.c' sed 's/^X//' > src/lessthan.c << '/' X X/* X * File: lessthan.c X * X * Sccs-id: @(#)lessthan.c 1.4 85/03/24 X * X * Description: This file contains the one routine lessthan which X * defines an ordering on the rectangles a and b, X * so that bitblt will be called by lbitblt X * in the correct order. X * X * Author: Simon Kenyon. X * X * History: SCK 1.1 83/10/03 Created. X * SCK 1.2 84/11/29 Made it work. X * SCK 1.3 85/03/04 Tidied up for release. X * SCK 1.4 85/03/24 Changed the include files around. X */ X X#include "../h/layers.h" X Xextern struct Point delta; X X/* X * Name: lessthan X * X * Description: Define an ordering on the rectangles a and b, X * so that bitblt will be called by lbitblt X * in the correct order. X * X * Synopsis: boolean lessthan (a, b) X * struct Rectangle a; X * struct Rectangle b; X * X * Globals: delta (r) X * X * Calls: Nothing. X * X * Called by: Pass (pass.c) X */ Xboolean lessthan (a, b) Xstruct Rectangle a; Xstruct Rectangle b; X{ X if ((a.origin.y < b.corner.y) && (b.origin.y < a.corner.y)) X return (((a.origin.x - b.origin.x) * delta.x) >= 0); X else X return (((a.origin.y - b.origin.y) * delta.y) >= 0); X} / echo 'x - src/raddp.c' sed 's/^X//' > src/raddp.c << '/' X X/* X * File: raddp.c X * X * Sccs-id: @(#)raddp.c 1.4 85/03/24 X * X * Description: This file contains the one function raddp which X * given a point p and a rectangle r, adds the point X * to the origin of the rectangle. X * X * Author: Simon Kenyon. X * X * History: SCK 1.1 83/10/03 Created. X * SCK 1.2 84/11/29 Made it work. X * SCK 1.3 85/03/04 Tidied up for release. X * SCK 1.4 85/03/24 Changed the include files around. X */ X X#include "../h/layers.h" X X/* X * Name: raddp X * X * Description: Given a point p and a rectangle r, add the point X * to the origin of the rectangle. X * X * Synopsis: struct Rectangle raddp (r, p) X * struct Rectangle r; X * struct Point p; X * X * Globals: None. X * X * Calls: Nothing. X * X * Called by: lblt (lblt.c) X */ Xstruct Rectangle raddp (r, p) Xstruct Rectangle r; Xstruct Point p; X{ X /* X * add p to r X */ X r.origin.x += p.x; X r.origin.y += p.y; X r.corner.x += p.x; X r.corner.y += p.y; X return (r); X} / echo 'x - src/rectf.c' sed 's/^X//' > src/rectf.c << '/' X X/* X * File: rectf.c X * X * Sccs-id: @(#)rectf.c 1.5 85/03/24 X * X * Description: This file contains the one function rectf which X * performs the function specified by integer code f, X * in a rectangle r, in a bitmap b. X * X * Author: Simon Kenyon. X * X * History: SCK 1.1 83/10/03 Created. X * SCK 1.2 84/11/29 Made it work. X * SCK 1.3 85/03/04 Tidied up for release. X * SCK 1.4 85/03/21 Added STORE after reading X * Rob's latest paper. X * SCK 1.5 85/03/24 Changed the include files around. X */ X X#include "../h/layers.h" X X/* X * Name: rectf X * X * Description: Perform the function specified by integer code f, X * in a rectangle r, in a bitmap b. X * X * Synopsis: rectf (b, r, f) X * struct Bitmap *b; X * struct Rectangle r; X * int f; X * X * Globals: None. X * X * Calls: bitblt (bitblt.c) X * X * Called by: newlayer (newlayer.c) X */ Xrectf (b, r, f) Xstruct Bitmap *b; Xstruct Rectangle r; Xint f; X{ X switch (f) { X case CLR: X /* X * clear r to zeros X */ X (void) bitblt (NULL, r, b, r.origin, NULL, ALL_ZEROS); X break; X case OR: X case STORE: X /* X * set r to ones X */ X (void) bitblt (NULL, r, b, r.origin, NULL, ALL_ONES); X break; X case XOR: X /* X * invert bits in r X */ X (void) bitblt (NULL, r, b, r.origin, NULL, ND); X break; X } X} / echo 'x - src/rectxrect.c' sed 's/^X//' > src/rectxrect.c << '/' X X/* X * File: rectxrect.c X * X * Sccs-id: @(#)rectxrect.c 1.4 85/03/24 X * X * Description: This file contains the one function rectXrect which X * tests to see if the two rectangles r and s intersect. X * X * Author: Simon Kenyon. X * X * History: SCK 1.1 83/10/03 Created. X * SCK 1.2 84/11/29 Made it work. X * SCK 1.3 85/03/04 Tidied up for release. X * SCK 1.4 85/03/24 Changed the include files around. X */ X X#include "../h/layers.h" X X/* X * Name: rectXrect X * X * Description: Test to see if the two rectangles r and s intersect. X * X * Synopsis: boolean rectXrect (r, s) X * struct Rectangle r; X * struct Rectangle s; X * X * Globals: None. X * X * Calls: Nothing. X * X * Called by: newlayer (newlayer.c) X * addobs (addobs.c) X * layerop (layerop.c) X * Rlayerop (Rlayerop.c) X * upfront (upfront.c) X */ Xboolean rectXrect (r, s) Xstruct Rectangle r; Xstruct Rectangle s; X{ X return ((r.origin.x < s.corner.x) && X (s.origin.x < r.corner.x) && X (r.origin.y < s.corner.y) && X (s.origin.y < r.corner.y)); X} / echo 'x - src/rsubp.c' sed 's/^X//' > src/rsubp.c << '/' X X/* X * File: rsubp.c X * X * Sccs-id: @(#)rsubp.c 1.4 85/03/24 X * X * Description: This file contains the one function rsubp which X * given a point p and a rectangle r, subtracts the point X * from the origin of the rectangle. X * X * Author: Simon Kenyon. X * X * History: SCK 1.1 83/10/03 Created. X * SCK 1.2 84/11/29 Made it work. X * SCK 1.3 85/03/04 Tidied up for release. X * SCK 1.4 85/03/24 Changed the include files around. X */ X X#include "../h/layers.h" X X/* X * Name: rsubp X * X * Description: Given a point p and a rectangle r, subtract the point X * from the origin of the rectangle. X * X * Synopsis: struct Rectangle rsubp (r, p) X * struct Rectangle r; X * struct Point p; X * X * Globals: None. X * X * Calls: Nothing. X * X * Called by: LBblt (lbblt.c) X */ Xstruct Rectangle rsubp (r, p) Xstruct Rectangle r; Xstruct Point p; X{ X /* X * subtract p from r X */ X r.origin.x -= p.x; X r.origin.y -= p.y; X r.corner.x -= p.x; X r.corner.y -= p.y; X return (r); X} / echo 'x - src/screenswap.c' sed 's/^X//' > src/screenswap.c << '/' X X/* X * File: screenswap.c X * X * Sccs-id: @(#)screenswap.c 1.4 85/03/24 X * X * Description: This file contains the one function screenswap which X * interchanges the data in the bitmap b with the contents X * of the rectangle r on the screen. X * X * Author: Simon Kenyon. X * X * History: SCK 1.1 83/10/03 Created. X * SCK 1.2 84/11/29 Made it work. X * SCK 1.3 85/03/04 Tidied up for release. X * SCK 1.4 85/03/24 Changed the include files around. X */ X X#include "../h/layers.h" X Xextern struct Bitmap *display; X X/* X * Name: screenswap X * X * Description: Interchange the data in the bitmap b with the contents X * of the rectangle r on the screen. X * X * Synopsis: screenswap (b, r) X * struct Bitmap *b; X * struct Rectangle r; X * X * Globals: display (r/w) X * X * Calls: bitblt (bitblt.c) X * X * Called by: upfront (upfront.c) X */ Xscreenswap (b, r) Xstruct Bitmap *b; Xstruct Rectangle r; X{ X /* X * implemented, without auxialiary storage, using three X * calls to bitblt() with function code XOR X */ X (void) bitblt (display, r, b, r.origin, NULL, S_XOR_D); X (void) bitblt (b, r, display, r.origin, NULL, S_XOR_D); X (void) bitblt (display, r, b, r.origin, NULL, S_XOR_D); X} / echo 'Part 04 of jerq layers code complete.' exit