[MediaVision] Add internal APIs for Design QR feature (#5241)
authorHaesu Gwon <haesu.gwon@samsung.com>
Thu, 4 May 2023 08:27:59 +0000 (17:27 +0900)
committerGitHub <noreply@github.com>
Thu, 4 May 2023 08:27:59 +0000 (17:27 +0900)
* [MediaVision] Add internal APIs for Design QR feature

src/Tizen.Multimedia.Vision/MediaVision/BarcodeGenerationConfiguration.cs
src/Tizen.Multimedia.Vision/MediaVision/BarcodeGenerator.cs
src/Tizen.Multimedia.Vision/MediaVision/QrConfiguration.cs
src/Tizen.Multimedia.Vision/MediaVision/QrShape.cs [new file with mode: 0755]

index aaf7f79..7ee7bc0 100755 (executable)
@@ -29,6 +29,9 @@ namespace Tizen.Multimedia.Vision
         private const string KeyTextAttr = "MV_BARCODE_GENERATE_ATTR_TEXT";
         private const string KeyForegroundColorAttr = "MV_BARCODE_GENERATE_ATTR_COLOR_FRONT";
         private const string KeyBackgroundColorAttr = "MV_BARCODE_GENERATE_ATTR_COLOR_BACK";
+        private const string KeyEmbedImageAbsolutePathAttr = "MV_BARCODE_GENERATE_ATTR_EMBED_IMG_PATH";
+        private const string KeyDataShapeAttr = "MV_BARCODE_GENERATE_ATTR_DATA_SHAPE";
+        private const string KeyFinderShapeAttr = "MV_BARCODE_GENERATE_ATTR_FINDER_SHAPE";
 
         /// <summary>
         /// Initializes a new instance of the <see cref="BarcodeGenerationConfiguration"/> class.
@@ -43,7 +46,7 @@ namespace Tizen.Multimedia.Vision
         /// Gets or sets the text visibility of the barcode to be generated.
         /// </summary>
         /// <exception cref="ArgumentException"><paramref name="value"/> is not valid.</exception>
-        /// <exception cref="ObjectDisposedException">The <see cref="BarcodeGenerationConfiguration"/> already has been disposed of.</exception>
+        /// <exception cref="ObjectDisposedException">The <see cref="BarcodeGenerationConfiguration"/> already has been disposed.</exception>
         /// <since_tizen> 4 </since_tizen>
         public Visibility TextVisibility
         {
@@ -67,7 +70,7 @@ namespace Tizen.Multimedia.Vision
         /// <remarks>
         /// The alpha value of the color will be ignored.
         /// </remarks>
-        /// <exception cref="ObjectDisposedException">The <see cref="BarcodeGenerationConfiguration"/> already has been disposed of.</exception>
+        /// <exception cref="ObjectDisposedException">The <see cref="BarcodeGenerationConfiguration"/> already has been disposed.</exception>
         /// <since_tizen> 4 </since_tizen>
         public Color ForegroundColor
         {
@@ -90,7 +93,7 @@ namespace Tizen.Multimedia.Vision
         /// <remarks>
         /// The alpha value of the color will be ignored.
         /// </remarks>
-        /// <exception cref="ObjectDisposedException">The <see cref="BarcodeGenerationConfiguration"/> already has been disposed of.</exception>
+        /// <exception cref="ObjectDisposedException">The <see cref="BarcodeGenerationConfiguration"/> already has been disposed.</exception>
         /// <since_tizen> 4 </since_tizen>
         public Color BackgroundColor
         {
@@ -104,5 +107,44 @@ namespace Tizen.Multimedia.Vision
                 _backgroundColor = value;
             }
         }
+
+        internal string EmbedImagePath
+        {
+            get
+            {
+                return GetString(KeyEmbedImageAbsolutePathAttr);
+            }
+            set
+            {
+                // Validation is already checked in QrConfiguration.
+                Set(KeyEmbedImageAbsolutePathAttr, value);
+            }
+        }
+
+        internal QrShape DataShape
+        {
+            get
+            {
+                return (QrShape)GetInt(KeyDataShapeAttr);
+            }
+            set
+            {
+                // Validation is already checked in QrConfiguration.
+                Set(KeyDataShapeAttr, (int)value);
+            }
+        }
+
+        internal QrShape FinderShape
+        {
+            get
+            {
+                return (QrShape)GetInt(KeyFinderShapeAttr);
+            }
+            set
+            {
+                // Validation is already checked in QrConfiguration.
+                Set(KeyFinderShapeAttr, (int)value);
+            }
+        }
     }
 }
