I checked in some fixes for the histogram in r5977. Long discussion with various tangents here
The main issues addressed are:
* Histogram would sample incorrect data when viewport width wasn't 720 or 960
* High res displays could overflow the histogram counter.
The changes are intended to be stay close to the old behavior (aside from the bugs) with intention of backporting it to the stable branch. I might try to do some additional optimization in the trunk after that's done.
Attached is some debugging code I used, for future reference. It times various stages parts of the process, displays viewport dimensions from CHDK and GetVRAM*PixelsSize, and the actual number of pixels sampled. It also allows drawing the sampled pixels on the viewport.