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

List:       kde-kimageshop
Subject:    Review for an extents bug for layers with non-transparent default
From:       Dmitry Kazakov <dimula73 () gmail ! com>
Date:       2010-02-26 22:49:21
Message-ID: ae32c1ef1002261449j15a82ev94ab6575e6e2c8a2 () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Just for review =)

-- 
Dmitry Kazakov

[Attachment #5 (text/html)]

Just for review =)<br clear="all"><br>-- <br>Dmitry Kazakov<br>

--0015175884aeda06ac048088b534--
["XXXX-bounds-bug.diff" (text/x-patch)]

diff --git a/krita/image/CMakeLists.txt b/krita/image/CMakeLists.txt
index 497f9e9..caeea92 100644
--- a/krita/image/CMakeLists.txt
+++ b/krita/image/CMakeLists.txt
@@ -111,6 +111,7 @@ set(kritaimage_LIB_SRCS
    kis_convolution_kernel.cc
    kis_convolution_painter.cc
    kis_cubic_curve.cpp
+   kis_default_bounds.cpp
    kis_effect_mask.cc
    kis_fast_math.cpp
    kis_fill_painter.cc
diff --git a/krita/image/kis_async_merger.h b/krita/image/kis_async_merger.h
index 09e5902..5c08cb9 100644
--- a/krita/image/kis_async_merger.h
+++ b/krita/image/kis_async_merger.h
@@ -269,6 +269,7 @@ private:
             gc.setCompositeOp(parentOriginal->colorSpace()->compositeOp(COMPOSITE_COPY));
  gc.bitBlt(rect.topLeft(), m_currentProjection, rect);
         }
+        qDebug() << "Writing projection" << topmostNode->parent()->name() << rect;
     }
 
     bool compositeWithProjection(KisLayerSP layer, const QRect &rect) {
@@ -288,6 +289,8 @@ private:
         gc.setOpacity(layer->opacity());
         gc.bitBlt(needRect.topLeft(), device, needRect);
 
+        qDebug() << "Compositing projection" << layer->name() << needRect;
+
         return true;
     }
 
