Added MediaVision Code.Updated license file
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia / MediaVision / BarcodeGenerator.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18
19 namespace Tizen.Multimedia
20 {
21     /// <summary>
22     /// This class contains the Media Vision barcode generate API.\n
23     /// These APIs can be used for generating the barcodes and QR codes.
24     /// Different encoding types <see cref="QrMode"/> , error correction codes <see cref="ErrorCorrectionLevel"/>  and code versions are supported for QRCodes.
25     /// </summary>
26     public static class BarcodeGenerator
27     {
28         /// <summary>
29         /// Generates <see cref="MediaVisionSource"/> with barcode image.
30         /// </summary>
31         /// <remarks>
32         /// If the text attribute of engine configuration is set to <see cref="TextAttribute.Visible"/> , InvalidOperationException will be thrown when type is <see cref="BarcodeType.QR"/>
33         /// </remarks>
34         /// <param name="config">The configuration of the bar code generator engine</param>
35         /// <param name="message">The message to be encoded in the barcode</param>
36         /// <param name="type">Type of the barcode to be generated</param>
37         /// <param name="source">The media vision source object which will be used to fill by the buffer with generated image</param>
38         /// <param name="qrConfig">The QrConfig object - required for QR codes only</param>
39         /// <code>
40         /// 
41         /// </code>
42         public static MediaVisionSource GenerateSource(BarcodeGeneratorEngineConfiguration config, string message, BarcodeType type, QrConfiguration qrConfig = null)
43         {
44             if (string.IsNullOrEmpty(message) ||
45                 type == BarcodeType.Undefined ||
46                 (type == BarcodeType.QR &&
47                 (qrConfig == null ||
48                 qrConfig.ErrorCorrectionLevel == ErrorCorrectionLevel.Unavailable ||
49                 qrConfig.Mode == QrMode.Unavailable ||
50                 qrConfig.Version < 1 ||
51                 qrConfig.Version > 40)))
52             {
53                 throw new ArgumentException("Invalid parameter");
54             }
55
56             MediaVisionSource source = new MediaVisionSource();
57             int ret = (type == BarcodeType.QR) ?
58                         Interop.MediaVision.BarCodeGenerator.GenerateSource(config._engineHandle, message, type, qrConfig.Mode, qrConfig.ErrorCorrectionLevel, qrConfig.Version, source._sourceHandle) :
59                         Interop.MediaVision.BarCodeGenerator.GenerateSource(config._engineHandle, message, type, QrMode.Unavailable, ErrorCorrectionLevel.Unavailable, 0, source._sourceHandle);
60             MediaVisionErrorFactory.CheckAndThrowException(ret, "Failed to generate source");
61             return source;
62         }
63
64         /// <summary>
65         /// Generates image file with barcode.
66         /// </summary>
67         /// <remarks>
68         /// If the text attribute of engine configuration is set to <see cref="TextAttribute.Visible"/> ,
69         /// InvalidOperationException will be thrown when type is <see cref="BarcodeType.QR"/>\n
70         /// </remarks>
71         /// <param name="config">The configuration of the bar code generator engine</param>
72         /// <param name="message">The message to be encoded in the barcode</param>
73         /// <param name="type">Type of the barcode to be generated</param>
74         /// <param name="imageConfig">The BarcodeImageConfig object that contains information about the file to be generated</param>
75         /// <param name="qrConfig">The QrConfig object - required for QR codes only</param>
76         /// <code>
77         /// 
78         /// </code>
79         public static void GenerateImage(BarcodeGeneratorEngineConfiguration config, string message, BarcodeType type, BarcodeImageConfiguration imageConfig, QrConfiguration qrConfig = null)
80         {
81             if (string.IsNullOrEmpty(message) ||
82                 imageConfig == null ||
83                 string.IsNullOrEmpty(imageConfig.Path) ||
84                 type == BarcodeType.Undefined ||
85                 (type == BarcodeType.QR &&
86                 (qrConfig == null ||
87                 qrConfig.ErrorCorrectionLevel == ErrorCorrectionLevel.Unavailable ||
88                 qrConfig.Mode == QrMode.Unavailable ||
89                 qrConfig.Version < 1 ||
90                 qrConfig.Version > 40)))
91             {
92                 throw new ArgumentException("Invalid parameter");
93             }
94
95             int ret = (type == BarcodeType.QR) ?
96                         Interop.MediaVision.BarCodeGenerator.GenerateImage(config._engineHandle,
97                                                                             message,
98                                                                             imageConfig.Width,
99                                                                             imageConfig.Height,
100                                                                             type,
101                                                                             qrConfig.Mode,
102                                                                             qrConfig.ErrorCorrectionLevel,
103                                                                             qrConfig.Version,
104                                                                             imageConfig.Path,
105                                                                             imageConfig.Format) :
106                         Interop.MediaVision.BarCodeGenerator.GenerateImage(config._engineHandle,
107                                                                             message,
108                                                                             imageConfig.Width,
109                                                                             imageConfig.Height,
110                                                                             type,
111                                                                             QrMode.Unavailable,
112                                                                             ErrorCorrectionLevel.Unavailable,
113                                                                             0,
114                                                                             imageConfig.Path,
115                                                                             imageConfig.Format);
116             MediaVisionErrorFactory.CheckAndThrowException(ret, "Failed to generate image");
117         }
118     }
119 }