Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: JAI on MacOS X?



Walter, here is a partial solution I've posted in the mailing list:

I haven't run the tutor or the sample project, as the solutions I present
are code changes and not external fixes. Also you can load your jpegs using
JAI.create("fileload", ...) you must go through ImageCodec. If you need
details just ask.

I still have some questions but it works:
I hope this helps:

<paste start>
Hello JAI interest group and Mac Java development mail list:

Sorry for the long e-mail, but there are some questions at the end...

As I need to run my JAI Applications under both windows and OS X I had no
option but to do a little research on the problems of JAI on OS X.

First of all thanks to all who gave solutions, ideas and hints on where the
problem is and how to solve it.

As far as I tested JAI 1.1.1 will run on OS X on pure java versions only
having two problems:
* jpeg files causes an ArrayIndexOutOfBoundsException when loading
* any other image format (except BMP) will load but show as a white
image (search the mail list archives for "JAI and Mac OS X info")


The workaround to the second problem is to reformat the image to have a
bandOffsets = {2,1,0} (a format that OS X's JAVA 2D knows how to draw)
thanks for Bob Deen for the solution.

here is the code:

PlanarImage reformat (PlanarImage imageSource)
{
SampleModel originalSampleModel = imageSource.getSampleModel();

ImageLayout layout = new ImageLayout(imageSource);

int[] bandOffsets = {2,1,0};
int numBands = bandOffsets.length;

int type = originalSampleModel.getDataType();

SampleModel newSampleModel =

LeafJAICodecs.RasterFactory.createPixelInterleavedSampleModel(type,

originalSampleModel.getWidth(),

originalSampleModel.getHeight(),

numBands,

numBands*originalSampleModel.getWidth(),

bandOffsets);


layout.setSampleModel(newSampleModel);

ParameterBlock pb = new ParameterBlock();
pb.addSource(imageSource);
pb.add(type);

RenderingHints hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT,
layout);
PlanarImage result = JAI.create("format", pb, hints);

return result;
}

The workaround for the first problem:

I've downloaded the source code for the JAI codecs (can be downloaded from
http://developer.java.sun.com/developer/sampsource/jai/) and debugged the
code the exception is thrown
at the marked lines bellow:
in the JPEGImageDecoder.java file:

------------ code paste start -----------------
BufferedImage image = null;
synchronized(LOCK) {
com.sun.image.codec.jpeg.JPEGImageDecoder decoder =

com.sun.image.codec.jpeg.JPEGCodec.createJPEGDecoder(stream);
try {
// decodeAsBufferedImage performs default color conversions
image = decoder.decodeAsBufferedImage();
} catch (ImageFormatException e) {
throw new
RuntimeException(JaiI18N.getString("JPEGImageDecoder1"));
} catch (IOException e) {
throw new
RuntimeException(JaiI18N.getString("JPEGImageDecoder2"));
}
}

minX = 0;
minY = 0;
tileWidth = width = image.getWidth();
tileHeight = height = image.getHeight();

// Force image to have a ComponentSampleModel if it does not have
one
// and the ImageDecodeParam is either null or is a JPEGDecodeParam
// with 'decodeToCSM' set to 'true'.
if ((param == null ||
(param instanceof JPEGDecodeParam &&
((JPEGDecodeParam)param).getDecodeToCSM())) &&
!(image.getSampleModel() instanceof ComponentSampleModel)) {

int type = -1;
int numBands = image.getSampleModel().getNumBands();
if (numBands == 1) {
type = BufferedImage.TYPE_BYTE_GRAY;
} else if (numBands == 3) {
type = BufferedImage.TYPE_3BYTE_BGR;
} else if (numBands == 4) {
type = BufferedImage.TYPE_4BYTE_ABGR;
} else {
throw new
RuntimeException(JaiI18N.getString("JPEGImageDecoder3"));
}

BufferedImage bi = new BufferedImage(width, height, type);

// the following line will throw the ArrayIndexOutOfBoundsException:
bi.getWritableTile(0, 0).setRect(image.getWritableTile(0, 0));


bi.releaseWritableTile(0, 0);
image = bi;
}

-------------- end of code ------------
If you remove the "if block" that contains the above code the JPGs can be
viewed both on Windows and on OSX.

Finally my questions:
On the decoder code the "if block" is commented as:
// Force image to have a ComponentSampleModel if it does not have
one
// and the ImageDecodeParam is either null or is a JPEGDecodeParam
// with 'decodeToCSM' set to 'true'.

I was done for some reason, but it works without it.
* Can someone explain me the reason?
* Can I safely remove it?
* Does the reformat of TIFF have any effect such as performance
issues? Let's say that after I load and reformat I will also get the
BufferedImage and warp it into a new Planar Image.

Thanks for your help.

<mail paste end>


-----Original Message-----
From: Walter Ritter [mailto:email@hidden]
Sent: Thursday, October 03, 2002 18:01
To: email@hidden
Subject: JAI on MacOS X?


Hi all,

I have to use JAI in a project but sadly it isn't supported officially
in MacOS X (yeah, I know, the worlds best Java-Developing platform). I
searched the list archives at java.sun.com and found some messages of
people who had successfully used JAI (unaccelerated of course), so
there should be hope for me :-) Sadly I couldn't find any specific
hints on how I could get JAI to work.

Did anybody here run jai_tutor successfully on OS X? If yes, would you
mind telling me what steps are involved?

Thanks in advance!
Walter
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/java-dev
Be sure to read the FAQ http://developer.apple.com/java/faq/ before posting
Do not post admin requests to the list. They will be ignored.
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Be sure to read the FAQ http://developer.apple.com/java/faq/ before posting
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.