[Libreoffice-commits] core.git: vcl/qa vcl/source
Luboš Luňák (via logerrit)
logerrit at kemper.freedesktop.org
Mon Mar 25 12:47:19 UTC 2019
vcl/qa/cppunit/pdfexport/data/tdf121615.odt |binary
vcl/qa/cppunit/pdfexport/pdfexport.cxx | 58 ++++++++++++++++++++++++++++
vcl/source/filter/jpeg/JpegWriter.cxx | 5 +-
3 files changed, 62 insertions(+), 1 deletion(-)
New commits:
commit 4b48f5c2fd2d0d6de1e1df4c13ceba47b1da7b5e
Author: Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Wed Mar 13 17:35:27 2019 +0100
Commit: Luboš Luňák <l.lunak at collabora.com>
CommitDate: Mon Mar 25 13:46:57 2019 +0100
fix grayscale jpeg writing in pdfexport (tdf#121615)
If the bitmap to be written is non-8bit, e.g. in case of using OpenGL
(on Linux the test requires "SAL_FORCEGL=1 SAL_USE_VCLPLUGIN=gen",
on Windows it's probably the default case), then the bitmap is not
in native format for 8bit. This was done correctly by 45e8e0fbee40f
that introduced it but somehow it got lost later (I can't even find
where).
Change-Id: Ib1810cb9cf12e373c1cb41da40fa28e96ad7db28
Reviewed-on: https://gerrit.libreoffice.org/69213
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak at collabora.com>
diff --git a/vcl/qa/cppunit/pdfexport/data/tdf121615.odt b/vcl/qa/cppunit/pdfexport/data/tdf121615.odt
new file mode 100644
index 000000000000..7d2a87cf0e40
Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/tdf121615.odt differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 98e4c20a33b3..b950cefbf1cf 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -30,9 +30,19 @@
#include <fpdf_edit.h>
#include <fpdf_text.h>
#include <fpdfview.h>
+#include <vcl/graphicfilter.hxx>
using namespace ::com::sun::star;
+static std::ostream& operator<<(std::ostream& rStrm, const Color& rColor)
+{
+ rStrm << "Color: R:" << static_cast<int>(rColor.GetRed())
+ << " G:" << static_cast<int>(rColor.GetGreen())
+ << " B:" << static_cast<int>(rColor.GetBlue())
+ << " A:" << static_cast<int>(rColor.GetTransparency());
+ return rStrm;
+}
+
namespace
{
@@ -118,6 +128,7 @@ public:
void testTdf113143();
void testTdf115262();
void testTdf121962();
+ void testTdf121615();
CPPUNIT_TEST_SUITE(PdfExportTest);
CPPUNIT_TEST(testTdf106059);
@@ -152,6 +163,7 @@ public:
CPPUNIT_TEST(testTdf113143);
CPPUNIT_TEST(testTdf115262);
CPPUNIT_TEST(testTdf121962);
+ CPPUNIT_TEST(testTdf121615);
CPPUNIT_TEST_SUITE_END();
};
@@ -1672,6 +1684,52 @@ void PdfExportTest::testTdf121962()
}
}
+void PdfExportTest::testTdf121615()
+{
+ vcl::filter::PDFDocument aDocument;
+ load("tdf121615.odt", aDocument);
+
+ // The document has one page.
+ std::vector<vcl::filter::PDFObjectElement*> aPages = aDocument.GetPages();
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aPages.size());
+
+ // Get access to the only image on the only page.
+ vcl::filter::PDFObjectElement* pResources = aPages[0]->LookupObject("Resources");
+ CPPUNIT_ASSERT(pResources);
+ auto pXObjects = dynamic_cast<vcl::filter::PDFDictionaryElement*>(pResources->Lookup("XObject"));
+ CPPUNIT_ASSERT(pXObjects);
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pXObjects->GetItems().size());
+ vcl::filter::PDFObjectElement* pXObject = pXObjects->LookupObject(pXObjects->GetItems().begin()->first);
+ CPPUNIT_ASSERT(pXObject);
+ vcl::filter::PDFStreamElement* pStream = pXObject->GetStream();
+ CPPUNIT_ASSERT(pStream);
+ SvMemoryStream& rObjectStream = pStream->GetMemory();
+
+ // Load the embedded image.
+ rObjectStream.Seek( 0 );
+ GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
+ Graphic aGraphic;
+ sal_uInt16 format;
+ ErrCode bResult = rFilter.ImportGraphic(aGraphic, OUString( "import" ), rObjectStream,
+ GRFILTER_FORMAT_DONTKNOW, &format);
+ CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, bResult);
+
+ // The image should be grayscale 8bit JPEG.
+ sal_uInt16 jpegFormat = rFilter.GetImportFormatNumberForShortName( JPG_SHORTNAME );
+ CPPUNIT_ASSERT( jpegFormat != GRFILTER_FORMAT_NOTFOUND );
+ CPPUNIT_ASSERT_EQUAL( jpegFormat, format );
+ BitmapEx aBitmap = aGraphic.GetBitmapEx();
+ CPPUNIT_ASSERT_EQUAL( 200L, aBitmap.GetSizePixel().Width());
+ CPPUNIT_ASSERT_EQUAL( 300L, aBitmap.GetSizePixel().Height());
+ CPPUNIT_ASSERT_EQUAL( 8, int(aBitmap.GetBitCount()));
+ // tdf#121615 was caused by broken handling of data width with 8bit color,
+ // so the test image has some black in the bottomright corner, check it's there
+ CPPUNIT_ASSERT_EQUAL( COL_WHITE, aBitmap.GetPixelColor( 0, 0 ));
+ CPPUNIT_ASSERT_EQUAL( COL_WHITE, aBitmap.GetPixelColor( 0, 299 ));
+ CPPUNIT_ASSERT_EQUAL( COL_WHITE, aBitmap.GetPixelColor( 199, 0 ));
+ CPPUNIT_ASSERT_EQUAL( COL_BLACK, aBitmap.GetPixelColor( 199, 299 ));
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(PdfExportTest);
}
diff --git a/vcl/source/filter/jpeg/JpegWriter.cxx b/vcl/source/filter/jpeg/JpegWriter.cxx
index ac01d6f18aa1..407e2423b64a 100644
--- a/vcl/source/filter/jpeg/JpegWriter.cxx
+++ b/vcl/source/filter/jpeg/JpegWriter.cxx
@@ -230,7 +230,10 @@ bool JPEGWriter::Write( const Graphic& rGraphic )
if( mpExpWasGrey )
*mpExpWasGrey = mbGreys;
- mbNative = ( mpReadAccess->GetScanlineFormat() == ScanlineFormat::N24BitTcRgb );
+ if ( mbGreys )
+ mbNative = ( mpReadAccess->GetScanlineFormat() == ScanlineFormat::N8BitPal );
+ else
+ mbNative = ( mpReadAccess->GetScanlineFormat() == ScanlineFormat::N24BitTcRgb );
if( !mbNative )
mpBuffer = new sal_uInt8[ AlignedWidth4Bytes( mbGreys ? mpReadAccess->Width() * 8L : mpReadAccess->Width() * 24L ) ];
More information about the Libreoffice-commits
mailing list