Consolidate threshold dithering code