Hi everyone,

Sorry for cross-posting. I guess this belongs to the Java2D list, but my assumption is that someone in the imageio-community is more likely to have run into this problem before, and have some hints.


I'm currently writing an ImageIO plugin for Photoshop Document format (PSD). I'm running into a problem when I try to run a ColorConvertOp with a non-ICC (CMYK) color space (my own custom class). Does anyone have some hints on how to make this work? Or is this a JDK bug?

The exception I get is this:

java.lang.IllegalArgumentException: Component index out of range: + component
        at java.awt.color.ICC_ColorSpace.getMinValue(ICC_ColorSpace.java:522)
at java.awt.image.ColorConvertOp.nonICCBIFilter(ColorConvertOp.java: 790)
        at java.awt.image.ColorConvertOp.filter(ColorConvertOp.java:260)
at com .twelvemonkeys .imageio.plugins.psd.PSDImageReader.main(PSDImageReader.java:491)

To me, it seems like a bug in ColorConvertOp, as my custom color space has same number of components as the embedded ICC color profile in the PSD, and running the CCOp on the ColorSpace created from that ICC profile works fine.

There's at least a bug in the code that creates the exception message (end quote in wrong place), that makes me worried this code might never be tested..

    // From ColorConvertOp:
    public float getMinValue(int component) {
if ((component < 0) || (component > this.getNumComponents() - 1)) {
            throw new IllegalArgumentException(
                "Component index out of range: + component");
        }

        ...


The code I use to convert looks like this:

        ...

        BufferedImage image = psdImageReader.read(0);

if (image.getColorModel().getColorSpace().getType() == ColorSpace.TYPE_CMYK) { ColorConvertOp op = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_sRGB), null); image = op.filter(image, new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_4BYTE_ABGR_PRE));
        }


My custom color space class looks like this (not complete yet, but enough to make it work):

final class CMYKColorSpace extends ColorSpace {

    CMYKColorSpace() {
        super(ColorSpace.TYPE_CMYK, 4);
    }

    public float[] toRGB(float[] colorvalue) {
        return new float[] {
                (1 - colorvalue[0]) * (1 - colorvalue[3]),
                (1 - colorvalue[1]) * (1 - colorvalue[3]),
                (1 - colorvalue[2]) * (1 - colorvalue[3])
        };
    }

    public float[] fromRGB(float[] rgbvalue) {
        // Compute CMY
        float c = 1 - rgbvalue[0];
        float m = 1 - rgbvalue[1];
        float y = 1 - rgbvalue[2];

        // Find K
        float k = Math.min(c, Math.min(m, y));

        // Convert to CMYK values
        return new float[] {(c - k), (m - k), (y - k), k};
    }

    public float[] toCIEXYZ(float[] colorvalue) {
throw new UnsupportedOperationException("Method toCIEXYZ not implemented"); // TODO: Implement
    }

    public float[] fromCIEXYZ(float[] colorvalue) {
throw new UnsupportedOperationException("Method fromCIEXYZ not implemented"); // TODO: Implement
    }
}


Best regards,

--
Harald K

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to