private ICC_Profile buildICCProfile( final ImageInfo info, final ColorSpace colorSpace, final ByteArrayOutputStream iccStream) throws IOException { if (iccStream != null && iccStream.size() > 0) { if (log.isDebugEnabled()) { log.debug("Effective ICC profile size: " + iccStream.size()); } final int alignment = 4; final int padding = (alignment - iccStream.size() % alignment) % alignment; if (padding != 0) { try { iccStream.write(new byte[padding]); } catch (final IOException ioe) { throw new IOException("Error while aligning ICC stream: " + ioe.getMessage()); } } ICC_Profile iccProfile = null; try { iccProfile = ColorProfileUtil.getICC_Profile(iccStream.toByteArray()); if (log.isDebugEnabled()) { log.debug("JPEG has an ICC profile: " + iccProfile.toString()); } } catch (final IllegalArgumentException iae) { log.warn( "An ICC profile is present in the JPEG file but it is invalid (" + iae.getMessage() + "). The color profile will be ignored. (" + info.getOriginalURI() + ")"); return null; } if (iccProfile.getNumComponents() != colorSpace.getNumComponents()) { log.warn( "The number of components of the ICC profile (" + iccProfile.getNumComponents() + ") doesn't match the image (" + colorSpace.getNumComponents() + "). Ignoring the ICC color profile."); return null; } else { return iccProfile; } } else { return null; // no ICC profile available } }
/** * Indicates whether a given color profile is identical to the default sRGB profile provided by * the Java class library. * * @param profile the color profile to check * @return true if it is the default sRGB profile * @deprecated use org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil directly */ public static boolean isDefaultsRGB(ICC_Profile profile) { return org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil.isDefaultsRGB(profile); }
/** * Returns the profile description of an ICC profile * * @param profile the profile * @return the description * @deprecated use org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil directly */ public static String getICCProfileDescription(ICC_Profile profile) { return org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil.getICCProfileDescription( profile); }