|
|
1.1 root 1: /* Copyright (c) 1989, 1990 AT&T --- All Rights Reserved. */
2: /* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T. */
3: /* The copyright notice does not imply actual or intended publication. */
4: /* AUTHORS: */
5: /* T. Thompson - ATT-BL HO - first version */
6: /* Routines for generating PostScript from RLE. */
7: /* The routines at the bottom of this file, which */
8: /* do the actual conversion to postscript, were */
9: /* take from 'sun2ps'. The original header */
10: /* giving credit to its authors is there. */
11:
12: /* The 'binary' version of the output is collected in a */
13: /* temporary file, which is then fed back to the routines */
14: /* that generate postscript in a run-length-encoded form. */
15: /* Ideally it should just convert the original run-length */
16: /* encoding directly, but this is just a hack. The REAL */
17: /* bottleneck is the PostScript printer, of course. */
18: /* Printing an 800 by 800 pixel image takes 5 minutes. */
19:
20: #include <stdio.h>
21: #include <math.h>
22: #include <string.h>
23: #include "CPU.h"
24: #include "boole.h"
25: #include "limits.h" /* numeric extreme values */
26: #include "Units.h"
27: #include "Coord.h"
28: #include "pic.h"
29: #include <sys/types.h>
30: #include <suntool/sunview.h>
31: #include <pixrect/pixrect.h>
32: #include <pixrect/pr_io.h>
33:
34: int Raswidth;
35: int Raslength;
36: extern char Revbyte[256];
37: extern char Revnib[16];
38:
39: static FILE *fout;
40:
41: void
42: RAST_start(h)
43: PIC_hdr *h;
44: {
45: int n, v;
46: struct rasterfile rh;
47:
48: /* build a table of reversed bytes */
49: for ( n=0; n<256; n++ )
50: Revbyte[n] = Revnib[(n>>4)&0xf] | Revnib[n&0xf]<<4;
51:
52: fout = h->fp;
53: h->bpl = (h->bpl+7)/8;
54: Raslength = h->bpl * h->bx.b.y;
55: Raswidth = h->bx.b.x;
56:
57: rh.ras_magic = RAS_MAGIC;
58: rh.ras_width = h->bx.b.x;
59: rh.ras_height = h->bx.b.y;
60: rh.ras_depth = 1;
61: rh.ras_length = Raslength;
62: rh.ras_type = RT_STANDARD;
63: rh.ras_maptype = RMT_NONE;
64: rh.ras_maplength = 0;
65: pr_dump_header(fout,&rh,(colormap_t*)0);
66: }
67:
68: void
69: RAST_end()
70: {
71: }
72:
73: /* write a full line of picture data, returning status: 1 OK, 0 EOF,
74: -1 ERR */
75: int RAST_wline(h,line)
76: PIC_hdr *h;
77: unsigned char *line;
78: { int stat;
79: int n;
80:
81: for ( n=h->bpl; n>0; n-- ) {
82: if ( putc(Revbyte[*line++],fout) == EOF )
83: break;
84: }
85: if ( n == 0 ) {
86: h->seek += h->bpl;
87: h->cy++;
88: return(1);
89: }
90: else { /* ERR */
91: err("write to fd%d stat%d",fileno(h->fp),stat);
92: if((stat>=0)&&(stat<h->bpl)) return(0 /*EOF*/);
93: else return(-1);
94: };
95: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.