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

List:       kde-commits
Subject:    koffice/krita/plugins/paintops/deform
From:       Lukáš Tvrdý <lukast.dev () gmail ! com>
Date:       2010-09-07 15:39:45
Message-ID: 20100907153945.5606AAC769 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1172609 by lukast:

o fix moving the pixels
o enumerify

Copy the pixels that are not touched by preset to workaround COMPOSITE_COPY not \
respecting the selection. Create selection mask in yes/no style -- composite only \
pixels we touch.

New bug is that deform now does not respect selection now :(
There is pending review on patch in review board.

When you want to move the pixels, select COPY mode, not NORMAL.

CCBUG:217124

 M  +56 -25    deform_brush.cpp  
 M  +5 -3      deform_brush.h  
 M  +32 -1     kis_deform_paintop.cpp  
 M  +5 -0      kis_deform_paintop.h  


--- trunk/koffice/krita/plugins/paintops/deform/deform_brush.cpp #1172608:1172609
@@ -31,6 +31,7 @@
 
 #include <cmath>
 #include <ctime>
+#include <KoColorSpaceRegistry.h>
 
 const qreal radToDeg = 57.29578;
 const qreal degToRad = M_PI / 180.0;
@@ -71,7 +72,7 @@
     m_srcAcc = &srcAcc;
     m_pixelSize = layer->pixelSize();
 
-    if (!setupAction(pos)){ return; }
+    if (!setupAction(DeformModes(m_properties->action-1),pos)){ return; }
 
     int curXi = static_cast<int>(pos.x() + 0.5);
     int curYi = static_cast<int>(pos.y() + 0.5);
@@ -108,35 +109,37 @@
 
 void DeformBrush::initDeformAction()
 {
-    switch(m_properties->action){
-        case 1:
-        case 2:
+    DeformModes mode = DeformModes(m_properties->action-1);
+    
+    switch(mode){
+        case GROW:
+        case SHRINK:
         {
             m_deformAction = new DeformScale();
             break;
         }
-        case 3:
-        case 4:
+        case SWIRL_CW:
+        case SWIRL_CCW:
         {
             m_deformAction = new DeformRotation();
             break;
         }
 
-        case 5:
+        case MOVE:
         {
             m_deformAction = new DeformMove();
             static_cast<DeformMove*>(m_deformAction)->setFactor(m_properties->deformAmount);
  break;
         }
-        case 6:
-        case 7:
+        case LENS_IN:
+        case LENS_OUT:
         {
             m_deformAction = new DeformLens();
             static_cast<DeformLens*>(m_deformAction)->setLensFactor(m_properties->deformAmount,0.0);
                
-            static_cast<DeformLens*>(m_deformAction)->setMode(m_properties->action \
== 7); +            static_cast<DeformLens*>(m_deformAction)->setMode(mode == \
LENS_OUT);  break;
         }
-        case 8:
+        case DEFORM_COLOR:
         {
             m_deformAction = new DeformColor();
             static_cast<DeformColor*>(m_deformAction)->setFactor(m_properties->deformAmount);
 @@ -149,15 +152,15 @@
     }
 }
 
-bool DeformBrush::setupAction(QPointF pos)
+bool DeformBrush::setupAction(DeformModes mode,const QPointF& pos)
 {
 
-    switch(m_properties->action){
-        case 1:
-        case 2:
+    switch(mode){
+        case GROW:
+        case SHRINK:
         {
             // grow or shrink, the sign decide
-            qreal sign = (m_properties->action == 1) ? 1.0 : -1.0;
+            qreal sign = (mode == GROW) ? 1.0 : -1.0;
             qreal factor;
             if (m_properties->useCounter){
                 factor = (1.0 + sign*(m_counter*m_counter / 100.0));
@@ -167,11 +170,11 @@
             dynamic_cast<DeformScale*>(m_deformAction)->setFactor(factor);
             break;
         }
-        case 3:
-        case 4:
+        case SWIRL_CW:
+        case SWIRL_CCW:
         {
              // CW or CCW, the sign decide
-            qreal sign = (m_properties->action == 3) ? 1.0 : -1.0;
+            qreal sign = (mode == SWIRL_CW) ? 1.0 : -1.0;
             qreal factor;
             if (m_properties->useCounter){
                 factor = m_counter * sign * degToRad;
@@ -181,7 +184,7 @@
             dynamic_cast<DeformRotation*>(m_deformAction)->setAlpha(factor);
             break;
         }
-        case 5:
+        case MOVE:
         {
             if (m_firstPaint == false) {
                 m_prevX = pos.x();
@@ -196,13 +199,13 @@
             }
             break;
         }
-        case 6:
-        case 7:
+        case LENS_IN:
+        case LENS_OUT:
         {
             static_cast<DeformLens*>(m_deformAction)->setMaxDistance(m_sizeProperties->diameter \
* 0.5, m_sizeProperties->diameter * 0.5);  break;
         }
-        case 8:
+        case DEFORM_COLOR:
         {
             // no run-time setup
             break;
@@ -214,8 +217,13 @@
     return true;
 }
 
-void DeformBrush::paintMask(KisFixedPaintDeviceSP dab, KisPaintDeviceSP layer, qreal \
scale, qreal rotation, QPointF pos, qreal subPixelX, qreal subPixelY) \
+KisFixedPaintDeviceSP DeformBrush::paintMask(KisFixedPaintDeviceSP dab,  +           \
KisPaintDeviceSP layer,  +                                             qreal scale, 
+                                             qreal rotation, 
+                                             QPointF pos, qreal subPixelX, qreal \
subPixelY, int dabX, int dabY)  {
+    KisFixedPaintDeviceSP mask = new \
KisFixedPaintDevice(KoColorSpaceRegistry::instance()->alpha8());  \
KisRandomSubAccessorPixel srcAcc = layer->createRandomSubAccessor();  m_srcAcc = \
&srcAcc;  m_pixelSize = layer->colorSpace()->pixelSize();
@@ -253,7 +261,9 @@
     qreal distance;
 
     // if can't paint, stop
-    if (!setupAction(pos)) return;
+    if (!setupAction(DeformModes(m_properties->action-1),pos)) {
+        return 0;
+    }
 
     qreal cosa = cos(-rotation);
     qreal sina = sin(-rotation);
@@ -261,6 +271,13 @@
     qreal bcosa = cos(rotation);
     qreal bsina = sin(rotation);
 
+    
+    mask->setRect(dab->bounds());
+    mask->initialize();
+    quint8* maskPointer = mask->data();
+    qint8 maskPixelSize = mask->pixelSize();
+    KoColor pixel(dab->colorSpace());
+    
     for (int y = 0; y <  dstHeight; y++){
         for (int x = 0; x < dstWidth; x++){
             maskX = x - m_centerX;
@@ -272,13 +289,20 @@
             distance = norme(rmaskX * m_majorAxis, rmaskY * m_minorAxis);
             if (distance > 1.0){
                 // leave there OPACITY TRANSPARENT pixel (default pixel)
+                m_srcAcc->moveTo(x + dabX, y + dabY);
+                m_srcAcc->sampledRawData(dabPointer);
                 dabPointer += m_pixelSize;
+
+                *maskPointer = OPACITY_TRANSPARENT_U8;
+                maskPointer += maskPixelSize;
                 continue;
             }
 
             if (m_sizeProperties->density != 1.0){
                 if (m_sizeProperties->density < drand48()){
                     dabPointer += m_pixelSize;
+                    *maskPointer = OPACITY_TRANSPARENT_U8;
+                    maskPointer += maskPixelSize;
                     continue;
                 }
             }
@@ -293,9 +317,16 @@
 
             movePixel(maskX, maskY, dabPointer);
             dabPointer += m_pixelSize;
+            
+            *maskPointer = OPACITY_OPAQUE_U8;
+            maskPointer += maskPixelSize;
+            
         }
     }
     m_counter++;
+
+    return mask;
+
 }
 
 void DeformBrush::debugColor(const quint8* data, KoColorSpace * cs)
--- trunk/koffice/krita/plugins/paintops/deform/deform_brush.h #1172608:1172609
@@ -34,6 +34,8 @@
 }
 #endif
 
+enum DeformModes {GROW, SHRINK, SWIRL_CW, SWIRL_CCW, MOVE, LENS_IN, LENS_OUT, \
DEFORM_COLOR}; +
 class DeformProperties
 {
 public:
@@ -169,9 +171,9 @@
     DeformBrush();
     ~DeformBrush();
 
-    void paintMask(KisFixedPaintDeviceSP dab, KisPaintDeviceSP layer,
+    KisFixedPaintDeviceSP paintMask(KisFixedPaintDeviceSP dab, KisPaintDeviceSP \
layer,  qreal scale,qreal rotation,QPointF pos,
-                   qreal subPixelX,qreal subPixelY);
+                   qreal subPixelX,qreal subPixelY, int dabX, int dabY);
 
     void oldDeform(KisPaintDeviceSP dab,KisPaintDeviceSP layer,QPointF pos);
     void setSizeProperties(KisBrushSizeProperties * properties){ m_sizeProperties = \
properties; } @@ -181,7 +183,7 @@
 
 private:
     // return true if can paint
-    bool setupAction(QPointF pos);
+    bool setupAction(DeformModes mode,const QPointF &pos);
     /// move pixel from new computed coords newX, newY to x,y (inverse mapping)
     void movePixel(qreal newX, qreal newY, quint8 *dst);
     void debugColor(const quint8* data, KoColorSpace * cs);
--- trunk/koffice/krita/plugins/paintops/deform/kis_deform_paintop.cpp \
#1172608:1172609 @@ -38,6 +38,8 @@
 
 #include "kis_deform_option.h"
 #include "kis_brush_size_option.h"
+#include <KoColorSpaceRegistry.h>
+#include <KoCompositeOp.h>
 
 KisDeformPaintOp::KisDeformPaintOp(const KisDeformPaintOpSettings *settings, \
KisPainter * painter, KisImageWSP image)  : KisPaintOp(painter)
@@ -63,20 +65,30 @@
 
     m_deformBrush.setProperties( &m_properties );
     m_deformBrush.setSizeProperties( &m_sizeProperties );
+
     m_deformBrush.initDeformAction();
 
     m_dev = source();
+    m_dabAsSelection = new KisSelection();
+    m_copyPainter = new KisPainter(m_dabAsSelection);
+    m_copyPainter->setOpacity(OPACITY_OPAQUE_U8);
+    m_copyPainter->setCompositeOp(COMPOSITE_COPY);
 
+    
     if ((m_sizeProperties.diameter * 0.5) > 1) {
         m_ySpacing = m_xSpacing = m_sizeProperties.diameter * 0.5 * \
m_sizeProperties.spacing;  } else {
         m_ySpacing = m_xSpacing = 1.0;
     }
     m_spacing = m_xSpacing;
+    
+    
+    
 }
 
 KisDeformPaintOp::~KisDeformPaintOp()
 {
+    delete m_copyPainter;
 }
 
 double KisDeformPaintOp::paintAt(const KisPaintInformation& info)
@@ -109,11 +121,30 @@
         splitCoordinate(pos.x(), &x, &subPixelX);
         splitCoordinate(pos.y(), &y, &subPixelY);
 
-        m_deformBrush.paintMask(dab, m_dev, scale,rotation,info.pos(), \
subPixelX,subPixelY); +        KisFixedPaintDeviceSP mask = \
m_deformBrush.paintMask(dab, m_dev,  +                                                \
scale,rotation, +                                                             \
info.pos(),  +                                                             \
subPixelX,subPixelY, +                                                             \
x,y +                                                             );
 
+        // this happens for the first dab of the move mode, we need more information \
for being able to move  +        if (!mask){
+            return m_spacing;
+        }
+        
+        m_dabAsSelection->clear();
+        m_copyPainter->bltFixed(QPoint(x,y),mask,mask->bounds());
+        
         quint8 origOpacity = m_opacityOption.apply(painter(), info);
+        KisSelectionSP origSelection = painter()->selection();
+        
+        painter()->setSelection(m_dabAsSelection);
         painter()->bltFixed(QPoint(x, y), dab, dab->bounds());
+        
+        painter()->setSelection(origSelection);
         painter()->setOpacity(origOpacity);
+        
         return m_spacing;
 #else
         if (!m_dab) {
--- trunk/koffice/krita/plugins/paintops/deform/kis_deform_paintop.h #1172608:1172609
@@ -51,6 +51,9 @@
     KisPaintDeviceSP m_dab;
     KisPaintDeviceSP m_dev;
 
+    KisSelectionSP m_dabAsSelection;
+    KisPainter * m_copyPainter;
+
     DeformBrush m_deformBrush;
     DeformProperties m_properties;
     KisBrushSizeProperties m_sizeProperties;
@@ -64,6 +67,8 @@
     qreal m_ySpacing;
     qreal m_spacing;
 
+    
+
 };
 
 #endif // KIS_DEFORMPAINTOP_H_


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

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