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 |
|
} |