tdf#76941 and tdf#87539: docx export image greyscale, watermark, black&white

Thanks to Miklos :)

Change-Id: Ib6344ff654e39bf712d7071545573fb2ec525b63
Reviewed-on: https://gerrit.libreoffice.org/15733
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Joren De Cuyper <jorendc@libreoffice.org>
diff --git a/sw/qa/extras/ooxmlexport/data/picture_colormode_black_white.odt b/sw/qa/extras/ooxmlexport/data/picture_colormode_black_white.odt
new file mode 100644
index 0000000..b2166bd
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/picture_colormode_black_white.odt
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/data/picture_colormode_grayscale.docx b/sw/qa/extras/ooxmlexport/data/picture_colormode_grayscale.docx
new file mode 100644
index 0000000..2bc6458
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/picture_colormode_grayscale.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/data/picture_colormode_watermark.odt b/sw/qa/extras/ooxmlexport/data/picture_colormode_watermark.odt
new file mode 100644
index 0000000..70dd5e9
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/picture_colormode_watermark.odt
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport7.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport7.cxx
index 6dec1e1..03afe28 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport7.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport7.cxx
@@ -948,6 +948,36 @@ DECLARE_OOXMLEXPORT_TEST(testPictureWrapPolygon, "picture-wrap-polygon.docx")
    CPPUNIT_ASSERT_EQUAL(sal_Int32(11), aSeq.getLength());
}

DECLARE_OOXMLEXPORT_TEST(testPictureColormodeGrayscale, "picture_colormode_grayscale.docx")
{
    // THe problem was that the grayscale was not exported
    xmlDocPtr pXmlDoc = parseExport ("word/document.xml");
    if (!pXmlDoc)
        return;

    assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/w:drawing/wp:inline/a:graphic/a:graphicData/pic:pic/pic:blipFill/a:blip/a:grayscl", 1);
}

DECLARE_OOXMLEXPORT_TEST(testPictureColormodeBlackWhite, "picture_colormode_black_white.odt")
{
    xmlDocPtr pXmlDoc = parseExport ("word/document.xml");
    if (!pXmlDoc)
        return;

    assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/w:drawing/wp:anchor/a:graphic/a:graphicData/pic:pic/pic:blipFill/a:blip/a:biLevel", "thresh", "50000");
}

DECLARE_OOXMLEXPORT_TEST(testPictureColormodeWatermark, "picture_colormode_watermark.odt")
{
    xmlDocPtr pXmlDoc = parseExport ("word/document.xml");
    if (!pXmlDoc)
        return;

    assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/w:drawing/wp:anchor/a:graphic/a:graphicData/pic:pic/pic:blipFill/a:blip/a:lum", "bright", "50000");
    assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/w:drawing/wp:anchor/a:graphic/a:graphicData/pic:pic/pic:blipFill/a:blip/a:lum", "contrast", "-70000");
}


DECLARE_OOXMLEXPORT_TEST(testExportShadow, "bnc637947.odt")
{
    // The problem was that shadows of shapes from non-OOXML origin were not exported to DrawingML
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index dcce02f..59027ee 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -4192,13 +4192,28 @@ void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size
   completely discarding it.
*/
    if ( aRelId.isEmpty() )
        m_pSerializer->singleElementNS( XML_a, XML_blip,
        m_pSerializer->startElementNS( XML_a, XML_blip,
            FSEND );
    else
        m_pSerializer->singleElementNS( XML_a, XML_blip,
        m_pSerializer->startElementNS( XML_a, XML_blip,
            FSNS( XML_r, nImageType ), aRelId.getStr(),
            FSEND );

    pItem = 0;
    sal_uInt32 nMode = GRAPHICDRAWMODE_STANDARD;

    if ( pGrfNode && SfxItemState::SET == pGrfNode->GetSwAttrSet().GetItemState(RES_GRFATR_DRAWMODE, true, &pItem))
    {
        nMode = static_cast<const SfxEnumItem*>(pItem)->GetValue();
        if (nMode == GRAPHICDRAWMODE_GREYS)
            m_pSerializer->singleElementNS (XML_a, XML_grayscl, FSEND);
        else if (nMode == GRAPHICDRAWMODE_MONO) //black/white has a 0,5 threshold in LibreOffice
            m_pSerializer->singleElementNS (XML_a, XML_biLevel, XML_thresh, OString::number(50000), FSEND);
        else if (nMode == GRAPHICDRAWMODE_WATERMARK) //watermark has a brightness/luminance of 0,5 and contrast of -0.7 in LibreOffice
            m_pSerializer->singleElementNS( XML_a, XML_lum, XML_bright, OString::number(50000), XML_contrast, OString::number(-70000), FSEND );
    }
    m_pSerializer->endElementNS( XML_a, XML_blip );

    if (pSdrObj){
        WriteSrcRect(pSdrObj);
    }