implementation color_encode