home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-08-22 | 37.6 KB | 1,447 lines |
- Newsgroups: comp.sources.misc
- From: Rich Burridge <richb@Aus.Sun.COM>
- Subject: v22i044: popi - The Digital Darkroom, Part05/09
- Message-ID: <1991Aug22.153108.15777@sparky.IMD.Sterling.COM>
- X-Md4-Signature: 9997d14001484957fbd42863e24e642f
- Date: Thu, 22 Aug 1991 15:31:08 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: Rich Burridge <richb@Aus.Sun.COM>
- Posting-number: Volume 22, Issue 44
- Archive-name: popi/part05
- Environment: Xlib, Xview, SunView
- Supersedes: popi: Volume 9, Issue 47-55
-
- #! /bin/sh
- # 1. Remove everything above the #! /bin/sh line
- # 2. Save the resulting text in a file.
- # 3. Execute the file with /bin/sh to create the files:
- # amiga.c
- # apollo.c
- # atariterm.c
- # graphics.c
- # hp.c
- # kerterm.c
- # This archive created: Wed Aug 21 10:35:59 EST 1991
- #
- #
- export PATH; PATH=/bin:$PATH
- #
- if [ -f amiga.c ]
- then
- echo shar: will not over-write existing file amiga.c
- else
- echo shar: extracting 'amiga.c', 4761 characters
- cat > amiga.c <<'Funky_Stuff'
- /*LINTLIBRARY*/
- #ifndef lint
- static char sccsid[] = "@(#)amiga.c 1.2 90/12/28" ;
- #endif
-
- /* @(#)amiga.c 1.2 90/12/28
- *
- * Popi device driver for the Amiga.
- * Written by Peter Chubb - Softway Pty Ltd.
- *
- * Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
- * This version is based on the code in his Prentice Hall book,
- * "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
- * which is copyright (c) 1988 by Bell Telephone Laboratories, Inc.
- *
- * Permission is given to distribute these extensions, as long as these
- * introductory messages are not removed, and no monies are exchanged.
- *
- * No responsibility is taken for any errors or inaccuracies inherent
- * either to the comments or the code of this program, but if reported
- * (see README file) then an attempt will be made to fix them.
- */
-
- #include "popi.h"
- #include "graphics.h"
- #include <exec/types.h>
- #include <intuition/intuition.h>
- #include <proto/graphics.h>
- #include <proto/intuition.h>
- #define Debug _X
- #include <proto/exec.h>
-
- /* These are the exportable routines used by the popi program.
- *
- * disp_init(argc, argv) - called from main at the start.
- * disp_finish() - called from main prior to exit.
- * disp_imgstart() - called prior to drawing an image.
- * disp_imgend() - called after drawing an image.
- * disp_putline(lines, y) - to draw an image scanline triple.
- * disp_getchar() - to get the next character typed.
- * disp_prompt() - display popi prompt and clear input buffer.
- * disp_error(errtype) - display error message.
- * disp_percentdone(n) - display percentage value of conversion.
- */
-
-
- static struct NewScreen NewScreen = {
- 0, /* LeftEdge */
- 0, /* TopEdge */
- 0, /* Width */
- 0, /* HEight */
- 4, /* No. Bitplanes */
- 0, 1, /* DetailPen, BlockPen */
- HIRES | LACE, /* ViewModes */
- CUSTOMSCREEN, /* Screen type */
- (struct TextAttr *)NULL, /* default font */
- "popi", /* Screen Title */
- (struct Gadget *)NULL, /* Gadget list */
- (struct BitMap *)NULL /* custom bitmap */
- };
-
- struct IntuitionBase *IntuitionBase;
- struct GfxBase *GfxBase;
- static struct Screen *disp;
-
- /*ARGSUSED*/
- void
- disp_init(argc,argv) /* called from main at the atart. */
- int argc;
- char *argv[];
- {
- long cnum;
-
- if((IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 0))
- == NULL){
- fprintf(stderr, "Couldn't open intuition\n");
- exit(10);
- }
- if((GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0))==NULL){
- fprintf(stderr, "Couldn't open Graphics library\n");
- CloseLibrary((struct Library *)IntuitionBase);
- exit(10);
- }
-
- NewScreen.Width = Xsize;
- NewScreen.Height = Ysize;
- if((disp = OpenScreen(&NewScreen)) == NULL){
- fprintf(stderr, "Couldn't open new screen\n");
- CloseLibrary((struct Library *)IntuitionBase);
- CloseLibrary((struct Library *)GfxBase);
- exit(10);
- }
- SetDrMd((&(disp->RastPort)), (long)JAM1);
- for(cnum = 0; cnum < 16; cnum++)
- SetRGB4(&(disp->ViewPort), cnum, cnum, cnum, cnum);
-
- }
-
-
- void
- disp_finish() /* called from main prior to exit. */
- {
- CloseScreen(disp);
- CloseLibrary((struct Library *)IntuitionBase);
- CloseLibrary((struct Library *)GfxBase);
- }
-
-
- void
- disp_imgstart() /* called prior to drawing an image. */
- {
- ScreenToFront(disp);
- }
-
-
- void
- disp_imgend() /* called after drawing an image. */
- {
- }
-
-
- void
- disp_putline(lines, y) /* called to draw image scanline y. */
- pixel_t **lines;
- int y;
- {
- short x;
- pixel_t *line;
-
- line = ntsc_luma(lines);
- for (x = 0; x < Xsize;)
- {
- SetAPen(&(disp->RastPort), (long)((*line++)>>4));
- WritePixel(&(disp->RastPort), (long)x++, (long)y);
- }
- }
-
-
- disp_getchar() /* get next user typed character. */
- {
- return(getchar());
- }
-
-
- disp_prompt() /* display popi prompt. */
- {
- PRINTF("-> ");
- return 3;
- }
-
-
- void
- disp_error(errtype, pos) /* display error message. */
- int errtype,
- pos;
- {
- extern int errno;
- extern char *sys_errlist[];
-
- if (errtype & ERR_PARSE)
- {
- int i;
-
- for (i=1; i < pos; ++i)
- PUTC('-', stderr);
- PUTC('^', stderr);
- PUTC('\n', stderr);
- }
-
- FPRINTF(stderr, "%s\n", ErrBuf);
- /* we assume errno hasn't been reset by the preceding output */
- if (errtype & ERR_SYS)
- FPRINTF(stderr, "\t(%s)\n", sys_errlist[errno]);
- }
-
- void
- disp_percentdone(percent)
- int percent;
- {
- static int lastpercent = 100;
-
- if (!Verbose)
- return;
- if (percent == 100)
- {
- printf("\r \n");
- return;
- }
- if (percent != lastpercent && percent % 5 == 0)
- {
- printf("\r%2d%% ", percent);
- fflush(stdout);
- lastpercent = percent;
- }
- }
- Funky_Stuff
- len=`wc -c < amiga.c`
- if [ $len != 4761 ] ; then
- echo error: amiga.c was $len bytes long, should have been 4761
- fi
- fi # end of overwriting check
- if [ -f apollo.c ]
- then
- echo shar: will not over-write existing file apollo.c
- else
- echo shar: extracting 'apollo.c', 7977 characters
- cat > apollo.c <<'Funky_Stuff'
- /*LINTLIBRARY*/
-
- /* @(#)apollo.c 1.2 90/12/28
- *
- * Popi device driver for an Apollo display.
- * Written by Tim Lambert - University of New South Wales.
- *
- * Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
- * This version is based on the code in his Prentice Hall book,
- * "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
- * which is copyright (c) 1988 by Bell Telephone Laboratories, Inc.
- *
- * Permission is given to distribute these extensions, as long as these
- * introductory messages are not removed, and no monies are exchanged.
- *
- * No responsibility is taken for any errors or inaccuracies inherent
- * either to the comments or the code of this program, but if reported
- * (see README file) then an attempt will be made to fix them.
- */
-
- #include "popi.h"
- #include "graphics.h"
- #include <apollo/base.h>
- #include <apollo/gpr.h>
- #include <apollo/pad.h>
- #include <apollo/error.h>
-
- /* geometry, and x11_display are used for x11 options - we don't use them */
- char x11_display[MAXLINE] ; /* X11 display information. */
- char geometry[MAXLINE] ; /* X11 geometry information. */
-
- /* These are the exportable routines used by the popi program.
- *
- * disp_init(argc, argv) - called from main at the start.
- * disp_finish() - called from main prior to exit.
- * disp_imgstart() - called prior to drawing an image.
- * disp_imgend() - called after drawing an image.
- * disp_putline(lines, y) - to draw an image scanline triple.
- * disp_getchar() - to get the next character typed.
- * disp_prompt() - display popi prompt and clear input buffer.
- * disp_error(errtype) - display error message.
- * disp_percentdone(n) - display percentage value of conversion.
- */
-
- status_$t status;
- gpr_$bitmap_desc_t display_bitmap;
- gpr_$offset_t display_bitmap_size;
- gpr_$rgb_plane_t hi_plane;
-
- #define RES 8
- int dither[RES][RES] = { /* dither matrix */
- { 0, 128, 32, 160, 8, 136, 40, 168, },
- { 192, 64, 224, 96, 200, 72, 232, 104, },
- { 48, 176, 16, 144, 56, 184, 24, 152, },
- { 240, 112, 208, 80, 248, 120, 216, 88, },
- { 12, 140, 44, 172, 4, 132, 36, 164, },
- { 204, 76, 236, 108, 196, 68, 228, 100, },
- { 60, 188, 28, 156, 52, 180, 20, 148, },
- { 252, 124, 220, 92, 244, 116, 212, 84, },
- } ;
- void check(char *messagex)
- {
- if (status.all)
- { error_$print (status);
- printf("Error occurred while %s.\n", messagex);
- }
- }
-
- /*ARGSUSED*/
- void
- disp_init(argc,argv) /* called from main at the atart. */
- int argc;
- char *argv[];
- {
- static short int unit = 1;
- static short int disp_len = sizeof(gpr_$disp_char_t);
- short int disp_len_returned;
- short int unobscured;
- gpr_$disp_char_t display_characteristics;
- static gpr_$display_mode_t mode = gpr_$direct;
- stream_$id_t graphics_str;
- pad_$window_desc_t window;
- gpr_$color_vector_t colour_map;
- short int i;
- int intense;
- gpr_$rgb_plane_t plane;
-
- gpr_$inq_disp_characteristics(mode, unit, disp_len,
- &display_characteristics,
- &disp_len_returned, &status);
- check("in disp_init after inquiring");
-
- display_bitmap_size.x_size = Xsize;
- display_bitmap_size.y_size = Ysize;
- hi_plane = display_characteristics.n_planes - 1;
-
- window.top = 0; window.left = 0;
- window.width = Xsize; window.height = Ysize;
- pad_$create_window((char *)NULL,0,pad_$transcript,unit,window,&graphics_str,&status);
- pad_$set_full_window(graphics_str,(short)1,&window,&status);
- pad_$set_border(graphics_str,(short)1,false,&status);
- pad_$set_auto_close(graphics_str,(short)1,true,&status);
- gpr_$init(mode, graphics_str, display_bitmap_size,
- hi_plane, &display_bitmap, &status);
- check("in disp_init after initializing");
- gpr_$set_auto_refresh(true,&status);
- gpr_$set_obscured_opt(gpr_$pop_if_obs,&status);
- gpr_$set_cursor_active(true,&status);
- pad_$def_pfk(graphics_str,"M3 ","=",1,&status); /* M3 reports current cursor position */
- pad_$def_pfk(graphics_str,"M3U ","",0,&status); /* just in case M3U does something */
- for(plane=0;plane<=hi_plane;plane++)
- gpr_$set_raster_op(plane,gpr_$rop_not_dst,&status); /* so that horiz_line below uses XOR */
- if(hi_plane==7){ /* 8 plane colour display */
- /* first 16 colours are used by DM, so we'll use remaining 240,
- mapping intensities in the range 0..255 to entries 16..255 */
- gpr_$inq_color_map( 0, 256, colour_map, &status );
- for(i=16;i<=255;i++){
- intense = (255*(i-16)/240);
- colour_map[i] = (intense << 16) + (intense << 8) + intense;
- }
- gpr_$acquire_display(&status);
- gpr_$set_color_map( 0, 256, colour_map, &status );
- gpr_$release_display(&status);
- }
- }
-
-
- void
- disp_finish() /* called from main prior to exit. */
- {
- gpr_$terminate(false,&status);
- }
-
-
- void
- disp_imgstart() /* called prior to drawing an image. */
- {
- }
-
-
- void
- disp_imgend() /* called after drawing an image. */
- {
- }
-
-
- void
- disp_putline(lines, y) /* called to draw image scanline y. */
- pixel_t **lines;
- int y;
- {
- linteger pixel_array[2000];
- pixel_t *line;
- static gpr_$window_t scanline = {{0,0},{1,1}};
- int x;
-
- line = ntsc_luma(lines);
- for (x=0;x<Xsize;x++){
- if (hi_plane==7){
- pixel_array[x] = (gpr_$pixel_value_t) line[x]*240/256 +16;
- } else {
- pixel_array[x] = !(line[x] >= dither[y % RES][x % RES]);
- }
- }
- scanline.window_size.y_size = (short)1;
- scanline.window_size.x_size = (short)Xsize;
- scanline.window_base.y_coord = (short)y;
- gpr_$set_obscured_opt(gpr_$pop_if_obs,&status);
- gpr_$acquire_display(&status); check("acquiring display");
- gpr_$write_pixels((gpr_$pixel_value_t *)pixel_array,scanline,&status); check("write pixels");
- gpr_$release_display(&status);
- }
-
-
- disp_getchar() /* get next user typed character. */
- {
- return(getchar());
- }
-
-
- disp_prompt() /* display popi prompt. */
- {
- PRINTF("-> ");
- return 3;
- }
-
-
- void
- disp_error(errtype, pos) /* display error message. */
- int errtype,
- pos;
- {
- extern int errno;
- extern char *sys_errlist[];
-
- if (errtype & ERR_PARSE)
- {
- int i;
-
- for (i=1; i < pos; ++i)
- PUTC('-', stderr);
- PUTC('^', stderr);
- PUTC('\n', stderr);
- }
-
- FPRINTF(stderr, "%s\n", ErrBuf);
- /* we assume errno hasn't been reset by the preceding output */
- if (errtype & ERR_SYS)
- FPRINTF(stderr, "\t(%s)\n", sys_errlist[errno]);
- }
-
- void horiz_line(percent)
- int percent;
- /* draw a horizontal line percent % of the way down */
- {
- #define MAX_WINDOWS 50
- gpr_$window_t vis_list[MAX_WINDOWS];
- int i;
- short int slots_total;
- short int x,y;
-
- y = Ysize * percent / 100;
- x = Xsize;
-
- gpr_$set_obscured_opt(gpr_$ok_if_obs,&status);
- gpr_$acquire_display(&status); check("acquiring display");
- gpr_$inq_vis_list (MAX_WINDOWS, &slots_total, vis_list, &status); check("inq vis list");
- for(i=0; i<slots_total; i++){
- gpr_$set_clip_window (vis_list[i], &status) ; check("set clip window");
- gpr_$move(0,y,&status);
- gpr_$line(x,y,&status);
- }
- gpr_$release_display(&status);
- }
-
-
-
- void
- disp_percentdone(percent)
- int percent;
- {
- static int lastpercent = 100;
-
- if (percent != lastpercent){
- horiz_line(percent);
- if(!(percent == 0 || percent == 100))
- horiz_line(lastpercent);
- lastpercent = percent;
- }
- }
-
- Funky_Stuff
- len=`wc -c < apollo.c`
- if [ $len != 7977 ] ; then
- echo error: apollo.c was $len bytes long, should have been 7977
- fi
- fi # end of overwriting check
- if [ -f atariterm.c ]
- then
- echo shar: will not over-write existing file atariterm.c
- else
- echo shar: extracting 'atariterm.c', 4119 characters
- cat > atariterm.c <<'Funky_Stuff'
- /*LINTLIBRARY*/
-
- /* @(#)atariterm.c 1.2 90/12/28
- *
- * Popi graphics driver for atari TERM windows.
- * Written by Stephen Frede, Softway Pty Ltd.
- *
- * Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
- * This version is based on the code in his Prentice Hall book,
- * "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
- * which is copyright (c) 1988 by Bell Telephone Laboratories, Inc.
- *
- * Permission is given to distribute these extensions, as long as these
- * introductory messages are not removed, and no monies are exchanged.
- *
- * No responsibility is taken for any errors or inaccuracies inherent
- * either to the comments or the code of this program, but if reported
- * (see README file) then an attempt will be made to fix them.
- */
-
-
- #include <stdio.h>
- #include <sys/types.h>
- #include "popi.h"
-
- thresh[BITSPERPIXEL][BITSPERPIXEL] =
- { /* Array containing threshold values. */
- { 0, 128, 32, 160, 8, 136, 40, 168, },
- { 192, 64, 224, 96, 200, 72, 232, 104, },
- { 48, 176, 16, 144, 56, 184, 24, 152, },
- { 240, 112, 208, 80, 248, 120, 216, 88, },
- { 12, 140, 44, 172, 4, 132, 36, 164, },
- { 204, 76, 236, 108, 196, 68, 228, 100, },
- { 60, 188, 28, 156, 52, 180, 20, 148, },
- { 252, 124, 220, 92, 244, 116, 212, 84, },
- };
-
- int ImgInProgress = 0;
-
- /* These are the exportable routines used by the popi program.
- *
- * disp_init(argc, argv) - called from main at the start.
- * disp_finish() - called from main prior to exit.
- * disp_imgstart() - called prior to drawing an image.
- * disp_imgend() - called after drawing an image.
- * disp_putline(lines, y) - to draw an image scanline triple.
- * disp_getchar() - to get the next character typed.
- * disp_prompt() - display popi prompt and clear input buffer.
- * disp_error(errtype) - display error message.
- * disp_percentdone(n) - display percentage value of conversion.
- */
-
- /*ARGSUSED*/
- void
- disp_init(argc,argv)
- int argc;
- char *argv[];
- {
- }
-
- void
- disp_finish()
- {
- }
-
- void
- disp_imgstart()
- {
- ImgInProgress = 1;
-
- putchar('\033');
- putchar('[');
- putchar('?');
- putchar('3');
- putchar('2');
- putchar('h');
- putchar('\033');
- putchar('[');
- putchar('2');
- putchar('J');
- putchar('\033');
- putchar('[');
- putchar(';');
- putchar('H');
- }
-
- void
- disp_imgend()
- {
- ImgInProgress = 0;
-
- putchar('\033');
- putchar('[');
- putchar('?');
- putchar('3');
- putchar('2');
- putchar('l');
- }
-
- void
- disp_putline(lines, y) /* Output scanline y. */
- pixel_t **lines;
- int y;
- {
- int x;
- short wd;
- int bit;
- pixel_t *line;
-
- line = ntsc_luma(lines);
- for (x = 0; x < Xsize;)
- {
- wd = 0;
- for (bit = 15; bit >= 0; --bit, ++x)
- if (*line++ < thresh[y % BITSPERPIXEL][x % BITSPERPIXEL])
- wd |= 1 << bit;
- putchar('0' + ((wd >> 10) & 0x3f));
- putchar('0' + ((wd >> 5) & 0x1f));
- putchar('0' + (wd & 0x1f));
- }
- putchar('\n');
- }
-
-
- disp_getchar() /* Get next user typed character. */
- {
- return(getchar());
- }
-
-
- disp_prompt() /* Display popi prompt and clear input line. */
- {
- PRINTF("-> ");
- return 3;
- }
-
-
- void
- disp_error(errtype, pos) /* Display error message. */
- int errtype,
- pos;
- {
- extern int errno;
- extern char *sys_errlist[];
-
- if (errtype & ERR_PARSE)
- {
- int i;
-
- for (i=1; i < pos; ++i)
- PUTC('-', stderr);
- PUTC('^', stderr);
- PUTC('\n', stderr);
- }
-
- FPRINTF(stderr, "%s\n", ErrBuf);
- /* we assume errno hasn't been reset by the preceding output */
- if (errtype & ERR_SYS)
- FPRINTF(stderr, "\t(%s)\n", sys_errlist[errno]);
- }
-
- void
- disp_percentdone(percent)
- int percent;
- {
- static int lastpercent = 100;
-
- if (!Verbose || ImgInProgress)
- return;
-
- if (percent == 100)
- {
- printf("\r \r");
- return;
- }
-
- if
- (
- percent != lastpercent
- /* && percent % 5 == 0 */
- )
- {
- printf("\r%2d%% ", percent);
- fflush(stdout);
- lastpercent = percent;
- }
- }
- Funky_Stuff
- len=`wc -c < atariterm.c`
- if [ $len != 4119 ] ; then
- echo error: atariterm.c was $len bytes long, should have been 4119
- fi
- fi # end of overwriting check
- if [ -f graphics.c ]
- then
- echo shar: will not over-write existing file graphics.c
- else
- echo shar: extracting 'graphics.c', 8522 characters
- cat > graphics.c <<'Funky_Stuff'
-
- /* @(#)graphics.c 1.3 91/08/20
- *
- * Independent graphics routines associated with the popi program.
- *
- * Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
- * This version is based on the code in his Prentice Hall book,
- * "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
- * which is copyright (c) 1988 by Bell Telephone Laboratories, Inc.
- *
- * Permission is given to distribute these extensions, as long as these
- * introductory messages are not removed, and no monies are exchanged.
- *
- * No responsibility is taken for any errors or inaccuracies inherent
- * either to the comments or the code of this program, but if reported
- * (see README file) then an attempt will be made to fix them.
- */
-
- #include "popi.h"
- #include "graphics.h"
-
- char nextline[MAXLINE] ; /* Next input line to be parsed. */
-
- int errpos = -1 ; /* Character position error occured at. */
- int iscolor ; /* Set if this is a color screen. */
- int ix = 0 ; /* Initial X position of the icon. */
- int iy = 0 ; /* Initial Y position of the icon. */
- int nfont_width ; /* Width of normal font characters. */
- int ops[MAXOPS] ; /* Rasterop functions. */
- int posspec = 0 ; /* Set if -g option is present (for X11) */
- int started = 0 ; /* Set if we've drawn the percent dialog box. */
- int tptr = 0 ; /* Input buffer pointer. */
- int wx = 0 ; /* Initial X position of the open window. */
- int wy = 0 ; /* Initial Y position of the open window. */
-
- extern int errno ;
- extern char *sys_errlist[] ;
-
-
- /* These are the exportable routines used by the popi program.
- *
- * disp_init(argc, argv) - called from main at the start.
- * disp_finish() - called from main prior to exit.
- * disp_imgstart() - called prior to drawing an image.
- * disp_imgend() - called after drawing an image.
- * disp_putline(lines, y) - to draw an image scanline triple.
- * disp_getchar() - to get the next character typed.
- * disp_prompt() - display popi prompt and clear input buffer.
- * disp_error(errtype, pos) - display error message.
- * disp_percentdone(n) - display percentage value of conversion.
- */
-
-
- void
- disp_init(argc, argv) /* Called from main at the start. */
- int argc ;
- char *argv[] ;
- {
- if (init_ws_type()) /* Determine window system type. */
- {
- FPRINTF(stderr, "Error initialising window system.\n") ;
- exit(1) ;
- }
- init_dither() ; /* Initialise dither arrays and variables. */
- init_fonts() ; /* Open required fonts. */
- make_items(argc, argv) ; /* Create icon, frame, canvas etc.. */
- paint_canvas() ; /* Draw dialog boxes. */
- start_tool() ;
- }
-
-
- void
- disp_finish() /* Called from main prior to exit. */
- {
- cleanup() ;
- }
-
-
- void
- disp_imgstart() /* Called prior to drawing an image. */
- {
- }
-
-
- void
- disp_imgend() /* Called after drawing an image. */
- {
- }
-
-
- void
- disp_putline(lines, y) /* Draw an image scanline triple. */
- unsigned char **lines ;
- int y ;
- {
- draw_scanline(lines, y) ;
- }
-
-
- disp_getchar() /* Get next user typed character. */
- {
- char c ;
- int finished = 0 ;
- int len ;
-
- if (tptr >= strlen(nextline))
- {
- while (!finished)
- {
- get_next_char(&c) ; /* Get next character typed. */
- if (c == '\0') continue ;
- if (errpos != -1)
- {
- drawarea(BOXX+100+errpos*nfont_width, BOXY+BOXH-9,
- nfont_width, 4, GCLR) ;
- drawarea(BOXX+91, BOXY+51, BOXW-102, BOXH-22, GCLR) ;
- errpos = -1 ;
- }
- if (c == BACKSPACE || c == DEL)
- {
- len = strlen(nextline) ;
- if (len) nextline[len-1] = '\0' ;
- }
- else if (c == RETURN || c == LINEFEED)
- {
- set_cursor(BUSY_CUR) ; /* We will now get busy! */
- c = '\n' ;
- STRNCAT(nextline, &c, 1) ;
- finished = 1 ;
- }
- else if (c >= 32) STRNCAT(nextline, &c, 1) ;
- drawarea(BOXX+91, BOXY+11, BOXW-102, BOXH-22, GCLR) ;
- put_text(BOXX, BOXY, BOXW, BOXH, nextline, 1) ;
- }
- tptr = 0 ;
- }
- return(nextline[tptr++]) ;
- }
-
-
- /* Show the percentage of the image converted as a graphical slider using
- * the error dialog box. If the percentage is zero, then we are just starting,
- * so the box is relabeled (to % done:). If the percentage is 100, then we
- * are just finishing, and the box is relabel back (to Error:), and cleared.
- * If the percent value is the same as last time we immediately return,
- * otherwise we show an intermediate percentage value.
- */
-
- void
- disp_percentdone(percent)
- int percent ;
- {
- static int opercent = -1 ; /* Previous display percent done value. */
- if (percent == opercent) return ; /* Same as last time? */
- opercent = percent ;
- if (!percent)
- {
- if (!started)
- draw_textbox(BOXX, BOXY+40, BOXW, BOXH, "% done:", "", 0) ;
- started = 1 ;
- }
- else if (percent == 100)
- {
- if (started)
- draw_textbox(BOXX, BOXY+40, BOXW, BOXH, "Error:", "", 0) ;
- started = 0 ;
- }
- else
- drawarea(BOXX+91, BOXY+51,
- (int) ((double) (BOXW-102) / 100 * percent), BOXH-20, GSET) ;
- }
-
-
- disp_prompt() /* Display popi prompt and clear input line. */
- {
- set_cursor(NORMAL_CUR) ;
- if (errpos == -1) drawarea(BOXX+91, BOXY+11, BOXW-102, BOXH-22, GCLR) ;
- STRCPY(nextline, "") ;
- tptr = 0 ;
- return 0 ;
- }
-
-
- void
- disp_error(errtype, pos) /* Display error message. */
- int errtype ;
- int pos ;
- {
- errpos = pos ;
- if (errtype & ERR_PARSE)
- drawarea(BOXX+100+errpos*nfont_width, BOXY+BOXH-9,
- nfont_width, 4, GSET) ;
-
- put_text(BOXX, BOXY+40, BOXW, BOXH, ErrBuf, 0) ;
-
- /* We assume errno hasn't been reset by the preceding output */
-
- if (errtype & ERR_SYS)
- {
- sleep(2) ;
- SPRINTF(ErrBuf, "\t(%s)\n", sys_errlist[errno]) ;
- drawarea(BOXX+91, BOXY+51, BOXW-102, BOXH-22, GCLR) ;
- put_text(BOXX, BOXY+40, BOXW, BOXH, ErrBuf, 0) ;
- }
- }
-
- /* These are other independent graphics routines used by popi. */
-
- draw_frame(x, y, width, height)
- int x, y, width, height ;
- {
- drawarea(x, y, width, height, GSET) ;
- drawarea(x+1, y+1, width-2, height-2, GCLR) ;
- drawarea(x+3, y+3, width-6, height-6, GSET) ;
- drawarea(x+5, y+5, width-10, height-10, GCLR) ;
- }
-
-
- /* Display a text box of given width and height with top left corner at
- * the given x,y location, displaying a title and the given text value.
- */
-
- draw_textbox(x, y, w, h, title, str, showcur)
- int x, y, w, h, showcur ;
- char *title, *str ;
- {
- draw_frame(x, y, w, h) ;
- drawtext(x+10, y+h-15, BFONT, title) ;
- draw_rect(x+90, y+10, x+w-10, y+h-10) ;
- put_text(x, y, w, h, str, showcur) ;
- }
-
-
- draw_rect(x1, y1, x2, y2)
- int x1, y1, x2, y2 ;
- {
- drawline(x1, y1, x2, y1) ;
- drawline(x1, y1, x1, y2) ;
- drawline(x2, y1, x2, y2) ;
- drawline(x1, y2, x2, y2) ;
- }
-
-
- /* Paint the contents of the popi canvas. This consists of first clearing
- * the whole canvas, then drawing a line to distinguish between the image
- * drawing area and the command feedback area. Two text boxes are then
- * drawn, one for user input and the other to shown any error messages.
- */
-
- paint_canvas()
- {
- drawarea(0, 0, TXsize, TYsize, GCLR) ;
- drawline(0, 99, TXsize, 99) ;
- if (Xsize < TXsize)
- drawline(Xsize, 100, Xsize, TYsize) ;
- draw_textbox(BOXX, BOXY, BOXW, BOXH, "Command:", nextline, 1) ;
- draw_textbox(BOXX, BOXY+40, BOXW, BOXH, "Error:", "", 0) ;
- }
-
-
- /* With the screen based window systems, display the character string
- * str at the given x,y location. The width of the dialog box is given,
- * so that if the text exceeds the displayable area, it is scrolled to
- * the left. A soft cursor in the form of a vertical line is shown if
- * so requested.
- */
-
- put_text(x, y, w, h, str, showcur)
- int x, y, w, h ;
- char *str ;
- {
- char dummy[MAXLINE] ;
- int limit, nochars ;
-
- limit = ((w - 100) / nfont_width) - 1 ;
- nochars = (strlen(str) <= limit) ? strlen(str) : limit ;
- STRNCPY(dummy, &str[strlen(str) - nochars], nochars) ;
-
- dummy[nochars] = '\0' ;
- drawtext(x+100, y+h-17, NFONT, dummy) ;
- if (showcur)
- drawline(x+100+strlen(dummy)*nfont_width, y+15,
- x+100+strlen(dummy)*nfont_width, y+h-15) ;
- }
- Funky_Stuff
- len=`wc -c < graphics.c`
- if [ $len != 8522 ] ; then
- echo error: graphics.c was $len bytes long, should have been 8522
- fi
- fi # end of overwriting check
- if [ -f hp.c ]
- then
- echo shar: will not over-write existing file hp.c
- else
- echo shar: extracting 'hp.c', 4044 characters
- cat > hp.c <<'Funky_Stuff'
- /*LINTLIBRARY*/
-
- /* @(#)hp.c 1.1 90/12/12
- *
- * Popi device driver for an HP 8+ plane display.
- * Written by Eric Haines - 3D/Eye Inc, Ithaca, NY
- *
- * Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
- * This version is based on the code in his Prentice Hall book,
- * "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
- * which is copyright (c) 1988 by Bell Telephone Laboratories, Inc.
- *
- * Permission is given to distribute these extensions, as long as these
- * introductory messages are not removed, and no monies are exchanged.
- *
- * No responsibility is taken for any errors or inaccuracies inherent
- * either to the comments or the code of this program, but if reported
- * (see README file) then an attempt will be made to fix them.
- */
-
- #include "popi.h"
- #include "graphics.h"
- #include <starbase.c.h>
-
- /* These are the exportable routines used by the popi program.
- *
- * disp_init(argc, argv) - called from main at the start.
- * disp_finish() - called from main prior to exit.
- * disp_imgstart() - called prior to drawing an image.
- * disp_imgend() - called after drawing an image.
- * disp_putline(line, y) - to draw an image scanline.
- * disp_getchar() - to get the next character typed.
- * disp_prompt() - display popi prompt and clear input buffer.
- * disp_error(errtype) - display error message.
- * disp_percentdone(n) - display percentage value of conversion.
- */
-
- extern char *getenv();
-
- /* Set environment variables OUTDEV and OUTDRIVER or change the
- * defaults to your machine.
- */
- char default_outdev[] = "/dev/hp98721" ;
- char default_outdriver[] = "hp98721" ;
- char default_indev[] = "/dev/hil2" ;
- char default_indriver[] = "hp-hil" ;
-
- int fd ;
-
- void
- disp_init(argc,argv) /* called from main at the start. */
- int argc;
- char *argv[];
- {
- fd = devopen(OUTDEV,INIT) ;
- if ( fd == -1 ) {
- printf("error opening output device\n" ) ;
- exit(1) ;
- }
- vdc_extent( fd, 0.0, 0.0, 0.0, 1.25, 1.0, 1.0 ) ;
- shade_mode( fd, CMAP_MONOTONIC | INIT, 0 ) ;
- make_picture_current( fd ) ;
- }
-
-
- void
- disp_finish() /* called from main prior to exit. */
- {
- gclose( fd ) ;
- }
-
-
- void
- disp_imgstart() /* called prior to drawing an image. */
- {
- }
-
-
- void
- disp_imgend() /* called after drawing an image. */
- {
- }
-
-
- void
- disp_putline(line, y) /* called to draw image scanline y. */
- pixel_t *line;
- int y;
- {
- dcblock_write( fd, 0,y,Xsize,1,line,0) ;
- }
-
-
- disp_getchar() /* get next user typed character. */
- {
- return(getchar());
- }
-
-
- disp_prompt() /* display popi prompt. */
- {
- PRINTF("-> ");
- return 3;
- }
-
-
- void
- disp_error(errtype, pos) /* display error message. */
- int errtype,
- pos;
- {
- extern int errno;
- extern char *sys_errlist[];
-
- if (errtype & ERR_PARSE)
- {
- int i;
-
- for (i=1; i < pos; ++i)
- PUTC('-', stderr);
- PUTC('^', stderr);
- PUTC('\n', stderr);
- }
-
- fprintf(stderr, "%s\n", ErrBuf);
- /* we assume errno hasn't been reset by the preceding output */
- if (errtype & ERR_SYS)
- fprintf(stderr, "\t(%s)\n", sys_errlist[errno]);
- }
-
- void
- disp_percentdone(percent)
- int percent;
- {
- static int lastpercent = 100;
-
- if (!Verbose)
- return;
- if (percent == 100)
- {
- printf("\r \n");
- return;
- }
- if (percent != lastpercent && percent % 5 == 0)
- {
- printf("\r%2d%% ", percent);
- fflush(stdout);
- lastpercent = percent;
- }
- }
-
- int devopen(dev_kind,init_mode)
- int dev_kind,init_mode;
- {
- char *dev, *driver;
- int fildes ;
-
- if ( dev_kind == OUTDEV ) {
- dev = getenv("OUTDEV");
- if (!dev) dev = default_outdev ;
- driver = getenv("OUTDRIVER");
- if (!driver) driver = default_outdriver ;
- } else {
- dev = getenv("INDEV");
- if (!dev) dev = default_indev ;
- driver = getenv("INDRIVER");
- if (!driver) driver = default_indriver ;
- }
-
- fildes = gopen(dev,dev_kind,driver,init_mode);
-
- return(fildes) ;
- }
- Funky_Stuff
- len=`wc -c < hp.c`
- if [ $len != 4044 ] ; then
- echo error: hp.c was $len bytes long, should have been 4044
- fi
- fi # end of overwriting check
- if [ -f kerterm.c ]
- then
- echo shar: will not over-write existing file kerterm.c
- else
- echo shar: extracting 'kerterm.c', 6197 characters
- cat > kerterm.c <<'Funky_Stuff'
- /*LINTLIBRARY*/
-
- /* @(#)kerterm.c 1.2 90/12/28
- *
- * Popi graphics driver for kermit TERM windows.
- * written by Frank Crawford - Q.H.Tours.
- *
- * Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
- * This version is based on the code in his Prentice Hall book,
- * "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
- * which is copyright (c) 1988 by Bell Telephone Laboratories, Inc.
- *
- * Permission is given to distribute these extensions, as long as these
- * introductory messages are not removed, and no monies are exchanged.
- *
- * No responsibility is taken for any errors or inaccuracies inherent
- * either to the comments or the code of this program, but if reported
- * (see README file) then an attempt will be made to fix them.
- */
-
-
- #include <stdio.h>
- #include <signal.h>
- #include <sys/types.h>
- #include "popi.h"
-
- #define KER_MAX_X 1023 /* Maximum Kermit X value */
- #define KER_MAX_Y 779 /* Maximum Kermit Y value */
- #define PC_MAX_X 640 /* Number of PC X value (EGA Card) */
- #define PC_MAX_Y 350 /* Number of PC Y value (EGA Card) */
- #define MAX_GREY 2 /* Max. Greyscale value (Black, Low-int, Hi-int) */
-
- int thresh[MAX_GREY][BITSPERPIXEL][BITSPERPIXEL] =
- {
- { /* Array containing threshold values for low value. */
- { 0, 64, 16, 80, 4, 68, 20, 84, },
- { 96, 32, 112, 48, 100, 36, 116, 52, },
- { 24, 88, 8, 72, 28, 92, 12, 76, },
- { 120, 56, 104, 40, 124, 60, 108, 44, },
- { 6, 70, 22, 86, 2, 66, 18, 82, },
- { 102, 38, 118, 54, 98, 34, 114, 50, },
- { 30, 94, 14, 78, 26, 90, 10, 74, },
- { 126, 62, 110, 46, 122, 58, 106, 42, },
- },
- { /* Array containing threshold values for high value. */
- { 128, 192, 144, 208, 132, 196, 148, 212, },
- { 224, 160, 240, 176, 228, 164, 244, 180, },
- { 152, 216, 136, 200, 156, 220, 140, 204, },
- { 248, 184, 232, 168, 252, 188, 236, 172, },
- { 134, 198, 150, 214, 130, 194, 146, 210, },
- { 230, 166, 246, 182, 226, 162, 242, 178, },
- { 158, 222, 142, 206, 154, 218, 138, 202, },
- { 254, 190, 238, 174, 250, 186, 234, 170, },
- },
- };
-
- /* These are the exportable routines used by the popi program.
- *
- * disp_init(argc, argv) - called from main at the start.
- * disp_finish() - called from main prior to exit.
- * disp_imgstart() - called prior to drawing an image.
- * disp_imgend() - called after drawing an image.
- * disp_putline(lines, y) - to draw an image scanline triple.
- * disp_getchar() - to get the next character typed.
- * disp_prompt() - display popi prompt and clear input buffer.
- * disp_error(errtype) - display error message.
- * disp_percentdone(n) - display percentage value of conversion.
- */
-
- /*ARGSUSED*/
- void
- disp_init(argc,argv)
- int argc;
- char *argv[];
- {
- }
-
- void
- disp_finish()
- {
- }
-
- void
- disp_intr(signal)
- int signal;
- {
- disp_imgend();
- exit(signal);
- }
-
- void
- disp_imgstart()
- {
- (void) signal(SIGINT, disp_intr);
- putchar('\033');
- putchar('\f');
- }
-
- void
- disp_imgend()
- {
- char ch;
-
- putchar('\033');
- putchar('[');
- putchar('0');
- putchar('m');
- PRINTF("\037\n\n\007Hit return when ready:");
- fflush(stdout);
- while (read(1, &ch, 1) == 1 && ch != '\n') /* Because of inconsistent use */
- ;
- putchar('\033');
- putchar('[');
- putchar('?');
- putchar('3');
- putchar('8');
- putchar('l');
- fflush(stdout);
- (void) signal(SIGINT, SIG_DFL);
- }
-
- static void
- coord(x, y, repeat)
- int x, y;
- int repeat;
- {
- /*
- * This function goes to a lot of effort to optimes the number of
- * characters sent down the line.
- */
- int hi_x, lo_x, hi_y, lo_y;
- static int sav_x = -1, sav_y = -1;
-
- y = KER_MAX_Y - y; /* To invert picture */
- hi_x = (x / 32);
- lo_x = (x % 32);
- hi_y = (y / 32);
- lo_y = (y % 32);
- if (!repeat || y != sav_y)
- {
- putchar(hi_y + 0x20);
- putchar(lo_y + 0x60);
- putchar(hi_x + 0x20);
- }
- else if (hi_x != (sav_x / 32))
- {
- putchar(lo_y + 0x60);
- putchar(hi_x + 0x20);
- }
- putchar(lo_x + 0x40);
- sav_x = x;
- sav_y = y;
- }
-
- void
- disp_putline(lines, y) /* Output scanline y. */
- pixel_t **lines;
- int y;
- {
- int x;
- int real_x, real_y;
- int repeat, level;
- pixel_t *line;
- static old_level = 0;
-
- repeat = 0;
- line = ntsc_luma(lines);
- /*
- * Calculate the real pixel location to handle the grey-scale threshold
- * values.
- */
- real_y = (y * PC_MAX_Y) / (KER_MAX_Y + 1);
- putchar('\034');
- for (x = 0; x < Xsize; x++, line++)
- {
- /* See above */
- real_x = (x * PC_MAX_X) / (KER_MAX_X + 1);
- for (level = 0; level < MAX_GREY; level++)
- if (*line < thresh[level][real_y % BITSPERPIXEL][real_x % BITSPERPIXEL])
- break;
- if (level != old_level)
- {
- if (level != 0)
- {
- putchar('\033');
- putchar('[');
- putchar((level == 1) ? '0' : '1');
- putchar('m');
- }
- old_level = level;
- }
- if (level != 0)
- coord(x, y, repeat++);
- }
- putchar('\n');
- }
-
-
- disp_getchar() /* Get next user typed character. */
- {
- return(getchar());
- }
-
-
- disp_prompt() /* Display popi prompt and clear input line. */
- {
- PRINTF("-> ");
- return 3;
- }
-
-
- void
- disp_error(errtype, pos) /* Display error message. */
- int errtype, pos ;
- {
- extern int errno;
- extern char *sys_errlist[];
-
- if (errtype & ERR_PARSE)
- {
- int i;
-
- for (i=1; i < pos; ++i)
- PUTC('-', stderr);
- PUTC('^', stderr);
- PUTC('\n', stderr);
- }
-
- FPRINTF(stderr, "%s\n", ErrBuf);
- /* we assume errno hasn't been reset by the preceding output */
- if (errtype & ERR_SYS)
- FPRINTF(stderr, "\t(%s)\n", sys_errlist[errno]);
- }
-
- void
- disp_percentdone(percent)
- int percent;
- {
- static int lastpercent = 100;
-
- if (!Verbose)
- return;
- if (percent == 100)
- {
- printf("\r \n");
- return;
- }
- if (percent != lastpercent && percent % 5 == 0)
- {
- printf("\r%2d%% ", percent);
- fflush(stdout);
- lastpercent = percent;
- }
- }
- Funky_Stuff
- len=`wc -c < kerterm.c`
- if [ $len != 6197 ] ; then
- echo error: kerterm.c was $len bytes long, should have been 6197
- fi
- fi # end of overwriting check
- exit 0 # Just in case...
-