ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/panim.c
Revision: 1.2
Committed: Tue Sep 12 13:04:21 1989 UTC (34 years, 8 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +1 -1 lines
Log Message:
added calls to get/put picture resolution (bug fix)

File Contents

# User Rev Content
1 greg 1.1 /* Copyright (c) 1988 Regents of the University of California */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * Send pictures to PC animation system.
9     *
10     * 6/20/88
11     */
12    
13     #include <stdio.h>
14     #include <rasterfile.h>
15    
16     #include "random.h"
17     #include "color.h"
18     #include "clntrpc.h"
19     #include "scan.h"
20    
21     #define GAMMA 2.0 /* gamma correction factor */
22    
23     BYTE gammamap[256]; /* gamma correction table */
24    
25    
26     main(argc, argv)
27     int argc;
28     char *argv[];
29     {
30     char *progname;
31     int nframes;
32     int port = PCPROGRAM;
33     /* initialize */
34     compgamma();
35     for (progname = *argv++; --argc; argv++)
36     if (!strcmp(*argv, "-p") && argv[1]) {
37     port = atoi(*++argv); argc--;
38     } else
39     break;
40     if (!argc) {
41     fputs("Usage: ", stderr);
42     fputs(progname, stderr);
43     fputs(" [-p port] hostname [-c copies][-r record] [frame] ..\n",
44     stderr);
45     exit(1);
46     }
47     scry_open(*argv++, TCP, port);
48     scry_set_compress(NONE);
49     scry_set_image(TARGA_IMAGE);
50     scry_set_record(PREVIEW);
51     scry_set_copy_num(3);
52     /* send frames */
53     nframes = 0;
54     for ( ; --argc; argv++)
55     if (!strcmp(*argv, "-r") && argv[1]) {
56     scry_set_record(atoi(*++argv)); argc--;
57     } else if (!strcmp(*argv, "-c") && argv[1]) {
58     scry_set_copy_num(atoi(*++argv)); argc--;
59     } else {
60     sendframe(*argv);
61     nframes++;
62     }
63     if (nframes == 0) /* get stdin */
64     sendframe(NULL);
65     /* clean up */
66     scry_close();
67     exit(0);
68     }
69    
70    
71     sendframe(file) /* convert and send a frame */
72     char *file;
73     {
74     COLR scanin[SCANLINE];
75     int xres, yres;
76     int xbeg, ybeg;
77     FILE *fp;
78     int j;
79     register int k, c;
80     register BYTE *in;
81     short *out;
82     /* open file */
83     if (file == NULL) {
84     fp = stdin;
85     file = "<stdin>";
86     } else if ((fp = fopen(file, "r")) == NULL) {
87     perror(file);
88     exit(1);
89     }
90     /* get dimensions */
91     getheader(fp, NULL);
92 greg 1.2 if (fgetresolu(&xres, &yres, fp) != (YMAJOR|YDECR) ||
93 greg 1.1 xres > SCANLINE || yres > NUMSCANS) {
94     fputs(file, stderr);
95     fputs(": bad picture size\n", stderr);
96     exit(1);
97     }
98     /* compute center */
99     xbeg = (SCANLINE-xres)/2;
100     ybeg = (NUMSCANS-yres)/2;
101     /* clear output */
102     bzero(sc_frame_arr, sizeof(sc_frame_arr));
103     /* get frame */
104     for (j = yres-1; j >= 0; j--) {
105     if (freadcolrs(scanin, xres, fp) < 0) {
106     fputs(file, stderr);
107     fputs(": read error\n", stderr);
108     exit(1);
109     }
110     for (in = scanin[0], out = sc_frame_arr[ybeg+j]+xbeg;
111     in < scanin[xres]; in += 4, out++) {
112     k = in[EXP] - COLXS;
113     if (k >= 8) {
114     in[RED] =
115     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     }
136     }
137     /* send frame */
138     scry_send_frame();
139     /* close file */
140     fclose(fp);
141     }
142    
143    
144     compgamma() /* compute gamma correction map */
145     {
146     extern double pow();
147     register int i, val;
148    
149     for (i = 0; i < 256; i++) {
150     val = pow(i/256.0, 1.0/GAMMA) * 256.0;
151     if (val > 248) val = 248;
152     gammamap[i] = val;
153     }
154     }