Skip to main content

[JAI] JAI - different behaviour when running Tomcat/Jetty server

5 replies [Last post]
Anonymous

Hi,

It seems JAI is behaving (regarding cropping) differently when running
in Tomcat server(in production) compared when running in Jetty server
(locally).
Anyone have any experience with this? The cropping operation seems to
crop at the top of my original images (with Tomcat) even though I
specify coordinates which should
make JAI crop in the centre. This works fine locally runnning Jetty
server.

best regards, Håkan
---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Håkan Jacobsson

An update regarding my issue:

When cropping JPG images in my webapp on our production server (linux
- running tomcat) - JAI ignores the coordinates I supply to the crop
operation.
This does not happen when testing locally (Mac OS X - running Jetty).
JAI always crops at the top left center in prodcution - no matter what
I supply for coordinates to the cropping area.
PNG image files are cropped OK.

22 jan 2010 kl. 11.46 skrev Håkan Jacobsson:

> Hi,
>
> It seems JAI is behaving (regarding cropping) differently when
> running in Tomcat server(in production) compared when running in
> Jetty server (locally).
> Anyone have any experience with this? The cropping operation seems
> to crop at the top of my original images (with Tomcat) even though I
> specify coordinates which should
> make JAI crop in the centre. This works fine locally runnning Jetty
> server.
>
> best regards, Håkan

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

Kustaa Nyholm

My hunch would be that this is a Mac/Linux issue not Tomcat/Jetty issue.
Have you tried to disable JAI native acceleration (is there one in Linux?)

br Kusti

> From: Håkan Jacobsson
> Reply-To:
> Date: Fri, 22 Jan 2010 14:50:56 +0200
> To: Håkan Jacobsson
> Cc:
> Conversation: [JAI] Re: JAI - different behaviour when running Tomcat/Jetty
> server
> Subject: [JAI] Re: JAI - different behaviour when running Tomcat/Jetty server
>
> An update regarding my issue:
>
> When cropping JPG images in my webapp on our production server (linux
> - running tomcat) - JAI ignores the coordinates I supply to the crop
> operation.
> This does not happen when testing locally (Mac OS X - running Jetty).
> JAI always crops at the top left center in prodcution - no matter what
> I supply for coordinates to the cropping area.
> PNG image files are cropped OK.
>
>
> 22 jan 2010 kl. 11.46 skrev Håkan Jacobsson:
>
>> Hi,
>>
>> It seems JAI is behaving (regarding cropping) differently when
>> running in Tomcat server(in production) compared when running in
>> Jetty server (locally).
>> Anyone have any experience with this? The cropping operation seems
>> to crop at the top of my original images (with Tomcat) even though I
>> specify coordinates which should
>> make JAI crop in the centre. This works fine locally runnning Jetty
>> server.
>>
>> best regards, Håkan
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>

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

Håkan Jacobsson

Kustaa,

Thanx for fast reply. There might not be in Linux. How can I disable
the native acceleration?

I can see on google that this is a known 'bug' with JAI. Suggestions
to solve the problem seem to include different ways of saving the
image. We're currently using ImageIO to save and read images. Would it
perhaps be better to use JAI for saving the images?

22 jan 2010 kl. 13.55 skrev Kustaa Nyholm:

> My hunch would be that this is a Mac/Linux issue not Tomcat/Jetty
> issue.
> Have you tried to disable JAI native acceleration (is there one in
> Linux?)
>
> br Kusti
>
>
>> From: Håkan Jacobsson
>> Reply-To:
>> Date: Fri, 22 Jan 2010 14:50:56 +0200
>> To: Håkan Jacobsson
>> Cc:
>> Conversation: [JAI] Re: JAI - different behaviour when running
>> Tomcat/Jetty
>> server
>> Subject: [JAI] Re: JAI - different behaviour when running Tomcat/
>> Jetty server
>>
>> An update regarding my issue:
>>
>> When cropping JPG images in my webapp on our production server (linux
>> - running tomcat) - JAI ignores the coordinates I supply to the crop
>> operation.
>> This does not happen when testing locally (Mac OS X - running Jetty).
>> JAI always crops at the top left center in prodcution - no matter
>> what
>> I supply for coordinates to the cropping area.
>> PNG image files are cropped OK.
>>
>>
>> 22 jan 2010 kl. 11.46 skrev Håkan Jacobsson:
>>
>>> Hi,
>>>
>>> It seems JAI is behaving (regarding cropping) differently when
>>> running in Tomcat server(in production) compared when running in
>>> Jetty server (locally).
>>> Anyone have any experience with this? The cropping operation seems
>>> to crop at the top of my original images (with Tomcat) even though I
>>> specify coordinates which should
>>> make JAI crop in the centre. This works fine locally runnning Jetty
>>> server.
>>>
>>> best regards, Håkan
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
>> For additional commands, e-mail: interest-help@jai.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>

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

Håkan Jacobsson

Ok, I found the solution. On google. Thought I'd share it here.
So, for JPEG (JPG) images. When using the crop operation with JAI
(Java Advanced Imaging) on Linux or Windows (note that I havent tested
this on Windows myself).
You need to make a special case when saving the image (to file/stream
or whatever).
You can not save it as a PlanarImage. You need to save it as a
BufferedImage. For other image formats (PNG, GIF etc.) you SHOULD save
it as a PlanarImage.
If you save a cropped JPEG image as a PlanarImage running Linux or
Windows you will always get an image cropped at the top left corner -
no matter what values you supply to the
ParameterBlock.
Apparently it is not the crop operation itself that fails. It has to
do with the way you save the image.
For JPEG images, save them as BufferedImages. For other formats, save
them as PlanarImages. Running Linux or Windows.
It is easy to retrieve a BufferedImage from a PlanarImage:

planarImage.getAsBufferedImage();

And please not that running Mac OS X you may save all image formats as
PlanarImages.

We are using Javas Image IO to save images. And also to read images.

/regards, Håkan Jacobsson

22 jan 2010 kl. 14.04 skrev Håkan Jacobsson:

> Kustaa,
>
> Thanx for fast reply. There might not be in Linux. How can I disable
> the native acceleration?
>
> I can see on google that this is a known 'bug' with JAI. Suggestions
> to solve the problem seem to include different ways of saving the
> image. We're currently using ImageIO to save and read images. Would
> it perhaps be better to use JAI for saving the images?
>
> 22 jan 2010 kl. 13.55 skrev Kustaa Nyholm:
>
>> My hunch would be that this is a Mac/Linux issue not Tomcat/Jetty
>> issue.
>> Have you tried to disable JAI native acceleration (is there one in
>> Linux?)
>>
>> br Kusti
>>
>>
>>> From: Håkan Jacobsson
>>> Reply-To:
>>> Date: Fri, 22 Jan 2010 14:50:56 +0200
>>> To: Håkan Jacobsson
>>> Cc:
>>> Conversation: [JAI] Re: JAI - different behaviour when running
>>> Tomcat/Jetty
>>> server
>>> Subject: [JAI] Re: JAI - different behaviour when running Tomcat/
>>> Jetty server
>>>
>>> An update regarding my issue:
>>>
>>> When cropping JPG images in my webapp on our production server
>>> (linux
>>> - running tomcat) - JAI ignores the coordinates I supply to the crop
>>> operation.
>>> This does not happen when testing locally (Mac OS X - running
>>> Jetty).
>>> JAI always crops at the top left center in prodcution - no matter
>>> what
>>> I supply for coordinates to the cropping area.
>>> PNG image files are cropped OK.
>>>
>>>
>>> 22 jan 2010 kl. 11.46 skrev Håkan Jacobsson:
>>>
>>>> Hi,
>>>>
>>>> It seems JAI is behaving (regarding cropping) differently when
>>>> running in Tomcat server(in production) compared when running in
>>>> Jetty server (locally).
>>>> Anyone have any experience with this? The cropping operation seems
>>>> to crop at the top of my original images (with Tomcat) even
>>>> though I
>>>> specify coordinates which should
>>>> make JAI crop in the centre. This works fine locally runnning Jetty
>>>> server.
>>>>
>>>> best regards, Håkan
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
>>> For additional commands, e-mail: interest-help@jai.dev.java.net
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
>> For additional commands, e-mail: interest-help@jai.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>

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

Bob Deen

I don't know for sure, but I suspect what's actually happening here is
not a bug in JAI but in fact a bug in the writer.

