Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Image manipulation using JAI

Posted on 2003-11-18
3
Medium Priority
?
505 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
1 Comment
 
LVL 1

Accepted Solution

by:
B000GT earned 1000 total points
ID: 9776839
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

877 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