1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
10 |
|
* 4/23/86 |
11 |
|
*/ |
12 |
|
|
13 |
< |
#include <stdio.h> |
13 |
> |
#include "standard.h" |
14 |
|
|
15 |
|
#include "color.h" |
16 |
|
|
17 |
< |
#define min(a,b) ((a)<(b)?(a):(b)) |
17 |
> |
#include "resolu.h" |
18 |
|
|
19 |
< |
int xres = 0; /* resolution of input */ |
20 |
< |
int yres = 0; |
19 |
> |
#define min(a,b) ((a)<(b)?(a):(b)) |
20 |
|
|
21 |
< |
int uniq = 0; /* unique values? */ |
21 |
> |
RESOLU picres; /* resolution of picture */ |
22 |
|
|
23 |
< |
int original = 0; /* original values? */ |
23 |
> |
int uniq = 0; /* print only unique values? */ |
24 |
|
|
25 |
+ |
int doexposure = 0; /* exposure change? (>100 to print) */ |
26 |
+ |
|
27 |
|
int dataonly = 0; /* data only format? */ |
28 |
|
|
29 |
|
int brightonly = 0; /* only brightness values? */ |
31 |
|
int reverse = 0; /* reverse conversion? */ |
32 |
|
|
33 |
|
int format = 'a'; /* input/output format */ |
34 |
+ |
char *fmtid = "ascii"; /* format identifier for header */ |
35 |
|
|
36 |
< |
int header = 1; /* do header */ |
36 |
> |
int header = 1; /* do header? */ |
37 |
|
|
38 |
< |
double exposure = 1.0; |
38 |
> |
int resolution = 1; /* put/get resolution string? */ |
39 |
|
|
40 |
+ |
int original = 0; /* convert to original values? */ |
41 |
+ |
|
42 |
+ |
int wrongformat = 0; /* wrong input format? */ |
43 |
+ |
|
44 |
+ |
double gamcor = 1.0; /* gamma correction */ |
45 |
+ |
|
46 |
+ |
int ord[3] = {RED, GRN, BLU}; /* RGB ordering */ |
47 |
+ |
int rord[4]; /* reverse ordering */ |
48 |
+ |
|
49 |
+ |
COLOR exposure = WHTCOLOR; |
50 |
+ |
|
51 |
|
char *progname; |
52 |
|
|
53 |
|
FILE *fin; |
59 |
|
int argc; |
60 |
|
char **argv; |
61 |
|
{ |
49 |
– |
extern double atof(); |
62 |
|
extern int checkhead(); |
63 |
+ |
double d, expval = 1.0; |
64 |
|
int i; |
65 |
|
|
66 |
|
progname = argv[0]; |
67 |
|
|
68 |
|
for (i = 1; i < argc; i++) |
69 |
< |
if (argv[i][0] == '-') |
69 |
> |
if (argv[i][0] == '-' || argv[i][0] == '+') |
70 |
|
switch (argv[i][1]) { |
71 |
< |
case 'h': /* no header */ |
72 |
< |
header = 0; |
71 |
> |
case 'h': /* header */ |
72 |
> |
header = argv[i][0] == '+'; |
73 |
|
break; |
74 |
+ |
case 'H': /* resolution string */ |
75 |
+ |
resolution = argv[i][0] == '+'; |
76 |
+ |
break; |
77 |
|
case 'u': /* unique values */ |
78 |
< |
uniq = 1; |
78 |
> |
uniq = argv[i][0] == '-'; |
79 |
|
break; |
80 |
|
case 'o': /* original values */ |
81 |
< |
original = 1; |
81 |
> |
original = argv[i][0] == '-'; |
82 |
|
break; |
83 |
+ |
case 'g': /* gamma correction */ |
84 |
+ |
gamcor = atof(argv[i+1]); |
85 |
+ |
if (argv[i][0] == '+') |
86 |
+ |
gamcor = 1.0/gamcor; |
87 |
+ |
i++; |
88 |
+ |
break; |
89 |
+ |
case 'e': /* exposure correction */ |
90 |
+ |
d = atof(argv[i+1]); |
91 |
+ |
if (argv[i+1][0] == '-' || argv[i+1][0] == '+') |
92 |
+ |
d = pow(2.0, d); |
93 |
+ |
if (argv[i][0] == '-') |
94 |
+ |
doexposure = 100; |
95 |
+ |
scalecolor(exposure, d); |
96 |
+ |
expval *= d; |
97 |
+ |
doexposure++; |
98 |
+ |
i++; |
99 |
+ |
break; |
100 |
+ |
case 'R': /* reverse byte sequence */ |
101 |
+ |
if (argv[i][0] == '-') { |
102 |
+ |
ord[0]=BLU; ord[1]=GRN; ord[2]=RED; |
103 |
+ |
} else { |
104 |
+ |
ord[0]=RED; ord[1]=GRN; ord[2]=BLU; |
105 |
+ |
} |
106 |
+ |
break; |
107 |
|
case 'r': /* reverse conversion */ |
108 |
< |
reverse = 1; |
108 |
> |
reverse = argv[i][0] == '-'; |
109 |
|
break; |
110 |
|
case 'b': /* brightness values */ |
111 |
< |
brightonly = 1; |
111 |
> |
brightonly = argv[i][0] == '-'; |
112 |
|
break; |
113 |
|
case 'd': /* data only (no indices) */ |
114 |
< |
dataonly = 1; |
114 |
> |
dataonly = argv[i][0] == '-'; |
115 |
|
switch (argv[i][2]) { |
116 |
|
case '\0': |
117 |
|
case 'a': /* ascii */ |
118 |
|
format = 'a'; |
119 |
+ |
fmtid = "ascii"; |
120 |
|
break; |
121 |
|
case 'i': /* integer */ |
122 |
+ |
format = 'i'; |
123 |
+ |
fmtid = "ascii"; |
124 |
+ |
break; |
125 |
|
case 'b': /* byte */ |
126 |
+ |
dataonly = 1; |
127 |
+ |
format = 'b'; |
128 |
+ |
fmtid = "byte"; |
129 |
+ |
break; |
130 |
|
case 'f': /* float */ |
131 |
+ |
dataonly = 1; |
132 |
+ |
format = 'f'; |
133 |
+ |
fmtid = "float"; |
134 |
+ |
break; |
135 |
|
case 'd': /* double */ |
136 |
< |
format = argv[i][2]; |
136 |
> |
dataonly = 1; |
137 |
> |
format = 'd'; |
138 |
> |
fmtid = "double"; |
139 |
|
break; |
140 |
|
default: |
141 |
|
goto unkopt; |
142 |
|
} |
143 |
|
break; |
144 |
|
case 'x': /* x resolution */ |
145 |
< |
xres = atoi(argv[++i]); |
145 |
> |
case 'X': /* x resolution */ |
146 |
> |
resolution = 0; |
147 |
> |
if (argv[i][0] == '-') |
148 |
> |
picres.or |= XDECR; |
149 |
> |
picres.xr = atoi(argv[++i]); |
150 |
|
break; |
151 |
|
case 'y': /* y resolution */ |
152 |
< |
yres = atoi(argv[++i]); |
152 |
> |
case 'Y': /* y resolution */ |
153 |
> |
resolution = 0; |
154 |
> |
if (argv[i][0] == '-') |
155 |
> |
picres.or |= YDECR; |
156 |
> |
if (picres.xr == 0) |
157 |
> |
picres.or |= YMAJOR; |
158 |
> |
picres.yr = atoi(argv[++i]); |
159 |
|
break; |
160 |
|
default: |
161 |
|
unkopt: |
166 |
|
} |
167 |
|
else |
168 |
|
break; |
169 |
< |
|
169 |
> |
/* recognize special formats */ |
170 |
> |
if (dataonly && format == 'b') |
171 |
> |
if (brightonly) |
172 |
> |
fmtid = "8-bit_grey"; |
173 |
> |
else |
174 |
> |
fmtid = "24-bit_rgb"; |
175 |
> |
/* assign reverse ordering */ |
176 |
> |
rord[ord[0]] = 0; |
177 |
> |
rord[ord[1]] = 1; |
178 |
> |
rord[ord[2]] = 2; |
179 |
> |
/* get input */ |
180 |
|
if (i == argc) { |
181 |
|
fin = stdin; |
182 |
|
} else if (i == argc-1) { |
193 |
|
set_io(); |
194 |
|
|
195 |
|
if (reverse) { |
196 |
< |
if (header) /* get header */ |
197 |
< |
copyheader(fin, stdout); |
198 |
< |
/* add to header */ |
199 |
< |
printargs(i, argv, stdout); |
200 |
< |
printf("\n"); |
201 |
< |
if (yres <= 0 || xres <= 0) { |
202 |
< |
fprintf(stderr, "%s: missing x and y resolution\n", |
203 |
< |
progname); |
196 |
> |
#ifdef MSDOS |
197 |
> |
setmode(fileno(stdout), O_BINARY); |
198 |
> |
if (format != 'a' && format != 'i') |
199 |
> |
setmode(fileno(fin), O_BINARY); |
200 |
> |
#endif |
201 |
> |
/* get header */ |
202 |
> |
if (header) { |
203 |
> |
if (checkheader(fin, fmtid, stdout) < 0) { |
204 |
> |
fprintf(stderr, "%s: wrong input format\n", |
205 |
> |
progname); |
206 |
> |
quit(1); |
207 |
> |
} |
208 |
> |
} else |
209 |
> |
newheader("RADIANCE", stdout); |
210 |
> |
/* get resolution */ |
211 |
> |
if ((resolution && !fgetsresolu(&picres, fin)) || |
212 |
> |
picres.xr <= 0 || picres.yr <= 0) { |
213 |
> |
fprintf(stderr, "%s: missing resolution\n", progname); |
214 |
|
quit(1); |
215 |
|
} |
216 |
< |
fputresolu(YMAJOR|YDECR, xres, yres, stdout); |
216 |
> |
/* add to header */ |
217 |
> |
printargs(i, argv, stdout); |
218 |
> |
if (doexposure > 100) |
219 |
> |
fputexpos(expval, stdout); |
220 |
> |
fputformat(COLRFMT, stdout); |
221 |
> |
putchar('\n'); |
222 |
> |
fputsresolu(&picres, stdout); /* always put resolution */ |
223 |
|
valtopix(); |
224 |
|
} else { |
225 |
+ |
#ifdef MSDOS |
226 |
+ |
setmode(fileno(fin), O_BINARY); |
227 |
+ |
if (format != 'a' && format != 'i') |
228 |
+ |
setmode(fileno(stdout), O_BINARY); |
229 |
+ |
#endif |
230 |
|
/* get header */ |
231 |
< |
getheader(fin, checkhead); |
232 |
< |
|
233 |
< |
if (xres <= 0 || yres <= 0) /* get picture size */ |
234 |
< |
if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) { |
235 |
< |
fprintf(stderr, |
236 |
< |
"%s: missing x and y resolution\n", |
237 |
< |
progname); |
238 |
< |
quit(1); |
239 |
< |
} |
231 |
> |
getheader(fin, checkhead, NULL); |
232 |
> |
if (wrongformat) { |
233 |
> |
fprintf(stderr, "%s: input not a Radiance picture\n", |
234 |
> |
progname); |
235 |
> |
quit(1); |
236 |
> |
} |
237 |
> |
if (!fgetsresolu(&picres, fin)) { |
238 |
> |
fprintf(stderr, "%s: missing resolution\n", progname); |
239 |
> |
quit(1); |
240 |
> |
} |
241 |
|
if (header) { |
242 |
|
printargs(i, argv, stdout); |
243 |
< |
printf("\n"); |
243 |
> |
if (doexposure > 100) |
244 |
> |
fputexpos(expval, stdout); |
245 |
> |
fputformat(fmtid, stdout); |
246 |
> |
putchar('\n'); |
247 |
|
} |
248 |
+ |
if (resolution) /* put resolution */ |
249 |
+ |
fputsresolu(&picres, stdout); |
250 |
|
pixtoval(); |
251 |
|
} |
252 |
|
|
257 |
|
checkhead(line) /* deal with line from header */ |
258 |
|
char *line; |
259 |
|
{ |
260 |
< |
if (header) |
260 |
> |
char fmt[32]; |
261 |
> |
double d; |
262 |
> |
COLOR ctmp; |
263 |
> |
|
264 |
> |
if (formatval(fmt, line)) |
265 |
> |
wrongformat = strcmp(fmt, COLRFMT); |
266 |
> |
else if (original && isexpos(line)) { |
267 |
> |
d = 1.0/exposval(line); |
268 |
> |
scalecolor(exposure, d); |
269 |
> |
doexposure++; |
270 |
> |
} else if (original && iscolcor(line)) { |
271 |
> |
colcorval(ctmp, line); |
272 |
> |
setcolor(exposure, colval(exposure,RED)/colval(ctmp,RED), |
273 |
> |
colval(exposure,GRN)/colval(ctmp,GRN), |
274 |
> |
colval(exposure,BLU)/colval(ctmp,BLU)); |
275 |
> |
doexposure++; |
276 |
> |
} else if (header) |
277 |
|
fputs(line, stdout); |
161 |
– |
if (isexpos(line)) |
162 |
– |
exposure *= exposval(line); |
278 |
|
} |
279 |
|
|
280 |
|
|
281 |
|
pixtoval() /* convert picture to values */ |
282 |
|
{ |
283 |
< |
COLOR *scanln; |
283 |
> |
register COLOR *scanln; |
284 |
> |
int dogamma; |
285 |
|
COLOR lastc; |
286 |
+ |
FLOAT hv[2]; |
287 |
|
int y; |
288 |
|
register int x; |
289 |
|
|
290 |
< |
scanln = (COLOR *)malloc(xres*sizeof(COLOR)); |
290 |
> |
scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR)); |
291 |
|
if (scanln == NULL) { |
292 |
|
fprintf(stderr, "%s: out of memory\n", progname); |
293 |
|
quit(1); |
294 |
|
} |
295 |
+ |
dogamma = gamcor < .95 || gamcor > 1.05; |
296 |
|
setcolor(lastc, 0.0, 0.0, 0.0); |
297 |
< |
for (y = yres-1; y >= 0; y--) { |
298 |
< |
if (freadscan(scanln, xres, fin) < 0) { |
297 |
> |
for (y = 0; y < numscans(&picres); y++) { |
298 |
> |
if (freadscan(scanln, scanlen(&picres), fin) < 0) { |
299 |
|
fprintf(stderr, "%s: read error\n", progname); |
300 |
|
quit(1); |
301 |
|
} |
302 |
< |
for (x = 0; x < xres; x++) { |
302 |
> |
for (x = 0; x < scanlen(&picres); x++) { |
303 |
|
if (uniq) |
304 |
< |
if ( scanln[x][RED] == lastc[RED] && |
305 |
< |
scanln[x][GRN] == lastc[GRN] && |
306 |
< |
scanln[x][BLU] == lastc[BLU] ) |
304 |
> |
if ( colval(scanln[x],RED) == |
305 |
> |
colval(lastc,RED) && |
306 |
> |
colval(scanln[x],GRN) == |
307 |
> |
colval(lastc,GRN) && |
308 |
> |
colval(scanln[x],BLU) == |
309 |
> |
colval(lastc,BLU) ) |
310 |
|
continue; |
311 |
|
else |
312 |
|
copycolor(lastc, scanln[x]); |
313 |
< |
if (original) |
314 |
< |
scalecolor(scanln[x], 1.0/exposure); |
315 |
< |
if (!dataonly) |
316 |
< |
printf("%7d %7d ", x, y); |
313 |
> |
if (doexposure) |
314 |
> |
multcolor(scanln[x], exposure); |
315 |
> |
if (dogamma) |
316 |
> |
setcolor(scanln[x], |
317 |
> |
pow(colval(scanln[x],RED), 1.0/gamcor), |
318 |
> |
pow(colval(scanln[x],GRN), 1.0/gamcor), |
319 |
> |
pow(colval(scanln[x],BLU), 1.0/gamcor)); |
320 |
> |
if (!dataonly) { |
321 |
> |
pix2loc(hv, &picres, x, y); |
322 |
> |
printf("%7d %7d ", (int)(hv[0]*picres.xr), |
323 |
> |
(int)(hv[1]*picres.yr)); |
324 |
> |
} |
325 |
|
if ((*putval)(scanln[x], stdout) < 0) { |
326 |
|
fprintf(stderr, "%s: write error\n", progname); |
327 |
|
quit(1); |
334 |
|
|
335 |
|
valtopix() /* convert values to a pixel file */ |
336 |
|
{ |
337 |
< |
COLOR *scanln; |
337 |
> |
int dogamma; |
338 |
> |
register COLOR *scanln; |
339 |
|
int y; |
340 |
|
register int x; |
341 |
|
|
342 |
< |
scanln = (COLOR *)malloc(xres*sizeof(COLOR)); |
342 |
> |
scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR)); |
343 |
|
if (scanln == NULL) { |
344 |
|
fprintf(stderr, "%s: out of memory\n", progname); |
345 |
|
quit(1); |
346 |
|
} |
347 |
< |
for (y = yres-1; y >= 0; y--) { |
348 |
< |
for (x = 0; x < xres; x++) { |
347 |
> |
dogamma = gamcor < .95 || gamcor > 1.05; |
348 |
> |
for (y = 0; y < numscans(&picres); y++) { |
349 |
> |
for (x = 0; x < scanlen(&picres); x++) { |
350 |
|
if (!dataonly) |
351 |
|
fscanf(fin, "%*d %*d"); |
352 |
|
if ((*getval)(scanln[x], fin) < 0) { |
353 |
|
fprintf(stderr, "%s: read error\n", progname); |
354 |
|
quit(1); |
355 |
|
} |
356 |
+ |
if (dogamma) |
357 |
+ |
setcolor(scanln[x], |
358 |
+ |
pow(colval(scanln[x],RED), gamcor), |
359 |
+ |
pow(colval(scanln[x],GRN), gamcor), |
360 |
+ |
pow(colval(scanln[x],BLU), gamcor)); |
361 |
+ |
if (doexposure) |
362 |
+ |
multcolor(scanln[x], exposure); |
363 |
|
} |
364 |
< |
if (fwritescan(scanln, xres, stdout) < 0 |
227 |
< |
|| fflush(stdout) < 0) { |
364 |
> |
if (fwritescan(scanln, scanlen(&picres), stdout) < 0) { |
365 |
|
fprintf(stderr, "%s: write error\n", progname); |
366 |
|
quit(1); |
367 |
|
} |
381 |
|
COLOR col; |
382 |
|
FILE *fp; |
383 |
|
{ |
384 |
< |
double vd[3]; |
384 |
> |
double vd[3]; |
385 |
|
|
386 |
|
if (fscanf(fp, "%lf %lf %lf", &vd[0], &vd[1], &vd[2]) != 3) |
387 |
|
return(-1); |
388 |
< |
setcolor(col, vd[0], vd[1], vd[2]); |
388 |
> |
setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]); |
389 |
|
return(0); |
390 |
|
} |
391 |
|
|
394 |
|
COLOR col; |
395 |
|
FILE *fp; |
396 |
|
{ |
397 |
< |
double vd[3]; |
397 |
> |
double vd[3]; |
398 |
|
|
399 |
< |
if (fread(vd, sizeof(double), 3, fp) != 3) |
399 |
> |
if (fread((char *)vd, sizeof(double), 3, fp) != 3) |
400 |
|
return(-1); |
401 |
< |
setcolor(col, vd[0], vd[1], vd[2]); |
401 |
> |
setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]); |
402 |
|
return(0); |
403 |
|
} |
404 |
|
|
409 |
|
{ |
410 |
|
float vf[3]; |
411 |
|
|
412 |
< |
if (fread(vf, sizeof(float), 3, fp) != 3) |
412 |
> |
if (fread((char *)vf, sizeof(float), 3, fp) != 3) |
413 |
|
return(-1); |
414 |
< |
setcolor(col, vf[0], vf[1], vf[2]); |
414 |
> |
setcolor(col, vf[rord[RED]], vf[rord[GRN]], vf[rord[BLU]]); |
415 |
|
return(0); |
416 |
|
} |
417 |
|
|
424 |
|
|
425 |
|
if (fscanf(fp, "%d %d %d", &vi[0], &vi[1], &vi[2]) != 3) |
426 |
|
return(-1); |
427 |
< |
setcolor(col,(vi[0]+.5)/256.,(vi[1]+.5)/256.,(vi[2]+.5)/256.); |
427 |
> |
setcolor(col, (vi[rord[RED]]+.5)/256., |
428 |
> |
(vi[rord[GRN]]+.5)/256., (vi[rord[BLU]]+.5)/256.); |
429 |
|
return(0); |
430 |
|
} |
431 |
|
|
436 |
|
{ |
437 |
|
BYTE vb[3]; |
438 |
|
|
439 |
< |
if (fread(vb, sizeof(BYTE), 3, fp) != 3) |
439 |
> |
if (fread((char *)vb, sizeof(BYTE), 3, fp) != 3) |
440 |
|
return(-1); |
441 |
< |
setcolor(col,(vb[0]+.5)/256.,(vb[1]+.5)/256.,(vb[2]+.5)/256.); |
441 |
> |
setcolor(col, (vb[rord[RED]]+.5)/256., |
442 |
> |
(vb[rord[GRN]]+.5)/256., (vb[rord[BLU]]+.5)/256.); |
443 |
|
return(0); |
444 |
|
} |
445 |
|
|
448 |
|
COLOR col; |
449 |
|
FILE *fp; |
450 |
|
{ |
451 |
< |
double vd; |
451 |
> |
double vd; |
452 |
|
|
453 |
|
if (fscanf(fp, "%lf", &vd) != 1) |
454 |
|
return(-1); |
461 |
|
COLOR col; |
462 |
|
FILE *fp; |
463 |
|
{ |
464 |
< |
double vd; |
464 |
> |
double vd; |
465 |
|
|
466 |
< |
if (fread(&vd, sizeof(double), 1, fp) != 1) |
466 |
> |
if (fread((char *)&vd, sizeof(double), 1, fp) != 1) |
467 |
|
return(-1); |
468 |
|
setcolor(col, vd, vd, vd); |
469 |
|
return(0); |
476 |
|
{ |
477 |
|
float vf; |
478 |
|
|
479 |
< |
if (fread(&vf, sizeof(float), 1, fp) != 1) |
479 |
> |
if (fread((char *)&vf, sizeof(float), 1, fp) != 1) |
480 |
|
return(-1); |
481 |
|
setcolor(col, vf, vf, vf); |
482 |
|
return(0); |
488 |
|
FILE *fp; |
489 |
|
{ |
490 |
|
int vi; |
491 |
< |
double d; |
491 |
> |
double d; |
492 |
|
|
493 |
|
if (fscanf(fp, "%d", &vi) != 1) |
494 |
|
return(-1); |
503 |
|
FILE *fp; |
504 |
|
{ |
505 |
|
BYTE vb; |
506 |
< |
double d; |
506 |
> |
double d; |
507 |
|
|
508 |
< |
if (fread(&vb, sizeof(BYTE), 1, fp) != 1) |
508 |
> |
if (fread((char *)&vb, sizeof(BYTE), 1, fp) != 1) |
509 |
|
return(-1); |
510 |
|
d = (vb+.5)/256.; |
511 |
|
setcolor(col, d, d, d); |
518 |
|
FILE *fp; |
519 |
|
{ |
520 |
|
fprintf(fp, "%15.3e %15.3e %15.3e\n", |
521 |
< |
colval(col,RED), |
522 |
< |
colval(col,GRN), |
523 |
< |
colval(col,BLU)); |
521 |
> |
colval(col,ord[0]), |
522 |
> |
colval(col,ord[1]), |
523 |
> |
colval(col,ord[2])); |
524 |
|
|
525 |
|
return(ferror(fp) ? -1 : 0); |
526 |
|
} |
532 |
|
{ |
533 |
|
float vf[3]; |
534 |
|
|
535 |
< |
vf[0] = colval(col,RED); |
536 |
< |
vf[1] = colval(col,GRN); |
537 |
< |
vf[2] = colval(col,BLU); |
538 |
< |
fwrite(vf, sizeof(float), 3, fp); |
535 |
> |
vf[0] = colval(col,ord[0]); |
536 |
> |
vf[1] = colval(col,ord[1]); |
537 |
> |
vf[2] = colval(col,ord[2]); |
538 |
> |
fwrite((char *)vf, sizeof(float), 3, fp); |
539 |
|
|
540 |
|
return(ferror(fp) ? -1 : 0); |
541 |
|
} |
545 |
|
COLOR col; |
546 |
|
FILE *fp; |
547 |
|
{ |
548 |
< |
double vd[3]; |
548 |
> |
double vd[3]; |
549 |
|
|
550 |
< |
vd[0] = colval(col,RED); |
551 |
< |
vd[1] = colval(col,GRN); |
552 |
< |
vd[2] = colval(col,BLU); |
553 |
< |
fwrite(vd, sizeof(double), 3, fp); |
550 |
> |
vd[0] = colval(col,ord[0]); |
551 |
> |
vd[1] = colval(col,ord[1]); |
552 |
> |
vd[2] = colval(col,ord[2]); |
553 |
> |
fwrite((char *)vd, sizeof(double), 3, fp); |
554 |
|
|
555 |
|
return(ferror(fp) ? -1 : 0); |
556 |
|
} |
561 |
|
FILE *fp; |
562 |
|
{ |
563 |
|
fprintf(fp, "%d %d %d\n", |
564 |
< |
(int)(colval(col,RED)*256.), |
565 |
< |
(int)(colval(col,GRN)*256.), |
566 |
< |
(int)(colval(col,BLU)*256.)); |
564 |
> |
(int)(colval(col,ord[0])*256.), |
565 |
> |
(int)(colval(col,ord[1])*256.), |
566 |
> |
(int)(colval(col,ord[2])*256.)); |
567 |
|
|
568 |
|
return(ferror(fp) ? -1 : 0); |
569 |
|
} |
576 |
|
register int i; |
577 |
|
BYTE vb[3]; |
578 |
|
|
579 |
< |
i = colval(col,RED)*256.; |
579 |
> |
i = colval(col,ord[0])*256.; |
580 |
|
vb[0] = min(i,255); |
581 |
< |
i = colval(col,GRN)*256.; |
581 |
> |
i = colval(col,ord[1])*256.; |
582 |
|
vb[1] = min(i,255); |
583 |
< |
i = colval(col,BLU)*256.; |
583 |
> |
i = colval(col,ord[2])*256.; |
584 |
|
vb[2] = min(i,255); |
585 |
< |
fwrite(vb, sizeof(BYTE), 3, fp); |
585 |
> |
fwrite((char *)vb, sizeof(BYTE), 3, fp); |
586 |
|
|
587 |
|
return(ferror(fp) ? -1 : 0); |
588 |
|
} |
605 |
|
float vf; |
606 |
|
|
607 |
|
vf = bright(col); |
608 |
< |
fwrite(&vf, sizeof(float), 1, fp); |
608 |
> |
fwrite((char *)&vf, sizeof(float), 1, fp); |
609 |
|
|
610 |
|
return(ferror(fp) ? -1 : 0); |
611 |
|
} |
615 |
|
COLOR col; |
616 |
|
FILE *fp; |
617 |
|
{ |
618 |
< |
double vd; |
618 |
> |
double vd; |
619 |
|
|
620 |
|
vd = bright(col); |
621 |
< |
fwrite(&vd, sizeof(double), 1, fp); |
621 |
> |
fwrite((char *)&vd, sizeof(double), 1, fp); |
622 |
|
|
623 |
|
return(ferror(fp) ? -1 : 0); |
624 |
|
} |
643 |
|
|
644 |
|
i = bright(col)*256.; |
645 |
|
vb = min(i,255); |
646 |
< |
fwrite(&vb, sizeof(BYTE), 1, fp); |
646 |
> |
fwrite((char *)&vb, sizeof(BYTE), 1, fp); |
647 |
|
|
648 |
|
return(ferror(fp) ? -1 : 0); |
649 |
|
} |