private static int output_value(int j, int maxj)
{
/* We always provide values 0 and MAXJSAMPLE for each component;
* any additional values are equally spaced between these limits.
* (Forcing the upper and lower values to the limits ensures that
* dithering can't produce a color outside the selected gamut.)
*/
return (int)((j * JpegConstants.MAXJSAMPLE + maxj / 2) / maxj);
}