Let ignore 32bit bmp format ignore alpha force 31/289631/3
authorEunki Hong <eunkiki.hong@samsung.com>
Fri, 10 Mar 2023 13:28:26 +0000 (22:28 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Mon, 13 Mar 2023 08:34:14 +0000 (17:34 +0900)
Change-Id: I0d9521088ebb4cb9a1cf1cd822f828bc09745298
Signed-off-by: Eunki Hong <eunkiki.hong@samsung.com>
automated-tests/images/test_32bpp.bmp [new file with mode: 0644]
automated-tests/images/test_32bpp.bmp.buffer [new file with mode: 0644]
automated-tests/src/dali-adaptor-internal/utc-Dali-BmpLoader.cpp
dali/internal/imaging/common/loader-bmp.cpp

diff --git a/automated-tests/images/test_32bpp.bmp b/automated-tests/images/test_32bpp.bmp
new file mode 100644 (file)
index 0000000..9524f76
Binary files /dev/null and b/automated-tests/images/test_32bpp.bmp differ
diff --git a/automated-tests/images/test_32bpp.bmp.buffer b/automated-tests/images/test_32bpp.bmp.buffer
new file mode 100644 (file)
index 0000000..186b0e3
Binary files /dev/null and b/automated-tests/images/test_32bpp.bmp.buffer differ
index 7babde8..fcbbcd7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -38,6 +38,16 @@ int UtcDaliBmp24bpp(void)
 
   END_TEST;
 }
+int UtcDaliBmp32bpp(void)
+{
+  ImageDetails image(TEST_IMAGE_DIR "/test_32bpp.bmp", 127u, 64u);
+
+  // Note : Currently we hard-overrite alpha channel as 255.
+  // Please fix UTC if we change current policy.
+  TestImageLoading(image, BmpLoaders);
+
+  END_TEST;
+}
 int UtcDaliBmpRGB8(void)
 {
   ImageDetails image(TEST_IMAGE_DIR "/w3c_home_256.bmp", 72u, 48u);
index fe108c3..a01d076 100644 (file)
@@ -1070,13 +1070,17 @@ bool LoadBitmapFromBmp(const Dali::ImageLoader::Input& input, Dali::Devel::Pixel
   switch(infoHeader.compression)
   {
     case 0:
+    {
       switch(infoHeader.bitsPerPixel)
       {
         case 32:
-          pixelFormat = Pixel::BGR8888;
+        {
+          pixelFormat = Pixel::RGBA8888;
           break;
+        }
 
         case 24:
+        {
           if(fileHeader.offset == FileHeaderOffsetOfRGB24V5) //0x8A
           {
             customizedFormat = BMP_RGB24V5;
@@ -1086,27 +1090,40 @@ bool LoadBitmapFromBmp(const Dali::ImageLoader::Input& input, Dali::Devel::Pixel
             pixelFormat = Pixel::RGB888;
           }
           break;
+        }
 
         case 16:
+        {
           customizedFormat = BMP_RGB555;
           break;
+        }
 
         case 8:
+        {
           customizedFormat = BMP_RGB8;
           break;
+        }
 
         case 4: // RGB4
+        {
           customizedFormat = BMP_RGB4;
           break;
+        }
 
         case 1: //RGB1
+        {
           customizedFormat = BMP_RGB1;
           break;
+        }
+
         default:
+        {
           DALI_LOG_ERROR("%d bits per pixel not supported for BMP files\n", infoHeader.bitsPerPixel);
           return false;
+        }
       }
       break;
+    }
     case 1: //// RLE8
     {
       if(infoHeader.bitsPerPixel == 8)
@@ -1165,8 +1182,10 @@ bool LoadBitmapFromBmp(const Dali::ImageLoader::Input& input, Dali::Devel::Pixel
       break;
     }
     default:
+    {
       DALI_LOG_ERROR("Compression not supported for BMP files\n");
       return false;
+    }
   }
 
   bool topDown = false;
@@ -1218,7 +1237,7 @@ bool LoadBitmapFromBmp(const Dali::ImageLoader::Input& input, Dali::Devel::Pixel
     case BMP_BITFIELDS32V4:
     {
       pixelBufferH   = abs(infoHeader.height);
-      newPixelFormat = Pixel::RGB8888;
+      newPixelFormat = Pixel::RGBA8888;
       break;
     }
     case BMP_RGB24V5:
@@ -1227,6 +1246,7 @@ bool LoadBitmapFromBmp(const Dali::ImageLoader::Input& input, Dali::Devel::Pixel
       break;
     }
     default:
+    {
       if(pixelFormat == Pixel::RGB565)
       {
         pixelBufferW   = ((imageW & 3) != 0) ? imageW + 4 - (imageW & 3) : imageW;
@@ -1240,6 +1260,7 @@ bool LoadBitmapFromBmp(const Dali::ImageLoader::Input& input, Dali::Devel::Pixel
         newPixelFormat = pixelFormat;
       }
       break;
+    }
   }
 
   bitmap      = Dali::Devel::PixelBuffer::New(pixelBufferW, pixelBufferH, newPixelFormat);
@@ -1328,13 +1349,28 @@ bool LoadBitmapFromBmp(const Dali::ImageLoader::Input& input, Dali::Devel::Pixel
             break;
           }
 
+          // If 32 bit mode then swap Blue and Red pixels. And Alpha pixels must be ignored.
+          // Reference : https://users.cs.fiu.edu/~czhang/teaching/cop4225/project_files/bitmap_format.htm
+          // ... if the compression field of the bitmap is set to bi_rgb, ... the high byte in each dword is not used.
+          // RGB8888 format doesn't seem to be supported by graphics-api
+          if(infoHeader.bitsPerPixel == 32)
+          {
+            for(unsigned int i = 0; i < rowStride; i += 4)
+            {
+              uint8_t temp          = pixelsIterator[i];
+              pixelsIterator[i]     = pixelsIterator[i + 2];
+              pixelsIterator[i + 2] = temp;
+              pixelsIterator[i + 3] = 255u;
+            }
+          }
+
           // If 24 bit mode then swap Blue and Red pixels
           // BGR888 doesn't seem to be supported by dali-core
           if(infoHeader.bitsPerPixel == 24)
           {
             for(unsigned int i = 0; i < rowStride; i += 3)
             {
-              unsigned char temp    = pixelsIterator[i];
+              uint8_t temp          = pixelsIterator[i];
               pixelsIterator[i]     = pixelsIterator[i + 2];
               pixelsIterator[i + 2] = temp;
             }