| 1 |
#ifndef lint
|
| 2 |
static const char RCSid[] = "$Id: panim.c,v 2.6 2004/01/02 10:25:13 schorsch Exp $";
|
| 3 |
#endif
|
| 4 |
/*
|
| 5 |
* Send pictures to PC animation system.
|
| 6 |
*
|
| 7 |
* 6/20/88
|
| 8 |
*/
|
| 9 |
|
| 10 |
#include <stdio.h>
|
| 11 |
#include <string.h>
|
| 12 |
|
| 13 |
#include "rtprocess.h"
|
| 14 |
#include "random.h"
|
| 15 |
#include "color.h"
|
| 16 |
#include "clntrpc.h"
|
| 17 |
#include "scan.h"
|
| 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 |
|
| 27 |
main(argc, argv)
|
| 28 |
int argc;
|
| 29 |
char *argv[];
|
| 30 |
{
|
| 31 |
char *progname;
|
| 32 |
int nframes;
|
| 33 |
int port = PCPROGRAM;
|
| 34 |
/* initialize */
|
| 35 |
compgamma();
|
| 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] [-u uncompress] hostname [-c copies][-r record] [frame] ..\n",
|
| 47 |
stderr);
|
| 48 |
exit(1);
|
| 49 |
}
|
| 50 |
scry_open(*argv++, TCP, port);
|
| 51 |
scry_set_compress(NONE);
|
| 52 |
scry_set_image(TARGA_IMAGE);
|
| 53 |
scry_set_record(PREVIEW);
|
| 54 |
scry_set_copy_num(3);
|
| 55 |
/* send frames */
|
| 56 |
nframes = 0;
|
| 57 |
for ( ; --argc; argv++)
|
| 58 |
if (!strcmp(*argv, "-r") && argv[1]) {
|
| 59 |
scry_set_record(atoi(*++argv)); argc--;
|
| 60 |
} else if (!strcmp(*argv, "-c") && argv[1]) {
|
| 61 |
scry_set_copy_num(atoi(*++argv)); argc--;
|
| 62 |
} else {
|
| 63 |
sendframe(*argv);
|
| 64 |
nframes++;
|
| 65 |
}
|
| 66 |
if (nframes == 0) /* get stdin */
|
| 67 |
sendframe(NULL);
|
| 68 |
/* clean up */
|
| 69 |
scry_close();
|
| 70 |
exit(0);
|
| 71 |
}
|
| 72 |
|
| 73 |
|
| 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 y;
|
| 83 |
register int x;
|
| 84 |
/* open file */
|
| 85 |
if (file == NULL) {
|
| 86 |
if (pcom != NULL)
|
| 87 |
fp = popen(pcom, "r");
|
| 88 |
else
|
| 89 |
fp = stdin;
|
| 90 |
file = "<stdin>";
|
| 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, 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);
|
| 112 |
fputs(": bad picture size\n", stderr);
|
| 113 |
exit(1);
|
| 114 |
}
|
| 115 |
/* compute center */
|
| 116 |
xbeg = (SCANLINE-xres)/2;
|
| 117 |
ybeg = (NUMSCANS-yres)/2;
|
| 118 |
/* clear output */
|
| 119 |
memset(sc_frame_arr, '\0', sizeof(sc_frame_arr));
|
| 120 |
/* get frame */
|
| 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 |
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 |
if (pcom != NULL)
|
| 138 |
pclose(fp);
|
| 139 |
else
|
| 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+0.5)/256.0, 1.0/GAMMA) * 256.0;
|
| 151 |
if (val > 248) val = 248;
|
| 152 |
gammamap[i] = val;
|
| 153 |
}
|
| 154 |
}
|