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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines