Solved

Image manipulation using JAI

Posted on 2003-11-18
3
486 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Protect jar file - windows app 2 65
Application launch issue with Apache Tomcat 5 64
How to get all the API from website? 11 106
restrict decimal places for double datatype 10 22
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

828 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