Revert "[4.0] Fix SVACE issues"
[platform/core/uifw/dali-adaptor.git] / platform-abstractions / portable / image-operations.cpp
index f759d39..2c5da3b 100644 (file)
@@ -50,7 +50,6 @@ const unsigned int MAXIMUM_TARGET_BITMAP_SIZE( ( 1u << 16 ) - 1 );
 // Constants used by the ImageResampler.
 const float DEFAULT_SOURCE_GAMMA = 1.75f;   ///< Default source gamma value used in the Resampler() function. Partial gamma correction looks better on mips. Set to 1.0 to disable gamma correction.
 const float FILTER_SCALE = 1.f;             ///< Default filter scale value used in the Resampler() function. Filter scale - values < 1.0 cause aliasing, but create sharper looking mips.
-const Resampler::Filter FILTER_TYPE = Resampler::LANCZOS4; ///< Default filter used in the Resampler() function. Possible Lanczos filters are: lanczos3, lanczos4, lanczos6, lanczos12
 
 using Integration::Bitmap;
 using Integration::BitmapPtr;
@@ -455,13 +454,43 @@ ImageDimensions CalculateDesiredDimensions( unsigned int bitmapWidth, unsigned i
   // If no dimensions have been requested, default to the source ones:
   if( requestedWidth == 0 && requestedHeight == 0 )
   {
-    return ImageDimensions( std::min( bitmapWidth, maxSize ), std::min( bitmapHeight, maxSize ) );
+    if( bitmapWidth <= maxSize && bitmapHeight <= maxSize )
+    {
+      return ImageDimensions( bitmapWidth, bitmapHeight );
+    }
+    else
+    {
+      // Calculate the size from the max texture size and the source image aspect ratio
+      if( bitmapWidth > bitmapHeight )
+      {
+        return ImageDimensions( maxSize, bitmapHeight * maxSize / static_cast< float >( bitmapWidth ) + 0.5f );
+      }
+      else
+      {
+        return ImageDimensions( bitmapWidth * maxSize / static_cast< float >( bitmapHeight ) + 0.5f, maxSize );
+      }
+    }
   }
 
   // If both dimensions have values requested, use them both:
   if( requestedWidth != 0 && requestedHeight != 0 )
   {
-    return ImageDimensions( std::min( requestedWidth, maxSize ), std::min( requestedHeight, maxSize ) );
+    if( requestedWidth <= maxSize && requestedWidth <= maxSize )
+    {
+      return ImageDimensions( requestedWidth, requestedHeight );
+    }
+    else
+    {
+      // Calculate the size from the max texture size and the source image aspect ratio
+      if( requestedWidth > requestedHeight )
+      {
+        return ImageDimensions( maxSize, requestedHeight * maxSize / static_cast< float >( requestedWidth ) + 0.5f );
+      }
+      else
+      {
+        return ImageDimensions( requestedWidth * maxSize / static_cast< float >( requestedHeight ) + 0.5f, maxSize );
+      }
+    }
   }
 
   // Only one of the dimensions has been requested. Calculate the other from
@@ -1523,11 +1552,13 @@ void LinearSample4BPP( const unsigned char * __restrict__ inPixels,
   LinearSampleGeneric<Pixel4Bytes, BilinearFilter4Bytes, true>( inPixels, inputDimensions, outPixels, desiredDimensions );
 }
 
-void LanczosSample( const unsigned char * __restrict__ inPixels,
-                    ImageDimensions inputDimensions,
-                    unsigned char * __restrict__ outPixels,
-                    ImageDimensions desiredDimensions,
-                    int numChannels, bool hasAlpha )
+
+void Resample( const unsigned char * __restrict__ inPixels,
+               ImageDimensions inputDimensions,
+               unsigned char * __restrict__ outPixels,
+               ImageDimensions desiredDimensions,
+               Resampler::Filter filterType,
+               int numChannels, bool hasAlpha )
 {
   // Got from the test.cpp of the ImageResampler lib.
   const float ONE_DIV_255 = 1.0f / 255.0f;
@@ -1583,7 +1614,7 @@ void LanczosSample( const unsigned char * __restrict__ inPixels,
                                  Resampler::BOUNDARY_CLAMP,
                                  0.0f,           // sample_low,
                                  1.0f,           // sample_high. Clamp output samples to specified range, or disable clamping if sample_low >= sample_high.
-                                 FILTER_TYPE,    // The type of filter. Currently Lanczos.
+                                 filterType,    // The type of filter.
                                  NULL,           // Pclist_x,
                                  NULL,           // Pclist_y. Optional pointers to contributor lists from another instance of a Resampler.
                                  FILTER_SCALE,   // src_x_ofs,
@@ -1598,7 +1629,7 @@ void LanczosSample( const unsigned char * __restrict__ inPixels,
                                    Resampler::BOUNDARY_CLAMP,
                                    0.0f,
                                    1.0f,
-                                   FILTER_TYPE,
+                                   filterType,
                                    resamplers[0]->get_clist_x(),
                                    resamplers[0]->get_clist_y(),
                                    FILTER_SCALE,
@@ -1705,7 +1736,7 @@ void LanczosSample4BPP( const unsigned char * __restrict__ inPixels,
                         unsigned char * __restrict__ outPixels,
                         ImageDimensions desiredDimensions )
 {
-  LanczosSample( inPixels, inputDimensions, outPixels, desiredDimensions, 4, true );
+  Resample( inPixels, inputDimensions, outPixels, desiredDimensions, Resampler::LANCZOS4, 4, true );
 }
 
 void LanczosSample1BPP( const unsigned char * __restrict__ inPixels,
@@ -1714,7 +1745,7 @@ void LanczosSample1BPP( const unsigned char * __restrict__ inPixels,
                         ImageDimensions desiredDimensions )
 {
   // For L8 images
-  LanczosSample( inPixels, inputDimensions, outPixels, desiredDimensions, 1, false );
+  Resample( inPixels, inputDimensions, outPixels, desiredDimensions, Resampler::LANCZOS4, 1, false );
 }
 
 // Dispatch to a format-appropriate linear sampling function: