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

Comparing ray/src/px/panim.c (file contents):
Revision 1.2 by greg, Tue Sep 12 13:04:21 1989 UTC vs.
Revision 2.1 by greg, Tue Nov 12 16:05:34 1991 UTC

# Line 11 | Line 11 | static char SCCSid[] = "$SunId$ LBL";
11   */
12  
13   #include <stdio.h>
14 #include <rasterfile.h>
14  
15   #include "random.h"
16   #include "color.h"
# Line 20 | Line 19 | static char SCCSid[] = "$SunId$ LBL";
19  
20   #define GAMMA           2.0             /* gamma correction factor */
21  
22 + FILE    *popen();
23 +
24 + char    *pcom = NULL;                   /* pipe command */
25 +
26   BYTE    gammamap[256];                  /* gamma correction table */
27  
28  
# Line 35 | Line 38 | char   *argv[];
38          for (progname = *argv++; --argc; argv++)
39                  if (!strcmp(*argv, "-p") && argv[1]) {
40                          port = atoi(*++argv); argc--;
41 +                } else if (!strcmp(*argv, "-u") && argv[1]) {
42 +                        pcom = *++argv; argc--;
43                  } else
44                          break;
45          if (!argc) {
46                  fputs("Usage: ", stderr);
47                  fputs(progname, stderr);
48 <                fputs(" [-p port] hostname [-c copies][-r record] [frame] ..\n",
48 >                fputs(" [-p port] [-u uncompress] hostname [-c copies][-r record] [frame] ..\n",
49                                  stderr);
50                  exit(1);
51          }
# Line 71 | Line 76 | char   *argv[];
76   sendframe(file)                 /* convert and send a frame */
77   char    *file;
78   {
79 +        char    command[128];
80          COLR    scanin[SCANLINE];
81          int     xres, yres;
82          int     xbeg, ybeg;
83          FILE    *fp;
84 <        int     j;
85 <        register int    k, c;
80 <        register BYTE   *in;
81 <        short   *out;
84 >        int     y;
85 >        register int    x;
86                                                  /* open file */
87          if (file == NULL) {
88 <                fp = stdin;
88 >                if (pcom != NULL)
89 >                        fp = popen(pcom, "r");
90 >                else
91 >                        fp = stdin;
92                  file = "<stdin>";
93 <        } else if ((fp = fopen(file, "r")) == NULL) {
93 >        } else {
94 >                if (pcom != NULL) {
95 >                        sprintf(command, "( %s ) < %s", pcom, file);
96 >                        fp = popen(command, "r");
97 >                } else
98 >                        fp = fopen(file, "r");
99 >        }
100 >        if (fp == NULL) {
101                  perror(file);
102                  exit(1);
103          }
104                                                  /* get dimensions */
105          getheader(fp, NULL);
106 +        if (checkheader(fp, COLRFMT, NULL) < 0) {
107 +                fputs(file, stderr);
108 +                fputs(": not a Radiance picture\n", stderr);
109 +                exit(1);
110 +        }
111          if (fgetresolu(&xres, &yres, fp) != (YMAJOR|YDECR) ||
112                          xres > SCANLINE || yres > NUMSCANS) {
113                  fputs(file, stderr);
# Line 101 | Line 120 | char   *file;
120                                                  /* clear output */
121          bzero(sc_frame_arr, sizeof(sc_frame_arr));
122                                                  /* get frame */
123 <        for (j = yres-1; j >= 0; j--) {
123 >        for (y = yres-1; y >= 0; y--) {
124                  if (freadcolrs(scanin, xres, fp) < 0) {
125                          fputs(file, stderr);
126                          fputs(": read error\n", stderr);
127                          exit(1);
128                  }
129 <                for (in = scanin[0], out = sc_frame_arr[ybeg+j]+xbeg;
130 <                                in < scanin[xres]; in += 4, out++) {
131 <                        k = in[EXP] - COLXS;
132 <                        if (k >= 8) {
133 <                                in[RED] =
134 <                                in[GRN] =
116 <                                in[BLU] = 255;
117 <                        } else if (k <= -8) {
118 <                                in[RED] =
119 <                                in[GRN] =
120 <                                in[BLU] = 0;
121 <                        } else if (k > 0) {
122 <                                c = in[RED] << k;
123 <                                in[RED] = c > 255 ? 255 : c;
124 <                                c = in[GRN] << k;
125 <                                in[GRN] = c > 255 ? 255 : c;
126 <                                c = in[BLU] << k;
127 <                                in[BLU] = c > 255 ? 255 : c;
128 <                        } else if (k < 0) {
129 <                                in[RED] = in[RED] >> -k;
130 <                                in[GRN] = in[GRN] >> -k;
131 <                                in[BLU] = in[BLU] >> -k;
132 <                        }
133 <                        for (k = 0; k < 3; k++)
134 <                                *out = *out<<5 | (gammamap[in[k]]+(random()&0x7))>>3;
135 <                }
129 >                normcolrs(scanin, xres, 0);     /* normalize */
130 >                for (x = 0; x < xres; x++)      /* convert */
131 >                        sc_frame_arr[y+ybeg][x+xbeg] =
132 >                        ((gammamap[scanin[x][RED]]+(random()&7))&0xf8)<<7
133 >                        | ((gammamap[scanin[x][GRN]]+(random()&7))&0xf8)<<2
134 >                        | (gammamap[scanin[x][BLU]]+(random()&7))>>3;
135          }
136                                                  /* send frame */
137          scry_send_frame();
138                                                  /* close file */
139 <        fclose(fp);
139 >        if (pcom != NULL)
140 >                pclose(fp);
141 >        else
142 >                fclose(fp);
143   }
144  
145  
# Line 147 | Line 149 | compgamma()                            /* compute gamma correction map */
149          register int  i, val;
150  
151          for (i = 0; i < 256; i++) {
152 <                val = pow(i/256.0, 1.0/GAMMA) * 256.0;
152 >                val = pow((i+0.5)/256.0, 1.0/GAMMA) * 256.0;
153                  if (val > 248) val = 248;
154                  gammamap[i] = val;
155          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines