Commit 077258f2 authored by Martin Tobias Holmedahl Sandsmark's avatar Martin Tobias Holmedahl Sandsmark
Browse files

(re-)Implement recoloring

parent 1e320126
......@@ -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")
......
......@@ -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 )
{
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment