Coverity CID : 1256564
CLAMP checks both if value is '< 0' and '> max'. Value will never be a negative number since it is an unsigned integer. Removing that check and only checking if it is bigger than max and setting it appropriately. CID 1256559
Use the new dither object to perform dithering. Add option to select dithering method. Add option to quantize to a specific value
Add a new object that implements various dithering methods.