| 1 |
greg |
1.1 |
#ifndef lint
|
| 2 |
greg |
1.4 |
static const char RCSid[] = "$Id: slide.c,v 1.3 2003/02/22 02:07:28 greg Exp $";
|
| 3 |
greg |
1.1 |
#endif
|
| 4 |
greg |
1.2 |
/*
|
| 5 |
greg |
1.1 |
* slide.c - driver for dicomed film recorder using GRAFPAC under VMS.
|
| 6 |
|
|
*
|
| 7 |
|
|
* 2/19/86
|
| 8 |
|
|
*
|
| 9 |
|
|
* Version for color slide ouput.
|
| 10 |
|
|
* Link with grafpac driver "DS":
|
| 11 |
|
|
* link slide.obj,color.obj,sys_grafpac:ds/lib
|
| 12 |
|
|
*/
|
| 13 |
|
|
|
| 14 |
|
|
#include <stdio.h>
|
| 15 |
|
|
|
| 16 |
|
|
#include "color.h"
|
| 17 |
|
|
|
| 18 |
|
|
#include "random.h"
|
| 19 |
|
|
|
| 20 |
|
|
|
| 21 |
|
|
#define XSIZE 4096 /* device width */
|
| 22 |
|
|
#define YSIZE 4096 /* device length */
|
| 23 |
|
|
|
| 24 |
|
|
#define NCOLS 4018 /* maximum # columns for output */
|
| 25 |
|
|
#define NROWS 2712 /* maximum # rows for output */
|
| 26 |
|
|
|
| 27 |
|
|
#define XCENTER 2048 /* center for x */
|
| 28 |
|
|
#define YCENTER 2048 /* center for y */
|
| 29 |
|
|
|
| 30 |
|
|
int nrows; /* number of rows for output */
|
| 31 |
|
|
int ncols; /* number of columns for output */
|
| 32 |
|
|
|
| 33 |
|
|
int xoffset; /* offset for x */
|
| 34 |
|
|
int yoffset; /* offset for y */
|
| 35 |
|
|
|
| 36 |
|
|
#define RSIZ 17 /* size of response map */
|
| 37 |
|
|
|
| 38 |
|
|
float rmap[2*RSIZ] = { /* response map */
|
| 39 |
|
|
.0, .0,
|
| 40 |
|
|
.0004, .059,
|
| 41 |
|
|
.0008, .122,
|
| 42 |
|
|
.0018, .184,
|
| 43 |
|
|
.0033, .247,
|
| 44 |
|
|
.0061, .310,
|
| 45 |
|
|
.0119, .373,
|
| 46 |
|
|
.0202, .435,
|
| 47 |
|
|
.0373, .498,
|
| 48 |
|
|
.065, .561,
|
| 49 |
|
|
.113, .624,
|
| 50 |
|
|
.199, .686,
|
| 51 |
|
|
.300, .749,
|
| 52 |
|
|
.432, .812,
|
| 53 |
|
|
.596, .875,
|
| 54 |
|
|
.767, .937,
|
| 55 |
|
|
1.000, 1.000,
|
| 56 |
|
|
};
|
| 57 |
|
|
|
| 58 |
|
|
|
| 59 |
|
|
main(argc, argv)
|
| 60 |
|
|
int argc;
|
| 61 |
|
|
char **argv;
|
| 62 |
|
|
{
|
| 63 |
|
|
FILE *fin;
|
| 64 |
|
|
COLOR scanline[NCOLS];
|
| 65 |
|
|
int mult;
|
| 66 |
|
|
char sbuf[128];
|
| 67 |
|
|
int i, j;
|
| 68 |
|
|
|
| 69 |
|
|
/*
|
| 70 |
|
|
for (i = 1; i < argc; i++)
|
| 71 |
|
|
if (argv[i][0] == '-')
|
| 72 |
|
|
switch (argv[i][1]) {
|
| 73 |
|
|
default:
|
| 74 |
|
|
fprintf(stderr, "unknown option: %s\n", argv[i]);
|
| 75 |
|
|
exit(1);
|
| 76 |
|
|
break;
|
| 77 |
|
|
}
|
| 78 |
|
|
else
|
| 79 |
|
|
break;
|
| 80 |
|
|
|
| 81 |
|
|
*/
|
| 82 |
|
|
argc = 2;
|
| 83 |
|
|
argv[1] = "pixfile";
|
| 84 |
|
|
i = 1;
|
| 85 |
|
|
|
| 86 |
|
|
if (argc - i < 1)
|
| 87 |
|
|
fin = 0;
|
| 88 |
|
|
else if ((fin = fopen(argv[i], "r")) == NULL) {
|
| 89 |
|
|
fprintf(stderr, "%s: can't open file \"%s\"\n",
|
| 90 |
|
|
argv[0], argv[i]);
|
| 91 |
|
|
exit(1);
|
| 92 |
|
|
}
|
| 93 |
|
|
|
| 94 |
|
|
/* discard header */
|
| 95 |
|
|
while (fgets(sbuf, sizeof(sbuf), fin) != NULL && sbuf[0] != '\n')
|
| 96 |
|
|
;
|
| 97 |
|
|
/* get picture size */
|
| 98 |
|
|
if (fgets(sbuf, sizeof(sbuf), fin) == NULL ||
|
| 99 |
|
|
sscanf(sbuf, "-Y %d +X %d\n", &nrows, &ncols) != 2) {
|
| 100 |
|
|
fprintf(stderr, "%s: bad picture size\n", argv[0]);
|
| 101 |
|
|
exit(1);
|
| 102 |
|
|
}
|
| 103 |
|
|
|
| 104 |
|
|
if (ncols > NCOLS || nrows > NROWS) {
|
| 105 |
|
|
fprintf(stderr, "%s: resolution mismatch\n", argv[0]);
|
| 106 |
|
|
exit(1);
|
| 107 |
|
|
}
|
| 108 |
|
|
|
| 109 |
|
|
mult = NCOLS/ncols;
|
| 110 |
|
|
if (NROWS/nrows < mult)
|
| 111 |
|
|
mult = NROWS/nrows;
|
| 112 |
|
|
|
| 113 |
|
|
xoffset = XCENTER/mult - ncols/2;
|
| 114 |
|
|
yoffset = YCENTER/mult - nrows/2;
|
| 115 |
|
|
|
| 116 |
|
|
tvinit();
|
| 117 |
|
|
i = XSIZE/mult; j = YSIZE/mult; tvvrs(&i, &j);
|
| 118 |
|
|
i = 12; tvset("ifile", &i);
|
| 119 |
|
|
tvset("nrco", "rgb");
|
| 120 |
|
|
|
| 121 |
|
|
for (i = nrows-1; i >= 0; i--) {
|
| 122 |
|
|
if (freadscan(scanline, ncols, fin) < 0) {
|
| 123 |
|
|
fprintf(stderr, "%s: read error in row %d\n",
|
| 124 |
|
|
argv[0], i);
|
| 125 |
|
|
exit(1);
|
| 126 |
|
|
}
|
| 127 |
|
|
scanout(scanline, i);
|
| 128 |
|
|
}
|
| 129 |
|
|
|
| 130 |
|
|
tvsend();
|
| 131 |
|
|
tvend();
|
| 132 |
|
|
|
| 133 |
|
|
return(0);
|
| 134 |
|
|
}
|
| 135 |
|
|
|
| 136 |
|
|
|
| 137 |
|
|
scanout(scan, y) /* output scan line */
|
| 138 |
|
|
register COLOR *scan;
|
| 139 |
|
|
int y;
|
| 140 |
|
|
{
|
| 141 |
|
|
static int zero;
|
| 142 |
|
|
static float rgb[3][NCOLS];
|
| 143 |
|
|
int i;
|
| 144 |
|
|
register int j;
|
| 145 |
|
|
|
| 146 |
|
|
zero = xoffset;
|
| 147 |
|
|
y += yoffset;
|
| 148 |
|
|
|
| 149 |
|
|
for (j = 0; j < ncols; j++) {
|
| 150 |
|
|
mapcolor(scan[j], scan[j]);
|
| 151 |
|
|
for (i = 0; i < 3; i++)
|
| 152 |
|
|
rgb[i][j] = scan[j][i] + (.5-frandom())/255.0;
|
| 153 |
|
|
}
|
| 154 |
|
|
tvrstc(&zero, &y, rgb[0], rgb[1], rgb[2], &ncols);
|
| 155 |
|
|
}
|
| 156 |
|
|
|
| 157 |
|
|
|
| 158 |
|
|
mapcolor(c1, c2) /* map c1 into c2 */
|
| 159 |
|
|
register COLOR c1;
|
| 160 |
|
|
COLOR c2;
|
| 161 |
|
|
{
|
| 162 |
|
|
static float *mp[3] = {rmap, rmap, rmap};
|
| 163 |
|
|
double x;
|
| 164 |
|
|
register int i;
|
| 165 |
|
|
|
| 166 |
|
|
for (i = 0; i < 3; i++) {
|
| 167 |
|
|
if (colval(c1,i) >= 1.0) {
|
| 168 |
|
|
colval(c2,i) = 1.0;
|
| 169 |
|
|
continue;
|
| 170 |
|
|
}
|
| 171 |
|
|
while (colval(c1,i) >= mp[i][2])
|
| 172 |
|
|
mp[i] += 2;
|
| 173 |
|
|
while (colval(c1,i) < mp[i][0])
|
| 174 |
|
|
mp[i] -= 2;
|
| 175 |
|
|
x = (colval(c1,i) - mp[i][0]) / (mp[i][2] - mp[i][0]);
|
| 176 |
|
|
colval(c2,i) = (1.0-x)*mp[i][1] + x*mp[i][3];
|
| 177 |
|
|
}
|
| 178 |
|
|
}
|