JDK-5086246 : The JPEG encoder reserves a lot of memory to convert large BGR images
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.1.2
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-08-12
  • Updated: 2014-03-18
Related Reports
Relates :  
Description
Name: rmT116609			Date: 08/12/2004


A DESCRIPTION OF THE REQUEST :
When trying to convert a large image to a JPEG image, the encoder seems to reserve all the needed memory to keep the whole image in memory. So, for large images, it is impossible to convert the image to JPEG if you do not have enough memory to keep it in memory. For other formats (TIFF, BMP, PNG...) it does not occur.


JUSTIFICATION :
The JAI should deal with large images.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The amount of memory reserved for the encoding of a JPEG image should not be proportional to the size of the image being covnverted
ACTUAL -
The amount of memory reserved for the encoding of a JPEG image IS proportional to the size of the image being covnverted

---------- BEGIN SOURCE ----------

      //This is an extract of code that convert a TIFF to JPEG
      ParameterBlock pb3 = new ParameterBlock();
      pb3.add(new FileSeekableStream(tempTiff));
      RenderedOp rendOp = JAI.create("tiff", pb3);
      ParameterBlock pb4 = new ParameterBlock();
      pb4.addSource(rendOp);
      pb4.add(salidaJPEG);
      pb4.add("jpeg");
      JPEGEncodeParam encParam2 = new JPEGEncodeParam();
      encParam2.setQuality(calidad);
      pb4.add(encParam2);
      JAI.create("filestore", pb4);

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Surprisingly, the old JIMI library seems not to have this probles, though it does not compile correctly in JDK 1.4
(Incident Review ID: 290143) 
======================================================================

Comments
Please re-open if - if fix is in progress or on the plan to fix soon - if this is a P3 (file as P3, not P4)
18-03-2014

EVALUATION See also 6268083: Core J2SE JPEG ImageWriter consumes much memory when writing which also talks about the memory needed to encode BGR images. I haven't closed this a dup as I have not verified if both the com.sun.image.code.jpeg and the image i/o plugin need to be fixed separately. Certainly I think both 5086246 and 6268083 need to be considered together.
06-12-2005

WORK AROUND Use RGB images in preference to BGR images. ###@###.### 2005-05-10 17:58:14 GMT
10-05-2005

SUGGESTED FIX Modify the encoder not to require a copy when RGB are band-ordered as B-G-R. ###@###.### 2005-05-10 17:58:15 GMT
10-05-2005