diff --git a/krita/image/kis_default_bounds.cpp b/krita/image/kis_default_bounds.cpp
new file mode 100644
index 0000000..0db69d6
--- /dev/null
+++ b/krita/image/kis_default_bounds.cpp
@@ -0,0 +1,60 @@
+/*
+ *  Copyright (c) 2010 Boudewijn Rempt <boud@valdyas.org>
+ *  Copyright (c) 2010 Dmitry Kazakov <dimula73@gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+
+#include "kis_global.h"
+#include "kis_default_bounds.h"
+
+
+struct KisDefaultBounds::Private
+{
+    KisImageWSP image;
+};
+
+
+KisDefaultBounds::KisDefaultBounds(KisImageWSP image)
+    : m_d(new Private())
+{
+    m_d->image = image;
+}
+
+KisDefaultBounds::KisDefaultBounds(const KisDefaultBounds& rhs)
+    : m_d(new Private())
+{
+    m_d->image = rhs.m_d->image;
+}
+
+KisDefaultBounds& KisDefaultBounds::operator=(const KisDefaultBounds& rhs)
+{
+    m_d->image = rhs.m_d->image;
+}
+
+KisDefaultBounds::~KisDefaultBounds()
+{
+    delete m_d;
+}
+
+QRect KisDefaultBounds::bounds() const
+{
+    /**
+     * By default return infinite rect to cover everything
+     */
+    return m_d->image ? m_d->image->bounds() :
+        QRect(qint32_MIN/2, qint32_MIN/2, qint32_MAX, qint32_MAX);
+}
diff --git a/krita/image/kis_default_bounds.h b/krita/image/kis_default_bounds.h
new file mode 100644
index 0000000..d4c3690
--- /dev/null
+++ b/krita/image/kis_default_bounds.h
@@ -0,0 +1,41 @@
+/*
+ *  Copyright (c) 2010 Boudewijn Rempt <boud@valdyas.org>
+ *  Copyright (c) 2010 Dmitry Kazakov <dimula73@gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+#ifndef KIS_DEFAULT_BOUNDS_H
+#define KIS_DEFAULT_BOUNDS_H
+
+#include <QRect>
+#include "kis_types.h"
+#include "kis_image.h"
+
+class KRITAIMAGE_EXPORT KisDefaultBounds
+{
+public:
+    KisDefaultBounds(KisImageWSP image = 0);
+    ~KisDefaultBounds();
+    KisDefaultBounds(const KisDefaultBounds& rhs);
+    KisDefaultBounds& operator=(const KisDefaultBounds& rhs);
+
+    QRect bounds() const;
+
+private:
+    struct Private;
+    Private * const m_d;
+};
+
+#endif // KIS_DEFAULT_BOUNDS_H
diff --git a/krita/image/kis_group_layer.cc b/krita/image/kis_group_layer.cc
index 754ad7a..c14b7ee 100644
--- a/krita/image/kis_group_layer.cc
+++ b/krita/image/kis_group_layer.cc
@@ -27,6 +27,7 @@
 #include "kis_debug.h"
 #include "kis_image.h"
 #include "kis_paint_device.h"
+#include "kis_default_bounds.h"
 
 class KisGroupLayer::Private
 {
@@ -46,7 +47,7 @@ KisGroupLayer::KisGroupLayer(KisImageWSP image, const QString \
&name, quint8 opac  KisLayer(image, name, opacity),
         m_d(new Private())
 {
-    m_d->paintDevice = new KisPaintDevice(this, image->colorSpace());
+    m_d->paintDevice = new KisPaintDevice(this, image->colorSpace(), \
KisDefaultBounds(image));  }
 
 KisGroupLayer::KisGroupLayer(const KisGroupLayer &rhs) :
@@ -78,6 +79,12 @@ QIcon KisGroupLayer::icon() const
     return KIcon("folder");
 }
 
+void KisGroupLayer::setImage(KisImageWSP image)
+{
+    m_d->paintDevice->setDefaultBounds(KisDefaultBounds(image));
+    KisLayer::setImage(image);
+}
+
 void KisGroupLayer::resetCache(const KoColorSpace *colorSpace)
 {
     if (!colorSpace)
diff --git a/krita/image/kis_group_layer.h b/krita/image/kis_group_layer.h
index 00adc35..b5ed737 100644
--- a/krita/image/kis_group_layer.h
+++ b/krita/image/kis_group_layer.h
@@ -48,6 +48,8 @@ public:
 
     QIcon icon() const;
 
+    void setImage(KisImageWSP image);
+
     /**
      * Clear the projection
      */
diff --git a/krita/image/kis_image.h b/krita/image/kis_image.h
index 6e6064d..d563e7b 100644
--- a/krita/image/kis_image.h
+++ b/krita/image/kis_image.h
@@ -32,6 +32,7 @@
 #include "kis_shared.h"
 #include "kis_node_graph_listener.h"
 #include "kis_node_facade.h"
+#include "kis_default_bounds.h"
 
 class KoColorSpace;
 class KoCompositeOp;
@@ -406,6 +407,7 @@ public:
     KisLayerSP flattenLayer(KisLayerSP layer);
 
 
+    /// This overrides interface for KisDefaultBounds
     /// @return the exact bounds of the image in pixel coordinates.
     QRect bounds() const;
 
diff --git a/krita/image/kis_paint_device.cc b/krita/image/kis_paint_device.cc
index d1a9644..117ce12 100644
--- a/krita/image/kis_paint_device.cc
+++ b/krita/image/kis_paint_device.cc
@@ -59,6 +59,7 @@ class KisPaintDevice::Private
 
 public:
     KisNodeWSP parent;
+    KisDefaultBounds defaultBounds;
     qint32 x;
     qint32 y;
     KoColorSpace* colorSpace;
@@ -117,7 +118,7 @@ KisPaintDevice::KisPaintDevice(const KoColorSpace * colorSpace, \
const QString& n  
 }
 
