added memory allocation checks (fixes issue 355)
trunk: extend support for pdf2jp2