Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
Functions | Variables
rletops.c File Reference
#include <stdio.h>
#include <math.h>
#include "rle.h"
Include dependency graph for rletops.c:

Go to the source code of this file.

Functions

void prologue ()
 
void puthexpix ()
 
void epilogue ()
 
void main (int argc, char **argv)
 
void prologue (FILE *outfile, int scribe_mode, int nr, int nc, float x1, float y1, float x2, float y2)
 
void epilogue (FILE *outfile, int scribemode)
 
void puthexpix (FILE *outfile, unsigned char p)
 

Variables

static char rcs_ident [] = "$Id: rletops.c,v 3.0.1.2 1992/01/20 18:04:10 spencer Exp $"
 
static int gencps = 0
 

Function Documentation

void epilogue ( )
void epilogue ( FILE *  outfile,
int  scribemode 
)

Definition at line 219 of file rletops.c.

222 {
223  fprintf(outfile,"\n");
224  if (!scribemode)
225  fprintf(outfile,"showpage\n");
226  fprintf(outfile,"grestore\n");
227 }
FILE * outfile
Definition: giftorle.c:61
void main ( int  argc,
char **  argv 
)

Definition at line 62 of file rletops.c.

65 {
66  char *infname = NULL,
67  *outfname = NULL;
68  FILE *outfile;
69  rle_hdr hdr;
70  int sflag = 0,
71  oflag = 0,
72  cflag = 0;
73  int add_extra_white_line = 0;
74  float heightinch = 3.0,
75  center = 3.25,
76  aspect = 1.0;
77  int y, nrow, nscan, i, pix, dummy;
78  float x1, y1, x2, y2, widthinch;
79  unsigned char ** scan;
80  unsigned char * buffer;
81 
82  if ( scanargs( argc, argv,
83  "% C%- s%- h%-height!f c%-center!f a%-aspect!f o%-outfile!s infile%s\n(\
84 \tConvert a URT RLE image to PostScript.\n\
85 \t-C\tOutput color PostScript.\n\
86 \t-s\t\"Scribe mode\", no showpage, center about 3.25\" at bottom.\n\
87 \t-h\tScale output to given height in inches.\n\
88 \t-c\tCenter at given distance from left (default 3.25\").\n\
89 \t-a\tPixel aspect ratio (default 1.0).)",
90  &gencps, &sflag, &dummy, &heightinch, &cflag, &center, &dummy,
91  &aspect, &oflag, &outfname, &infname ) == 0 )
92  exit( 1 );
93 
94  /* Open RLE file and get header information */
95  /* Initialize header. */
96  hdr = *rle_hdr_init( (rle_hdr *)NULL );
97  rle_names( &hdr, cmd_name( argv ), infname, 0 );
98 
99  hdr.rle_file = rle_open_f(hdr.cmd, infname, "r");
100  rle_get_setup_ok( &hdr, hdr.cmd, infname );
101 
102  if ( ( hdr.ncolors != 3 ) && ( hdr.ncolors != 1))
103  {
104  fprintf( stderr, "%s is not RGB or b&w image",
105  infname ? infname : "stdin" );
106  exit( 0 );
107  }
108 
109  if ( hdr.ncolors == 1 )
110  gencps = 0; /* can't have color out if no color in! */
111 
112  outfile = rle_open_f(hdr.cmd, outfname, "w");
113 
114  /*
115  * Spencer trick: save space by sliding the input image over to the
116  * left margin.
117  */
118  hdr.xmax -= hdr.xmin;
119  hdr.xmin = 0;
120  nrow = hdr.xmax + 1;
121  nscan = (hdr.ymax - hdr.ymin + 1);
122 
123  /* The laserwriters throw out files with an odd number of scanlines! */
124  if (nscan % 2)
125  {
126  nscan++;
127  add_extra_white_line = 1;
128  }
129 
130  /* Allocate scanline memory */
131 
132  buffer = (unsigned char *)malloc( nrow );
133  rle_row_alloc( &hdr, &scan );
134 
135  /* Calculate image size and placement */
136 
137  widthinch = (float) nrow * heightinch * aspect / (float) nscan;
138  if (sflag)
139  {
140  x1 = center - widthinch / 2.0;
141  y1 = 0.0;
142  }
143  else
144  {
145  if (cflag)
146  x1 = center - widthinch / 2.0;
147  else
148  /* center on whole page */
149  x1 = 4.25 - widthinch / 2.0;
150  /* place top edge one inch from top of page */
151  y1 = 11.0 - 1.0 - heightinch;
152  }
153  x2 = x1 + widthinch;
154  y2 = y1 + heightinch;
155  prologue(outfile,sflag,nscan,nrow,x1,y1,x2,y2);
156 
157  while ( (y = rle_getrow( &hdr, scan )) <=
158  hdr.ymax )
159  {
160  if (gencps) {
161  /* generate a color line */
162  for(pix = 0; pix < nrow; pix ++) {
163  puthexpix(outfile,scan[0][pix]);
164  puthexpix(outfile,scan[1][pix]);
165  puthexpix(outfile,scan[2][pix]);
166  }
167  } else {
168  /* generate a monochrome line */
169  if (hdr.ncolors == 1)
170  buffer = scan[0];
171  else
172  rgb_to_bw( scan[0], scan[1], scan[2], buffer, nrow );
173  for(pix = 0; pix < nrow; pix ++)
174  puthexpix(outfile,buffer[pix]);
175  }
176  }
177  if (add_extra_white_line)
178  for(i = 0; i < (gencps ? 3 : 1); i++)
179  for(pix = 0; pix < nrow; pix ++)
180  puthexpix(outfile,255);
181 
182  epilogue(outfile, sflag);
183 
184  exit( 0 );
185 }
int xmin
Definition: rle.h:100
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
FILE * outfile
Definition: giftorle.c:61
static int gencps
Definition: rletops.c:59
int rle_row_alloc(rle_hdr *the_hdr, rle_pixel ***scanp)
Definition: rle_row_alc.c:56
void prologue()
rle_hdr hdr
Definition: iristorle.c:35
int ymin
Definition: rle.h:100
void rgb_to_bw(rle_pixel *red_row, rle_pixel *green_row, rle_pixel *blue_row, rle_pixel *bw_row, int rowlen)
Definition: rle_putrow.c:680
void puthexpix()
static int y
Definition: getami.c:691
unsigned char ** scan
Definition: rle.c:26
string infname
Definition: getbob.c:68
int nrow
Definition: getsun.c:82
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
const char * cmd
Definition: rle.h:133
#define sflag
Definition: rle.h:96
void epilogue()
int xmax
Definition: rle.h:100
int nscan
Definition: getsun.c:82
int ymax
Definition: rle.h:100
void * malloc()
int i
Definition: rletorla.c:82
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
int cflag
Definition: getgmr.c:19
char * cmd_name(char **argv)
Definition: cmd_name.c:31
boolean dummy
Definition: getbob.c:77
unsigned char * buffer
Definition: getsun.c:87
int oflag
Definition: painttorle.c:45
void rle_get_setup_ok(rle_hdr *the_hdr, const char *prog_name, const char *file_name)
int rle_getrow(rle_hdr *the_hdr, rle_pixel *scanline[])
FILE * rle_file
Definition: rle.h:114
int ncolors
Definition: rle.h:100
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267
void prologue ( )
void prologue ( FILE *  outfile,
int  scribe_mode,
int  nr,
int  nc,
float  x1,
float  y1,
float  x2,
float  y2 
)

