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.1 by greg, Thu Feb 2 10:49:42 1989 UTC vs.
Revision 2.5 by schorsch, Sun Mar 28 20:33:14 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines