Median cut algorithm implemented for color palette