home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume22 / popi / part05 < prev    next >
Encoding:
Text File  |  1991-08-22  |  37.6 KB  |  1,447 lines

  1. Newsgroups: comp.sources.misc
  2. From: Rich Burridge <richb@Aus.Sun.COM>
  3. Subject:  v22i044:  popi - The Digital Darkroom, Part05/09
  4. Message-ID: <1991Aug22.153108.15777@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: 9997d14001484957fbd42863e24e642f
  6. Date: Thu, 22 Aug 1991 15:31:08 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: Rich Burridge <richb@Aus.Sun.COM>
  10. Posting-number: Volume 22, Issue 44
  11. Archive-name: popi/part05
  12. Environment: Xlib, Xview, SunView
  13. Supersedes: popi: Volume 9, Issue 47-55
  14.  
  15. #! /bin/sh
  16. # 1. Remove everything above the #! /bin/sh line
  17. # 2. Save the resulting text in a file.
  18. # 3. Execute the file with /bin/sh to create the files:
  19. #    amiga.c
  20. #    apollo.c
  21. #    atariterm.c
  22. #    graphics.c
  23. #    hp.c
  24. #    kerterm.c
  25. # This archive created: Wed Aug 21 10:35:59 EST 1991
  26. #
  27. #
  28. export PATH; PATH=/bin:$PATH
  29. #
  30. if [ -f amiga.c ]
  31. then
  32. echo shar: will not over-write existing file amiga.c
  33. else
  34. echo shar: extracting 'amiga.c',     4761 characters
  35. cat > amiga.c <<'Funky_Stuff'
  36. /*LINTLIBRARY*/
  37. #ifndef lint
  38. static char sccsid[] = "@(#)amiga.c 1.2 90/12/28" ;
  39. #endif
  40.  
  41. /*  @(#)amiga.c 1.2 90/12/28
  42.  *
  43.  *  Popi device driver for the Amiga.
  44.  *  Written by Peter Chubb - Softway Pty Ltd.
  45.  *
  46.  *  Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
  47.  *  This version is based on the code in his Prentice Hall book,
  48.  *  "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
  49.  *  which is copyright (c) 1988 by Bell Telephone Laboratories, Inc. 
  50.  *
  51.  *  Permission is given to distribute these extensions, as long as these
  52.  *  introductory messages are not removed, and no monies are exchanged.
  53.  *
  54.  *  No responsibility is taken for any errors or inaccuracies inherent
  55.  *  either to the comments or the code of this program, but if reported
  56.  *  (see README file) then an attempt will be made to fix them.
  57.  */
  58.  
  59. #include "popi.h"
  60. #include "graphics.h"
  61. #include <exec/types.h>
  62. #include <intuition/intuition.h>
  63. #include <proto/graphics.h>
  64. #include <proto/intuition.h>
  65. #define Debug _X
  66. #include <proto/exec.h>
  67.  
  68. /*  These are the exportable routines used by the popi program.
  69.  *
  70.  *  disp_init(argc, argv)    - called from main at the start.
  71.  *  disp_finish()            - called from main prior to exit.
  72.  *  disp_imgstart()          - called prior to drawing an image.
  73.  *  disp_imgend()            - called after drawing an image.
  74.  *  disp_putline(lines, y)   - to draw an image scanline triple.
  75.  *  disp_getchar()           - to get the next character typed.
  76.  *  disp_prompt()            - display popi prompt and clear input buffer.
  77.  *  disp_error(errtype)      - display error message.
  78.  *  disp_percentdone(n)      - display percentage value of conversion.
  79.  */
  80.  
  81.  
  82. static struct NewScreen NewScreen = {
  83.     0, /* LeftEdge */
  84.     0, /* TopEdge */
  85.     0, /* Width */
  86.     0, /* HEight */
  87.     4, /* No. Bitplanes */
  88.     0, 1, /* DetailPen, BlockPen */
  89.     HIRES | LACE, /* ViewModes */
  90.     CUSTOMSCREEN, /* Screen type */
  91.     (struct TextAttr *)NULL,    /* default font */
  92.     "popi",        /* Screen Title */
  93.     (struct Gadget *)NULL, /* Gadget list */
  94.     (struct BitMap *)NULL /* custom bitmap */
  95.  };
  96.  
  97. struct IntuitionBase *IntuitionBase;
  98. struct GfxBase *GfxBase;
  99. static struct Screen *disp;
  100.  
  101. /*ARGSUSED*/
  102. void
  103. disp_init(argc,argv)           /* called from main at the atart. */
  104. int argc;
  105. char *argv[];
  106. {
  107.   long cnum;
  108.  
  109.   if((IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 0))
  110.     == NULL){
  111.     fprintf(stderr, "Couldn't open intuition\n");
  112.     exit(10);
  113.   }
  114.   if((GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0))==NULL){
  115.     fprintf(stderr, "Couldn't open Graphics library\n");
  116.     CloseLibrary((struct Library *)IntuitionBase);
  117.     exit(10);
  118.   }
  119.  
  120.   NewScreen.Width  = Xsize;
  121.   NewScreen.Height = Ysize;
  122.   if((disp = OpenScreen(&NewScreen)) == NULL){
  123.     fprintf(stderr, "Couldn't open new screen\n");
  124.     CloseLibrary((struct Library *)IntuitionBase);
  125.     CloseLibrary((struct Library *)GfxBase);
  126.     exit(10);
  127.   }
  128.   SetDrMd((&(disp->RastPort)), (long)JAM1);
  129.   for(cnum = 0; cnum < 16; cnum++)
  130.     SetRGB4(&(disp->ViewPort), cnum, cnum, cnum, cnum);   
  131.  
  132. }
  133.  
  134.  
  135. void
  136. disp_finish()                  /* called from main prior to exit. */
  137. {
  138.     CloseScreen(disp);
  139.     CloseLibrary((struct Library *)IntuitionBase);
  140.     CloseLibrary((struct Library *)GfxBase);
  141. }
  142.  
  143.  
  144. void
  145. disp_imgstart()                /* called prior to drawing an image. */
  146. {
  147.     ScreenToFront(disp);
  148. }
  149.  
  150.  
  151. void
  152. disp_imgend()                  /* called after drawing an image. */
  153. {
  154. }
  155.  
  156.  
  157. void
  158. disp_putline(lines, y)        /* called to draw image scanline y. */
  159. pixel_t **lines;
  160. int y;
  161. {
  162.     short x;
  163.     pixel_t *line;
  164.  
  165.     line = ntsc_luma(lines);
  166.     for (x = 0; x < Xsize;)
  167.     {
  168.     SetAPen(&(disp->RastPort), (long)((*line++)>>4));
  169.     WritePixel(&(disp->RastPort), (long)x++, (long)y);
  170.     }
  171. }
  172.  
  173.  
  174. disp_getchar()                 /* get next user typed character. */
  175. {
  176.   return(getchar());
  177. }
  178.  
  179.  
  180. disp_prompt()                  /* display popi prompt. */
  181. {
  182.   PRINTF("-> ");
  183.   return 3;
  184. }
  185.  
  186.  
  187. void
  188. disp_error(errtype, pos)            /* display error message. */
  189. int    errtype,
  190.     pos;
  191. {
  192.     extern int  errno;
  193.     extern char *sys_errlist[];
  194.  
  195.     if (errtype & ERR_PARSE)
  196.     {
  197.         int     i;
  198.  
  199.         for (i=1; i < pos; ++i)
  200.             PUTC('-', stderr);
  201.         PUTC('^', stderr);
  202.         PUTC('\n', stderr);
  203.     }
  204.  
  205.     FPRINTF(stderr, "%s\n", ErrBuf);
  206.     /* we assume errno hasn't been reset by the preceding output */
  207.     if (errtype & ERR_SYS)
  208.         FPRINTF(stderr, "\t(%s)\n", sys_errlist[errno]);
  209. }
  210.  
  211. void
  212. disp_percentdone(percent)
  213. int    percent;
  214. {
  215.     static int    lastpercent = 100;
  216.  
  217.     if (!Verbose)
  218.     return;
  219.     if (percent == 100)
  220.     {
  221.     printf("\r    \n");
  222.     return;
  223.     }
  224.     if (percent != lastpercent && percent % 5 == 0)
  225.     {
  226.     printf("\r%2d%% ", percent);
  227.     fflush(stdout);
  228.     lastpercent = percent;
  229.     }
  230. }
  231. Funky_Stuff
  232. len=`wc -c < amiga.c`
  233. if [ $len !=     4761 ] ; then
  234. echo error: amiga.c was $len bytes long, should have been     4761
  235. fi
  236. fi # end of overwriting check
  237. if [ -f apollo.c ]
  238. then
  239. echo shar: will not over-write existing file apollo.c
  240. else
  241. echo shar: extracting 'apollo.c',     7977 characters
  242. cat > apollo.c <<'Funky_Stuff'
  243. /*LINTLIBRARY*/
  244.  
  245. /*  @(#)apollo.c 1.2 90/12/28
  246.  *
  247.  *  Popi device driver for an Apollo display.
  248.  *  Written by Tim Lambert - University of New South Wales.
  249.  *
  250.  *  Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
  251.  *  This version is based on the code in his Prentice Hall book,
  252.  *  "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
  253.  *  which is copyright (c) 1988 by Bell Telephone Laboratories, Inc. 
  254.  *
  255.  *  Permission is given to distribute these extensions, as long as these
  256.  *  introductory messages are not removed, and no monies are exchanged.
  257.  *
  258.  *  No responsibility is taken for any errors or inaccuracies inherent
  259.  *  either to the comments or the code of this program, but if reported
  260.  *  (see README file) then an attempt will be made to fix them.
  261.  */
  262.  
  263. #include "popi.h"
  264. #include "graphics.h"
  265. #include <apollo/base.h>
  266. #include <apollo/gpr.h>
  267. #include <apollo/pad.h>
  268. #include <apollo/error.h>
  269.  
  270. /* geometry, and x11_display are used for x11 options - we don't use them */
  271. char x11_display[MAXLINE] ;       /* X11 display information. */
  272. char geometry[MAXLINE] ;          /* X11 geometry information. */
  273.  
  274. /*  These are the exportable routines used by the popi program.
  275.  *
  276.  *  disp_init(argc, argv)    - called from main at the start.
  277.  *  disp_finish()            - called from main prior to exit.
  278.  *  disp_imgstart()          - called prior to drawing an image.
  279.  *  disp_imgend()            - called after drawing an image.
  280.  *  disp_putline(lines, y)   - to draw an image scanline triple.
  281.  *  disp_getchar()           - to get the next character typed.
  282.  *  disp_prompt()            - display popi prompt and clear input buffer.
  283.  *  disp_error(errtype)      - display error message.
  284.  *  disp_percentdone(n)      - display percentage value of conversion.
  285.  */
  286.  
  287. status_$t            status;
  288. gpr_$bitmap_desc_t   display_bitmap;
  289. gpr_$offset_t        display_bitmap_size;
  290. gpr_$rgb_plane_t     hi_plane;
  291.  
  292. #define  RES  8
  293. int dither[RES][RES] = {        /* dither matrix */
  294.   {   0, 128,  32, 160,   8, 136,  40, 168, },
  295.   { 192,  64, 224,  96, 200,  72, 232, 104, },
  296.   {  48, 176,  16, 144,  56, 184,  24, 152, },
  297.   { 240, 112, 208,  80, 248, 120, 216,  88, },
  298.   {  12, 140,  44, 172,   4, 132,  36, 164, },
  299.   { 204,  76, 236, 108, 196,  68, 228, 100, },
  300.   {  60, 188,  28, 156,  52, 180,  20, 148, },
  301.   { 252, 124, 220,  92, 244, 116, 212,  84, },
  302. } ;
  303. void check(char *messagex)
  304. {
  305.    if (status.all)
  306.    {   error_$print (status);
  307.        printf("Error occurred while %s.\n", messagex);
  308.    }
  309. }
  310.  
  311. /*ARGSUSED*/
  312. void
  313. disp_init(argc,argv)           /* called from main at the atart. */
  314. int argc;
  315. char *argv[];
  316. {
  317. static short int         unit = 1;
  318. static short int         disp_len = sizeof(gpr_$disp_char_t);
  319.        short int         disp_len_returned;
  320.        short int         unobscured;
  321. gpr_$disp_char_t     display_characteristics;
  322. static gpr_$display_mode_t mode = gpr_$direct;
  323.         stream_$id_t         graphics_str;
  324.         pad_$window_desc_t   window;
  325.         gpr_$color_vector_t  colour_map;
  326.         short int            i;
  327.         int                  intense;
  328.         gpr_$rgb_plane_t     plane;
  329.  
  330.    gpr_$inq_disp_characteristics(mode, unit, disp_len,
  331.                                  &display_characteristics,
  332.                                   &disp_len_returned, &status);
  333.    check("in disp_init after inquiring");
  334.  
  335.    display_bitmap_size.x_size = Xsize;
  336.    display_bitmap_size.y_size = Ysize;
  337.    hi_plane                   = display_characteristics.n_planes - 1;
  338.  
  339.    window.top   =  0;     window.left   =  0;
  340.    window.width =  Xsize;   window.height =  Ysize;
  341.    pad_$create_window((char *)NULL,0,pad_$transcript,unit,window,&graphics_str,&status);
  342.    pad_$set_full_window(graphics_str,(short)1,&window,&status);
  343.    pad_$set_border(graphics_str,(short)1,false,&status);
  344.    pad_$set_auto_close(graphics_str,(short)1,true,&status);
  345.    gpr_$init(mode, graphics_str, display_bitmap_size,
  346.              hi_plane, &display_bitmap, &status);
  347.    check("in disp_init after initializing");
  348.    gpr_$set_auto_refresh(true,&status);
  349.    gpr_$set_obscured_opt(gpr_$pop_if_obs,&status);
  350.    gpr_$set_cursor_active(true,&status);
  351.    pad_$def_pfk(graphics_str,"M3  ","=",1,&status); /* M3 reports current cursor position */
  352.    pad_$def_pfk(graphics_str,"M3U ","",0,&status); /* just in case M3U does something */
  353.    for(plane=0;plane<=hi_plane;plane++)
  354.     gpr_$set_raster_op(plane,gpr_$rop_not_dst,&status);  /* so that horiz_line below uses XOR */
  355.    if(hi_plane==7){ /* 8 plane colour display */
  356.        /* first 16 colours are used by DM, so we'll use remaining 240,
  357.           mapping intensities in the range 0..255 to entries 16..255 */
  358.        gpr_$inq_color_map( 0, 256, colour_map, &status );
  359.        for(i=16;i<=255;i++){
  360.            intense = (255*(i-16)/240);
  361.            colour_map[i] = (intense << 16) + (intense << 8) + intense;
  362.        }
  363.        gpr_$acquire_display(&status);
  364.        gpr_$set_color_map( 0, 256, colour_map, &status );
  365.        gpr_$release_display(&status);
  366.    }
  367. }
  368.  
  369.  
  370. void
  371. disp_finish()                  /* called from main prior to exit. */
  372. {
  373.     gpr_$terminate(false,&status);
  374. }
  375.  
  376.  
  377. void
  378. disp_imgstart()                /* called prior to drawing an image. */
  379. {
  380. }
  381.  
  382.  
  383. void
  384. disp_imgend()                  /* called after drawing an image. */
  385. {
  386. }
  387.  
  388.  
  389. void
  390. disp_putline(lines, y)        /* called to draw image scanline y. */
  391. pixel_t **lines;
  392. int y;
  393. {
  394.   linteger pixel_array[2000];
  395.   pixel_t *line;
  396.   static gpr_$window_t                  scanline = {{0,0},{1,1}};
  397.   int x;
  398.  
  399.   line = ntsc_luma(lines);
  400.   for (x=0;x<Xsize;x++){
  401.     if (hi_plane==7){
  402.         pixel_array[x] = (gpr_$pixel_value_t) line[x]*240/256 +16;
  403.     } else {
  404.         pixel_array[x] = !(line[x] >= dither[y % RES][x % RES]);
  405.     }
  406.   }
  407.   scanline.window_size.y_size = (short)1;
  408.   scanline.window_size.x_size = (short)Xsize;
  409.   scanline.window_base.y_coord = (short)y;
  410.   gpr_$set_obscured_opt(gpr_$pop_if_obs,&status);
  411.   gpr_$acquire_display(&status); check("acquiring display");
  412.   gpr_$write_pixels((gpr_$pixel_value_t *)pixel_array,scanline,&status); check("write pixels");
  413.   gpr_$release_display(&status); 
  414. }
  415.  
  416.  
  417. disp_getchar()                 /* get next user typed character. */
  418. {
  419.   return(getchar());
  420. }
  421.  
  422.  
  423. disp_prompt()                  /* display popi prompt. */
  424. {
  425.   PRINTF("-> ");
  426.   return 3;
  427. }
  428.  
  429.  
  430. void
  431. disp_error(errtype, pos)            /* display error message. */
  432. int    errtype,
  433.     pos;
  434. {
  435.     extern int  errno;
  436.     extern char *sys_errlist[];
  437.  
  438.     if (errtype & ERR_PARSE)
  439.     {
  440.         int     i;
  441.  
  442.         for (i=1; i < pos; ++i)
  443.             PUTC('-', stderr);
  444.         PUTC('^', stderr);
  445.         PUTC('\n', stderr);
  446.     }
  447.  
  448.     FPRINTF(stderr, "%s\n", ErrBuf);
  449.     /* we assume errno hasn't been reset by the preceding output */
  450.     if (errtype & ERR_SYS)
  451.         FPRINTF(stderr, "\t(%s)\n", sys_errlist[errno]);
  452. }
  453.  
  454. void horiz_line(percent)
  455. int percent;
  456. /* draw a horizontal line percent % of the way down */
  457. {
  458. #define MAX_WINDOWS 50
  459.     gpr_$window_t vis_list[MAX_WINDOWS];
  460.     int i;
  461.     short int slots_total;
  462.     short int x,y;
  463.  
  464.     y = Ysize * percent / 100;
  465.     x = Xsize;
  466.  
  467.     gpr_$set_obscured_opt(gpr_$ok_if_obs,&status);
  468.     gpr_$acquire_display(&status); check("acquiring display");
  469.     gpr_$inq_vis_list (MAX_WINDOWS, &slots_total, vis_list, &status); check("inq vis list");
  470.     for(i=0; i<slots_total; i++){
  471.       gpr_$set_clip_window (vis_list[i], &status) ; check("set clip window");
  472.       gpr_$move(0,y,&status);
  473.       gpr_$line(x,y,&status);
  474.     }
  475.     gpr_$release_display(&status);
  476. }
  477.  
  478.  
  479.  
  480. void
  481. disp_percentdone(percent)                
  482. int    percent;                             
  483. {                                        
  484.     static int    lastpercent = 100;
  485.                                          
  486.     if (percent != lastpercent){
  487.         horiz_line(percent);
  488.     if(!(percent == 0 || percent == 100))
  489.         horiz_line(lastpercent);
  490.     lastpercent = percent;                  
  491.     }                                    
  492. }                                        
  493.  
  494. Funky_Stuff
  495. len=`wc -c < apollo.c`
  496. if [ $len !=     7977 ] ; then
  497. echo error: apollo.c was $len bytes long, should have been     7977
  498. fi
  499. fi # end of overwriting check
  500. if [ -f atariterm.c ]
  501. then
  502. echo shar: will not over-write existing file atariterm.c
  503. else
  504. echo shar: extracting 'atariterm.c',     4119 characters
  505. cat > atariterm.c <<'Funky_Stuff'
  506. /*LINTLIBRARY*/
  507.  
  508. /*  @(#)atariterm.c 1.2 90/12/28
  509.  *
  510.  *  Popi graphics driver for atari TERM windows.
  511.  *  Written by Stephen Frede, Softway Pty Ltd.
  512.  *
  513.  *  Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
  514.  *  This version is based on the code in his Prentice Hall book,
  515.  *  "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
  516.  *  which is copyright (c) 1988 by Bell Telephone Laboratories, Inc. 
  517.  *
  518.  *  Permission is given to distribute these extensions, as long as these
  519.  *  introductory messages are not removed, and no monies are exchanged.
  520.  *
  521.  *  No responsibility is taken for any errors or inaccuracies inherent
  522.  *  either to the comments or the code of this program, but if reported
  523.  *  (see README file) then an attempt will be made to fix them.
  524.  */
  525.  
  526.  
  527. #include <stdio.h>
  528. #include <sys/types.h>
  529. #include "popi.h"
  530.  
  531. thresh[BITSPERPIXEL][BITSPERPIXEL] =
  532. {        /* Array containing threshold values. */
  533.     {   0, 128,  32, 160,   8, 136,  40, 168, },
  534.     { 192,  64, 224,  96, 200,  72, 232, 104, },
  535.     {  48, 176,  16, 144,  56, 184,  24, 152, },
  536.     { 240, 112, 208,  80, 248, 120, 216,  88, },
  537.     {  12, 140,  44, 172,   4, 132,  36, 164, },
  538.     { 204,  76, 236, 108, 196,  68, 228, 100, },
  539.     {  60, 188,  28, 156,  52, 180,  20, 148, },
  540.     { 252, 124, 220,  92, 244, 116, 212,  84, },
  541. };
  542.  
  543. int    ImgInProgress = 0;
  544.  
  545. /*  These are the exportable routines used by the popi program.
  546.  *
  547.  *  disp_init(argc, argv)    - called from main at the start.
  548.  *  disp_finish()            - called from main prior to exit.
  549.  *  disp_imgstart()          - called prior to drawing an image.
  550.  *  disp_imgend()            - called after drawing an image.
  551.  *  disp_putline(lines, y)   - to draw an image scanline triple.
  552.  *  disp_getchar()           - to get the next character typed.
  553.  *  disp_prompt()            - display popi prompt and clear input buffer.
  554.  *  disp_error(errtype)      - display error message.
  555.  *  disp_percentdone(n)      - display percentage value of conversion.
  556.  */
  557.  
  558. /*ARGSUSED*/
  559. void
  560. disp_init(argc,argv)
  561. int argc;
  562. char *argv[];
  563. {
  564. }
  565.  
  566. void
  567. disp_finish()
  568. {
  569. }
  570.  
  571. void
  572. disp_imgstart()
  573. {
  574.     ImgInProgress = 1;
  575.  
  576.     putchar('\033');
  577.     putchar('[');
  578.     putchar('?');
  579.     putchar('3');
  580.     putchar('2');
  581.     putchar('h');
  582.     putchar('\033');
  583.     putchar('[');
  584.     putchar('2');
  585.     putchar('J');
  586.     putchar('\033');
  587.     putchar('[');
  588.     putchar(';');
  589.     putchar('H');
  590. }
  591.  
  592. void
  593. disp_imgend()
  594. {
  595.     ImgInProgress = 0;
  596.  
  597.     putchar('\033');
  598.     putchar('[');
  599.     putchar('?');
  600.     putchar('3');
  601.     putchar('2');
  602.     putchar('l');
  603. }
  604.  
  605. void
  606. disp_putline(lines, y)                     /* Output scanline y. */
  607. pixel_t **lines;
  608. int y;
  609. {
  610.     int x;
  611.     short wd;
  612.     int bit;
  613.     pixel_t *line;
  614.  
  615.     line = ntsc_luma(lines);
  616.     for (x = 0; x < Xsize;)
  617.     {
  618.     wd = 0;
  619.     for (bit = 15; bit >= 0; --bit, ++x)
  620.         if (*line++ < thresh[y % BITSPERPIXEL][x % BITSPERPIXEL])
  621.         wd |= 1 << bit;
  622.     putchar('0' + ((wd >> 10) & 0x3f));
  623.     putchar('0' + ((wd >> 5) & 0x1f));
  624.     putchar('0' + (wd & 0x1f));
  625.     }
  626.     putchar('\n');
  627. }
  628.  
  629.  
  630. disp_getchar()          /* Get next user typed character. */
  631. {
  632.     return(getchar());
  633. }
  634.  
  635.  
  636. disp_prompt()         /* Display popi prompt and clear input line. */
  637. {
  638.     PRINTF("-> ");
  639.     return 3;
  640. }
  641.  
  642.  
  643. void
  644. disp_error(errtype, pos)         /* Display error message. */
  645. int    errtype,
  646.     pos;
  647. {
  648.     extern int  errno;
  649.     extern char *sys_errlist[];
  650.  
  651.     if (errtype & ERR_PARSE)
  652.     {
  653.         int     i;
  654.  
  655.         for (i=1; i < pos; ++i)
  656.             PUTC('-', stderr);
  657.         PUTC('^', stderr);
  658.         PUTC('\n', stderr);
  659.     }
  660.  
  661.     FPRINTF(stderr, "%s\n", ErrBuf);
  662.     /* we assume errno hasn't been reset by the preceding output */
  663.     if (errtype & ERR_SYS)
  664.         FPRINTF(stderr, "\t(%s)\n", sys_errlist[errno]);
  665. }
  666.  
  667. void
  668. disp_percentdone(percent)
  669. int    percent;
  670. {
  671.     static int    lastpercent = 100;
  672.  
  673.     if (!Verbose || ImgInProgress)
  674.     return;
  675.  
  676.     if (percent == 100)
  677.     {
  678.     printf("\r    \r");
  679.     return;
  680.     }
  681.  
  682.     if
  683.     (
  684.     percent != lastpercent
  685.     /* && percent % 5 == 0 */
  686.     )
  687.     {
  688.     printf("\r%2d%% ", percent);
  689.     fflush(stdout);
  690.     lastpercent = percent;
  691.     }
  692. }
  693. Funky_Stuff
  694. len=`wc -c < atariterm.c`
  695. if [ $len !=     4119 ] ; then
  696. echo error: atariterm.c was $len bytes long, should have been     4119
  697. fi
  698. fi # end of overwriting check
  699. if [ -f graphics.c ]
  700. then
  701. echo shar: will not over-write existing file graphics.c
  702. else
  703. echo shar: extracting 'graphics.c',     8522 characters
  704. cat > graphics.c <<'Funky_Stuff'
  705.  
  706. /*  @(#)graphics.c 1.3 91/08/20
  707.  *
  708.  *  Independent graphics routines associated with the popi program.
  709.  *
  710.  *  Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
  711.  *  This version is based on the code in his Prentice Hall book,
  712.  *  "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
  713.  *  which is copyright (c) 1988 by Bell Telephone Laboratories, Inc. 
  714.  *
  715.  *  Permission is given to distribute these extensions, as long as these
  716.  *  introductory messages are not removed, and no monies are exchanged.
  717.  *
  718.  *  No responsibility is taken for any errors or inaccuracies inherent
  719.  *  either to the comments or the code of this program, but if reported
  720.  *  (see README file) then an attempt will be made to fix them.
  721.  */
  722.  
  723. #include "popi.h"
  724. #include "graphics.h"
  725.  
  726. char nextline[MAXLINE] ;          /* Next input line to be parsed. */
  727.  
  728. int errpos = -1 ;         /* Character position error occured at. */
  729. int iscolor ;             /* Set if this is a color screen. */
  730. int ix = 0 ;              /* Initial X position of the icon. */
  731. int iy = 0 ;              /* Initial Y position of the icon. */
  732. int nfont_width ;         /* Width of normal font characters. */
  733. int ops[MAXOPS] ;         /* Rasterop functions. */
  734. int posspec = 0 ;         /* Set if -g option is present (for X11) */
  735. int started = 0 ;         /* Set if we've drawn the percent dialog box. */
  736. int tptr = 0 ;            /* Input buffer pointer. */
  737. int wx = 0 ;              /* Initial X position of the open window. */
  738. int wy = 0 ;              /* Initial Y position of the open window. */
  739.  
  740. extern int  errno ;
  741. extern char *sys_errlist[] ;
  742.  
  743.  
  744. /*  These are the exportable routines used by the popi program.
  745.  *
  746.  *  disp_init(argc, argv)    - called from main at the start.
  747.  *  disp_finish()            - called from main prior to exit.
  748.  *  disp_imgstart()          - called prior to drawing an image.
  749.  *  disp_imgend()            - called after drawing an image.
  750.  *  disp_putline(lines, y)   - to draw an image scanline triple.
  751.  *  disp_getchar()           - to get the next character typed.
  752.  *  disp_prompt()            - display popi prompt and clear input buffer.
  753.  *  disp_error(errtype, pos) - display error message.
  754.  *  disp_percentdone(n)      - display percentage value of conversion.
  755.  */
  756.  
  757.  
  758. void
  759. disp_init(argc, argv)        /* Called from main at the start. */
  760. int argc ;
  761. char *argv[] ;
  762. {
  763.   if (init_ws_type())        /* Determine window system type. */
  764.     {
  765.       FPRINTF(stderr, "Error initialising window system.\n") ;
  766.       exit(1) ;
  767.     }
  768.   init_dither() ;            /* Initialise dither arrays and variables. */
  769.   init_fonts() ;             /* Open required fonts. */
  770.   make_items(argc, argv) ;   /* Create icon, frame, canvas etc.. */
  771.   paint_canvas() ;           /* Draw dialog boxes. */
  772.   start_tool() ;
  773. }
  774.  
  775.  
  776. void
  777. disp_finish()                /* Called from main prior to exit. */
  778. {
  779.   cleanup() ;
  780. }
  781.  
  782.  
  783. void
  784. disp_imgstart()              /* Called prior to drawing an image. */
  785. {
  786. }
  787.  
  788.  
  789. void
  790. disp_imgend()                /* Called after drawing an image. */
  791. {
  792. }
  793.  
  794.  
  795. void
  796. disp_putline(lines, y)        /* Draw an image scanline triple. */
  797. unsigned char **lines ;
  798. int y ;
  799. {
  800.   draw_scanline(lines, y) ;
  801. }
  802.  
  803.  
  804. disp_getchar()       /* Get next user typed character. */
  805. {
  806.   char c ;
  807.   int finished = 0 ;
  808.   int len ;
  809.  
  810.   if (tptr >= strlen(nextline))
  811.     {
  812.       while (!finished)
  813.         {
  814.           get_next_char(&c) ;              /* Get next character typed. */
  815.           if (c == '\0') continue ;
  816.           if (errpos != -1)
  817.             {
  818.               drawarea(BOXX+100+errpos*nfont_width, BOXY+BOXH-9,
  819.                        nfont_width, 4, GCLR) ;
  820.               drawarea(BOXX+91, BOXY+51, BOXW-102, BOXH-22, GCLR) ;
  821.               errpos = -1 ;
  822.             }
  823.           if (c == BACKSPACE || c == DEL)
  824.             {
  825.               len = strlen(nextline) ;
  826.               if (len) nextline[len-1] = '\0' ;
  827.             }
  828.           else if (c == RETURN || c == LINEFEED)
  829.             {
  830.               set_cursor(BUSY_CUR) ;       /* We will now get busy! */
  831.               c = '\n' ;
  832.               STRNCAT(nextline, &c, 1) ;
  833.               finished = 1 ;
  834.             }
  835.           else if (c >= 32) STRNCAT(nextline, &c, 1) ;
  836.           drawarea(BOXX+91, BOXY+11, BOXW-102, BOXH-22, GCLR) ;
  837.           put_text(BOXX, BOXY, BOXW, BOXH, nextline, 1) ;
  838.         }
  839.       tptr = 0 ;
  840.     }    
  841.   return(nextline[tptr++]) ;
  842. }
  843.  
  844.  
  845. /*  Show the percentage of the image converted as a graphical slider using
  846.  *  the error dialog box. If the percentage is zero, then we are just starting,
  847.  *  so the box is relabeled (to % done:). If the percentage is 100, then we
  848.  *  are just finishing, and the box is relabel back (to Error:), and cleared.
  849.  *  If the percent value is the same as last time we immediately return,
  850.  *  otherwise we show an intermediate percentage value.
  851.  */
  852.  
  853. void
  854. disp_percentdone(percent)
  855. int percent ;
  856. {
  857.   static int    opercent = -1 ;       /* Previous display percent done value. */
  858.   if (percent == opercent) return ;    /* Same as last time? */
  859.   opercent = percent ;
  860.   if (!percent)
  861.     {
  862.       if (!started)
  863.         draw_textbox(BOXX, BOXY+40, BOXW, BOXH, "% done:", "", 0) ;
  864.       started = 1 ;
  865.     }
  866.   else if (percent == 100)
  867.     {
  868.       if (started)
  869.         draw_textbox(BOXX, BOXY+40, BOXW, BOXH, "Error:", "", 0) ;
  870.       started = 0 ;
  871.     }
  872.   else
  873.     drawarea(BOXX+91, BOXY+51,
  874.              (int) ((double) (BOXW-102) / 100 * percent), BOXH-20, GSET) ;
  875. }
  876.  
  877.  
  878. disp_prompt()        /* Display popi prompt and clear input line. */
  879. {
  880.   set_cursor(NORMAL_CUR) ;
  881.   if (errpos == -1) drawarea(BOXX+91, BOXY+11, BOXW-102, BOXH-22, GCLR) ;
  882.   STRCPY(nextline, "") ;
  883.   tptr = 0 ;
  884.   return 0 ;
  885. }
  886.  
  887.  
  888. void
  889. disp_error(errtype, pos)    /* Display error message. */
  890. int errtype ;
  891. int pos ;
  892. {
  893.   errpos = pos ;
  894.   if (errtype & ERR_PARSE)
  895.     drawarea(BOXX+100+errpos*nfont_width, BOXY+BOXH-9,
  896.              nfont_width, 4, GSET) ;
  897.  
  898.   put_text(BOXX, BOXY+40, BOXW, BOXH, ErrBuf, 0) ;
  899.  
  900. /*  We assume errno hasn't been reset by the preceding output */
  901.  
  902.   if (errtype & ERR_SYS)
  903.     {
  904.       sleep(2) ;
  905.       SPRINTF(ErrBuf, "\t(%s)\n", sys_errlist[errno]) ;
  906.       drawarea(BOXX+91, BOXY+51, BOXW-102, BOXH-22, GCLR) ;
  907.       put_text(BOXX, BOXY+40, BOXW, BOXH, ErrBuf, 0) ;
  908.     }
  909. }
  910.  
  911. /* These are other independent graphics routines used by popi. */
  912.  
  913. draw_frame(x, y, width, height)
  914. int x, y, width, height ;
  915. {
  916.   drawarea(x,   y,   width,    height,    GSET) ;
  917.   drawarea(x+1, y+1, width-2,  height-2,  GCLR) ;
  918.   drawarea(x+3, y+3, width-6,  height-6,  GSET) ;
  919.   drawarea(x+5, y+5, width-10, height-10, GCLR) ;
  920. }
  921.  
  922.  
  923. /*  Display a text box of given width and height with top left corner at
  924.  *  the given x,y location, displaying a title and the given text value.
  925.  */
  926.  
  927. draw_textbox(x, y, w, h, title, str, showcur)
  928. int x, y, w, h, showcur ;
  929. char *title, *str ;
  930. {
  931.   draw_frame(x, y, w, h) ;
  932.   drawtext(x+10, y+h-15, BFONT, title) ;
  933.   draw_rect(x+90, y+10, x+w-10, y+h-10) ;
  934.   put_text(x, y, w, h, str, showcur) ;
  935. }
  936.  
  937.  
  938. draw_rect(x1, y1, x2, y2)
  939. int x1, y1, x2, y2 ;
  940. {
  941.   drawline(x1, y1, x2, y1) ;
  942.   drawline(x1, y1, x1, y2) ;
  943.   drawline(x2, y1, x2, y2) ;
  944.   drawline(x1, y2, x2, y2) ;
  945. }
  946.  
  947.  
  948. /*  Paint the contents of the popi canvas. This consists of first clearing
  949.  *  the whole canvas, then drawing a line to distinguish between the image
  950.  *  drawing area and the command feedback area. Two text boxes are then
  951.  *  drawn, one for user input and the other to shown any error messages.
  952.  */
  953.  
  954. paint_canvas()
  955. {
  956.   drawarea(0, 0, TXsize, TYsize, GCLR) ;
  957.   drawline(0, 99, TXsize, 99) ;
  958.   if (Xsize < TXsize)
  959.     drawline(Xsize, 100, Xsize, TYsize) ;
  960.   draw_textbox(BOXX, BOXY,    BOXW, BOXH, "Command:", nextline, 1) ;
  961.   draw_textbox(BOXX, BOXY+40, BOXW, BOXH, "Error:",   "",       0) ;
  962. }
  963.  
  964.  
  965. /*  With the screen based window systems, display the character string
  966.  *  str at the given x,y location. The width of the dialog box is given,
  967.  *  so that if the text exceeds the displayable area, it is scrolled to
  968.  *  the left. A soft cursor in the form of a vertical line is shown if
  969.  *  so requested.
  970.  */
  971.  
  972. put_text(x, y, w, h, str, showcur)
  973. int x, y, w, h ;
  974. char *str ;
  975. {
  976.   char dummy[MAXLINE] ;
  977.   int limit, nochars ;
  978.  
  979.   limit = ((w - 100) / nfont_width) - 1 ;
  980.   nochars = (strlen(str) <= limit) ? strlen(str) : limit ;
  981.   STRNCPY(dummy, &str[strlen(str) - nochars], nochars) ;
  982.  
  983.   dummy[nochars] = '\0' ;
  984.   drawtext(x+100, y+h-17, NFONT, dummy) ;
  985.   if (showcur)
  986.     drawline(x+100+strlen(dummy)*nfont_width, y+15,
  987.              x+100+strlen(dummy)*nfont_width, y+h-15) ;
  988. }
  989. Funky_Stuff
  990. len=`wc -c < graphics.c`
  991. if [ $len !=     8522 ] ; then
  992. echo error: graphics.c was $len bytes long, should have been     8522
  993. fi
  994. fi # end of overwriting check
  995. if [ -f hp.c ]
  996. then
  997. echo shar: will not over-write existing file hp.c
  998. else
  999. echo shar: extracting 'hp.c',     4044 characters
  1000. cat > hp.c <<'Funky_Stuff'
  1001. /*LINTLIBRARY*/
  1002.  
  1003. /*  @(#)hp.c 1.1 90/12/12
  1004.  *
  1005.  *  Popi device driver for an HP 8+ plane display.
  1006.  *  Written by Eric Haines - 3D/Eye Inc, Ithaca, NY
  1007.  *
  1008.  *  Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
  1009.  *  This version is based on the code in his Prentice Hall book,
  1010.  *  "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
  1011.  *  which is copyright (c) 1988 by Bell Telephone Laboratories, Inc. 
  1012.  *
  1013.  *  Permission is given to distribute these extensions, as long as these
  1014.  *  introductory messages are not removed, and no monies are exchanged.
  1015.  *
  1016.  *  No responsibility is taken for any errors or inaccuracies inherent
  1017.  *  either to the comments or the code of this program, but if reported
  1018.  *  (see README file) then an attempt will be made to fix them.
  1019.  */
  1020.  
  1021. #include "popi.h"
  1022. #include "graphics.h"
  1023. #include <starbase.c.h>
  1024.  
  1025. /*  These are the exportable routines used by the popi program.
  1026.  *
  1027.  *  disp_init(argc, argv)    - called from main at the start.
  1028.  *  disp_finish()            - called from main prior to exit.
  1029.  *  disp_imgstart()          - called prior to drawing an image.
  1030.  *  disp_imgend()            - called after drawing an image.
  1031.  *  disp_putline(line, y)    - to draw an image scanline.
  1032.  *  disp_getchar()           - to get the next character typed.
  1033.  *  disp_prompt()            - display popi prompt and clear input buffer.
  1034.  *  disp_error(errtype)      - display error message.
  1035.  *  disp_percentdone(n)      - display percentage value of conversion.
  1036.  */
  1037.  
  1038. extern char *getenv();
  1039.  
  1040. /* Set environment variables OUTDEV and OUTDRIVER or change the
  1041.  * defaults to your machine.
  1042.  */
  1043. char    default_outdev[] = "/dev/hp98721" ;
  1044. char    default_outdriver[] = "hp98721" ;
  1045. char    default_indev[] = "/dev/hil2" ;
  1046. char    default_indriver[] = "hp-hil" ;
  1047.  
  1048. int    fd ;
  1049.  
  1050. void
  1051. disp_init(argc,argv)           /* called from main at the start. */
  1052. int argc;
  1053. char *argv[];
  1054. {
  1055.     fd = devopen(OUTDEV,INIT) ;
  1056.     if ( fd == -1 ) {
  1057.     printf("error opening output device\n" ) ;
  1058.     exit(1) ;
  1059.     }
  1060.     vdc_extent( fd, 0.0, 0.0, 0.0, 1.25, 1.0, 1.0 ) ;
  1061.     shade_mode( fd, CMAP_MONOTONIC | INIT, 0 ) ;
  1062.     make_picture_current( fd ) ;
  1063. }
  1064.  
  1065.  
  1066. void
  1067. disp_finish()                  /* called from main prior to exit. */
  1068. {
  1069.     gclose( fd ) ;
  1070. }
  1071.  
  1072.  
  1073. void
  1074. disp_imgstart()                /* called prior to drawing an image. */
  1075. {
  1076. }
  1077.  
  1078.  
  1079. void
  1080. disp_imgend()                  /* called after drawing an image. */
  1081. {
  1082. }
  1083.  
  1084.  
  1085. void
  1086. disp_putline(line, y)        /* called to draw image scanline y. */
  1087. pixel_t *line;
  1088. int y;
  1089. {
  1090.     dcblock_write( fd, 0,y,Xsize,1,line,0) ;
  1091. }
  1092.  
  1093.  
  1094. disp_getchar()                 /* get next user typed character. */
  1095. {
  1096.   return(getchar());
  1097. }
  1098.  
  1099.  
  1100. disp_prompt()                  /* display popi prompt. */
  1101. {
  1102.   PRINTF("-> ");
  1103.   return 3;
  1104. }
  1105.  
  1106.  
  1107. void
  1108. disp_error(errtype, pos)            /* display error message. */
  1109. int    errtype,
  1110.     pos;
  1111. {
  1112.     extern int  errno;
  1113.     extern char *sys_errlist[];
  1114.  
  1115.     if (errtype & ERR_PARSE)
  1116.     {
  1117.         int     i;
  1118.  
  1119.         for (i=1; i < pos; ++i)
  1120.             PUTC('-', stderr);
  1121.         PUTC('^', stderr);
  1122.         PUTC('\n', stderr);
  1123.     }
  1124.  
  1125.     fprintf(stderr, "%s\n", ErrBuf);
  1126.     /* we assume errno hasn't been reset by the preceding output */
  1127.     if (errtype & ERR_SYS)
  1128.         fprintf(stderr, "\t(%s)\n", sys_errlist[errno]);
  1129. }
  1130.  
  1131. void
  1132. disp_percentdone(percent)
  1133. int    percent;
  1134. {
  1135.     static int    lastpercent = 100;
  1136.  
  1137.     if (!Verbose)
  1138.     return;
  1139.     if (percent == 100)
  1140.     {
  1141.     printf("\r    \n");
  1142.     return;
  1143.     }
  1144.     if (percent != lastpercent && percent % 5 == 0)
  1145.     {
  1146.     printf("\r%2d%% ", percent);
  1147.     fflush(stdout);
  1148.     lastpercent = percent;
  1149.     }
  1150. }
  1151.  
  1152. int devopen(dev_kind,init_mode)
  1153. int dev_kind,init_mode;
  1154. {
  1155. char    *dev, *driver;
  1156. int    fildes ;
  1157.  
  1158.     if ( dev_kind == OUTDEV ) {
  1159.     dev = getenv("OUTDEV");
  1160.     if (!dev) dev = default_outdev ;
  1161.     driver = getenv("OUTDRIVER");
  1162.     if (!driver) driver = default_outdriver ;
  1163.     } else {
  1164.     dev = getenv("INDEV");
  1165.     if (!dev) dev = default_indev ;
  1166.     driver = getenv("INDRIVER");
  1167.     if (!driver) driver = default_indriver ;
  1168.     }
  1169.  
  1170.     fildes = gopen(dev,dev_kind,driver,init_mode);
  1171.  
  1172.     return(fildes) ;
  1173. }
  1174. Funky_Stuff
  1175. len=`wc -c < hp.c`
  1176. if [ $len !=     4044 ] ; then
  1177. echo error: hp.c was $len bytes long, should have been     4044
  1178. fi
  1179. fi # end of overwriting check
  1180. if [ -f kerterm.c ]
  1181. then
  1182. echo shar: will not over-write existing file kerterm.c
  1183. else
  1184. echo shar: extracting 'kerterm.c',     6197 characters
  1185. cat > kerterm.c <<'Funky_Stuff'
  1186. /*LINTLIBRARY*/
  1187.  
  1188. /*  @(#)kerterm.c 1.2 90/12/28
  1189.  *
  1190.  *  Popi graphics driver for kermit TERM windows.
  1191.  *  written by Frank Crawford - Q.H.Tours.
  1192.  *
  1193.  *  Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
  1194.  *  This version is based on the code in his Prentice Hall book,
  1195.  *  "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
  1196.  *  which is copyright (c) 1988 by Bell Telephone Laboratories, Inc. 
  1197.  *
  1198.  *  Permission is given to distribute these extensions, as long as these
  1199.  *  introductory messages are not removed, and no monies are exchanged.
  1200.  *
  1201.  *  No responsibility is taken for any errors or inaccuracies inherent
  1202.  *  either to the comments or the code of this program, but if reported
  1203.  *  (see README file) then an attempt will be made to fix them.
  1204.  */
  1205.  
  1206.  
  1207. #include <stdio.h>
  1208. #include <signal.h>
  1209. #include <sys/types.h>
  1210. #include "popi.h"
  1211.  
  1212. #define  KER_MAX_X  1023    /* Maximum Kermit X value */
  1213. #define  KER_MAX_Y  779     /* Maximum Kermit Y value */
  1214. #define  PC_MAX_X   640     /* Number of PC X value (EGA Card) */
  1215. #define  PC_MAX_Y   350     /* Number of PC Y value (EGA Card) */
  1216. #define  MAX_GREY   2       /* Max. Greyscale value (Black, Low-int, Hi-int) */
  1217.  
  1218. int thresh[MAX_GREY][BITSPERPIXEL][BITSPERPIXEL] =
  1219. {
  1220.     {        /* Array containing threshold values for low value. */
  1221.       {   0,  64,  16,  80,   4,  68,  20,  84, },
  1222.       {  96,  32, 112,  48, 100,  36, 116,  52, },
  1223.       {  24,  88,   8,  72,  28,  92,  12,  76, },
  1224.       { 120,  56, 104,  40, 124,  60, 108,  44, },
  1225.       {   6,  70,  22,  86,   2,  66,  18,  82, },
  1226.       { 102,  38, 118,  54,  98,  34, 114,  50, },
  1227.       {  30,  94,  14,  78,  26,  90,  10,  74, },
  1228.       { 126,  62, 110,  46, 122,  58, 106,  42, },
  1229.     },
  1230.     {        /* Array containing threshold values for high value. */
  1231.       { 128, 192, 144, 208, 132, 196, 148, 212, },
  1232.       { 224, 160, 240, 176, 228, 164, 244, 180, },
  1233.       { 152, 216, 136, 200, 156, 220, 140, 204, },
  1234.       { 248, 184, 232, 168, 252, 188, 236, 172, },
  1235.       { 134, 198, 150, 214, 130, 194, 146, 210, },
  1236.       { 230, 166, 246, 182, 226, 162, 242, 178, },
  1237.       { 158, 222, 142, 206, 154, 218, 138, 202, },
  1238.       { 254, 190, 238, 174, 250, 186, 234, 170, },
  1239.     },
  1240. };
  1241.  
  1242. /*  These are the exportable routines used by the popi program.
  1243.  *
  1244.  *  disp_init(argc, argv)    - called from main at the start.
  1245.  *  disp_finish()            - called from main prior to exit.
  1246.  *  disp_imgstart()          - called prior to drawing an image.
  1247.  *  disp_imgend()            - called after drawing an image.
  1248.  *  disp_putline(lines, y)   - to draw an image scanline triple.
  1249.  *  disp_getchar()           - to get the next character typed.
  1250.  *  disp_prompt()            - display popi prompt and clear input buffer.
  1251.  *  disp_error(errtype)      - display error message.
  1252.  *  disp_percentdone(n)      - display percentage value of conversion.
  1253.  */
  1254.  
  1255. /*ARGSUSED*/
  1256. void
  1257. disp_init(argc,argv)
  1258. int argc;
  1259. char *argv[];
  1260. {
  1261. }
  1262.  
  1263. void
  1264. disp_finish()
  1265. {
  1266. }
  1267.  
  1268. void
  1269. disp_intr(signal)
  1270. int signal;
  1271. {
  1272.     disp_imgend();
  1273.     exit(signal);
  1274. }
  1275.  
  1276. void
  1277. disp_imgstart()
  1278. {
  1279.     (void) signal(SIGINT, disp_intr);
  1280.     putchar('\033');
  1281.     putchar('\f');
  1282. }
  1283.  
  1284. void
  1285. disp_imgend()
  1286. {
  1287.     char ch;
  1288.  
  1289.     putchar('\033');
  1290.     putchar('[');
  1291.     putchar('0');
  1292.     putchar('m');
  1293.     PRINTF("\037\n\n\007Hit return when ready:");
  1294.     fflush(stdout);
  1295.     while (read(1, &ch, 1) == 1 && ch != '\n')    /* Because of inconsistent use */
  1296.     ;
  1297.     putchar('\033');
  1298.     putchar('[');
  1299.     putchar('?');
  1300.     putchar('3');
  1301.     putchar('8');
  1302.     putchar('l');
  1303.     fflush(stdout);
  1304.     (void) signal(SIGINT, SIG_DFL);
  1305. }
  1306.  
  1307. static void
  1308. coord(x, y, repeat)
  1309. int x, y;
  1310. int repeat;
  1311. {
  1312.     /*
  1313.      * This function goes to a lot of effort to optimes the number of
  1314.      * characters sent down the line.
  1315.      */
  1316.     int hi_x, lo_x, hi_y, lo_y;
  1317.     static int sav_x = -1, sav_y = -1;
  1318.  
  1319.     y = KER_MAX_Y - y;    /* To invert picture */
  1320.     hi_x = (x / 32);
  1321.     lo_x = (x % 32);
  1322.     hi_y = (y / 32);
  1323.     lo_y = (y % 32);
  1324.     if (!repeat || y != sav_y)
  1325.     {
  1326.     putchar(hi_y + 0x20);
  1327.     putchar(lo_y + 0x60);
  1328.     putchar(hi_x + 0x20);
  1329.     }
  1330.     else if (hi_x != (sav_x / 32))
  1331.     {
  1332.     putchar(lo_y + 0x60);
  1333.     putchar(hi_x + 0x20);
  1334.     }
  1335.     putchar(lo_x + 0x40);
  1336.     sav_x = x;
  1337.     sav_y = y;
  1338. }
  1339.  
  1340. void
  1341. disp_putline(lines, y)                     /* Output scanline y. */
  1342. pixel_t **lines;
  1343. int y;
  1344. {
  1345.     int x;
  1346.     int real_x, real_y;
  1347.     int repeat, level;
  1348.     pixel_t *line;
  1349.     static old_level = 0;
  1350.  
  1351.     repeat = 0;
  1352.     line = ntsc_luma(lines);
  1353.     /*
  1354.      * Calculate the real pixel location to handle the grey-scale threshold
  1355.      * values.
  1356.      */
  1357.     real_y = (y * PC_MAX_Y) / (KER_MAX_Y + 1);
  1358.     putchar('\034');
  1359.     for (x = 0; x < Xsize; x++, line++)
  1360.     {
  1361.       /* See above */
  1362.       real_x = (x * PC_MAX_X) / (KER_MAX_X + 1);
  1363.       for (level = 0; level < MAX_GREY; level++)
  1364.           if (*line < thresh[level][real_y % BITSPERPIXEL][real_x % BITSPERPIXEL])
  1365.               break;
  1366.     if (level != old_level)
  1367.     {
  1368.         if (level != 0)
  1369.         {
  1370.         putchar('\033');
  1371.         putchar('[');
  1372.         putchar((level == 1) ? '0' : '1');
  1373.         putchar('m');
  1374.         }
  1375.         old_level = level;
  1376.     }
  1377.     if (level != 0)
  1378.         coord(x, y, repeat++);
  1379.     }
  1380.     putchar('\n');
  1381. }
  1382.  
  1383.  
  1384. disp_getchar()          /* Get next user typed character. */
  1385. {
  1386.     return(getchar());
  1387. }
  1388.  
  1389.  
  1390. disp_prompt()         /* Display popi prompt and clear input line. */
  1391. {
  1392.     PRINTF("-> ");
  1393.     return 3;
  1394. }
  1395.  
  1396.  
  1397. void
  1398. disp_error(errtype, pos)         /* Display error message. */
  1399. int errtype, pos ;
  1400. {
  1401.     extern int  errno;
  1402.     extern char *sys_errlist[];
  1403.  
  1404.     if (errtype & ERR_PARSE)
  1405.     {
  1406.         int     i;
  1407.  
  1408.         for (i=1; i < pos; ++i)
  1409.             PUTC('-', stderr);
  1410.         PUTC('^', stderr);
  1411.         PUTC('\n', stderr);
  1412.     }
  1413.  
  1414.     FPRINTF(stderr, "%s\n", ErrBuf);
  1415.     /* we assume errno hasn't been reset by the preceding output */
  1416.     if (errtype & ERR_SYS)
  1417.         FPRINTF(stderr, "\t(%s)\n", sys_errlist[errno]);
  1418. }
  1419.  
  1420. void
  1421. disp_percentdone(percent)
  1422. int    percent;
  1423. {
  1424.     static int    lastpercent = 100;
  1425.  
  1426.     if (!Verbose)
  1427.     return;
  1428.     if (percent == 100)
  1429.     {
  1430.     printf("\r    \n");
  1431.     return;
  1432.     }
  1433.     if (percent != lastpercent && percent % 5 == 0)
  1434.     {
  1435.     printf("\r%2d%% ", percent);
  1436.     fflush(stdout);
  1437.     lastpercent = percent;
  1438.     }
  1439. }
  1440. Funky_Stuff
  1441. len=`wc -c < kerterm.c`
  1442. if [ $len !=     6197 ] ; then
  1443. echo error: kerterm.c was $len bytes long, should have been     6197
  1444. fi
  1445. fi # end of overwriting check
  1446. exit 0 # Just in case...
  1447.