![]() | Documentation Contents |
Image I/O Enhancements in Java™ SE 6.0 |
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.gifpackage 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
ImageWriterclass. 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 theImageIOclass that obtain file suffixes to be filtered. ThegetReaderFileSuffixes()andgetWriterFileSuffixesmethods return an array ofStringslisting 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 DescandQuality Valuesarrays are of the same length for JPG:The .
4953566 The
mark()orreset()methods of theImageInputStream classdo not work properly with PNGImageReader:The following note was added to the
ImageInputStreamclass specification to clarify thatImageReaderclasses 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 theJPEGQTableclass in the packagejavax.imageio.plugins.jpegwas supposed to return aStringobject 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.javafile 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
BMPImageReaderclass fails to read3BYTE_BGRimages encoded using BMP Writer withBI_JPEGcompression:While attempting to write an image of the
BI_JPEGcompression type, thejava.io.EOFExceptionwas thrown by theBMPImageReaderclass. The problem was that theBMPImageReaderclass did not process embedded images both ofBI_JPEGandBI_PNGtypes. To resolve this problem, the embedded image handling is moved to separate code.6297016 Output BMP image is distorted when writing
TYPE_3BYTE_BGRbuffered image withBI_BITFIELDScompression:While attempting to write a buffered image of the
TYPE_3BYTE_BGRtype to a file using theBMPWriterclass and theBI_BITFIELDScompression 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.writemethod presented a BMP file as a 32 bit image even if the source image had 24 bits per pixel presentation. The fix enables thewritePixelsprocedure 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
BMPReaderclass fails to read theTYPE_BYTE_GRAYimage encoded by theBMPWriterclass withBI_RLE8compression:The
BMPReaderclass did not properly read theTYPE_BYTE_GRAYimage written with theBMPWriterclass using theBI_RLE8compression. 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
ImageInputStreamImplclass 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 theImageInputStreamImpllevel, since third-party IISI subclasses may rely on thefinalize()method calling theirclose()method as per the spec. However, forImageInputStreamImplsubclasses 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
JPEGImageWriterclass contained memory-inefficient code. The suggested fix helps to improve performance for simple rendered images.6336804 The
javax.imageio.ImageIOclass can handle leaks in some methods:Some of the
read()andwrite()convenience methods in thejavax.imageio.ImageIOclass 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 theFileImageInputStream4x 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 theImageInputStreamImplclass.6348744 The
PNGImageReaderclass should skip metadata if theignoreMetadataflag has thetruevalue:Before JDK 6, the
PNGImageReaderclass read all image metadata, even if theignoreMetadataflag was set. The fix reduces overhead and improves performance when reading small PNG images by skipping metadata blocks if theignoreMetadataflag istrue.6354056 The
JPEGImageReaderclass 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
libjpegto improve runtime performance:The
libjpeglibrary 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 theIFileCacheImageInputStreamandFileCacheImageOutputStreamshould avoid using theFile.deleteOnExitmethod:FileCacheImageInputStreamandFileCacheImageOutputStreamclasses used the functionality of thedeleteOnExitmethod of theFileclass. 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
ImageReaderclass does not validate the image index which is passed to some of the methods:The
getWidth(imgIndex),getHeight(imgIndex), andgetAspectRatio(imgIndex)methods of theImageReaderclass did not throw theIndexOutOfBoundsExceptionif the given PNG image index was out of range. The performed fix resolves this issue by throwing the exception appropriately.4895547
JPEGImageMetadataobtained from reader throwsNullPointerExceptionwhen calling themergeTree()method:The list of parent attributes did not contain attributes related to the child node and this fact caused the
NullPointerExceptionin 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:jniflag caused the following error in several methods of theJPEGImageReaderclass: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 theimageioregistry initialization code did not have read access to jars in thejava.ext.dirswhen the registry code was called from applet context. Therefore, theimageioplugins installed tojava.ext.dirswere not available in case of applets. The fix idea is to register plugins fromjava.ext.dirsin the privileged action block.6342404 The
ImageIOplugin failure causes all readers to fail:Removing an
ImageIOplugin'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
ColorSpaceinstance was re-created for embedded color profiles whenever an image header was read. In addition, there was no means for correct comparison ofColorSpaceandICC_Profileclasses. This omission made comparing instances ofImageTypeSpecifierclass impossible. The proposed workaround for this problem is as follows: to detect the case when theiccCSinstance 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:
JPGReaderthrows an exception when using theTYPE_CUSTOM TypeSpecifierreturned by theReader.getImageTypesmethod:The regression was caused by the fix for 4705399, where color conversion was removed (
JPEGImageReader.javalines 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
TheImageIOdoes not correctly read certain standard JPG files:ImageIOincorrectly 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
TheImageIOclass:PNGImageReaderfailed to create theImageTypeSpecifierinstance 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.readmethod improperly decodes Nikon Jpegs:The
ImageIOjpeg 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.javafile 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, thedestinationOffsetis 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.shis 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.javaregression 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 theFileCacheImageInputStreamclass 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 © 1993, 2010, Oracle and/or its affiliates. All rights reserved. Please send comments using this Feedback page. |
Java Technology |