kviewshell
renderedDocumentPagePixmap.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include <kimageeffect.h>
00024 #include <kdebug.h>
00025 #include <qimage.h>
00026
00027 #include "kvsprefs.h"
00028 #include "renderedDocumentPagePixmap.h"
00029
00030 RenderedDocumentPagePixmap::RenderedDocumentPagePixmap()
00031 : _accessiblePixmap(0), dirty(true)
00032 {
00033 }
00034
00035 RenderedDocumentPagePixmap::~RenderedDocumentPagePixmap()
00036 {
00037 delete _accessiblePixmap;
00038 }
00039
00040
00041 QPainter* RenderedDocumentPagePixmap::getPainter()
00042 {
00043 if (paintingActive()) {
00044 kdError(1223) << "RenderedDocumentPagePixmap::getPainter() called when painting was active" << endl;
00045 return 0;
00046 } else
00047 return new QPainter(this);
00048 }
00049
00050
00051 void RenderedDocumentPagePixmap::resize(int width, int height)
00052 {
00053 QPixmap::resize(width, height);
00054 if(_accessiblePixmap)
00055 _accessiblePixmap->resize(width, height);
00056
00057 dirty = true;
00058 }
00059
00060 void RenderedDocumentPagePixmap::resize(const QSize& size)
00061 {
00062 resize(size.width(), size.height());
00063 }
00064
00065 QPixmap RenderedDocumentPagePixmap::accessiblePixmap()
00066 {
00067 if (!_accessiblePixmap || dirty)
00068 {
00069 QImage backImage = this->convertToImage();
00070 switch (KVSPrefs::renderMode())
00071 {
00072 case KVSPrefs::EnumRenderMode::Inverted:
00073
00074 backImage.invertPixels(false);
00075 break;
00076 case KVSPrefs::EnumRenderMode::Recolor:
00077
00078 KImageEffect::flatten(backImage, KVSPrefs::recolorForeground(), KVSPrefs::recolorBackground());
00079 break;
00080 case KVSPrefs::EnumRenderMode::BlackWhite:
00081
00082 unsigned int* data = (unsigned int*)backImage.bits();
00083 int val;
00084 int pixels = backImage.width() * backImage.height();
00085 int con = KVSPrefs::bWContrast();
00086 int thr = 255 - KVSPrefs::bWThreshold();
00087
00088 for( int i = 0; i < pixels; ++i )
00089 {
00090 val = qGray(data[i]);
00091 if (val > thr)
00092 val = 128 + (127 * (val - thr)) / (255 - thr);
00093 else if ( val < thr )
00094 val = (128 * val) / thr;
00095 if (con > 2)
00096 {
00097 val = con * (val - thr) / 2 + thr;
00098 if (val > 255)
00099 val = 255;
00100 else if (val < 0)
00101 val = 0;
00102 }
00103 data[i] = qRgba(val, val, val, 255);
00104 }
00105 break;
00106 }
00107 if (!_accessiblePixmap)
00108 _accessiblePixmap = new QPixmap(width(), height());
00109
00110 _accessiblePixmap->convertFromImage(backImage);
00111 dirty = false;
00112 }
00113
00114 return *_accessiblePixmap;
00115 }
00116
00117 unsigned int RenderedDocumentPagePixmap::memory()
00118 {
00119 return size().height() * size().width() * depth() / 8;
00120 }
00121
00122 #include "renderedDocumentPagePixmap.moc"