Skip to main content

[JAI-IMAGEIO] Speeding up scaling in JAI

5 replies [Last post]
Anonymous

I am using JAI to scale images. The images are BufferedImages, and the
big hit is when I use getAsBufferedImage to change the result back to
a BufferedImage.

Is there a faster way to do this and still have an image I can use
'outside' JAI?

MArk

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

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Brian Burkhalter

Correct. As mentioned elsewhere today, one case indeed double memory use by
using getAsBufferedImage() but the copy is needed to guarantee semantics as a
BufferedImage is a WritableRenderedImage wheareas a PlanarImage is a
RenderedImage only. For a single-tiled PlanarImage the copy can be averted by
using getTile(0,0) to get the single tile, pulling the DataBuffer and
SampleModel out, using these to create a WritableRaster, and then creating a
BufferedImage from the WritableRaster and the image ColorModel. Note however
that writing to the resulting BufferedImage will overwrite the original image
data.

On Mon, 8 Jan 2007, Simone Giannecchini wrote:

> 1>Using getAsBufferedImage can be bad because it performs a copy of
> the result of the JAI chain hence it can be quite inefficient on big
> rasters.

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

Simone Giannecchini

Just to throw my 2 cents there.

1>Using getAsBufferedImage can be bad because it performs a copy of
the result of the JAI chain hence it can be quite inefficient on big
rasters.

2>A bufferedImage is a RenderedImage. A RenderedOp can be used to
create a PlanarImage which is a RenderedImage. What about exploit that
insteaod of going back to BufferedImage? If you really want to get a
BufferedImage how about using getData setData methods (be aware that
this will share the underlying rasters)?

Hope that helps,
Simone.

On 1/8/07, Fabrizio Giudici wrote:
>
> On Jan 8, 2007, at 17:11 , mark.stephens@ukonline.co.uk wrote:
>
> > I am using JAI to scale images. The images are BufferedImages, and the
> > big hit is when I use getAsBufferedImage to change the result back to
> > a BufferedImage.
>
> Probably the problem is not the getAsBufferedImage(), but the fact
> that with JAI operations are usually postponed until the are
> necessary. For this reason, it's likely that getAsBufferedImage()
> it's just the point that triggers the scale operation. So you should
> probably look at that operation. How large is the image? Are you
> using tiling? How are the tile cache settings? Which exact operation
> are you using for scaling?
>
> >
> > Is there a faster way to do this and still have an image I can use
> > 'outside' JAI?
> >
> > MArk
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> > For additional commands, e-mail: interest-help@jai-
> > imageio.dev.java.net
> >
> >
>
> --
> Fabrizio Giudici, Ph.D. - Java Architect, Project Manager
> Tidalwave s.a.s. - "We make Java work. Everywhere."
> weblogs.java.net/blog/fabriziogiudici - www.tidalwave.it/blog
> Fabrizio.Giudici@tidalwave.it - mobile: +39 348.150.6941
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
>
>

--
-------------------------------------------------------
Eng. Simone Giannecchini
President /CEO GeoSolutions

http://www.geo-solutions.it

-------------------------------------------------------

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

mark.stephens@ukonline.co.uk

In message <961f4d9e0701080923i6f745bf3xa922b2eb912366f5@mail.gmail.co
m>
"Simone Giannecchini" wrote:

> Just to throw my 2 cents there.

Every penny welcome!

>
> 1>Using getAsBufferedImage can be bad because it performs a copy of
> the result of the JAI chain hence it can be quite inefficient on big
> rasters.
>
> 2>A bufferedImage is a RenderedImage. A RenderedOp can be used to
> create a PlanarImage which is a RenderedImage. What about exploit that
> insteaod of going back to BufferedImage? If you really want to get a
> BufferedImage how about using getData setData methods (be aware that
> this will share the underlying rasters)?

Will have a look at Planar image.

Regards,

MArk

>
>
> Hope that helps,
> Simone.
>
> On 1/8/07, Fabrizio Giudici wrote:
>>
>> On Jan 8, 2007, at 17:11 , mark.stephens@ukonline.co.uk wrote:
>>
>> > I am using JAI to scale images. The images are BufferedImages, and the
>> > big hit is when I use getAsBufferedImage to change the result back to
>> > a BufferedImage.
>>
>> Probably the problem is not the getAsBufferedImage(), but the fact
>> that with JAI operations are usually postponed until the are
>> necessary. For this reason, it's likely that getAsBufferedImage()
>> it's just the point that triggers the scale operation. So you should
>> probably look at that operation. How large is the image? Are you
>> using tiling? How are the tile cache settings? Which exact operation
>> are you using for scaling?
>>
>> >
>> > Is there a faster way to do this and still have an image I can use
>> > 'outside' JAI?
>> >
>> > MArk
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
>> > For additional commands, e-mail: interest-help@jai-
>> > imageio.dev.java.net
>> >
>> >
>>
>> --
>> Fabrizio Giudici, Ph.D. - Java Architect, Project Manager
>> Tidalwave s.a.s. - "We make Java work. Everywhere."
>> weblogs.java.net/blog/fabriziogiudici - www.tidalwave.it/blog
>> Fabrizio.Giudici@tidalwave.it - mobile: +39 348.150.6941
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
>> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
>>
>>
>
>

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

Fabrizio Giudici

On Jan 8, 2007, at 17:11 , mark.stephens@ukonline.co.uk wrote:

> I am using JAI to scale images. The images are BufferedImages, and the
> big hit is when I use getAsBufferedImage to change the result back to
> a BufferedImage.

Probably the problem is not the getAsBufferedImage(), but the fact
that with JAI operations are usually postponed until the are
necessary. For this reason, it's likely that getAsBufferedImage()
it's just the point that triggers the scale operation. So you should
probably look at that operation. How large is the image? Are you
using tiling? How are the tile cache settings? Which exact operation
are you using for scaling?

>
> Is there a faster way to do this and still have an image I can use
> 'outside' JAI?
>
> MArk
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-
> imageio.dev.java.net
>
>

--
Fabrizio Giudici, Ph.D. - Java Architect, Project Manager
Tidalwave s.a.s. - "We make Java work. Everywhere."
weblogs.java.net/blog/fabriziogiudici - www.tidalwave.it/blog
Fabrizio.Giudici@tidalwave.it - mobile: +39 348.150.6941

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

mark.stephens@ukonline.co.uk

In message
Fabrizio Giudici wrote:

>
> On Jan 8, 2007, at 17:11 , mark.stephens@ukonline.co.uk wrote:
>
>> I am using JAI to scale images. The images are BufferedImages, and the
>> big hit is when I use getAsBufferedImage to change the result back to
>> a BufferedImage.
>
> Probably the problem is not the getAsBufferedImage(), but the fact
> that with JAI operations are usually postponed until the are
> necessary. For this reason, it's likely that getAsBufferedImage()
> it's just the point that triggers the scale operation. So you should
> probably look at that operation. How large is the image?

>From 50x50 to 2000x2000 pixels

> Are you
> using tiling? How are the tile cache settings? Which exact operation
> are you using for scaling?

I'm not using tiling and using JAI.create with "scale" operation.

MArkee

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