Runtime error when parsing ppt that has png image embedded into it

Trying out the java slides API. Wow this is great stuff!



One piece of missing functionality I’ve identified: the libary doesn’t
seem to support embedded .PNG files. When I run my code:



1 FileInputStream fis = new FileInputStream(“C:\ppt\foo.ppt”);

2 Presentation p = new Presentation(fis);

3 Slide firstSlide = p.getSlides().get(0);

4 BufferedImage bi=firstSlide.getThumbnail(1,1);

5 File file = new File(“C:\ppt\firstslide.jpg”);

6 ImageIO.write(bi, “jpg”, file);



When I run this code in debug mode, it generates a thumbnail (without
the PNG). I assume this means that PNG embedding is not supported yet
by the Slides API. OK, I think to myself, I can live with that for
now…



However, when I run the same code (as opposed to debugging it), I get
the following exception on line 2 (where the Presentation object is
constructed). What’s this about? Anyone know how to troubleshoot?



Stack trace is included below, PPT that caused the error included as an attachement.



Error: One factory fails for the operation “png”

Occurs in: javax.media.jai.ThreadSafeOperationRegistry

java.lang.reflect.InvocationTargetException

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:585)

at javax.media.jai.FactoryCache.invoke(FactoryCache.java:130)

at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1682)

at
javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:481)

at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:340)

at com.sun.media.jai.opimage.StreamRIF.create(StreamRIF.java:110)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:585)

at javax.media.jai.FactoryCache.invoke(FactoryCache.java:130)

at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1682)

at
javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:481)

at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:340)

at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:830)

at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:878)

at javax.media.jai.RenderedOp.getWidth(RenderedOp.java:2190)

at com.aspose.slides.PPImage.(SourceFile:42)

at com.aspose.slides.Picture.(SourceFile:15)

at com.aspose.slides.Presentation.do(SourceFile:186)

at com.aspose.slides.Presentation.(SourceFile:407)

at slideshare.extractor.PPTExtractor.main(PPTExtractor.java:31)

Caused by: com.sun.media.jai.codecimpl.util.ImagingException

at
com.sun.media.jai.codecimpl.ImagingListenerProxy.errorOccurred(ImagingListenerProxy.java:71)

at com.sun.media.jai.codecimpl.PNGImage.(PNGImageDecoder.java:504)

at
com.sun.media.jai.codecimpl.PNGImageDecoder.decodeAsRenderedImage(PNGImageDecoder.java:81)

at com.sun.media.jai.opimage.CodecRIFUtil.create(CodecRIFUtil.java:96)

at com.sun.media.jai.opimage.PNGRIF.create(PNGRIF.java:56)

… 25 more

Caused by: com.sun.media.jai.codecimpl.util.ImagingException: I/O error reading PNG file.

… 29 more

Caused by: java.lang.ArrayIndexOutOfBoundsException: 128

at com.sun.media.jai.codecimpl.PNGImage.parse_bKGD_chunk(PNGImageDecoder.java:951)

at com.sun.media.jai.codecimpl.PNGImage.(PNGImageDecoder.java:454)

… 28 more

Error: One factory fails for the operation “stream”

Occurs in: javax.media.jai.ThreadSafeOperationRegistry

java.lang.reflect.InvocationTargetException

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:585)

at javax.media.jai.FactoryCache.invoke(FactoryCache.java:130)

at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1682)

at
javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:481)

at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:340)

at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:830)

at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:878)

at javax.media.jai.RenderedOp.getWidth(RenderedOp.java:2190)

at com.aspose.slides.PPImage.(SourceFile:42)

at com.aspose.slides.Picture.(SourceFile:15)

at com.aspose.slides.Presentation.do(SourceFile:186)

at com.aspose.slides.Presentation.(SourceFile:407)

at slideshare.extractor.PPTExtractor.main(PPTExtractor.java:31)

Caused by: javax.media.jai.util.ImagingException: All factories fail for the operation “png”

at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1695)

at
javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:481)

at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:340)

at com.sun.media.jai.opimage.StreamRIF.create(StreamRIF.java:110)

… 16 more

Caused by: java.lang.reflect.InvocationTargetException

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:585)

at javax.media.jai.FactoryCache.invoke(FactoryCache.java:130)

at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1682)

… 19 more

Caused by: com.sun.media.jai.codecimpl.util.ImagingException

at
com.sun.media.jai.codecimpl.ImagingListenerProxy.errorOccurred(ImagingListenerProxy.java:71)

at com.sun.media.jai.codecimpl.PNGImage.(PNGImageDecoder.java:504)

at
com.sun.media.jai.codecimpl.PNGImageDecoder.decodeAsRenderedImage(PNGImageDecoder.java:81)

2

3

4

5

6

at com.sun.media.jai.opimage.CodecRIFUtil.create(CodecRIFUtil.java:96)

at com.sun.media.jai.opimage.PNGRIF.create(PNGRIF.java:56)

… 25 more

Caused by: com.sun.media.jai.codecimpl.util.ImagingException: I/O error reading PNG file.

… 29 more

Caused by: java.lang.ArrayIndexOutOfBoundsException: 128

at com.sun.media.jai.codecimpl.PNGImage.parse_bKGD_chunk(PNGImageDecoder.java:951)

at com.sun.media.jai.codecimpl.PNGImage.(PNGImageDecoder.java:454)

… 28 more

Please attach ppt file or send it by email to tyumen @ aspose . com
Really this exception is thrown inside JAI library. Sometimes it can’t open png files.

Here’s the ppt file (I attached it b4, not sure why it’s not going through).



If it doesn’t attach this time I will email it to you. Thanks!.

Trying with IE to see if file upload is broken in Firefox…

Looks like that was the problem. File is uploaded.

That is bug in Sun’s JAI library. It can’t read bKGD chunk in png files with color palette.
I have made small patch for cvs version of JAI. I’m not sure if it’s absolutely correct way
to fix it but it works on several test png files. So you can try to use it. Check attached patch.

Alexy,

I'm downloading cvs of jai-core now, will test with your patch very soon.

Out of curiousity: what OS do you test on? I notice all the jai src is OS specific ... so it's entirely possible this PNG bug only manifests on Windows (which would make it a non-issue, since no one deploys java web apps on windows anyway).

Regards!

-J

jai has pure java part and optional native codecs.
I don’t use (simply didn’t install) this optional part at all.
So my tests should work on any OS. Yes, I tested it on Windows.

Alexey:

Is this patch still available? I am running into the same issue using the latest Aspose component and JAI library (1.1.2_01). When I try and download the referenced patch from your message, I get a 404.

Thanks,

Tom Murphy

Dear Tom,

I have created article in the Wiki. Please check this page:
http://www.aspose.com/Wiki/default.aspx/Aspose.Slides/ErrorOneFactoryFailsForTheOperationPng.html

Alexey:

Thanks for directing me to the right place. Is there a patched version of the JAR file available? I am pulling down the cvs source but I thought it couldn't hurt to ask.

Thanks again,

Tom Murphy

I have updated wiki page so jar files now available.

Alekey:

Grabbed the files and used them in conjunction with the latest slides patch and the problems seem to be resolved. I have turned our application over to our QA department but things look good to go.

Thanks for all the help.

Tom Murphy