Your base algorithm is just adding fixed offsets to each color channel of the gray value. We can generalize this so that the NewColor
parameter determines the offset for each channel. Notice that depth
becomes redundant and you can leave it out entirely.
rbase:=getrvalue(NewColor);
gbase:=getgvalue(NewColor);
bbase:=getbvalue(NewColor);
base:=min(rbase,min(gbase,bbase));
rdepth:=rbase-base;
gdepth:=gbase-base;
bdepth:=bbase-base;
rr:=r+rdepth;
gg:=g+gdepth;
bb:=b+bdepth;
if rr < rdepth then
rr:=255;
if gg < gdepth then
gg:=255;
if bb < bdepth then
bb:=255;