Fix pixel format bug in pixel manipulation 83/247583/2
authorHeeyong Song <heeyong.song@samsung.com>
Thu, 12 Nov 2020 07:19:38 +0000 (16:19 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Fri, 13 Nov 2020 05:40:57 +0000 (14:40 +0900)
LUMINANCE should be first in LUMINANCE_ALPHA_CHANNELS format.

Change-Id: Ia9bef6173f24a54d7fc8140381affa5a342e3e1e

automated-tests/images/circle1-LA88.png [new file with mode: 0644]
automated-tests/src/dali-adaptor-internal/utc-Dali-Internal-PixelBuffer.cpp
dali/internal/imaging/common/pixel-manipulation.cpp

diff --git a/automated-tests/images/circle1-LA88.png b/automated-tests/images/circle1-LA88.png
new file mode 100644 (file)
index 0000000..a958733
Binary files /dev/null and b/automated-tests/images/circle1-LA88.png differ
index 8a323ba..dcc6a3a 100644 (file)
 // Internal headers are allowed here
 
 #include <dali/internal/imaging/common/pixel-manipulation.h>
+#include <dali/devel-api/adaptor-framework/image-loading.h>
 
 using namespace Dali;
 using namespace Dali::Internal::Adaptor;
+
+namespace
+{
+
+// resolution: 96*96, pixel format: LA88
+const char* TEST_IMAGE_LA88 = TEST_IMAGE_DIR "/circle1-LA88.png";
+
+} // namespace
+
 void utc_dali_internal_pixel_data_startup()
 {
   test_return_value = TET_UNDEF;
@@ -167,6 +177,38 @@ int UtcDaliPixelManipulation02(void)
   END_TEST;
 }
 
+int UtcDaliPixelManipulationLA88(void)
+{
+  tet_infoline("Testing Dali::Internal::AdaptorManipulation Read/WriteChannel - LA88 format");
+
+  Devel::PixelBuffer pixelBuffer = Dali::LoadImageFromFile(TEST_IMAGE_LA88);
+  DALI_TEST_CHECK(pixelBuffer);
+
+  unsigned int width = pixelBuffer.GetWidth();
+  unsigned int height = pixelBuffer.GetHeight();
+  DALI_TEST_EQUALS(width, 96u, TEST_LOCATION);
+  DALI_TEST_EQUALS(height, 96u, TEST_LOCATION);
+  DALI_TEST_EQUALS(pixelBuffer.GetPixelFormat(), Pixel::LA88, TEST_LOCATION);
+
+  unsigned char* pixel = pixelBuffer.GetBuffer();
+  unsigned int value;
+
+  value = Dali::Internal::Adaptor::ReadChannel(&pixel[0], Dali::Pixel::LA88, Dali::Internal::Adaptor::LUMINANCE);
+  DALI_TEST_EQUALS(value, 0x0, TEST_LOCATION);
+  value = Dali::Internal::Adaptor::ReadChannel(&pixel[0], Dali::Pixel::LA88, Dali::Internal::Adaptor::ALPHA);
+  DALI_TEST_EQUALS(value, 0x0, TEST_LOCATION);
+
+  // Get center pixel
+  unsigned int stride = width * Pixel::GetBytesPerPixel(Dali::Pixel::LA88);
+  unsigned int center = height / 2 * stride + width / 2 * Pixel::GetBytesPerPixel(Dali::Pixel::LA88);
+  value = Dali::Internal::Adaptor::ReadChannel(&pixel[center], Dali::Pixel::LA88, Dali::Internal::Adaptor::LUMINANCE);
+  DALI_TEST_EQUALS(value, 0x0, TEST_LOCATION);
+  value = Dali::Internal::Adaptor::ReadChannel(&pixel[center], Dali::Pixel::LA88, Dali::Internal::Adaptor::ALPHA);
+  DALI_TEST_EQUALS(value, 0xFF, TEST_LOCATION);
+
+  END_TEST;
+}
+
 int UtcDaliPixelManipulation03N(void)
 {
   tet_infoline("Testing Dali::Internal::AdaptorManipulation Read/WriteChannel");
index fa5094a..fff8604 100644 (file)
@@ -33,7 +33,7 @@ namespace
 
 constexpr Channel ALPHA_CHANNEL_ONLY[]       = {ALPHA};
 constexpr Channel LUMINANCE_CHANNEL_ONLY[]   = {LUMINANCE};
-constexpr Channel LUMINANCE_ALPHA_CHANNELS[] = {ALPHA, LUMINANCE};
+constexpr Channel LUMINANCE_ALPHA_CHANNELS[] = {LUMINANCE, ALPHA};
 constexpr Channel RGB_CHANNELS[]             = {RED, GREEN, BLUE};
 constexpr Channel BGR_CHANNELS[]             = {BLUE, GREEN, RED};
 constexpr Channel RGBA_CHANNELS[]            = {RED, GREEN, BLUE, ALPHA};