Support SamplingMode::LANCZOS and SamplingMode::BOX_THEN_LANCZOS 93/317993/3
authorEunki, Hong <eunkiki.hong@samsung.com>
Mon, 23 Sep 2024 07:27:27 +0000 (16:27 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Tue, 24 Sep 2024 13:08:07 +0000 (22:08 +0900)
TODO : LanczosSample support only for 1BPP and 4BPP.
Until support it with various pixel format, just use LinearSample instead.

Change-Id: I7c42859987964397fa7dfd2d2ee565e16cd61832
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
automated-tests/src/dali-adaptor-internal/utc-Dali-ImageOperations.cpp
dali/internal/imaging/common/image-operations.cpp
dali/internal/imaging/common/loader-jpeg-turbo.cpp

index 6c54a622e46e56b0116b009a97282a2e04d8be39..93e39bca5f4764cb4a895726b0b3c6e7bd1a578c 100644 (file)
@@ -342,6 +342,8 @@ int UtcDaliImageOperationsAveragePixelRGB565(void)
   END_TEST;
 }
 
+namespace
+{
 /**
  * @brief Build a square bitmap, downscale it and assert the resulting bitmap has the right dimensions.
  */
@@ -365,6 +367,99 @@ void TestDownscaledBitmapHasRightDimensionsAndFormat(
   DALI_TEST_EQUALS(downScaled.GetPixelFormat(), format, location);
 }
 
+/**
+ * @brief Test that resizing RGBA8888 images as raw pixel arrays produces a result of the correct dimensions.
+ */
+void TestDownscaleOutputsExpectedDimensionsRGBA8888(uint32_t pixels[], unsigned inputWidth, unsigned inputHeight, unsigned int desiredWidth, unsigned int desiredHeight, unsigned int expectedWidth, unsigned int expectedHeight, const char* const location)
+{
+  unsigned int resultingWidth = -1, resultingHeight = -1, resultingStride = -1;
+  Dali::Internal::Platform::DownscaleInPlacePow2RGBA8888(
+    reinterpret_cast<unsigned char*>(pixels),
+    inputWidth,
+    inputHeight,
+    inputWidth,
+    desiredWidth,
+    desiredHeight,
+    BoxDimensionTestBoth,
+    resultingWidth,
+    resultingHeight,
+    resultingStride);
+
+  DALI_TEST_EQUALS(resultingWidth, expectedWidth, location);
+  DALI_TEST_EQUALS(resultingHeight, expectedHeight, location);
+  DALI_TEST_EQUALS(resultingStride, expectedWidth, location);
+}
+
+/**
+ * @brief Test that resizing RGB565 images as raw pixel arrays produces a result of the correct dimensions.
+ */
+void TestDownscaleOutputsExpectedDimensionsRGB565(uint16_t pixels[], unsigned inputWidth, unsigned inputHeight, unsigned int desiredWidth, unsigned int desiredHeight, unsigned int expectedWidth, unsigned int expectedHeight, const char* const location)
+{
+  unsigned int resultingWidth = -1, resultingHeight = -1, resultingStride = -1;
+  Dali::Internal::Platform::DownscaleInPlacePow2RGB565(
+    reinterpret_cast<unsigned char*>(pixels),
+    inputWidth,
+    inputHeight,
+    inputWidth,
+    desiredWidth,
+    desiredHeight,
+    BoxDimensionTestBoth,
+    resultingWidth,
+    resultingHeight,
+    resultingStride);
+
+  DALI_TEST_EQUALS(resultingWidth, expectedWidth, location);
+  DALI_TEST_EQUALS(resultingHeight, expectedHeight, location);
+  DALI_TEST_EQUALS(resultingStride, expectedWidth, location);
+}
+
+/**
+ * @brief Test that resizing 2-byte-per-pixel images as raw pixel arrays produces a result of the correct dimensions.
+ */
+void TestDownscaleOutputsExpectedDimensions2ComponentPair(uint8_t pixels[], unsigned inputWidth, unsigned inputHeight, unsigned int desiredWidth, unsigned int desiredHeight, unsigned int expectedWidth, unsigned int expectedHeight, const char* const location)
+{
+  unsigned int resultingWidth = -1, resultingHeight = -1, resultingStride = -1;
+  Dali::Internal::Platform::DownscaleInPlacePow2ComponentPair(
+    pixels,
+    inputWidth,
+    inputHeight,
+    inputWidth,
+    desiredWidth,
+    desiredHeight,
+    BoxDimensionTestBoth,
+    resultingWidth,
+    resultingHeight,
+    resultingStride);
+
+  DALI_TEST_EQUALS(resultingWidth, expectedWidth, location);
+  DALI_TEST_EQUALS(resultingHeight, expectedHeight, location);
+  DALI_TEST_EQUALS(resultingStride, expectedWidth, location);
+}
+
+/**
+ * @brief Test that resizing single-byte-per-pixel images as raw pixel arrays produces a result of the correct dimensions.
+ */
+void TestDownscaleOutputsExpectedDimensionsSingleComponent(uint8_t pixels[], unsigned inputWidth, unsigned inputHeight, unsigned int desiredWidth, unsigned int desiredHeight, unsigned int expectedWidth, unsigned int expectedHeight, const char* const location)
+{
+  unsigned int resultingWidth = -1, resultingHeight = -1, resultingStride = -1;
+  Dali::Internal::Platform::DownscaleInPlacePow2SingleBytePerPixel(
+    pixels,
+    inputWidth,
+    inputHeight,
+    inputWidth,
+    desiredWidth,
+    desiredHeight,
+    BoxDimensionTestBoth,
+    resultingWidth,
+    resultingHeight,
+    resultingStride);
+
+  DALI_TEST_EQUALS(resultingWidth, expectedWidth, location);
+  DALI_TEST_EQUALS(resultingHeight, expectedHeight, location);
+  DALI_TEST_EQUALS(resultingStride, expectedWidth, location);
+}
+} // namespace
+
 /**
  * @brief Test the top-level function for reducing the dimension of a bitmap,
  * feeding it each of the five pixel formats that are output by image loaders.
@@ -502,98 +597,6 @@ int UtcDaliImageOperationsDownscaleInPlacePow2RGB888(void)
   END_TEST;
 }
 
-/**
- * @brief Test that resizing RGBA8888 images as raw pixel arrays produces a result of the correct dimensions.
- */
-void TestDownscaleOutputsExpectedDimensionsRGBA8888(uint32_t pixels[], unsigned inputWidth, unsigned inputHeight, unsigned int desiredWidth, unsigned int desiredHeight, unsigned int expectedWidth, unsigned int expectedHeight, const char* const location)
-{
-  unsigned int resultingWidth = -1, resultingHeight = -1, resultingStride = -1;
-  Dali::Internal::Platform::DownscaleInPlacePow2RGBA8888(
-    reinterpret_cast<unsigned char*>(pixels),
-    inputWidth,
-    inputHeight,
-    inputWidth,
-    desiredWidth,
-    desiredHeight,
-    BoxDimensionTestBoth,
-    resultingWidth,
-    resultingHeight,
-    resultingStride);
-
-  DALI_TEST_EQUALS(resultingWidth, expectedWidth, location);
-  DALI_TEST_EQUALS(resultingHeight, expectedHeight, location);
-  DALI_TEST_EQUALS(resultingStride, expectedWidth, location);
-}
-
-/**
- * @brief Test that resizing RGB565 images as raw pixel arrays produces a result of the correct dimensions.
- */
-void TestDownscaleOutputsExpectedDimensionsRGB565(uint16_t pixels[], unsigned inputWidth, unsigned inputHeight, unsigned int desiredWidth, unsigned int desiredHeight, unsigned int expectedWidth, unsigned int expectedHeight, const char* const location)
-{
-  unsigned int resultingWidth = -1, resultingHeight = -1, resultingStride = -1;
-  Dali::Internal::Platform::DownscaleInPlacePow2RGB565(
-    reinterpret_cast<unsigned char*>(pixels),
-    inputWidth,
-    inputHeight,
-    inputWidth,
-    desiredWidth,
-    desiredHeight,
-    BoxDimensionTestBoth,
-    resultingWidth,
-    resultingHeight,
-    resultingStride);
-
-  DALI_TEST_EQUALS(resultingWidth, expectedWidth, location);
-  DALI_TEST_EQUALS(resultingHeight, expectedHeight, location);
-  DALI_TEST_EQUALS(resultingStride, expectedWidth, location);
-}
-
-/**
- * @brief Test that resizing 2-byte-per-pixel images as raw pixel arrays produces a result of the correct dimensions.
- */
-void TestDownscaleOutputsExpectedDimensions2ComponentPair(uint8_t pixels[], unsigned inputWidth, unsigned inputHeight, unsigned int desiredWidth, unsigned int desiredHeight, unsigned int expectedWidth, unsigned int expectedHeight, const char* const location)
-{
-  unsigned int resultingWidth = -1, resultingHeight = -1, resultingStride = -1;
-  Dali::Internal::Platform::DownscaleInPlacePow2ComponentPair(
-    pixels,
-    inputWidth,
-    inputHeight,
-    inputWidth,
-    desiredWidth,
-    desiredHeight,
-    BoxDimensionTestBoth,
-    resultingWidth,
-    resultingHeight,
-    resultingStride);
-
-  DALI_TEST_EQUALS(resultingWidth, expectedWidth, location);
-  DALI_TEST_EQUALS(resultingHeight, expectedHeight, location);
-  DALI_TEST_EQUALS(resultingStride, expectedWidth, location);
-}
-
-/**
- * @brief Test that resizing single-byte-per-pixel images as raw pixel arrays produces a result of the correct dimensions.
- */
-void TestDownscaleOutputsExpectedDimensionsSingleComponent(uint8_t pixels[], unsigned inputWidth, unsigned inputHeight, unsigned int desiredWidth, unsigned int desiredHeight, unsigned int expectedWidth, unsigned int expectedHeight, const char* const location)
-{
-  unsigned int resultingWidth = -1, resultingHeight = -1, resultingStride = -1;
-  Dali::Internal::Platform::DownscaleInPlacePow2SingleBytePerPixel(
-    pixels,
-    inputWidth,
-    inputHeight,
-    inputWidth,
-    desiredWidth,
-    desiredHeight,
-    BoxDimensionTestBoth,
-    resultingWidth,
-    resultingHeight,
-    resultingStride);
-
-  DALI_TEST_EQUALS(resultingWidth, expectedWidth, location);
-  DALI_TEST_EQUALS(resultingHeight, expectedHeight, location);
-  DALI_TEST_EQUALS(resultingStride, expectedWidth, location);
-}
-
 /**
  * @brief Test downscaling of RGBA8888 images in raw image arrays.
  */
index 8a20af1f51fd5202e45017d746043164a7cb313f..13ef4f53b3be1ee506b81db756e65945a127ac4e 100644 (file)
@@ -466,25 +466,25 @@ ImageDimensions CalculateDesiredDimensions(uint32_t bitmapWidth, uint32_t bitmap
   // If both dimensions have values requested, use them both:
   if(requestedWidth != 0 && requestedHeight != 0)
   {
-    DALI_ASSERT_DEBUG( (bitmapWidth > 0 && bitmapHeight > 0) && "Bitmap dimensions are zero");
+    DALI_ASSERT_DEBUG((bitmapWidth > 0 && bitmapHeight > 0) && "Bitmap dimensions are zero");
 
     if(fittingMode == FittingMode::VISUAL_FITTING)
     {
       uint32_t adjustedDesiredWidth, adjustedDesiredHeight;
-      float aspectOfDesiredSize = (float)requestedHeight / (float)requestedWidth;
-      float aspectOfImageSize = (float)bitmapHeight / (float)bitmapWidth;
-      if (aspectOfImageSize > aspectOfDesiredSize)
+      float    aspectOfDesiredSize = (float)requestedHeight / (float)requestedWidth;
+      float    aspectOfImageSize   = (float)bitmapHeight / (float)bitmapWidth;
+      if(aspectOfImageSize > aspectOfDesiredSize)
       {
-        adjustedDesiredWidth = requestedWidth;
+        adjustedDesiredWidth  = requestedWidth;
         adjustedDesiredHeight = (static_cast<uint64_t>(bitmapHeight) * requestedWidth + bitmapWidth / 2) / bitmapWidth; ///< round up
       }
       else
       {
-        adjustedDesiredWidth = (static_cast<uint64_t>(bitmapWidth) * requestedHeight + bitmapHeight / 2) / bitmapHeight; ///< round up
+        adjustedDesiredWidth  = (static_cast<uint64_t>(bitmapWidth) * requestedHeight + bitmapHeight / 2) / bitmapHeight; ///< round up
         adjustedDesiredHeight = requestedHeight;
       }
 
-      requestedWidth = adjustedDesiredWidth;
+      requestedWidth  = adjustedDesiredWidth;
       requestedHeight = adjustedDesiredHeight;
     }
 
@@ -1173,6 +1173,7 @@ Dali::Devel::PixelBuffer DownscaleBitmap(Dali::Devel::PixelBuffer bitmap,
     if(filteredWidth < shrunkWidth || filteredHeight < shrunkHeight)
     {
       if(samplingMode == SamplingMode::LINEAR || samplingMode == SamplingMode::BOX_THEN_LINEAR ||
+         samplingMode == SamplingMode::LANCZOS || samplingMode == SamplingMode::BOX_THEN_LANCZOS ||
          samplingMode == SamplingMode::NEAREST || samplingMode == SamplingMode::BOX_THEN_NEAREST)
       {
         outputBitmap = Dali::Devel::PixelBuffer::New(filteredWidth, filteredHeight, pixelFormat);
@@ -1183,6 +1184,19 @@ Dali::Devel::PixelBuffer DownscaleBitmap(Dali::Devel::PixelBuffer bitmap,
           {
             LinearSample(bitmap.GetBuffer(), ImageDimensions(shrunkWidth, shrunkHeight), outStride, pixelFormat, outputBitmap.GetBuffer(), filteredDimensions);
           }
+          else if(samplingMode == SamplingMode::LANCZOS || samplingMode == SamplingMode::BOX_THEN_LANCZOS)
+          {
+            // TODO : Need to support LanczosSample various pixel format.
+            // Until now, just use LinearSample instead.
+            if(pixelFormat == Pixel::RGBA8888 || pixelFormat == Pixel::BGRA8888 || pixelFormat == Pixel::L8 || pixelFormat == Pixel::A8)
+            {
+              LanczosSample(bitmap.GetBuffer(), ImageDimensions(shrunkWidth, shrunkHeight), outStride, pixelFormat, outputBitmap.GetBuffer(), filteredDimensions);
+            }
+            else
+            {
+              LinearSample(bitmap.GetBuffer(), ImageDimensions(shrunkWidth, shrunkHeight), outStride, pixelFormat, outputBitmap.GetBuffer(), filteredDimensions);
+            }
+          }
           else
           {
             PointSample(bitmap.GetBuffer(), shrunkWidth, shrunkHeight, outStride, pixelFormat, outputBitmap.GetBuffer(), filteredWidth, filteredHeight);
@@ -1660,7 +1674,7 @@ void DownscaleInPlacePow2(uint8_t* const     pixels,
   outHeight = inputHeight;
   outStride = inputStride;
   // Perform power of 2 iterated 4:1 box filtering if the requested filter mode requires it:
-  if(samplingMode == SamplingMode::BOX || samplingMode == SamplingMode::BOX_THEN_NEAREST || samplingMode == SamplingMode::BOX_THEN_LINEAR)
+  if(samplingMode == SamplingMode::BOX || samplingMode == SamplingMode::BOX_THEN_NEAREST || samplingMode == SamplingMode::BOX_THEN_LINEAR || samplingMode == SamplingMode::BOX_THEN_LANCZOS)
   {
     // Check the pixel format is one that is supported:
     if(pixelFormat == Pixel::RGBA8888 || pixelFormat == Pixel::RGB888 || pixelFormat == Pixel::RGB565 || pixelFormat == Pixel::LA88 || pixelFormat == Pixel::L8 || pixelFormat == Pixel::A8 || pixelFormat == Pixel::CHROMINANCE_U || pixelFormat == Pixel::CHROMINANCE_V)
index 6cf24cea997dd3826be238cf1f41e448eee5b5e3..1a1d5ab7654208eea99bc6470ae6a08e3babc11a 100644 (file)
@@ -1206,6 +1206,7 @@ bool TransformSize(int requiredWidth, int requiredHeight, FittingMode::Type fitt
       case SamplingMode::BOX:
       case SamplingMode::BOX_THEN_NEAREST:
       case SamplingMode::BOX_THEN_LINEAR:
+      case SamplingMode::BOX_THEN_LANCZOS:
       case SamplingMode::DONT_CARE:
       {
         useTurboJpegScaleFactor = true;
@@ -1214,6 +1215,7 @@ bool TransformSize(int requiredWidth, int requiredHeight, FittingMode::Type fitt
       case SamplingMode::NO_FILTER:
       case SamplingMode::NEAREST:
       case SamplingMode::LINEAR:
+      case SamplingMode::LANCZOS:
       {
         useTurboJpegScaleFactor = false;
         break;