JDK-6266748 : JPEGImageWriter.write() makes a copy of the raster (inefficient)
  • Type: Bug
  • Status: Resolved
  • Resolution: Fixed
  • Component: client-libs
  • Sub-Component: javax.imageio
  • Priority: P4
  • Affected Version: 5.0
  • OS: solaris_9
  • CPU: generic
  • Submit Date: 2005-05-06
  • Updated Date: 2008-02-05
  • Resolved Date: 2005-10-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
6 b56Resolved
Related Reports
Relates :  
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 

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

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

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.

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

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