index 03038bb..061781d 100755 (executable)
@@ -31,6 +31,20 @@ namespace Tizen.Multimedia.Vision
         private const int NoneErrorCorrection = (int)ErrorCorrectionLevel.High + 1;
         private const int NoneQrMode = (int)QrMode.Utf8 + 1;
 
+        private static void SetDesignQrOptions(QrConfiguration qrConfig, BarcodeGenerationConfiguration config)
+        {
+            if (config != null && qrConfig != null)
+            {
+                if (qrConfig.EmbedImagePath != null)
+                {
+                    config.EmbedImagePath = qrConfig.EmbedImagePath;
+                }
+
+                config.DataShape = qrConfig.DataShape;
+                config.FinderShape = qrConfig.FinderShape;
+            }
+        }
+
         private static MediaVisionSource GenerateSource(BarcodeGenerationConfiguration config,
             string message, BarcodeType type, int qrMode, int qrEcc, int qrVersion)
         {
@@ -59,6 +73,7 @@ namespace Tizen.Multimedia.Vision
         /// <summary>
         /// Generates a QR image with the specified message.
         /// </summary>
+        /// <feature>http://tizen.org/feature/vision.barcode_generation</feature>
         /// <param name="message">The message to be encoded in the barcode.</param>
         /// <param name="qrConfig">The <see cref="QrConfiguration"/> instance.</param>
         /// <returns><see cref="MediaVisionSource"/> containing the generated QR image.</returns>
@@ -83,6 +98,7 @@ namespace Tizen.Multimedia.Vision
         /// <summary>
         /// Generates a QR image with the specified message with <see cref="BarcodeGenerationConfiguration"/>.
         /// </summary>
+        /// <feature>http://tizen.org/feature/vision.barcode_generation</feature>
         /// <param name="message">The message to be encoded in the barcode.</param>
         /// <param name="qrConfig">The <see cref="QrConfiguration"/> instance.</param>
         /// <param name="config">The configuration of the barcode generator. This value can be null.</param>
@@ -124,6 +140,16 @@ namespace Tizen.Multimedia.Vision
                     throw new NotSupportedException("Text can't be visible in QR.");
                 }
             }
+            else
+            {
+                if (qrConfig.DataShape != QrShape.Rectangular || qrConfig.FinderShape != QrShape.Rectangular ||
+                    qrConfig.EmbedImagePath != null)
+                {
+                    config = new BarcodeGenerationConfiguration();
+                }
+            }
+
+            SetDesignQrOptions(qrConfig, config);
 
             return GenerateSource(config, message, BarcodeType.QR, (int)qrConfig.Mode,
                 (int)qrConfig.ErrorCorrectionLevel, qrConfig.Version);
@@ -155,6 +181,7 @@ namespace Tizen.Multimedia.Vision
         /// <summary>
         /// Generates a barcode image with the specified message and <see cref="BarcodeGenerationConfiguration"/>.
         /// </summary>
+        /// <feature>http://tizen.org/feature/vision.barcode_generation</feature>
         /// <param name="message">The message to be encoded in the barcode.</param>
         /// <param name="type">Type of the barcode to be generated.</param>
         /// <param name="config">The configuration of the barcode generator. This value can be null.</param>
@@ -208,6 +235,7 @@ namespace Tizen.Multimedia.Vision
         /// <summary>
         /// Generates a QR image file with the specified message.
         /// </summary>
+        /// <feature>http://tizen.org/feature/vision.barcode_generation</feature>
         /// <remarks>
         ///     <see cref="BarcodeGenerationConfiguration.TextVisibility"/> must be <see cref="Visibility.Invisible"/>,
         ///     because the text visibility is not supported in the QR code.
@@ -227,7 +255,7 @@ namespace Tizen.Multimedia.Vision
         ///     -or-<br/>
         ///     <paramref name="message"/> contains characters which are illegal by the <see cref="QrMode"/>.
         /// </exception>
-        /// <exception cref="UnauthorizedAccessException">No permission to write a file.</exception>
+        /// <exception cref="UnauthorizedAccessException">No permission to access a file.</exception>
         /// <exception cref="NotSupportedException">The feature is not supported.</exception>
         /// <seealso cref="QrMode"/>
         /// <since_tizen> 4 </since_tizen>
@@ -240,6 +268,7 @@ namespace Tizen.Multimedia.Vision
         /// <summary>
         /// Generates a QR image file with the specified message and <see cref="BarcodeGenerationConfiguration"/>.
         /// </summary>
+        /// <feature>http://tizen.org/feature/vision.barcode_generation</feature>
         /// <remarks>
         ///     <see cref="BarcodeGenerationConfiguration.TextVisibility"/> must be <see cref="Visibility.Invisible"/>,
         ///     because the text visibility is not supported in the QR code.
@@ -261,7 +290,7 @@ namespace Tizen.Multimedia.Vision
         ///     -or-<br/>
         ///     <paramref name="message"/> contains characters which are illegal by the <see cref="QrMode"/>.
         /// </exception>
-        /// <exception cref="UnauthorizedAccessException">No permission to write a file.</exception>
+        /// <exception cref="UnauthorizedAccessException">No permission to access a file.</exception>
         /// <exception cref="NotSupportedException">
         ///     The feature is not supported.<br/>
         ///     -or-<br/>
@@ -284,6 +313,16 @@ namespace Tizen.Multimedia.Vision
                     throw new NotSupportedException("Text can't be visible in QR.");
                 }
             }
+            else
+            {
+                if (qrConfig.DataShape != QrShape.Rectangular || qrConfig.FinderShape != QrShape.Rectangular ||
+                    qrConfig.EmbedImagePath != null)
+                {
+                    config = new BarcodeGenerationConfiguration();
+                }
+            }
+
+            SetDesignQrOptions(qrConfig, config);
 
             GenerateImage(config, message, BarcodeType.QR, imageConfig, (int)qrConfig.Mode,
                 (int)qrConfig.ErrorCorrectionLevel, qrConfig.Version);
@@ -292,6 +331,7 @@ namespace Tizen.Multimedia.Vision
         /// <summary>
         /// Generates a barcode image file with the specified message.
         /// </summary>
+        /// <feature>http://tizen.org/feature/vision.barcode_generation</feature>
         /// <param name="message">The message to be encoded in the barcode.</param>
         /// <param name="type">Type of the barcode to be generated.</param>
         /// <param name="imageConfig">The <see cref="BarcodeImageConfiguration"/> that contains
@@ -310,7 +350,7 @@ namespace Tizen.Multimedia.Vision
         ///     -or-<br/>
         ///     <paramref name="message"/> contains illegal characters.
         /// </exception>
-        /// <exception cref="UnauthorizedAccessException">No permission to write a file.</exception>
+        /// <exception cref="UnauthorizedAccessException">No permission to access a file.</exception>
         /// <exception cref="NotSupportedException">The feature is not supported.</exception>
         /// <since_tizen> 4 </since_tizen>
         public static void GenerateImage(string message, BarcodeType type, BarcodeImageConfiguration imageConfig)
@@ -321,6 +361,7 @@ namespace Tizen.Multimedia.Vision
         /// <summary>
         /// Generates a barcode image file with the specified message and <see cref="BarcodeGenerationConfiguration"/>.
         /// </summary>
+        /// <feature>http://tizen.org/feature/vision.barcode_generation</feature>
         /// <param name="message">The message to be encoded in the barcode.</param>
         /// <param name="type">Type of the barcode to be generated.</param>
         /// <param name="imageConfig">The <see cref="BarcodeImageConfiguration"/> that contains
@@ -340,7 +381,7 @@ namespace Tizen.Multimedia.Vision
         ///     -or-<br/>
         ///     <paramref name="message"/> contains illegal characters.
         /// </exception>
