Skip to main content

RawImageInputStream error with JPEG2000 compression

3 replies [Last post]
scyudits
Offline
Joined: 2005-07-15
Points: 0

I am trying to create a RenderedImage from a RawImageInputStream, and compress it with JPEG2000. However, the same ImageWrite operation that works for a TiledImage does not work for this RawImageInputStream. I get the following error:

java.lang.IllegalStateException: output == null!
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageWriter.write(J2KImageWriter.java:184)

Here is the code I use to get the RenderedImage from the RawImageInputStream. Note that I am actually using java.lang.reflect.* to instantiate the com.sun.media.imageio.* classes, but I've left that out of the code for clarity.

InputStream bis = a binary input stream;
SampleModel sm = the sample model for this data;
ImageInputStream iis = ImageIO.createImageInputStream(bis);
RawImageInputStream riis = new RawImageInputStream(iis, sm, new long[]{0}, new Dimension[]{new Dimension(width, height)});
RawImageReader rawImRead = new RawImageReader(null);

rawImRead.setInput(riis);
RenderedImage op = rawImRead.readAsRenderedImage(0, null);

Is my definition of the RawImageInputStream correct? What is causing the error?

Reply viewing options

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

The error message indicates that the stream set on the writer is 'null'. What
version are you using?

Brian

On Fri, 5 May 2006, jai-imageio@javadesktop.org wrote:

> I am trying to create a RenderedImage from a RawImageInputStream, and compress it with JPEG2000. However, the same ImageWrite operation that works for a TiledImage does not work for this RawImageInputStream. I get the following error:
>
> java.lang.IllegalStateException: output == null!
> at com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageWriter.write(J2KImageWriter.java:184)
>
> Here is the code I use to get the RenderedImage from the RawImageInputStream. Note that I am actually using java.lang.reflect.* to instantiate the com.sun.media.imageio.* classes, but I've left that out of the code for clarity.
>
> InputStream bis = a binary input stream;
> SampleModel sm = the sample model for this data;
> ImageInputStream iis = ImageIO.createImageInputStream(bis);
> RawImageInputStream riis = new RawImageInputStream(iis, sm, new long[]{0}, new Dimension[]{new Dimension(width, height)});
> RawImageReader rawImRead = new RawImageReader(null);
>
> rawImRead.setInput(riis);
> RenderedImage op = rawImRead.readAsRenderedImage(0, null);
>
> Is my definition of the RawImageInputStream correct? What is causing the error?
> [Message sent by forum member 'scyudits' (scyudits)]
>
> http://forums.java.net/jive/thread.jspa?messageID=110937
>
> ---------------------------------------------------------------------
> 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 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

scyudits
Offline
Joined: 2005-07-15
Points: 0

Update, and questions:

1. The following JPEG2000 compression code results in an OutOfMemoryError for a large enough image, even when the RenderedImage is defined directly from the stream, and when I use the "Format" operator to tile it before passing it to ImageWrite.write()

ImageOutputStream ios = /*a binary output stream, fits up to 4GB */
InputStream bis = /*a binary input stream, fits up to 4GB */
SampleModel sm = the sample model for this data;
ImageInputStream iis = ImageIO.createImageInputStream(bis);
RawImageInputStream riis = new RawImageInputStream(iis, sm, new long[]{0}, new Dimension[]{new Dimension(width, height)});
RawImageReader rawImRead = new RawImageReader(null);
rawImRead.setInput(riis);
RenderedImage op = rawImRead.readAsRenderedImage(0, null);

ParameterBlock pb = new ParameterBlock();
pb.addSource(op);
pb.add(sm.getDataType());
ImageLayout il = new ImageLayout(0, 0, dim1, dim1, null, null);
RenderingHints rh = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, il);
RenderedOp op1 = JAI.create("format", pb, rh);

ImageWriter writer = /*JPEG2000 ImageWriter*/
writer.setOutput(ios);
J2KImageWriteParam jiwp = new J2KImageWriteParam();
jiwp.setLossless(false);
jiwp.setTiling(104,104,0,0);

