[Digikam-devel] extragear/graphics/digikam/libs/dimg
Andi Clemens
andi.clemens at gmx.net
Wed Nov 4 12:52:58 GMT 2009
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:digikam-devel at kde.org
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;
}
More information about the Digikam-devel
mailing list