• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kviewshell

renderedDocumentPagePixmap.cpp

Go to the documentation of this file.
00001 
00002 /* This file is part of the KDE project
00003    Copyright (C) 2005 Wilfried Huss <Wilfried.Huss@gmx.at>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
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         // Invert image pixels using QImage internal function
00074         backImage.invertPixels(false);
00075         break;
00076       case KVSPrefs::EnumRenderMode::Recolor:
00077         // Recolor image using KImageEffect::flatten with dither:0
00078         KImageEffect::flatten(backImage, KVSPrefs::recolorForeground(), KVSPrefs::recolorBackground());
00079         break;
00080       case KVSPrefs::EnumRenderMode::BlackWhite:
00081         // Manual Gray and Contrast
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"

kviewshell

Skip menu "kviewshell"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • kviewshell
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal