Solved

Image manipulation using JAI

Posted on 2003-11-18
3
496 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

635 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