Skip to main content

JAI platform indipendent on MAC osx

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
3 replies [Last post]
alfredo.marchini
Offline
Joined: 2012-06-30

Hi,
I develop an application with JAI that from a big image (about 500MB size) outputs 2 JPEG images, one 1900x1200 and other 320x320. The source image can be TIFF, JPEG, GIF, BMP, PNG, with alpha or not.
I didn't install anything in JVM, I only added jai_core.jar and jai_codec.jar to my application.
With this context (I don't know if it is a correct context) I found some problems that I will try to explain:
- SubsampleAverage works better than Scale, but is not good like scaling with standard java BufferedImage.
- After subsampling crop doesn't work well, if I have a subsampled image of 420x320size and I want to crop to 60,0,320,320 it outputs me a blank rect from 0 to 59px; in detail a get PlanarImage from JAI.create("SubsampleAverage") then I use it for crop and It gives me this problem.
- Only on MAC OSX (Linux doesn't give this problem): TIFF PlanarImage ColorSpace are seen as RGB and not CMYK. Linux see the same image as CMYK.
This problem born because I need to trasform CMYK images to 3 band RGB images (for storing inside a JPEG image). If I force the transform on a CMYK image that is seen as RGB it works well, but I need to know if it is a CMYK or RGB because I can import an RGB image with alpha and I dont' want to convert it.
I try also to add to put "com.sun.media.jai.disableMediaLib" as "true" but with no changes.
It's all.
Thank you very much.
Bye

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
haraldk
Offline
Joined: 2005-05-10

Not sure if this is of any help to you but, anyway:

Quote:

- Only on MAC OSX (Linux doesn't give this problem): TIFF PlanarImage ColorSpace are seen as RGB and not CMYK. Linux see the same image as CMYK.

Java for Mac OS X usually comes with its own version of the TIFFImageReader(Spi) provided by Apple, that, despite the package name being the same as the JAI version, is completely different. This might be the reason why TIFF images behave differently on OS X.

Regards,

--
Harald K

alfredo.marchini
Offline
Joined: 2012-06-30

Hi,
this can be a valid explananion about the TIFF CMYK problem, at the moment I resolved with a flag that permit my customer to manually convert cmyk to rgb (I cannot have this info because jai tells me rgb and If I have an rgb with alpha the bands are 4 like cmyk).
And for the other 2 problems?
The SubsampleAverage works worse than default scale with BufferedImage?
The crop that doesn't work after on a sumbsampled planarimage?
Nobody found these problems?
Thank u very much
Regards

haraldk
Offline
Joined: 2005-05-10

I've only used the JAI-imageio part of JAI, so I'm afraid I can't help there...

You should be able to unregister the Apple-provided TIFFImageReaderSpi, to avoid the CMYK-to-RGB issue (if that is indeed the problem). Have a look at IIORegistry.

The crop issue sounds like a bug to me, however, I'm not sure if anyone maintains JAI anymore (I've asked multiple times/multiple places, trying to fix some issues in the ImageIO parts, with no luck).

In my experience (not using JAI, so your results may differ), resampling or scaling images in Java of the size you mention is typically a tradeoff in speed/quality. You can get:

- Really good performance, using little memory, but poor quality (using subsampled reading)
- Great quality, but using lots of memory and semi-slow (reading all the pixel data, and resampling)
- Great quality, using little memory, but slow performance (reading the pixel data in chunks, resampling each chunk)

(or any combination of these, that may produce acceptable quality with acceptable performance, given specific constraints)

Regards,

--
Harald K