Fix mishandling of incomplete, inverted masks.

This fixes #4926. Sometimes image masks have less data than the height*width requires. createMask() was handling this correctly on normal masks, but when the mask was inverted it did the wrong thing.