107 |
|
#endif |
108 |
|
|
109 |
|
|
110 |
+ |
fputresolu(ord, xres, yres, fp) /* put x and y resolution */ |
111 |
+ |
register int ord; |
112 |
+ |
int xres, yres; |
113 |
+ |
FILE *fp; |
114 |
+ |
{ |
115 |
+ |
if (ord&YMAJOR) |
116 |
+ |
fprintf(fp, "%cY %d %cX %d\n", |
117 |
+ |
ord&YDECR ? '-' : '+', yres, |
118 |
+ |
ord&XDECR ? '-' : '+', xres); |
119 |
+ |
else |
120 |
+ |
fprintf(fp, "%cX %d %cY %d\n", |
121 |
+ |
ord&XDECR ? '-' : '+', xres, |
122 |
+ |
ord&YDECR ? '-' : '+', yres); |
123 |
+ |
} |
124 |
+ |
|
125 |
+ |
|
126 |
+ |
fgetresolu(xrp, yrp, fp) /* get x and y resolution */ |
127 |
+ |
int *xrp, *yrp; |
128 |
+ |
FILE *fp; |
129 |
+ |
{ |
130 |
+ |
char buf[64], *xndx, *yndx; |
131 |
+ |
register char *cp; |
132 |
+ |
register int ord; |
133 |
+ |
|
134 |
+ |
if (fgets(buf, sizeof(buf), fp) == NULL) |
135 |
+ |
return(-1); |
136 |
+ |
xndx = yndx = NULL; |
137 |
+ |
for (cp = buf+1; *cp; cp++) |
138 |
+ |
if (*cp == 'X') |
139 |
+ |
xndx = cp; |
140 |
+ |
else if (*cp == 'Y') |
141 |
+ |
yndx = cp; |
142 |
+ |
if (xndx == NULL || yndx == NULL) |
143 |
+ |
return(-1); |
144 |
+ |
ord = 0; |
145 |
+ |
if (xndx > yndx) ord |= YMAJOR; |
146 |
+ |
if (xndx[-1] == '-') ord |= XDECR; |
147 |
+ |
if (yndx[-1] == '-') ord |= YDECR; |
148 |
+ |
if ((*xrp = atoi(xndx+1)) <= 0) |
149 |
+ |
return(-1); |
150 |
+ |
if ((*yrp = atoi(yndx+1)) <= 0) |
151 |
+ |
return(-1); |
152 |
+ |
return(ord); |
153 |
+ |
} |
154 |
+ |
|
155 |
+ |
|
156 |
|
fwritecolrs(scanline, len, fp) /* write out a colr scanline */ |
157 |
|
register COLR *scanline; |
158 |
|
int len; |
335 |
|
d = r > g ? r : g; |
336 |
|
if (b > d) d = b; |
337 |
|
|
338 |
< |
if (d <= 0.0) { |
338 |
> |
if (d <= 1e-32) { |
339 |
|
clr[RED] = clr[GRN] = clr[BLU] = 0; |
340 |
|
clr[EXP] = 0; |
341 |
|
return; |
354 |
|
register COLOR col; |
355 |
|
register COLR clr; |
356 |
|
{ |
357 |
< |
double ldexp(), f; |
357 |
> |
double f; |
358 |
|
|
359 |
|
if (clr[EXP] == 0) |
360 |
|
col[RED] = col[GRN] = col[BLU] = 0.0; |
364 |
|
col[GRN] = (clr[GRN] + 0.5)*f; |
365 |
|
col[BLU] = (clr[BLU] + 0.5)*f; |
366 |
|
} |
367 |
+ |
} |
368 |
+ |
|
369 |
+ |
|
370 |
+ |
int |
371 |
+ |
colr_norm(clr, nclr) /* normalize a short color, return shift */ |
372 |
+ |
COLR clr, nclr; |
373 |
+ |
{ |
374 |
+ |
register int c; |
375 |
+ |
register int shift = clr[EXP]-COLXS; |
376 |
+ |
|
377 |
+ |
if (shift > 0) { |
378 |
+ |
if (shift >= 8) { |
379 |
+ |
nclr[RED] = nclr[GRN] = nclr[BLU] = 255; |
380 |
+ |
} else { |
381 |
+ |
c = clr[RED] << shift; |
382 |
+ |
nclr[RED] = c > 255 ? 255 : c; |
383 |
+ |
c = clr[GRN] << shift; |
384 |
+ |
nclr[GRN] = c > 255 ? 255 : c; |
385 |
+ |
c = clr[BLU] << shift; |
386 |
+ |
nclr[BLU] = c > 255 ? 255 : c; |
387 |
+ |
} |
388 |
+ |
} else if (shift < 0) { |
389 |
+ |
if (shift <= -8) { |
390 |
+ |
nclr[RED] = nclr[GRN] = nclr[BLU] = 0; |
391 |
+ |
} else { |
392 |
+ |
nclr[RED] = clr[RED] >> -shift; |
393 |
+ |
nclr[GRN] = clr[GRN] >> -shift; |
394 |
+ |
nclr[BLU] = clr[BLU] >> -shift; |
395 |
+ |
} |
396 |
+ |
} else { |
397 |
+ |
nclr[RED] = clr[RED]; |
398 |
+ |
nclr[GRN] = clr[GRN]; |
399 |
+ |
nclr[BLU] = clr[BLU]; |
400 |
+ |
} |
401 |
+ |
nclr[EXP] = COLXS; |
402 |
+ |
return(shift); |
403 |
+ |
} |
404 |
+ |
|
405 |
+ |
|
406 |
+ |
bigdiff(c1, c2, md) /* c1 delta c2 > md? */ |
407 |
+ |
register COLOR c1, c2; |
408 |
+ |
double md; |
409 |
+ |
{ |
410 |
+ |
register int i; |
411 |
+ |
|
412 |
+ |
for (i = 0; i < 3; i++) |
413 |
+ |
if (colval(c1,i)-colval(c2,i) > md*colval(c2,i) || |
414 |
+ |
colval(c2,i)-colval(c1,i) > md*colval(c1,i)) |
415 |
+ |
return(1); |
416 |
+ |
return(0); |
417 |
|
} |