mwherman@watcgl.UUCP (Michael W. Herman) (04/13/85)
[You may have seen a previous version of *append* that I posted yesterday. This is basically the same but moves the incrementing of *bitptr* out of the loop and also attempts to speed up the cases when *size* is greater than 1 - MWH] I folded *addbit* into *append*, added a few register variables and *append* is now running 3 times faster (4.2BSD on a 780). This makes *plot* run about 2 times faster. I have also changed *plot* to output versatec format raster files that *lpr -v* understands if anyone is interested (it's not very difficult.) My compliments to Simon Kenyon on what seems to be an excellent package (so far). -------------------------- cut here -------------------------------------- # This is a shell archive. Remove anything before this line, then # unpack it by saving it in a file and typing "sh file". (Files # unpacked will be owned by you and have default permissions.) # # This archive contains: # append.c echo x - append.c cat > "append.c" << '//E*O*F append.c//' /* * File: append.c * * Sccs-id: @(#)append.c 1.4 85/03/24 * * Description: This file contains the one function append which * adds some more bits to the end of the plot line. * * Author: Simon Kenyon. * * History: SCK 1.1 83/10/03 Created. * SCK 1.2 84/11/29 Made it work. * SCK 1.3 85/03/04 Tidied up for release. * SCK 1.4 85/03/24 Changed the include files around. * MWH 1.4 85/04/12 imbedded *addbit* code into *append* */ #include "../h/layers.h" /* * Name: append * * Description: Add some more bits to the end of the plot line. * * Synopsis: append (bits, start, end, size) * unsigned short bits; * int start; * int end; * int size; * * Called by: plot (plot.c) */ #ifdef MWH850412 static unsigned short wordmask[] = { 0x8000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0200, 0x0100, 0x0080, 0x0040, 0x0020, 0x0010, 0x0008, 0x0004, 0x0002, 0x0001 }; extern int bitptr; unsigned short line[512]; append (bits, start, end, size) register unsigned short bits; int start; int end; int size; { register int i; register int j; register int wordidx; register int bitidx; wordidx = bitptr / WORDSIZE; bitidx = bitptr % WORDSIZE; for (i = start; i <= end; i++) { if ( bits & (1 << (WORDSIZE - (i + 1))) ) { for (j = 0; j < size; j++) { /* replicate this bit *size* times */ line[wordidx] |= wordmask[bitidx]; bitidx++; if (bitidx == WORDSIZE) { bitidx = 0; wordidx++; } } } else { for (j = 0; j < size; j++) { /* replicate this bit *size* times */ line[wordidx] &= ~wordmask[bitidx]; bitidx++; if (bitidx == WORDSIZE) { bitidx = 0; wordidx++; } } } } bitptr += (end-start+1) * size; } #else /* original code */ append (bits, start, end, size) register unsigned short bits; int start; register int end; register int size; { register int i; register int j; for (i = start; i <= end; i++) for (j = 0; j < size; j++) if (bits & (1 << (WORDSIZE - (i + 1)))) addbit (1); else addbit (0); } #endif MWH850412 //E*O*F append.c// exit 0