this is too hard to read/follow, I think.  Could it just be a standard iterator, maybe with one pass for each channel or something?