[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:35:53
Message-ID: 20100522213553.98422AC8BD () svn ! kde ! org
[Download RAW message or body]
SVN commit 1129573 by dkazakov:
More splitting in KisProjectionCache and in KisImagePyramid.
(no testing has been done yet)
M +13 -4 kis_image_pyramid.cpp
M +3 -1 kis_image_pyramid.h
M +2 -3 kis_prescaled_projection.cpp
M +5 -0 kis_projection_backend.cpp
M +7 -2 kis_projection_backend.h
M +40 -23 kis_projection_cache.cpp
M +3 -1 kis_projection_cache.h
--- trunk/koffice/krita/ui/canvas/kis_image_pyramid.cpp #1129572:1129573
@@ -131,7 +131,7 @@
clearPyramid();
setImageSize(m_originalImage->width(), m_originalImage->height());
- setDirty(m_originalImage->projection()->exactBounds());
+ retrieveImageData(m_originalImage->projection()->exactBounds());
}
}
@@ -142,19 +142,28 @@
/* nothing interesting */
}
-void KisImagePyramid::setDirty(const QRect &rc)
+void KisImagePyramid::setDirty(UpdateInformation &info)
{
+ retrieveImageData(info.dirtyImageRect);
+ prescalePyramid(info);
+}
+
+void KisImagePyramid::retrieveImageData(const QRect &rect)
+{
KisPaintDeviceSP originalProjection = m_originalImage->projection();
KisPainter gc(m_pyramid[ORIGINAL_INDEX]);
gc.setCompositeOp(m_monitorColorSpace->compositeOp(COMPOSITE_COPY));
gc.setOpacity(OPACITY_OPAQUE_U8);
- gc.bitBlt(rc.topLeft(), originalProjection, rc);
+ gc.bitBlt(rect.topLeft(), originalProjection, rect);
gc.end();
+}
+void KisImagePyramid::prescalePyramid(UpdateInformation &info)
+{
KisPaintDevice *src;
KisPaintDevice *dst;
- QRect currentSrcRect = rc;
+ QRect currentSrcRect = info.dirtyImageRect;
for (int i = FIRST_NOT_ORIGINAL_INDEX; i < m_pyramidHeight; i++) {
src = m_pyramid[i-1].data();
--- trunk/koffice/krita/ui/canvas/kis_image_pyramid.h #1129572:1129573
@@ -40,7 +40,7 @@
void setImage(KisImageWSP newImage);
void setImageSize(qint32 w, qint32 h);
void setMonitorProfile(const KoColorProfile* monitorProfile);
- void setDirty(const QRect& rc);
+ void setDirty(UpdateInformation &info);
KisImagePatch getNearestPatch(UpdateInformation &info);
void drawFromOriginalImage(QPainter& gc, UpdateInformation &info);
@@ -84,6 +84,8 @@
qint32 m_pyramidHeight;
private:
+ void retrieveImageData(const QRect &rect);
+ void prescalePyramid(UpdateInformation &info);
void rebuildPyramid();
void clearPyramid();
--- trunk/koffice/krita/ui/canvas/kis_prescaled_projection.cpp #1129572:1129573
@@ -288,13 +288,12 @@
if (!rc.intersects(m_d->image->bounds()))
return QRect();
- m_d->projectionBackend->setDirty(rc);
-
QRect rawViewRect = toAlignedRectWorkaround(viewRectFromImagePixels(rc));
UpdateInformation info = getUpdateInformation(rawViewRect, rc);
- QRect viewportRect = toAlignedRectWorkaround(info.viewportRect);
+ m_d->projectionBackend->setDirty(info);
+ QRect viewportRect = toAlignedRectWorkaround(info.viewportRect);
if(!viewportRect.isEmpty())
updateScaledImage(info);
--- trunk/koffice/krita/ui/canvas/kis_projection_backend.cpp #1129572:1129573
@@ -36,6 +36,11 @@
Q_UNUSED(scale);
}
+bool KisImagePatch::isValid()
+{
+ return !m_image.isNull();
+}
+
void KisImagePatch::drawMe(QPainter &gc,
const QRectF &dstRect,
QPainter::RenderHints renderHints)
--- trunk/koffice/krita/ui/canvas/kis_projection_backend.h #1129572:1129573
@@ -51,7 +51,7 @@
/**
* Updates @rc (in KisImage pixels) from the base image
*/
- virtual void setDirty(const QRect& rc) = 0;
+ virtual void setDirty(UpdateInformation &info) = 0;
/**
* Some backends cannot work with arbitrary areas due to
@@ -114,6 +114,11 @@
QImage m_image;
/**
+ * Checks whether the patch can be used for drawing the image
+ */
+ bool isValid();
+
+ /**
* Darws an m_interestRect of the patch onto @gc
* By the way it fits this rect into @dstRect
* @renderHints are directly tranmitted to QPainter
@@ -176,7 +181,7 @@
/**
* Used for temporary sorage of KisImage's data
- * by KisPrescaledCache
+ * by KisProjectionCache
*/
KisImagePatch patch;
};
--- trunk/koffice/krita/ui/canvas/kis_projection_cache.cpp #1129572:1129573
@@ -49,7 +49,7 @@
if (toggle != m_cacheKisImageAsQImage) {
if (toggle) {
m_cacheKisImageAsQImage = true;
- setDirty(QRect(0, 0, m_imageSize.width(), m_imageSize.height()));
+ updateCachedQImage(QRect(0, 0, m_imageSize.width(), m_imageSize.height()));
} else {
m_cacheKisImageAsQImage = false;
m_unscaledCache = QImage();
@@ -76,7 +76,12 @@
#endif
m_unscaledCache = QImage(w, h, QImage::Format_ARGB32);
- setDirty(QRect(0, 0, w, h));
+ /**
+ * FIXME: Check why not use m_image->bounds()
+ * instead of QRect(0, 0, w, h)
+ */
+ if (m_cacheKisImageAsQImage)
+ updateCachedQImage(QRect(0, 0, w, h));
#ifndef ALWAYS_CACHE_AS_QIMAGE
}
@@ -88,26 +93,42 @@
m_monitorProfile = monitorProfile;
}
-void KisProjectionCache::setDirty(const QRect & rc)
+void KisProjectionCache::setDirty(UpdateInformation &info)
{
-
-
if (!m_image) return;
- if (!m_cacheKisImageAsQImage) return;
+ if (m_cacheKisImageAsQImage) {
+ updateCachedQImage(info.dirtyImageRect);
+ }
+ else {
+ /**
+ * We can neither draw the image directly from the KisImage
+ * nor cache it in the internal QImage.
+ * The only way out left is to create a patch and store
+ * a dirty piece of image there
+ */
+ /* if(info.transfer == UpdateInformation::DIRECT) */
+ info.transfer = UpdateInformation::PATCH;
+ }
- if (m_unscaledCache.isNull()) {
- m_unscaledCache = QImage(m_image->width(), m_image->height(), QImage::Format_ARGB32);
+ if (info.transfer == UpdateInformation::PATCH)
+ info.patch = getNearestPatch(info);
}
- QPainter p(&m_unscaledCache);
- p.setCompositionMode(QPainter::CompositionMode_Source);
+void KisProjectionCache::updateCachedQImage(const QRect &rect)
+{
+ if (m_unscaledCache.isNull())
+ m_unscaledCache = QImage(m_image->width(), m_image->height(), QImage::Format_ARGB32);
- QImage updateImage = m_image->convertToQImage(rc.x(), rc.y(), rc.width(), rc.height(),
+ QPainter gc(&m_unscaledCache);
+ gc.setCompositionMode(QPainter::CompositionMode_Source);
+
+ QImage updateImage = m_image->convertToQImage(rect,
m_monitorProfile);
- p.drawImage(rc.x(), rc.y(), updateImage, 0, 0, rc.width(), rc.height());
- p.end();
-
+ gc.drawImage(rect.x(), rect.y(),
+ updateImage, 0, 0,
+ rect.width(), rect.height());
+ gc.end();
}
KisImagePatch KisProjectionCache::getNearestPatch(UpdateInformation &info)
@@ -127,15 +148,11 @@
info.borderWidth, info.borderWidth);
patch.m_patchRect = adjustedRect;
- if (m_cacheKisImageAsQImage) {
+ if (m_cacheKisImageAsQImage)
patch.m_image = m_unscaledCache.copy(patch.m_patchRect);
- } else {
- qint32 x, y, w, h;
- patch.m_patchRect.getRect(&x, &y, &w, &h);
-
- patch.m_image = m_image->convertToQImage(x, y, w, h,
+ else
+ patch.m_image = m_image->convertToQImage(patch.m_patchRect,
m_monitorProfile);
- }
return patch;
}
@@ -149,7 +166,7 @@
gc.drawImage(info.viewportRect, m_unscaledCache, info.imageRect);
gc.restore();
} else {
- KisImagePatch patch = getNearestPatch(info);
- patch.drawMe(gc, info.viewportRect, info.renderHints);
+ Q_ASSERT(info.patch.isValid());
+ info.patch.drawMe(gc, info.viewportRect, info.renderHints);
}
}
--- trunk/koffice/krita/ui/canvas/kis_projection_cache.h #1129572:1129573
@@ -42,7 +42,7 @@
void setImage(KisImageWSP image);
void setImageSize(qint32 w, qint32 h);
void setMonitorProfile(const KoColorProfile* monitorProfile);
- void setDirty(const QRect& rc);
+ void setDirty(UpdateInformation &info);
KisImagePatch getNearestPatch(UpdateInformation &info);
@@ -50,6 +50,8 @@
void setCacheKisImageAsQImage(bool toggle);
+private:
+ void updateCachedQImage(const QRect &rect);
private:
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic