home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1719 / rasterfil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  2.6 KB  |  136 lines

  1. /*
  2.     rasterfil a printcap filter for printing rasterfile format.
  3.  
  4.     Written by Brian Utterback
  5.     December 1987
  6.  
  7. */
  8.  
  9.  
  10. #include <stdio.h>
  11. #include <assert.h>
  12. #include <varargs.h>
  13. #include <sys/types.h>
  14. #include <pixrect/pixrect_hs.h>
  15.  
  16.  
  17. main(argc, argv)
  18. int argc;
  19. char *argv[];
  20. {
  21.     Pixrect *pr, *mpr;
  22.     struct rasterfile rh;
  23.     colormap_t colormap;
  24.     int i,lineby, l,maxbytes,numlines;
  25.         int npages=2;
  26.     char *dd;
  27.     int atoi();
  28.     int xwidth;
  29.     FILE *fopen(), *fp;
  30.     char *cp;
  31.     char *logi,*host,*actf;
  32.  
  33.     while (--argc) {
  34.         if (*(cp = *++argv) == '-' ) {
  35.             switch (cp[1]) {
  36.             case 'x':
  37.                 xwidth = atoi(&cp[2]);
  38.                 break;
  39.  
  40.             case 'y':
  41.                 /* don't do anything with y */
  42.                 break;
  43.  
  44.             case 'n':
  45.                 logi = argv[1];
  46.                 break;
  47.  
  48.             case 'h':
  49.                 host = argv[1];
  50.                 actf = argv[2];
  51.                 break;
  52.             }
  53.         }
  54.     };
  55.  
  56.  
  57.     if ((fp = fopen(actf,"a")) == NULL ) {
  58.         fprintf(stderr,
  59.             "Rasterfilter: Can't open %s\n", actf);
  60.         exit(1);
  61.     };
  62.     fprintf(fp,"%7.2f\t%s:%s\n",(float)npages,host,logi);
  63.     fclose(fp);
  64.  
  65.     /*
  66.      * Load the rasterfile header and check if the input file
  67.      * is in the standard format or the format we are supposed
  68.      * to be able to convert.
  69.      */
  70.     if (pr_load_header(stdin, &rh)) {
  71.         fprintf(stderr,
  72.             "Rasterfilter: unable to load header:%d\n",
  73.             PR_IO_ERR_RASREAD);
  74.         exit(2);
  75.     };
  76.  
  77.     switch (rh.ras_type) {
  78.     case RT_STANDARD:
  79.         case RT_BYTE_ENCODED:
  80.         break;
  81.  
  82.     default:
  83.         fprintf(stderr,
  84.             "Rasterfilter: incorrect type %d\n", rh.ras_type);
  85.         exit(2);
  86.     }
  87.  
  88.     /* load the colormap and image */
  89.     colormap.type = RMT_NONE;
  90.     if (pr_load_colormap(stdin, &rh, &colormap) ||
  91.         !(pr = pr_load_image(stdin, &rh, &colormap))) {
  92.         fprintf(stderr,
  93.             "Rasterfilter: unable to load image:%d\n",
  94.                 PR_IO_ERR_RASREAD);
  95.  
  96.         exit(2);
  97.     };
  98.  
  99.     /* Make the memory pixrect */
  100.     mpr = mem_create(pr->pr_size.x,1,1);
  101.     
  102.     /* reset the printer */
  103.     printf("\033E");
  104.     /* position the cursor */
  105.     printf("\033*p0x0Y");    
  106.     /* set the resolution */
  107.     if (xwidth == 0 ) xwidth = 1200;
  108.     maxbytes = xwidth / 8;
  109.     numlines = maxbytes * 11;
  110.     printf("\033*t%dR",maxbytes);
  111.     /* set the graphics margin */
  112.     printf("\033*r1A");
  113.     fflush(stdout);
  114.  
  115.     /* for each row in the pixrect, transfer the data to the printer */
  116.     numlines = (numlines < pr->pr_size.y) ? numlines : pr->pr_size.y;
  117.     for (i = 0; i < numlines ; i++ ) {
  118.         pr_rop(mpr, 0, 0, pr->pr_size.x,1, PIX_SRC, pr,0,i);
  119.         /* set up the transfer */
  120.         printf("\033*b");
  121.         /* get the number of bytes */
  122.         lineby = mpr_mdlinebytes(mpr);
  123.         lineby = (lineby > maxbytes) ? maxbytes : lineby;
  124.          printf("%dW",lineby);
  125.         /* write out the bytes */
  126.         l = fwrite((char *)(mpr_d(mpr)->md_image),sizeof(*dd),
  127.              lineby,stdout);
  128.         assert(l==lineby);
  129.     };
  130.     printf("\033*rB");
  131.     printf("\033E");
  132.  
  133.     exit(0);
  134. }
  135.  
  136.