Ops like crop and translate do not necessarily change the physical
image. Under certain circumstances they work by simply adjusting the
image size and/or origin coordinates. So it's practically a "free"
operation in that no pixels are copied... only the description in the
PlanarImage object changes (actually it's in the RenderedImage interface).

That should work in all cases. However, some writers ignore the image
origin (which is understandable, but clearly a bug). That would cause
the symptoms you see. The PlanarImage is described correctly, it's just
not *used* correctly by the writer. When you put it into a
BufferedImage, the pixels are actually copied so there's a physical
crop, not just a logical one, so the writers work again. The platform
dependency is due to different native-code writers on the different
platforms.

I hope this helps...

-Bob

Håkan Jacobsson wrote:
> Ok, I found the solution. On google. Thought I'd share it here.
> So, for JPEG (JPG) images. When using the crop operation with JAI (Java
> Advanced Imaging) on Linux or Windows (note that I havent tested this on
> Windows myself).
> You need to make a special case when saving the image (to file/stream or
> whatever).
> You can not save it as a PlanarImage. You need to save it as a
> BufferedImage. For other image formats (PNG, GIF etc.) you SHOULD save
> it as a PlanarImage.
> If you save a cropped JPEG image as a PlanarImage running Linux or
> Windows you will always get an image cropped at the top left corner - no
> matter what values you supply to the
> ParameterBlock.
> Apparently it is not the crop operation itself that fails. It has to do
> with the way you save the image.
> For JPEG images, save them as BufferedImages. For other formats, save
> them as PlanarImages. Running Linux or Windows.
> It is easy to retrieve a BufferedImage from a PlanarImage:
>
> planarImage.getAsBufferedImage();
>
> And please not that running Mac OS X you may save all image formats as
> PlanarImages.
>
> We are using Javas Image IO to save images. And also to read images.
>
> /regards, Håkan Jacobsson
>
> 22 jan 2010 kl. 14.04 skrev Håkan Jacobsson:
>
>> Kustaa,
>>
>> Thanx for fast reply. There might not be in Linux. How can I disable
>> the native acceleration?
>>
>> I can see on google that this is a known 'bug' with JAI. Suggestions
>> to solve the problem seem to include different ways of saving the
>> image. We're currently using ImageIO to save and read images. Would it
>> perhaps be better to use JAI for saving the images?
>>
>> 22 jan 2010 kl. 13.55 skrev Kustaa Nyholm:
>>
>>> My hunch would be that this is a Mac/Linux issue not Tomcat/Jetty issue.
>>> Have you tried to disable JAI native acceleration (is there one in
>>> Linux?)
>>>
>>> br Kusti
>>>
>>>
>>>> From: Håkan Jacobsson
>>>> Reply-To:
>>>> Date: Fri, 22 Jan 2010 14:50:56 +0200
>>>> To: Håkan Jacobsson
>>>> Cc:
>>>> Conversation: [JAI] Re: JAI - different behaviour when running
>>>> Tomcat/Jetty
>>>> server
>>>> Subject: [JAI] Re: JAI - different behaviour when running
>>>> Tomcat/Jetty server
>>>>
>>>> An update regarding my issue:
>>>>
>>>> When cropping JPG images in my webapp on our production server (linux
>>>> - running tomcat) - JAI ignores the coordinates I supply to the crop
>>>> operation.
>>>> This does not happen when testing locally (Mac OS X - running Jetty).
>>>> JAI always crops at the top left center in prodcution - no matter what
>>>> I supply for coordinates to the cropping area.
>>>> PNG image files are cropped OK.
>>>>
>>>>
>>>> 22 jan 2010 kl. 11.46 skrev Håkan Jacobsson:
>>>>
>>>>> Hi,
>>>>>
>>>>> It seems JAI is behaving (regarding cropping) differently when
>>>>> running in Tomcat server(in production) compared when running in
>>>>> Jetty server (locally).
>>>>> Anyone have any experience with this? The cropping operation seems
>>>>> to crop at the top of my original images (with Tomcat) even though I
>>>>> specify coordinates which should
>>>>> make JAI crop in the centre. This works fine locally runnning Jetty
>>>>> server.
>>>>>
>>>>> best regards, Håkan
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
>>>> For additional commands, e-mail: interest-help@jai.dev.java.net
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
>>> For additional commands, e-mail: interest-help@jai.dev.java.net
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
>> For additional commands, e-mail: interest-help@jai.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>

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