Faster algorithm for finding closest colour in palette

Avoid sorting the whole palette for every pixel. About x10 times
faster...