Optimizations for 1 bpc images

Two low-level optimizations for black and white images and image masks.

1. in getComponents(), unroll a loop to save some if's
2. in fillGrayBuffer(), join buffer decoding and scaling into one single loop, and apply simplifications for the 1bpc special case