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

Comparing ray/src/px/mt160r.c (file contents):
Revision 1.1 by greg, Thu Feb 2 10:49:20 1989 UTC vs.
Revision 2.6 by greg, Sat Feb 22 02:07:27 2003 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   *  mt160r.c - program to dump pixel file to Mannesman-Tally 160.
6   *
# Line 11 | Line 8 | static char SCCSid[] = "$SunId$ LBL";
8   */
9  
10   #include  <stdio.h>
11 + #ifdef MSDOS
12 + #include  <fcntl.h>
13 + #endif
14 + #include  <time.h>
15  
16   #include  "color.h"
17 + #include  "resolu.h"
18  
19 < #define  NCOLS          880             /* for wide carriage */
19 > #define  NCOLS          880             /* for wide carriage */
20  
21  
22   main(argc, argv)
# Line 23 | Line 25 | char  *argv[];
25   {
26          int  i;
27          int  status = 0;
28 <        
28 > #ifdef MSDOS
29 >        extern int  _fmode;
30 >        _fmode = O_BINARY;
31 >        setmode(fileno(stdin), O_BINARY);
32 >        setmode(fileno(stdout), O_BINARY);
33 > #endif
34          if (argc < 2)
35                  status += printp(NULL) == -1;
36          else
# Line 38 | Line 45 | char  *fname;
45   {
46          FILE  *input;
47          int  xres, yres;
48 <        COLOR  scanline[NCOLS];
42 <        char  sbuf[256];
48 >        COLR  scanline[NCOLS];
49          int  i;
50 <
50 >        
51          if (fname == NULL) {
52                  input = stdin;
53                  fname = "<stdin>";
# Line 50 | Line 56 | char  *fname;
56                  return(-1);
57          }
58                                  /* discard header */
59 <        while (fgets(sbuf, sizeof(sbuf), input) != NULL && sbuf[0] != '\n')
60 <                ;
59 >        if (checkheader(input, COLRFMT, NULL) < 0) {
60 >                fprintf(stderr, "%s: not a Radiance picture\n", fname);
61 >                return(-1);
62 >        }
63                                  /* get picture dimensions */
64 <        if (fgets(sbuf, sizeof(sbuf), input) == NULL ||
57 <                        sscanf(sbuf, "-Y %d +X %d\n", &yres, &xres) != 2) {
64 >        if (fgetresolu(&xres, &yres, input) < 0) {
65                  fprintf(stderr, "%s: bad picture size\n", fname);
66                  return(-1);
67          }
# Line 66 | Line 73 | char  *fname;
73          fputs("\033[6~\033[7z", stdout);
74          
75          for (i = yres-1; i >= 0; i--) {
76 <                if (freadscan(scanline, xres, input) < 0) {
76 >                if (freadcolrs(scanline, xres, input) < 0) {
77                          fprintf(stderr, "%s: read error (y=%d)\n", fname, i);
78                          return(-1);
79                  }
80 +                normcolrs(scanline, xres, 0);
81                  plotscan(scanline, xres, i);
82          }
83  
# Line 82 | Line 90 | char  *fname;
90  
91  
92   plotscan(scan, len, y)                  /* plot a scanline */
93 < COLOR  scan[];
93 > COLR  scan[];
94   int  len;
95   int  y;
96   {
# Line 108 | Line 116 | int  y;
116                  }
117                  putchar('\r');
118                  putchar('\n');
119 +                fflush(stdout);
120          }
121   }
122  
123  
124 < bit(col, x)                             /* return bit for color at x */
125 < COLOR  col;
124 > bit(clr, x)                             /* return bit for color at x */
125 > COLR  clr;
126   register int  x;
127   {
128 <        static float  cerr[NCOLS];
129 <        static double  err;
130 <        double  b;
128 >        static int  cerr[NCOLS];
129 >        static int  err;
130 >        int  b, errp;
131          register int  isblack;
132  
133 <        b = bright(col);
134 <        if (b > 1.0) b = 1.0;
133 >        b = normbright(clr);
134 >        errp = err;
135          err += b + cerr[x];
136 <        isblack = err < 0.5;
137 <        if (!isblack) err -= 1.0;
138 <        cerr[x] = err *= 0.5;
136 >        isblack = err < 128;
137 >        if (!isblack) err -= 256;
138 >        err /= 3;
139 >        cerr[x] = err + errp;
140          return(isblack);
141   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines