qt4/src/poppler-page.cc | 112 +++++++++++++++++++++++++++++------------------- qt4/src/poppler-qt4.h | 5 +- qt5/src/poppler-page.cc | 112 +++++++++++++++++++++++++++++------------------- qt5/src/poppler-qt5.h | 5 +- splash/SplashBitmap.cc | 28 +++++++++--- splash/SplashBitmap.h | 5 +- 6 files changed, 168 insertions(+), 99 deletions(-)
New commits: commit 334dc56f2f9adf4daa33c20ce034a5b1f8259baf Author: Albert Astals Cid <[email protected]> Date: Sun Jul 12 23:29:30 2015 +0200 [qt] KeepAlphaChannel -> IgnorePaperColor diff --git a/qt4/src/poppler-page.cc b/qt4/src/poppler-page.cc index c99048f..979b9ef 100644 --- a/qt4/src/poppler-page.cc +++ b/qt4/src/poppler-page.cc @@ -329,8 +329,8 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h, SplashColorMode colorMode = splashModeRGB8; - const bool keepAlphaChannel = m_page->parentDoc->m_hints & Document::KeepAlphaChannel; - if (keepAlphaChannel) colorMode = splashModeXBGR8; + const bool ignorePaperColor = m_page->parentDoc->m_hints & Document::IgnorePaperColor; + if (ignorePaperColor) colorMode = splashModeXBGR8; #if defined(SPLASH_CMYK) if (overprintPreview) colorMode = splashModeDeviceN8; @@ -343,7 +343,7 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h, SplashOutputDev splash_output( colorMode, 4, gFalse, - keepAlphaChannel ? NULL : bgColor, + ignorePaperColor ? NULL : bgColor, gTrue, thinLineMode, overprintPreview); @@ -367,8 +367,8 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h, // If we use DeviceN8, convert to XBGR8. // If requested, also transfer Splash's internal alpha channel. - if (overprintPreview || keepAlphaChannel) { - if (bitmap->convertToXBGR(keepAlphaChannel)) { + if (overprintPreview || ignorePaperColor) { + if (bitmap->convertToXBGR(ignorePaperColor)) { SplashColorPtr data = bitmap->getDataPtr(); if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { @@ -386,8 +386,7 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h, // Construct a Qt image sharing the raw bitmap data. img = QImage(data, bw, bh, brs, QImage::Format_ARGB32).copy(); } - } - else { + } else { SplashColorPtr data = bitmap->getDataPtr(); if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { diff --git a/qt4/src/poppler-qt4.h b/qt4/src/poppler-qt4.h index 768a438..c0340a4 100644 --- a/qt4/src/poppler-qt4.h +++ b/qt4/src/poppler-qt4.h @@ -1,7 +1,7 @@ /* poppler-qt.h: qt interface to poppler * Copyright (C) 2005, Net Integration Technologies, Inc. * Copyright (C) 2005, 2007, Brad Hards <[email protected]> - * Copyright (C) 2005-2012, 2014, Albert Astals Cid <[email protected]> + * Copyright (C) 2005-2012, 2014, 2015, Albert Astals Cid <[email protected]> * Copyright (C) 2005, Stefan Kebekus <[email protected]> * Copyright (C) 2006-2011, Pino Toscano <[email protected]> * Copyright (C) 2009 Shawn Rutledge <[email protected]> @@ -902,7 +902,7 @@ delete it; OverprintPreview = 0x00000010, ///< Overprint preview \since 0.22 ThinLineSolid = 0x00000020, ///< Enhance thin lines solid \since 0.24 ThinLineShape = 0x00000040, ///< Enhance thin lines shape. Wins over ThinLineSolid \since 0.24 - KeepAlphaChannel = 0x00000080 ///< Do not compose with the paper color \since 0.34 + IgnorePaperColor = 0x00000080 ///< Do not compose with the paper color \since 0.35 }; Q_DECLARE_FLAGS( RenderHints, RenderHint ) diff --git a/qt5/src/poppler-page.cc b/qt5/src/poppler-page.cc index 7ae3c71..2015329 100644 --- a/qt5/src/poppler-page.cc +++ b/qt5/src/poppler-page.cc @@ -329,8 +329,8 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h, SplashColorMode colorMode = splashModeRGB8; - const bool keepAlphaChannel = m_page->parentDoc->m_hints & Document::KeepAlphaChannel; - if (keepAlphaChannel) colorMode = splashModeXBGR8; + const bool ignorePaperColor = m_page->parentDoc->m_hints & Document::IgnorePaperColor; + if (ignorePaperColor) colorMode = splashModeXBGR8; #if defined(SPLASH_CMYK) if (overprintPreview) colorMode = splashModeDeviceN8; @@ -343,7 +343,7 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h, SplashOutputDev splash_output( colorMode, 4, gFalse, - keepAlphaChannel ? NULL : bgColor, + ignorePaperColor ? NULL : bgColor, gTrue, thinLineMode, overprintPreview); @@ -367,8 +367,8 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h, // If we use DeviceN8, convert to XBGR8. // If requested, also transfer Splash's internal alpha channel. - if (overprintPreview || keepAlphaChannel) { - if (bitmap->convertToXBGR(keepAlphaChannel)) { + if (overprintPreview || ignorePaperColor) { + if (bitmap->convertToXBGR(ignorePaperColor)) { SplashColorPtr data = bitmap->takeData(); if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { @@ -386,8 +386,7 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h, // Construct a Qt image holding (and also owning) the raw bitmap data. img = QImage(data, bw, bh, brs, QImage::Format_ARGB32, gfree, data); } - } - else { + } else { SplashColorPtr data = bitmap->takeData(); if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { diff --git a/qt5/src/poppler-qt5.h b/qt5/src/poppler-qt5.h index 7e6c6e4..b159477 100644 --- a/qt5/src/poppler-qt5.h +++ b/qt5/src/poppler-qt5.h @@ -1,7 +1,7 @@ /* poppler-qt.h: qt interface to poppler * Copyright (C) 2005, Net Integration Technologies, Inc. * Copyright (C) 2005, 2007, Brad Hards <[email protected]> - * Copyright (C) 2005-2014, Albert Astals Cid <[email protected]> + * Copyright (C) 2005-2015, Albert Astals Cid <[email protected]> * Copyright (C) 2005, Stefan Kebekus <[email protected]> * Copyright (C) 2006-2011, Pino Toscano <[email protected]> * Copyright (C) 2009 Shawn Rutledge <[email protected]> @@ -892,7 +892,7 @@ delete it; OverprintPreview = 0x00000010, ///< Overprint preview \since 0.22 ThinLineSolid = 0x00000020, ///< Enhance thin lines solid \since 0.24 ThinLineShape = 0x00000040, ///< Enhance thin lines shape. Wins over ThinLineSolid \since 0.24 - KeepAlphaChannel = 0x00000080 ///< Do not compose with the paper color \since 0.34 + IgnorePaperColor = 0x00000080 ///< Do not compose with the paper color \since 0.35 }; Q_DECLARE_FLAGS( RenderHints, RenderHint ) commit 2a1363a4a3129fe4b5e4fae1018dc8919a2d796a Author: Albert Astals Cid <[email protected]> Date: Sun Jul 12 23:22:32 2015 +0200 Update (C) diff --git a/splash/SplashBitmap.cc b/splash/SplashBitmap.cc index 7da373b..9830a9a 100644 --- a/splash/SplashBitmap.cc +++ b/splash/SplashBitmap.cc @@ -21,6 +21,7 @@ // Copyright (C) 2010 William Bader <[email protected]> // Copyright (C) 2011-2013 Thomas Freitag <[email protected]> // Copyright (C) 2012 Anthony Wesley <[email protected]> +// Copyright (C) 2015 Adam Reichold <[email protected]> // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git diff --git a/splash/SplashBitmap.h b/splash/SplashBitmap.h index 99879fb..9fa7613 100644 --- a/splash/SplashBitmap.h +++ b/splash/SplashBitmap.h @@ -20,6 +20,7 @@ // Copyright (C) 2010 Christian Feuersänger <[email protected]> // Copyright (C) 2010 William Bader <[email protected]> // Copyright (C) 2012 Thomas Freitag <[email protected]> +// Copyright (C) 2015 Adam Reichold <[email protected]> // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git commit e903b2364f55c4f6417d826ab85dcb60cd240563 Author: Albert Astals Cid <[email protected]> Date: Sun Jul 12 23:20:20 2015 +0200 [qt] fix spacing in header diff --git a/qt4/src/poppler-qt4.h b/qt4/src/poppler-qt4.h index b4494e3..768a438 100644 --- a/qt4/src/poppler-qt4.h +++ b/qt4/src/poppler-qt4.h @@ -901,8 +901,8 @@ delete it; TextSlightHinting = 0x00000008, ///< Lighter hinting for text when combined with TextHinting \since 0.18 OverprintPreview = 0x00000010, ///< Overprint preview \since 0.22 ThinLineSolid = 0x00000020, ///< Enhance thin lines solid \since 0.24 - ThinLineShape = 0x00000040, ///< Enhance thin lines shape. Wins over ThinLineSolid \since 0.24 - KeepAlphaChannel = 0x00000080 ///< Do not compose with the paper color \since 0.34 + ThinLineShape = 0x00000040, ///< Enhance thin lines shape. Wins over ThinLineSolid \since 0.24 + KeepAlphaChannel = 0x00000080 ///< Do not compose with the paper color \since 0.34 }; Q_DECLARE_FLAGS( RenderHints, RenderHint ) diff --git a/qt5/src/poppler-qt5.h b/qt5/src/poppler-qt5.h index fa23844..7e6c6e4 100644 --- a/qt5/src/poppler-qt5.h +++ b/qt5/src/poppler-qt5.h @@ -891,8 +891,8 @@ delete it; TextSlightHinting = 0x00000008, ///< Lighter hinting for text when combined with TextHinting \since 0.18 OverprintPreview = 0x00000010, ///< Overprint preview \since 0.22 ThinLineSolid = 0x00000020, ///< Enhance thin lines solid \since 0.24 - ThinLineShape = 0x00000040, ///< Enhance thin lines shape. Wins over ThinLineSolid \since 0.24 - KeepAlphaChannel = 0x00000080 ///< Do not compose with the paper color \since 0.34 + ThinLineShape = 0x00000040, ///< Enhance thin lines shape. Wins over ThinLineSolid \since 0.24 + KeepAlphaChannel = 0x00000080 ///< Do not compose with the paper color \since 0.34 }; Q_DECLARE_FLAGS( RenderHints, RenderHint ) commit 810c659faea542c3bd6e9c48c9a7c60b886a9269 Author: Adam Reichold <[email protected]> Date: Fri Jul 3 00:31:56 2015 +0200 Switch default image format of Qt frontends This changes the Poppler::Page::renderToImage method w.r.t. to the image formats used to render using Splash, i.e. the default will be RGB8. If overprint preview is requested, DeviceN8 will be used and converted to XBGR8 for display. If the internal alpha channel is requested, XBGR8 will be used and augmented by Splash's separate alpha channel. This yields some improvements w.r.t. to rendering including alpha blending with the paper colour, i.e. synthetic benchmarks using structurally simple documents yield more than two percent improvement. diff --git a/qt4/src/poppler-page.cc b/qt4/src/poppler-page.cc index 55abf8a..c99048f 100644 --- a/qt4/src/poppler-page.cc +++ b/qt4/src/poppler-page.cc @@ -294,10 +294,10 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h, { #if defined(HAVE_SPLASH) SplashColor bgColor; - GBool overprint = gFalse; + GBool overprintPreview = gFalse; #if defined(SPLASH_CMYK) - overprint = m_page->parentDoc->m_hints & Document::OverprintPreview ? gTrue : gFalse; - if (overprint) + overprintPreview = m_page->parentDoc->m_hints & Document::OverprintPreview ? gTrue : gFalse; + if (overprintPreview) { Guchar c, m, y, k; @@ -326,61 +326,84 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h, bgColor[1] = m_page->parentDoc->paperColor.green(); bgColor[2] = m_page->parentDoc->paperColor.red(); } + + SplashColorMode colorMode = splashModeRGB8; + + const bool keepAlphaChannel = m_page->parentDoc->m_hints & Document::KeepAlphaChannel; + if (keepAlphaChannel) colorMode = splashModeXBGR8; + +#if defined(SPLASH_CMYK) + if (overprintPreview) colorMode = splashModeDeviceN8; +#endif SplashThinLineMode thinLineMode = splashThinLineDefault; if (m_page->parentDoc->m_hints & Document::ThinLineShape) thinLineMode = splashThinLineShape; if (m_page->parentDoc->m_hints & Document::ThinLineSolid) thinLineMode = splashThinLineSolid; - const bool keepAlphaChannel = m_page->parentDoc->m_hints & Document::KeepAlphaChannel; - - SplashOutputDev * splash_output = new SplashOutputDev( -#if defined(SPLASH_CMYK) - (overprint) ? splashModeDeviceN8 : splashModeXBGR8, -#else - splashModeXBGR8, -#endif - 4, gFalse, keepAlphaChannel ? NULL : bgColor, gTrue, thinLineMode, overprint); - - splash_output->setFontAntialias(m_page->parentDoc->m_hints & Document::TextAntialiasing ? gTrue : gFalse); - splash_output->setVectorAntialias(m_page->parentDoc->m_hints & Document::Antialiasing ? gTrue : gFalse); - splash_output->setFreeTypeHinting(m_page->parentDoc->m_hints & Document::TextHinting ? gTrue : gFalse, + SplashOutputDev splash_output( + colorMode, 4, + gFalse, + keepAlphaChannel ? NULL : bgColor, + gTrue, + thinLineMode, + overprintPreview); + + splash_output.setFontAntialias(m_page->parentDoc->m_hints & Document::TextAntialiasing ? gTrue : gFalse); + splash_output.setVectorAntialias(m_page->parentDoc->m_hints & Document::Antialiasing ? gTrue : gFalse); + splash_output.setFreeTypeHinting(m_page->parentDoc->m_hints & Document::TextHinting ? gTrue : gFalse, m_page->parentDoc->m_hints & Document::TextSlightHinting ? gTrue : gFalse); - splash_output->startDoc(m_page->parentDoc->doc); + splash_output.startDoc(m_page->parentDoc->doc); - m_page->parentDoc->doc->displayPageSlice(splash_output, m_page->index + 1, xres, yres, + m_page->parentDoc->doc->displayPageSlice(&splash_output, m_page->index + 1, xres, yres, rotation, false, true, false, x, y, w, h, NULL, NULL, NULL, NULL, gTrue); - SplashBitmap *bitmap = splash_output->getBitmap(); - int bw = bitmap->getWidth(); - int bh = bitmap->getHeight(); - - if (bitmap->convertToXBGR(keepAlphaChannel)) - { - SplashColorPtr dataPtr = bitmap->getDataPtr(); - - if (QSysInfo::BigEndian == QSysInfo::ByteOrder) - { - uchar c; - int count = bw * bh * 4; - for (int k = 0; k < count; k += 4) - { - c = dataPtr[k]; - dataPtr[k] = dataPtr[k+3]; - dataPtr[k+3] = c; - - c = dataPtr[k+1]; - dataPtr[k+1] = dataPtr[k+2]; - dataPtr[k+2] = c; - } - } - - // construct a qimage SHARING the raw bitmap data in memory - QImage tmpimg( dataPtr, bw, bh, QImage::Format_ARGB32 ); - img = tmpimg.copy(); + SplashBitmap *bitmap = splash_output.getBitmap(); + + const int bw = bitmap->getWidth(); + const int bh = bitmap->getHeight(); + const int brs = bitmap->getRowSize(); + + // If we use DeviceN8, convert to XBGR8. + // If requested, also transfer Splash's internal alpha channel. + if (overprintPreview || keepAlphaChannel) { + if (bitmap->convertToXBGR(keepAlphaChannel)) { + SplashColorPtr data = bitmap->getDataPtr(); + + if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { + // Convert byte order from RGBX to XBGR. + for (int i = 0; i < bh; ++i) { + for (int j = 0; j < bw; ++j) { + SplashColorPtr pixel = &data[i * brs + j]; + + qSwap(pixel[0], pixel[3]); + qSwap(pixel[1], pixel[2]); + } + } + } + + // Construct a Qt image sharing the raw bitmap data. + img = QImage(data, bw, bh, brs, QImage::Format_ARGB32).copy(); + } + } + else { + SplashColorPtr data = bitmap->getDataPtr(); + + if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { + // Convert byte order from BGR to RGB. + for (int i = 0; i < bh; ++i) { + for (int j = 0; j < bw; ++j) { + SplashColorPtr pixel = &data[i * brs + j]; + + qSwap(pixel[0], pixel[2]); + } + } + } + + // Construct a Qt image sharing the raw bitmap data. + img = QImage(data, bw, bh, brs, QImage::Format_RGB888).copy(); } - delete splash_output; #endif break; } diff --git a/qt5/src/poppler-page.cc b/qt5/src/poppler-page.cc index d2fa3dd..7ae3c71 100644 --- a/qt5/src/poppler-page.cc +++ b/qt5/src/poppler-page.cc @@ -294,10 +294,10 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h, { #if defined(HAVE_SPLASH) SplashColor bgColor; - GBool overprint = gFalse; + GBool overprintPreview = gFalse; #if defined(SPLASH_CMYK) - overprint = m_page->parentDoc->m_hints & Document::OverprintPreview ? gTrue : gFalse; - if (overprint) + overprintPreview = m_page->parentDoc->m_hints & Document::OverprintPreview ? gTrue : gFalse; + if (overprintPreview) { Guchar c, m, y, k; @@ -326,60 +326,84 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h, bgColor[1] = m_page->parentDoc->paperColor.green(); bgColor[2] = m_page->parentDoc->paperColor.red(); } + + SplashColorMode colorMode = splashModeRGB8; + const bool keepAlphaChannel = m_page->parentDoc->m_hints & Document::KeepAlphaChannel; + if (keepAlphaChannel) colorMode = splashModeXBGR8; + +#if defined(SPLASH_CMYK) + if (overprintPreview) colorMode = splashModeDeviceN8; +#endif + SplashThinLineMode thinLineMode = splashThinLineDefault; if (m_page->parentDoc->m_hints & Document::ThinLineShape) thinLineMode = splashThinLineShape; if (m_page->parentDoc->m_hints & Document::ThinLineSolid) thinLineMode = splashThinLineSolid; - const bool keepAlphaChannel = m_page->parentDoc->m_hints & Document::KeepAlphaChannel; - - SplashOutputDev * splash_output = new SplashOutputDev( -#if defined(SPLASH_CMYK) - (overprint) ? splashModeDeviceN8 : splashModeXBGR8, -#else - splashModeXBGR8, -#endif - 4, gFalse, keepAlphaChannel ? NULL : bgColor, gTrue, thinLineMode, overprint); - - splash_output->setFontAntialias(m_page->parentDoc->m_hints & Document::TextAntialiasing ? gTrue : gFalse); - splash_output->setVectorAntialias(m_page->parentDoc->m_hints & Document::Antialiasing ? gTrue : gFalse); - splash_output->setFreeTypeHinting(m_page->parentDoc->m_hints & Document::TextHinting ? gTrue : gFalse, + SplashOutputDev splash_output( + colorMode, 4, + gFalse, + keepAlphaChannel ? NULL : bgColor, + gTrue, + thinLineMode, + overprintPreview); + + splash_output.setFontAntialias(m_page->parentDoc->m_hints & Document::TextAntialiasing ? gTrue : gFalse); + splash_output.setVectorAntialias(m_page->parentDoc->m_hints & Document::Antialiasing ? gTrue : gFalse); + splash_output.setFreeTypeHinting(m_page->parentDoc->m_hints & Document::TextHinting ? gTrue : gFalse, m_page->parentDoc->m_hints & Document::TextSlightHinting ? gTrue : gFalse); - splash_output->startDoc(m_page->parentDoc->doc); + splash_output.startDoc(m_page->parentDoc->doc); - m_page->parentDoc->doc->displayPageSlice(splash_output, m_page->index + 1, xres, yres, + m_page->parentDoc->doc->displayPageSlice(&splash_output, m_page->index + 1, xres, yres, rotation, false, true, false, x, y, w, h, NULL, NULL, NULL, NULL, gTrue); - SplashBitmap *bitmap = splash_output->getBitmap(); - int bw = bitmap->getWidth(); - int bh = bitmap->getHeight(); - - if (bitmap->convertToXBGR(keepAlphaChannel)) - { - SplashColorPtr dataPtr = bitmap->takeData(); - - if (QSysInfo::BigEndian == QSysInfo::ByteOrder) - { - uchar c; - int count = bw * bh * 4; - for (int k = 0; k < count; k += 4) - { - c = dataPtr[k]; - dataPtr[k] = dataPtr[k+3]; - dataPtr[k+3] = c; - - c = dataPtr[k+1]; - dataPtr[k+1] = dataPtr[k+2]; - dataPtr[k+2] = c; - } - } - - // Construct a Qt image holding (and also owning) the raw bitmap data. - img = QImage(dataPtr, bw, bh, QImage::Format_ARGB32, gfree, dataPtr); + SplashBitmap *bitmap = splash_output.getBitmap(); + + const int bw = bitmap->getWidth(); + const int bh = bitmap->getHeight(); + const int brs = bitmap->getRowSize(); + + // If we use DeviceN8, convert to XBGR8. + // If requested, also transfer Splash's internal alpha channel. + if (overprintPreview || keepAlphaChannel) { + if (bitmap->convertToXBGR(keepAlphaChannel)) { + SplashColorPtr data = bitmap->takeData(); + + if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { + // Convert byte order from RGBX to XBGR. + for (int i = 0; i < bh; ++i) { + for (int j = 0; j < bw; ++j) { + SplashColorPtr pixel = &data[i * brs + j]; + + qSwap(pixel[0], pixel[3]); + qSwap(pixel[1], pixel[2]); + } + } + } + + // Construct a Qt image holding (and also owning) the raw bitmap data. + img = QImage(data, bw, bh, brs, QImage::Format_ARGB32, gfree, data); + } + } + else { + SplashColorPtr data = bitmap->takeData(); + + if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { + // Convert byte order from BGR to RGB. + for (int i = 0; i < bh; ++i) { + for (int j = 0; j < bw; ++j) { + SplashColorPtr pixel = &data[i * brs + j]; + + qSwap(pixel[0], pixel[2]); + } + } + } + + // Construct a Qt image holding (and also owning) the raw bitmap data. + img = QImage(data, bw, bh, brs, QImage::Format_RGB888, gfree, data); } - delete splash_output; #endif break; } commit 8fea54e48ec9ba35122c565f761e7e7f016a34f9 Author: Adam Reichold <[email protected]> Date: Thu Jul 2 21:08:38 2015 +0200 Improve efficiency of Poppler::Page::renderToImage Improves the efficiency of rendering into a QImage using the Splash output device by removing a copy of the raw bitmap data since Qt5 will properly free this data using a function supplied during construction, i.e. in this case gfree. This improves performance in synthentic rendering benchmarks by approximately four percent and reduces the maximum working set size. diff --git a/qt5/src/poppler-page.cc b/qt5/src/poppler-page.cc index 07ad9b6..d2fa3dd 100644 --- a/qt5/src/poppler-page.cc +++ b/qt5/src/poppler-page.cc @@ -358,7 +358,7 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h, if (bitmap->convertToXBGR(keepAlphaChannel)) { - SplashColorPtr dataPtr = bitmap->getDataPtr(); + SplashColorPtr dataPtr = bitmap->takeData(); if (QSysInfo::BigEndian == QSysInfo::ByteOrder) { @@ -376,9 +376,8 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h, } } - // construct a qimage SHARING the raw bitmap data in memory - QImage tmpimg( dataPtr, bw, bh, QImage::Format_ARGB32 ); - img = tmpimg.copy(); + // Construct a Qt image holding (and also owning) the raw bitmap data. + img = QImage(dataPtr, bw, bh, QImage::Format_ARGB32, gfree, dataPtr); } delete splash_output; #endif commit 09db5a71fff4b7a0ed1d5d7e76c8270e2f6e9a8d Author: Adam Reichold <[email protected]> Date: Thu Jul 2 21:02:59 2015 +0200 Add KeepAlphaChannel render flag to Qt frontends Adds a new render flag which will indicate that the image return by Poppler::Page::renderToImage will not be opaque and alpha blended with the paper colour, but retain its actually background transparency. This improves performance in synthentic rendering benchmarks by almost five percent and the additional alpha blending that is then done by the consuming application is often a hardware-accellerated operation. diff --git a/qt4/src/poppler-page.cc b/qt4/src/poppler-page.cc index 49ad871..55abf8a 100644 --- a/qt4/src/poppler-page.cc +++ b/qt4/src/poppler-page.cc @@ -331,13 +331,15 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h, if (m_page->parentDoc->m_hints & Document::ThinLineShape) thinLineMode = splashThinLineShape; if (m_page->parentDoc->m_hints & Document::ThinLineSolid) thinLineMode = splashThinLineSolid; + const bool keepAlphaChannel = m_page->parentDoc->m_hints & Document::KeepAlphaChannel; + SplashOutputDev * splash_output = new SplashOutputDev( #if defined(SPLASH_CMYK) (overprint) ? splashModeDeviceN8 : splashModeXBGR8, #else splashModeXBGR8, #endif - 4, gFalse, bgColor, gTrue, thinLineMode, overprint); + 4, gFalse, keepAlphaChannel ? NULL : bgColor, gTrue, thinLineMode, overprint); splash_output->setFontAntialias(m_page->parentDoc->m_hints & Document::TextAntialiasing ? gTrue : gFalse); splash_output->setVectorAntialias(m_page->parentDoc->m_hints & Document::Antialiasing ? gTrue : gFalse); @@ -354,7 +356,7 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h, int bw = bitmap->getWidth(); int bh = bitmap->getHeight(); - if (bitmap->convertToXBGR()) + if (bitmap->convertToXBGR(keepAlphaChannel)) { SplashColorPtr dataPtr = bitmap->getDataPtr(); diff --git a/qt4/src/poppler-qt4.h b/qt4/src/poppler-qt4.h index e5e808d..b4494e3 100644 --- a/qt4/src/poppler-qt4.h +++ b/qt4/src/poppler-qt4.h @@ -901,7 +901,8 @@ delete it; TextSlightHinting = 0x00000008, ///< Lighter hinting for text when combined with TextHinting \since 0.18 OverprintPreview = 0x00000010, ///< Overprint preview \since 0.22 ThinLineSolid = 0x00000020, ///< Enhance thin lines solid \since 0.24 - ThinLineShape = 0x00000040 ///< Enhance thin lines shape. Wins over ThinLineSolid \since 0.24 + ThinLineShape = 0x00000040, ///< Enhance thin lines shape. Wins over ThinLineSolid \since 0.24 + KeepAlphaChannel = 0x00000080 ///< Do not compose with the paper color \since 0.34 }; Q_DECLARE_FLAGS( RenderHints, RenderHint ) diff --git a/qt5/src/poppler-page.cc b/qt5/src/poppler-page.cc index 408099c..07ad9b6 100644 --- a/qt5/src/poppler-page.cc +++ b/qt5/src/poppler-page.cc @@ -331,13 +331,15 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h, if (m_page->parentDoc->m_hints & Document::ThinLineShape) thinLineMode = splashThinLineShape; if (m_page->parentDoc->m_hints & Document::ThinLineSolid) thinLineMode = splashThinLineSolid; + const bool keepAlphaChannel = m_page->parentDoc->m_hints & Document::KeepAlphaChannel; + SplashOutputDev * splash_output = new SplashOutputDev( #if defined(SPLASH_CMYK) (overprint) ? splashModeDeviceN8 : splashModeXBGR8, #else splashModeXBGR8, #endif - 4, gFalse, bgColor, gTrue, thinLineMode, overprint); + 4, gFalse, keepAlphaChannel ? NULL : bgColor, gTrue, thinLineMode, overprint); splash_output->setFontAntialias(m_page->parentDoc->m_hints & Document::TextAntialiasing ? gTrue : gFalse); splash_output->setVectorAntialias(m_page->parentDoc->m_hints & Document::Antialiasing ? gTrue : gFalse); @@ -354,7 +356,7 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h, int bw = bitmap->getWidth(); int bh = bitmap->getHeight(); - if (bitmap->convertToXBGR()) + if (bitmap->convertToXBGR(keepAlphaChannel)) { SplashColorPtr dataPtr = bitmap->getDataPtr(); diff --git a/qt5/src/poppler-qt5.h b/qt5/src/poppler-qt5.h index 79c3f74..fa23844 100644 --- a/qt5/src/poppler-qt5.h +++ b/qt5/src/poppler-qt5.h @@ -891,7 +891,8 @@ delete it; TextSlightHinting = 0x00000008, ///< Lighter hinting for text when combined with TextHinting \since 0.18 OverprintPreview = 0x00000010, ///< Overprint preview \since 0.22 ThinLineSolid = 0x00000020, ///< Enhance thin lines solid \since 0.24 - ThinLineShape = 0x00000040 ///< Enhance thin lines shape. Wins over ThinLineSolid \since 0.24 + ThinLineShape = 0x00000040, ///< Enhance thin lines shape. Wins over ThinLineSolid \since 0.24 + KeepAlphaChannel = 0x00000080 ///< Do not compose with the paper color \since 0.34 }; Q_DECLARE_FLAGS( RenderHints, RenderHint ) commit d604a075c6b171d5c3fe26c146d3469c4bc0af3f Author: Adam Reichold <[email protected]> Date: Thu Jul 2 21:00:16 2015 +0200 Make SplashBitmap XBGR transfer alpha channel Adds an option to SplashBitmap::convertToXBGR and SplashBitmap::getXBGRLine so that both optionally transfer Splash's internal alpha channel into the fourth component of the resulting bitmap data. diff --git a/splash/SplashBitmap.cc b/splash/SplashBitmap.cc index e886683..7da373b 100644 --- a/splash/SplashBitmap.cc +++ b/splash/SplashBitmap.cc @@ -460,7 +460,7 @@ void SplashBitmap::getRGBLine(int yl, SplashColorPtr line) { } } -void SplashBitmap::getXBGRLine(int yl, SplashColorPtr line) { +void SplashBitmap::getXBGRLine(int yl, SplashColorPtr line, bool useAlpha) { SplashColor col; double c, m, y, k, c1, m1, y1, k1, r, g, b; @@ -503,20 +503,37 @@ void SplashBitmap::getXBGRLine(int yl, SplashColorPtr line) { *line++ = dblToByte(clip01(b)); *line++ = dblToByte(clip01(g)); *line++ = dblToByte(clip01(r)); - *line++ = 255; + *line++ = useAlpha ? getAlpha(x, yl) : 255; } } -GBool SplashBitmap::convertToXBGR() { - if (mode == splashModeXBGR8) +GBool SplashBitmap::convertToXBGR(bool useAlpha) { + if (mode == splashModeXBGR8) { + if (useAlpha) { + // Copy the alpha channel into the fourth component so that XBGR becomes ABGR. + const SplashColorPtr dbegin = data; + const SplashColorPtr dend = data + rowSize * height; + + Guchar *const abegin = alpha; + Guchar *const aend = alpha + width * height; + + SplashColorPtr d = dbegin + 3; + Guchar *a = abegin; + + for(; d < dend && a < aend; d += 4, a += 1) { + *d = *a; + } + } + return gTrue; + } int newrowSize = width * 4; SplashColorPtr newdata = (SplashColorPtr)gmallocn_checkoverflow(newrowSize, height); if (newdata != NULL) { for (int y = 0; y < height; y++) { unsigned char *row = newdata + y * newrowSize; - getXBGRLine(y, row); + getXBGRLine(y, row, useAlpha); } if (rowSize < 0) { gfree(data + (height - 1) * rowSize); diff --git a/splash/SplashBitmap.h b/splash/SplashBitmap.h index 70509ab..99879fb 100644 --- a/splash/SplashBitmap.h +++ b/splash/SplashBitmap.h @@ -75,11 +75,11 @@ public: SplashError writeImgFile(SplashImageFileFormat format, FILE *f, int hDPI, int vDPI, const char *compressionString = ""); SplashError writeImgFile(ImgWriter *writer, FILE *f, int hDPI, int vDPI); - GBool convertToXBGR(); + GBool convertToXBGR(bool useAlpha = false); void getPixel(int x, int y, SplashColorPtr pixel); void getRGBLine(int y, SplashColorPtr line); - void getXBGRLine(int y, SplashColorPtr line); + void getXBGRLine(int y, SplashColorPtr line, bool useAlpha = false); #if SPLASH_CMYK void getCMYKLine(int y, SplashColorPtr line); #endif
_______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
