1
/*===========================================================================
2
Copyright (C) 1995-2005 European Southern Observatory (ESO)
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License as
6
published by the Free Software Foundation; either version 2 of
7
the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public
15
License along with this program; if not, write to the Free
16
Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
19
Correspondence concerning ESO-MIDAS should be addressed as follows:
20
Internet e-mail: midas@eso.org
21
Postal address: European Southern Observatory
22
Data Management Division
23
Karl-Schwarzschild-Strasse 2
24
D 85748 Garching bei Muenchen
26
===========================================================================*/
29
* HEADER : versatec.c - Vers 3.6.001 - Jul. 1992 - F.Tribioli, L.Fini OAA
30
* - Vers 3.6.000 - Dic. 1989 - F. Tribioli, OAA
32
* Raster generator for Versatec V-80 printers
34
* Usage: versatec -h To get the usage help message
36
* 910228 CG: exit(); -> exit(1);
51
static unsigned rowlen=DEFWDTOTPOINTS/8;
52
static int channel; /* Versatec device channel number */
53
static int nrows; /* Number of rows in the bitmap */
55
static unsigned char codeline[DEFWDTOTPOINTS*2+1];
56
/* Array to hold encoded bit map line */
57
static unsigned char * rowpt[MAXROWS];
58
/* Array to hold pointers to beginning */
60
static unsigned char * pixels; /* Pointer to dynamically allocated */
64
static unsigned char bmasks[]={0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
66
FILE * infile,* outfile;
68
static int clip=FALSE;
69
static int wflag=FALSE;
71
static double wdfact = 1.0;
72
static double lnfact = 1.0;
74
static double wdscale;
75
static double lnscale;
77
static long lnoffset = 0;
78
static long wdoffset = 0;
79
static long stripguard = 0.0;
80
static char csave='!';
82
static long nlines; /* Input file line counter */
83
static long outlines=0; /* Output print line counter */
85
static char * writemode = "w";
90
printf("Raster generator for Versatec V-80 printers.");
91
printf(" Vers. 3.5 - F. Tribioli, Dec 1989.\n\n");
92
printf("Usage: versatec [?/-h] [-wf] [-lf] [-c] [input] [output]\n\n");
93
printf("where: input is the input file (see note below)");
94
printf(" (default is stdin)\n");
95
printf(" output is the output file (default is stdout)\n");
96
printf(" -wf apply a scaling factor f along paper width\n");
97
printf(" -lf apply a scaling factor f along paper length\n");
98
printf(" -c select clipping mode when requested ");
99
printf("width is larger than\n");
100
printf(" available (default is rescaling mode)\n");
101
printf(" -s enable splitting of large plot when requested ");
102
printf("width is larger\n");
103
printf(" than available (default is rescaling mode). ");
104
printf("Disable -c switch\n");
105
printf(" -h/? Print this help information\n\n");
106
printf("NOTE: the rasterizing program must be feed with an ");
107
printf("input file generated\n");
108
printf(" by the AGL standard raster driver and then ");
109
printf("sorted alphabetically\n");
110
printf(" with any sorting utility. If the file is not sorted ");
111
printf("the rasterizer\n");
112
printf(" will fail.\n\n");
113
printf("Copyright 1989 by F. Tribioli. This program may be freely ");
114
printf("copied and used\n");
115
printf("provided this copyright notice will remain attached to it.\n\n");
118
void markpixel(wd,ln)
121
long wdidx,wdrest,wd0,ln0;
129
if(ln0>=nrows || ln0<0) return;
130
if(wdidx<0 || wdidx>=rowlen) return;
131
*(rowpt[ln0]+wdidx) |= bmasks[wdrest];
136
* routine : getspace. Allocates memory space for the bitmap and sets the
140
void getspace(n_rows)
141
long n_rows; /* number of character rows */
148
printf("Rasterizer error: Bitmap strip length too big\n");
152
nbytes = rowlen * n_rows;
154
pixels = (unsigned char *)malloc((size_t)nbytes);
157
printf("Rasterizer error: Not enough memory for bitmap\n");
161
for(i=0; i<nbytes; i++)
168
for(i=0; i<n_rows; i++) /* Initialize row pointers */
169
rowpt[i] = pixels + (i * rowlen);
173
* routine : encode. Compress original bitmap line. First short is the
174
* value of the first pixel of the line. The other short
175
* are the number of consecutive pixels with the same value.
179
unsigned char *pt; /* pointer to bitmap row to encode */
180
int *nout; /* encoded data length */
184
unsigned char bitval,bitsave,*pt1;
188
*pt1++ = bitsave = (*pt & *bmasks) ? 1 : 0;
189
for(i=0;i<VERSATECBUFSIZE;i++)
193
bitval = (*pt & bmasks[j]) ? 1 : 0;
194
if(bitval == bitsave)
198
*pt1++=(unsigned char)(counter>>8);
199
*pt1++=(unsigned char)(counter & 255);
207
*pt1++=(unsigned char)(counter>>8);
208
*pt1++=(unsigned char)(counter & 255);
213
* routine: writeout. Write on output disk file a compressed bitmap
216
void writeout() /* Writes all character rows */
224
for(i=0; i<nrows; i++)
230
encode(pt+ndone,&leng);
231
if((nout=fwrite(codeline,1,leng,outfile))!=leng)
233
fprintf(stderr,"VERSATEC - Error writing output file");
236
ndone+=VERSATECBUFSIZE;
239
for(j=0;j<rowlen;j++) *(pt++)=0;
245
* routine : rasterize. Set pixels along vector trace
248
void rasterize(c,wd0,ln0,wd1,ln1,hwid,vwid)
249
char c; /* strip identifier */
250
double wd0,ln0,wd1,ln1; /* line ending points coordinates */
251
double hwid; /* Half line width (horizontal) */
252
double vwid; /* Half line width (vertical) */
254
double wd,ln,wdend,lnend;
257
wd0 *= wdscale; /* First convert coordinates into */
258
wd1 *= wdscale; /* Pixel positions */
262
/* physical strip length (=nrows) */
271
csave=c; /* save strip identifier */
273
ln1+=lnoffset; /* shift coordinates to fit well in the current strip */
278
if( (wd0<0 && wd1<0) || (wd0>DEFWDTOTPOINTS && wd1>DEFWDTOTPOINTS) ) return;
280
dw=wd1-wd0; dl=ln1-ln0;
282
if( fabs(dw) >= fabs(dl) )
283
{ /* Stepping along paper width */
287
wdend =wd0; lnend =ln0;
294
wdend =wd1; lnend =ln1;
300
wdend =wd1; lnend =ln1;
306
double lna=ln-vwid,lnb=ln+vwid,lnt;
307
for(lnt=lna; lnt<=lnb; lnt++) markpixel(wd,lnt);
313
{ /* Stepping along paper length */
317
wdend =wd0; lnend =ln0;
324
wdend =wd1; lnend =ln1;
330
wdend =wd1; lnend =ln1;
336
double wda=wd-hwid,wdb=wd+hwid,wdt;
337
for(wdt=wda; wdt<=wdb; wdt++) markpixel(wdt,ln);
352
double paperwd, paperln, stripln;
353
double wdpointsmm, lnpointsmm, dummy;
359
wdpointsmm=DEFWDPOINTSMM;
360
lnpointsmm=DEFLNPOINTSMM;
371
for(i=1; i<argc; i++)
372
{ /* argument selection loop */
374
if((*pt=='-')||(*pt=='/'))
380
sscanf(pt,"%lf",&wdfact);
384
sscanf(pt,"%lf",&lnfact);
407
/* This is input file name */
410
infile=fopen(pt,"r");
413
fprintf(stderr,"\nVERSATEC - Error opening file %s for input\n",pt);
420
outfile=fopen(pt,"w");
423
fprintf(stderr,"\nVERSATEC - Error opening file %s for output\n",pt);
430
if(infile==NULL) infile = stdin;
431
if(outfile==NULL) outfile = stdout;
433
fscanf(infile, " %lf %lf %lf\n", &paperwd, &paperln, &stripln );
438
wdpoints = paperwd * wdpointsmm + 0.5; /* Strip limits in pixels */
439
stpoints = stripln * lnpointsmm + 0.5; /* coordinates */
441
if(wdpoints>DEFWDTOTPOINTS) /* Check if graph fits into paper */
447
double rescal = (double) DEFWDTOTPOINTS / wdpoints;
452
wdpoints = DEFWDTOTPOINTS;
456
wdoffset=(DEFWDTOTPOINTS-wdpoints)/2;
458
wdscale = wdpointsmm * wdfact;
459
lnscale = lnpointsmm * lnfact;
471
double wd0,ln0,wd1,ln1;
477
n=fscanf(infile, "%c %lf %lf %lf %lf %d\n",
478
&strip, &wd0, &ln0, &wd1, &ln1, &width );
482
printf("\nFormat error in line %ld of input file\n\n",nlines);
486
vwid = width*lnfact ;
489
rasterize(strip,wd0,ln0,wd1,ln1,hwid,vwid);
491
while (1); /* Do loop terminates on input eof */
492
writeout(); /* Write remaining stripes */
493
if(wdpoints>DEFWDTOTPOINTS)
494
writeout(); /* Introduce a blank space between stripes */
495
lnoffset=0; /* Reset length parameters */
497
wdoffset-=DEFWDTOTPOINTS; /* Set new width offset */
498
wdpoints-=DEFWDTOTPOINTS; /* Set remaining width to plot */
499
csave='!'; /* Reset strip identifier */
500
rewind(infile); /* Rewind input file to plot new strip */
501
fscanf(infile, " %lf %lf %lf\n", &dummy, &dummy, &dummy);
504
while(split && wdpoints>0);
505
/* Do loop terminates when all stripes are writed out */
506
if(infile!=stdin) fclose(infile);
507
if(outfile!=stdout) fclose(outfile);