pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "风云天空" <1010800...@qq.com>
Subject can I use the source code with some modify for mutil-threading in my company project.
Date Mon, 21 Mar 2016 03:08:33 GMT
I modify the code below:from:
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
        
        profile = ICC_Profile.getInstance(input);
        if (is_sRGB(profile))
        {
            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);

        // create a color in order to trigger a ProfileDataException
        // or CMMException due to invalid profiles, see PDFBOX-1295 and PDFBOX-1740
        new Color(awtColorSpace, new float[getNumberOfComponents()], 1f);
    }
    catch (RuntimeException e)
    {
        if (e instanceof ProfileDataException ||
            e instanceof CMMException ||
            e instanceof IllegalArgumentException)
        {
            // fall back to alternateColorSpace color space
            awtColorSpace = null;
            alternateColorSpace = getAlternateColorSpace();
            LOG.error("Can't read embedded ICC profile (" + e.getLocalizedMessage() + "),
using alternate color space: " + alternateColorSpace.getName());
            initialColor = alternateColorSpace.getInitialColor();
        }
        else
        {
            throw e;
        }
    }
    finally
    {
        IOUtils.closeQuietly(input);
    }
}
TO: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 = null;
        synchronized(ICC_Profile.class){
            profile = ICC_Profile.getInstance(input);
        }
        if (is_sRGB(profile))
        {
            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);

        // create a color in order to trigger a ProfileDataException
        // or CMMException due to invalid profiles, see PDFBOX-1295 and PDFBOX-1740
        new Color(awtColorSpace, new float[getNumberOfComponents()], 1f);
    }
    catch (RuntimeException e)
    {
        if (e instanceof ProfileDataException ||
            e instanceof CMMException ||
            e instanceof IllegalArgumentException)
        {
            // fall back to alternateColorSpace color space
            awtColorSpace = null;
            alternateColorSpace = getAlternateColorSpace();
            LOG.error("Can't read embedded ICC profile (" + e.getLocalizedMessage() + "),
using alternate color space: " + alternateColorSpace.getName());
            initialColor = alternateColorSpace.getInitialColor();
        }
        else
        {
            throw e;
        }
    }
    finally
    {
        IOUtils.closeQuietly(input);
    }
}
modify content:ICC_Profile profile = null;
synchronized(ICC_Profile.class){
  profile = ICC_Profile.getInstance(input);
}
Mime
  • Unnamed multipart/alternative (inline, 8-Bit, 0 bytes)
View raw message