[NUI] Support ImageView and ImageVisual the SamplingMode
authorEunki, Hong <eunkiki.hong@samsung.com>
Mon, 23 Sep 2024 10:51:12 +0000 (19:51 +0900)
committerbshsqa <32317749+bshsqa@users.noreply.github.com>
Wed, 25 Sep 2024 12:13:40 +0000 (21:13 +0900)
Let we add property for change sampling mode when we change

desired size of given image.

Relative dali patch

https://review.tizen.org/gerrit/c/platform/core/uifw/dali-core/+/317969

https://review.tizen.org/gerrit/c/platform/core/uifw/dali-adaptor/+/317993

https://review.tizen.org/gerrit/c/platform/core/uifw/dali-toolkit/+/317992

https://review.tizen.org/gerrit/c/platform/core/uifw/dali-demo/+/318001

Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
src/Tizen.NUI/src/public/BaseComponents/ImageView.cs
src/Tizen.NUI/src/public/Visuals/VisualConstants.cs
src/Tizen.NUI/src/public/Visuals/VisualObject/ImageVisual.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/VisualTest.cs

index dd8fbde624bb8865f386b2a5ab158038d9190bfd..8297bb9cf3a93a0b221d2c3a74cc775e53112c50 100755 (executable)
@@ -125,6 +125,7 @@ namespace Tizen.NUI.BaseComponents
             ImageVisualProperty.AlphaMaskURL,
             ImageVisualProperty.CropToMask,
             Visual.Property.VisualFittingMode,
+            ImageVisualProperty.SamplingMode,
             ImageVisualProperty.DesiredWidth,
             ImageVisualProperty.DesiredHeight,
             ImageVisualProperty.ReleasePolicy,
@@ -1288,6 +1289,32 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        /// <summary>
+        /// Gets or sets filtering options used when resizing images to the sample original pixels.<br />
+        /// If not supplied, the default is SamplingModeType.BoxThenLinear.<br />
+        /// For normal quad images only.<br />
+        /// Optional.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public SamplingModeType SamplingMode
+        {
+            get
+            {
+                int ret = (int)SamplingModeType.BoxThenLinear;
+
+                using PropertyValue samplingMode = GetCachedImageVisualProperty(ImageVisualProperty.SamplingMode);
+                samplingMode?.Get(out ret);
+
+                return (SamplingModeType)ret;
+            }
+            set
+            {
+                using PropertyValue setValue = new PropertyValue((int)value);
+                UpdateImage(ImageVisualProperty.SamplingMode, setValue);
+                NotifyPropertyChanged();
+            }
+        }
+
         /// <summary>
         /// This method allows users to configure the blending of two images(previous and currnet) using alpha values.
         /// </summary>
index ae43965d2e0d4f11957872862b3bdf887c48884e..16ce53074b1d831bb5c879879e20902b5bc79112 100755 (executable)
@@ -199,7 +199,17 @@ namespace Tizen.NUI
         /// <summary>
         /// For caching algorithms where a client strongly prefers a cache-hit to reuse a cached image.
         /// </summary>
-        DontCare
+        DontCare,
+        /// <summary>
+        /// Use Lanczos resample algorithm.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        Lanczos,
+        /// <summary>
+        /// Iteratively box filter to generate an image of 1/2, 1/4, 1/8 etc width and height and approximately the desired size, then apply Lanczos resample algorithm.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        BoxThenLanczos,
     }
 
     /// <summary>
index c1f60836f132d0b7b6d250cd48204c7f0662c7d5..2b1c51168e88a9880e252b02ddd1a5e654988790 100644 (file)
@@ -331,6 +331,28 @@ namespace Tizen.NUI.Visuals
             }
         }
 
+        /// <summary>
+        /// Gets or sets filtering options used when resizing images to the sample original pixels.<br />
+        /// If not supplied, the default is SamplingModeType.BoxThenLinear.<br />
+        /// For normal quad images only.<br />
+        /// Optional.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public SamplingModeType SamplingMode
+        {
+            set
+            {
+                UpdateVisualProperty((int)Tizen.NUI.ImageVisualProperty.SamplingMode, new PropertyValue((int)value));
+            }
+            get
+            {
+                int ret = (int)SamplingModeType.BoxThenLinear;
+                var propertyValue = GetCachedVisualProperty((int)Tizen.NUI.ImageVisualProperty.SamplingMode);
+                propertyValue?.Get(out ret);
+                return (SamplingModeType)ret;
+            }
+        }
+
         /// <summary>
         /// Gets or sets the desired image width.<br />
         /// If not specified, the actual image width is used.<br />
index 54dbea7b4be62a883e7d6ebc7f8cdeeb70290ed9..32fe162a98ab90c7a35521e3bcc56b6bca39d87f 100755 (executable)
@@ -90,6 +90,18 @@ namespace Tizen.NUI.Samples
                 {
                     focusIndicatorVisual.ResourceUrl = focusIndicatorImageUrl;
                 }
+                else if(e.Key.KeyPressedName == "6")
+                {
+                    View focusedView = FocusManager.Instance.GetCurrentFocusView();
+                    if(focusedView != null)
+                    {
+                        var thumbnailVisual = focusedView.FindVisualByName("thumbnailImage") as Visuals.ImageVisual;
+                        if(thumbnailVisual != null)
+                        {
+                            thumbnailVisual.SamplingMode = GetNextSamplingModeType(thumbnailVisual.SamplingMode);
+                        }
+                    }
+                }
             }
         }
 
@@ -314,6 +326,8 @@ namespace Tizen.NUI.Samples
 
                 SynchronousSizing = true,
 
+                SamplingMode = SamplingModeType.BoxThenLanczos,
+
                 OffsetXPolicy = VisualTransformPolicyType.Absolute,
                 OffsetYPolicy = VisualTransformPolicyType.Absolute,
                 WidthPolicy = VisualTransformPolicyType.Absolute,
@@ -390,5 +404,57 @@ namespace Tizen.NUI.Samples
 
             return view;
         }
+
+        static private SamplingModeType GetNextSamplingModeType(SamplingModeType currentSamplingMode)
+        {
+            SamplingModeType nextSamplingMode = SamplingModeType.DontCare;
+            switch(currentSamplingMode)
+            {
+                case SamplingModeType.Box:
+                {
+                    nextSamplingMode = SamplingModeType.Nearest;
+                    break;
+                }
+                case SamplingModeType.Nearest:
+                {
+                    nextSamplingMode = SamplingModeType.Linear;
+                    break;
+                }
+                case SamplingModeType.Linear:
+                {
+                    nextSamplingMode = SamplingModeType.BoxThenNearest;
+                    break;
+                }
+                case SamplingModeType.BoxThenNearest:
+                {
+                    nextSamplingMode = SamplingModeType.BoxThenLinear;
+                    break;
+                }
+                case SamplingModeType.BoxThenLinear:
+                {
+                    nextSamplingMode = SamplingModeType.Lanczos;
+                    break;
+                }
+                case SamplingModeType.Lanczos:
+                {
+                    nextSamplingMode = SamplingModeType.BoxThenLanczos;
+                    break;
+                }
+                case SamplingModeType.BoxThenLanczos:
+                {
+                    nextSamplingMode = SamplingModeType.DontCare;
+                    break;
+                }
+                case SamplingModeType.DontCare:
+                default:
+                {
+                    nextSamplingMode = SamplingModeType.Box;
+                    break;
+                }
+            }
+            Tizen.Log.Error("NUI", $"Change sampling mode from [{currentSamplingMode}] to [{nextSamplingMode}]\n");
+
+            return nextSamplingMode;
+        }
     }
 }