javax.imageio.IIOException: Missing Huffman code

Discussion in 'Java' started by niko, Feb 11, 2005.

  1. niko

    niko Guest

    Posted this in the sun java forums without any replies. Posting it
    here too...
    ---------------------------------------------------------------------------


    Does anyone know what the exception "javax.imageio.IIOException:
    Missing Huffman code table entry" is indicating? My code reads and
    writes an image to disk using the image io APIs. Most images are ok
    but for some of them, I get the exception. The images come from
    external sources, usually direct from digital cameras and look fine in
    any browser/viewer.

    Any ideas?

    This is the code:

    static public void testProblem(File src, File dest, IPTCInfo info)
    throws Exception {

    ImageReader reader = null;
    ImageWriter writer = null;
    ImageInputStream iis = null;
    ImageOutputStream ios = null;
    BufferedImage buff = null;
    IIOMetadata metadata = null;


    try {
    // First, find a reader for jpg which handles metdata

    Iterator it = ImageIO.getImageReadersByFormatName("jpg");
    while (it.hasNext() && metadata==null) {

    /**
    * Try this reader...
    */

    reader = (ImageReader) it.next();

    //Open up the ImageInputStream

    iis = ImageIO.createImageInputStream(src);

    if (iis!=null) {

    // Set the readers stream
    reader.setInput(iis);
    // Read the pixels and metadata
    buff = reader.read(0);

    metadata = reader.getImageMetadata(0);

    if (metadata==null)
    iis.close();

    }
    }

    if (metadata==null)
    throw new Exception("IPTCUtil: No metadata found");


    // Writing the File

    writer = ImageIO.getImageWriter(reader);

    IIOImage outImage = new IIOImage(buff,null, metadata);
    ios = ImageIO.createImageOutputStream(dest);
    writer.setOutput(ios);
    writer.write(metadata,outImage,null);

    } catch (Exception ex) {
    throw ex;
    } finally {
    if (reader!=null)
    reader.dispose();
    if (writer!=null)
    writer.dispose();
    if (iis!=null)
    iis.close();
    if (ios!=null)
    ios.close();
    }
    }
     
    niko, Feb 11, 2005
    #1
    1. Advertising

  2. > Does anyone know what the exception "javax.imageio.IIOException:
    > Missing Huffman code table entry" is indicating?


    Huffman table should be embedded into image.
    Without Huffman table image can't be decompressed.

    --
    Andrey Kuznetsov
    http://uio.dev.java.net Unified I/O for Java
    http://reader.imagero.com Java image reader
    http://jgui.imagero.com Java GUI components and utilities
     
    Andrey Kuznetsov, Feb 11, 2005
    #2
    1. Advertising

  3. niko

    niko Guest

    "Andrey Kuznetsov" <> wrote in message news:<cuj9th$2ds$>...
    > > Does anyone know what the exception "javax.imageio.IIOException:
    > > Missing Huffman code table entry" is indicating?

    >
    > Huffman table should be embedded into image.
    > Without Huffman table image can't be decompressed.


    Thanx, I was able to store the file by passing a parameter of class
    JPEGImageWriteParam and calling setOptimizeHuffmanTables(true)
    when writing it to disk.



    / niko
     
    niko, Feb 12, 2005
    #3
  4. niko

    niko Guest

    "Andrey Kuznetsov" <> wrote in message news:<cuj9th$2ds$>...
    > > Does anyone know what the exception "javax.imageio.IIOException:
    > > Missing Huffman code table entry" is indicating?

    >
    > Huffman table should be embedded into image.
    > Without Huffman table image can't be decompressed.


    Also, the images that gave the exception look fine when I view them.
    But, do you think that they might be faulty or anything? (By faulty I
    mean non JPEG conformant, but still viewable by "not so picky"
    viewers?
     
    niko, Feb 12, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. F C
    Replies:
    2
    Views:
    5,219
  2. Paul  Smith
    Replies:
    0
    Views:
    759
    Paul Smith
    Nov 18, 2003
  3. Davidski
    Replies:
    0
    Views:
    3,950
    Davidski
    Nov 5, 2004
  4. Robert Metzger
    Replies:
    1
    Views:
    4,252
    Andrey Kuznetsov
    Jan 14, 2005
  5. Chris Berg
    Replies:
    1
    Views:
    2,774
    Andrew Thompson
    Jul 15, 2005
Loading...

Share This Page