Woah, this is crazy. It's obviously wrong but, it is also oddly correct.

I had an idea where I do...
red[curr] = Math.round( Math.sqrt( (red[lastOriginal] + diff ) * lightdata[curr] ) );
the entire premise was based on 255 = Math.sqrt( (255) * 255);
in other words, if the top equals the top anything else is on it's way to the bottom. That lead me to believe I was basically going to multiply the shadow into the colormap "by hand".
The results are wrong(ish) but absolutely genius for an idiot.

I had an idea where I do...
red[curr] = Math.round( Math.sqrt( (red[lastOriginal] + diff ) * lightdata[curr] ) );
the entire premise was based on 255 = Math.sqrt( (255) * 255);
in other words, if the top equals the top anything else is on it's way to the bottom. That lead me to believe I was basically going to multiply the shadow into the colormap "by hand".
The results are wrong(ish) but absolutely genius for an idiot.
Comment