jimomura@lsuc.uucp (Jim Omura) (05/16/89)
# This is a shell archive. # Remove everything above and including the cut line. # Then run the rest of the file through sh. #----cut here-----cut here-----cut here-----cut here----# #!/bin/sh # shar: Shell Archiver # Run the following text with /bin/sh to create: # iex.c # ilonghelp.c # imenu.c # isetpath.c # iterm.c # iwposk.mk # iwprint.h # iwpdist.c # iwpgrey.c # iwprint.c # This archive created: # By: Jim Omura () cat << \SHAR_EOF > iex.c /* Iex.c */ /* Version 0.3 Public Domain * 1987/11/13 * This version for OS-9 6809 or OS-9 68K */ /* by Jim Omura, 2A King George's Drive, * Toronto, Ontario, M6M 2G9, Canada * * Expand an Imagewise run-length encoded file to full size * for further processing. Full Size = 62,710 */ #include <stdio.h> #include <modes.h> #define STDIN 0 #define STDOUT 1 #define STDERR 2 #define FALSE 0 #define TRUE 1 #define ERROR -1 /* Program Specific Definitions */ #define ENDFLD 0x42 /* End of Video Field */ #define BIGREP 0x90 /* Repeat 16*n times */ #define SMLREP 0x80 /* Repeat n times */ int expcntr; /* Expansion Counter */ char hbuf[1]; /* Hold Buffer */ main(argc,argv) int argc; char **argv; { char cbuf[1]; /* Character buffer */ register unsigned cval; /* value of a character */ int exitflag; /* Exit Flag */ int inpath; /* Input File pointer */ int outpath; /* Output File pointer */ int result; /* Results of functions */ /* Set Defaults: */ inpath = STDIN; outpath = STDOUT; for(;argc > 1;--argc) { ++argv; /* Point to next argument */ if(**argv=='-') { for(;;) { ++*argv; /* Point to next character */ switch((int)**argv) { case '\n': break; case '?': shorthelp(); exit(0); default: continue; } /* Endswitch */ break; } /* Endloop */ continue; /* Next argv */ } /* Endif */ if(inpath==STDIN) { inpath=(open(*argv,S_IREAD)); if (inpath == ERROR) { printf("\nIex: Bad input filename.\n"); exit(errno); } continue; /* Next Arg */ } /* Endif */ if(outpath==STDOUT) { outpath=(creat(*argv,S_IREAD | S_IWRITE)); if (outpath == ERROR) { printf("\nIex: Bad output filename.\n"); exit(errno); } continue; /* Next Arg */ } /* Endif */ } /* Endloop */ expcntr=0; exitflag=FALSE; for(;;) { /* Process a Character */ /* Get a Character */ result=read(inpath,cbuf,1); if (result == ERROR) { printf("\nIex: Read error"); exit(errno); } if (result == 0) { /* If end of file, close & exit (error) */ exitflag=TRUE; } if (exitflag == FALSE) { cval = ((unsigned) *cbuf); /* The 'unsigned' cast doesn't work */ cval = cval & 0xff; /* Correct for Bug */ if (cval > (BIGREP - 1)) { /* big expand */ expcntr=((cval & 0x0f) * 16); if (expcntr == 0) { expcntr=256; } expand(outpath); continue; } /* Endif Big Repeat */ if (cval > (SMLREP - 1)) { /* small expand */ expcntr=(cval & 0x0f); if (expcntr == 0) { expcntr=16; } expand(outpath); continue; } /* Endif Small Repeat */ /* if Not a Repeat loop then write Char. */ write(outpath,cbuf,1); } /* Endif not endflag */ if (*cbuf < 0x40) /* Cannot consolidate because ... */ { /* Don't know if expansion across ... */ *hbuf=*cbuf; /* End of Line Char. is allowed. */ } /* Endif */ if (*cbuf == ENDFLD) { (exitflag=TRUE); } if (exitflag) { /* Close Files and Exit */ exit(0); } } /* End Character Process loop */ exit(0); } /* End of main */ /* ---------------------------------------- */ int expand(outpath) int outpath; { extern int expcntr; /* Repetitions */ extern char hbuf[1]; /* Char. */ for(; (expcntr > 0) ; --expcntr) { write(outpath,hbuf,1); } } /* End of expand() */ /* --------------------------------------- */ /* shorthelp() */ shorthelp() { fprintf(stderr,"Iex: Expand imagewise file\n"); fprintf(stderr,"Usage: iex [-?] [infile] [outfile]\n"); } /* End of shorthelp() */ /* End Iex.c */ SHAR_EOF cat << \SHAR_EOF > ilonghelp.c /* ilonghelp.c */ /* OS-9 6809 ImageWise Framegrabber support module * 1987/10/21 */ /* By Jim Omura * 2A King George's Drive * Toronto, Ontario, Canada */ #include "icap.h" /* longhelp() * * receives no parameters and returns no parameters */ longhelp() { char mchoice[2]; /* Long Help Choice */ int report; char *selmess; /* Selection message */ selmess="\nChoice: "; for(;;) { printf("\nIcap Help Menu:\n"); printf("\n 0. Shell and return\n"); printf(" 1. Set File Name\n"); printf(" 2. Set Number of files\n"); printf(" 3. Ready to begin capture\n"); printf(" 4. Terminal Mode\n"); printf(" 5. Shell & Capture\n"); printf(" 6. Verbose Toggle\n"); printf(" 7. Exiting Icap\n"); printf(" g. General comments\n"); printf("\n r. Return to Main Menu\n"); printf("\n"); write(STDOUT,selmess,9); fgets(mchoice,1,stdin); switch((int) *mchoice) { case '0': printf("Passes a system call to a shell and returns\n"); printf("to the main menu.\n"); continue; case '1': printf("Enter a new output filename.\n"); printf("If multiple files, then use '00' for last chars.\n"); continue; case '2': printf("Number of files for multiple file capture."); printf("If not specified then only one file."); continue; case '3': printf("Starts the capture.\n"); printf("Returns to Main Menu when done.\n"); printf("Must specify Filename before capture.\n"); printf("If no filename specified, then defaults to\n"); printf("Standard output.\n"); printf("Closes capture file if successful and sets\n"); printf("output to standard output. If multiple files\n"); printf("the next file is started immediately.\n"); printf("Does not close capture file if aborted!\n"); continue; case '4': printf("Terminal mode. Simple telecommunications\n"); printf("to setup a remote Imagewise connection.\n"); printf("Also to clear input prior to start.\n"); continue; case '5': printf("Forks a shell, but upon exiting the new shell\n"); printf("begins to capture the current screen. This\n"); printf("should make it possible to integrate 'icap'\n"); printf("with your favorite draw or paint program.\n"); printf("\n Verbose mode should be OFF.\n"); continue; case '6': printf("Toggles verbose mode\n"); continue; case '7': printf("Icap Closes all files on exit.\n"); continue; case 'g': printf("Flow control (Xon/Xoff) is not turned off by this\n"); printf("program. Be sure to do so with Xmode or the file\n"); printf("will not be complete.\n"); printf("\n The program is designed and tested for 1200\n"); printf("baud capture to RAM Disk and may not work at\n"); printf("higher speeds or writing to other devices.\n"); continue; case 'r': break; default: } /* Endswitch */ break; } /* Endloop */ } /* End of longhelp() */ /* End of ilonghelp.c */ SHAR_EOF cat << \SHAR_EOF > imenu.c /* imenu.c */ /* Part of Icap6809 OS-9 6809 ImageWise Framegrabber support module * Last Modified 1987/10/27 */ /* By Jim Omura * 2A King George's Drive * Toronto, Ontario, Canada */ #include "icap.h" /* Program Specific Constants */ /* Declare Globals */ /* menu() * * Receives 'inpath' and 'outpath' * Returns no parameters * uses globals: 'pathname' */ menu(inpath,outpath) int inpath; int outpath; { char combuff[80]; /* Command buffer--can't>80! */ extern int files; char *freqmess; /* File request message */ char mchoice[2]; /* Menu Choice */ char *nflsmess; /* Number of files message */ extern char pathname[80]; int report; char *selmess; /* Selection message */ char *shellmess; /* Shell command prompt */ extern int verbose; /* Set String Constants */ freqmess="Input new filename: "; nflsmess="Input Number of files: "; /* 23 chars. */ selmess="Choice: "; shellmess="$:"; /* 2 chars. */ for(;;) { printf("\nIcap Menu:\n"); printf("\n ? Help\n"); printf(" 0. Shell & return to menu\n"); printf(" 1. Set File Name\n"); printf(" 2. Set Number of files\n"); printf(" 3. Begin capture\n"); printf(" 4. Terminal Mode\n"); printf(" 5. Shell and Capture\n"); printf(" 6. Verbose toggle\n"); printf(" 7. Exit\n"); printf("\n"); write(STDOUT,selmess,8); fgets(mchoice,2,stdin); switch((int) *mchoice) { case '?': longhelp(); /* see 'ilonghelp.c' */ continue; case '0': write(STDOUT,shellmess,2); readln(STDIN,combuff,80); system(combuff); continue; case '1': /* Get New Filename */ if(outpath != STDOUT) { close(outpath); outpath = STDOUT; } write(STDOUT,freqmess,20); readln(STDIN,pathname,80); if(*pathname == 0) { printf("No path entered.\n"); } else { outpath=creat(pathname,S_IWRITE); if (outpath == ERROR) { fprintf(stderr,"Output file error\n"); } } continue; case '2': write(STDOUT,nflsmess,23); readln(STDIN,combuff,3); files = atoi(combuff); continue; case '3': if(verbose) { fprintf(stderr,"Starting Capture. ^J to abort.\n"); } report=capture(inpath,outpath); if(report == TRUE) { printf("File captured\n"); close(outpath); outpath = STDOUT; } else { printf("Capture aborted. File still open.\n"); } continue; case '4': term(inpath); continue; case '5': write(STDOUT,shellmess,2); readln(STDIN,combuff,80); system(combuff); report=capture(inpath,outpath); if(report == TRUE) { printf("File captured\n"); close(outpath); outpath = STDOUT; } else { printf("Capture aborted. File still open.\n"); } continue; case '6': printf("Verbose flag now = "); if (verbose) { verbose = FALSE; printf("false\n"); } else { verbose = TRUE; printf("true\n"); } continue; case '7': exit(0); default: } /* Endswitch */ } /* Endloop */ } /* End of menu() */ /* End of imenu.c */ SHAR_EOF cat << \SHAR_EOF > isetpath.c /* isetpath.c */ /* OS-9 6809 ImageWise Framegrabber support module */ /* By Jim Omura * 2A King George's Drive * Toronto, Ontario, Canada */ #include "icap.h" #include <sgstat.h> #define SS_OPT 0 /* Program Specific Constants */ /* setinpath() * * Sets input path to not treat any characters specially. * Some settings may not be necessary. Note that Xon * and Xoff must be cleared before running icap. */ setinpath(inpath) int inpath; { static struct sgbuf sgstats; getstat(SS_OPT,inpath,&sgstats); /* Get Old settings */ sgstats.sg_backsp=0; sgstats.sg_delete=0; sgstats.sg_echo =0; sgstats.sg_alf =0; sgstats.sg_nulls =0; sgstats.sg_pause =0; /* No pause eo page */ sgstats.sg_bspch =0; /* Back sp. char */ sgstats.sg_dlnch =0; /* Del Line char */ sgstats.sg_eorch =0; sgstats.sg_eofch =0; sgstats.sg_rlnch =0; /* Repeat line char */ sgstats.sg_dulnch=0; /* Duplicate line char */ sgstats.sg_psch =0; /* Pause char */ sgstats.sg_kbich=0; sgstats.sg_kbach=0; sgstats.sg_bsech =0; /* Backspace Echo ch. */ sgstats.sg_bellch=0; /* sgstats.sg_xon=0; /* Not in OS-9 6809 */ /* sgstats.sg_xoff=0; /* Not in OS-9 6809 */ setstat(SS_OPT,inpath,&sgstats); } /* End of setinpath() */ /* End of isetpath.c */ SHAR_EOF cat << \SHAR_EOF > iterm.c /* iterm.c */ /* OS-9 6809 ImageWise Framegrabber support module */ /* By Jim Omura * 2A King George's Drive * Toronto, Ontario, Canada */ #include "icap.h" #define SS_RDY 1 /* Program Specific Constants */ #define BUFFSIZE 1 #define LESC 0x0a /* Local escape ^J */ /* Declare Globals */ /* term() * * This is a simple terminal to call up a Remote * framegrabber. */ term(mpath) int mpath; { char buffer[BUFFSIZE]; int bufpntr; int report; printf("Terminal Emulator -- ^J to exit\n"); for(;;) { report = getstat(SS_RDY,STDIN); #ifdef DEBUG /* fprintf(stderr,"getstat %4d\n",report); /* Testline */ #endif if (report > -1) { report = read(STDIN,buffer,BUFFSIZE); for(bufpntr=0;bufpntr < report; ++bufpntr) { if (buffer[bufpntr] == LESC) { return; } } write(mpath,buffer,report); } /* Endif Keyboard Input */ report = getstat(SS_RDY,mpath); if (report > -1) { report = read(mpath,buffer,BUFFSIZE); write(STDOUT,buffer,report); } /* Endif Modem Input */ } /* Endloop Terminal */ } /* End of term() */ /* End of iterm.c */ SHAR_EOF cat << \SHAR_EOF > iwposk.mk * Make iwprint.c * Reserved Macros: ODIR = /dd/usr/bin RDIR = RELS CFLAGS = -dDEBUG -r=$(RDIR) -t=/r0 * User Macros: CFILES = iwprint.c iwpdist.c iwpgrey.c RFILES = iwprint.r iwpdist.r iwpgrey.r HFILES = iwprint.h /dd/defs/stdio.h iwprint: $(RFILES) cc RELS/iwprint.r RELS/iwpdist.r RELS/iwpgrey.r\ -f=/dd/usr/bin/iwprint $(RFILES): $(HFILES) cc $*.c $(CFLAGS) SHAR_EOF cat << \SHAR_EOF > iwprint.h /* Iwprint. * 87/10/25 * by Jim Omura, 2A King George's Drive * Toronto, Ontario, Canada */ #include <stdio.h> #define ESC 0x1b #define ERROR -1 #define FALSE 0 #define STDIN 0 #define STDOUT 1 #define STDERR 2 #define TRUE 1 /* Program Specific definitions: --------------- */ /* Picture Type Codes */ #define STPIC 0 #define IWPIC 1 /* Bytes in one input file */ #define IWFLEN 62710 /* ImageWise File */ #define STFLEN 32000 /* ST File Len */ /* Bytes to be processed for 1 printer line */ #define STPRCBTS 960 /* ST file = 160 * 6 pixel rows */ #define IWPRCBTS 1536 /* Imagewise = 256 * 6 pixel rows */ /* Words picture line = PROCBYTES / 2. */ #define PROCWRDS 480 /* Printer row length in bytes */ #define PRTRWLN 5120 /* Imagewise = 256 * 5 * 4 */ /* #define PRTRWLN 5120 /* ST = 320 * 4 * 4 */ /* End of iwprint.h */ SHAR_EOF cat << \SHAR_EOF > iwpdist.c /* Iwpdist.c * 87/10/16 * by Jim Omura, 2A King George's Drive * Toronto, Ontario, Canada */ #include "iwprint.h" /* --------------------------------------------- */ /* distribute() * * Rearrange the Pixel bitmap into a 4 * 4 square. */ distribute(bitrow,byterow,pixcol) int bitrow; int byterow; int pixcol; { int xcntr; /* Inner loop counter X axis */ int offset; extern char outbuff[PRTRWLN]; int ycntr; /* Outer loop counter Y axis */ extern unsigned long pixel; extern int pixwidth; for(ycntr = 0 ; ycntr < 4 ; ++ycntr) { for(xcntr = 0 ; xcntr < pixwidth ; ++xcntr) { offset = (20 * pixcol) + (xcntr * 4) + byterow; outbuff[offset] = outbuff[offset] << 1; if( pixel & 1) /* If 0 bit is set */ { ++outbuff[offset]; } /* endif */ pixel = pixel >> 1; } /* Endloop Makerow */ ++bitrow; if (bitrow > 5) { bitrow = 0; ++byterow; } /* Endif Inc. ByteRow */ } /* Endloop Make Pixel */ } /* End of distribute() */ /* End of iwpdist.c */ SHAR_EOF cat << \SHAR_EOF > iwpgrey.c /* Iwpgrey.c * 87/10/26 * by Jim Omura, 2A King George's Drive * Toronto, Ontario, Canada */ #include "iwprint.h" /* ------------------------------------------------ */ assigngrey(bright,contrast,negimage) int bright; int contrast; int negimage; { extern int verbose; extern unsigned int greyscale[64]; int greyval; int outcntr; for (outcntr = 0 ; outcntr < 64 ; ++outcntr) { greyval = outcntr + bright; greyval = (greyval * 20 * contrast) / 6300; /* Rescale Grey value */ if (greyval > 20) { greyval = 20; } else { if (greyval < 0) { greyval = 0; } } /* Endif Limits correction */ if (negimage == FALSE) { greyval = 20 - greyval; /* Invert greyvalue */ } /* Endif */ greyscale[outcntr] = greyval; /* Store Greyvalue in table. */ } /* Endloop Get grey scale table */ if (verbose) { for (outcntr = 0 ; outcntr < 64 ; ++outcntr) { fprintf(stderr,"%6d %3d",outcntr,greyscale[outcntr]); if (1 + outcntr == (int) (4 * ((1 + outcntr) / 4)) ) { fprintf(stderr,"\n"); } /* Endif */ } /* Endloop Print Grey Table */ } /* Endif Verbose -- Grey Scale Vals */ } /* End of assigngrey() */ /* End of iwpgrey.c */ SHAR_EOF cat << \SHAR_EOF > iwprint.c /* Iwprint.c * 87/10/26 * by Jim Omura, 2A King George's Drive * Toronto, Ontario, Canada */ /* Dumps an Imagewise picture to a Toshiba P-321, or compatible * printer. Not integrated with 'picprt'. The problems of * printing a digitizer's file are too different to combine * with a regular picture. You end up with too many * conditionals. It would run too slow. * * Usage: * * iwprint [-?fnv] [infile] [outfile] [-b=nn] [-c=nnn] * * ? = Short Help * b = Brightness (+/- dots per pixel) * c = Contrast (nnn%) * f = Fast (no dither) * n = Negative Image * v = Verbose */ /* The problem of dealing with short lines is addressed by using * the start of line character to trigger a new line of pixels * regardless of where it occurs in the picture and printing * it regardless. No attempt is made to synthesize a corrected * line. */ #include "iwprint.h" #include <time.h> #define FENDCHAR 0x42 /* Field End Char. */ #define FSTCHAR 0x40 /* Field Start Char. */ #define LNSTCHAR 0x41 /* Line Start Char. */ /* Declare Global Variables: ------------------- */ unsigned char inbuff[IWPRCBTS]; /* Input in Bytes */ int inbufpntr; /* Points to current block */ unsigned int greyscale[64]; /* Greyscale conv. table */ char outbuff[PRTRWLN]; /* Holds 1 graphics line */ unsigned long pixel; /* Used to convert nibbles */ int pixwidth; /* Pixel width in dots */ int verbose; /* main()--------------------------------------- */ main(argc,argv) int argc; char **argv; { int bitrow; /* Current Row pointer */ int bright; /* Brightness correction */ int byterow; /* Byte offset pointer */ int bytes; /* Number of Bytes processed */ int contrast; /* Contrast scaler */ int ditherflag; /* Ditherize flag */ register int greyval; /* Greyscale value */ int incntr; /* Input counter */ int inpath; /* Input file path */ char *lnend; /* Line terminator string */ char lheader[7]; /* Line Header */ int negimage; /* Negative image */ int newlnflag; /* 2 cases for end of line */ int outcntr; /* Outer loop counter */ int outpath; /* Output file path */ int pixcol; /* Pixel Column pointer */ int procbytes; /* Bytes to process in 1 line */ char *prtinit; /* Printer initialization */ register int report; /* Return value from functions */ char *toshln1; lnend = "\r\l"; /* Line terminator constant */ prtinit = "L07\0"; /* 7 lines per inch */ toshln1=";1280\0"; /* Columns = 256 * 5 */ /* Initialize Variables */ bright = 0; contrast = 100; ditherflag = TRUE; greyval = 0; inpath = STDIN; outpath = STDOUT; negimage = FALSE; newlnflag = TRUE; pixwidth = 5; procbytes = IWPRCBTS; /* Bytes to process per line */ verbose = FALSE; /* Open files */ for (; argc > 1 ;) { --argc; ++argv; if (**argv == '-') /* Dash Handler */ { for (;;) { ++*argv; switch ((int) **argv) { case '\0': break; case '?': shorthelp(); exit(0); case 'b': ++*argv; if(**argv == '=') { ++*argv; } bright = atoi(*argv); continue; case 'c': ++*argv; if(**argv == '=') { ++*argv; } contrast = atoi(*argv); continue; case 'f': ditherflag = FALSE; continue; case 'n': negimage = TRUE; continue; case 'v': verbose = TRUE; continue; default: continue; } /* Endswitch */ break; } /* Endloop param. unpacker */ continue; } /* Endif dash params. */ if (inpath == STDIN) /* If the path is still default */ { inpath = open(*argv,_READ); if (inpath == ERROR) { fprintf(stderr,"Open input file error.\n"); exit(0); } /* Endif File open error */ continue; } /* Endif */ if (outpath == STDOUT) { outpath = creat(*argv,_WRITE); if (outpath == ERROR) { fprintf(stderr,"File Create error.\n"); exit(0); } /* Endif */ continue; } /* Endif new output file */ } /* Endloop Parameter handler */ /* Printer Initializer --------------------------------- */ lheader[0] = ESC; strcpy(&lheader[1],prtinit); write(outpath,lheader,4); /* *** Change for different printers *** */ /* Build 'lheader' ------------------------------------- */ lheader[0] = ESC; strcpy(&lheader[1],toshln1); /* Grey Table Assignments ------------------------------ */ assigngrey(bright,contrast,negimage); /* This is the actual File conversion: ----------------- */ bitrow = 0; /* Clear IO buff pntrs */ byterow = 0; inbufpntr = 0; pixcol = 0; clearoutbuff(); for (bytes = 0; bytes < IWFLEN ;) { /* Process File Loop */ /* Get bytes for processing -- not related to output size */ inbufpntr = 0; report = read(inpath,inbuff,procbytes); if (report < procbytes) { if (verbose) { fprintf(stderr,"iwprint: Pic Data Read Error.\n"); } /* Endif */ for ( ; report < procbytes ; ++report) { inbuff[report] = 0; } /* Endloop fill short line */ } /* Endif Short Input Read */ bytes = bytes + procbytes; /* Build a printer Line */ for ( ; inbufpntr < procbytes ; ++inbufpntr) { greyval = inbuff[inbufpntr]; /* Unpack a Greyval */ if (greyval == FSTCHAR) { if (verbose) { fprintf(stderr,"Start Detected\n"); } continue; } /* Endif Field Start char. handler */ if ((greyval < 0) || (greyval > LNSTCHAR)) { greyval = 0; } /* Endif exceed limits */ if (greyval == LNSTCHAR) { if (newlnflag == FALSE) { pixcol = 256; /* Set end of print line cond. */ fprintf(stderr,"Short Line Error\n"); } } else { newlnflag = FALSE; greyval = greyscale[greyval]; /* Convert to Grey Scale */ pixel = 0; /* Clear the Pixel map */ if (ditherflag) { pixel = dither(greyval,inbufpntr); } else { for (;;) /* Convert one pixel to bitmap */ { if (greyval == 0) { break; } /* Endif */ pixel = pixel << 1; ++pixel; --greyval; } /* Endloop Convert to Bitmap */ } /* Endcondition not dithered */ /* Redistribute the word into the image map */ distribute(bitrow,byterow,pixcol); /* Point to next Pixel */ ++pixcol; } /* Endcondition Not Newline Char */ if (pixcol == 256) { newlnflag = TRUE; pixcol = 0; bitrow = bitrow + 4; if (bitrow > 5) { bitrow = bitrow - 6; ++byterow; } /* Endif Inc Byterow */ if (byterow == 4) { bitrow = 0; byterow = 0; /* print out the line */ write(outpath,lheader,6); write(outpath,outbuff,PRTRWLN); write(outpath,lnend,2); /* CR/LF */ clearoutbuff(); if(verbose) { fprintf(stderr,"%6d bytes done.\n",bytes); } /* Endif */ } /* Endif Out Line Done */ } /* Endif Inc Bitrow */ } /* Endloop Build output buffer */ } /* Endloop process a file */ /* Print out extra dataline if needed */ if ((bitrow != 0) || (byterow != 0) || (pixcol != 0)) { write(outpath,lheader,6); write(outpath,outbuff,PRTRWLN); write(outpath,lnend,2); } if(verbose) { fprintf(stderr,"Clean Exit.\n"); } /* Endif */ exit(0); /* Clean Exit */ } /* End Main() */ /* ------------------------------------------------ */ clearoutbuff() { int incntr; extern char outbuff[PRTRWLN]; for ( incntr = 0 ; incntr < PRTRWLN ; ++incntr ) { /* Clear Output Buffer */ outbuff[incntr] = 0; } /* Endloop */ } /* End clearoutbuff() */ /* ------------------------------------------------- */ int dither(greyval,seed) int greyval; int seed; { register int buffer; static int bitmask[]={ /* The 20 possible bits to set */ 0x00000001,0x00000002,0x00000004,0x00000008, /* 1, 2, 4, 8 */ 0x00000010,0x00000020,0x00000040,0x00000080, /* 16, 32, 64, 128 */ 0x00000100,0x00000200,0x00000400,0x00000800, /* 256, 512, 1024, 2048 */ 0x00001000,0x00002000,0x00004000,0x00008000, /* 4096,8192,16384,32768 */ 0x00010000,0x00020000,0x00040000,0x00080000 }; /* etc. :-) */ static struct sgtbuf ctime; /* Current Time structure (bytes) */ static int index[20]; /* Index into bitmask */ register int limit; register int offset; /* Initialize Variables */ buffer = 0; for (limit = 0 ; limit < 20 ; ++limit) /* Just a handy variable */ { index[limit] = limit; } limit = 20; /* Note that you don't bother to initialize 'offset' * It's appropriate that it start at a random point. */ for (; greyval > 0; --greyval) { getime(&ctime); offset = offset + (int)ctime.t_second + seed; offset = offset % limit; /* offset = remainder */ buffer = buffer + bitmask[index[offset]]; --limit; index[offset] = index[limit]; /* To be done */ } return(buffer); } /* End of dither() */ /* ------------------------------------------------- */ /* shorthelp() * * Prints a short help message. No variables passed. * Required 'stdio.h' in globals. */ shorthelp() { fprintf(stderr,"iwprint: Printer output of ImageWise file.\n"); fprintf(stderr,"\nUsage: iwprint [-?fnv] [infile] [outfile] "); fprintf(stderr,"-b=nn -c=nnn\n"); fprintf(stderr,"\n ? = Help and exit,\n"); fprintf(stderr," b = brightness (+/-up to 20)\n"); fprintf(stderr," c = contrast (percent of original)\n"); fprintf(stderr," f = fast (no dither)\n"); fprintf(stderr," n = negative,\n v = verbose\n"); } /* End of shorthelp() */ /* End of iwprint.c */ SHAR_EOF # End of shell archive exit 0 -- Jim Omura, 2A King George's Drive, Toronto, (416) 652-3880 lsuc!jimomura Byte Information eXchange: jimomura