summaryrefslogtreecommitdiffstats
path: root/src/gui/painting/qpdf.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2014-09-02 10:46:01 +0200
committerMarc Mutz <marc.mutz@kdab.com>2014-09-02 19:06:49 +0200
commit23c1b132b1727caee1a4891c34ef27e3a5697df5 (patch)
tree30215a72b98ec65e8bd90a237c57e6404560f2c4 /src/gui/painting/qpdf.cpp
parent3ded19c86560117a2a04e04b8944ebee4a82081d (diff)
QPdf: Extract Method is_monochrome()
The old code repeatedly evaluated QImage::colorTable(), which returns a vector by value. Instead, factor the checks performed on the color table into a helper function and pass the color table to it, reducing the number of evaluations from three to one. Also makes the code more readable, because the condition now fits on a single line. Change-Id: I82773c235047e76b87c8a9d630f7df9440430351 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>
Diffstat (limited to 'src/gui/painting/qpdf.cpp')
-rw-r--r--src/gui/painting/qpdf.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp
index 0c888d645d..c7f3c0fd5b 100644
--- a/src/gui/painting/qpdf.cpp
+++ b/src/gui/painting/qpdf.cpp
@@ -2323,6 +2323,14 @@ int QPdfEnginePrivate::addBrushPattern(const QTransform &m, bool *specifyColor,
return patternObj;
}
+static inline bool is_monochrome(const QVector<QRgb> &colorTable)
+{
+ return colorTable.size() == 2
+ && colorTable.at(0) == QColor(Qt::black).rgba()
+ && colorTable.at(1) == QColor(Qt::white).rgba()
+ ;
+}
+
/*!
* Adds an image to the pdf and return the pdf-object id. Returns -1 if adding the image failed.
*/
@@ -2337,10 +2345,7 @@ int QPdfEnginePrivate::addImage(const QImage &img, bool *bitmap, qint64 serial_n
QImage image = img;
QImage::Format format = image.format();
- if (image.depth() == 1 && *bitmap && img.colorTable().size() == 2
- && img.colorTable().at(0) == QColor(Qt::black).rgba()
- && img.colorTable().at(1) == QColor(Qt::white).rgba())
- {
+ if (image.depth() == 1 && *bitmap && is_monochrome(img.colorTable())) {
if (format == QImage::Format_MonoLSB)
image = image.convertToFormat(QImage::Format_Mono);
format = QImage::Format_Mono;