[NUI] Add GetOriginalImageSize() considering rotation (#2587)
authortscholb <scholb.kim@samsung.com>
Fri, 29 Jan 2021 08:37:53 +0000 (17:37 +0900)
committerGitHub <noreply@github.com>
Fri, 29 Jan 2021 08:37:53 +0000 (17:37 +0900)
src/Tizen.NUI/src/internal/Interop/Interop.ImageLoading.cs
src/Tizen.NUI/src/public/BaseComponents/ImageView.cs
src/Tizen.NUI/src/public/ImageLoading.cs

index f599a37..2f5b70d 100755 (executable)
@@ -38,8 +38,11 @@ namespace Tizen.NUI
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_GetClosestImageSize__SWIG_4")]
             public static extern global::System.IntPtr GetClosestImageSize__SWIG_4(string jarg1);
 
-            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_GetOriginalImageSize")]
-            public static extern global::System.IntPtr GetOriginalImageSize(string jarg1);
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_GetOriginalImageSize__SWIG_0")]
+            public static extern global::System.IntPtr GetOriginalImageSize_SWIG_0(string jarg1);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_GetOriginalImageSize__SWIG_1")]
+            public static extern global::System.IntPtr GetOriginalImageSize_SWIG_1(string jarg1, bool jarg2);
 
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DownloadImageSynchronously__SWIG_0")]
             public static extern global::System.IntPtr DownloadImageSynchronously__SWIG_0(string jarg1, global::System.Runtime.InteropServices.HandleRef jarg2, int jarg3, int jarg4, bool jarg5);
index 5204247..565b1af 100755 (executable)
@@ -1135,10 +1135,23 @@ namespace Tizen.NUI.BaseComponents
             {
                 if(_resourceUrl != null)
                 {
-                  Size2D desiredSize = new Size2D(_desired_width,_desired_height);
-                  Size2D imageSize = ImageLoading.GetClosestImageSize(_resourceUrl, desiredSize, FittingModeType.ScaleToFill);
-                  temp.Insert(ImageVisualProperty.DesiredWidth, new PropertyValue((int)imageSize.Width));
-                  temp.Insert(ImageVisualProperty.DesiredHeight, new PropertyValue((int)imageSize.Height));
+                  Size2D imageSize = ImageLoading.GetOriginalImageSize(_resourceUrl,true);
+
+                  int adjustedDesiredWidth, adjustedDesiredHeight;
+                  float aspectOfDesiredSize = (float)_desired_height / (float)_desired_width;
+                  float aspectOfImageSize = (float)imageSize.Height / (float)imageSize.Width;
+                  if( aspectOfImageSize > aspectOfDesiredSize)
+                  {
+                    adjustedDesiredWidth = _desired_width;
+                    adjustedDesiredHeight = imageSize.Height * _desired_width / imageSize.Width;
+                  }
+                  else
+                  {
+                    adjustedDesiredWidth = imageSize.Width * _desired_height/ imageSize.Height;
+                    adjustedDesiredHeight = _desired_height;
+                  }
+                  temp.Insert(ImageVisualProperty.DesiredWidth, new PropertyValue(adjustedDesiredWidth));
+                  temp.Insert(ImageVisualProperty.DesiredHeight, new PropertyValue(adjustedDesiredHeight));
                   temp.Insert(ImageVisualProperty.FittingMode, new PropertyValue((int) FittingModeType.ScaleToFill));
                 }
             }
index 6de37ca..58728fd 100755 (executable)
@@ -211,7 +211,7 @@ namespace Tizen.NUI
         }
 
         /// <summary>
-        /// Get the size of an original image
+        /// Get the size of an original image. this method will not respect any rotation of image
         /// </summary>
         /// <param name="filename">The name of the image.</param>
         /// <returns>Dimension of the original image.</returns>
@@ -220,7 +220,24 @@ namespace Tizen.NUI
         [EditorBrowsable(EditorBrowsableState.Never)]
         public static Size2D GetOriginalImageSize(string filename)
         {
-            var val = new Uint16Pair(Interop.ImageLoading.GetOriginalImageSize(filename), true);
+            var val = new Uint16Pair(Interop.ImageLoading.GetOriginalImageSize_SWIG_0(filename), true);
+            Size2D ret = new Size2D(val.GetWidth(), val.GetHeight());
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        /// <summary>
+        /// Get the size of an original image consider rotation
+        /// </summary>
+        /// <param name="filename">The name of the image.</param>
+        /// <param name="orientationCorrection">Reorient the image to respect any orientation metadata in its header.</param>
+        /// <returns>Dimension of the original image.</returns>
+        /// <since_tizen> 6 </since_tizen>
+        /// This will be released at Tizen.NET API Level 9. Therefore, currently this would be used as an in-house API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static Size2D GetOriginalImageSize(string filename, bool orientationCorrection )
+        {
+            var val = new Uint16Pair(Interop.ImageLoading.GetOriginalImageSize_SWIG_1(filename,orientationCorrection), true);
             Size2D ret = new Size2D(val.GetWidth(), val.GetHeight());
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;