Bug 52078 - Slide.draw throws java.lang.OutOfMemoryError in some slides with grouped shapes
Summary: Slide.draw throws java.lang.OutOfMemoryError in some slides with grouped shapes
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSLF (show other bugs)
Version: 3.8-dev
Hardware: PC All
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-24 20:50 UTC by Saulo Brito
Modified: 2012-11-16 12:08 UTC (History)
0 users



Attachments
PPT with a slide with shapes grouped (199.00 KB, application/vnd.ms-powerpoint)
2011-10-24 20:50 UTC, Saulo Brito
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Saulo Brito 2011-10-24 20:50:50 UTC
Created attachment 27840 [details]
PPT with a slide with shapes grouped

Slide.draw throws java.lang.OutOfMemoryError in some slides with grouped shapes. 

How to reproduce:

- Download the attached PPT (TesteAgrupado.ppt)
- Run org.apache.poi.hslf.examples.PPT2PNG TesteAgrupado.ppt

If you open the PPT, ungroup the shapes within the first slide and run the PPT2PNG again, no error will occur!

I´ve already tried to increase the heap memory size but got the same error.

The output and stack trace:

Rendering slide 1
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
        at java.awt.image.DataBufferInt.<init>(Unknown Source)
        at java.awt.image.Raster.createPackedRaster(Unknown Source)
        at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknow
n Source)
        at sun.awt.image.ImageRepresentation.createBufferedImage(Unknown Source)

        at sun.awt.image.ImageRepresentation.setPixels(Unknown Source)
        at java.awt.image.AreaAveragingScaleFilter.accumPixels(Unknown Source)
        at java.awt.image.AreaAveragingScaleFilter.setPixels(Unknown Source)
        at sun.awt.image.OffScreenImageSource.sendPixels(Unknown Source)
        at sun.awt.image.OffScreenImageSource.produce(Unknown Source)
        at sun.awt.image.OffScreenImageSource.addConsumer(Unknown Source)
        at sun.awt.image.OffScreenImageSource.startProduction(Unknown Source)
        at java.awt.image.FilteredImageSource.startProduction(Unknown Source)
        at sun.awt.image.ImageRepresentation.startProduction(Unknown Source)
        at sun.awt.image.ImageRepresentation.drawToBufImage(Unknown Source)
        at sun.java2d.pipe.DrawImage.copyImage(Unknown Source)
        at sun.java2d.SunGraphics2D.drawImage(Unknown Source)
        at sun.java2d.SunGraphics2D.drawImage(Unknown Source)
        at org.apache.poi.hslf.blip.BitmapPainter.paint(BitmapPainter.java:65)
        at org.apache.poi.hslf.usermodel.PictureData.draw(PictureData.java:230)
        at org.apache.poi.hslf.model.Picture.draw(Picture.java:268)
        at org.apache.poi.hslf.model.ShapeGroup.draw(ShapeGroup.java:289)
        at org.apache.poi.hslf.model.Slide.draw(Slide.java:433)
        at org.apache.poi.hslf.examples.PPT2PNG.main(PPT2PNG.java:95)
Comment 1 Yegor Kozlov 2012-02-25 09:40:38 UTC
Should be fixed in r1293561

Yegor
Comment 2 Mariano 2012-11-09 15:47:20 UTC
Why Status is RESOLVED? I didn't find the solution!
Please, can show me?

Thanks
Comment 3 Yegor Kozlov 2012-11-09 16:44:39 UTC
Did you try the latest build from trunk? Does it still throw OutOfMemory for the attached file?

(In reply to comment #2)
> Why Status is RESOLVED? I didn't find the solution!
> Please, can show me?
> 
> Thanks
Comment 4 Mariano 2012-11-13 13:42:47 UTC
OK, i saw it, but i don't understand how can I get the Picture object(parent) in BitmapPainter.paint(Graphics2D graphics, PictureData pict, Picture parent) method?
I put my method that returns a list of strings(the BufferedImage converted in base64) --> one string for one slide

/***************************************************/
private List<String> obtainSlidesFromPPT(InputStream is) {
	SlideShow ppt = null;
	List<String> returnList = new LinkedList<String>();
	try {
		ppt = new SlideShow(is);
		is.close();
		Dimension pgsize = ppt.getPageSize();
		PictureData [] pd = ppt.getPictureData();
		int nSlides = pd.length;
		for (int i = 0; i < nSlides; i++) {
			PictureData pict = pd[i];
			BufferedImage img = ImageIO.read(new ByteArrayInputStream(pict.getData()));
			Graphics2D graphics = img.createGraphics();
			//Rectangle anchor = parent.getLogicalAnchor2D().getBounds();
			 graphics.drawImage(img, anchor.x, anchor.y, anchor.width, anchor.height, null);
			graphics.dispose();				returnList.add(covertBufferedImageInBase64String(img));		
			}
		} catch (IOException ioe) {
			System.err.println(ioe.getMessage());
		}
		return returnList;
	}
/***************************************************/


(In reply to comment #3)
> Did you try the latest build from trunk? Does it still throw OutOfMemory for
> the attached file?
> 
> (In reply to comment #2)
> > Why Status is RESOLVED? I didn't find the solution!
> > Please, can show me?
> > 
> > Thanks
Comment 5 Yegor Kozlov 2012-11-16 12:08:49 UTC
To get Picture objects from a slide you need to iterate over the shapes and check if a shape is an instance of Picture, see example at http://poi.apache.org/slideshow/how-to-shapes.html#Pictures


(In reply to comment #4)
> OK, i saw it, but i don't understand how can I get the Picture
> object(parent) in BitmapPainter.paint(Graphics2D graphics, PictureData pict,
> Picture parent) method?
> I put my method that returns a list of strings(the BufferedImage converted
> in base64) --> one string for one slide
> 
> /***************************************************/
> private List<String> obtainSlidesFromPPT(InputStream is) {
> 	SlideShow ppt = null;
> 	List<String> returnList = new LinkedList<String>();
> 	try {
> 		ppt = new SlideShow(is);
> 		is.close();
> 		Dimension pgsize = ppt.getPageSize();
> 		PictureData [] pd = ppt.getPictureData();
> 		int nSlides = pd.length;
> 		for (int i = 0; i < nSlides; i++) {
> 			PictureData pict = pd[i];
> 			BufferedImage img = ImageIO.read(new
> ByteArrayInputStream(pict.getData()));
> 			Graphics2D graphics = img.createGraphics();
> 			//Rectangle anchor = parent.getLogicalAnchor2D().getBounds();
> 			 graphics.drawImage(img, anchor.x, anchor.y, anchor.width, anchor.height,
> null);
> 			graphics.dispose();			
> returnList.add(covertBufferedImageInBase64String(img));		
> 			}
> 		} catch (IOException ioe) {
> 			System.err.println(ioe.getMessage());
> 		}
> 		return returnList;
> 	}
> /***************************************************/
> 
> 
> (In reply to comment #3)
> > Did you try the latest build from trunk? Does it still throw OutOfMemory for
> > the attached file?
> > 
> > (In reply to comment #2)
> > > Why Status is RESOLVED? I didn't find the solution!
> > > Please, can show me?
> > > 
> > > Thanks