Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Content.MediaContent / Tizen.Content.MediaContent / ImageInformation.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
18
19 using System;
20 using System.Collections.Generic;
21 using System.Threading.Tasks;
22 using System.Collections.ObjectModel;
23 using System.Runtime.InteropServices;
24
25 namespace Tizen.Content.MediaContent
26 {
27     /// <summary>
28     /// ImageContent class API gives the information related to the image media stored in the device</summary>
29     public class ImageInformation : MediaInformation
30     {
31         private readonly Interop.ImageInformation.SafeImageInformationHandle _handle;
32
33         /// <summary>
34         ///  Gets the id of the media.
35         /// </summary>
36         /// <since_tizen> 3 </since_tizen>
37         public string MediaId
38         {
39             get
40             {
41                 IntPtr val = IntPtr.Zero;
42                 try
43                 {
44                     MediaContentValidator.ThrowIfError(
45                         Interop.ImageInformation.GetMediaId(_handle, out val), "Failed to get value");
46
47                     return Marshal.PtrToStringAnsi(val);
48                 }
49                 finally
50                 {
51                     Interop.Libc.Free(val);
52                 }
53             }
54         }
55
56         /// <summary>
57         ///  Gets the image width in pixels.
58         /// </summary>
59         /// <since_tizen> 3 </since_tizen>
60         public int Width
61         {
62             get
63             {
64                 int width = 0;
65                 MediaContentValidator.ThrowIfError(
66                     Interop.ImageInformation.GetWidth(_handle, out width), "Failed to get value");
67
68                 return width;
69             }
70         }
71
72         /// <summary>
73         ///  Gets the image height in pixels.
74         /// </summary>
75         /// <since_tizen> 3 </since_tizen>
76         public int Height
77         {
78             get
79             {
80                 int height = 0;
81                 MediaContentValidator.ThrowIfError(
82                     Interop.ImageInformation.GetHeight(_handle, out height), "Failed to get value");
83
84                 return height;
85             }
86         }
87
88         /// <summary>
89         ///  Image orientation.
90         /// </summary>
91         /// <since_tizen> 3 </since_tizen>
92         public MediaContentOrientation Orientation
93         {
94             get
95             {
96                 MediaContentOrientation orientation = MediaContentOrientation.NotAvailable;
97                 MediaContentValidator.ThrowIfError(
98                     Interop.ImageInformation.GetOrientation(_handle, out orientation), "Failed to get value");
99
100                 return orientation;
101             }
102
103             set
104             {
105                 MediaContentValidator.ThrowIfError(
106                     Interop.ImageInformation.SetOrientation(_handle, value), "Failed to set value");
107             }
108         }
109
110         /// <summary>
111         /// Gets the image creation time in seconds, since the Epoch.
112         /// </summary>
113         /// <since_tizen> 3 </since_tizen>
114         public string TakenDate
115         {
116             get
117             {
118                 IntPtr val = IntPtr.Zero;
119                 try
120                 {
121                     MediaContentValidator.ThrowIfError(
122                         Interop.ImageInformation.GetDateTaken(_handle, out val), "Failed to get value");
123
124                     return Marshal.PtrToStringAnsi(val);
125                 }
126                 finally
127                 {
128                     Interop.Libc.Free(val);
129                 }
130             }
131         }
132
133         /// <summary>
134         /// Gets the burst shot ID.
135         /// If BurstId is null, this is not a burst shot
136         /// </summary>
137         /// <since_tizen> 3 </since_tizen>
138         public string BurstId
139         {
140             get
141             {
142                 IntPtr val = IntPtr.Zero;
143                 try
144                 {
145                     MediaContentValidator.ThrowIfError(
146                         Interop.ImageInformation.GetBurstId(_handle, out val), "Failed to get value");
147
148                     return Marshal.PtrToStringAnsi(val);
149                 }
150                 finally
151                 {
152                     Interop.Libc.Free(val);
153                 }
154             }
155         }
156
157         /// <summary>
158         /// Gets the exposure time from exif.
159         /// </summary>
160         /// <since_tizen> 3 </since_tizen>
161         public string ExposureTime
162         {
163             get
164             {
165                 IntPtr val = IntPtr.Zero;
166                 try
167                 {
168                     MediaContentValidator.ThrowIfError(
169                         Interop.ImageInformation.GetExposureTime(_handle, out val), "Failed to get value");
170
171                     return Marshal.PtrToStringAnsi(val);
172                 }
173                 finally
174                 {
175                     Interop.Libc.Free(val);
176                 }
177             }
178         }
179
180         /// <summary>
181         /// Gets the fnumber from exif.
182         /// </summary>
183         /// <since_tizen> 3 </since_tizen>
184         public double FNumber
185         {
186             get
187             {
188                 double fNumber = 0.0;
189                 MediaContentValidator.ThrowIfError(
190                     Interop.ImageInformation.GetFNumber(_handle, out fNumber), "Failed to get value");
191
192                 return fNumber;
193             }
194         }
195
196         /// <summary>
197         /// Gets the iso from exif.
198         /// </summary>
199         /// <since_tizen> 3 </since_tizen>
200         public int Iso
201         {
202             get
203             {
204                 int iso = 0;
205                 MediaContentValidator.ThrowIfError(
206                     Interop.ImageInformation.GetISO(_handle, out iso), "Failed to get value");
207
208                 return iso;
209             }
210         }
211
212         /// <summary>
213         /// Gets the model from exif.
214         /// </summary>
215         /// <since_tizen> 3 </since_tizen>
216         public string Model
217         {
218             get
219             {
220                 IntPtr val = IntPtr.Zero;
221                 try
222                 {
223                     MediaContentValidator.ThrowIfError(
224                         Interop.ImageInformation.GetModel(_handle, out val), "Failed to get value");
225
226                     return Marshal.PtrToStringAnsi(val);
227                 }
228                 finally
229                 {
230                     Interop.Libc.Free(val);
231                 }
232             }
233         }
234
235         /// <summary>
236         /// Checks whether the media is a burst shot image.
237         /// The value is true if the media is a burst shot image,
238         /// otherwise false if the media is not a burst shot image.
239         /// </summary>
240         /// <since_tizen> 3 </since_tizen>
241         public bool IsBurstShot
242         {
243             get
244             {
245                 bool isBurst = false;
246                 MediaContentValidator.ThrowIfError(
247                     Interop.ImageInformation.IsBurstShot(_handle, out isBurst), "Failed to get value");
248
249                 return isBurst;
250             }
251         }
252
253         /// <summary>
254         /// Iterates through the media faces with filter in the given media file from the media database.
255         /// If NULL is passed to the filter, no filtering is applied.
256         /// </summary>
257         /// <since_tizen> 3 </since_tizen>
258         /// <returns>
259         /// Task to get all the MediaFaces </returns>
260         /// <param name="filter"> filter for the Tags</param>
261         public IEnumerable<MediaFace> GetMediaFaces(ContentFilter filter)
262         {
263             Collection<MediaFace> coll = new Collection<MediaFace>();
264
265             Interop.MediaInformation.MediaFaceCallback callback = (IntPtr faceHandle, IntPtr userData) =>
266             {
267                 IntPtr newHandle = IntPtr.Zero;
268                 MediaContentValidator.ThrowIfError(
269                     Interop.Face.Clone(out newHandle, faceHandle), "Failed to clone Tag");
270
271                 coll.Add(new MediaFace(newHandle));
272                 return true;
273             };
274             IntPtr filterHandle = (filter != null) ? filter.Handle : IntPtr.Zero;
275             MediaContentValidator.ThrowIfError(
276                 Interop.MediaInformation.GetAllFaces(MediaId, filterHandle, callback, IntPtr.Zero), "Failed to get value");
277
278             return coll;
279         }
280
281         /// <summary>
282         /// Gets the number of faces for the passed filter in the given media ID from the media database.
283         /// </summary>
284         /// <since_tizen> 3 </since_tizen>
285         /// <returns>
286         /// int count</returns>
287         /// <param name="filter">The Filter for matching Face</param>
288         public int GetMediaFaceCount(ContentFilter filter)
289         {
290             int count = 0;
291             IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero;
292             MediaContentValidator.ThrowIfError(
293                 Interop.MediaInformation.GetFaceCount(MediaId, handle, out count), "Failed to get value");
294
295             return count;
296         }
297
298
299         /// <summary>
300         /// Inserts a MediaFace item to the media database
301         /// </summary>
302         /// <since_tizen> 3 </since_tizen>
303         /// <param name="image">The image on which face is to be added</param>
304         /// <param name="rect">The dimensions of the face</param>
305         /// <returns>The MediaFace instance</returns>
306         public MediaFace AddFace(ImageInformation image, FaceRect rect)
307         {
308             MediaFace face = new MediaFace(image, rect);
309             ContentManager.Database.Insert(face);
310             return face;
311         }
312
313         /// <summary>
314         /// Deletes the MediaFace from the media database.
315         /// </summary>
316         /// <since_tizen> 3 </since_tizen>
317         /// <param name="face">The face instance to be deleted</param>
318         public void DeleteFace(MediaFace face)
319         {
320             ContentManager.Database.Delete(face);
321         }
322
323         /// <summary>
324         /// Updates the MediaFace in the media database
325         /// </summary>
326         /// <since_tizen> 3 </since_tizen>
327         /// <param name="face">The MediaFace object to be updated</param>
328         public void UpdateFace(MediaFace face)
329         {
330             ContentManager.Database.Update(face);
331         }
332
333         internal IntPtr ImageHandle
334         {
335             get
336             {
337                 return _handle.DangerousGetHandle();
338             }
339         }
340
341         internal ImageInformation(Interop.ImageInformation.SafeImageInformationHandle handle, Interop.MediaInformation.SafeMediaInformationHandle mediaInformationHandle)
342             : base(mediaInformationHandle)
343         {
344             _handle = handle;
345         }
346     }
347 }