367 |
|
} |
368 |
|
|
369 |
|
|
370 |
< |
int |
371 |
< |
colr_norm(clr, nclr) /* normalize a short color, return shift */ |
372 |
< |
COLR clr, nclr; |
370 |
> |
normcolrs(scan, len, adjust) /* normalize a scanline of colrs */ |
371 |
> |
register COLR *scan; |
372 |
> |
int len; |
373 |
> |
int adjust; |
374 |
|
{ |
375 |
|
register int c; |
376 |
< |
register int shift = clr[EXP]-COLXS; |
376 |
> |
register int shift; |
377 |
|
|
378 |
< |
if (shift > 0) { |
379 |
< |
if (shift >= 8) { |
380 |
< |
nclr[RED] = nclr[GRN] = nclr[BLU] = 255; |
381 |
< |
} else { |
382 |
< |
c = clr[RED] << shift; |
383 |
< |
nclr[RED] = c > 255 ? 255 : c; |
384 |
< |
c = clr[GRN] << shift; |
385 |
< |
nclr[GRN] = c > 255 ? 255 : c; |
386 |
< |
c = clr[BLU] << shift; |
387 |
< |
nclr[BLU] = c > 255 ? 255 : c; |
378 |
> |
while (len-- > 0) { |
379 |
> |
shift = scan[0][EXP] + adjust - COLXS; |
380 |
> |
if (shift > 0) { |
381 |
> |
if (shift > 8) { |
382 |
> |
scan[0][RED] = |
383 |
> |
scan[0][GRN] = |
384 |
> |
scan[0][BLU] = 255; |
385 |
> |
} else { |
386 |
> |
shift--; |
387 |
> |
c = (scan[0][RED]<<1 | 1) << shift; |
388 |
> |
scan[0][RED] = c > 255 ? 255 : c; |
389 |
> |
c = (scan[0][GRN]<<1 | 1) << shift; |
390 |
> |
scan[0][GRN] = c > 255 ? 255 : c; |
391 |
> |
c = (scan[0][BLU]<<1 | 1) << shift; |
392 |
> |
scan[0][BLU] = c > 255 ? 255 : c; |
393 |
> |
} |
394 |
> |
} else if (shift < 0) { |
395 |
> |
if (shift < -8) { |
396 |
> |
scan[0][RED] = |
397 |
> |
scan[0][GRN] = |
398 |
> |
scan[0][BLU] = 0; |
399 |
> |
} else { |
400 |
> |
shift = -1-shift; |
401 |
> |
scan[0][RED] = ((scan[0][RED]>>shift)+1)>>1; |
402 |
> |
scan[0][GRN] = ((scan[0][GRN]>>shift)+1)>>1; |
403 |
> |
scan[0][BLU] = ((scan[0][BLU]>>shift)+1)>>1; |
404 |
> |
} |
405 |
|
} |
406 |
< |
} else if (shift < 0) { |
407 |
< |
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]; |
406 |
> |
scan[0][EXP] = COLXS - adjust; |
407 |
> |
scan++; |
408 |
|
} |
409 |
< |
nclr[EXP] = COLXS; |
410 |
< |
return(shift); |
409 |
> |
} |
410 |
> |
|
411 |
> |
|
412 |
> |
bigdiff(c1, c2, md) /* c1 delta c2 > md? */ |
413 |
> |
register COLOR c1, c2; |
414 |
> |
double md; |
415 |
> |
{ |
416 |
> |
register int i; |
417 |
> |
|
418 |
> |
for (i = 0; i < 3; i++) |
419 |
> |
if (colval(c1,i)-colval(c2,i) > md*colval(c2,i) || |
420 |
> |
colval(c2,i)-colval(c1,i) > md*colval(c1,i)) |
421 |
> |
return(1); |
422 |
> |
return(0); |
423 |
|
} |