Solved

Image manipulation using JAI

Posted on 2003-11-18
3
477 Views
Last Modified: 2008-02-26
I've created a java class, using the tutorials on the sun web site, that displays an image to the screen together with the function to zoom in on a highlighted area. The java class works fine with the image provided by the tutorial, however when I change the image I get the following error...

java.lang.IllegalArgumentException: Tables must be 0, 1, 2, or 3.
      at sun.awt.image.codec.JPEGParam.setDCHuffmanComponentMapping(JPEGParam.java:589)
      at sun.awt.image.codec.JPEGImageDecoderImpl.readJPEGStream(Native Method)
      at sun.awt.image.codec.JPEGImageDecoderImpl.decodeAsBufferedImage(JPEGImageDecoderImpl.java:226)
      at com.sun.media.jai.codecimpl.JPEGImage.<init>(JPEGImageDecoder.java:112)
      at com.sun.media.jai.codecimpl.JPEGImageDecoder.decodeAsRenderedImage(JPEGImageDecoder.java:51)
      at com.sun.media.jai.opimage.CodecRIFUtil.create(CodecRIFUtil.java:89)
      at com.sun.media.jai.opimage.JPEGRIF.create(JPEGRIF.java:52)
      at java.lang.reflect.Method.invoke(Native Method)
      at javax.media.jai.FactoryCache.invoke(FactoryCache.java:130)
      at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1669)
      at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:481)
      at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:340)
      at com.sun.media.jai.opimage.StreamRIF.create(StreamRIF.java:104)
      at java.lang.reflect.Method.invoke(Native Method)
      at javax.media.jai.FactoryCache.invoke(FactoryCache.java:130)
      at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1669)
      at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:481)
      at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:340)
      at com.sun.media.jai.opimage.FileLoadRIF.create(FileLoadRIF.java:109)
      at java.lang.reflect.Method.invoke(Native Method)
      at javax.media.jai.FactoryCache.invoke(FactoryCache.java:130)
      at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1669)
      at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:481)
      at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:340)
      at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:805)
      at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:853)
      at javax.media.jai.RenderedOp.getWidth(RenderedOp.java:2135)
      at kris.test.zoom.ImageDisplay.initialize(ImageDisplay.java:101)
      at kris.test.zoom.ImageDisplay.<init>(ImageDisplay.java:156)
      at kris.test.zoom.About.<init>(About.java:66)
      at kris.test.zoom.KeyFromImageMagnifier.<init>(KeyFromImageMagnifier.java:95)
      at java.lang.reflect.Constructor.newInstance(Native Method)
      at com.ibm.etools.jbcf.vce.launcher.remotevm.JavaBeansLauncher.main(JavaBeansLauncher.java:81)

I've traced the error back to the declaration of the image...

private About aboutPanel = new About("C:\\presc.jpg",
                                        Magnifier.DEFAULT_MAGNIFICATION);     // this doesn't work

private About aboutPanel = new About("C:\\JaiTutor\\images\\Pisa.jpg",          
                                       Magnifier.DEFAULT_MAGNIFICATION);           // this does work!!!

what's confusing is the fact that both images are JPEG images. I've heard that there are different types of JPEG image, if this is correct is there anyway of changing the code so all types of JPEG images are excepted?

I'd be very grateful to anyone who can shed some light onto this problem

Thanks
Kris
0
Comment
Question by:krisjburn
3 Comments
 
LVL 1

Accepted Solution

by:
B000GT earned 250 total points
Comment Utility
I'm not certain as to if a certain JPEG is different from another JPEG and i haven't run through the example but i have searched around and found the API for JAI
and have traced a few of the sources for the JAI files you are looking into...
i'll let you do the rest of the work because i need sleep...
here are the links
SOURCES:
http://developer.java.sun.com/developer/onlineTraining/javaai/jai/src/ImageDisplay.java
http://developer.java.sun.com/developer/onlineTraining/javaai/jai/src/About.java
API DOCS:
http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/

I think that you will find that if you take the JAI sources, all of them after downloading them and snooping through the files that lead to one another you, you can pinpoint where the error is occuring in the sources, and maybe from their, either fix it yourself, or write a fix and send it to sun...if you find that it needs to be fixed.

hope my searching around has helped a bit...

i believe you will find this in ImageDisplay.java interesting

/**
     * Default constructor
     */
    public ImageDisplay() {
        super();
        source = null;

        lutData = new byte[256];

        for ( int i = 0; i < 256; i++ ) {
            lutData[i] = (byte)i;
        }

        componentWidth  = 64;
        componentHeight = 64;
        setPreferredSize(new Dimension(componentWidth, componentHeight));
        setOrigin(0, 0);
    }

    /**
     * Constructs an ImageDisplay to display a PlanarImage.
     *
     * @param source a PlanarImage to be displayed.
     */
    public ImageDisplay(PlanarImage im) {
        super();
        source = im;
        initialize();

        lutData = new byte[256];

        for ( int i = 0; i < 256; i++ ) {
            lutData[i] = (byte)i;
        }

        setOrigin(0, 0);
    }
........................................

hope it helps

- nc
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now