I don't get all the -1 stuff here.  In this case, for a pure white image, I think you return a maxColor of 254 when in fact all of the pixels are larger than that!