void PictureImage::scaleAndCreatePixmap(const QSize& size, bool fastMode) { if ((size == m_cachedSize) && ((fastMode) || (!m_cacheIsInFastMode))) { // The cached pixmap has already the right size // and: // - we are in fast mode (We do not care if the re-size was done slowly previously) // - the re-size was already done in slow mode return; } // Slow mode can be very slow, especially at high zoom levels -> configurable if (!isSlowResizeModeAllowed()) { kDebug(30508) << "User has disallowed slow mode!"; fastMode = true; } // Use QImage::scale if we have fastMode==true if (fastMode) { m_cachedPixmap = QPixmap::fromImage(m_originalImage.scaled(size), Qt::ColorOnly); // Always color or else B/W can be reversed m_cacheIsInFastMode = true; } else { m_cachedPixmap = QPixmap::fromImage(m_originalImage.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), Qt::ColorOnly); // Always color or else B/W can be reversed m_cacheIsInFastMode = false; } m_cachedSize = size; }
void KoPictureEps::scaleAndCreatePixmap(const QSize& size, bool fastMode, const int resolutionx, const int resolutiony ) { kdDebug(30003) << "KoPictureEps::scaleAndCreatePixmap " << size << " " << (fastMode?QString("fast"):QString("slow")) << " resolutionx: " << resolutionx << " resolutiony: " << resolutiony << endl; if ((size==m_cachedSize) && ((fastMode) || (!m_cacheIsInFastMode))) { // The cached pixmap has already the right size // and: // - we are in fast mode (We do not care if the re-size was done slowly previously) // - the re-size was already done in slow mode kdDebug(30003) << "Already cached!" << endl; return; } // Slow mode can be very slow, especially at high zoom levels -> configurable if ( !isSlowResizeModeAllowed() ) { kdDebug(30003) << "User has disallowed slow mode!" << endl; fastMode = true; } // We cannot use fast mode, if nothing was ever cached. if ( fastMode && !m_cachedSize.isEmpty()) { kdDebug(30003) << "Fast scaling!" << endl; // Slower than caching a QImage, but faster than re-sampling! QImage image( m_cachedPixmap.convertToImage() ); m_cachedPixmap=image.scale( size ); m_cacheIsInFastMode=true; m_cachedSize=size; } else { QTime time; time.start(); QApplication::setOverrideCursor( Qt::waitCursor ); m_cachedPixmap = scaleWithGhostScript( size, resolutionx, resolutiony ); QApplication::restoreOverrideCursor(); m_cacheIsInFastMode=false; m_cachedSize=size; kdDebug(30003) << "Time: " << (time.elapsed()/1000.0) << " s" << endl; } kdDebug(30003) << "New size: " << size << endl; }