Big rework of image.c and the image cache system.