This code performs linear interpolation between two colors, could be probably optimized to smaller function (any volunteers? ):
Code:
type
TColor = array[0..3] of byte;
function ClampB(n: integer): byte;
begin
if n > 255 then
Result := 255
else
if n < 0 then
Result := 0
else
Result := n;
end;
function fraction(maxnew, maxold, val: single): single;
begin
if maxnew = 0 then
Result := 0
else
Result := (val * maxold) / maxnew;
end;
function ColorLERP(src, dest: TColor; min, max, val: single): TColor; // Linear interpolation between two colors
var
interp: integer;
begin
interp := trunc(fraction(max, 255, val));
Result[0] := ClampB(ClampB(src[0] - interp) + ClampB(dest[0] - 255 + interp));
Result[1] := ClampB(ClampB(src[1] - interp) + ClampB(dest[1] - 255 + interp));
Result[2] := ClampB(ClampB(src[2] - interp) + ClampB(dest[2] - 255 + interp));
Result[3] := ClampB(ClampB(src[3] - interp) + ClampB(dest[3] - 255 + interp));
end;
Bookmarks