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.5 by schorsch, Mon Nov 10 12:28:56 2003 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines