Images and ICC profiles

Discussion in 'Java' started by David Bouchard, May 6, 2005.

  1. i,

    I've been trying for a few days to convert images using icc profiles.
    What i want to do seems fairly easy but i've had no luck so far :

    - i've an image (jpg image)
    - i've an icc profile
    [ successfuly read using ICC_Profile.getInstance(new
    FileInputStream("profiles/profile.icc")); ]

    I just want to convert the image using this icc profile.
    I've tried JAI, 'standard' java 1.4.2 apis but none worked.
    Could someone who successfuly converted an image using an icc profle
    provide java code ?

    Thanks a lot,
    David.

    In the following code, when I uncomment (1) and comment (2), the image
    is converted to grayscale
    screen output : http://homepage.mac.com/d.bouchard/dev/color2gray.png

    If I comment (1) and uncomment (2), the image is not converted (i.e.
    nothing happens)

    console output :

    INFO TestICC2 - loading profile
    INFO TestICC2 - GAMMA COMPONENT [0] [2.6015625]
    INFO TestICC2 - GAMMA COMPONENT [1] [2.6015625]
    INFO TestICC2 - GAMMA COMPONENT [2] [2.6015625]
    INFO TestICC2 - WHITE POINT [0] [0.9538574]
    INFO TestICC2 - WHITE POINT [1] [1.0]
    INFO TestICC2 - WHITE POINT [2] [1.4311523]
    INFO TestICC2 - MATRIX
    INFO TestICC2 - 0.3535614 0.43249512 0.17814636
    INFO TestICC2 - 0.19529724 0.6667633 0.13853455
    INFO TestICC2 - 0.012313843 0.092926025 0.71951294

    screen output : http://homepage.mac.com/d.bouchard/dev/color2icc.png

    The code :

    public TestICC2()
    {
    try
    {
    JFrame frame = new JFrame("test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel main = new JPanel(new BorderLayout());
    frame.setContentPane(main);
    ImageIcon ii = new ImageIcon(IMAGE);
    JLabel srcLabel = new JLabel(ii);
    main.add(srcLabel, BorderLayout.WEST);
    frame.pack();
    frame.setVisible(true);
    logger.info("loading profile");
    ICC_Profile profiles[] = new ICC_Profile[1];
    // Color2Gray (1)
    //profiles[0] =
    ICC_ProfileGray.getInstance(ICC_ColorSpace.CS_GRAY);
    // Color2ICC (2)
    profiles[0] = ICC_Profile.getInstance(new
    FileInputStream(PROFILE));
    displayInfoProfil(profiles[0]);
    BufferedImage src = new
    BufferedImage(ii.getIconWidth(),
    ii.getIconHeight(),
    BufferedImage.TYPE_INT_RGB);
    src.getGraphics().drawImage(ii.getImage(), 0, 0, this);
    ColorConvertOp cco = new ColorConvertOp(profiles,
    null);
    BufferedImage dest = cco.filter(src, null);
    JLabel destLabel = new JLabel(new ImageIcon(dest));
    main.add(destLabel, BorderLayout.EAST);
    frame.pack();
    }
    catch (Exception e)
    {
    logger.error("error", e);
    }

    }

    public void displayInfoProfil(ICC_Profile profile)
    {
    if (profile instanceof ICC_ProfileRGB)
    {
    ICC_ProfileRGB iccPRGB = (ICC_ProfileRGB)profile;
    int i , j;
    for ( i = 0 ; i < iccPRGB.getNumComponents() ; i++ )
    {
    logger.info("GAMMA COMPONENT [" + i + "] ["
    + iccPRGB.getGamma(i) + "]");
    }
    float mwp[] = iccPRGB.getMediaWhitePoint();
    for ( i = 0 ; i < mwp.length ; i++ )
    {
    logger.info("WHITE POINT [" + i + "] [" +
    mwp + "]");
    }
    float matrice[][] = iccPRGB.getMatrix();
    StringBuffer sb = new StringBuffer();
    logger.info("MATRIX");
    for ( i = 0 ; i < matrice.length ; i++ )
    {
    sb.setLength(0);
    sb.append("|");
    for ( j = 0 ; j < matrice.length ; j++ )
    {
    sb.append(matrice[j] + "\t");
    }
    sb.append("|");
    logger.info(sb.toString());
    }
    }
    }
     
    David Bouchard, May 6, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Bouchard

    Image conversion with icc profiles

    David Bouchard, May 2, 2005, in forum: Java
    Replies:
    4
    Views:
    604
    David Bouchard
    May 4, 2005
  2. David Bouchard

    Image conversion with icc profiles

    David Bouchard, May 2, 2005, in forum: Java
    Replies:
    0
    Views:
    406
    David Bouchard
    May 2, 2005
  3. David Bouchard

    Using ICC profiles

    David Bouchard, May 10, 2005, in forum: Java
    Replies:
    4
    Views:
    542
    asaguden
    May 11, 2005
  4. Michael Hoffman
    Replies:
    3
    Views:
    571
    Michael Hoffman
    Mar 14, 2005
  5. Preben
    Replies:
    2
    Views:
    588
    Preben
    Sep 25, 2006
Loading...

Share This Page