From a3a3f76ca662915ffbfae0c5fd7936cc1d85a16a Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Mon, 23 Sep 2024 19:51:12 +0900 Subject: [PATCH] [NUI] Support ImageView and ImageVisual the SamplingMode 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 --- .../src/public/BaseComponents/ImageView.cs | 27 ++++++++ .../src/public/Visuals/VisualConstants.cs | 12 +++- .../Visuals/VisualObject/ImageVisual.cs | 22 +++++++ .../Tizen.NUI.Samples/Samples/VisualTest.cs | 66 +++++++++++++++++++ 4 files changed, 126 insertions(+), 1 deletion(-) diff --git a/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs b/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs index dd8fbde624b..8297bb9cf3a 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs @@ -125,6 +125,7 @@ private static string ConvertResourceUrl(ref string value) ImageVisualProperty.AlphaMaskURL, ImageVisualProperty.CropToMask, Visual.Property.VisualFittingMode, + ImageVisualProperty.SamplingMode, ImageVisualProperty.DesiredWidth, ImageVisualProperty.DesiredHeight, ImageVisualProperty.ReleasePolicy, @@ -1288,6 +1289,32 @@ private FittingModeType InternalFittingMode } } + /// + /// Gets or sets filtering options used when resizing images to the sample original pixels.
+ /// If not supplied, the default is SamplingModeType.BoxThenLinear.
+ /// For normal quad images only.
+ /// Optional. + ///
+ [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(); + } + } + /// /// This method allows users to configure the blending of two images(previous and currnet) using alpha values. /// diff --git a/src/Tizen.NUI/src/public/Visuals/VisualConstants.cs b/src/Tizen.NUI/src/public/Visuals/VisualConstants.cs index ae43965d2e0..16ce53074b1 100755 --- a/src/Tizen.NUI/src/public/Visuals/VisualConstants.cs +++ b/src/Tizen.NUI/src/public/Visuals/VisualConstants.cs @@ -199,7 +199,17 @@ public enum SamplingModeType /// /// For caching algorithms where a client strongly prefers a cache-hit to reuse a cached image. /// - DontCare + DontCare, + /// + /// Use Lanczos resample algorithm. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + Lanczos, + /// + /// 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. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + BoxThenLanczos, } /// diff --git a/src/Tizen.NUI/src/public/Visuals/VisualObject/ImageVisual.cs b/src/Tizen.NUI/src/public/Visuals/VisualObject/ImageVisual.cs index c1f60836f13..2b1c51168e8 100644 --- a/src/Tizen.NUI/src/public/Visuals/VisualObject/ImageVisual.cs +++ b/src/Tizen.NUI/src/public/Visuals/VisualObject/ImageVisual.cs @@ -331,6 +331,28 @@ public ReleasePolicyType ReleasePolicy } } + /// + /// Gets or sets filtering options used when resizing images to the sample original pixels.
+ /// If not supplied, the default is SamplingModeType.BoxThenLinear.
+ /// For normal quad images only.
+ /// Optional. + ///
+ [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; + } + } + /// /// Gets or sets the desired image width.
/// If not specified, the actual image width is used.
diff --git a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/VisualTest.cs b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/VisualTest.cs index 54dbea7b4be..32fe162a98a 100755 --- a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/VisualTest.cs +++ b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/VisualTest.cs @@ -90,6 +90,18 @@ private void WinKeyEvent(object sender, Window.KeyEventArgs e) { 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 @@ private View CreateViewWithVisual(int id) SynchronousSizing = true, + SamplingMode = SamplingModeType.BoxThenLanczos, + OffsetXPolicy = VisualTransformPolicyType.Absolute, OffsetYPolicy = VisualTransformPolicyType.Absolute, WidthPolicy = VisualTransformPolicyType.Absolute, @@ -390,5 +404,57 @@ private View CreateViewWithVisual(int id) 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; + } } }