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>bb10
parent
3ded19c865
commit
23c1b132b1
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue