Image I/O Enhancements in Java™ SE 6.0 |
Guide-Index |
A writer plug-in for the GIF file format
While reading capabilities for the GIF file format have been available since Java SE 1.4, the
com.sun.media.imageio.plugins.gif
package lacked a writer. The newly added GIF image writer enables writing images which satisfy the following requirements:
- The number of bands is 1
- The number of bits per sample is not greater than 8
- The size of a color component is not greater than 8
Additionally, the GIF images writer supports the animated GIF images creation through the standard methods defined in the
ImageWriter
class. See more details about the GIF images writer in the Standard plug-in for GIF image format notes.New methods for file formats filtering
Two new methods were introduced in theImageIO
class that obtain file suffixes to be filtered. ThegetReaderFileSuffixes()
andgetWriterFileSuffixes
methods return an array ofStrings
listing all of the file suffixes associated with the formats recognized by the current set of registered readers and writers.
API and doc changes
4972087
Quality Desc
andQuality Values
arrays are of the same length for JPG:The .
4953566 The
mark()
orreset()
methods of theImageInputStream class
do not work properly with PNGImageReader
:The following note was added to the
ImageInputStream
class specification to clarify thatImageReader
classes are allowed to call theflushBefore()
as part of the decoding process:Note that it is valid for an ImageReader to call flushBefore as part of a read operation. Therefore, if an application calls the mark prior to passing that stream to an ImageReader, the application should not assume that the marked position will remain valid after the read operation has completed.
5068322 The
Thejavax.imageio.plugins.jpeg.JPEGQTable.toString()
method produces incorrect description:toString()
method of theJPEGQTable
class in the packagejavax.imageio.plugins.jpeg
was supposed to return aString
object containing the values of the table, but instead repeated only the first line of the table. The performed fix eliminate this error.6359957 Wrong doc URL reference for PNG specification:
The link to the PNG specification in the javax.imageio.metadata package was corrected to the following URL:
http://www.libpng.org/pub/png/spec/
6457035 javadoc for
TheImageInputStreamImpl.read()
method is missing:ImageInputStreamImpl.java
file had a missing '*' character at the beginning of the javadoc for the abstractread()
method definition. The fix fills in the missing character.BMP plugin improvements
6294920 The
BMPImageReader
class fails to read3BYTE_BGR
images encoded using BMP Writer withBI_JPEG
compression:While attempting to write an image of the
BI_JPEG
compression type, thejava.io.EOFException
was thrown by theBMPImageReader
class. The problem was that theBMPImageReader
class did not process embedded images both ofBI_JPEG
andBI_PNG
types. To resolve this problem, the embedded image handling is moved to separate code.6297016 Output BMP image is distorted when writing
TYPE_3BYTE_BGR
buffered image withBI_BITFIELDS
compression:While attempting to write a buffered image of the
TYPE_3BYTE_BGR
type to a file using theBMPWriter
class and theBI_BITFIELDS
compression type, the output image was distorted and unusable. This problem was caused by the bitfileds masks which were applied to a bmp image. However, an image data layout was not changed according to the BMP format requirements. To fix this problem thewritePixels()
method is used to copy image data correctly.5076878 ImageIO BMP Writer writes 32 bit files for 24 bit images:
The
ImageIO.write
method presented a BMP file as a 32 bit image even if the source image had 24 bits per pixel presentation. The fix enables thewritePixels
procedure whenever the number of bits per pixel is smaller than the size of a databuffer type (for example, withTYPE_INT_RGB,
the actual number of bits per pixel is 24 while the size of the databuffer type is 32).6332480 The
BMPReader
class fails to read theTYPE_BYTE_GRAY
image encoded by theBMPWriter
class withBI_RLE8
compression:The
BMPReader
class did not properly read theTYPE_BYTE_GRAY
image written with theBMPWriter
class using theBI_RLE8
compression. The problem was that the RLE decoding procedures (both RLE4 and RLE8) mistakenly used the width of the destination region instead of the height to calculate the range of image lines for copying. The performed fix uses the height of the destination region to calculate the range.6399660 Using subsampling with compression alters the colors for some of the image types for BMP:
While using all the supported compression types for BMP, different affects on image were detected including blurring, a different color appearance, and slight image corruption. The performed fix separates processing BI_RGB compression and BI_RGB compression as follows:
- For BI_RGB compression the BGR order of raster data should be used (except the case of 16bpp images where RGB data order is defined by the BMP spec)
- For BI_BITFIELDS compression the order of raster data should be defined using corresponding masks. The RGB order of raster data is used for the default bitfields masks.
Performance and resource management
6299405 The
ImageInputStreamImpl
class still uses thefinalize()
method which causes thejava.lang.OutOfMemoryError
:The
finalize()
method had to be emptied and its functionality (closing the stream) must be replaced with a more prompt mechanism. The finalize() method cannot be easily emptied at theImageInputStreamImpl
level, since third-party IISI subclasses may rely on thefinalize()
method calling theirclose()
method as per the spec. However, forImageInputStreamImpl
subclasses under Sun control, thefinalize()
methods can be emptied. The Java2D Disposer mechanism is used instead.6266748 The
JPEGImageWriter.write()
method makes a copy of the raster:The write() method of the
JPEGImageWriter
class contained memory-inefficient code. The suggested fix helps to improve performance for simple rendered images.6336804 The
javax.imageio.ImageIO
class can handle leaks in some methods:Some of the
read()
andwrite()
convenience methods in thejavax.imageio.ImageIO
class did not properly close streams and dispose reader or writer instances in a try and finally blocks. As a fix the appropriate notes were added to each method's javadocs indicating whether it is the caller's responsibility to close the provided stream or not.6347575 FileImageInputStream.readInt() and similar methods are inefficient:
Calling theread()
method of theFileImageInputStream
4x was much more expensive than making a single call to theread(byte[])
method with a cached byte array. This fact had a profound impact on performance of reading small PNG and other images. The fixes were performed for thereadShort()
andreadInt()
methods of theImageInputStreamImpl
class.6348744 The
PNGImageReader
class should skip metadata if theignoreMetadata
flag has thetrue
value:Before JDK 6, the
PNGImageReader
class read all image metadata, even if theignoreMetadata
flag was set. The fix reduces overhead and improves performance when reading small PNG images by skipping metadata blocks if theignoreMetadata
flag istrue
.6354056 The
JPEGImageReader
class could be optimized:The JPEG image reader copied decoded data into memory, but not in an optimized way. The performed fix improves this operation by using the
memcpy()
method instead of copying one byte at a time.6354112 Increase compiler optimization level for
libjpeg
to improve runtime performance:The
libjpeg
library in the JDK was built with default compiler optimization flags. The values of these flags are increased to a higher level to enable the native IJG JPEG libraries to run faster.6404011 IllegalArgumentException: "Invalid ICC Profile Data" when reading a certain JPEG image:
This bug was an unchecked exception and could cause a system crash on some platforms. The fix catches the
IllegalArgumentException
, which is thrown by ICC_Profile, and handles images without taking into account invalid color profiles.Robustness
6291034 The
Both theIFileCacheImageInputStream
andFileCacheImageOutputStream
should avoid using theFile.deleteOnExit
method:FileCacheImageInputStream
andFileCacheImageOutputStream
classes used the functionality of thedeleteOnExit
method of theFile
class. The fix has replaced the File.deleteOnExit() functionality with the shutdown hook that closes streams that are still open before the VM shutdown.4892630 The
ImageReader
class does not validate the image index which is passed to some of the methods:The
getWidth(imgIndex)
,getHeight(imgIndex)
, andgetAspectRatio(imgIndex)
methods of theImageReader
class did not throw theIndexOutOfBoundsException
if the given PNG image index was out of range. The performed fix resolves this issue by throwing the exception appropriately.4895547
JPEGImageMetadata
obtained from reader throwsNullPointerException
when calling themergeTree()
method:The list of parent attributes did not contain attributes related to the child node and this fact caused the
NullPointerException
in theMarkerSegment.getAttributeValue()
method while trying to get child related attribute. The performed fix obtains the attribute list from the child node.4528643 Native JPEG code makes JNI calls in scope of GetPrimitiveArrayCritical:
Running any application that reads or writes JPEG images with the non-standard
-Xcheck:jni
flag caused the following error in several methods of theJPEGImageReader
class:Calling other JNI functions in the scope of Get/ReleasePrimitiveArrayCritical or Get/ReleaseStringCriticalIn the fix, the affected methods are surrounded with the RELEASE/GET_ARRAYS macros.
5076692 Installed Extensions Image I/O reader-writer plug-ins unusable in applet context:
The problem was that theimageio
registry initialization code did not have read access to jars in thejava.ext.dirs
when the registry code was called from applet context. Therefore, theimageio
plugins installed tojava.ext.dirs
were not available in case of applets. The fix idea is to register plugins fromjava.ext.dirs
in the privileged action block.6342404 The
ImageIO
plugin failure causes all readers to fail:Removing an
ImageIO
plugin's code from the classpath, but still including an entry for the plugin's ImageReader in META-INF/services made using any of the ImageIO plugins impossible. To fix this bug, a 'try and catch' block was added to theIIORegistry.registerApplicationClasspathSpis()
method to catch theServiceConfigurationError
.6395551 Setting the destination type to type specifier returned by redr.getImageTypes() throws exception for JPG:
The problem was that a new
ColorSpace
instance was re-created for embedded color profiles whenever an image header was read. In addition, there was no means for correct comparison ofColorSpace
andICC_Profile
classes. This omission made comparing instances ofImageTypeSpecifier
class impossible. The proposed workaround for this problem is as follows: to detect the case when theiccCS
instance contains the same profile data as a newly read. If so, the 'old' instance is left; otherwise (if the profile data seems to be different) a new color space instance is created for the embedded color profile.6399616 PIT:
JPGReader
throws an exception when using theTYPE_CUSTOM TypeSpecifier
returned by theReader.getImageTypes
method:The regression was caused by the fix for 4705399, where color conversion was removed (
JPEGImageReader.java
lines 783 -786) because it caused extra color conversion for images with embedded color profiles. However, this conversion was required when the destination type defined different color spaces for images that do not contain embedded profiles. The fix for this case converts image data from sRGB (produced by the decoder) to the color space used in the destination image.Quality
5028259 Setting the destination image type for jpeg images increases the size of the result file:
If the write parameter with the destination type was used explicitly to write a jpeg image, then the size of the result file was bigger than if the same destination type was used implicitly. The problem was revealed when the destination type was specified but the corresponding metadata object was not specified. The fix creates the metadata object using the given destination type in order to build a SOF marker object, which will be used to change the default values of the
QtableSelectors
.4881314
TheImageIO
does not correctly read certain standard JPG files:ImageIO
incorrectly reads some JPG files. The result was a red or green image that looked like a photographic negative. The fix eliminates color space conversion for EXIF images. To detect EXIF images, the check for the APP1 marker in the image header is added.5098176 Some PNG images fail to load with the
TheImageIO
class:PNGImageReader
failed to create theImageTypeSpecifier
instance corresponding to the indexed PNG image if the length of the image palette in smaller than 2 bitDepth. To avoid this limitation new palette arrays of the appropriate power of 2 size were created. These arrays are padded with the last value from original arrays in order to avoid the appearance of colors that do not exist in the original palette.6372769 The
ImageIO.read
method improperly decodes Nikon Jpegs:The
ImageIO
jpeg reader performed extra color conversion if an image contained the embedded color profile. The bug was fixed by removing the extra color conversion operation.Miscellaneous
6195593 REGRESSION: The
javax/imageio/IRPTest.java
file fails:The problem was caused by the fix for the bug 5039494. Starting with this fix, the
ImageReader.computeRegion()
method was used to calculate the destination region. In order to avoid discrepancies between calculated destination regions and destinations offset from the parameter, thedestinationOffset
is updated according to the calculated values.6304433 Test bug: the regression test for the bug 6291034 fails on all platforms:
The regression test failure was caused by the creation of an output image file. This file was created after counting the existing files in the work directory and was not deleted on regression test finish. So, after regression test execution, the work directory always contained one extra file, although all temporary files were deleted upon VM exit. The solution is to use byte array input or output streams instead of file input or output streams in order to avoid creating extra files in the work directory.
6356926 PIT: The regression test
javax/imageio/stream/DeleteOnExit.sh
is failing:The problem was caused by the fix for the bug 6299405. The affected code is fixed and the corresponding comment has been added.
6459309 The
NoAPP0Test.java
regression test failed on all platforms:The difference in pixel values is caused by using new version of sRGB profile that was updated as part of fix for 6279846. New profile was integrated in the b92 build.
6363748 The
close()
method of theFileCacheImageInputStream
class fails:The problem was caused by the fix for the bug 6299405. As a part of that fix the
FileCacheImageInputStream.close()
method was changed so that it nulled out its reference to the cache object. To eliminate this issue theFCIIS.read()
method is updated to call thecheckClosed()
method as it is supposed to do.
Copyright © 1999-2006
Sun Microsystems, Inc.
All Rights Reserved.
|