-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
5.0
-
x86
-
windows_xp
A DESCRIPTION OF THE REQUEST :
Loading JPEG files to IIOImage (with metadata included) that have multiple
APP0 markers fails.
According to Spec JFIF 1.02 multiple APP0 markers are allowed on JPEG files.
ImageIO doesn't support multiple APP0 markers when metadata is accessed.
JUSTIFICATION :
* More JPEG files could be read to IIOImage
* The current standard should be supported
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Metadata from JPEG files with multiple APP0 markers should be accepted by ImageIO.
ACTUAL -
With ImageIO a second APP0 marker leads to the following exception when read to IIOImage:
"javax.imageio.IIOException: JFIF APP0 must be first marker after SOI"
---------- BEGIN SOURCE ----------
import java.io.File;
import java.io.FileInputStream;
import java.util.Iterator;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
public class Imaging {
/**
* Load a JPEG with multiple APP0 markers.
* @param argv Arguments
**/
public static final void main(String[] argv) {
File file = new File("Page1.jpg");
FileInputStream fis = null;
ImageReader reader = null;
IIOImage image;
try {
fis = new FileInputStream(file);
// get reader
Iterator readers = ImageIO.getImageReadersByMIMEType("image/jpeg");
if (!readers.hasNext()) {
throw new Exception("Format image/jpeg not supported for input");
}
reader = (ImageReader)readers.next();
// set input
ImageInputStream iis = ImageIO.createImageInputStream(fis);
reader.setInput(iis, true);
// read image
image = reader.readAll(0, null);
} catch(Exception ex) {
ex.printStackTrace();
} finally {
if(fis!=null) {
try { fis.close(); } catch(Exception ex) {}
}
if (reader!=null) {
reader.dispose();
}
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Read to BufferedImage without metadata - not a workaround if metadata is needed.
Because the Image with multiple APP0 markers is created through another
bug in ImageIO JPEGWriter I have a workaround for that.
Loading JPEG files to IIOImage (with metadata included) that have multiple
APP0 markers fails.
According to Spec JFIF 1.02 multiple APP0 markers are allowed on JPEG files.
ImageIO doesn't support multiple APP0 markers when metadata is accessed.
JUSTIFICATION :
* More JPEG files could be read to IIOImage
* The current standard should be supported
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Metadata from JPEG files with multiple APP0 markers should be accepted by ImageIO.
ACTUAL -
With ImageIO a second APP0 marker leads to the following exception when read to IIOImage:
"javax.imageio.IIOException: JFIF APP0 must be first marker after SOI"
---------- BEGIN SOURCE ----------
import java.io.File;
import java.io.FileInputStream;
import java.util.Iterator;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
public class Imaging {
/**
* Load a JPEG with multiple APP0 markers.
* @param argv Arguments
**/
public static final void main(String[] argv) {
File file = new File("Page1.jpg");
FileInputStream fis = null;
ImageReader reader = null;
IIOImage image;
try {
fis = new FileInputStream(file);
// get reader
Iterator readers = ImageIO.getImageReadersByMIMEType("image/jpeg");
if (!readers.hasNext()) {
throw new Exception("Format image/jpeg not supported for input");
}
reader = (ImageReader)readers.next();
// set input
ImageInputStream iis = ImageIO.createImageInputStream(fis);
reader.setInput(iis, true);
// read image
image = reader.readAll(0, null);
} catch(Exception ex) {
ex.printStackTrace();
} finally {
if(fis!=null) {
try { fis.close(); } catch(Exception ex) {}
}
if (reader!=null) {
reader.dispose();
}
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Read to BufferedImage without metadata - not a workaround if metadata is needed.
Because the Image with multiple APP0 markers is created through another
bug in ImageIO JPEGWriter I have a workaround for that.