-        /// <exception cref="UnauthorizedAccessException">No permission to write a file.</exception>
+        /// <exception cref="UnauthorizedAccessException">No permission to access a file.</exception>
         /// <exception cref="NotSupportedException">The feature is not supported.</exception>
         /// <exception cref="ObjectDisposedException"><paramref name="config"/> already has been disposed of.</exception>
         /// <since_tizen> 4 </since_tizen>
index cd070a7..896f2de 100755 (executable)
@@ -15,6 +15,7 @@
  */
 
 using System;
+using System.ComponentModel;
 
 namespace Tizen.Multimedia.Vision
 {
@@ -24,6 +25,10 @@ namespace Tizen.Multimedia.Vision
     /// <since_tizen> 4 </since_tizen>
     public class QrConfiguration
     {
+        private string _embedImagePath;
+        private QrShape _dataShape = QrShape.Rectangular;
+        private QrShape _finderShape = QrShape.Rectangular;
+
         /// <summary>
         /// Initializes a new instance of the <see cref="QrConfiguration"/> class.
         /// </summary>
@@ -78,5 +83,69 @@ namespace Tizen.Multimedia.Vision
         /// </summary>
         /// <since_tizen> 4 </since_tizen>
         public int Version { get; }
+
+        /// <summary>
+        /// Gets or sets the embed image absolute path of the Design QR code.
+        /// </summary>
+        /// <remarks>
+        /// The mediastorage privilege (http://tizen.org/privilege/mediastorage) is needed if the image path is relevant to media storage.<br/>
+        /// The externalstorage privilege (http://tizen.org/privilege/externalstorage) is needed if the image path is relevant to external storage.
+        /// </remarks>
+        /// <exception cref="ArgumentNullException"><paramref name="value"/> is null.</exception>
+        /// <exception cref="ArgumentException"><paramref name="value"/> is zero-length string.</exception>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public string EmbedImagePath
+        {
+            get
+            {
+                return _embedImagePath;
+            }
+            set
+            {
+                ValidationUtil.ValidateIsNullOrEmpty(value, nameof(value));
+
+                _embedImagePath = value;
+            }
+        }
+
+        /// <summary>
+        /// Gets or sets the data shape of the Design QR code.
+        /// </summary>
+        /// <remarks>The default value is <see cref="QrShape.Rectangular"/>.</remarks>
+        /// <exception cref="ArgumentException"><paramref name="value"/> is not valid.</exception>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public QrShape DataShape
+        {
+            get
+            {
+                return _dataShape;
+            }
+            set
+            {
+                ValidationUtil.ValidateEnum(typeof(QrShape), value, nameof(value));
+
+                _dataShape = value;
+            }
+        }
+
+        /// <summary>
+        /// Gets or sets the finder shape of the Design QR code.
+        /// </summary>
+        /// <remarks>The default value is <see cref="QrShape.Rectangular"/>.</remarks>
+        /// <exception cref="ArgumentException"><paramref name="value"/> is not valid.</exception>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public QrShape FinderShape
+        {
+            get
+            {
+                return _finderShape;
+            }
+            set
+            {
+                ValidationUtil.ValidateEnum(typeof(QrShape), value, nameof(value));
+
+                _finderShape = value;
+            }
+        }
     }
 }
diff --git a/src/Tizen.Multimedia.Vision/MediaVision/QrShape.cs b/src/Tizen.Multimedia.Vision/MediaVision/QrShape.cs
new file mode 100755 (executable)
index 0000000..c5d1c0c
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System.ComponentModel;
+
+namespace Tizen.Multimedia.Vision
+{
+    /// <summary>
+    /// Specifies the shape of QR code.
+    /// </summary>
+    /// <seealso cref="QrConfiguration.DataShape"/>
+    /// <seealso cref="QrConfiguration.FinderShape"/>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public enum QrShape
+    {
+        /// <summary>
+        /// Rectangular.
+        /// </summary>
+        Rectangular,
+
+        /// <summary>
+        /// Rectangular with rounded corners.
+        /// </summary>
+        RoundRectangular,
+
+        /// <summary>
+        /// Circle.
+        /// </summary>
+        Circle
+    }
+}