I received the test image from Carl and it does have an APP2 marker
with an ICC profile so its as I suspected.
com.sun.image.codec.jpeg is faster mainly because its not processing
this.

On my XP PC for 50 loads of the sample image I have
ImageIO : 32 seconds
JPEGDecoder : 13 seconds

But if I allow Image I/O to skip applying the color space conversion
I get 15 seconds - almost on a par ..

The way to 'skip' this is to specify that the returned buffered
image use the color space with the profile, rather than being
converted to sRGB before returning.

This does mean you need to directly invoke the JPEG reader
so you can tell it this. Sample code below :

There's a couple of robustness things lacking (like not
checking for null) but that's pretty much what you need.


Iterator<ImageReader> it = ImageIO.getImageReadersBySuffix("jpg");
ImageReader jpegReader = it.next();
jpegReader.setInput(new FileImageInputStream(file));
Iterator<ImageTypeSpecifier> typeIterator = jpegReader.getImageTypes(0);
ImageTypeSpecifier its = null;
while (typeIterator.hasNext() && its == null) {
    ImageTypeSpecifier tmp = typeIterator.next();
    ColorSpace cs = tmp.getColorModel().getColorSpace();
    if ((cs.getType() == ColorSpace.TYPE_RGB) && !cs.isCS_sRGB()) {
        its = tmp;
      }
}
ImageReadParam param = jpegReader.getDefaultReadParam();
param.setDestinationType(its);
BufferedImage bimg = jpegReader.read(0, param);

It used to be the case that this was the default.

However notice that drawing this image will now take
longer as the conversion will be applied then.
This turned out to be a problem too for most people.
So this is probably not going to help if you need to
do that drawing anyway. We've discussed whether applying the
conversion is really necessary if RenderingHint.KEY_RENDERING
is set to VALUE_RENDER_SPEED, and the image types are generally
compatible, so perhaps in the future that will offer a solution.

In the interim you could just create a new BufferedImage
using the Raster from the returned one and a color model
which has an sSRGB color space .. ie essentially dropping
the ColorSpace which has the ICC profile data.

-phil.

Phil Race wrote:
There may be some differences in the way that the two APIs process the
image.
For example I noted recently that the old com.sun.image.codec,jpeg is
completely
ignorant of an APP2 marker with an ICC profile in which case its faster,
but produces incorrect
results.  So for many photographic images it probably should not be used
on those grounds
alone. I am not at all sure that's the issue in your case. It would
need  investigation .
Can you send me (not the whole list) directly via email your  test image.
phil DOT race AT sun DOT com

-phil.

[EMAIL PROTECTED] wrote:
I've run some tests and concluded that JPEGCodec.createJPEGDecoder(new
FileInputStream(file)).decodeAsBufferedImage() is faster than
ImageIO.read(new File(file)) .
I have a test image that's 1978x2500 that loads in 375ms using
JPEGCodec and 735 ms using ImageIO. I set ImageIO.setUseCache(false).
Is there something I'm doing wrong or is the old package faster. I'm
writing an application to read images/slideshow, etc and speed is very
important. Do you have any tips or suggestions?
I'm running Java 6 u1 on Windows XP Media Center. 128MB VRAM, AMD
Athlon 3800 Dual Core X2, 1GB RAM.

Thanks in advance,

Carl Antaki
[Message sent by forum member 'carcour' (carcour)]

http://forums.java.net/jive/thread.jspa?messageID=211620

===========================================================================

To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
of the message "signoff JAVA2D-INTEREST".  For general help, send
email to
[EMAIL PROTECTED] and include in the body of the message "help".


===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to