Very slow image operation

Hello,

I have a strange problem.

Some of my images areVERY slow to load, scale... (any image operation).

I have those 2 images :

http://193.252.5.30/tmp/cat1.jpg (25Ko : 295x551 pixels)

http://193.252.5.30/tmp/cat2.jpg (24Ko : 295x551 pixels)

I wrote a little program which load and scale the image.

Here is the result :

cat1.jpg

Time to load image : 171 ms.

Time to scale image : 157 ms.

cat2.jpg

Time to load image : 1157 ms.

Time to scale image : 2578 ms.

How can this huge difference explained ?

Thanks for your help.

The program :

publicclass Test

{

privatefinalstatic BufferedImage scale(BufferedImage source,float scaleFactor)

{

int width = Math.round(source.getWidth()*scaleFactor);

int height = Math.round(source.getHeight()*scaleFactor);

ColorModel dstCM = source.getColorModel();

BufferedImage dst =new BufferedImage(dstCM, dstCM.createCompatibleWritableRaster(width, height), dstCM.isAlphaPremultiplied(),null);

Image scaledImage = source.getScaledInstance(width, height, Image.SCALE_AREA_AVERAGING);

Graphics2D g = dst.createGraphics();

g.drawImage(source, 0, 0, width, height,null);

g.dispose();

return dst;

}

publicstaticvoid main(String[] args)throws IOException

{

String imagePath ="cat1.jpg";

//String imagePath = "cat2.jpg";

long t1 = System.currentTimeMillis();

BufferedImage image = ImageIO.read(new File(imagePath));

long t2 = System.currentTimeMillis();

System.out.println("Time to load image : " + (t2-t1) +" ms.");

t1 = System.currentTimeMillis();

image = scale(image, 0.2f);

t2 = System.currentTimeMillis();

System.out.println("Time to scale image : " + (t2-t1) +" ms.");

}

}

[2860 byte] By [yann.mla] at [2007-10-2 21:45:11]
# 1

> Hello,

>

> I have a strange problem.

> Some of my images are VERY slow to load,

> scale... (any image operation).

>

> I have those 2 images :

> http://193.252.5.30/tmp/cat1.jpg (25Ko : 295x551

> pixels)

> http://193.252.5.30/tmp/cat2.jpg (24Ko : 295x551

> pixels)

>

> I wrote a little program which load and scale the

> image.

> Here is the result :

>

> cat1.jpg

> Time to load image : 171 ms.

> Time to scale image : 157 ms.

> cat2.jpg

> Time to load image : 1157 ms.

> Time to scale image : 2578 ms.

>

> How can this huge difference explained ?

> Thanks for your help.

Using the Netbeans profiler, I can see that for some reason, the cat2.jpg image is resulting in a hot spot where the scale() method ends up performing a color conversion via ColorConvertOp. Placing a debugger breakpoint on this call and debugging the code using cat1.jpg, the method is never called. So, there is something different about the color models of the two images, or there is a bug in the image reading code that is misinterpreting the image data.

This bug may be what you are seeing:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4705399

Niceguy1a at 2007-7-14 1:00:43 > top of Java-index,Security,Cryptography...