Skip to main content

[JAI-IMAGEIO] ImageReader.getMinIndex() and getRawImageType()

6 replies [Last post]
Anonymous

When I call ImageReader's getMinIndex() method I get zero. However if I
call ImageReader's getRawImageType(0) on this same image, I get an
IndexOutOfBoundsException: "imageIndex out of bounds!"

What's the problem?

When I dump the XML of the IIOMetadata for this image (a PNG), I find

...

--
"Hell hath no limits, nor is circumscrib'd In one self-place; but where we
are is hell, And where hell is, there must we ever be" --Christopher
Marlowe, *Doctor Faustus* (v, 121-24)
[att1.html]

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
broumbroum
Offline
Joined: 2010-04-24

> When I call ImageReader's getMinIndex() method I get
> zero. However if I
> call ImageReader's getRawImageType(0) on this same
> image, I get an
> IndexOutOfBoundsException: "imageIndex out of
> bounds!"
>

either try with getImageType(0) and if it fails, maybe your png stream is not fully seekable or[b] it misses the pixels data[/b]. Try with a [code]FileCacheImageInputStream[/code] as input to the ImageReader, but check up the source file or stream contents with a common image viewer !

Message was edited by: broumbroum

Harald Kuhr

On 5. aug. 2010, at 00.03, jai-imageio@javadesktop.org wrote:

>> When I call ImageReader's getMinIndex() method I get
>> zero. However if I
>> call ImageReader's getRawImageType(0) on this same
>> image, I get an
>> IndexOutOfBoundsException: "imageIndex out of
>> bounds!"
>>
>
> either try with getImageType(0) and if it fails, maybe your png stream is not fully seekable or[b] it misses the pixels data[/b]. Try with a FileCacheImageInputStream() as input to the ImageReader, but check up the source file or stream contents with a common image viewer !

What does getNumImages(true) return? Checking minIndex alone isn't a gurantee that there won't be an IOOBE.

My guess is that most ImageReaders don't test the image for pixel data, before returning minIndex = 0. I'm not sure the spec is 100% clear on what should happen if there's no pixel data, but at least I'm pretty sure getNumImages should return 0. In that case all index-based methods will (should) throw IOOBE (as there's no value x in (0 < x, x < 0)).

If getNumImages does return a positive value I'd say it's a bug.

--
Harald K

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

Thad Humphries

getNumImages(true) returns 1, so minIndex is certainly wrong when the reader
uses ImageInputStream

getMinIndex() does work if I use FileCacheImageInputStream. Thanks for that
tip. However, is seems to me that if I can't get a good reader without a
cache, ImageIO.createImageInputStream(Object) [in my case, a
java.io.InputStream] should have thrown an exception, not returned me a bad
reader. There seems to be a lot of garbage like this in ImageIO. For
example, ImageIO.getImageReadersByFormatName("jpeg") won't return
Iterator on a non-JFIF JPEG image I have, though the image
opens fine with JAI.

The PNG image itself is good. It began as a JPEG which I scaled and saved
as PNG with Gimp. It opens in my browser, with JAI, and all Linux image
tools I've tried.

On Thu, Aug 5, 2010 at 4:38 AM, Harald Kuhr wrote:

>
> On 5. aug. 2010, at 00.03, jai-imageio@javadesktop.org wrote:
>
> >> When I call ImageReader's getMinIndex() method I get
> >> zero. However if I
> >> call ImageReader's getRawImageType(0) on this same
> >> image, I get an
> >> IndexOutOfBoundsException: "imageIndex out of
> >> bounds!"
> >>
> >
> > either try with getImageType(0) and if it fails, maybe your png stream is
> not fully seekable or[b] it misses the pixels data[/b]. Try with a
> FileCacheImageInputStream() as input to the ImageReader, but check up the
> source file or stream contents with a common image viewer !
>
> What does getNumImages(true) return? Checking minIndex alone isn't a
> gurantee that there won't be an IOOBE.
>
> My guess is that most ImageReaders don't test the image for pixel data,
> before returning minIndex = 0. I'm not sure the spec is 100% clear on what
> should happen if there's no pixel data, but at least I'm pretty sure
> getNumImages should return 0. In that case all index-based methods will
> (should) throw IOOBE (as there's no value x in (0 < x, x < 0)).
>
> If getNumImages does return a positive value I'd say it's a bug.
>
>
> --
> Harald K
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
>
>

--
"Hell hath no limits, nor is circumscrib'd In one self-place; but where we
are is hell, And where hell is, there must we ever be" --Christopher
Marlowe, *Doctor Faustus* (v, 121-24)
[att1.html]

broumbroum
Offline
Joined: 2010-04-24

ImageIO.setUseCache() , see doc about that.

Thad Humphries

Thanks! I see that useCache defaults to true but, oddly, is not set
automagically, like to java.io.tmpdir.

So I set the cache directory to java.io.tmpdir (/tmp) and
ImageIO.createImageInputStream give me a ImageInputStream that behaves as I
expect.

On Thu, Aug 5, 2010 at 11:30 AM, wrote:

> ImageIO.setUseCache() , see doc about that.
> [Message sent by forum member 'broumbroum']
>
> http://forums.java.net/jive/thread.jspa?messageID=479434
>

--
"Hell hath no limits, nor is circumscrib'd In one self-place; but where we
are is hell, And where hell is, there must we ever be" --Christopher
Marlowe, *Doctor Faustus* (v, 121-24)
[att1.html]

Thad Humphries

Oops. My error. The cache IS set to java.io.tmpdir, but
ImageIO.getCacheDirectory() returns "null to indicate the system-dependent
default temporary-file directory."

On Thu, Aug 5, 2010 at 1:58 PM, Thad Humphries
wrote:

> Thanks! I see that useCache defaults to true but, oddly, is not set
> automagically, like to java.io.tmpdir.
>
> So I set the cache directory to java.io.tmpdir (/tmp) and
> ImageIO.createImageInputStream give me a ImageInputStream that behaves as I
> expect.
>
>
> On Thu, Aug 5, 2010 at 11:30 AM, wrote:
>
>> ImageIO.setUseCache() , see doc about that.
>> [Message sent by forum member 'broumbroum']
>>
>> http://forums.java.net/jive/thread.jspa?messageID=479434
>>
>
--
"Hell hath no limits, nor is circumscrib'd In one self-place; but where we
are is hell, And where hell is, there must we ever be" --Christopher
Marlowe, *Doctor Faustus* (v, 121-24)
[att1.html]