Definition at line 188 of file rletops.c.

193 {
194  fprintf(outfile,"%%!\n");
195  fprintf(outfile, "%%%%BoundingBox: %d %d %d %d\n",
196  (int)(x1 * 72), (int)(y1 * 72),
197  (int)(x2 * 72), (int)(y2 * 72));
198  fprintf(outfile, "%%%%EndComments\n");
199  fprintf(outfile,"gsave\n");
200  if (! scribe_mode)
201  fprintf(outfile,"initgraphics\n");
202  fprintf(outfile,"72 72 scale\n");
203  fprintf(outfile,"/imline %d string def\n",nc*2*(gencps?3:1));
204  fprintf(outfile,"/drawimage {\n");
205  fprintf(outfile," %d %d 8\n",nc,nr);
206  fprintf(outfile," [%d 0 0 %d 0 %d]\n",nc,-1*nr,nr);
207  fprintf(outfile," { currentfile imline readhexstring pop } ");
208  if (gencps)
209  fprintf(outfile,"false 3 colorimage\n");
210  else
211  fprintf(outfile,"image\n");
212  fprintf(outfile,"} def\n");
213  fprintf(outfile,"%f %f translate\n",x1,y2);
214  fprintf(outfile,"%f %f scale\n",x2-x1,y1-y2);
215  fprintf(outfile,"drawimage\n");
216 }
FILE * outfile
Definition: giftorle.c:61
static int gencps
Definition: rletops.c:59
void puthexpix ( )
void puthexpix ( FILE *  outfile,
unsigned char  p 
)

Definition at line 230 of file rletops.c.

233 {
234  static npixo = 0;
235  static char tohex[] = "0123456789ABCDEF";
236 
237  putc(tohex[(p>>4)&0xF],outfile);
238  putc(tohex[p&0xF],outfile);
239  npixo += 1;
240  if (npixo >= 32) {
241  putc('\n',outfile);
242  npixo = 0;
243  }
244 }
FILE * outfile
Definition: giftorle.c:61

Variable Documentation

int gencps = 0
static

Definition at line 59 of file rletops.c.

char rcs_ident[] = "$Id: rletops.c,v 3.0.1.2 1992/01/20 18:04:10 spencer Exp $"
static

Definition at line 50 of file rletops.c.