Skip to main content

[JAI-IMAGEIO] Animated GIF

7 replies [Last post]
Anonymous

I know we can write animated GIFs with Imageio since I remember some
emails about this.

Does anyone have some sample code for doing this task that I can reuse?

Thx.
Simone.

--
°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
Simone Giannecchini
Software Engineer
Freelance Consultant

http://simboss.wordpress.com/

°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°

---------------------------------------------------------------------
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

No code but from this

https://jai.dev.java.net/servlets/ReadMsg?listName=interest&msgNo=1178

you can see it's simple. Your images should already be index-color when passed
to the GIF writer. The only complication would be I think if you were passing
in metadata.

Brian

On Thu, 15 Jun 2006, Simone Giannecchini wrote:

> I know we can write animated GIFs with Imageio since I remember some
> emails about this.
>
> Does anyone have some sample code for doing this task that I can reuse?

----------------
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

Thx for the link Brian, but I am looking for something more specific to GIF

For example, how can I control the loop repetitions number or the
delay between two different frames?

Besides I am getting some nasty errors when I try to write a sequence
with the GIF writer.

I will post some code tomorrow when I will be at work.

Thx,
SImone.

On 6/15/06, Brian Burkhalter wrote:
> No code but from this
>
> https://jai.dev.java.net/servlets/ReadMsg?listName=interest&msgNo=1178
>
> you can see it's simple. Your images should already be index-color when passed
> to the GIF writer. The only complication would be I think if you were passing
> in metadata.
>
> Brian
>
> On Thu, 15 Jun 2006, Simone Giannecchini wrote:
>
> > I know we can write animated GIFs with Imageio since I remember some
> > emails about this.
> >
> > Does anyone have some sample code for doing this task that I can reuse?
>
> ----------------
> 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
Software Engineer
Freelance Consultant

http://simboss.wordpress.com/

°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°

---------------------------------------------------------------------
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

Ciao Brian,
I solved all the issues, I am able to set both the delay for each
frame as well as the loop count. I took me a while to figure out how
to do it but it was not that difficult. I might write a small paper to
describe the process.

This email is for side isue I ran into at the end of this process.
To encode the images I am going through JAI using the following code

ImageWriteDescriptor.createCollection(listOfImages, otStream, "gif",
Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE,
null, null, metadataArray, null, null, null, null, gifWriter,
null);

I got the following exception:

Exception in thread "main" java.lang.NullPointerException
at com.sun.media.jai.imageioimpl.ImageWriteCRIF.create(ImageWriteCRIF.java:627)
at com.sun.media.jai.imageioimpl.ImageWriteCIF.create(ImageWriteCIF.java:218)
at javax.media.jai.CollectionOp.createInstance(CollectionOp.java:756)
at javax.media.jai.CollectionOp.createCollection(CollectionOp.java:678)
at javax.media.jai.CollectionOp.getCollection(CollectionOp.java:671)
at javax.media.jai.JAI.createCollectionNS(JAI.java:1281)
at javax.media.jai.JAI.createCollection(JAI.java:1153)
at com.sun.media.jai.operator.ImageWriteDescriptor.createCollection(ImageWriteDescriptor.java:1062)
at it.geosolutions.graphics.gifanimated.GIFAnimated.generate(GIFAnimated.java:442)
at it.geosolutions.graphics.gifanimated.GIFAnimated.main(GIFAnimated.java:276)

I inspected the code of ImageWriteCRIF class downloading the code from
cvs and I found a bug.

Look at the following code excerpt starting at line 589:

---
// Set the return value.
if(allowPixelReplacement &&
source instanceof PlanarImage &&
writer.canReplacePixels(imageIndex)) {

// Create an image which is a PropertyChangeListener of
// "invalidregion" events including RenderingChangeEvents.
image = new PixelReplacementImage(source,
rh,
param,
writer,
imageIndex,
streamToClose);

// Register the image as a sink of its source so that
// it automatically receives events.
((PlanarImage)source).addSink(image);
} else if(!writeToSequence) {
Object writerOutput = writer.getOutput();
if(writerOutput != pb.getObjectParameter(0) &&
writerOutput instanceof ImageOutputStream) {
// This block is executed if and only if pixel
// replacement is not occurring, a sequence is
// not being written, and an ImageOutputStream
// inaccessible to the application is set on the
// ImageWriter.
((ImageOutputStream)writerOutput).flush();
}

// Set the return value to the original image or
// a wrapped version thereof.
image = source instanceof WritablePropertySource ?
source : new RenderedImageAdapter(source);
}

// Set required properties.
WritablePropertySource wps = (WritablePropertySource)image;

// Set the ImageWriteParam property.
wps.setProperty(
ImageWriteDescriptor.PROPERTY_NAME_IMAGE_WRITE_PARAM,
param);

----

in case both branches conditions are false, like in my case, image is
uninitialized therefore I got the null pointer exception.

Solving this issue shold be pretty easy, but I have not time right now
to do it myself.

Could you subit a bug report for this. I hope to see this bug fixed
soon because I susually use the daily build for ImageIO and this buf
is preventing me from using the ImageWrite operator for wiriting
sequence of image since the same things happens for multipage tiff
files.

Simone.

