Fix CMYK and grayscale, more robust dimension checking, tweak algorithm used for different scaling factors
Loop tweaks, error handling, change some 16-bit ints to 32 bit