[Tizen] Fix SVACE error in pixel-buffer-impl.cpp 73/261673/1 accepted/tizen/unified/20210723.122647 submit/tizen/20210723.022907
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Mon, 19 Jul 2021 09:03:32 +0000 (10:03 +0100)
committerjoogab.yun <joogab.yun@samsung.com>
Thu, 22 Jul 2021 08:35:52 +0000 (17:35 +0900)
Change-Id: I06b14dc13dee75ebe09e2c786455f5a969e398aa

dali/internal/imaging/common/pixel-buffer-impl.cpp

index e69f2c8..6ed2e31 100644 (file)
@@ -479,19 +479,23 @@ uint32_t PixelBuffer::GetBrightness() const
   {
     unsigned char* pixel      = mBuffer;
     const uint32_t bufferSize = mWidth * mHeight;
-    uint64_t       red        = 0;
-    uint64_t       green      = 0;
-    uint64_t       blue       = 0;
 
-    for(uint32_t i = 0; i < bufferSize; ++i)
+    if(bufferSize) // avoid division by zero to calculate brightness
     {
-      red += ReadChannel(pixel, mPixelFormat, Adaptor::RED);
-      green += ReadChannel(pixel, mPixelFormat, Adaptor::GREEN);
-      blue += ReadChannel(pixel, mPixelFormat, Adaptor::BLUE);
-      pixel += bytesPerPixel;
+      uint64_t red   = 0;
+      uint64_t green = 0;
+      uint64_t blue  = 0;
+
+      for(uint32_t i = 0; i < bufferSize; ++i)
+      {
+        red += ReadChannel(pixel, mPixelFormat, Adaptor::RED);
+        green += ReadChannel(pixel, mPixelFormat, Adaptor::GREEN);
+        blue += ReadChannel(pixel, mPixelFormat, Adaptor::BLUE);
+        pixel += bytesPerPixel;
+      }
+      // http://www.w3.org/TR/AERT#color-contrast
+      brightness = (red * BRIGHTNESS_CONSTANT_R + green * BRIGHTNESS_CONSTANT_G + blue * BRIGHTNESS_CONSTANT_B) / (1000uLL * bufferSize);
     }
-    // http://www.w3.org/TR/AERT#color-contrast
-    brightness = (red * BRIGHTNESS_CONSTANT_R + green * BRIGHTNESS_CONSTANT_G + blue * BRIGHTNESS_CONSTANT_B) / (1000uLL * bufferSize);
   }
 
   return brightness;