ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/psign.c
(Generate patch)

Comparing ray/src/px/psign.c (file contents):
Revision 2.4 by greg, Tue Jun 16 15:34:47 1992 UTC vs.
Revision 2.7 by greg, Thu Jun 18 16:14:43 1992 UTC

# Line 16 | Line 16 | static char SCCSid[] = "$SunId$ LBL";
16  
17   #include  "font.h"
18  
19 < #define  SSS                    2       /* super-sample size */
19 > #ifndef  SSS
20 > #define  SSS                    3       /* super-sample size */
21 > #endif
22  
23   #define  MAXLINE                512     /* longest allowable line */
24  
# Line 29 | Line 31 | static char SCCSid[] = "$SunId$ LBL";
31  
32   char  *fontfile = "helvet.fnt";         /* our font file */
33  
34 < COLR  bgcolr = WHTCOLR;                 /* background color */
35 < COLR  fgcolr = BLKCOLR;                 /* foreground color */
34 > COLOR  bgcolor = WHTCOLOR;              /* background color */
35 > COLOR  fgcolor = BLKCOLOR;              /* foreground color */
36  
37   int  direct = 'r';                      /* direction (right, up, left, down) */
38  
39 < int  cheight = 32;                      /* character height */
39 > int  cheight = 32*SSS;                  /* character height */
40   double  aspect = 1.67;                  /* height/width character aspect */
41 + double  spacing = 0.0;                  /* character spacing */
42   int  cwidth;                            /* computed character width */
43  
44   unsigned char  *ourbitmap;              /* our output bitmap */
# Line 77 | Line 80 | char  *argv[];
80                  case 'c':                       /* color */
81                          switch (argv[an][2]) {
82                          case 'f':                       /* foreground */
83 <                                setcolr(fgcolr, atof(argv[an+1]),
83 >                                setcolor(fgcolor, atof(argv[an+1]),
84                                                  atof(argv[an+2]),
85                                                  atof(argv[an+3]));
86                                  an += 3;
87                                  break;
88                          case 'b':                       /* background */
89 <                                setcolr(bgcolr, atof(argv[an+1]),
89 >                                setcolor(bgcolor, atof(argv[an+1]),
90                                                  atof(argv[an+2]),
91                                                  atof(argv[an+3]));
92                                  an += 3;
# Line 108 | Line 111 | char  *argv[];
111                          }
112                          break;
113                  case 'h':                       /* height of characters */
114 <                        cheight = atoi(argv[++an]);
114 >                        cheight = atoi(argv[++an])*SSS;
115                          break;
116                  case 'a':                       /* aspect ratio */
117                          aspect = atof(argv[++an]);
118                          break;
119 +                case 's':                       /* spacing */
120 +                        spacing = atof(argv[++an]);
121 +                        break;
122                  default:;
123   unkopt:
124                          fprintf(stderr, "%s: unknown option: %s\n",
# Line 148 | Line 154 | makemap()                      /* create the bit map */
154   {
155          cwidth = cheight/aspect + 0.5;
156          if (direct == 'r' || direct == 'l') {
157 <                xsiz = maxline*cwidth;
157 >                xsiz = (long)maxwidth*cwidth >> 8;
158                  ysiz = nlines*cheight;
159          } else {                        /* reverse orientation */
160                  xsiz = nlines*cheight;
161 <                ysiz = maxline*cwidth;
161 >                ysiz = (long)maxwidth*cwidth >> 8;
162          }
163 +        if (xsiz % SSS)
164 +                xsiz += SSS - xsiz%SSS;
165 +        if (ysiz % SSS)
166 +                ysiz += SSS - ysiz%SSS;
167          xdim = (xsiz+7)/8;
168          ourbitmap = (BYTE *)calloc(ysiz, xdim);
169 <        if (ourbitmap == NULL) {
170 <                fprintf(stderr, "out of memory in makemap\n");
161 <                exit(1);
162 <        }
169 >        if (ourbitmap == NULL)
170 >                error(SYSTEM, "Out of memory in makemap");
171   }
172  
173  
# Line 187 | Line 195 | FILE  *fp;
195                          maxline = len;
196                  strncpy(curl->s, buf, len);
197                  curl->s[len] = '\0';
198 < len = uniftext(curl->sp, curl->s, ourfont);
198 >                if (spacing < -1./256.)
199 >                        len = squeeztext(curl->sp, curl->s, ourfont,
200 >                                        (int)(spacing*-256.0));
201 >                else if (spacing > 1./256.)
202 >                        len = proptext(curl->sp, curl->s, ourfont,
203 >                                        (int)(spacing*256.0), 3);
204 >                else
205 >                        len = uniftext(curl->sp, curl->s, ourfont);
206                  if (len > maxwidth)
207                          maxwidth = len;
208                  curl->next = ourtext;
# Line 196 | Line 211 | len = uniftext(curl->sp, curl->s, ourfont);
211          }
212          return;
213   memerr:
214 <        fprintf(stderr, "out of memory in gettext\n");
200 <        exit(1);
214 >        error(SYSTEM, "Out of memory in gettext");
215   }
216  
217  
# Line 224 | Line 238 | char  *av[];
238          ourtext->sp = (short *)malloc(sizeof(short)*(maxline+1));
239          if (ourtext->sp == NULL)
240                  goto memerr;
241 < maxwidth = uniftext(ourtext->sp, ourtext->s, ourfont);
241 >        if (spacing < 0.0)
242 >                maxwidth = squeeztext(ourtext->sp, ourtext->s, ourfont,
243 >                                (int)(spacing*-256.0));
244 >        else if (spacing > 0.0)
245 >                maxwidth = proptext(ourtext->sp, ourtext->s, ourfont,
246 >                                (int)(spacing*256.0), 3);
247 >        else
248 >                maxwidth = uniftext(ourtext->sp, ourtext->s, ourfont);
249          nlines = 1;
250          return;
251   memerr:
252 <        fprintf(stderr, "out of memory in arg_text\n");
232 <        exit(1);
252 >        error(SYSTEM, "Out of memory in arg_text");
253   }
254  
255  
# Line 339 | Line 359 | int  run, rise;
359   writemap(fp)                    /* write out bitmap */
360   FILE  *fp;
361   {
362 +        COLR  pixval[SSS*SSS+1];        /* possible pixel values */
363 +        COLOR  ctmp0, ctmp1;
364 +        double  d;
365          COLR  *scanout;
366 <        int  y;
367 <        register int  x;
366 >        int  x, y;
367 >        register int  i, j;
368 >        int  cnt;
369          register int  inglyph;
370  
371 <        fprintf(fp, "-Y %d +X %d\n", ysiz, xsiz);
371 >        fprintf(fp, "-Y %d +X %d\n", ysiz/SSS, xsiz/SSS);
372  
373 <        scanout = (COLR *)malloc(xsiz*sizeof(COLR));
374 <        if (scanout == NULL) {
375 <                fprintf(stderr, "out of memory in writemap\n");
376 <                exit(1);
373 >        scanout = (COLR *)malloc(xsiz/SSS*sizeof(COLR));
374 >        if (scanout == NULL)
375 >                error(SYSTEM, "Out of memory in writemap");
376 >        for (i = 0; i <= SSS*SSS; i++) {        /* compute possible values */
377 >                copycolor(ctmp0, fgcolor);
378 >                d = (double)i/(SSS*SSS);
379 >                scalecolor(ctmp0, d);
380 >                copycolor(ctmp1, bgcolor);
381 >                d = 1.0 - d;
382 >                scalecolor(ctmp1, d);
383 >                addcolor(ctmp0, ctmp1);
384 >                setcolr(pixval[i], colval(ctmp0,RED),
385 >                                colval(ctmp0,GRN), colval(ctmp0,BLU));
386          }
387 <        for (y = ysiz-1; y >= 0; y--) {
387 >        for (y = ysiz/SSS-1; y >= 0; y--) {
388                  inglyph = 0;
389 <                for (x = 0; x < xsiz; x++) {
390 <                        if (tstbit(x, y))
391 <                                inglyph ^= 1;
392 <                        if (inglyph)
393 <                                copycolr(scanout[x], fgcolr);
394 <                        else
395 <                                copycolr(scanout[x], bgcolr);
389 >                for (x = 0; x < xsiz/SSS; x++) {
390 >                        cnt = 0;
391 >                        for (j = 0; j < SSS; j++)
392 >                                for (i = 0; i < SSS; i++) {
393 >                                        if (tstbit(x*SSS+i, y*SSS+j))
394 >                                                inglyph ^= 1<<j;
395 >                                        if (inglyph & 1<<j)
396 >                                                cnt++;
397 >                                }
398 >                        copycolr(scanout[x], pixval[cnt]);
399                  }
400 <                if (fwritecolrs(scanout, xsiz, fp) < 0) {
400 >                if (fwritecolrs(scanout, xsiz/SSS, fp) < 0) {
401                          fprintf(stderr, "write error in writemap\n");
402                          exit(1);
403                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines