Browse Source

Optimized Image::Clear() for the four component case (ARGB). In my case this optimized Clear() only takes ~0.362ms compared to 14.853ms before, see http://i.imgur.com/8O7V77o.jpg http://i.imgur.com/qjhkaWw.jpg.
There could be an issue, see #1260.

damu 9 years ago
parent
commit
8328a33de9
1 changed files with 14 additions and 3 deletions
  1. 14 3
      Source/Urho3D/Resource/Image.cpp

+ 14 - 3
Source/Urho3D/Resource/Image.cpp

@@ -1114,9 +1114,20 @@ void Image::ClearInt(unsigned uintColor)
         return;
         return;
     }
     }
 
 
-    unsigned char* src = (unsigned char*)&uintColor;
-    for (unsigned i = 0; i < width_ * height_ * depth_ * components_; ++i)
-        data_[i] = src[i % components_];
+    if(components_==4)
+    {
+        uint32_t color=uintColor;
+        uint32_t* data=(uint32_t*)GetData();
+        uint32_t* data_end=(uint32_t*)(GetData()+width_ * height_ * depth_ * components_);
+        for (; data < data_end; data++)
+            *data = color;
+    }
+    else
+    {
+        unsigned char* src = (unsigned char*)&uintColor;
+        for (unsigned i = 0; i < width_ * height_ * depth_ * components_; ++i)
+            data_[i] = src[i % components_];
+    }
 }
 }
 
 
 bool Image::SaveBMP(const String& fileName) const
 bool Image::SaveBMP(const String& fileName) const