From 726a7d4996126e1c06e277a65211e734ce1fdce0 Mon Sep 17 00:00:00 2001 From: Haesu Gwon Date: Thu, 13 Apr 2023 17:09:15 +0900 Subject: [PATCH] [MediaVision] Add APIs for Design QR feature (#5104) * [MediaVision] Add Design QR feature --- .../MediaVision/BarcodeGenerationConfiguration.cs | 48 ++++++++++++++- .../MediaVision/BarcodeGenerator.cs | 47 +++++++++++++-- .../MediaVision/QrConfiguration.cs | 68 ++++++++++++++++++++++ src/Tizen.Multimedia.Vision/MediaVision/QrShape.cs | 42 +++++++++++++ 4 files changed, 198 insertions(+), 7 deletions(-) create mode 100755 src/Tizen.Multimedia.Vision/MediaVision/QrShape.cs diff --git a/src/Tizen.Multimedia.Vision/MediaVision/BarcodeGenerationConfiguration.cs b/src/Tizen.Multimedia.Vision/MediaVision/BarcodeGenerationConfiguration.cs index aaf7f79..7ee7bc0 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/BarcodeGenerationConfiguration.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/BarcodeGenerationConfiguration.cs @@ -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"; /// /// Initializes a new instance of the class. @@ -43,7 +46,7 @@ namespace Tizen.Multimedia.Vision /// Gets or sets the text visibility of the barcode to be generated. /// /// is not valid. - /// The already has been disposed of. + /// The already has been disposed. /// 4 public Visibility TextVisibility { @@ -67,7 +70,7 @@ namespace Tizen.Multimedia.Vision /// /// The alpha value of the color will be ignored. /// - /// The already has been disposed of. + /// The already has been disposed. /// 4 public Color ForegroundColor { @@ -90,7 +93,7 @@ namespace Tizen.Multimedia.Vision /// /// The alpha value of the color will be ignored. /// - /// The already has been disposed of. + /// The already has been disposed. /// 4 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); + } + } } } diff --git a/src/Tizen.Multimedia.Vision/MediaVision/BarcodeGenerator.cs b/src/Tizen.Multimedia.Vision/MediaVision/BarcodeGenerator.cs index 03038bb..dde2bf0 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/BarcodeGenerator.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/BarcodeGenerator.cs @@ -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 /// /// Generates a QR image with the specified message. /// + /// http://tizen.org/feature/vision.barcode_generation /// The message to be encoded in the barcode. /// The instance. /// containing the generated QR image. @@ -83,6 +98,7 @@ namespace Tizen.Multimedia.Vision /// /// Generates a QR image with the specified message with . /// + /// http://tizen.org/feature/vision.barcode_generation /// The message to be encoded in the barcode. /// The instance. /// The configuration of the barcode generator. This value can be null. @@ -124,6 +140,15 @@ namespace Tizen.Multimedia.Vision throw new NotSupportedException("Text can't be visible in QR."); } } + else + { + if (qrConfig.DataShape != QrShape.Rectangular || qrConfig.FinderShape != QrShape.Rectangular) + { + config = new BarcodeGenerationConfiguration(); + + SetDesignQrOptions(qrConfig, config); + } + } return GenerateSource(config, message, BarcodeType.QR, (int)qrConfig.Mode, (int)qrConfig.ErrorCorrectionLevel, qrConfig.Version); @@ -155,6 +180,7 @@ namespace Tizen.Multimedia.Vision /// /// Generates a barcode image with the specified message and . /// + /// http://tizen.org/feature/vision.barcode_generation /// The message to be encoded in the barcode. /// Type of the barcode to be generated. /// The configuration of the barcode generator. This value can be null. @@ -208,6 +234,7 @@ namespace Tizen.Multimedia.Vision /// /// Generates a QR image file with the specified message. /// + /// http://tizen.org/feature/vision.barcode_generation /// /// must be , /// because the text visibility is not supported in the QR code. @@ -227,7 +254,7 @@ namespace Tizen.Multimedia.Vision /// -or-
/// contains characters which are illegal by the . /// - /// No permission to write a file. + /// No permission to access a file. /// The feature is not supported. /// /// 4 @@ -240,6 +267,7 @@ namespace Tizen.Multimedia.Vision /// /// Generates a QR image file with the specified message and . /// + /// http://tizen.org/feature/vision.barcode_generation /// /// must be , /// because the text visibility is not supported in the QR code. @@ -261,7 +289,7 @@ namespace Tizen.Multimedia.Vision /// -or-
/// contains characters which are illegal by the . /// - /// No permission to write a file. + /// No permission to access a file. /// /// The feature is not supported.
/// -or-
@@ -284,6 +312,15 @@ namespace Tizen.Multimedia.Vision throw new NotSupportedException("Text can't be visible in QR."); } } + else + { + if (qrConfig.DataShape != QrShape.Rectangular || qrConfig.FinderShape != QrShape.Rectangular) + { + config = new BarcodeGenerationConfiguration(); + + SetDesignQrOptions(qrConfig, config); + } + } GenerateImage(config, message, BarcodeType.QR, imageConfig, (int)qrConfig.Mode, (int)qrConfig.ErrorCorrectionLevel, qrConfig.Version); @@ -292,6 +329,7 @@ namespace Tizen.Multimedia.Vision /// /// Generates a barcode image file with the specified message. /// + /// http://tizen.org/feature/vision.barcode_generation /// The message to be encoded in the barcode. /// Type of the barcode to be generated. /// The that contains @@ -310,7 +348,7 @@ namespace Tizen.Multimedia.Vision /// -or-
/// contains illegal characters. ///
- /// No permission to write a file. + /// No permission to access a file. /// The feature is not supported. /// 4 public static void GenerateImage(string message, BarcodeType type, BarcodeImageConfiguration imageConfig) @@ -321,6 +359,7 @@ namespace Tizen.Multimedia.Vision /// /// Generates a barcode image file with the specified message and . /// + /// http://tizen.org/feature/vision.barcode_generation /// The message to be encoded in the barcode. /// Type of the barcode to be generated. /// The that contains @@ -340,7 +379,7 @@ namespace Tizen.Multimedia.Vision /// -or-
/// contains illegal characters. /// - /// No permission to write a file. + /// No permission to access a file. /// The feature is not supported. /// already has been disposed of. /// 4 diff --git a/src/Tizen.Multimedia.Vision/MediaVision/QrConfiguration.cs b/src/Tizen.Multimedia.Vision/MediaVision/QrConfiguration.cs index cd070a7..be63fbd 100755 --- a/src/Tizen.Multimedia.Vision/MediaVision/QrConfiguration.cs +++ b/src/Tizen.Multimedia.Vision/MediaVision/QrConfiguration.cs @@ -24,6 +24,10 @@ namespace Tizen.Multimedia.Vision /// 4 public class QrConfiguration { + private string _embedImagePath; + private QrShape _dataShape = QrShape.Rectangular; + private QrShape _finderShape = QrShape.Rectangular; + /// /// Initializes a new instance of the class. /// @@ -78,5 +82,69 @@ namespace Tizen.Multimedia.Vision /// /// 4 public int Version { get; } + + /// + /// Gets or sets the embed image absolute path of the Design QR code. + /// + /// + /// The mediastorage privilege (http://tizen.org/privilege/mediastorage) is needed if the image path is relevant to media storage.
+ /// The externalstorage privilege (http://tizen.org/privilege/externalstorage) is needed if the image path is relevant to external storage. + ///
+ /// is null. + /// is zero-length string. + /// 11 + public string EmbedImagePath + { + get + { + return _embedImagePath; + } + set + { + ValidationUtil.ValidateIsNullOrEmpty(value, nameof(value)); + + _embedImagePath = value; + } + } + + /// + /// Gets or sets the data shape of the Design QR code. + /// + /// The default value is . + /// is not valid. + /// 11 + public QrShape DataShape + { + get + { + return _dataShape; + } + set + { + ValidationUtil.ValidateEnum(typeof(QrShape), value, nameof(value)); + + _dataShape = value; + } + } + + /// + /// Gets or sets the finder shape of the Design QR code. + /// + /// The default value is . + /// is not valid. + /// 11 + 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 index 0000000..a46e943 --- /dev/null +++ b/src/Tizen.Multimedia.Vision/MediaVision/QrShape.cs @@ -0,0 +1,42 @@ +/* + * 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. + */ + +namespace Tizen.Multimedia.Vision +{ + /// + /// Specifies the shape of QR code. + /// + /// + /// + /// 11 + public enum QrShape + { + /// + /// Rectangular. + /// + Rectangular, + + /// + /// Rectangular with rounded corners. + /// + RoundRectangular, + + /// + /// Circle. + /// + Circle + } +} -- 2.7.4