Skip to main content

[JAI-IMAGEIO] problems reading jpeg...

12 replies [Last post]
Anonymous

When I try to read the attached file, I get the following exception:

javax.imageio.IIOException: JFIF APP0 must be first marker after SOI
at com.sun.imageio.plugins.jpeg.JPEGMetadata.
(JPEGMetadata.java:206)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.getImageMetadata
(JPEGImageReader.java:853)
at tyler.empire.image.ImageUtilities.getImage(ImageUtilities.java:614)
at tyler.empire.image.ImageUtilities.getImage(ImageUtilities.java:508)
at tyler.empire.image.ImageUtilities.getImage(ImageUtilities.java:493)
at tyler.empire.image.TestReadImage.main(TestReadImage.java:30)

If I tell the reader to not read any metadata, it reads fine.
jpeginfo says the file is OK.

Is it because the file is an EXIF?

I am using the J2Se JPEG imageio plugin. I cannot use the ImageIO
tools jpeg reader because of critical bugs in it that cause JVM
crashes on some images.

Thoughts?
Robert Engels



[att1.html]
[tt49311.jpg]

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
marber
Offline
Joined: 2007-12-20

Hi,
I get the same exception in my application.
I wrote a program that read a JPEG, change it and save it in a new JPEG file. I need that the new jpeg file preserve the original metadata.
To read metadata from source jpeg I use the same code you use before.
If I try my code on your jpeg (the one you attached here) I get the same exeption.

Googling, I read that it's possible to read IIOMetadata by JAI without getting this exception but I have not idea how to do it.
Could someone help me and describe me how to write the code in this way?.

Thanks to all.

bpb
Offline
Joined: 2004-06-23

