Skip to main content

Delete me.

5 replies [Last post]
rkic
Offline
Joined: 2007-08-01

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Rafael Santos

rkic

Does the exception reports the exact line where you try to encode the
file? Which is the colormodel of the original image?

Rafael
>
> I'm trying to convert an RGB image to IHS color space, change some bands and convert it back to RGB for display purposes ( ImageDisplay.set(image) ), but every time I try to display or save the image to disk with JAI.create("encode"... I get an ArrayIndexOutOfBoundsException error.
> I'm not sure why or what is causing this, so any help would be kindly appreciated.
>
> Code source: https://jaistuff.dev.java.net/code/operators.RGBtoIHS.html
>
>
> public RenderedOp colorByIHS(RenderedOp image) {
> JAI.setDefaultTileSize(new Dimension(image.getTileWidth(), image.getTileHeight()));
> IHSColorSpace ihs = IHSColorSpace.getInstance();
> ColorModel ihsColorModel = new ComponentColorModel(ihs, new int []{8,8,8}, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE) ;
> ParameterBlock pb = new ParameterBlock();
> pb.addSource(image);
> pb.add(ihsColorModel);
> RenderedImage ihsImage = JAI.create("colorconvert", pb);
> RenderedImage[] bands = new RenderedImage[3];
> for(int band=0; band<3; band++) {
> pb = new ParameterBlock();
> pb.addSource(ihsImage);
> pb.add(new int[]{band});
> bands[band] = JAI.create("bandselect",pb);
> }
> pb = new ParameterBlock();
> pb.add((float)image.getWidth());
> pb.add((float)image.getHeight());
> pb.add(new Byte[]{(byte)255});
> RenderedImage newIntensity = JAI.create("constant",pb);
> pb = new ParameterBlock();
> pb.add((float)image.getWidth());
> pb.add((float)image.getHeight());
> pb.add(new Byte[]{(byte)255});
> RenderedImage newSaturation = JAI.create("constant",pb);
> ImageLayout imageLayout = new ImageLayout();
> imageLayout.setColorModel(ihsColorModel);
> imageLayout.setSampleModel(ihsImage.getSampleModel());
> RenderingHints rendHints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT,imageLayout);
> pb = new ParameterBlock();
> pb.addSource(newIntensity);
> pb.addSource(bands[1]);
> pb.addSource(newSaturation);
> RenderedImage modifiedIhsImage = JAI.create("bandmerge", pb, rendHints);
> pb = new ParameterBlock();
> pb.addSource(modifiedIhsImage);
> pb.add(image.getColorModel());
> RenderedOp newImg = JAI.create("colorconvert", pb);
> return newImg;
> }
>
> If I try to use the set() method from ImageDisplay (came with the Tutorial demo of JAI demo's) I get the exception, and also when I try to save the image to disk. As long as I don't save/display, the code runs just fine, which makes me think that the actual conversion is okay, but it just can't display/save the new image properly.
>
> Thanks in advance for your help.
> [Message sent by forum member 'rkic' (rkic)]
>
> http://forums.java.net/jive/thread.jspa?messageID=232684
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

rkic
Offline
Joined: 2007-08-01

Rafael,

No I don't get the exact line where the error occurs. My stacktrace:

Exception in thread "AWT-EventQueue-1" java.lang.ArrayIndexOutOfBoundsException: 786434
at javax.media.jai.IHSColorSpace.fromRGBByte(IHSColorSpace.java:500)
at javax.media.jai.IHSColorSpace.fromRGB(IHSColorSpace.java:427)
at com.sun.media.jai.opimage.ColorConvertOpImage.computeRectColorSpaceJAIFromRGB(ColorConvertOpImage.java:329)
at com.sun.media.jai.opimage.ColorConvertOpImage.computeRect(ColorConvertOpImage.java:285)
at javax.media.jai.PointOpImage.computeTile(PointOpImage.java:914)
at com.sun.media.jai.util.SunTileScheduler.scheduleTile(SunTileScheduler.java:904)
at javax.media.jai.OpImage.getTile(OpImage.java:1129)
at javax.media.jai.PointOpImage.computeTile(PointOpImage.java:911)
at com.sun.media.jai.util.SunTileScheduler.scheduleTile(SunTileScheduler.java:904)
at javax.media.jai.OpImage.getTile(OpImage.java:1129)
at javax.media.jai.PointOpImage.computeTile(PointOpImage.java:962)
at com.sun.media.jai.util.SunTileScheduler.scheduleTile(SunTileScheduler.java:904)
at javax.media.jai.OpImage.getTile(OpImage.java:1129)
at javax.media.jai.PointOpImage.computeTile(PointOpImage.java:911)
at com.sun.media.jai.util.SunTileScheduler.scheduleTile(SunTileScheduler.java:904)
at javax.media.jai.OpImage.getTile(OpImage.java:1129)
at javax.media.jai.PlanarImage.copyData(PlanarImage.java:2343)
at javax.media.jai.PlanarImage.copyExtendedData(PlanarImage.java:2398)
at javax.media.jai.PlanarImage.getExtendedData(PlanarImage.java:2459)
at javax.media.jai.ScaleOpImage.computeTile(ScaleOpImage.java:1255)
at com.sun.media.jai.util.SunTileScheduler.scheduleTile(SunTileScheduler.java:904)
at javax.media.jai.OpImage.getTile(OpImage.java:1129)
at javax.media.jai.RenderedOp.getTile(RenderedOp.java:2257)
at imageeditor.ImageDisplay.paintComponent(ImageDisplay.java:362)
at javax.swing.JComponent.paint(JComponent.java:1027)
at javax.swing.JComponent.paintChildren(JComponent.java:864)
at javax.swing.JComponent.paint(JComponent.java:1036)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5122)
at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:285)
at javax.swing.RepaintManager.paint(RepaintManager.java:1128)
at javax.swing.JComponent._paintImmediately(JComponent.java:5070)
at javax.swing.JComponent.paintImmediately(JComponent.java:4880)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:723)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:679)
at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:659)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

