ND2: fix channel count and scanline padding for large images

Fixes QA #4836 and ticket #10228.