extragear/graphics/digikam/libs/dimg

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

extragear/graphics/digikam/libs/dimg

Bugzilla from andi.clemens@gmx.net
SVN commit 1044664 by aclemens:

Little speed gain: if (under) / if (over) calls in a for-loop are expensive, if
we don't need to check for this all the time, we should avoid it.
Sure this will blow up the code (and duplicate it), but it saves computation
time.
On my machine I got a 22% speed gain.
The only bottleneck left in this method is the check for black / white color
for each pixel.
Any idea how to make this faster? Right now these checks make 60% of the
computation time in the for-loop (e.g. dimg.cpp:1602)

CCMAIL:[hidden email]

 M  +48 -15    dimg.cpp  


--- trunk/extragear/graphics/digikam/libs/dimg/dimg.cpp #1044663:1044664
@@ -1582,10 +1582,6 @@
     int o_green = expoSettings->overExposureColor.green();
     int o_blue  = expoSettings->overExposureColor.blue();
 
-    int s_red   = 0;
-    int s_green = 0;
-    int s_blue  = 0;
-
     bool under  = expoSettings->underExposureIndicator;
     bool over   = expoSettings->overExposureIndicator;
 
@@ -1595,14 +1591,14 @@
     uint*  sptr = (uint*)m_priv->data;
     uchar* dptr = bits;
 
-    for (uint i = 0; i < dim; ++i)
+    if (under && over)
     {
-        s_red   = qRed(*sptr);
-        s_green = qGreen(*sptr);
-        s_blue  = qBlue(*sptr);
+        for (uint i = 0; i < dim; ++i)
+        {
+            int s_red   = qRed(*sptr);
+            int s_green = qGreen(*sptr);
+            int s_blue  = qBlue(*sptr);
 
-        if (under)
-        {
             if ((s_red == 0) && (s_green == 0) && (s_blue == 0))
             {
                 dptr[0] = u_blue;
@@ -1610,10 +1606,7 @@
                 dptr[2] = u_red;
                 dptr[3] = 0xFF;
             }
-        }
 
-        if (over)
-        {
             if ((s_red == max) && (s_green == max) && (s_blue == max))
             {
                 dptr[0] = o_blue;
@@ -1621,12 +1614,52 @@
                 dptr[2] = o_red;
                 dptr[3] = 0xFF;
             }
+
+            dptr += 4;
+            ++sptr;
         }
+    }
+    else if (under)
+    {
+        for (uint i = 0; i < dim; ++i)
+        {
+            int s_red   = qRed(*sptr);
+            int s_green = qGreen(*sptr);
+            int s_blue  = qBlue(*sptr);
 
-        dptr += 4;
-        ++sptr;
+            if ((s_red == 0) && (s_green == 0) && (s_blue == 0))
+            {
+                dptr[0] = u_blue;
+                dptr[1] = u_green;
+                dptr[2] = u_red;
+                dptr[3] = 0xFF;
+            }
+
+            dptr += 4;
+            ++sptr;
+        }
     }
+    else if (over)
+    {
+        for (uint i = 0; i < dim; ++i)
+        {
+            int s_red   = qRed(*sptr);
+            int s_green = qGreen(*sptr);
+            int s_blue  = qBlue(*sptr);
 
+            if ((s_red == 0) && (s_green == 0) && (s_blue == 0))
+            {
+                dptr[0] = o_blue;
+                dptr[1] = o_green;
+                dptr[2] = o_red;
+                dptr[3] = 0xFF;
+            }
+
+            dptr += 4;
+            ++sptr;
+        }
+    }
+
     return img;
 }
 
_______________________________________________
Digikam-devel mailing list
[hidden email]
https://mail.kde.org/mailman/listinfo/digikam-devel