Skip to main content

JPEG 2000 writer; may not write multiple times within a single execution

3 replies [Last post]
cij100
Offline
Joined: 2007-05-12

We have a system that generates and converts imagery. During testing, we came across a problem when requesting multiple JPEG 2000 files; where the image for the first request was written correctly, but subsequent writes failed. This problem was found in part of a larger system, but a simplified test case can be seen below. In the failiure case, a file is created, but contains 0 bytes of data. The JPEG2000 writer does not report any errors or throw any exceptions when it fails.

Using this test, with a 4000x4000 pixel source image, imageIO 1.0_01, windows native writerand the JVM with a max heap of 1024Mb.demonstrates this problem. However, if the maximum heap is reduced to 768Mb, then the problem is no longer apparent, and all 4 images are written. If the source image is 16x16 pixels then all 4 are also written.

I can't release the original image, but I can hopefully generate one that causes the problem to appear. In the code below there is a hard coded reference which will obviously need changing should the code be used for more then illustrative purposes.

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class TestJ2K
{
private final static Logger LOGGER = Logger.getLogger(TestJ2K.class);

public static void main(String[] args)
{

File source_file = new File("c:/imageData1184165300597.jpg");

BufferedImage image;
try
{
if (source_file.exists())
{
image = ImageIO.read(source_file);

File dest_1 = new File("c:/image_1" + ".jp2");
File dest_2 = new File("c:/image_2" + ".jp2");
File dest_3 = new File("c:/image_3" + ".jp2");
File dest_4 = new File("c:/image_4" + ".jp2");

ImageIO.write(image, "jpeg 2000", dest_1);

image = ImageIO.read(source_file);
ImageIO.write(image, "jpeg 2000", dest_2);

image = ImageIO.read(source_file);
ImageIO.write(image, "jpeg 2000", dest_3);

image = ImageIO.read(source_file);
ImageIO.write(image, "jpeg 2000", dest_4);

System.out.println("Complete");
}
else
{
System.out.println("Error, NULL");
}
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
James Cheng

> Using this test, with a 4000x4000 pixel source image, imageIO 1.0_01, windows native writer

Can you try the current release, JAI Image I/O Tools 1.1?

Thanks,
-James

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

cij100
Offline
Joined: 2007-05-12

Sorry, I meant to say that I'd tried it with the 1.1 build and the same problem was experienced. I'll double check that it was running aginst the new version and not looking at the older version installed elsewhere, but I'm pretty sure that it's been tried with 1.1.

cij100
Offline
Joined: 2007-05-12

I've reproduced this problem (based upon the same source image) on mulitple machines, with different processor/memory configurations. They all run java 1.5 and either 1.0 or 1.1 jai image i/o tools.

Using the pure java writer instead of the native version seems to provide us with a work around, although it's not an ideal soultion.