home *** CD-ROM | disk | FTP | other *** search
- /*
- rasterfil a printcap filter for printing rasterfile format.
-
- Written by Brian Utterback
- December 1987
-
- */
-
-
- #include <stdio.h>
- #include <assert.h>
- #include <varargs.h>
- #include <sys/types.h>
- #include <pixrect/pixrect_hs.h>
-
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- Pixrect *pr, *mpr;
- struct rasterfile rh;
- colormap_t colormap;
- int i,lineby, l,maxbytes,numlines;
- int npages=2;
- char *dd;
- int atoi();
- int xwidth;
- FILE *fopen(), *fp;
- char *cp;
- char *logi,*host,*actf;
-
- while (--argc) {
- if (*(cp = *++argv) == '-' ) {
- switch (cp[1]) {
- case 'x':
- xwidth = atoi(&cp[2]);
- break;
-
- case 'y':
- /* don't do anything with y */
- break;
-
- case 'n':
- logi = argv[1];
- break;
-
- case 'h':
- host = argv[1];
- actf = argv[2];
- break;
- }
- }
- };
-
-
- if ((fp = fopen(actf,"a")) == NULL ) {
- fprintf(stderr,
- "Rasterfilter: Can't open %s\n", actf);
- exit(1);
- };
- fprintf(fp,"%7.2f\t%s:%s\n",(float)npages,host,logi);
- fclose(fp);
-
- /*
- * Load the rasterfile header and check if the input file
- * is in the standard format or the format we are supposed
- * to be able to convert.
- */
- if (pr_load_header(stdin, &rh)) {
- fprintf(stderr,
- "Rasterfilter: unable to load header:%d\n",
- PR_IO_ERR_RASREAD);
- exit(2);
- };
-
- switch (rh.ras_type) {
- case RT_STANDARD:
- case RT_BYTE_ENCODED:
- break;
-
- default:
- fprintf(stderr,
- "Rasterfilter: incorrect type %d\n", rh.ras_type);
- exit(2);
- }
-
- /* load the colormap and image */
- colormap.type = RMT_NONE;
- if (pr_load_colormap(stdin, &rh, &colormap) ||
- !(pr = pr_load_image(stdin, &rh, &colormap))) {
- fprintf(stderr,
- "Rasterfilter: unable to load image:%d\n",
- PR_IO_ERR_RASREAD);
-
- exit(2);
- };
-
- /* Make the memory pixrect */
- mpr = mem_create(pr->pr_size.x,1,1);
-
- /* reset the printer */
- printf("\033E");
- /* position the cursor */
- printf("\033*p0x0Y");
- /* set the resolution */
- if (xwidth == 0 ) xwidth = 1200;
- maxbytes = xwidth / 8;
- numlines = maxbytes * 11;
- printf("\033*t%dR",maxbytes);
- /* set the graphics margin */
- printf("\033*r1A");
- fflush(stdout);
-
- /* for each row in the pixrect, transfer the data to the printer */
- numlines = (numlines < pr->pr_size.y) ? numlines : pr->pr_size.y;
- for (i = 0; i < numlines ; i++ ) {
- pr_rop(mpr, 0, 0, pr->pr_size.x,1, PIX_SRC, pr,0,i);
- /* set up the transfer */
- printf("\033*b");
- /* get the number of bytes */
- lineby = mpr_mdlinebytes(mpr);
- lineby = (lineby > maxbytes) ? maxbytes : lineby;
- printf("%dW",lineby);
- /* write out the bytes */
- l = fwrite((char *)(mpr_d(mpr)->md_image),sizeof(*dd),
- lineby,stdout);
- assert(l==lineby);
- };
- printf("\033*rB");
- printf("\033E");
-
- exit(0);
- }
-
-