for (int channelIndex = 0; channelIndex < in.getNumChannels(); channelIndex++)
{
Histogram1DCreator hc = new Histogram1DCreator();
hc.setImage(in, channelIndex);
hc.process();
Histogram1D hist = hc.getHistogram();
final int MAX_SAMPLE = in.getMaxSample(channelIndex);
int[] data = new int[MAX_SAMPLE + 1];
int NUM_PIXELS = in.getWidth() * in.getHeight();
long sum = 0;
for (int i = 0; i < data.length; i++)
{
sum += hist.getEntry(i);
long result = sum * MAX_SAMPLE / NUM_PIXELS;
if (result > (long)Integer.MAX_VALUE)
{
throw new IllegalStateException("Result does not fit into an int.");
}