IIOImage im = new IIOImage(op1, null, writer.getDefaultImageMetadata(new ImageTypeSpecifier(op1), jiwp));
writer.write(null, im, jiwp);

java.lang.OutOfMemoryError
at jj2000.j2k.entropy.encoder.EBCOTRateAllocator.(EBCOTRateAllocator.java:358)
at jj2000.j2k.entropy.encoder.PostCompRateAllocator.createInstance(PostCompRateAllocator.java:258)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageWriter.write(J2KImageWriter.java:325)

So my question here is, is there a bug in the JPEG2000 compression (e.g. putting the whole image into memory at once) that prevents it from being scalable, or is there a parameter that I can set to make it scalable?

2. Alternatively, in the hopes that going through the JAI ImageWrite operator would be more scalable, I am trying to pass a RenderedImage to the JPEG2000 JAI ImageWrite operation, but I am getting an "Unable to render RenderedOp for this operation" error. The input RenderedImage itself renders without errors when I call RenderedImage.getData() and getWidth(), getHeight(), etc.

InputStream bis = a binary input stream;
SampleModel sm = the sample model for this data;
ImageInputStream iis = ImageIO.createImageInputStream(bis);
RawImageInputStream riis = new RawImageInputStream(iis, sm, new long[]{0}, new Dimension[]{new Dimension(width, height)});
RawImageReader rawImRead = new RawImageReader(null);
rawImRead.setInput(riis);
RenderedImage op = rawImRead.readAsRenderedImage(0, null);
ParameterBlock pb1 = new ParameterBlock();
pb1.addSource(ti);
pb1.add(ios);
pb1.add("jpeg2000");
pb1.add(new Boolean(false));
pb1.add(new Boolean(false));
pb1.add(new Boolean(false));
pb1.add(new Boolean(true));
pb1.add(new Dimension(104,104));
pb1.add(null);
pb1.add(null);
pb1.add(null);
pb1.add(null);
pb1.add(null);
J2KImageWriteParam jiwp = new J2KImageWriteParam();
jiwp.setLossless(false);
jiwp.setTiling(104,104,0,0);
pb1.add(jiwp);
ImageWriter writer = /*JPEG2000 ImageWriter*/
writer.setOutput(ios);
pb1.add(writer);

JAI thejai = JAI.getDefaultInstance();
OperationRegistry or = thejai.getOperationRegistry();
try
{
or.registerDescriptor(new ImageWriteDescriptor());
thejai.setOperationRegistry(or);
}
catch (Exception ex)
{
//if already registered, ok.
}

thejai.createNS("ImageWrite", pb1, null);

java.lang.RuntimeException: - Unable to render RenderedOp for this operation.
at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:838)
at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:878)
at javax.media.jai.RenderedOp.getRendering(RenderedOp.java:899)
at javax.media.jai.JAI.createNS(JAI.java:1103)
...

My question here is, first of all, what is causing this error and how to fix it? And secondly, would going through the ImageWrite operation make JPEG2000 compression scalable? In other words, would the rendering process stream directly from the input stream to the output stream without holding the entire image in memory?

Thanks,

Sophia

> The error message indicates that the stream set on
> the writer is 'null'. What
> version are you using?
>
> Brian
>
> On Fri, 5 May 2006, jai-imageio@javadesktop.org
> wrote:
>
> > I am trying to create a RenderedImage from a
> RawImageInputStream, and compress it with JPEG2000.
> However, the same ImageWrite operation that works for
> a TiledImage does not work for this
> RawImageInputStream. I get the following error:
> >
> > java.lang.IllegalStateException: output == null!
> > at
> com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageWri
> ter.write(J2KImageWriter.java:184)
> >
> > Here is the code I use to get the RenderedImage
> from the RawImageInputStream. Note that I am actually
> using java.lang.reflect.* to instantiate the
> com.sun.media.imageio.* classes, but I've left that
> out of the code for clarity.
> >
> > InputStream bis = a binary input stream;
> > SampleModel sm = the sample model for this data;
> > ImageInputStream iis =
> ImageIO.createImageInputStream(bis);
> > RawImageInputStream riis = new
> RawImageInputStream(iis, sm, new long[]{0}, new
> Dimension[]{new Dimension(width, height)});
> > RawImageReader rawImRead = new
> RawImageReader(null);
> >
> > rawImRead.setInput(riis);
> > RenderedImage op = rawImRead.readAsRenderedImage(0,
> null);
> >
> > Is my definition of the RawImageInputStream
> correct? What is causing the error?
> > [Message sent by forum member 'scyudits'
> (scyudits)]
> >
> >
> http://forums.java.net/jive/thread.jspa?messageID=1109
> 37
> >
> >
> ------------------------------------------------------
> ---------------
> > 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 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

