This is a continuation of
PDFBOX-3569. In a (private) PDF document there are graphics produced by CorelDraw which are combined by more than 2500 images, each with its own indexed color space based on an ICC color space (the shadows of graphic objects are created by large number of gray lines ...). In our environment (OpenJDK 7 and OpenJDK 8, IcedTea, Suse Linux 64Bit) rendering a single page with one graphic takes 780 seconds. The most time is spent in creating the indexed color space via ICC color space mapping:
The call of LittleCMS (LCMS) multi thousand times is the problem here taking way to much time. Unfortunately using kcms via -Dsun.java2d.cmm=sun.java2d.cmm.kcms.KcmsServiceProvider is also no option as the Suse IceadTea OpenJDK seems to not have included it (anymore?) - in both Java 7 and Java 8.
However the ICC color space (PDICCBased) returns in this case CMYK as alternate color space and for CMYK we have the alternative rendering via system property org.apache.pdfbox.rendering.UsePureJavaCMYKConversion from
The idea is now to have an option to force using the alternative color space instead of the ICC one to circumvent using LCMS in toRGBImage(). For CMYK as alternative color space it has to be combined with the system property 'UsePureJavaCMYKConversion'.
Using this approach the rendering time of the page with the problematic graphic drops from 780 seconds to 1 second!
It is clear that using the alternate color space might return wrong/not exact colors. Therefore it should be only an option to enable this mode. However for processing large collections of PDF documents (e.g. focusing on text) or to display a PDF in a timely manner the performance improvement should outperform the drop in image quality.
While the provided patch will use the alternate color space if activated in any case, it could be possible at a later stage to add more intelligent logic which decides on a runtime analysis when to use this mode (number of calls to LCMS, time needed etc.).
If there are no objections with this patch I will apply it in the next days.