/** * Removes a ProfileActivator object from the vector of ProfileActivator * objects whose activate method will be called if the CMM needs to be * activated. */ public static void activateProfiles() { int i, n; deferring = false; if (aVector == null) { return; } n = aVector.size(); for (ProfileActivator pa : aVector) { try { pa.activate(); } catch (ProfileDataException e) { /* * Ignore profile activation error for now: * such exception is pssible due to absence * or corruption of standard color profile. * As for now we expect all profiles should * be shiped with jre and presence of this * exception is indication of some configuration * problem in jre installation. * * NB: we still are greedy loading deferred profiles * and load them all if any of them is needed. * Therefore broken profile (if any) might be never used. * If there will be attempt to use broken profile then * it will result in CMMException. */ } } aVector.removeAllElements(); aVector = null; return; }
/** * Load the ICC profile, or init alternateColorSpace color space. */ private void loadICCProfile() throws IOException { InputStream input = null; try { input = this.stream.createInputStream(); // if the embedded profile is sRGB then we can use Java's built-in profile, which // results in a large performance gain as it's our native color space, see PDFBOX-2587 ICC_Profile profile; synchronized (LOG) { profile = ICC_Profile.getInstance(input); if (is_sRGB(profile)) { isRGB = true; awtColorSpace = (ICC_ColorSpace) ColorSpace.getInstance(ColorSpace.CS_sRGB); iccProfile = awtColorSpace.getProfile(); } else { awtColorSpace = new ICC_ColorSpace(profile); iccProfile = profile; } // set initial colour float[] initial = new float[getNumberOfComponents()]; for (int c = 0; c < getNumberOfComponents(); c++) { initial[c] = Math.max(0, getRangeForComponent(c).getMin()); } initialColor = new PDColor(initial, this); // do things that trigger a ProfileDataException // or CMMException due to invalid profiles, see PDFBOX-1295 and PDFBOX-1740 // or ArrayIndexOutOfBoundsException, see PDFBOX-3610 awtColorSpace.toRGB(new float[awtColorSpace.getNumComponents()]); // this one triggers an exception for PDFBOX-3549 with KCMS new Color(awtColorSpace, new float[getNumberOfComponents()], 1f); } } catch (RuntimeException e) { if (e instanceof ProfileDataException || e instanceof CMMException || e instanceof IllegalArgumentException || e instanceof ArrayIndexOutOfBoundsException) { // fall back to alternateColorSpace color space awtColorSpace = null; alternateColorSpace = getAlternateColorSpace(); if (alternateColorSpace.equals(PDDeviceRGB.INSTANCE)) { isRGB = true; } LOG.warn("Can't read embedded ICC profile (" + e.getLocalizedMessage() + "), using alternate color space: " + alternateColorSpace.getName()); initialColor = alternateColorSpace.getInitialColor(); } else { throw e; } } finally { IOUtils.closeQuietly(input); } }
/** * Activate a previously deferred ICC_Profile object. */ public void activate() throws ProfileDataException;