scyudits
Offline
Joined: 2005-07-15
Points: 0

sorry, in the first example, dim1 = 104

> Update, and questions:
>
> 1. The following JPEG2000 compression code results in
> an OutOfMemoryError for a large enough image, even
> when the RenderedImage is defined directly from the
> stream, and when I use the "Format" operator to tile
> it before passing it to ImageWrite.write()
>
> ImageOutputStream ios = /*a binary output stream,
> fits up to 4GB */
> InputStream bis = /*a binary input stream, fits up to
> 4GB */
> SampleModel sm = the sample model for this data;
> ImageInputStream iis =
> ImageIO.createImageInputStream(bis);
> RawImageInputStream riis = new
> RawImageInputStream(iis, sm, new long[]{0}, new
> Dimension[]{new Dimension(width, height)});
> RawImageReader rawImRead = new RawImageReader(null);
> rawImRead.setInput(riis);
> RenderedImage op = rawImRead.readAsRenderedImage(0,
> null);
>
> ParameterBlock pb = new ParameterBlock();
> pb.addSource(op);
> pb.add(sm.getDataType());
> ImageLayout il = new ImageLayout(0, 0, dim1, dim1,
> null, null);
> RenderingHints rh = new
> RenderingHints(JAI.KEY_IMAGE_LAYOUT, il);
> RenderedOp op1 = JAI.create("format", pb, rh);
>
> ImageWriter writer = /*JPEG2000 ImageWriter*/
> writer.setOutput(ios);
> J2KImageWriteParam jiwp = new J2KImageWriteParam();
> jiwp.setLossless(false);
> jiwp.setTiling(104,104,0,0);
>
> IIOImage im = new IIOImage(op1, null,
> writer.getDefaultImageMetadata(new
> ImageTypeSpecifier(op1), jiwp));
> writer.write(null, im, jiwp);
>
> java.lang.OutOfMemoryError
> at
> t
> jj2000.j2k.entropy.encoder.EBCOTRateAllocator.(E
> BCOTRateAllocator.java:358)
> at
> t
> jj2000.j2k.entropy.encoder.PostCompRateAllocator.creat
> eInstance(PostCompRateAllocator.java:258)
> at
> t
> com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageWri
> ter.write(J2KImageWriter.java:325)
>
> So my question here is, is there a bug in the
> JPEG2000 compression (e.g. putting the whole image
> into memory at once) that prevents it from being
> scalable, or is there a parameter that I can set to
> make it scalable?
>
> 2. Alternatively, in the hopes that going through the
> JAI ImageWrite operator would be more scalable, I am
> trying to pass a RenderedImage to the JPEG2000 JAI
> ImageWrite operation, but I am getting an "Unable to
> render RenderedOp for this operation" error. The
> input RenderedImage itself renders without errors
> when I call RenderedImage.getData() and getWidth(),
> getHeight(), etc.
>
> InputStream bis = a binary input stream;
> SampleModel sm = the sample model for this data;
> ImageInputStream iis =
> ImageIO.createImageInputStream(bis);
> RawImageInputStream riis = new
> RawImageInputStream(iis, sm, new long[]{0}, new
> Dimension[]{new Dimension(width, height)});
> RawImageReader rawImRead = new RawImageReader(null);
> rawImRead.setInput(riis);
> RenderedImage op = rawImRead.readAsRenderedImage(0,
> null);
> ParameterBlock pb1 = new ParameterBlock();
> pb1.addSource(ti);
> pb1.add(ios);
> pb1.add("jpeg2000");
> pb1.add(new Boolean(false));
> pb1.add(new Boolean(false));
> pb1.add(new Boolean(false));
> pb1.add(new Boolean(true));
> pb1.add(new Dimension(104,104));
> pb1.add(null);
> pb1.add(null);
> pb1.add(null);
> pb1.add(null);
> pb1.add(null);
> J2KImageWriteParam jiwp = new J2KImageWriteParam();
> jiwp.setLossless(false);
> jiwp.setTiling(104,104,0,0);
> pb1.add(jiwp);
> ImageWriter writer = /*JPEG2000 ImageWriter*/
> writer.setOutput(ios);
> pb1.add(writer);
>
> JAI thejai = JAI.getDefaultInstance();
> OperationRegistry or =
> thejai.getOperationRegistry();
> try
> {
> or.registerDescriptor(new ImageWriteDescriptor());
> thejai.setOperationRegistry(or);
> }
> catch (Exception ex)
> {
> //if already registered, ok.
> }
>
> thejai.createNS("ImageWrite", pb1, null);
>
> java.lang.RuntimeException: - Unable to render
> RenderedOp for this operation.
> at
> t
> javax.media.jai.RenderedOp.createInstance(RenderedOp.j
> ava:838)
> at
> t
> javax.media.jai.RenderedOp.createRendering(RenderedOp.
> java:878)
> at
> t
> javax.media.jai.RenderedOp.getRendering(RenderedOp.jav
> a:899)
> at javax.media.jai.JAI.createNS(JAI.java:1103)
> ...
>
> My question here is, first of all, what is causing
> this error and how to fix it? And secondly, would
> going through the ImageWrite operation make JPEG2000
> compression scalable? In other words, would the
> rendering process stream directly from the input
> stream to the output stream without holding the
> entire image in memory?
>
> Thanks,
>
> Sophia
>
> > The error message indicates that the stream set on
> > the writer is 'null'. What
> > version are you using?
> >
> > Brian
> >
> > On Fri, 5 May 2006, jai-imageio@javadesktop.org
> > wrote:
> >
> > > I am trying to create a RenderedImage from a
> > RawImageInputStream, and compress it with
> JPEG2000.
> > However, the same ImageWrite operation that works
> for
> > a TiledImage does not work for this
> > RawImageInputStream. I get the following error:
> > >
> > > java.lang.IllegalStateException: output == null!
> > > at
> >
> com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageWri
>
> > ter.write(J2KImageWriter.java:184)
> > >
> > > Here is the code I use to get the RenderedImage
> > from the RawImageInputStream. Note that I am
> actually
> > using java.lang.reflect.* to instantiate the
> > com.sun.media.imageio.* classes, but I've left
> that
> > out of the code for clarity.
> > >
> > > InputStream bis = a binary input stream;
> > > SampleModel sm = the sample model for this data;
> > > ImageInputStream iis =
> > ImageIO.createImageInputStream(bis);
> > > RawImageInputStream riis = new
> > RawImageInputStream(iis, sm, new long[]{0}, new
> > Dimension[]{new Dimension(width, height)});
> > > RawImageReader rawImRead = new
> > RawImageReader(null);
> > >
> > > rawImRead.setInput(riis);
> > > RenderedImage op =
> rawImRead.readAsRenderedImage(0,
> > null);
> > >
> > > Is my definition of the RawImageInputStream
> > correct? What is causing the error?
> > > [Message sent by forum member 'scyudits'
> > (scyudits)]
> > >
> > >
> >
> http://forums.java.net/jive/thread.jspa?messageID=1109
>
> > 37
> > >
> > >
> >
> ------------------------------------------------------
>
> > ---------------
> > > 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 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