summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin T. H. Sandsmark <martin.sandsmark@kde.org>2016-07-24 19:34:56 (GMT)
committerMartin T. H. Sandsmark <martin.sandsmark@kde.org>2016-07-24 19:34:56 (GMT)
commit077258f2357126be0242fa79c58d45b9b25266ad (patch)
tree4a0444771a4d338d667116cd21988e17cd63a425
parent1e32012649d1843397fc713973946252b87e7c16 (diff)
(re-)Implement recoloring
-rw-r--r--CMakeLists.txt8
-rw-r--r--ui/pagepainter.cpp31
-rw-r--r--ui/pagepainter.h1
3 files changed, 28 insertions, 12 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d999cbe..5bf5782 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -58,14 +58,6 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/modules)
find_package(ZLIB REQUIRED)
-# There was no Qt 5 version at the time of porting
-#find_package(QImageBlitz)
-#set_package_properties("QImageBlitz" PROPERTIES
-# DESCRIPTION "An image effects library"
-# URL "http://sourceforge.net/projects/qimageblitz"
-# TYPE RECOMMENDED
-# PURPOSE "Required to build Okular.")
-
add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS)
add_definitions(-DTRANSLATION_DOMAIN="okular")
diff --git a/ui/pagepainter.cpp b/ui/pagepainter.cpp
index 268f328..b2230ab 100644
--- a/ui/pagepainter.cpp
+++ b/ui/pagepainter.cpp
@@ -18,7 +18,6 @@
#include <kiconloader.h>
#include <QtCore/QDebug>
#include <QApplication>
-// TODO KF5 #include <qimageblitz.h>
// system includes
#include <math.h>
@@ -349,9 +348,7 @@ void PagePainter::paintCroppedPageOnPainter( QPainter * destPainter, const Okula
backImage.invertPixels(QImage::InvertRgb);
break;
case Okular::SettingsCore::EnumRenderMode::Recolor:
- // Recolor image using Blitz::flatten with dither:0
-#pragma message("KF5: implement RenderMode::Recolor again")
- // Blitz::flatten( backImage, Okular::Settings::recolorForeground(), Okular::Settings::recolorBackground() );
+ recolor(&backImage, Okular::Settings::recolorForeground(), Okular::Settings::recolorBackground());
break;
case Okular::SettingsCore::EnumRenderMode::BlackWhite:
// Manual Gray and Contrast
@@ -881,6 +878,32 @@ void PagePainter::cropPixmapOnImage( QImage & dest, const QPixmap * src, const Q
}
}
+void PagePainter::recolor(QImage *image, const QColor &foreground, const QColor &background)
+{
+ if (image->format() != QImage::Format_ARGB32_Premultiplied) {
+ qWarning() << "Wrong image format! Converting...";
+ *image = image->convertToFormat(QImage::Format_ARGB32_Premultiplied);
+ }
+
+ Q_ASSERT(image->format() == QImage::Format_ARGB32_Premultiplied);
+
+ const float scaleRed = background.redF() - foreground.redF();
+ const float scaleGreen = background.greenF() - foreground.greenF();
+ const float scaleBlue = background.blueF() - foreground.blueF();
+
+ for (int y=0; y<image->height(); y++) {
+ QRgb *pixels = reinterpret_cast<QRgb*>(image->scanLine(y));
+
+ for (int x=0; x<image->width(); x++) {
+ const int lightness = qGray(pixels[x]);
+ pixels[x] = qRgba(scaleRed * lightness,
+ scaleGreen * lightness,
+ scaleBlue * lightness,
+ qAlpha(pixels[x]));
+ }
+ }
+}
+
void PagePainter::scalePixmapOnImage ( QImage & dest, const QPixmap * src,
int scaledWidth, int scaledHeight, const QRect & cropRect, QImage::Format format )
{
diff --git a/ui/pagepainter.h b/ui/pagepainter.h
index 5b25af6..42be542 100644
--- a/ui/pagepainter.h
+++ b/ui/pagepainter.h
@@ -54,6 +54,7 @@ class Q_DECL_EXPORT PagePainter
private:
static void cropPixmapOnImage( QImage & dest, const QPixmap * src, const QRect & r );
+ static void recolor(QImage *image, const QColor &foreground, const QColor &background);
// create an image taking the 'cropRect' portion of an image scaled
// to 'scaledWidth' by 'scaledHeight' pixels. cropRect must be inside