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

List:       kde-commits
Subject:    branches/KDE/4.1/kdelibs/khtml
From:       Harri Porten <porten () kde ! org>
Date:       2008-10-04 11:17:02
Message-ID: 1223119022.812639.11899.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 867730 by porten:

Merged revision 867728:
Set color components directly on the scan line rather
than reading and setting QColor values with pixel() and
setPixel(). Saved about 4-6% of cpu cycles on a heavy
duty example.

 M  +1 -16     ecma/kjs_context2d.cpp  
 M  +28 -0     html/html_canvasimpl.cpp  
 M  +1 -0      html/html_canvasimpl.h  


--- branches/KDE/4.1/kdelibs/khtml/ecma/kjs_context2d.cpp #867729:867730
@@ -815,22 +815,7 @@
         unsigned char componentValue = decodeComponent(exec, value);
         unsigned int  pixel = index / 4;
         unsigned int  comp  = index % 4;
-        QColor cur = parent->impl()->pixel(pixel);
-        switch (comp) { //RGBA..
-        case 0:
-            cur.setRed(componentValue);
-            break;
-        case 1:
-            cur.setGreen(componentValue);
-            break;
-        case 2:
-            cur.setBlue(componentValue);
-            break;
-        default:
-            cur.setAlpha(componentValue);
-            break;
-        }
-        parent->impl()->setPixel(pixel, cur);
+        parent->impl()->setComponent(pixel, comp, componentValue);
         return;
     }
 
--- branches/KDE/4.1/kdelibs/khtml/html/html_canvasimpl.cpp #867729:867730
@@ -695,6 +695,34 @@
     data.setPixel(pixelNum % w, pixelNum / w, code);
 }
 
+void CanvasImageDataImpl::setComponent(unsigned pixelNum, int component,
+                                       int value)
+{
+    int w = data.width();
+    int x = pixelNum % w;
+    int y = pixelNum / w;
+    // ### could avoid inherent QImage::detach() by a const cast
+    QRgb *rgb = reinterpret_cast<QRgb*>(data.scanLine(y) + 4 * x);
+    unsigned char a = qAlpha(*rgb);
+    switch (component) {
+    case 0:
+      *rgb = qRgba(premulComponent(value, a), qGreen(*rgb), qBlue(*rgb), a);
+      break;
+    case 1:
+      *rgb = qRgba(qRed(*rgb), premulComponent(value, a), qBlue(*rgb), a);
+      break;
+    case 2:
+      *rgb = qRgba(qRed(*rgb), qGreen(*rgb), premulComponent(value, a), a);
+      break;
+    default:
+      *rgb = qRgba(premulComponent(unpremulComponent(qRed(*rgb), a), value),
+                   premulComponent(unpremulComponent(qGreen(*rgb), a), value),
+                   premulComponent(unpremulComponent(qBlue(*rgb), a), value),
+                   value);
+      break;
+    }
+}
+
 //-------
 
 void CanvasContext2DImpl::setStrokeStyle(CanvasStyleBaseImpl* strokeStyle)
--- branches/KDE/4.1/kdelibs/khtml/html/html_canvasimpl.h #867729:867730
@@ -186,6 +186,7 @@
     unsigned height() const;
     QColor pixel(unsigned pixelNum) const;
     void   setPixel(unsigned pixelNum, const QColor& val);
+    void   setComponent(unsigned pixelNum, int component, int value);
     QImage data;
 };
 
[prev in list] [next in list] [prev in thread] [next in thread] 

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