The colormodel of the original image is RGB (I think) because it's just a jpeg image I opened with JAI.create.

rkic
Offline
Joined: 2007-08-01

I think I've somehow solved the ArrayOutOfBoundsException, but now I'm getting an exception that my ColorModel is incompatible with the image SampleModel. I've looked around the JAI-INTEREST archives and I've seen people with a similar problem but not quite this situation.

The image I'm loading has the following attributes:
-------------------
PlanarImage[
minX=130
minY=57
width=680
height=850
tileGridXOffset=0
tileGridYOffset=0
tileWidth=636
tileHeight=636 sampleModel=java.awt.image.PixelInterleavedSampleModel@3067402
colorModel=ColorModel: #pixelBits = 24
numComponents = 3
color space = java.awt.color.ICC_ColorSpace@940b84
transparency = 1
has alpha = false
isAlphaPre = false]

The exception:
---------------------
Exception in thread "AWT-EventQueue-1" java.lang.IllegalArgumentException: The specified ColorModel is incompatible with the image SampleModel.
at javax.media.jai.PlanarImage.setImageLayout(PlanarImage.java:535)
at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:867)
at javax.media.jai.RenderedOp.getSampleModel(RenderedOp.java:2233)
at javax.media.jai.operator.BandSelectDescriptor.validateArguments(BandSelectDescriptor.java:141)
at javax.media.jai.JAI.createNS(JAI.java:1086)
at javax.media.jai.JAI.create(JAI.java:973)
at javax.media.jai.JAI.create(JAI.java:1395)
at imageeditor.ImageUtils.colorByIHS(ImageUtils.java:106)
at imageeditor.Main.multiButtonPressed(Main.java:750)
at imageeditor.Main$9.mousePressed(Main.java:364)
at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:263)
at java.awt.Component.processMouseEvent(Component.java:6035)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5803)
at java.awt.Container.processEvent(Container.java:2058)
at java.awt.Component.dispatchEventImpl(Component.java:4410)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3983)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
at java.awt.Container.dispatchEventImpl(Container.java:2102)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

I really have no clue as to what the error is, since I'm fairly new to JAI and not exactly sure what a SampleModel is and does. I'd appreciate any help.

Brian Burkhalter

SampleModel-ColorModel compatibility is defined by Java 2D. To understand the
details of JAI you first need to understand at least the imaging portion of
Java 2D which is documented here:

http://java.sun.com/javase/6/docs/technotes/guides/2d/spec/j2d-image.htm...

The Java 2D guides in general are here:

http://java.sun.com/javase/6/docs/technotes/guides/2d/index.html

On Tue, 28 Aug 2007, jai-interest@javadesktop.org wrote:

> I really have no clue as to what the error is, since I'm fairly new to JAI and not exactly sure what a SampleModel is and does. I'd appreciate any help.
> [Message sent by forum member 'rkic' (rkic)]
>
> http://forums.java.net/jive/thread.jspa?messageID=232874

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

rkic
Offline
Joined: 2007-08-01

Thank you Brian, I will look in to those pages. So basically I have to specify a different ColorModel for the colorconvert?