---
On 6/16/06, Simone Giannecchini wrote:
> Thx for the link Brian, but I am looking for something more specific to GIF
>
> For example, how can I control the loop repetitions number or the
> delay between two different frames?
>
> Besides I am getting some nasty errors when I try to write a sequence
> with the GIF writer.
>
> I will post some code tomorrow when I will be at work.
>
>
> Thx,
> SImone.
>
> On 6/15/06, Brian Burkhalter wrote:
> > No code but from this
> >
> > https://jai.dev.java.net/servlets/ReadMsg?listName=interest&msgNo=1178
> >
> > you can see it's simple. Your images should already be index-color when passed
> > to the GIF writer. The only complication would be I think if you were passing
> > in metadata.
> >
> > Brian
> >
> > On Thu, 15 Jun 2006, Simone Giannecchini wrote:
> >
> > > I know we can write animated GIFs with Imageio since I remember some
> > > emails about this.
> > >
> > > Does anyone have some sample code for doing this task that I can reuse?
> >
> > ----------------
> > 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
> Software Engineer
> Freelance Consultant
>
> http://simboss.wordpress.com/
>
> °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
>

--
°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
Simone Giannecchini
Software Engineer
Freelance Consultant

http://simboss.wordpress.com/

°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°

---------------------------------------------------------------------
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

Simone,

> I solved all the issues, I am able to set both the delay for each
> frame as well as the loop count. I took me a while to figure out how
> to do it but it was not that difficult. I might write a small paper to
> describe the process.

That would be appreciated. I had started a response for this yesterday and
here is the draft:

"You can specify anything that appears in the stream or image metadata as
described here:

http://java.sun.com/j2se/1.5.0/docs/api/javax/imageio/metadata/doc-files/gif_me$

For example, you can set the delay via the delayTime attribute of the
GraphicControlExtension element of the image metadata."

I think the loops are set by some Netscape application extension, is that
correct?

> This email is for side isue I ran into at the end of this process.
> To encode the images I am going through JAI using the following code
>
> in case both branches conditions are false, like in my case, image is
> uninitialized therefore I got the null pointer exception.
>
> Solving this issue shold be pretty easy, but I have not time right now
> to do it myself.
>
> Could you subit a bug report for this. I hope to see this bug fixed
> soon because I susually use the daily build for ImageIO and this buf
> is preventing me from using the ImageWrite operator for wiriting
> sequence of image since the same things happens for multipage tiff
> files.

I didn't analyze your description but it sounds tractable. I would appreciate
it if you would file an issue yourself preferably with a test case attached.

Thanks,

Brian

----------------
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

Ciao Brian, hi all,
I fixed the bug myself on the cvs head, should I send here a patch?

SImone

On 6/16/06, Brian Burkhalter wrote:
> Simone,
>
> > I solved all the issues, I am able to set both the delay for each
> > frame as well as the loop count. I took me a while to figure out how
> > to do it but it was not that difficult. I might write a small paper to
> > describe the process.
>
> That would be appreciated. I had started a response for this yesterday and
> here is the draft:
>
> "You can specify anything that appears in the stream or image metadata as
> described here:
>
> http://java.sun.com/j2se/1.5.0/docs/api/javax/imageio/metadata/doc-files/gif_me$
>
> For example, you can set the delay via the delayTime attribute of the
> GraphicControlExtension element of the image metadata."
>
> I think the loops are set by some Netscape application extension, is that
> correct?
>
> > This email is for side isue I ran into at the end of this process.
> > To encode the images I am going through JAI using the following code
> >
> > in case both branches conditions are false, like in my case, image is
> > uninitialized therefore I got the null pointer exception.
> >
> > Solving this issue shold be pretty easy, but I have not time right now
> > to do it myself.
> >
> > Could you subit a bug report for this. I hope to see this bug fixed
> > soon because I susually use the daily build for ImageIO and this buf
> > is preventing me from using the ImageWrite operator for wiriting
> > sequence of image since the same things happens for multipage tiff
> > files.
>
> I didn't analyze your description but it sounds tractable. I would appreciate
> it if you would file an issue yourself preferably with a test case attached.
>
> Thanks,
>
> Brian
>
> ----------------
> 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
Software Engineer
Freelance Consultant

http://simboss.wordpress.com/

°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°

---------------------------------------------------------------------
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

Simone,

> I fixed the bug myself on the cvs head,

Great!

> should I send here a patch?

Unfortunately we can't accept it for jai-imageio unless we have a Joint
Copyright Assignment on file. Please see here

https://jai-imageio.dev.java.net/contribute.html

for more information. If you have a scanner or fax machine it takes about 5
minutes to submit.

As for submission, the ideal thing is to file an issue with type PATCH and
attach the patch to the issue. The formalities of issue filing and patch
submission are reviewed here:

https://jai-imageio.dev.java.net/#Reporting_Issues
https://jai-imageio.dev.java.net/patches.html

Thanks,

Brian

----------------
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

Hi Brian,
I sent the fax, is there a way to have a feedback about it being
receive or not?

Thx,
SImone.

On 6/20/06, Brian Burkhalter wrote:
> Simone,
>
> > I fixed the bug myself on the cvs head,
>
> Great!
>
> > should I send here a patch?
>
> Unfortunately we can't accept it for jai-imageio unless we have a Joint
> Copyright Assignment on file. Please see here
>
> https://jai-imageio.dev.java.net/contribute.html
>
> for more information. If you have a scanner or fax machine it takes about 5
> minutes to submit.
>
> As for submission, the ideal thing is to file an issue with type PATCH and
> attach the patch to the issue. The formalities of issue filing and patch
> submission are reviewed here:
>
> https://jai-imageio.dev.java.net/#Reporting_Issues
> https://jai-imageio.dev.java.net/patches.html
>
> Thanks,
>
> Brian
>
> ----------------
> 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
Software Engineer
Freelance Consultant

http://simboss.wordpress.com/

°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°

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