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

Comparing ray/src/px/ttyimage.c (file contents):
Revision 1.2 by greg, Tue Sep 12 13:04:41 1989 UTC vs.
Revision 2.2 by greg, Mon Sep 21 12:15:22 1992 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1992 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 11 | Line 11 | static char SCCSid[] = "$SunId$ LBL";
11   */
12  
13   #include  <stdio.h>
14 + #ifdef MSDOS
15 + #include  <fcntl.h>
16 + #endif
17  
18   #include  "color.h"
19 + #include  "resolu.h"
20  
21  
22 < #define  NCOLS          133
22 > #define  NCOLS          133
23  
20 char  shadech[] = " .,:;+?%&*$@#";
24  
22 #define  NSHADES        (sizeof(shadech)-1)
23
24 #define  shade(col)     ( bright(col)>=1.0 ? NSHADES-1 : \
25                                (int)(bright(col)*NSHADES) )
26
27 char  *progname;
28
29
25   main(argc, argv)
26   int  argc;
27   char  **argv;
28   {
29          FILE  *input;
30          int  xres, yres;
31 <        COLOR  scanline[NCOLS];
37 <        char  sbuf[256];
31 >        COLR  scanline[NCOLS];
32          register int  i, j;
33          
40        progname = argv[0];
41
34          if (argc < 2)
35                  input = stdin;
36          else if ((input = fopen(argv[1], "r")) == NULL) {
37 <                fprintf(stderr, "%s: can't open file \"%s\"\n", progname, argv[1]);
37 >                fprintf(stderr, "%s: can't open file \"%s\"\n", argv[0], argv[1]);
38                  exit(1);
39          }
40 <        
41 <                                /* discard header */
42 <        while (fgets(sbuf, sizeof(sbuf), input) != NULL && sbuf[0] != '\n')
51 <                ;
40 > #ifdef MSDOS
41 >        setmode(fileno(input), O_BINARY);
42 > #endif
43                                  /* get picture dimensions */
44 <        if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) {
45 <                fprintf(stderr, "%s: bad picture size\n", progname);
44 >        if (checkheader(input, COLRFMT, NULL) < 0 ||
45 >                        fgetresolu(&xres, &yres, input) < 0) {
46 >                fprintf(stderr, "%s: bad picture format\n", argv[0]);
47                  exit(1);
48          }
49          if (xres > NCOLS) {
50 <                fprintf(stderr, "%s: resolution mismatch\n", progname);
50 >                fprintf(stderr, "%s: resolution mismatch\n", argv[0]);
51                  exit(1);
52          }
53          
54          for (i = 0; i < yres; i++) {
55 <                if (freadscan(scanline, xres, input) < 0) {
56 <                        fprintf(stderr, "%s: read error\n", progname);
55 >                if (freadcolrs(scanline, xres, input) < 0) {
56 >                        fprintf(stderr, "%s: read error\n", argv[0]);
57                          exit(1);
58                  }
59 +                normcolrs(scanline, xres, 0);
60                  for (j = 0; j < xres; j++)
61 <                        putchar(shadech[shade(scanline[j])]);
61 >                        putchar(shade(scanline[j]));
62                  putchar('\n');
63          }
64  
65          exit(0);
66 + }
67 +
68 +
69 + int
70 + shade(clr)                      /* return character for color */
71 + COLR  clr;
72 + {
73 + #define NSHADES  13
74 +
75 +        static char  shadech[NSHADES+1] = " .,:;+?%&*$@#";
76 +
77 +        return(shadech[normbright(clr)*NSHADES/256]);
78 +
79 + #undef NSHADES
80   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines