Juanma helped me spot a few more errors in the patch off-list. Here's another iteration. I added a BLOCK_INPUT in define_image_type; this seems necessary because lookup_image_type can be called with input unblocked. If further testing does not turn up any issues, I'll commit it so that the Vlibrary_cache refactoring work can proceed.