Minor optimization on image loading
[platform/core/uifw/dali-adaptor.git] / dali / internal / imaging / common / loader-bmp.cpp
index 1e6bddf..05d0518 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 #include <dali/internal/imaging/common/loader-bmp.h>
 
-#include <dali/public-api/common/vector-wrapper.h>
 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
 #include <dali/integration-api/debug.h>
+#include <dali/public-api/common/vector-wrapper.h>
 
 namespace Dali
 {
-
 namespace TizenPlatform
 {
-
 namespace
 {
-const unsigned int FileHeaderOffsetOfBF32V4 = 0x7A;
-const unsigned int MaskForBFRGB565 = 0x80;
+const unsigned int FileHeaderOffsetOfBF32V4  = 0x7A;
+const unsigned int MaskForBFRGB565           = 0x80;
 const unsigned int FileHeaderOffsetOfRGB24V5 = 0x8A;
 
 enum BmpFormat
 {
-  BMP_RGB1 = 14,    //BI_RGB & bpp =1
-  BMP_RGB4,         //BI_RGB & bpp = 4
-  BMP_RGB8,         //BI_RGB & bpp = 8
-  BMP_RGB555,       //BI_RGB & bpp = 16
-  BMP_BITFIELDS555, //BI_BITFIELDS & 16bit & R:G:B = 5:5:5
-  BMP_BITFIELDS32,  //BI_BITFIELDS & 32bit & R:G:B:A = 8:8:8:8
-  BMP_RLE8,         //BI_RLE8
-  BMP_RLE4,         //BI_RLE4
-  BMP_BITFIELDS32V4,//BI_BITFIELDS & 32bit
-  BMP_RGB24V5,      //BI_RGB & bpp = 24 & bmp version5
+  BMP_RGB1 = 14,     //BI_RGB & bpp =1
+  BMP_RGB4,          //BI_RGB & bpp = 4
+  BMP_RGB8,          //BI_RGB & bpp = 8
+  BMP_RGB555,        //BI_RGB & bpp = 16
+  BMP_BITFIELDS555,  //BI_BITFIELDS & 16bit & R:G:B = 5:5:5
+  BMP_BITFIELDS32,   //BI_BITFIELDS & 32bit & R:G:B:A = 8:8:8:8
+  BMP_RLE8,          //BI_RLE8
+  BMP_RLE4,          //BI_RLE4
+  BMP_BITFIELDS32V4, //BI_BITFIELDS & 32bit
+  BMP_RGB24V5,       //BI_RGB & bpp = 24 & bmp version5
   BMP_NOTEXIST
 };
 
 struct BmpFileHeader
 {
-  unsigned short signature; // Bitmap file signature
-  unsigned int   fileSize;  // Bitmap file size in bytes
-  unsigned short reserved1; // Reserved bits
-  unsigned short reserved2; // Reserved bits
-  unsigned int   offset;    // Offset from BMP file header to BMP bits
-} __attribute__ ( (__packed__)); // Stops the structure from being aligned to every 4 bytes
+  unsigned short signature;    // Bitmap file signature
+  unsigned int   fileSize;     // Bitmap file size in bytes
+  unsigned short reserved1;    // Reserved bits
+  unsigned short reserved2;    // Reserved bits
+  unsigned int   offset;       // Offset from BMP file header to BMP bits
+} __attribute__((__packed__)); // Stops the structure from being aligned to every 4 bytes
 
 struct BmpInfoHeader
 {
@@ -70,7 +68,7 @@ struct BmpInfoHeader
   unsigned int   yPixelsPerMeter; // The number of pixels per meter in y axis
   unsigned int   numberOfColors;  // The number of colors in the color table
   unsigned int   importantColors; // The important color count
-} __attribute__ ( (__packed__)); // Stops the structure from being aligned to every 4 bytes
+} __attribute__((__packed__));    // Stops the structure from being aligned to every 4 bytes
 
 /**
  * Template function to read from the file directly into our structure.
@@ -84,7 +82,7 @@ inline bool ReadHeader(FILE* fp, T& header)
   const unsigned int readLength = sizeof(T);
 
   // Load the information directly into our structure
-  if ( fread( &header, 1, readLength, fp ) != readLength )
+  if(DALI_UNLIKELY(fread(&header, 1, readLength, fp) != readLength))
   {
     return false;
   }
@@ -92,23 +90,26 @@ inline bool ReadHeader(FILE* fp, T& header)
   return true;
 }
 
-bool LoadBmpHeader(FILE *fp, unsigned int &width, unsigned int &height, BmpFileHeader &fileHeader, BmpInfoHeader &infoHeader)
+bool LoadBmpHeader(FILE* fp, unsigned int& width, unsigned int& height, BmpFileHeader& fileHeader, BmpInfoHeader& infoHeader)
 {
-  if (!ReadHeader(fp, fileHeader))
+  if(DALI_UNLIKELY(!ReadHeader(fp, fileHeader)))
   {
+    DALI_LOG_ERROR("File header read failed\n");
     return false;
   }
 
-  if (!ReadHeader(fp, infoHeader))
+  if(DALI_UNLIKELY(!ReadHeader(fp, infoHeader)))
   {
+    DALI_LOG_ERROR("Info header read failed\n");
     return false;
   }
 
-  width = infoHeader.width;
+  width  = infoHeader.width;
   height = abs(infoHeader.height);
 
-  if( infoHeader.width == 0 )
+  if(DALI_UNLIKELY(infoHeader.width == 0))
   {
+    DALI_LOG_ERROR("Invalid header size\n");
     return false;
   }
 
@@ -126,53 +127,53 @@ bool LoadBmpHeader(FILE *fp, unsigned int &width, unsigned int &height, BmpFileH
  * @param[in]  padding padded to a u_int32 boundary for each line
  * @return true, if decode successful, false otherwise
  */
-bool DecodeRGB24V5(FILE *fp,
+bool DecodeRGB24V5(FILE*          fp,
                    unsigned char* pixels,
-                   unsigned int width,
-                   unsigned int height,
-                   unsigned int offset,
-                   bool topDown,
-                   unsigned int rowStride,
-                   unsigned int padding)
+                   unsigned int   width,
+                   unsigned int   height,
+                   unsigned int   offset,
+                   bool           topDown,
+                   unsigned int   rowStride,
+                   unsigned int   padding)
 {
-  if(fp == NULL || pixels == NULL)
+  if(DALI_UNLIKELY(fp == NULL || pixels == NULL))
   {
     DALI_LOG_ERROR("Error decoding BMP_RGB24V5 format\n");
     return false;
   }
-  if ( fseek(fp, offset, SEEK_SET) )
+  if(DALI_UNLIKELY(fseek(fp, offset, SEEK_SET)))
   {
     DALI_LOG_ERROR("Error seeking BMP_RGB24V5 data\n");
     return false;
   }
 
-  for(unsigned int yPos = 0; yPos < height; yPos ++)
+  for(std::uint32_t yPos = 0; yPos < height; ++yPos)
   {
-    unsigned char* pixelsPtr = NULL;
+    std::uint8_t* pixelsPtr = NULL;
     if(topDown)
     {
-      pixelsPtr = pixels + ( yPos * rowStride);
+      pixelsPtr = pixels + (yPos * rowStride);
     }
     else
     {
-      pixelsPtr = pixels + (((height-1)-yPos) * rowStride);
+      pixelsPtr = pixels + (((height - 1) - yPos) * rowStride);
     }
-    if (fread(pixelsPtr, 1, rowStride, fp) != rowStride)
+    if(DALI_UNLIKELY(fread(pixelsPtr, 1, rowStride, fp) != rowStride))
     {
       DALI_LOG_ERROR("Error reading the BMP image\n");
       return false;
     }
-    for(unsigned int i = 0; i < rowStride; i += 3)
+    for(std::uint32_t i = 0; i < rowStride; i += 3)
     {
-      unsigned char temp = pixelsPtr[i];
-      pixelsPtr[i] = pixelsPtr[i + 2];
-      pixelsPtr[i + 2] = temp;
+      std::uint8_t temp = pixelsPtr[i];
+      pixelsPtr[i]      = pixelsPtr[i + 2];
+      pixelsPtr[i + 2]  = temp;
     }
 
-    if (padding)
+    if(padding)
     {
       // move past the padding.
-      if( fseek(fp, padding, SEEK_CUR) )
+      if(DALI_UNLIKELY(fseek(fp, padding, SEEK_CUR)))
       {
         DALI_LOG_ERROR("Error moving past BMP_RGB24V5 padding\n");
       }
@@ -193,57 +194,56 @@ bool DecodeRGB24V5(FILE *fp,
  * @param[in]  padding   padded to a u_int32 boundary for each line
  * @return true, if decode successful, false otherwise
  */
-bool DecodeBF32V4(FILE *fp,
+bool DecodeBF32V4(FILE*          fp,
                   unsigned char* pixels,
-                  unsigned int width,
-                  unsigned int height,
-                  unsigned int offset,
-                  bool topDown,
-                  unsigned int rowStride,
-                  unsigned int padding)
+                  unsigned int   width,
+                  unsigned int   height,
+                  unsigned int   offset,
+                  bool           topDown,
+                  unsigned int   rowStride,
+                  unsigned int   padding)
 {
-  if(fp == NULL || pixels == NULL)
+  if(DALI_UNLIKELY(fp == NULL || pixels == NULL))
   {
     DALI_LOG_ERROR("Error decoding BMP_BITFIELDS32V4 format\n");
     return false;
   }
-  if( fseek(fp, offset, SEEK_SET) )
+  if(DALI_UNLIKELY(fseek(fp, offset, SEEK_SET)))
   {
     DALI_LOG_ERROR("Error seeking BMP_BITFIELDS32V4 data\n");
     return false;
   }
 
-  for(unsigned int yPos = 0; yPos < height; yPos ++)
+  for(std::uint32_t yPos = 0; yPos < height; ++yPos)
   {
-    unsigned char* pixelsPtr = NULL;
+    std::uint8_t* pixelsPtr = NULL;
     if(topDown)
     {
-      pixelsPtr = pixels + ( yPos * rowStride);
+      pixelsPtr = pixels + (yPos * rowStride);
     }
     else
     {
-      pixelsPtr = pixels + (((height-1)-yPos) * rowStride);
+      pixelsPtr = pixels + (((height - 1) - yPos) * rowStride);
     }
-    if (fread(pixelsPtr, 1, rowStride, fp) != rowStride)
+    if(DALI_UNLIKELY(fread(pixelsPtr, 1, rowStride, fp) != rowStride))
     {
       DALI_LOG_ERROR("Error reading the BMP image\n");
       return false;
     }
-    for(unsigned int i = 0; i < rowStride; i += 4)
+    for(std::uint32_t i = 0; i < rowStride; i += 4)
     {
-      unsigned char temp = pixelsPtr[i];
-      pixelsPtr[i] = pixelsPtr[i + 2];
-      pixelsPtr[i + 2] = temp;
+      std::uint8_t temp = pixelsPtr[i];
+      pixelsPtr[i]      = pixelsPtr[i + 2];
+      pixelsPtr[i + 2]  = temp;
     }
-    if (padding)
+    if(padding)
     {
       // move past the padding.
-      if( fseek(fp, padding, SEEK_CUR) )
+      if(DALI_UNLIKELY(fseek(fp, padding, SEEK_CUR)))
       {
         DALI_LOG_ERROR("Error moving past BMP_BITFIELDS32V4 padding\n");
       }
     }
-
   }
   return true;
 }
@@ -260,56 +260,56 @@ bool DecodeBF32V4(FILE *fp,
  * @param[in]  padding   padded to a u_int32 boundary for each line
  * @return true, if decode successful, false otherwise
  */
-bool DecodeBF32(FILE *fp,
+bool DecodeBF32(FILE*          fp,
                 unsigned char* pixels,
-                unsigned int width,
-                unsigned int height,
-                unsigned int offset,
-                bool topDown,
-                unsigned int rowStride,
-                unsigned int padding)
+                unsigned int   width,
+                unsigned int   height,
+                unsigned int   offset,
+                bool           topDown,
+                unsigned int   rowStride,
+                unsigned int   padding)
 {
-  if(fp == NULL || pixels == NULL)
+  if(DALI_UNLIKELY(fp == NULL || pixels == NULL))
   {
     DALI_LOG_ERROR("Error decoding BMP_BITFIELDS32 format\n");
     return false;
   }
-  if( fseek(fp, offset, SEEK_SET) )
+  if(DALI_UNLIKELY(fseek(fp, offset, SEEK_SET)))
   {
     DALI_LOG_ERROR("Error seeking BMP_BITFIELDS32 data\n");
     return false;
   }
 
-  for (unsigned int yPos = 0; yPos < height; yPos++)
+  for(std::uint32_t yPos = 0; yPos < height; ++yPos)
   {
-    unsigned char* pixelsPtr;
-    if (topDown)
+    std::uint8_t* pixelsPtr;
+    if(topDown)
     {
       // the data in the file is top down, and we store the data top down
-      pixelsPtr = pixels + ( yPos * rowStride);
+      pixelsPtr = pixels + (yPos * rowStride);
     }
     else
     {
       // the data in the file is bottom up, and we store the data top down
-      pixelsPtr = pixels + (((height-1)-yPos) * rowStride);
+      pixelsPtr = pixels + (((height - 1) - yPos) * rowStride);
     }
 
-    if (fread(pixelsPtr, 1, rowStride, fp) != rowStride)
+    if(DALI_UNLIKELY(fread(pixelsPtr, 1, rowStride, fp) != rowStride))
     {
       DALI_LOG_ERROR("Error reading the BMP image\n");
       return false;
     }
-    for(unsigned int i = 0; i < rowStride; i += 4)
+    for(std::uint32_t i = 0; i < rowStride; i += 4)
     {
-      unsigned char temp = pixelsPtr[i];
-      pixelsPtr[i] = pixelsPtr[i + 2];
-      pixelsPtr[i + 2] = temp;
+      std::uint8_t temp = pixelsPtr[i];
+      pixelsPtr[i]      = pixelsPtr[i + 2];
+      pixelsPtr[i + 2]  = temp;
     }
 
-    if (padding)
+    if(padding)
     {
       // move past the padding.
-      if( fseek(fp, padding, SEEK_CUR) )
+      if(DALI_UNLIKELY(fseek(fp, padding, SEEK_CUR)))
       {
         DALI_LOG_ERROR("Error moving past BMP_BITFIELDS32 padding\n");
       }
@@ -328,41 +328,41 @@ bool DecodeBF32(FILE *fp,
  * @param[in]  topDown indicate image data is read from bottom or from top
  * @return true, if decode successful, false otherwise
  */
-bool DecodeBF565(FILE *fp,
+bool DecodeBF565(FILE*          fp,
                  unsigned char* pixels,
-                 unsigned int width,
-                 unsigned int height,
-                 unsigned int offset,
-                 bool topDown)
+                 unsigned int   width,
+                 unsigned int   height,
+                 unsigned int   offset,
+                 bool           topDown)
 {
-  if(fp == NULL || pixels == NULL)
+  if(DALI_UNLIKELY(fp == NULL || pixels == NULL))
   {
     DALI_LOG_ERROR("Error decoding RGB565 format\n");
     return false;
   }
-  if( fseek(fp, offset, SEEK_SET) )
+  if(DALI_UNLIKELY(fseek(fp, offset, SEEK_SET)))
   {
     DALI_LOG_ERROR("Error seeking RGB565 data\n");
     return false;
   }
 
-  width = ((width & 3) != 0) ? width + 4 - (width & 3) : width;
-  unsigned int rowStride = width * 2;
+  width                   = ((width & 3) != 0) ? width + 4 - (width & 3) : width;
+  std::uint32_t rowStride = width * 2;
 
-  for(unsigned int i = 0; i < height; i++)
+  for(std::uint32_t i = 0; i < height; ++i)
   {
-    unsigned char* pixelsPtr = NULL;
-    if (topDown)
+    std::uint8_t* pixelsPtr = NULL;
+    if(topDown)
     {
       // the data in the file is top down, and we store the data top down
-      pixelsPtr = pixels + ( i * rowStride);
+      pixelsPtr = pixels + (i * rowStride);
     }
     else
     {
       // the data in the file is bottom up, and we store the data top down
       pixelsPtr = pixels + (((height - 1) - i) * rowStride);
     }
-    if(fread(pixelsPtr, 1, rowStride, fp) != rowStride)
+    if(DALI_UNLIKELY(fread(pixelsPtr, 1, rowStride, fp) != rowStride))
     {
       return false;
     }
@@ -381,20 +381,20 @@ bool DecodeBF565(FILE *fp,
  * @param[in]  topDown indicate image data is read from bottom or from top
  * @return true, if decode successful, false otherwise
  */
-bool DecodeBF555(FILE *fp,
+bool DecodeBF555(FILE*          fp,
                  unsigned char* pixels,
-                 unsigned int width,
-                 unsigned int height,
-                 unsigned int offset,
-                 bool topDown)
+                 unsigned int   width,
+                 unsigned int   height,
+                 unsigned int   offset,
+                 bool           topDown)
 {
-  if(fp == NULL || pixels == NULL)
+  if(DALI_UNLIKELY(fp == NULL || pixels == NULL))
   {
     DALI_LOG_ERROR("Error decoding BMP_BITFIELDS555 format\n");
     return false;
   }
 
-  if( fseek(fp, offset, SEEK_SET) )
+  if(DALI_UNLIKELY(fseek(fp, offset, SEEK_SET)))
   {
     DALI_LOG_ERROR("Error seeking BMP_BITFIELDS555 data\n");
     return false;
@@ -402,40 +402,40 @@ bool DecodeBF555(FILE *fp,
 
   width = ((width & 3) != 0) ? width + 4 - (width & 3) : width;
 
-  std::vector<char> raw(width * height * 2);
-  unsigned int rawStride = width * 2;
-  unsigned int rowStride = width * 3;
+  std::vector<std::uint8_t> raw(width * height * 2);
+  std::uint32_t             rawStride = width * 2;
+  std::uint32_t             rowStride = width * 3;
 
-  char *rawPtr = NULL;
-  for(unsigned int j = 0; j <  height; j ++)
+  std::uint8_t* rawPtr = NULL;
+  for(std::uint32_t j = 0; j < height; ++j)
   {
-    rawPtr = &raw[0] + ( j * rawStride);
-    if(fread(rawPtr, 1, rawStride, fp) != rawStride)
+    rawPtr = &raw[0] + (j * rawStride);
+    if(DALI_UNLIKELY(fread(rawPtr, 1, rawStride, fp) != rawStride))
     {
       return false;
     }
   }
 
-  for (unsigned int yPos = 0; yPos < height; yPos++)
+  for(std::uint32_t yPos = 0; yPos < height; ++yPos)
   {
-    unsigned char* pixelsPtr = NULL;
-    if (topDown)
+    std::uint8_t* pixelsPtr = NULL;
+    if(topDown)
     {
       // the data in the file is top down, and we store the data top down
-      pixelsPtr = pixels + ( yPos * rowStride);
+      pixelsPtr = pixels + (yPos * rowStride);
     }
     else
     {
       // the data in the file is bottom up, and we store the data top down
-      pixelsPtr = pixels + (((height-1)-yPos) * rowStride);
+      pixelsPtr = pixels + (((height - 1) - yPos) * rowStride);
     }
 
-    for(unsigned int k = 0; k < width; k ++)
+    for(std::uint32_t k = 0; k < width; ++k)
     {
-      int index = yPos * rawStride + 2 * k;
-      pixelsPtr[3 * k] = ((raw[ index + 1] >> 2) & 0x1F) * 0xFF / 0x1F;
-      pixelsPtr[3 * k + 1] = (((raw[index + 1] & 0x03) << 3) | (raw[ index] >> 5))  * 0xFF/ 0x1F;
-      pixelsPtr[3 * k + 2] = (raw[ index] & 0x1F) * 0xFF / 0x1F;
+      std::uint32_t index  = yPos * rawStride + 2 * k;
+      pixelsPtr[3 * k]     = ((raw[index + 1] >> 2) & 0x1F) * 0xFF / 0x1F;
+      pixelsPtr[3 * k + 1] = (((raw[index + 1] & 0x03) << 3) | (raw[index] >> 5)) * 0xFF / 0x1F;
+      pixelsPtr[3 * k + 2] = (raw[index] & 0x1F) * 0xFF / 0x1F;
     }
   }
   return true;
@@ -451,59 +451,58 @@ bool DecodeBF555(FILE *fp,
  * @param[in]  topDown indicate image data is read from bottom or from top
  * @return true, if decode successful, false otherwise
  */
-bool DecodeRGB555(FILE *fp,
+bool DecodeRGB555(FILE*          fp,
                   unsigned char* pixels,
-                  unsigned int width,
-                  unsigned int height,
-                  unsigned int offset,
-                  bool topDown)
+                  unsigned int   width,
+                  unsigned int   height,
+                  unsigned int   offset,
+                  bool           topDown)
 {
-  if(fp == NULL || pixels == NULL)
+  if(DALI_UNLIKELY(fp == NULL || pixels == NULL))
   {
     DALI_LOG_ERROR("Error decoding BMP_RGB555 format\n");
     return false;
   }
-  if( fseek(fp, offset, SEEK_SET) )
+  if(DALI_UNLIKELY(fseek(fp, offset, SEEK_SET)))
   {
     DALI_LOG_ERROR("Error seeking BMP_RGB555 data\n");
     return false;
   }
 
   width = ((width & 3) != 0) ? width + 4 - (width & 3) : width;
-  std::vector<char> raw(width * height * 2);
-  unsigned int rawStride = width * 2;
-  unsigned int rowStride = width * 3;
+  std::vector<std::uint8_t> raw(width * height * 2);
+  std::uint32_t             rawStride = width * 2;
+  std::uint32_t             rowStride = width * 3;
 
-  char *rawPtr = NULL;
-  for(unsigned int j = 0; j <  height; j ++)
+  std::uint8_t* rawPtr = NULL;
+  for(std::uint32_t j = 0; j < height; ++j)
   {
-    rawPtr = &raw[0] + ( j * rawStride);
-    if(fread(rawPtr, 1, rawStride, fp) != rawStride)
+    rawPtr = &raw[0] + (j * rawStride);
+    if(DALI_UNLIKELY(fread(rawPtr, 1, rawStride, fp) != rawStride))
     {
       return false;
     }
   }
-  for(unsigned int i = 0; i < height; i++)
+  for(std::uint32_t i = 0; i < height; ++i)
   {
-    unsigned char* pixelsPtr = NULL;
-    if (topDown)
+    std::uint8_t* pixelsPtr = NULL;
+    if(topDown)
     {
       // the data in the file is top down, and we store the data top down
-      pixelsPtr = pixels + ( i * rowStride);
+      pixelsPtr = pixels + (i * rowStride);
     }
     else
     {
       // the data in the file is bottom up, and we store the data top down
       pixelsPtr = pixels + (((height - 1) - i) * rowStride);
     }
-    for(unsigned int k = 0; k < width; k ++)
+    for(std::uint32_t k = 0; k < width; ++k)
     {
-      int index = i * rawStride + 2 * k;
-      pixelsPtr[3 * k] = ((raw[ index + 1] >> 2) & 0x1F) * 0xFF / 0x1F;
-      pixelsPtr[3 * k + 1] = (((raw[index + 1] & 0x03) << 3) | (raw[ index] >> 5))  * 0xFF/ 0x1F;
-      pixelsPtr[3 * k + 2] = (raw[ index] & 0x1F) * 0xFF / 0x1F;
+      std::uint32_t index  = i * rawStride + 2 * k;
+      pixelsPtr[3 * k]     = ((raw[index + 1] >> 2) & 0x1F) * 0xFF / 0x1F;
+      pixelsPtr[3 * k + 1] = (((raw[index + 1] & 0x03) << 3) | (raw[index] >> 5)) * 0xFF / 0x1F;
+      pixelsPtr[3 * k + 2] = (raw[index] & 0x1F) * 0xFF / 0x1F;
     }
-
   }
   return true;
 }
@@ -518,39 +517,38 @@ bool DecodeRGB555(FILE *fp,
  * @param[in]  topDown indicate image data is read from bottom or from top
  * @return true, if decode successful, false otherwise
  */
-bool DecodeRGB1(FILE *fp,
+bool DecodeRGB1(FILE*          fp,
                 unsigned char* pixels,
-                unsigned int width,
-                unsigned int height,
-                unsigned int offset,
-                bool topDown)
+                unsigned int   width,
+                unsigned int   height,
+                unsigned int   offset,
+                bool           topDown)
 {
-  if(fp == NULL || pixels == NULL)
+  if(DALI_UNLIKELY(fp == NULL || pixels == NULL))
   {
     DALI_LOG_ERROR("Error decoding BMP_RGB1 format\n");
     return false;
   }
-  if( fseek(fp, offset, SEEK_SET) )
+  if(DALI_UNLIKELY(fseek(fp, offset, SEEK_SET)))
   {
     DALI_LOG_ERROR("Error seeking BMP_RGB1 data\n");
     return false;
   }
 
-  unsigned char colorTable[8] = {0};
-  char cmd;
-  unsigned int fillw = ((width & 63) != 0) ? width + 64 - (width & 63) : width;
-  std::vector<char> colorIndex(fillw * height);
-  unsigned int rowStride = fillw * 3; // RGB
-
+  std::uint8_t              colorTable[8] = {0};
+  std::uint8_t              cmd;
+  std::uint32_t             fillw = ((width & 63) != 0) ? width + 64 - (width & 63) : width;
+  std::vector<std::uint8_t> colorIndex(fillw * height);
+  std::uint32_t             rowStride = fillw * 3; // RGB
 
-  if(fread(colorTable, 1, 8, fp) != 8)
+  if(DALI_UNLIKELY(fread(colorTable, 1, 8, fp) != 8))
   {
     return false;
   }
 
-  for(unsigned int i = 0; i < fillw * height; i += 8)
+  for(std::uint32_t i = 0; i < fillw * height; i += 8)
   {
-    if(fread(&cmd, 1, 1, fp) != 1)
+    if(DALI_UNLIKELY(fread(&cmd, 1, 1, fp) != 1))
     {
       return false;
     }
@@ -565,36 +563,36 @@ bool DecodeRGB1(FILE *fp,
     colorIndex[i + 7] = (cmd & 0x01);
   }
 
-  for(unsigned int index = 0; index < height; index = index + 1)
+  for(std::uint32_t index = 0; index < height; ++index)
   {
-    unsigned char* pixelsPtr = NULL;
-    if (topDown)
+    std::uint8_t* pixelsPtr = NULL;
+    if(topDown)
     {
       // the data in the file is top down, and we store the data top down
-      pixelsPtr = pixels + ( index * rowStride);
+      pixelsPtr = pixels + (index * rowStride);
     }
     else
     {
       // the data in the file is bottom up, and we store the data top down
       pixelsPtr = pixels + (((height - 1) - index) * rowStride);
     }
-    for(unsigned int j = 0; j < fillw; j ++)
+    for(std::uint32_t j = 0; j < fillw; ++j)
     {
-      unsigned int ctIndex = 0;
-      if((fillw * index + j ) < (fillw * height))
+      std::uint32_t ctIndex = 0;
+      if((fillw * index + j) < (fillw * height))
       {
-        ctIndex = colorIndex[ fillw * index + j ];
+        ctIndex = colorIndex[fillw * index + j];
       }
       else
       {
         break;
       }
       // temp solution for PLM bug P130411-5268, there is one mono bmp that cause DecodeRGB1 API crash.
-      if( ((3 * j + 2) < height * fillw * 3) && (ctIndex < 2))
+      if(((3 * j + 2) < height * fillw * 3) && (ctIndex < 2))
       {
-        pixelsPtr[ 3 * j ] = colorTable[4 * ctIndex + 2];
+        pixelsPtr[3 * j]     = colorTable[4 * ctIndex + 2];
         pixelsPtr[3 * j + 1] = colorTable[4 * ctIndex + 1];
-        pixelsPtr[3 * j + 2] = colorTable[4 * ctIndex ];
+        pixelsPtr[3 * j + 2] = colorTable[4 * ctIndex];
       }
     }
   }
@@ -611,66 +609,66 @@ bool DecodeRGB1(FILE *fp,
  * @param[in]  topDown indicate image data is read from bottom or from top
  * @return true, if decode successful, false otherwise
  */
-bool DecodeRGB4(FILE *fp,
+bool DecodeRGB4(FILE*          fp,
                 unsigned char* pixels,
-                unsigned int width,
-                unsigned int height,
-                unsigned int offset,
-                bool topDown)
+                unsigned int   width,
+                unsigned int   height,
+                unsigned int   offset,
+                bool           topDown)
 {
-  if(fp == NULL || pixels == NULL)
+  if(DALI_UNLIKELY(fp == NULL || pixels == NULL))
   {
     DALI_LOG_ERROR("Error decoding BMP_RGB4 format\n");
     return false;
   }
-  if( fseek(fp, offset, SEEK_SET) )
+  if(DALI_UNLIKELY(fseek(fp, offset, SEEK_SET)))
   {
     DALI_LOG_ERROR("Error seeking BMP_RGB4 data\n");
     return false;
   }
 
-  char colorTable[64];
-  char cmd;
-  unsigned int fillw = ((width & 3) != 0) ? width + 4 - (width & 3) : width;
-  std::vector<char> colorIndex(fillw * height);
-  unsigned int rowStride = fillw  * 3;
+  std::uint8_t              colorTable[64];
+  std::uint8_t              cmd;
+  std::uint32_t             fillw = ((width & 3) != 0) ? width + 4 - (width & 3) : width;
+  std::vector<std::uint8_t> colorIndex(fillw * height);
+  std::uint32_t             rowStride = fillw * 3;
 
-  if(fread(colorTable, 1, 64, fp) != 64)
+  if(DALI_UNLIKELY(fread(colorTable, 1, 64, fp) != 64))
   {
     return false;
   }
 
-  for(unsigned int i = 0; i < fillw * height; i += 2)
+  for(std::uint32_t i = 0; i < fillw * height; i += 2)
   {
-    if (fread(&cmd, 1, 1, fp) != 1)
+    if(DALI_UNLIKELY(fread(&cmd, 1, 1, fp) != 1))
     {
       return false;
     }
 
-    colorIndex[i] = cmd >> 4;
+    colorIndex[i]     = cmd >> 4;
     colorIndex[i + 1] = cmd & (0x0F);
   }
-  unsigned int ctIndex = 0;
+  std::uint32_t ctIndex = 0;
 
-  for(unsigned int index = 0; index < height; index = index + 1)
+  for(std::uint32_t index = 0; index < height; ++index)
   {
-    unsigned char* pixelsPtr = NULL;
-    if (topDown)
+    std::uint8_t* pixelsPtr = NULL;
+    if(topDown)
     {
       // the data in the file is top down, and we store the data top down
-      pixelsPtr = pixels + ( index * rowStride);
+      pixelsPtr = pixels + (index * rowStride);
     }
     else
     {
       // the data in the file is bottom up, and we store the data top down
       pixelsPtr = pixels + (((height - 1) - index) * rowStride);
     }
-    for(unsigned int j = 0; j < fillw; j ++)
+    for(std::uint32_t j = 0; j < fillw; ++j)
     {
-      ctIndex = colorIndex[ fillw * index + j ];
-      pixelsPtr[ 3 * j ] = colorTable[4 * ctIndex + 2];
+      ctIndex                = colorIndex[fillw * index + j];
+      pixelsPtr[3 * j]       = colorTable[4 * ctIndex + 2];
       pixelsPtr[(3 * j + 1)] = colorTable[4 * ctIndex + 1];
-      pixelsPtr[(3 * j + 2)] = colorTable[4 * ctIndex ];
+      pixelsPtr[(3 * j + 2)] = colorTable[4 * ctIndex];
     }
   }
 
@@ -687,63 +685,57 @@ bool DecodeRGB4(FILE *fp,
  * @param[in]  topDown indicate image data is read from bottom or from top
  * @return true, if decode successful, false otherwise
  */
-bool DecodeRGB8(FILE *fp,
+bool DecodeRGB8(FILE*          fp,
                 unsigned char* pixels,
-                unsigned int width,
-                unsigned int height,
-                unsigned int offset,
-                bool topDown)
+                unsigned int   width,
+                unsigned int   height,
+                unsigned int   offset,
+                bool           topDown)
 {
-  if(fp == NULL || pixels == NULL)
+  if(DALI_UNLIKELY(fp == NULL || pixels == NULL))
   {
     DALI_LOG_ERROR("Error decoding BMP_RGB8 format\n");
     return false;
   }
-  if( fseek(fp, offset, SEEK_SET) )
+  if(DALI_UNLIKELY(fseek(fp, offset, SEEK_SET)))
   {
     DALI_LOG_ERROR("Error seeking BMP_RGB8 data\n");
     return false;
   }
 
-  std::vector<char> colorTable(1024);
+  std::vector<std::uint8_t> colorTable(1024);
   width = ((width & 3) != 0) ? width + 4 - (width & 3) : width;
-  char cmd;
-  std::vector<char> colorIndex(width * height);
-  unsigned int rowStride = width * 3;//RGB8->RGB24
+  std::vector<std::uint8_t> colorIndex(width * height);
+  std::uint32_t             rowStride = width * 3; //RGB8->RGB24
 
-  if(fread(&colorTable[0], 1, 1024, fp) != 1024)
+  if(DALI_UNLIKELY(fread(&colorTable[0], 1, 1024, fp) != 1024))
   {
     return false;
   }
-  for(unsigned int i = 0; i < width * height; i ++)
+  if(DALI_UNLIKELY(fread(&colorIndex[0], 1, width * height, fp) != width * height))
   {
-    if (fread(&cmd, 1, 1, fp) != 1)
-    {
-      return false;
-    }
-
-    colorIndex[i] = cmd;
+    return false;
   }
-  unsigned int ctIndex = 0;
-  for(unsigned int index = 0; index < height; index = index + 1)
+  std::uint8_t ctIndex = 0;
+  for(std::uint32_t index = 0; index < height; ++index)
   {
-    unsigned char* pixelsPtr = NULL;
-    if (topDown)
+    std::uint8_t* pixelsPtr = NULL;
+    if(topDown)
     {
       // the data in the file is top down, and we store the data top down
-      pixelsPtr = pixels + ( index * rowStride);
+      pixelsPtr = pixels + (index * rowStride);
     }
     else
     {
       // the data in the file is bottom up, and we store the data top down
       pixelsPtr = pixels + (((height - 1) - index) * rowStride);
     }
-    for(unsigned int j = 0; j < width; j ++)
+    for(std::uint8_t j = 0; j < width; ++j)
     {
-      ctIndex = colorIndex[ width * index + j ];
-      pixelsPtr[ 3 * j ] = colorTable[4 * ctIndex + 2];
+      ctIndex                = colorIndex[width * index + j];
+      pixelsPtr[3 * j]       = colorTable[4 * ctIndex + 2];
       pixelsPtr[(3 * j + 1)] = colorTable[4 * ctIndex + 1];
-      pixelsPtr[(3 * j + 2)] = colorTable[4 * ctIndex ];
+      pixelsPtr[(3 * j + 2)] = colorTable[4 * ctIndex];
     }
   }
   return true;
@@ -759,52 +751,52 @@ bool DecodeRGB8(FILE *fp,
  * @param[in]  topDown indicate image data is read from bottom or from top
  * @return true, if decode successful, false otherwise
  */
-bool DecodeRLE4(FILE *fp,
+bool DecodeRLE4(FILE*          fp,
                 unsigned char* pixels,
-                unsigned int width,
-                unsigned int height,
-                unsigned int offset,
-                bool topDown)
+                unsigned int   width,
+                unsigned int   height,
+                unsigned int   offset,
+                bool           topDown)
 {
-  if(fp == NULL || pixels == NULL)
+  if(DALI_UNLIKELY(fp == NULL || pixels == NULL))
   {
     DALI_LOG_ERROR("Error decoding BMP_RLE4 format\n");
     return false;
   }
-  unsigned char* pixelsPtr = pixels;
-  width = ((width & 3) != 0) ? width + 4 - (width & 3) : width;
-  char cmd[2];
-  unsigned int cmdStride = 2;
-  char colorTable[64];
-  std::vector<char> colorIndex(width * height >> 1);
-  std::vector<char> run;
-  unsigned int x = 0;
-  unsigned int y = 0;
-  unsigned int dx = 0;
-  unsigned int dy = 0;
+  std::uint8_t* pixelsPtr = pixels;
+  width                   = ((width & 3) != 0) ? width + 4 - (width & 3) : width;
+  std::uint8_t              cmd[2];
+  std::uint32_t             cmdStride = 2;
+  std::uint8_t              colorTable[64];
+  std::vector<std::uint8_t> colorIndex(width * height >> 1);
+  std::vector<std::uint8_t> run;
+  std::uint32_t             x  = 0;
+  std::uint32_t             y  = 0;
+  std::uint32_t             dx = 0;
+  std::uint32_t             dy = 0;
   width += (width & 1);
   width = width >> 1;
 
   bool finish = false;
 
-  if( fseek(fp, offset, SEEK_SET) )
+  if(DALI_UNLIKELY(fseek(fp, offset, SEEK_SET)))
   {
     DALI_LOG_ERROR("Error seeking BMP_RLE4 data\n");
     return false;
   }
 
-  if (fread(colorTable, 1, 64, fp) != 64)
+  if(DALI_UNLIKELY(fread(colorTable, 1, 64, fp) != 64))
   {
     return false;
   }
 
   while((x >> 1) + y * width < width * height)
   {
-    if (finish)
+    if(finish)
     {
       break;
     }
-    if (fread(cmd, 1, cmdStride, fp) != cmdStride)
+    if(DALI_UNLIKELY(fread(cmd, 1, cmdStride, fp) != cmdStride))
     {
       return false;
     }
@@ -817,10 +809,10 @@ bool DecodeRLE4(FILE *fp,
           break;
         case 0: // end of line
           x = 0;
-          y ++;
+          y++;
           break;
         case 2: // delta
-          if (fread(cmd, 1, cmdStride, fp) != cmdStride)
+          if(DALI_UNLIKELY(fread(cmd, 1, cmdStride, fp) != cmdStride))
           {
             DALI_LOG_ERROR("Error reading the BMP image\n");
             return false;
@@ -832,14 +824,14 @@ bool DecodeRLE4(FILE *fp,
           break;
         default:
           // decode a literal run
-          unsigned int length = cmd[1] & (0xFF);
+          std::uint32_t length = cmd[1] & (0xFF);
           //size of run, which is word aligned
-          unsigned int bytesize = length;
+          std::uint32_t bytesize = length;
           bytesize += (bytesize & 1);
           bytesize >>= 1;
           bytesize += (bytesize & 1);
           run.resize(bytesize);
-          if(fread(&run[0], 1, bytesize, fp) != bytesize)
+          if(DALI_UNLIKELY(fread(&run[0], 1, bytesize, fp) != bytesize))
           {
             DALI_LOG_ERROR("Error reading the BMP image\n");
             return false;
@@ -848,16 +840,16 @@ bool DecodeRLE4(FILE *fp,
           {
             length += (length & 1);
             length >>= 1;
-            for(unsigned int i = 0; i < length; i += 1)
+            for(std::uint32_t i = 0; i < length; ++i)
             {
               colorIndex[(x >> 1) + width * (height - y - 1) + i] = run[i];
             }
           }
           else
           {
-            for(unsigned int i = 0; i < length; i ++)
+            for(std::uint32_t i = 0; i < length; ++i)
             {
-              if((i & 1) == 0)//copy high to low
+              if((i & 1) == 0) //copy high to low
               {
                 colorIndex[((x + i) >> 1) + width * (height - y - 1)] |= ((run[i >> 1] & 0xF0) >> 4);
               }
@@ -873,19 +865,19 @@ bool DecodeRLE4(FILE *fp,
     }
     else
     {
-      unsigned int length = cmd[0] & (0xFF);
+      std::uint32_t length = cmd[0] & (0xFF);
       if((x & 1) == 0)
       {
         length += (length & 1);
         length >>= 1;
-        for(unsigned int i = 0; i < length; i ++)
+        for(std::uint32_t i = 0; i < length; ++i)
         {
-          colorIndex[(height-y-1)*width + i + (x >> 1)] = cmd[1];
+          colorIndex[(height - y - 1) * width + i + (x >> 1)] = cmd[1];
         }
       }
       else
       {
-        for(unsigned int i = 0; i < length; i ++)
+        for(std::uint32_t i = 0; i < length; ++i)
         {
           if((i & 1) == 0)
           {
@@ -901,18 +893,18 @@ bool DecodeRLE4(FILE *fp,
     }
   }
 
-  int ctIndexHigh = 0;
-  int ctIndexLow = 0;
-  for(unsigned int index = 0; index < (width * height ); index = index + 1)
+  std::uint32_t ctIndexHigh = 0;
+  std::uint32_t ctIndexLow  = 0;
+  for(std::uint32_t index = 0; index < (width * height); ++index)
   {
-    ctIndexHigh = colorIndex[ index] >> 4;
-    ctIndexLow = colorIndex[index] & (0x0F);
-    pixelsPtr[6 * index ] = colorTable[4 * ctIndexHigh + 2];
+    ctIndexHigh              = colorIndex[index] >> 4;
+    ctIndexLow               = colorIndex[index] & (0x0F);
+    pixelsPtr[6 * index]     = colorTable[4 * ctIndexHigh + 2];
     pixelsPtr[6 * index + 1] = colorTable[4 * ctIndexHigh + 1];
-    pixelsPtr[6 * index + 2] = colorTable[4 * ctIndexHigh ];
+    pixelsPtr[6 * index + 2] = colorTable[4 * ctIndexHigh];
     pixelsPtr[6 * index + 3] = colorTable[4 * ctIndexLow + 2];
     pixelsPtr[6 * index + 4] = colorTable[4 * ctIndexLow + 1];
-    pixelsPtr[6 * index + 5] = colorTable[4 * ctIndexLow ];
+    pixelsPtr[6 * index + 5] = colorTable[4 * ctIndexLow];
   }
   return true;
 }
@@ -927,57 +919,57 @@ bool DecodeRLE4(FILE *fp,
  * @param[in]  topDown indicate image data is read from bottom or from top
  * @return true, if decode successful, false otherwise
  */
-bool DecodeRLE8(FILE *fp,
+bool DecodeRLE8(FILE*          fp,
                 unsigned char* pixels,
-                unsigned int width,
-                unsigned int height,
-                unsigned int offset,
-                bool topDown)
+                unsigned int   width,
+                unsigned int   height,
+                unsigned int   offset,
+                bool           topDown)
 {
-  if(fp == NULL || pixels == NULL)
+  if(DALI_UNLIKELY(fp == NULL || pixels == NULL))
   {
     DALI_LOG_ERROR("Error decoding BMP_RLE8 format\n");
     return false;
   }
-  unsigned char* pixelsPtr = pixels;
-  unsigned int x = 0;
-  unsigned int y = 0;
-  unsigned int cmdStride = 2;
+  std::uint8_t* pixelsPtr = pixels;
+  std::uint32_t x         = 0;
+  std::uint32_t y         = 0;
+  std::uint32_t cmdStride = 2;
 
   width = ((width & 3) != 0) ? width + 4 - (width & 3) : width;
-  std::vector<char> colorTable(1024);
-  char cmd[2];
-  std::vector<char> colorIndex(width * height);
+  std::vector<std::uint8_t> colorTable(1024);
+  std::uint8_t              cmd[2];
+  std::vector<std::uint8_t> colorIndex(width * height);
 
-  if( fseek(fp, offset, SEEK_SET) )
+  if(DALI_UNLIKELY(fseek(fp, offset, SEEK_SET)))
   {
     DALI_LOG_ERROR("Error seeking BMP_RLE8 data\n");
     return false;
   }
 
-  if (fread(&colorTable[0], 1, 1024, fp) != 1024)
+  if(DALI_UNLIKELY(fread(&colorTable[0], 1, 1024, fp) != 1024))
   {
     return false;
   }
 
-  unsigned int dx = 0;
-  unsigned int dy = 0;
-  bool finish = false;
-  unsigned int length = 0;
-  unsigned int copylength = 0;
-  std::vector<char> run;
-  while((x + y * width) < width * height )
+  std::uint32_t             dx         = 0;
+  std::uint32_t             dy         = 0;
+  bool                      finish     = false;
+  std::uint32_t             length     = 0;
+  std::uint32_t             copylength = 0;
+  std::vector<std::uint8_t> run;
+  while((x + y * width) < width * height)
   {
-    if (finish)
+    if(DALI_UNLIKELY(finish))
     {
       break;
     }
-    if (fread(cmd, 1, cmdStride, fp) != cmdStride)
+    if(DALI_UNLIKELY(fread(cmd, 1, cmdStride, fp) != cmdStride))
     {
       return false;
     }
 
-    if(cmd[0] == 0)//ESCAPE
+    if(cmd[0] == 0) //ESCAPE
     {
       switch(cmd[1])
       {
@@ -986,10 +978,10 @@ bool DecodeRLE8(FILE *fp,
           break;
         case 0: // end of line
           x = 0;
-          y ++;
+          y++;
           break;
         case 2: // delta
-          if (fread(cmd, 1, cmdStride, fp) != cmdStride)
+          if(DALI_UNLIKELY(fread(cmd, 1, cmdStride, fp) != cmdStride))
           {
             DALI_LOG_ERROR("Error reading the BMP image\n");
             return false;
@@ -1001,91 +993,91 @@ bool DecodeRLE8(FILE *fp,
           break;
         default:
           //decode a literal run
-          length = cmd[1] & (0xFF);
+          length     = cmd[1] & (0xFF);
           copylength = length;
           //absolute mode must be word-aligned
           length += (length & 1);
           run.resize(length);
-          if(fread(&run[0], 1, length, fp) != length)
+          if(DALI_UNLIKELY(fread(&run[0], 1, length, fp) != length))
           {
             DALI_LOG_ERROR("Error reading the BMP image\n");
             return false;
           }
 
-          for(unsigned int i = 0; i < length; i += 1)
+          for(std::uint32_t i = 0; i < length; ++i)
           {
             colorIndex[x + width * (height - y - 1) + i] = run[i];
           }
           x += copylength;
           break;
       }
-    }// end if cmd[0] ==
+    } // end if cmd[0] ==
     else
     {
       length = cmd[0] & (0xFF);
-      for(unsigned int i = 0; i < length; i ++)
+      for(std::uint32_t i = 0; i < length; ++i)
       {
         colorIndex[(height - y - 1) * width + x] = cmd[1];
         x++;
       }
     }
   }
-  int ctIndex = 0;
-  for(unsigned int index = 0; index < width * height; index = index + 1)
+  std::uint32_t ctIndex = 0;
+  for(std::uint32_t index = 0; index < width * height; ++index)
   {
-    ctIndex = colorIndex[ index];
-    pixelsPtr[3 * index ] = colorTable[4 * ctIndex + 2];
+    ctIndex                  = colorIndex[index];
+    pixelsPtr[3 * index]     = colorTable[4 * ctIndex + 2];
     pixelsPtr[3 * index + 1] = colorTable[4 * ctIndex + 1];
-    pixelsPtr[3 * index + 2] = colorTable[4 * ctIndex ];
+    pixelsPtr[3 * index + 2] = colorTable[4 * ctIndex];
   }
   return true;
 }
 
 } // unnamed namespace
 
-bool LoadBmpHeader( const ImageLoader::Input& input, unsigned int& width, unsigned int& height )
+bool LoadBmpHeader(const Dali::ImageLoader::Input& input, unsigned int& width, unsigned int& height)
 {
   BmpFileHeader fileHeader;
   BmpInfoHeader infoHeader;
 
-  bool ret = LoadBmpHeader( input.file, width, height, fileHeader, infoHeader );
+  bool ret = LoadBmpHeader(input.file, width, height, fileHeader, infoHeader);
 
   return ret;
 }
 
-bool LoadBitmapFromBmp( const ImageLoader::Input& input, Dali::Devel::PixelBuffer& bitmap )
+bool LoadBitmapFromBmp(const Dali::ImageLoader::Input& input, Dali::Devel::PixelBuffer& bitmap)
 {
   //DALI_ASSERT_DEBUG( bitmap.GetPackedPixelsProfile() != 0 && "Need a packed pixel bitmap to load into." );
   FILE* const fp = input.file;
-  if(fp == NULL)
+  if(DALI_UNLIKELY(fp == NULL))
   {
     DALI_LOG_ERROR("Error loading bitmap\n");
     return false;
   }
-  BmpFormat customizedFormat = BMP_NOTEXIST;
+  BmpFormat     customizedFormat = BMP_NOTEXIST;
   BmpFileHeader fileHeader;
   BmpInfoHeader infoHeader;
 
   // Load the header info
   unsigned int width, height;
 
-  if (!LoadBmpHeader(fp, width, height, fileHeader, infoHeader))
+  if(DALI_UNLIKELY(!LoadBmpHeader(fp, width, height, fileHeader, infoHeader)))
   {
-      return false;
+    return false;
   }
 
   Pixel::Format pixelFormat = Pixel::RGB888;
   switch(infoHeader.compression)
   {
     case 0:
-      switch (infoHeader.bitsPerPixel)
+      switch(infoHeader.bitsPerPixel)
       {
         case 32:
           pixelFormat = Pixel::BGR8888;
           break;
 
         case 24:
-          if(fileHeader.offset == FileHeaderOffsetOfRGB24V5)//0x8A
+          if(fileHeader.offset == FileHeaderOffsetOfRGB24V5) //0x8A
           {
             customizedFormat = BMP_RGB24V5;
           }
@@ -1111,10 +1103,10 @@ bool LoadBitmapFromBmp( const ImageLoader::Input& input, Dali::Devel::PixelBuffe
           customizedFormat = BMP_RGB1;
           break;
         default:
-          DALI_LOG_WARNING("%d bits per pixel not supported for BMP files\n", infoHeader.bitsPerPixel);
+          DALI_LOG_ERROR("%d bits per pixel not supported for BMP files\n", infoHeader.bitsPerPixel);
           return false;
       }
-    break;
+      break;
     case 1: //// RLE8
     {
       if(infoHeader.bitsPerPixel == 8)
@@ -1135,13 +1127,13 @@ bool LoadBitmapFromBmp( const ImageLoader::Input& input, Dali::Devel::PixelBuffe
     {
       if(infoHeader.bitsPerPixel == 16)
       {
-        if( fseek(fp, 14 + infoHeader.infoHeaderSize + 1, SEEK_SET) )
+        if(DALI_UNLIKELY(fseek(fp, 14 + infoHeader.infoHeaderSize + 1, SEEK_SET)))
         {
           return false;
         }
 
         char mask;
-        if(fread(&mask, 1, 1, fp) != 1)
+        if(DALI_UNLIKELY(fread(&mask, 1, 1, fp) != 1))
         {
           return false;
         }
@@ -1150,7 +1142,7 @@ bool LoadBitmapFromBmp( const ImageLoader::Input& input, Dali::Devel::PixelBuffe
         {
           pixelFormat = Pixel::RGB565;
         }
-        else if((mask & 0x80) == 0)// mask is 0x 7C
+        else if((mask & 0x80) == 0) // mask is 0x 7C
         {
           customizedFormat = BMP_BITFIELDS555;
         }
@@ -1161,7 +1153,7 @@ bool LoadBitmapFromBmp( const ImageLoader::Input& input, Dali::Devel::PixelBuffe
       }
       else if(infoHeader.bitsPerPixel == 32)
       {
-        if(fileHeader.offset == FileHeaderOffsetOfBF32V4)// 0x7A
+        if(fileHeader.offset == FileHeaderOffsetOfBF32V4) // 0x7A
         {
           customizedFormat = BMP_BITFIELDS32V4;
         }
@@ -1173,84 +1165,84 @@ bool LoadBitmapFromBmp( const ImageLoader::Input& input, Dali::Devel::PixelBuffe
       break;
     }
     default:
-      DALI_LOG_WARNING("Compression not supported for BMP files\n");
+      DALI_LOG_ERROR("Compression not supported for BMP files\n");
       return false;
   }
 
   bool topDown = false;
 
   // if height is negative, bitmap data is top down
-  if (infoHeader.height<0)
+  if(infoHeader.height < 0)
   {
-    infoHeader.height =  abs(infoHeader.height);
-    height = infoHeader.height;
-    topDown = true;
+    infoHeader.height = abs(infoHeader.height);
+    height            = infoHeader.height;
+    topDown           = true;
   }
 
-  unsigned int rowStride = infoHeader.width * (infoHeader.bitsPerPixel >>3);
+  unsigned int rowStride = infoHeader.width * (infoHeader.bitsPerPixel >> 3);
 
   // bitmaps row stride is padded to 4 bytes
   unsigned int padding = (rowStride % 4);
-  if (padding)
+  if(padding)
   {
     padding = 4 - padding;
   }
 
-  int imageW = infoHeader.width;
-  int pixelBufferW = infoHeader.width;
-  int pixelBufferH = infoHeader.height;
+  int  imageW         = infoHeader.width;
+  int  pixelBufferW   = infoHeader.width;
+  int  pixelBufferH   = infoHeader.height;
   auto newPixelFormat = Pixel::Format::INVALID;
 
   switch(customizedFormat)
   {
-  case BMP_RLE8:
-  case BMP_RGB8:
-  case BMP_RGB4:
-  case BMP_RLE4:
-  case BMP_RGB555:
-  case BMP_BITFIELDS555:
-  {
-    pixelBufferW = ((imageW & 3) != 0) ? imageW + 4 - (imageW & 3) : imageW;
-    pixelBufferH = abs(infoHeader.height);
-    newPixelFormat = Pixel::RGB888;
-    break;
-  }
-  case BMP_RGB1:
-  {
-    pixelBufferW = ((imageW & 63) != 0) ? imageW + 64 - (imageW & 63) : imageW;
-    pixelBufferH = abs(infoHeader.height);
-    newPixelFormat = Pixel::RGB888;
-    break;
-  }
-  case BMP_BITFIELDS32:
-  case BMP_BITFIELDS32V4:
-  {
-    pixelBufferH = abs(infoHeader.height);
-    newPixelFormat = Pixel::RGB8888;
-    break;
-  }
-  case BMP_RGB24V5:
-  {
-    newPixelFormat = Pixel::RGB888;
-    break;
-  }
-  default:
-    if(pixelFormat == Pixel::RGB565 )
+    case BMP_RLE8:
+    case BMP_RGB8:
+    case BMP_RGB4:
+    case BMP_RLE4:
+    case BMP_RGB555:
+    case BMP_BITFIELDS555:
     {
-      pixelBufferW = ((imageW & 3) != 0) ? imageW + 4 - (imageW & 3) : imageW;
-      pixelBufferH = abs(infoHeader.height);
-      newPixelFormat = Pixel::RGB565;
+      pixelBufferW   = ((imageW & 3) != 0) ? imageW + 4 - (imageW & 3) : imageW;
+      pixelBufferH   = abs(infoHeader.height);
+      newPixelFormat = Pixel::RGB888;
+      break;
     }
-    else
+    case BMP_RGB1:
+    {
+      pixelBufferW   = ((imageW & 63) != 0) ? imageW + 64 - (imageW & 63) : imageW;
+      pixelBufferH   = abs(infoHeader.height);
+      newPixelFormat = Pixel::RGB888;
+      break;
+    }
+    case BMP_BITFIELDS32:
+    case BMP_BITFIELDS32V4:
+    {
+      pixelBufferH   = abs(infoHeader.height);
+      newPixelFormat = Pixel::RGB8888;
+      break;
+    }
+    case BMP_RGB24V5:
     {
-      pixelBufferW = infoHeader.width;
-      pixelBufferH = infoHeader.height;
-      newPixelFormat = pixelFormat;
+      newPixelFormat = Pixel::RGB888;
+      break;
     }
-    break;
+    default:
+      if(pixelFormat == Pixel::RGB565)
+      {
+        pixelBufferW   = ((imageW & 3) != 0) ? imageW + 4 - (imageW & 3) : imageW;
+        pixelBufferH   = abs(infoHeader.height);
+        newPixelFormat = Pixel::RGB565;
+      }
+      else
+      {
+        pixelBufferW   = infoHeader.width;
+        pixelBufferH   = infoHeader.height;
+        newPixelFormat = pixelFormat;
+      }
+      break;
   }
 
-  bitmap = Dali::Devel::PixelBuffer::New(pixelBufferW, pixelBufferH, newPixelFormat);
+  bitmap      = Dali::Devel::PixelBuffer::New(pixelBufferW, pixelBufferH, newPixelFormat);
   auto pixels = bitmap.GetBuffer();
 
   // Read the raw bitmap data
@@ -1261,7 +1253,7 @@ bool LoadBitmapFromBmp( const ImageLoader::Input& input, Dali::Devel::PixelBuffe
   {
     case BMP_RGB1:
     {
-      decodeResult = DecodeRGB1( fp, pixels, infoHeader.width, abs(infoHeader.height), 14 + infoHeader.infoHeaderSize, topDown);
+      decodeResult = DecodeRGB1(fp, pixels, infoHeader.width, abs(infoHeader.height), 14 + infoHeader.infoHeaderSize, topDown);
       break;
     }
     case BMP_RGB4:
@@ -1271,17 +1263,17 @@ bool LoadBitmapFromBmp( const ImageLoader::Input& input, Dali::Devel::PixelBuffe
     }
     case BMP_RLE4:
     {
-      decodeResult = DecodeRLE4( fp, pixels, infoHeader.width, abs(infoHeader.height), 14 + infoHeader.infoHeaderSize, topDown);
+      decodeResult = DecodeRLE4(fp, pixels, infoHeader.width, abs(infoHeader.height), 14 + infoHeader.infoHeaderSize, topDown);
       break;
     }
     case BMP_BITFIELDS32:
     {
-      decodeResult = DecodeBF32(fp, pixels, infoHeader.width,  abs(infoHeader.height), fileHeader.offset, topDown, rowStride, padding);
+      decodeResult = DecodeBF32(fp, pixels, infoHeader.width, abs(infoHeader.height), fileHeader.offset, topDown, rowStride, padding);
       break;
     }
     case BMP_BITFIELDS555:
     {
-      decodeResult = DecodeBF555(fp, pixels,infoHeader.width,  abs(infoHeader.height), fileHeader.offset, topDown);
+      decodeResult = DecodeBF555(fp, pixels, infoHeader.width, abs(infoHeader.height), fileHeader.offset, topDown);
       break;
     }
     case BMP_RGB555:
@@ -1313,24 +1305,24 @@ bool LoadBitmapFromBmp( const ImageLoader::Input& input, Dali::Devel::PixelBuffe
     {
       if(pixelFormat == Pixel::RGB565)
       {
-        decodeResult = DecodeBF565(fp, pixels, infoHeader.width, abs(infoHeader.height), fileHeader.offset,  topDown);
+        decodeResult = DecodeBF565(fp, pixels, infoHeader.width, abs(infoHeader.height), fileHeader.offset, topDown);
       }
       else
       {
-        for (unsigned int yPos = 0; yPos < height; yPos++)
+        for(unsigned int yPos = 0; yPos < height; yPos++)
         {
-          if (topDown)
+          if(topDown)
           {
             // the data in the file is top down, and we store the data top down
-            pixelsIterator = pixels + ( yPos * rowStride);
+            pixelsIterator = pixels + (yPos * rowStride);
           }
           else
           {
             // the data in the file is bottom up, and we store the data top down
-            pixelsIterator = pixels + (((height-1)-yPos) * rowStride);
+            pixelsIterator = pixels + (((height - 1) - yPos) * rowStride);
           }
 
-          if (fread(pixelsIterator, 1, rowStride, fp) != rowStride)
+          if(DALI_UNLIKELY(fread(pixelsIterator, 1, rowStride, fp) != rowStride))
           {
             DALI_LOG_ERROR("Error reading the BMP image\n");
             break;
@@ -1338,19 +1330,19 @@ bool LoadBitmapFromBmp( const ImageLoader::Input& input, Dali::Devel::PixelBuffe
 
           // If 24 bit mode then swap Blue and Red pixels
           // BGR888 doesn't seem to be supported by dali-core
-          if (infoHeader.bitsPerPixel == 24 )
+          if(infoHeader.bitsPerPixel == 24)
           {
             for(unsigned int i = 0; i < rowStride; i += 3)
             {
-              unsigned char temp = pixelsIterator[i];
-              pixelsIterator[i] = pixelsIterator[i+2];
-              pixelsIterator[i+2] = temp;
+              unsigned char temp    = pixelsIterator[i];
+              pixelsIterator[i]     = pixelsIterator[i + 2];
+              pixelsIterator[i + 2] = temp;
             }
           }
 
-          if (padding)
+          if(padding)
           {
-            if( fseek(fp, padding, SEEK_CUR) )  // move past the padding.
+            if(DALI_UNLIKELY(fseek(fp, padding, SEEK_CUR))) // move past the padding.
             {
               DALI_LOG_ERROR("Error moving past BMP padding\n");
             }
@@ -1362,8 +1354,9 @@ bool LoadBitmapFromBmp( const ImageLoader::Input& input, Dali::Devel::PixelBuffe
     }
   } // switch
 
-  if( !decodeResult )
+  if(DALI_UNLIKELY(!decodeResult))
   {
+    DALI_LOG_ERROR("Decoding failed\n");
     return false;
   }