Problem with imageio: ImageReader stalls on JPEGs at ~95%

Discussion in 'Java' started by Aaron Davies, Jun 25, 2004.

  1. Aaron Davies

    Aaron Davies Guest

    I'm trying to write some classes for my collaborative whiteboard to
    transmit images over the network, using the javax.imageio API, but I'm
    running into an odd problem: my code words fine with PNGs, but not
    with JPEGs. As you can see below, I've attached a progress listener to
    the reader, which reports progress up to just under 95%, then nothing.
    The warning listener reports no warnings. The images are written by an
    ImageWriter in another section of the code, which also uses the same
    listeners, and *does* report completion w/o warnings. With PNGs, the
    read completes just fine. Any help would be much appreciated; snippets
    follow. (ImageStatusUpdater is a class of mine which implements
    IIOReadProgressListener, IIOWriteProgressListener,
    IIOReadWarningListener, and IIOWriteWarningListener.)

    From the writer's code:

    Socket _soc = serverSocket.accept();
    ImageWriter _writer = (ImageWriter)
    ImageIO.getImageWritersByFormatName(
    format).next();
    ImageStatusUpdater _isu = new ImageStatusUpdater();
    _writer.addIIOWriteProgressListener(_isu);
    _writer.addIIOWriteWarningListener(_isu);
    _writer.setOutput(ImageIO.createImageOutputStream(_soc
    .getOutputStream()));
    _writer.write(image);

    And the reader's:

    Socket _socket = new Socket(ip, port);
    ImageReader _ir = (ImageReader) ImageIO.
    getImageReadersBySuffix(suffix).next();
    ImageStatusUpdater _isu = new ImageStatusUpdater();
    _ir.addIIOReadProgressListener(_isu);
    _ir.addIIOReadWarningListener(_isu);
    InputStream _is = _socket.getInputStream();
    ImageInputStream _iis = ImageIO.createImageInputStream(_is);
    _ir.setInput(_iis, true, true);
    imageIcon.setImage(_ir.read(0));
     
    Aaron Davies, Jun 25, 2004
    #1
    1. Advertising

  2. Aaron Davies

    ak Guest

    > I'm trying to write some classes for my collaborative whiteboard to
    > transmit images over the network, using the javax.imageio API, but I'm
    > running into an odd problem: my code words fine with PNGs, but not
    > with JPEGs. As you can see below, I've attached a progress listener to
    > the reader, which reports progress up to just under 95%, then nothing.
    > The warning listener reports no warnings. The images are written by an
    > ImageWriter in another section of the code, which also uses the same
    > listeners, and *does* report completion w/o warnings. With PNGs, the
    > read completes just fine. Any help would be much appreciated; snippets
    > follow. (ImageStatusUpdater is a class of mine which implements
    > IIOReadProgressListener, IIOWriteProgressListener,
    > IIOReadWarningListener, and IIOWriteWarningListener.)
    >
    > From the writer's code:
    >
    > Socket _soc = serverSocket.accept();
    > ImageWriter _writer = (ImageWriter)
    > ImageIO.getImageWritersByFormatName(
    > format).next();
    > ImageStatusUpdater _isu = new ImageStatusUpdater();
    > _writer.addIIOWriteProgressListener(_isu);
    > _writer.addIIOWriteWarningListener(_isu);
    > _writer.setOutput(ImageIO.createImageOutputStream(_soc
    > .getOutputStream()));
    > _writer.write(image);
    >


    I think, that you need to flush your output stream just after writeImage.

    --
    http://uio.dev.java.net Unified I/O for Java
    http://reader.imagero.com Java image reader
     
    ak, Jun 26, 2004
    #2
    1. Advertising

  3. Aaron Davies

    Aaron Davies Guest

    "ak" <> wrote in message news:<cbiju4$50v$>...
    > > I'm trying to write some classes for my collaborative whiteboard to
    > > transmit images over the network, using the javax.imageio API, but I'm
    > > running into an odd problem: my code words fine with PNGs, but not
    > > with JPEGs. As you can see below, I've attached a progress listener to
    > > the reader, which reports progress up to just under 95%, then nothing.
    > > The warning listener reports no warnings. The images are written by an
    > > ImageWriter in another section of the code, which also uses the same
    > > listeners, and *does* report completion w/o warnings. With PNGs, the
    > > read completes just fine. Any help would be much appreciated; snippets
    > > follow. (ImageStatusUpdater is a class of mine which implements
    > > IIOReadProgressListener, IIOWriteProgressListener,
    > > IIOReadWarningListener, and IIOWriteWarningListener.)
    > >
    > > From the writer's code:
    > >
    > > Socket _soc = serverSocket.accept();
    > > ImageWriter _writer = (ImageWriter)
    > > ImageIO.getImageWritersByFormatName(
    > > format).next();
    > > ImageStatusUpdater _isu = new ImageStatusUpdater();
    > > _writer.addIIOWriteProgressListener(_isu);
    > > _writer.addIIOWriteWarningListener(_isu);
    > > _writer.setOutput(ImageIO.createImageOutputStream(_soc
    > > .getOutputStream()));
    > > _writer.write(image);
    > >

    >
    > I think, that you need to flush your output stream just after writeImage.



    I just tried it, it doesn't help. Also, why would that affect JPEGs but not PNGs?
     
    Aaron Davies, Jun 28, 2004
    #3
  4. Aaron Davies

    Roedy Green Guest

    On 28 Jun 2004 08:04:22 -0700, (Aaron Davies)
    wrote or quoted :

    >I just tried it, it doesn't help. Also, why would that affect JPEGs but not PNGs?


    non-existent and irrelevant newesgroups snipped.


    JPEG is a compressed format. These are notorious for not giving you
    all the bytes you ask for on each read. Like GZIP you likely must be
    careful with flushes, finisheds and too keep reading even after fewer
    bytes than you requested.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Jun 28, 2004
    #4
  5. Aaron Davies

    dar7yl Guest

    "Aaron Davies" <> wrote in message
    news:...
    > I'm trying to write some classes for my collaborative whiteboard to
    > transmit images over the network, using the javax.imageio API, but I'm
    > running into an odd problem: my code words fine with PNGs, but not
    > with JPEGs. As you can see below, I've attached a progress listener to
    > the reader, which reports progress up to just under 95%, then nothing.


    It could be that the progress is actually 100% complete, but the listener is
    stalled on the proverbial event-dispatch-loop while something in the cleanup
    code is infinite-looping. Just a hint to look "outside the box".
    --
    regards,
    Dar7yl (the 7 is silent)
     
    dar7yl, Jun 30, 2004
    #5
    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,190
  2. Tom Davies

    Monitoring thread stalls

    Tom Davies, Oct 18, 2003, in forum: Java
    Replies:
    3
    Views:
    861
    Robert Olofsson
    Oct 18, 2003
  3. Davidski
    Replies:
    0
    Views:
    3,921
    Davidski
    Nov 5, 2004
  4. jasonM

    Creating an ImageReader

    jasonM, Oct 14, 2008, in forum: Java
    Replies:
    8
    Views:
    558
    John B. Matthews
    Oct 15, 2008
  5. Harold Yarmouth

    Bugs in javax.imageio.ImageReader

    Harold Yarmouth, Oct 27, 2008, in forum: Java
    Replies:
    4
    Views:
    3,485
    Harold Yarmouth
    Oct 30, 2008
Loading...

Share This Page