2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Diagnostics;
19 using System.Runtime.InteropServices;
20 using static Interop.Camera;
22 namespace Tizen.Multimedia
25 /// The class containing the preview image data.
27 /// <since_tizen> 4 </since_tizen>
28 public class PreviewFrame
30 internal PreviewFrame(IntPtr ptr)
32 var unmanagedStruct = Marshal.PtrToStructure<CameraPreviewDataStruct>(ptr);
34 Format = unmanagedStruct.Format;
35 Resolution = new Size(unmanagedStruct.Width, unmanagedStruct.Height);
36 TimeStamp = unmanagedStruct.TimeStamp;
37 PlaneType = GetPlaneType(unmanagedStruct);
38 Plane = ConvertPlane(unmanagedStruct);
41 private IPreviewPlane ConvertPlane(CameraPreviewDataStruct unmanagedStruct)
43 if (unmanagedStruct.NumOfPlanes == 1)
45 if (unmanagedStruct.Format == CameraPixelFormat.H264 || unmanagedStruct.Format == CameraPixelFormat.Jpeg)
47 return new EncodedPlane(unmanagedStruct.Plane.EncodedPlane);
49 else if (unmanagedStruct.Format == CameraPixelFormat.Invz)
51 return new DepthPlane(unmanagedStruct.Plane.DepthPlane);
53 else if (unmanagedStruct.Format == CameraPixelFormat.Rgba || unmanagedStruct.Format == CameraPixelFormat.Argb)
55 return new RgbPlane(unmanagedStruct.Plane.RgbPlane);
59 return new SinglePlane(unmanagedStruct.Plane.SinglePlane);
62 else if (unmanagedStruct.NumOfPlanes == 2)
64 var size = Resolution.Width * Resolution.Height;
65 unmanagedStruct.Plane.DoublePlane.YLength = (uint)size;
66 unmanagedStruct.Plane.DoublePlane.UVLength = (uint)size / 2;
67 return new DoublePlane(unmanagedStruct.Plane.DoublePlane);
69 else if (unmanagedStruct.NumOfPlanes == 3)
71 return new TriplePlane(unmanagedStruct.Plane.TriplePlane);
74 Debug.Fail("Unknown preview data!");
78 private static PlaneType GetPlaneType(CameraPreviewDataStruct unmanagedStruct)
80 if (unmanagedStruct.NumOfPlanes == 1)
82 if (unmanagedStruct.Format == CameraPixelFormat.H264 || unmanagedStruct.Format == CameraPixelFormat.Jpeg)
84 return PlaneType.EncodedPlane;
86 else if (unmanagedStruct.Format == CameraPixelFormat.Invz)
88 return PlaneType.DepthPlane;
90 else if (unmanagedStruct.Format == CameraPixelFormat.Rgba || unmanagedStruct.Format == CameraPixelFormat.Argb)
92 return PlaneType.RgbPlane;
96 return PlaneType.SinglePlane;
99 else if (unmanagedStruct.NumOfPlanes == 2)
101 return PlaneType.DoublePlane;
104 return PlaneType.TriplePlane;
108 /// The pixel format of the image.
110 /// <since_tizen> 4 </since_tizen>
111 public CameraPixelFormat Format { get; }
114 /// The resolution of the preview image.
116 /// <since_tizen> 4 </since_tizen>
117 public Size Resolution { get; }
120 /// The time stamp of the preview frame.
122 /// <since_tizen> 4 </since_tizen>
123 public uint TimeStamp { get; }
126 /// The type of the preview plane. <see cref="Tizen.Multimedia.PlaneType"/>
128 /// <since_tizen> 4 </since_tizen>
129 public PlaneType PlaneType { get; }
132 /// The buffer including the preview frame.
134 /// <since_tizen> 4 </since_tizen>
135 public IPreviewPlane Plane { get; }