Generalized the type of safeGetPixel
Fix for safeGetPixel