367 |
|
} |
368 |
|
|
369 |
|
|
370 |
< |
int |
371 |
< |
colr_norm(clr, nclr) /* normalize a short color, return shift */ |
372 |
< |
COLR clr, nclr; |
370 |
> |
normcolrs(scan, len) /* normalize a scanline of colrs */ |
371 |
> |
register COLR *scan; |
372 |
> |
int len; |
373 |
|
{ |
374 |
|
register int c; |
375 |
< |
register int shift = clr[EXP]-COLXS; |
375 |
> |
register int shift; |
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; |
377 |
> |
while (len-- > 0) { |
378 |
> |
shift = scan[0][EXP] - COLXS; |
379 |
> |
if (shift > 0) { |
380 |
> |
if (shift > 8) { |
381 |
> |
scan[0][RED] = |
382 |
> |
scan[0][GRN] = |
383 |
> |
scan[0][BLU] = 255; |
384 |
> |
} else { |
385 |
> |
shift--; |
386 |
> |
c = (scan[0][RED]<<1 | 1) << shift; |
387 |
> |
scan[0][RED] = c > 255 ? 255 : c; |
388 |
> |
c = (scan[0][GRN]<<1 | 1) << shift; |
389 |
> |
scan[0][GRN] = c > 255 ? 255 : c; |
390 |
> |
c = (scan[0][BLU]<<1 | 1) << shift; |
391 |
> |
scan[0][BLU] = c > 255 ? 255 : c; |
392 |
> |
} |
393 |
> |
} else if (shift < 0) { |
394 |
> |
if (shift < -8) { |
395 |
> |
scan[0][RED] = |
396 |
> |
scan[0][GRN] = |
397 |
> |
scan[0][BLU] = 0; |
398 |
> |
} else { |
399 |
> |
shift = -1-shift; |
400 |
> |
scan[0][RED] = ((scan[0][RED]>>shift)+1)>>1; |
401 |
> |
scan[0][GRN] = ((scan[0][GRN]>>shift)+1)>>1; |
402 |
> |
scan[0][BLU] = ((scan[0][BLU]>>shift)+1)>>1; |
403 |
> |
} |
404 |
|
} |
405 |
< |
} else if (shift < 0) { |
406 |
< |
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]; |
405 |
> |
scan[0][EXP] = COLXS; |
406 |
> |
scan++; |
407 |
|
} |
401 |
– |
nclr[EXP] = COLXS; |
402 |
– |
return(shift); |
408 |
|
} |
409 |
|
|
410 |
|
|