United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6266748 : JPEGImageWriter.write() makes a copy of the raster (inefficient)

Details
Type:
Bug
Submit Date:
2005-05-06
Status:
Resolved
Updated Date:
2008-02-05
Project Name:
JDK
Resolved Date:
2005-10-10
Component:
client-libs
OS:
solaris_9
Sub-Component:
javax.imageio
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
5.0
Fixed Versions:

Related Reports
Relates:

Sub Tasks

Description
This statement

                 // XXX - this makes a copy, which is memory-inefficient
                 srcRas = rimage.getData();

in JPEGImageWriter is really lame. If the source is a BufferedImage it is 
going to copy the entire thing in memory. If it is an untiled JAI image this 
should not happen (a child of the tile would be returned instead of copying).

Nonetheless I would suggest changing this to the code listed below. If a more
minor change would get in to the next build sooner then I would suggest this 
instead:

 		srcRas = rimage instanceof BufferedImage ?
 		    srcRas = ((BufferedImage)rimage).getRaster() :
 		    rimage.getData();

which should solve most of the problem.
###@###.### 2005-05-06 20:43:42 GMT

                                    

Comments
SUGGESTED FIX

                 if(rimage instanceof BufferedImage) {
                     // Use the Raster directly.
                     srcRas = ((BufferedImage)rimage).getRaster();
                 } else if(rimage.getNumXTiles() == 1 &&
                           rimage.getNumYTiles() == 1) {
                     // Get the unique tile.
                     srcRas = rimage.getTile(rimage.getMinTileX(),
                                             rimage.getMinTileY());

                     // Ensure the Raster has the dimensions of the image
                     // as the tile dimensions might differ.
                     if (srcRas.getWidth() != rimage.getWidth() ||
                         srcRas.getHeight() != rimage.getHeight()) {
                         srcRas = srcRas.createChild(srcRas.getMinX(),
                                                     srcRas.getMinY(),
                                                     rimage.getWidth(),
                                                     rimage.getHeight(),
                                                     srcRas.getMinX(),
                                                     srcRas.getMinY(),
                                                     null);
                     }
                } else {
                    // Image is tiled so get a contiguous raster by copying.
                    srcRas = rimage.getData();
                }

###@###.### 2005-05-06 20:43:43 GMT
                                     
2005-05-06
EVALUATION

See suggested fix.
###@###.### 2005-05-06 20:46:40 GMT
                                     
2005-05-06
EVALUATION

The "minor change" suggested in the description field is just what we have
currently in JPEGImageWriter, so perhaps the submitter was looking at an
old version of JPEGImageWriter.  In any case, the full suggested fix would
probably help improve performance for simple RenderedImages, so it's still
worth pursuing.
                                     
2005-09-29



Hardware and Software, Engineered to Work Together