You use exactly the same code as for the Java SE javax.imageio JPEG plugins but you have to have Image I/O Tools (http://jai-imageio.dev.java.net) installed - including the native libraries.

Brian

> Googling, I read that it's possible to read
> IIOMetadata by JAI without getting this exception but
> I have not idea how to do it.
> Could someone help me and describe me how to write
> the code in this way?.

mjacob@union06.de

That is what I found out also. Only the call to getMetadata()
leads to this Exception.

@Brian
If you can't reproduce this with a call to getMetadata() in your
version of Java I will have to check which version we use.
I'm sure it is not the latest 1.5.

>You have to request the metadata - standard ImageIO.read() sets the
>"skip metadata" flag.
>
>I have the problem with 1.5._07 and _12.
>
>On Nov 2, 2007, at 12:57 PM, jai-imageio@javadesktop.org wrote:
>
>> Which version of Java SE is at issue here? I can load it using
>> 1.5.0_13.
>>
>> Brian
>>
>>> It seems that there are two APP0 marker. I remember I
>>> encountered something with
>>> pure Java JDK JPEG decoder. The JDK decoder can't
>>> handle two APP0.
>>> But the encoder can write it ... its a bug according
>>> to the specs.
>>>
>>> Kind regards,
>>> Marco
>>> --
>>> Marco Jacob, PMP
>>> Prisma GmbH, Germany
>>>
>>> When I try to read the attached file, I get the
>>> following exception:
>>>
>>>
>>>
>>> javax.imageio.IIOException: JFIF APP0 must be first
>>> marker after SOI
>>> at
>>> com.sun.imageio.plugins.jpeg.JPEGMetadata.(JPEGM
>>> etadata.java:206)
>>> at
>>> com.sun.imageio.plugins.jpeg.JPEGImageReader.getImageM
>>> etadata(JPEGImageReader.java:853)
>>> at
>>> tyler.empire.image.ImageUtilities.getImage(ImageUtilit
>>> ies.java:614)
>>> at
>>> tyler.empire.image.ImageUtilities.getImage(ImageUtilit
>>> ies.java:508)
>>> at
>>> tyler.empire.image.ImageUtilities.getImage(ImageUtilit
>>> ies.java:493)
>>> at
>>> tyler.empire.image.TestReadImage.main(TestReadImage.ja
>>> va:30)
>>>
>>>
>>> If I tell the reader to not read any metadata, it
>>> reads fine. jpeginfo says the file is OK.
>>>
>>>
>>> Is it because the file is an EXIF?
>>>
>>>
>>> I am using the J2Se JPEG imageio plugin. I cannot use
>>> the ImageIO tools jpeg reader because of critical
>>> bugs in it that cause JVM crashes on some images.
>>>
>>>
>>> Thoughts?
>>> Robert Engels
>>> [att1.html]
>>> [tt49311.jpg]
>> [Message sent by forum member 'bpb' (bpb)]
>>
>> http://forums.java.net/jive/thread.jspa?messageID=243543

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

bpb
Offline
Joined: 2004-06-23

Sorry but I must have been asleep before.

When attempting to get the metadata of this image I get this error

Exception in thread "main" javax.imageio.IIOException: JFIF APP0 must be first marker after SOI
at com.sun.imageio.plugins.jpeg.JPEGMetadata.(JPEGMetadata.java:206)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.getImageMetadata(JPEGImageReader.java:904)

for 1.5.0_13 and 1.6.0_03 on Solaris-sparc. As this is Java code I would expect the same error on all platforms.

The JAI Image I/O Tools plugin works correctly; this error message is from Java SE.

> That is what I found out also. Only the call to
> getMetadata()
> leads to this Exception.
>
> @Brian
> If you can't reproduce this with a call to
> getMetadata() in your
> version of Java I will have to check which version we
> use.
> I'm sure it is not the latest 1.5.
>
> >You have to request the metadata - standard
> ImageIO.read() sets the
> >"skip metadata" flag.
> >
> >I have the problem with 1.5._07 and _12.
> >
> >On Nov 2, 2007, at 12:57 PM,
> jai-imageio@javadesktop.org wrote:
> >
> >> Which version of Java SE is at issue here? I can
> load it using
> >> 1.5.0_13.
> >>
> >> Brian
> >>
> >>> It seems that there are two APP0 marker. I
> remember I
> >>> encountered something with
> >>> pure Java JDK JPEG decoder. The JDK decoder can't
> >>> handle two APP0.
> >>> But the encoder can write it ... its a bug
> according
> >>> to the specs.
> >>>
> >>> Kind regards,
> >>> Marco
> >>> --
> >>> Marco Jacob, PMP
> >>> Prisma GmbH, Germany
> >>>
> >>> When I try to read the attached file, I get the
> >>> following exception:
> >>>
> >>>
> >>>
> >>> javax.imageio.IIOException: JFIF APP0 must be
> first
> >>> marker after SOI
> >>> at
> >>>
> com.sun.imageio.plugins.jpeg.JPEGMetadata.(JPEGM
> >>> etadata.java:206)
> >>> at
> >>>
> com.sun.imageio.plugins.jpeg.JPEGImageReader.getImageM
> >>> etadata(JPEGImageReader.java:853)
> >>> at
> >>>
> tyler.empire.image.ImageUtilities.getImage(ImageUtilit
> >>> ies.java:614)
> >>> at
> >>>
> tyler.empire.image.ImageUtilities.getImage(ImageUtilit
> >>> ies.java:508)
> >>> at
> >>>
> tyler.empire.image.ImageUtilities.getImage(ImageUtilit
> >>> ies.java:493)
> >>> at
> >>>
> tyler.empire.image.TestReadImage.main(TestReadImage.ja
> >>> va:30)
> >>>
> >>>
> >>> If I tell the reader to not read any metadata, it
> >>> reads fine. jpeginfo says the file is OK.
> >>>
> >>>
> >>> Is it because the file is an EXIF?
> >>>
> >>>
> >>> I am using the J2Se JPEG imageio plugin. I cannot
> use
> >>> the ImageIO tools jpeg reader because of critical
> >>> bugs in it that cause JVM crashes on some images.
> >>>
> >>>
> >>> Thoughts?
> >>> Robert Engels
> >>> [att1.html]
> >>> [tt49311.jpg]
> >> [Message sent by forum member 'bpb' (bpb)]
> >>
> >>
> http://forums.java.net/jive/thread.jspa?messageID=2435
> 43
>
> ------------------------------------------------------
> ---------------
> To unsubscribe, e-mail:
> interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail:
> interest-help@jai-imageio.dev.java.net

mjacob@union06.de

It seems that there are two APP0 marker. I remember I encountered something with
pure Java JDK JPEG decoder. The JDK decoder can't handle two APP0.
But the encoder can write it ... its a bug according to the specs.

Kind regards,
  Marco
--
Marco Jacob, PMP
Prisma GmbH, Germany

 When I try to read the attached file, I get the following exception:

javax.imageio.IIOException: JFIF APP0 must be first marker after SOI
at com.sun.imageio.plugins.jpeg.JPEGMetadata.(JPEGMetadata.java:206)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.getImageMetadata(JPEGImageReader.java:853)
at tyler.empire.image.ImageUtilities.getImage(ImageUtilities.java:614)
at tyler.empire.image.ImageUtilities.getImage(ImageUtilities.java:508)
at tyler.empire.image.ImageUtilities.getImage(ImageUtilities.java:493)
at tyler.empire.image.TestReadImage.main(TestReadImage.java:30)

If I tell the reader to not read any metadata, it reads fine. jpeginfo says the file is OK.

Is it because the file is an EXIF?

I am using the J2Se JPEG imageio plugin. I cannot use the ImageIO tools jpeg reader because of critical bugs in it that cause JVM crashes on some images.

Thoughts?
Robert Engels
[att1.html]
[tt49311.jpg]

bpb
Offline
Joined: 2004-06-23

Which version of Java SE is at issue here? I can load it using 1.5.0_13.

Brian

> It seems that there are two APP0 marker. I remember I
> encountered something with
> pure Java JDK JPEG decoder. The JDK decoder can't
> handle two APP0.
> But the encoder can write it ... its a bug according
> to the specs.
>
> Kind regards,
> Marco
> --
> Marco Jacob, PMP
> Prisma GmbH, Germany
>
> When I try to read the attached file, I get the
> following exception:
>
>
>
> javax.imageio.IIOException: JFIF APP0 must be first
> marker after SOI
> at
> com.sun.imageio.plugins.jpeg.JPEGMetadata.(JPEGM
> etadata.java:206)
> at
> com.sun.imageio.plugins.jpeg.JPEGImageReader.getImageM
> etadata(JPEGImageReader.java:853)
> at
> tyler.empire.image.ImageUtilities.getImage(ImageUtilit
> ies.java:614)
> at
> tyler.empire.image.ImageUtilities.getImage(ImageUtilit
> ies.java:508)
> at
> tyler.empire.image.ImageUtilities.getImage(ImageUtilit
> ies.java:493)
> at
> tyler.empire.image.TestReadImage.main(TestReadImage.ja
> va:30)
>
>
> If I tell the reader to not read any metadata, it
> reads fine. jpeginfo says the file is OK.
>
>
> Is it because the file is an EXIF?
>
>
> I am using the J2Se JPEG imageio plugin. I cannot use
> the ImageIO tools jpeg reader because of critical
> bugs in it that cause JVM crashes on some images.
>
>
> Thoughts?
> Robert Engels
> [att1.html]
> [tt49311.jpg]

robert engels

You have to request the metadata - standard ImageIO.read() sets the
"skip metadata" flag.

I have the problem with 1.5._07 and _12.

On Nov 2, 2007, at 12:57 PM, jai-imageio@javadesktop.org wrote:

> Which version of Java SE is at issue here? I can load it using
> 1.5.0_13.
>
> Brian
>
>> It seems that there are two APP0 marker. I remember I
>> encountered something with
>> pure Java JDK JPEG decoder. The JDK decoder can't
>> handle two APP0.
>> But the encoder can write it ... its a bug according
>> to the specs.
>>
>> Kind regards,
>> Marco
>> --
>> Marco Jacob, PMP
>> Prisma GmbH, Germany
>>
>> When I try to read the attached file, I get the
>> following exception:
>>
>>
>>
>> javax.imageio.IIOException: JFIF APP0 must be first
>> marker after SOI
>> at
>> com.sun.imageio.plugins.jpeg.JPEGMetadata.(JPEGM
>> etadata.java:206)
>> at
>> com.sun.imageio.plugins.jpeg.JPEGImageReader.getImageM
>> etadata(JPEGImageReader.java:853)
>> at
>> tyler.empire.image.ImageUtilities.getImage(ImageUtilit
>> ies.java:614)
>> at
>> tyler.empire.image.ImageUtilities.getImage(ImageUtilit
>> ies.java:508)
>> at
>> tyler.empire.image.ImageUtilities.getImage(ImageUtilit
>> ies.java:493)
>> at
>> tyler.empire.image.TestReadImage.main(TestReadImage.ja
>> va:30)
>>
>>
>> If I tell the reader to not read any metadata, it
>> reads fine. jpeginfo says the file is OK.
>>
>>
>> Is it because the file is an EXIF?
>>
>>
>> I am using the J2Se JPEG imageio plugin. I cannot use
>> the ImageIO tools jpeg reader because of critical
>> bugs in it that cause JVM crashes on some images.
>>
>>
>> Thoughts?
>> Robert Engels
>> [att1.html]
>> [tt49311.jpg]
> [Message sent by forum member 'bpb' (bpb)]
>
> http://forums.java.net/jive/thread.jspa?messageID=243543
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-
> imageio.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

bpb
Offline
Joined: 2004-06-23

Weird. I'm not seeing it on Solaris at even 1.4.2_16.

> You have to request the metadata - standard
> ImageIO.read() sets the
> "skip metadata" flag.
>
> I have the problem with 1.5._07 and _12.
>
> On Nov 2, 2007, at 12:57 PM,
> jai-imageio@javadesktop.org wrote:
>
> > Which version of Java SE is at issue here? I can
> load it using
> > 1.5.0_13.

robert engels

Sorry I confused the issue...

The code that fails is:

IIOMetadata imageMetadata = reader.getImageMetadata(0);

It fails for us under OSX, Linux and Windows using the
JPEGImageReader plugin.

Our image code always read the metadata... if that call fails, it
thens set the Input using

reader.setInput(stream, false, true);

Robert

On Nov 2, 2007, at 1:44 PM, jai-imageio@javadesktop.org wrote:

> Weird. I'm not seeing it on Solaris at even 1.4.2_16.
>
>> You have to request the metadata - standard
>> ImageIO.read() sets the
>> "skip metadata" flag.
>>
>> I have the problem with 1.5._07 and _12.
>>
>> On Nov 2, 2007, at 12:57 PM,
>> jai-imageio@javadesktop.org wrote:
>>
>>> Which version of Java SE is at issue here? I can
>> load it using
>>> 1.5.0_13.
> [Message sent by forum member 'bpb' (bpb)]
>
> http://forums.java.net/jive/thread.jspa?messageID=243560
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-
> imageio.dev.java.net
>

[att1.html]

jiezhang
Offline
Joined: 2005-12-29

JPEG standard requests APP0 be the first marker after SOI.
In the image, EXIF maker is immediate after SOI and before APP0 marker.
So you can move EXIF after APP0 then should work.

robert engels

Thanks. Strange that jpeginfo says the file is fine.

Is there some other tool people use to validate the correctness of a
jpeg file?

On Nov 1, 2007, at 3:11 PM, jai-imageio@javadesktop.org wrote:

> JPEG standard requests APP0 be the first marker after SOI.
> In the image, EXIF maker is immediate after SOI and before APP0
> marker.
> So you can move EXIF after APP0 then should work.
> [Message sent by forum member 'jiezhang' (jiezhang)]
>
> http://forums.java.net/jive/thread.jspa?messageID=243376
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-
> imageio.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

jiezhang
Offline
Joined: 2005-12-29

Many image tools tolerate this issue although it does not follow the standard strictly.
It is hard to find a validation tool.
But you can rewrite the image then you will correct image.