-KisPaintDevice::KisPaintDevice(KisNodeWSP parent, const KoColorSpace * colorSpace, \
const QString& name) +KisPaintDevice::KisPaintDevice(KisNodeWSP parent, const \
KoColorSpace * colorSpace, KisDefaultBounds defaultBounds, const QString& name)  : \
QObject(0)  , m_d(new Private())
 {
@@ -128,7 +129,8 @@ KisPaintDevice::KisPaintDevice(KisNodeWSP parent, const \
KoColorSpace * colorSpac  m_d->x = 0;
     m_d->y = 0;
 
-    m_d->parent = parent;
+    setParentNode(parent);
+    setDefaultBounds(defaultBounds);
 
     m_d->colorSpace = KoColorSpaceRegistry::instance()->grabColorSpace(colorSpace);
 
@@ -204,6 +206,11 @@ void KisPaintDevice::setParentNode(KisNodeWSP parent)
     m_d->parent = parent;
 }
 
+void KisPaintDevice::setDefaultBounds(KisDefaultBounds defaultBounds)
+{
+    m_d->defaultBounds = defaultBounds;
+}
+
 void KisPaintDevice::move(qint32 x, qint32 y)
 {
     QRect dirtyRegion = extent();
@@ -233,12 +240,23 @@ void KisPaintDevice::extent(qint32 &x, qint32 &y, qint32 &w, \
qint32 &h) const  
 QRect KisPaintDevice::extent() const
 {
-    qint32 x, y, w, h;
-    m_datamanager->extent(x, y, w, h);
-    x += m_d->x;
-    y += m_d->y;
+    QRect extent;
+
+    quint8 defaultOpacity = colorSpace()->opacityU8(defaultPixel());
+    if(defaultOpacity != OPACITY_TRANSPARENT_U8) {
+        extent = m_d->defaultBounds.bounds();
+    }
+    else {
+        qint32 x, y, w, h;
+        m_datamanager->extent(x, y, w, h);
+        x += m_d->x;
+        y += m_d->y;
+        extent = QRect(x, y, w, h);
+    }
+
+    qDebug()<<"paint device extent"<<extent;
 
-    return QRect(x, y, w, h);
+    return extent;
 }
 
 void KisPaintDevice::exactBounds(qint32 &x, qint32 &y, qint32 &w, qint32 &h) const
diff --git a/krita/image/kis_paint_device.h b/krita/image/kis_paint_device.h
index 7df6983..3f6bc3d 100644
--- a/krita/image/kis_paint_device.h
+++ b/krita/image/kis_paint_device.h
@@ -30,6 +30,7 @@
 #include "kis_global.h"
 #include "kis_shared.h"
 #include "kis_iterators_pixel.h"
+#include "kis_default_bounds.h"
 
 #include <krita_export.h>
 
@@ -50,6 +51,7 @@ class KisRandomSubAccessorPixel;
 class KisDataManager;
 class KisSelectionComponent;
 
+
 typedef KisSharedPtr<KisDataManager> KisDataManagerSP;
 
 /**
@@ -84,7 +86,7 @@ public:
      * @param colorSpace the colorspace of this paint device
      * @param name for debugging purposes
      */
-    KisPaintDevice(KisNodeWSP parent, const KoColorSpace * colorSpace, const \
QString& name = QString()); +    KisPaintDevice(KisNodeWSP parent, const KoColorSpace \
* colorSpace, KisDefaultBounds defaultBounds = KisDefaultBounds(), const QString& \
name = QString());  
     KisPaintDevice(const KisPaintDevice& rhs);
     virtual ~KisPaintDevice();
@@ -109,6 +111,12 @@ public:
     void setParentNode(KisNodeWSP parent);
 
     /**
+     * set the default bounds for the paint device when
+     * the default pixel in not completely transarent
+     */
+    void setDefaultBounds(KisDefaultBounds bounds);
+
+    /**
      * Moves the device to these new coordinates (so no incremental move or so)
      */
     virtual void move(qint32 x, qint32 y);
diff --git a/krita/image/kis_paint_layer.cc b/krita/image/kis_paint_layer.cc
index 1d3c8c7..46bb427 100644
--- a/krita/image/kis_paint_layer.cc
+++ b/krita/image/kis_paint_layer.cc
@@ -32,6 +32,7 @@
 #include "kis_painter.h"
 #include "kis_paint_device.h"
 #include "kis_node_visitor.h"
+#include "kis_default_bounds.h"
 
 class KisPaintLayer::Private
 {
@@ -49,6 +50,7 @@ KisPaintLayer::KisPaintLayer(KisImageWSP image, const QString& \
name, quint8 opac  m_d->alphaLocked = false;
     m_d->paintDevice = dev;
     m_d->paintDevice->setParentNode(this);
+    m_d->paintDevice->setDefaultBounds(KisDefaultBounds(image));
 }
 
 
@@ -57,7 +59,7 @@ KisPaintLayer::KisPaintLayer(KisImageWSP image, const QString& \
name, quint8 opac  , m_d(new Private())
 {
     Q_ASSERT(image);
-    m_d->paintDevice = new KisPaintDevice(this, image->colorSpace());
+    m_d->paintDevice = new KisPaintDevice(this, image->colorSpace(), \
KisDefaultBounds(image));  m_d->alphaLocked = false;
 }
 
@@ -70,7 +72,7 @@ KisPaintLayer::KisPaintLayer(KisImageWSP image, const QString& \
name, quint8 opac  colorSpace = image->colorSpace();
     }
     Q_ASSERT(colorSpace);
-    m_d->paintDevice = new KisPaintDevice(this, colorSpace);
+    m_d->paintDevice = new KisPaintDevice(this, colorSpace, \
KisDefaultBounds(image));  m_d->alphaLocked = false;
 }
 
@@ -132,6 +134,12 @@ QIcon KisPaintLayer::icon() const
     return QIcon();
 }
 
+void KisPaintLayer::setImage(KisImageWSP image)
+{
+    m_d->paintDevice->setDefaultBounds(KisDefaultBounds(image));
+    KisLayer::setImage(image);
+}
+
 KoDocumentSectionModel::PropertyList KisPaintLayer::sectionModelProperties() const
 {
     KoDocumentSectionModel::PropertyList l = KisLayer::sectionModelProperties();
diff --git a/krita/image/kis_paint_layer.h b/krita/image/kis_paint_layer.h
index 75f7daf..9cad1df 100644
--- a/krita/image/kis_paint_layer.h
+++ b/krita/image/kis_paint_layer.h
@@ -60,6 +60,7 @@ public:
                                   const QRect& rect) const;
 
     QIcon icon() const;
+    void setImage(KisImageWSP image);
 
     KoDocumentSectionModel::PropertyList sectionModelProperties() const;
     void setSectionModelProperties(const KoDocumentSectionModel::PropertyList \
                &properties);
diff --git a/krita/image/kis_selection_based_layer.cpp \
b/krita/image/kis_selection_based_layer.cpp index 3063b39..93db088 100644
--- a/krita/image/kis_selection_based_layer.cpp
+++ b/krita/image/kis_selection_based_layer.cpp
@@ -27,6 +27,7 @@
 
 #include "kis_image.h"
 #include "kis_painter.h"
+#include "kis_default_bounds.h"
 
 #include "kis_selection.h"
 #include "kis_pixel_selection.h"
@@ -57,7 +58,7 @@ KisSelectionBasedLayer::KisSelectionBasedLayer(KisImageWSP image,
 
     setShowSelection(true);
 
-    m_d->paintDevice = new KisPaintDevice(image->colorSpace());
+    m_d->paintDevice = new KisPaintDevice(this, image->colorSpace(), \
KisDefaultBounds(image));  }
 
 KisSelectionBasedLayer::KisSelectionBasedLayer(const KisSelectionBasedLayer& rhs)
@@ -90,6 +91,12 @@ void KisSelectionBasedLayer::initSelection()
     m_d->selection->setInterestedInDirtyness(true);
 }
 
+void KisSelectionBasedLayer::setImage(KisImageWSP image)
+{
+    m_d->paintDevice->setDefaultBounds(KisDefaultBounds(image));
+    KisLayer::setImage(image);
+}
+
 bool KisSelectionBasedLayer::allowAsChild(KisNodeSP node) const
 {
     return node->inherits("KisMask");
diff --git a/krita/image/kis_selection_based_layer.h \
b/krita/image/kis_selection_based_layer.h index ea2c504..b15d9ab 100644
--- a/krita/image/kis_selection_based_layer.h
+++ b/krita/image/kis_selection_based_layer.h
@@ -61,6 +61,8 @@ public:
      */
     bool allowAsChild(KisNodeSP node) const;
 
+    void setImage(KisImageWSP image);
+
     KisPaintDeviceSP original() const;
     KisPaintDeviceSP paintDevice() const;
 



_______________________________________________
kimageshop mailing list
kimageshop@kde.org
https://mail.kde.org/mailman/listinfo/kimageshop


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

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