I'd leave this part out. You can accumulate values at the lower and upper ends  below. No need to compute it for the entire 256 values.

Also, if you're going to display a histogram visually you want the regular histogram, not a cumulative one.