Release 4.0.0-preview1-00172
[platform/core/csapi/tizenfx.git] / src / Tizen.Content.MediaContent / Tizen.Content.MediaContent / FaceInfo.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.Content.MediaContent
20 {
21     /// <summary>
22     /// Represents the face information for the media.
23     /// </summary>
24     public class FaceInfo
25     {
26         internal FaceInfo(IntPtr handle)
27         {
28             Id = InteropHelper.GetString(handle, Interop.Face.GetId);
29             MediaInfoId = InteropHelper.GetString(handle, Interop.Face.GetMediaId);
30
31             Tag = InteropHelper.GetString(handle, Interop.Face.GetTag);
32             Orientation = InteropHelper.GetValue<IntPtr, Orientation>(handle, Interop.Face.GetOrientation);
33
34             Rect = GetRect(handle);
35         }
36
37         private static Rectangle GetRect(IntPtr faceHandle)
38         {
39             Interop.Face.GetFaceRect(faceHandle, out var x, out var y, out var width, out var height).
40                 ThrowIfError("Failed to get rect for the face info");
41
42             return new Rectangle(x, y, width, height);
43         }
44
45         /// <summary>
46         /// Gets the region.
47         /// </summary>
48         /// <value>The region of face in the media.</value>
49         /// <remarks>
50         /// The coordinates of the rectangle are orientation-applied values.
51         /// </remarks>
52         public Rectangle Rect { get; }
53
54         /// <summary>
55         /// Gets the ID of face information.
56         /// </summary>
57         public string Id { get; }
58
59         /// <summary>
60         /// Gets the media ID that the face information is added.
61         /// </summary>
62         /// <value>The media ID that the face information is added.</value>
63         public string MediaInfoId { get; }
64
65         /// <summary>
66         /// Gets the tag name.
67         /// </summary>
68         /// <value>The tag name of face information.</value>
69         public string Tag { get; }
70
71         /// <summary>
72         /// Gets the orientation of face information.
73         /// </summary>
74         /// <value>The orientation of face information.</value>
75         public Orientation Orientation { get; }
76
77         internal static FaceInfo FromHandle(IntPtr handle)
78         {
79             return new FaceInfo(handle);
80         }
81
82         /// <summary>
83         /// Returns a string representation of the face information.
84         /// </summary>
85         /// <returns>A string representation of the current face info.</returns>
86         public override string ToString() =>
87             $"Id={Id}, MediaInfoId={MediaInfoId}, Rect=({Rect}), Tag={Tag}";
88     }
89 }