Skip to main content

javax.imageio.ImageReader.readRaster(..) returns raster with no color info.

4 replies [Last post]
demonduck
Offline
Joined: 2008-03-14
Points: 0

javax.imageio.ImageReader.readRaster(0,null) will read a Raster about
10-20% faster than javax.imageio.ImageReader.read(0) will read a
BufferedImage. Not much unless one intends to do it on the order
of 100 times -- O(2). Which I do intend to do in a tiling applet.

But readRaster() returns a Raster with no ColorModel or ColorSpace
information. The docs say:

/**
* Returns a new Raster object containing the raw pixel data
* from the image stream, without any color conversion applied. The
* application must determine how to interpret the pixel data by other
* means. Any destination or image-type parameters in the supplied
* ImageReadParam object are ignored, but all other
* parameters are used exactly as in the read(}
.
* This method allows formats that normally apply a color
* conversion, such as JPEG, and formats that do not normally have an
* associated colorspace, such as remote sensing or medical imaging data,
* to provide access to raw pixel data.

So that would be ok for my use. I could apply a ColorConvertOp to get the pixel
data into the color space that I wanted.

NOPE!

The only ColorConvertOp that works on Rasters needs a src ColorSpace and a dest
ColorSpace.

public ColorConvertOp(ColorSpace srcCspace,
ColorSpace dstCspace,
RenderingHints hints)

The problem is you can't know what the src ColorSpace is just from inspecting
the Raster returned by readRaster().

So the question:

How do I find out what the ColorSpace is of the Raster returned by readRaster()?

Reply viewing options

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

You need to read the metadata on the image.

On Jun 17, 2008, at 2:36 PM, jai-imageio@javadesktop.org wrote:

> javax.imageio.ImageReader.readRaster(0,null) will read a Raster about
> 10-20% faster than javax.imageio.ImageReader.read(0) will read a
> BufferedImage. Not much unless one intends to do it on the order
> of 100 times -- O(2). Which I do intend to do in a tiling applet.
>
> But readRaster() returns a Raster with no ColorModel or ColorSpace
> information. The docs say:
>
> /**
> * Returns a new Raster object containing the raw pixel data
> * from the image stream, without any color conversion
> applied. The
> * application must determine how to interpret the pixel data
> by other
> * means. Any destination or image-type parameters in the
> supplied
> * ImageReadParam object are ignored, but all other
> * parameters are used exactly as in the read(}
> .
> * This method allows formats that normally apply a color
> * conversion, such as JPEG, and formats that do not normally
> have an
> * associated colorspace, such as remote sensing or medical
> imaging data,
> * to provide access to raw pixel data.
>
> So that would be ok for my use. I could apply a ColorConvertOp to
> get the pixel
> data into the color space that I wanted.
>
> NOPE!
>
> The only ColorConvertOp that works on Rasters needs a src
> ColorSpace and a dest
> ColorSpace.
>
> public ColorConvertOp(ColorSpace srcCspace,
> ColorSpace dstCspace,
> RenderingHints hints)
>
> The problem is you can't know what the src ColorSpace is just from
> inspecting
> the Raster returned by readRaster().
>
> So the question:
>
> How do I find out what the ColorSpace is of the Raster returned by
> readRaster()?
> [Message sent by forum member 'demonduck' (demonduck)]
>
> http://forums.java.net/jive/thread.jspa?messageID=280813
>
> ---------------------------------------------------------------------
> 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

bpb
Offline
Joined: 2004-06-23
Points: 0

Or you could get the ImageReader and call getImageTypes() or getRawImageType() and get the ColorModel from the returned ImageTypeSpecifier.

Brian

> You need to read the metadata on the image.
>
> On Jun 17, 2008, at 2:36 PM,
> jai-imageio@javadesktop.org wrote:
>
> > javax.imageio.ImageReader.readRaster(0,null) will
> read a Raster about
> > 10-20% faster than
> javax.imageio.ImageReader.read(0) will read a
> > BufferedImage. Not much unless one intends to do
> it on the order
> > of 100 times -- O(2). Which I do intend to do in a
> tiling applet.
> >
> > But readRaster() returns a Raster with no
> ColorModel or ColorSpace
> > information. The docs say:
> >
> > /**
> > * Returns a new Raster object containing the
> raw pixel data
> > * from the image stream, without any color
> conversion
> > applied. The
> > * application must determine how to interpret
> the pixel data
> > by other
> > * means. Any destination or image-type
> parameters in the
> > supplied
> > * ImageReadParam object are ignored, but all
> other
> > * parameters are used exactly as in the read(}
> > .
> > * This method allows formats that normally
> apply a color
> > * conversion, such as JPEG, and formats that
> do not normally
> > have an
> > * associated colorspace, such as remote
> sensing or medical
> > imaging data,
> > * to provide access to raw pixel data.
> >
> > So that would be ok for my use. I could apply a
> ColorConvertOp to
> > get the pixel
> > data into the color space that I wanted.
> >
> > NOPE!
> >
> > The only ColorConvertOp that works on Rasters needs
> a src
> > ColorSpace and a dest
> > ColorSpace.
> >
> > public ColorConvertOp(ColorSpace srcCspace,
> > ColorSpace dstCspace,
> > RenderingHints hints)
> >
> > The problem is you can't know what the src
> ColorSpace is just from
> > inspecting
> > the Raster returned by readRaster().
> >
> > So the question:
> >
> > How do I find out what the ColorSpace is of the
> Raster returned by
> > readRaster()?
> > [Message sent by forum member 'demonduck'
> (demonduck)]
> >
> >
> http://forums.java.net/jive/thread.jspa?messageID=2808
> 13
> >
> >
> ------------------------------------------------------
> ---------------
> > 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

Ken Warner

That doesn't work. The getRawImageType() returns what
the file -- JPEG for example -- could be decoded as.

The getImageTypes() returns and Itorator that will
return three file types -- JPEG for example -- and
none of them describe the raw colorspace of the internal
representation of a JPEG file.

The readRaster() method returns the raw -- JPEG for
example -- image bytes in the internal, raw format
and there is no colorspace information available about
the Raster returned by the readRaster() method.

I tried and tried. There's a disconnect between what
you would expect and what actually happens.

jai-imageio@javadesktop.org wrote:
> Or you could get the ImageReader and call getImageTypes() or getRawImageType() and get the ColorModel from the returned ImageTypeSpecifier.
>
> Brian
>
>
>>You need to read the metadata on the image.
>>
>>On Jun 17, 2008, at 2:36 PM,
>>jai-imageio@javadesktop.org wrote:
>>
>>
>>>javax.imageio.ImageReader.readRaster(0,null) will
>>
>>read a Raster about
>>
>>>10-20% faster than
>>
>>javax.imageio.ImageReader.read(0) will read a
>>
>>>BufferedImage. Not much unless one intends to do
>>
>>it on the order
>>
>>>of 100 times -- O(2). Which I do intend to do in a
>>
>>tiling applet.
>>
>>>But readRaster() returns a Raster with no
>>
>>ColorModel or ColorSpace
>>
>>>information. The docs say:
>>>
>>>/**
>>> * Returns a new Raster object containing the
>>
>>raw pixel data
>>
>>> * from the image stream, without any color
>>
>>conversion
>>
>>>applied. The
>>> * application must determine how to interpret
>>
>>the pixel data
>>
>>>by other
>>> * means. Any destination or image-type
>>
>>parameters in the
>>
>>>supplied
>>> * ImageReadParam object are ignored, but all
>>
>>other
>>
>>> * parameters are used exactly as in the read(}
>>>.
>>> * This method allows formats that normally
>>
>>apply a color
>>
>>> * conversion, such as JPEG, and formats that
>>
>>do not normally
>>
>>>have an
>>> * associated colorspace, such as remote
>>
>>sensing or medical
>>
>>>imaging data,
>>> * to provide access to raw pixel data.
>>>
>>>So that would be ok for my use. I could apply a
>>
>>ColorConvertOp to
>>
>>>get the pixel
>>>data into the color space that I wanted.
>>>
>>>NOPE!
>>>
>>>The only ColorConvertOp that works on Rasters needs
>>
>>a src
>>
>>>ColorSpace and a dest
>>>ColorSpace.
>>>
>>>public ColorConvertOp(ColorSpace srcCspace,
>>> ColorSpace dstCspace,
>>> RenderingHints hints)
>>>
>>>The problem is you can't know what the src
>>
>>ColorSpace is just from
>>
>>>inspecting
>>>the Raster returned by readRaster().
>>>
>>>So the question:
>>>
>>>How do I find out what the ColorSpace is of the
>>
>>Raster returned by
>>
>>>readRaster()?
>>>[Message sent by forum member 'demonduck'
>>
>>(demonduck)]
>>
>>>
>>http://forums.java.net/jive/thread.jspa?messageID=2808
>>13
>>
>>>
>>------------------------------------------------------
>>---------------
>>
>>>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
>
> [Message sent by forum member 'bpb' (bpb)]
>
> http://forums.java.net/jive/thread.jspa?messageID=282102
>
> ---------------------------------------------------------------------
> 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

Brian Burkhalter

You are correct. I misread the post.

Brian

On Jun 23, 2008, at 5:02 PM, Ken Warner wrote:

> That doesn't work. The getRawImageType() returns what
> the file -- JPEG for example -- could be decoded as.
>
> The getImageTypes() returns and Itorator that will
> return three file types -- JPEG for example -- and
> none of them describe the raw colorspace of the internal
> representation of a JPEG file.
>
> The readRaster() method returns the raw -- JPEG for
> example -- image bytes in the internal, raw format
> and there is no colorspace information available about
> the Raster returned by the readRaster() method.
>
> I tried and tried. There's a disconnect between what
> you would expect and what actually happens.
>
> jai-imageio@javadesktop.org wrote:
>> Or you could get the ImageReader and call getImageTypes() or
>> getRawImageType() and get the ColorModel from the returned
>> ImageTypeSpecifier.
>> Brian
>>> You need to read the metadata on the image.
>>>
>>> On Jun 17, 2008, at 2:36 PM,
>>> jai-imageio@javadesktop.org wrote:
>>>
>>>
>>>> javax.imageio.ImageReader.readRaster(0,null) will
>>>
>>> read a Raster about
>>>
>>>> 10-20% faster than
>>>
>>> javax.imageio.ImageReader.read(0) will read a
>>>
>>>> BufferedImage. Not much unless one intends to do
>>>
>>> it on the order
>>>
>>>> of 100 times -- O(2). Which I do intend to do in a
>>>
>>> tiling applet.
>>>
>>>> But readRaster() returns a Raster with no
>>>
>>> ColorModel or ColorSpace
>>>
>>>> information. The docs say:
>>>>
>>>> /**
>>>> * Returns a new Raster object containing the
>>>
>>> raw pixel data
>>>
>>>> * from the image stream, without any color
>>>
>>> conversion
>>>> applied. The
>>>> * application must determine how to interpret
>>>
>>> the pixel data
>>>> by other
>>>> * means. Any destination or image-type
>>>
>>> parameters in the
>>>> supplied
>>>> * ImageReadParam object are ignored, but all
>>>
>>> other
>>>
>>>> * parameters are used exactly as in the read(}
>>>> .
>>>> * This method allows formats that normally
>>>
>>> apply a color
>>>
>>>> * conversion, such as JPEG, and formats that
>>>
>>> do not normally
>>>> have an
>>>> * associated colorspace, such as remote
>>>
>>> sensing or medical
>>>> imaging data,
>>>> * to provide access to raw pixel data.
>>>>
>>>> So that would be ok for my use. I could apply a
>>>
>>> ColorConvertOp to
>>>> get the pixel
>>>> data into the color space that I wanted.
>>>>
>>>> NOPE!
>>>>
>>>> The only ColorConvertOp that works on Rasters needs
>>>
>>> a src
>>>> ColorSpace and a dest
>>>> ColorSpace.
>>>>
>>>> public ColorConvertOp(ColorSpace srcCspace,
>>>> ColorSpace dstCspace,
>>>> RenderingHints hints)
>>>>
>>>> The problem is you can't know what the src
>>>
>>> ColorSpace is just from
>>>> inspecting
>>>> the Raster returned by readRaster().
>>>>
>>>> So the question:
>>>>
>>>> How do I find out what the ColorSpace is of the
>>>
>>> Raster returned by
>>>> readRaster()?
>>>> [Message sent by forum member 'demonduck'
>>>
>>> (demonduck)]
>>>
>>>>
>>> http://forums.java.net/jive/thread.jspa?messageID=2808
>>> 13
>>>
>>>>
>>> ------------------------------------------------------
>>> ---------------
>>>
>>>> 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
>> [Message sent by forum member 'bpb' (bpb)]
>> http://forums.java.net/jive/thread.jspa?messageID=282102
>> ---------------------------------------------------------------------
>> 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
>

>^..^< >^..^<

Brian Burkhalter
Java Imaging and Video
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