OSDN Git Service

replace if with switch statment in QColormap::pixel()
authorIvailo Monev <xakepa10@laimg.moc>
Wed, 25 Mar 2020 21:08:42 +0000 (21:08 +0000)
committerIvailo Monev <xakepa10@laimg.moc>
Wed, 25 Mar 2020 21:08:42 +0000 (21:08 +0000)
Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
src/gui/painting/qcolormap_x11.cpp

index 4ede583..43b1495 100644 (file)
@@ -616,12 +616,16 @@ uint QColormap::pixel(const QColor &color) const
     const uint r = (c.ct.argb.red   * d->r_max) >> 16;
     const uint g = (c.ct.argb.green * d->g_max) >> 16;
     const uint b = (c.ct.argb.blue  * d->b_max) >> 16;
-    if (d->mode != Direct) {
-        if (d->mode == Gray)
+
+    switch (d->mode) {
+        case Gray:
             return d->pixels.at((r * 30 + g * 59 + b * 11) / 100);
-        return d->pixels.at(r * d->g_max * d->b_max + g * d->b_max + b);
+        case Indexed:
+            return d->pixels.at(r * d->g_max * d->b_max + g * d->b_max + b);
+        case Direct:
+            return (r << d->r_shift) + (g << d->g_shift) + (b << d->b_shift);
     }
-    return (r << d->r_shift) + (g << d->g_shift) + (b << d->b_shift);
+    Q_UNREACHABLE();
 }
 
 const QColor QColormap::colorAt(uint pixel) const