Skip to main content

Problem Displaing color converted image

1 reply [Last post]
giuseppe83
Offline
Joined: 2005-08-31

I have problems with the attached code when the input image has an IndexedColorModel.
The color conversion seems to works but I can't display the image bacause I have an exception

Exception in thread "main" java.lang.IllegalArgumentException: Numbers of source Raster bands and source color space components do not match
at java.awt.image.ColorConvertOp.filter(Unknown Source)
at com.sun.media.jai.opimage.ColorConvertOpImage.computeRectNonColorSpaceJAI(ColorConvertOpImage.java:369)
at com.sun.media.jai.opimage.ColorConvertOpImage.computeRect(ColorConvertOpImage.java:289)
at javax.media.jai.PointOpImage.computeTile(PointOpImage.java:922)
at com.sun.media.jai.util.SunTileScheduler.scheduleTile(SunTileScheduler.java:912)
at javax.media.jai.OpImage.getTile(OpImage.java:1139)
at javax.media.jai.PlanarImage.getData(PlanarImage.java:2098)
at javax.media.jai.PlanarImage.getData(PlanarImage.java:2029)
at javax.media.jai.RenderedOp.getData(RenderedOp.java:2277)
at conversion.main(conversion.java:52)

Thanks for help

------code--------
public static void main(String[] args) throws Exception{
PlanarImage r=JAI.create("fileload","images/portaSC.gif");
PlanarImage dst=prova2(conv);
//view
JFrame f=new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(new DisplayJAI(dst));
f.pack();
f.setVisible(true);
}

public static PlanarImage prova2(PlanarImage image){

ColorSpace colorSpace = ColorSpace.getInstance
(java.awt.color.ColorSpace.CS_GRAY);
int[] bits = new int[]{8};
int opaque = Transparency.OPAQUE;
int dataType = DataBuffer.TYPE_BYTE;

ColorModel cm = new ComponentColorModel(
colorSpace, bits, false, false, opaque, dataType);
SampleModel sm = cm.createC
ompatibleSampleModel(image.getWidth(), image.getHeight());

ImageLayout layout = new ImageLayout();
layout.setColorModel(cm);
layout.setSampleModel(sm);

RenderingHints hints = new RenderingHints
(javax.media.jai.JAI.KEY_IMAGE_LAYOUT, layout);

ParameterBlock pb=new ParameterBlock();
pb.addSource(image).add(cm);
PlanarImage result = JAI.create("ColorConvert", pb,hints);
return result;
}

Message was edited by: giuseppe83

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
giuseppe83
Offline
Joined: 2005-08-31

I have solved the problem when I have an IndexColorModel but I have problems for example for conversion from CMYK (to GRAY)

I have searched in the forum and in the JAI-interest archive but the code that I have posted (taken from the archive) seems to be the better for color conversion. Why doesn't work?