[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice/krita/ui/canvas
From:       Dmitry Kazakov <dimula73 () gmail ! com>
Date:       2010-05-22 21:32:53
Message-ID: 20100522213253.DA54CAC8BD () svn ! kde ! org
[Download RAW message or body]

SVN commit 1129567 by dkazakov:

Some more splitting in KisPrescaledProjection

struct UpdateInformation should store initial image's dirty rect as
well. It will be needed when it'll be passed to
KisProjectionBackend::setDirty().


 M  +26 -22    kis_prescaled_projection.cpp  
 M  +2 -2      kis_prescaled_projection.h  
 M  +7 -1      kis_projection_backend.h  
 M  +0 -2      kis_projection_cache.cpp  


--- trunk/koffice/krita/ui/canvas/kis_prescaled_projection.cpp #1129566:1129567
@@ -343,25 +343,16 @@
 
     m_d->projectionBackend->setDirty(rc);
 
-    QRect viewRect = toAlignedRectWorkaround(viewRectFromImagePixels(rc));
-    viewRect = viewRect.intersected(QRect(QPoint(0, 0), m_d->canvasSize));
-    QRect newViewRect;
+    UpdateInformation info = getUpdateInformation(rc);
 
-    if (!viewRect.isEmpty()) {
-        UpdateInformation info = getUpdateInformation(viewRect);
+    QRect viewportRect = toAlignedRectWorkaround(info.viewportRect);
+
+    if(!viewportRect.isEmpty())
         updateScaledImage(info);
 
-        newViewRect = toAlignedRectWorkaround(info.viewportRect);
-        if (newViewRect != viewRect) {
-            dbgRender << "canvas size:" << m_d->canvasSize;
-            dbgRender << "viewRect before alignment:" << viewRect;
-            dbgRender << "viewRect after alignment: " << newViewRect;
+    return viewportRect;
         }
-    }
 
-    return newViewRect;
-}
-
 void KisPrescaledProjection::preScale()
 {
     Q_ASSERT(m_d->canvasSize.isValid());
@@ -371,7 +362,11 @@
 QRect KisPrescaledProjection::preScale(const QRect & rc)
 {
     if (!rc.isEmpty() && m_d->image) {
-        UpdateInformation info = getUpdateInformation(rc);
+        /**
+         * FIXME: Too many conversions view<->image
+         */
+        QRect imageRect = imageRectFromViewPortPixels(toFloatRectWorkaround(rc));
+        UpdateInformation info = getUpdateInformation(imageRect);
         updateScaledImage(info);
         return toAlignedRectWorkaround(info.viewportRect);
     }
@@ -420,10 +415,12 @@
 }
 
 UpdateInformation
-KisPrescaledProjection::getUpdateInformation(const QRect & viewportRect)
+KisPrescaledProjection::getUpdateInformation(const QRect &dirtyImageRect)
 {
     Q_ASSERT(m_d->viewConverter);
 
+    UpdateInformation info;
+
     // get the x and y zoom level of the canvas
     qreal zoomX, zoomY;
     m_d->viewConverter->zoom(&zoomX, &zoomY);
@@ -432,15 +429,22 @@
     qreal resX = m_d->image->xRes();
     qreal resY = m_d->image->yRes();
 
-    UpdateInformation info;
-
     // Compute the scale factors
     info.scaleX = zoomX / resX;
     info.scaleY = zoomY / resY;
 
-    info.imageRect = imageRectFromViewPortPixels(toFloatRectWorkaround(viewportRect));
+    info.dirtyImageRect = dirtyImageRect;
+
+    // first, crop the part of image rect that is outside of the canvas
+    QRect rawViewRect = toAlignedRectWorkaround(viewRectFromImagePixels(info.dirtyImageRect));
+    rawViewRect = rawViewRect.intersected(QRect(QPoint(0, 0), m_d->canvasSize));
+
+    // second, align this rect to the KisImage's pixels and pixels
+    // of projection backend
+    info.imageRect = imageRectFromViewPortPixels(toFloatRectWorkaround(rawViewRect));
     m_d->projectionBackend->alignSourceRect(info.imageRect, info.scaleX);
 
+    // finally, compute the dirty rect of the canvas
     info.viewportRect = viewRectFromImagePixels(info.imageRect);
 
     info.borderWidth = 0;
@@ -457,14 +461,14 @@
         info.transfer = UpdateInformation::PATCH;
     }
 
-
     dbgRender << "#####################################";
     dbgRender << ppVar(resX) << ppVar(resY);
     dbgRender << ppVar(zoomX) << ppVar(zoomY);
     dbgRender << ppVar(info.scaleX) << ppVar(info.scaleY);
     dbgRender << ppVar(info.borderWidth) << ppVar(info.renderHints);
     dbgRender << ppVar(info.transfer);
-    dbgRender << ppVar(viewportRect);
+    dbgRender << ppVar(dirtyImageRect);
+    dbgRender << "Not aligned rect of the canvas (raw):\t" << rawViewRect;
     dbgRender << "Update rect in KisImage's pixels:\t" << info.imageRect;
     dbgRender << "Update rect in canvas' pixels:\t" << info.viewportRect;
     dbgRender << "#####################################";
@@ -476,7 +480,7 @@
 {
     QPainter gc(&m_d->prescaledQImage);
     gc.setCompositionMode(QPainter::CompositionMode_Source);
-//    gc.fillRect(info.viewportRect, QColor(255, 0, 0, 255));
+    gc.fillRect(info.viewportRect, QColor(255, 0, 0, 255));
     drawUsingBackend(gc, info);
 }
 
--- trunk/koffice/krita/ui/canvas/kis_prescaled_projection.h #1129566:1129567
@@ -217,9 +217,9 @@
      * Prepare all the information about rects needed during
      * projection updating
      *
-     * @param viewportRect The desired rect. It's in viewport pixels
+     * @param dirtyImageRect the part of the KisImage that is dirty
      */
-    UpdateInformation getUpdateInformation(const QRect & viewportRect);
+    UpdateInformation getUpdateInformation(const QRect &dirtyImageRect);
 
 
     void retrieveImageData(const QRect &dirtyRect, UpdateInformation &info);
--- trunk/koffice/krita/ui/canvas/kis_projection_backend.h #1129566:1129567
@@ -139,8 +139,14 @@
     };
 
     /**
-     * Rect of KisImage corresponding to @viewportRect
+     * The rect that was reported by KisImage as dirty
      */
+    QRect dirtyImageRect;
+
+    /**
+     * Rect of KisImage corresponding to @viewportRect.
+     * It is cropped and aligned corresponding to the canvas.
+     */
     QRect imageRect;
 
     /**
--- trunk/koffice/krita/ui/canvas/kis_projection_cache.cpp #1129566:1129567
@@ -96,9 +96,7 @@
     if (!m_cacheKisImageAsQImage) return;
 
     if (m_unscaledCache.isNull()) {
-
         m_unscaledCache = QImage(m_image->width(), m_image->height(), QImage::Format_ARGB32);
-
     }
 
     QPainter p(&m_unscaledCache);
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic