--- ray/src/px/psign.c 1992/07/07 18:24:34 2.10 +++ ray/src/px/psign.c 2004/03/28 20:33:14 2.25 @@ -1,34 +1,28 @@ -/* Copyright (c) 1992 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: psign.c,v 2.25 2004/03/28 20:33:14 schorsch Exp $"; #endif - /* * psign.c - produce picture from text. * * 7/1/87 */ -#include "standard.h" +#include "copyright.h" -#include "color.h" +#include +#include "platform.h" +#include "standard.h" +#include "resolu.h" +#include "color.h" #include "font.h" -#ifndef SSS -#define SSS 3 /* super-sample size */ +#ifndef SSS +#define SSS 3 /* super-sample size */ #endif -#define MAXLINE 512 /* longest allowable line */ +#define MAXLINE 512 /* longest allowable line */ -#ifndef DEFPATH -#define DEFPATH ":/usr/local/lib/ray" -#endif -#ifndef ULIBVAR -#define ULIBVAR "RAYPATH" -#endif - char *fontfile = "helvet.fnt"; /* our font file */ COLOR bgcolor = WHTCOLOR; /* background color */ @@ -37,24 +31,28 @@ COLOR fgcolor = BLKCOLOR; /* foreground color */ int direct = 'r'; /* direction (right, up, left, down) */ int cheight = 32*SSS; /* character height */ -double aspect = 1.67; /* height/width character aspect */ -double spacing = 0.0; /* character spacing */ +double aspect = 1.67; /* height/width character aspect */ +double spacing = 0.0; /* character spacing */ int cwidth; /* computed character width */ unsigned char *ourbitmap; /* our output bitmap */ int xsiz, ysiz; /* bitmap dimensions */ int xdim; /* size of horizontal scan (bytes) */ -#define bitop(x,y,op) (ourbitmap[(y)*xdim+((x)>>3)] op (1<<((x)&7))) -#define tstbit(x,y) bitop(x,y,&) -#define setbit(x,y) bitop(x,y,|=) -#define clrbit(x,y) bitop(x,y,&=~) -#define tglbit(x,y) bitop(x,y,^=) + /* conflicting def's in param.h */ +#undef tstbit +#undef setbit +#undef clrbit +#undef tglbit +#define bitop(x,y,op) (ourbitmap[(y)*xdim+((x)>>3)] op (1<<((x)&7))) +#define tstbit(x,y) bitop(x,y,&) +#define setbit(x,y) bitop(x,y,|=) +#define clrbit(x,y) bitop(x,y,&=~) +#define tglbit(x,y) bitop(x,y,^=) + FONT *ourfont; /* our font */ -char *libpath; /* library search path */ - typedef struct line { char *s; /* line w/o LF */ short *sp; /* character spacing */ @@ -65,15 +63,24 @@ LINE *ourtext; /* our text */ int nlines, maxline; /* text dimensions */ int maxwidth; /* maximum line width (dvi) */ -extern char *getenv(); +static void makemap(void); +static void gettext(FILE *fp); +static void arg_text(int ac, char *av[]); +static void maptext(void); +static void mapglyph(GLYPH *gl, int tx0, int ty0); +static void mapcoord(int p[2], int tx, int ty); +static void mapedge(int x, int y, int run, int rise); +static void writemap(FILE *fp); -main(argc, argv) -int argc; -char *argv[]; +int +main( + int argc, + char *argv[] +) { int an; - + SET_FILE_BINARY(stdout); for (an = 1; an < argc && argv[an][0] == '-'; an++) switch (argv[an][1]) { case 'c': /* color */ @@ -117,7 +124,6 @@ char *argv[]; break; case 'h': /* height of characters */ cheight = atoi(argv[++an])*SSS; - xsiz = xsiz = 0; break; case 'a': /* aspect ratio */ aspect = atof(argv[++an]); @@ -132,8 +138,6 @@ unkopt: exit(1); } /* load font file */ - if ((libpath = getenv(ULIBVAR)) == NULL) - libpath = DEFPATH; ourfont = getfont(fontfile); /* get text */ if (an == argc) @@ -146,6 +150,7 @@ unkopt: /* convert text to bitmap */ maptext(); /* print header */ + newheader("RADIANCE", stdout); printargs(argc, argv, stdout); fputformat(COLRFMT, stdout); putchar('\n'); @@ -156,47 +161,56 @@ unkopt: } -makemap() /* create the bit map */ +static void +makemap(void) /* create the bit map */ { - double pictaspect; + double pictaspect; if (direct == 'r' || direct == 'l') { - if (xsiz == 0 || ysiz == 0) { + if (xsiz <= 0) { cwidth = cheight/aspect + 0.5; xsiz = (long)maxwidth*cwidth >> 8; ysiz = nlines*cheight; } else if (aspect > FTINY) { + if (ysiz <= 0) + ysiz = cheight*nlines; pictaspect = 256*nlines*aspect/maxwidth; if (pictaspect*xsiz < ysiz) ysiz = pictaspect*xsiz + 0.5; else xsiz = ysiz/pictaspect + 0.5; cheight = ysiz/nlines; - cwidth = cheight/aspect + 0.5; + cwidth = cheight/aspect; } else { + if (ysiz <= 0) + ysiz = cheight*nlines; pictaspect = (double)ysiz/xsiz; aspect = pictaspect*maxwidth/(256*nlines); cheight = ysiz/nlines; - cwidth = cheight/aspect + 0.5; + cwidth = cheight/aspect; } } else { /* reverse orientation */ - if (xsiz == 0 || ysiz == 0) { + if (ysiz <= 0) { cwidth = cheight/aspect + 0.5; xsiz = nlines*cheight; ysiz = (long)maxwidth*cwidth >> 8; } else if (aspect > FTINY) { + if (xsiz <= 0) + xsiz = cheight*nlines; pictaspect = maxwidth/(256*nlines*aspect); if (pictaspect*xsiz < ysiz) ysiz = pictaspect*xsiz + 0.5; else xsiz = ysiz/pictaspect + 0.5; cheight = xsiz/nlines; - cwidth = cheight/aspect + 0.5; + cwidth = cheight/aspect; } else { + if (xsiz <= 0) + xsiz = cheight*nlines; pictaspect = (double)ysiz/xsiz; aspect = maxwidth/(256*nlines*pictaspect); cheight = xsiz/nlines; - cwidth = cheight/aspect + 0.5; + cwidth = cheight/aspect; } } if (xsiz % SSS) @@ -207,14 +221,15 @@ makemap() /* create the bit map */ ourbitmap = (BYTE *)bmalloc(ysiz*xdim); if (ourbitmap == NULL) error(SYSTEM, "Out of memory in makemap"); - bzero((char *)ourbitmap, ysiz*xdim); + memset((char *)ourbitmap, '\0', ysiz*xdim); } -gettext(fp) /* get text from a file */ -FILE *fp; +static void +gettext( /* get text from a file */ + FILE *fp +) { - char *fgets(); char buf[MAXLINE]; register LINE *curl; int len; @@ -227,9 +242,9 @@ FILE *fp; if (curl == NULL) goto memerr; len = strlen(buf); - curl->s = malloc(len); + curl->s = (char *)malloc(len); curl->sp = (short *)malloc(sizeof(short)*len--); - if (curl->s == NULL | curl->sp == NULL) + if ((curl->s == NULL) | (curl->sp == NULL)) goto memerr; if (len > maxline) maxline = len; @@ -237,10 +252,10 @@ FILE *fp; curl->s[len] = '\0'; if (spacing < -1./256.) len = squeeztext(curl->sp, curl->s, ourfont, - (int)(spacing*-256.0)); + (int)(spacing*-256.)); else if (spacing > 1./256.) len = proptext(curl->sp, curl->s, ourfont, - (int)(spacing*256.0), 3); + (int)(spacing*256.), 3); else len = uniftext(curl->sp, curl->s, ourfont); if (len > maxwidth) @@ -255,16 +270,18 @@ memerr: } -arg_text(ac, av) /* get text from arguments */ -int ac; -char *av[]; +static void +arg_text( /* get text from arguments */ + int ac, + char *av[] +) { register char *cp; ourtext = (LINE *)malloc(sizeof(LINE)); if (ourtext == NULL) goto memerr; - ourtext->s = malloc(MAXLINE); + ourtext->s = (char *)malloc(MAXLINE); if (ourtext->s == NULL) goto memerr; for (cp = ourtext->s; ac-- > 0; av++) { @@ -278,12 +295,12 @@ char *av[]; ourtext->sp = (short *)malloc(sizeof(short)*(maxline+1)); if (ourtext->sp == NULL) goto memerr; - if (spacing < 0.0) + if (spacing < -1./256.) maxwidth = squeeztext(ourtext->sp, ourtext->s, ourfont, - (int)(spacing*-256.0)); - else if (spacing > 0.0) + (int)(spacing*-256.)); + else if (spacing > 1./256.) maxwidth = proptext(ourtext->sp, ourtext->s, ourfont, - (int)(spacing*256.0), 3); + (int)(spacing*256.), 3); else maxwidth = uniftext(ourtext->sp, ourtext->s, ourfont); nlines = 1; @@ -293,7 +310,8 @@ memerr: } -maptext() /* map our text */ +static void +maptext(void) /* map our text */ { register LINE *curl; int l, len; @@ -309,9 +327,12 @@ maptext() /* map our text */ } -mapglyph(gl, tx0, ty0) /* convert a glyph */ -GLYPH *gl; -int tx0, ty0; +static void +mapglyph( /* convert a glyph */ + GLYPH *gl, + int tx0, + int ty0 +) { int n; register GORD *gp; @@ -332,8 +353,12 @@ int tx0, ty0; } -mapcoord(p, tx, ty) /* map text to picture coordinates */ -int p[2], tx, ty; +static void +mapcoord( /* map text to picture coordinates */ + int p[2], + int tx, + int ty +) { tx = (long)tx*cwidth >> 8; ty = (long)ty*cheight >> 8; @@ -359,9 +384,13 @@ int p[2], tx, ty; } -mapedge(x, y, run, rise) /* map an edge */ -register int x, y; -int run, rise; +static void +mapedge( /* map an edge */ + register int x, + register int y, + int run, + int rise +) { int xstep; int rise2, run2; @@ -396,12 +425,14 @@ int run, rise; } -writemap(fp) /* write out bitmap */ -FILE *fp; +static void +writemap( /* write out bitmap */ + FILE *fp +) { COLR pixval[SSS*SSS+1]; /* possible pixel values */ COLOR ctmp0, ctmp1; - double d; + double d; COLR *scanout; int x, y; register int i, j; @@ -442,5 +473,5 @@ FILE *fp; exit(1); } } - free((char *)scanout); + free((void *)scanout); }