Bug 65523 - XSLFSheet.importBlip throws ClassCastException when importing a slide
Summary: XSLFSheet.importBlip throws ClassCastException when importing a slide
Status: NEW
Alias: None
Product: POI
Classification: Unclassified
Component: XSLF (show other bugs)
Version: 5.0.0-FINAL
Hardware: PC All
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-08-27 09:58 UTC by sabine.haas
Modified: 2021-08-27 17:47 UTC (History)
0 users



Attachments
PowerPoint with slide, which has a uncopiable picture (49.11 KB, application/vnd.openxmlformats-officedocument.presentationml.presentation)
2021-08-27 09:58 UTC, sabine.haas
Details

Note You need to log in before you can comment on or make changes to this bug.
Description sabine.haas 2021-08-27 09:58:32 UTC
Created attachment 37995 [details]
PowerPoint with slide, which has a uncopiable picture

Any slide import for pictures fails, if the user edited the picture color using Powerpoint.

In our case the slide contained a colored picture, which was edited to show as grey (Picture Color -> Color Saturation -> 0%)

An sample presentation and code will be uploaded with this ticket.

----------------------------------------------------------------------------
Test code:
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;
import org.springframework.core.io.ClassPathResource;

import java.io.ByteArrayOutputStream;

class Scratch {
    public static void main(String[] args) throws Exception {
        XMLSlideShow targetPresentation = new XMLSlideShow();
        XSLFSlide targetPresentationSlide = targetPresentation.createSlide();

        XMLSlideShow sourcePresentation = new XMLSlideShow(new ClassPathResource("POI_Blip_bug.pptx").getInputStream());
        XSLFSlide sourceSlide = sourcePresentation.getSlides().get(0);

        targetPresentationSlide.getSlideMaster().importContent(sourceSlide.getSlideMaster());
        targetPresentationSlide.getSlideLayout().importContent(sourceSlide.getSlideLayout());

        targetPresentationSlide.importContent(sourceSlide);

        targetPresentation.write(new ByteArrayOutputStream());
    }
}


--------------------------------------------------------------------------------
Exception in thread "main" java.lang.ClassCastException: class org.apache.poi.ooxml.POIXMLDocumentPart cannot be cast to class org.apache.poi.xslf.usermodel.XSLFPictureData (org.apache.poi.ooxml.POIXMLDocumentPart and org.apache.poi.xslf.usermodel.XSLFPictureData are in unnamed module of loader 'app')
	at org.apache.poi.xslf.usermodel.XSLFSheet.importBlip(XSLFSheet.java:651)
	at org.apache.poi.xslf.usermodel.XSLFPictureShape.copy(XSLFPictureShape.java:385)
	at org.apache.poi.xslf.usermodel.XSLFSheet.wipeAndReinitialize(XSLFSheet.java:455)
	at org.apache.poi.xslf.usermodel.XSLFSheet.importContent(XSLFSheet.java:434)
	at org.apache.poi.xslf.usermodel.XSLFSlide.importContent(XSLFSlide.java:293)
Comment 1 PJ Fanning 2021-08-27 16:52:22 UTC
I had a quick look and there appear to be 2 images - 1 is ok and the other is not (rId2 is ok, rId3 is not)

the first one is a jpeg, the second one is this 

Name: /ppt/media/hdphoto1.wdp - Content Type: image/vnd.ms-photo

I suspect that POI does not support this file format.
Comment 2 PJ Fanning 2021-08-27 17:11:41 UTC
XSLFRelation _table has mappings for relation types - it does not support this one: http://schemas.microsoft.com/office/2007/relationships/hdphoto
Comment 3 PJ Fanning 2021-08-27 17:35:27 UTC
I added basic support for hdphoto images - r1892653 - I don't know a great deal about the XLSF code base so I'm happy for other devs to review this change and to revert it if it is the wrong approach.
Comment 4 PJ Fanning 2021-08-27 17:47:09 UTC
Possibly, next set of problem with wdp images is getting the dimensions - we have custom classes in https://github.com/apache/poi/tree/trunk/poi/src/main/java/org/apache/poi/sl/image -- the one that is used by default is the bitmap map but it looks like it will default the dimensions if the image data is not parseable.