[camera tutorial] adding camera display setting tutorial
authorHyuntae Kim <ht1211.kim@samsung.com>
Wed, 5 Aug 2015 10:33:21 +0000 (19:33 +0900)
committerHyuntae Kim <ht1211.kim@samsung.com>
Wed, 5 Aug 2015 11:41:31 +0000 (20:41 +0900)
Change-Id: I0fe313309fabed02c8b3c3cd4fce7f77ace7cdff
Signed-off-by: hyuntae kim <ht1211.kim@samsung.com>
org.tizen.tutorials/html/native/multimedia/camera_tutorial_n.htm

index d0f7db0..063ec8f 100644 (file)
@@ -24,6 +24,7 @@
                <p class="toc-title">Content</p>
                <ul class="toc">
                        <li><a href="#init">Initializing the Camera</a></li>
+                       <li><a href="#display">Setting the Display for Camera Preview</a></li>
                        <li><a href="#photo">Taking a Photo</a></li>
                        <li><a href="#attributes">Setting Camera Attributes</a></li>
                        <li><a href="#release">Releasing Resources</a></li>
@@ -49,6 +50,9 @@
  <li><a href="#init">Initializing the Camera</a>
  <p>Initialize the camera for use.</p>
  </li>
+ <li><a href="#display">Setting the Display for Camera Preview</a>
+  <p>Diplay the camera preview</p>
+ </li>
  <li><a href="#photo">Taking a Photo</a>
   <p>Start a camera preview and take a photo.</p>
  </li>
@@ -342,9 +346,106 @@ static void _camera_focus_cb(camera_focus_state_e state, void *user_data)
 }</pre>
 
 </li>
-
 </ol>
 
+ <li>
+        <h2 id="display" name="display">Setting the Display for Camera Preview</h2>
+                <p>In order to display camera preview to the screen, need to check settings for camera display.</p>
+                <p>Camera Framework already provided proper display with default setting. Applications don't have to invoke display setting. However, if some applications want to use own display setting, you refer this page for intended display setting.</p>
+                <ol>
+                       <li>Camera Device Location
+                               <p>To display camera preview to the screen, you need to check device location.</p>
+                               <p>This location of camera device depends on the hardware device.</p>
+                               <pre class="prettyprint">
+typedef enum
+{
+    CAMERA_DEVICE_CAMERA0 = 0, /**< Primary camera*/
+    CAMERA_DEVICE_CAMERA1      /**< Secondary camera*/
+} camera_device_e;
+                               </pre>
+                       </li>
+                       <li>Camera Device Orientation</li>
+                               <p>To consider proper display, you must think the physical lens orientation and location.</p>
+                               <p>If the facing direction of camera is opposite to the display, camear device orientation is calculated clockwise. If the facing direction of camera is same direction to the display, camera device orientation is calculated counterclockwise.</p>
+                               <pre class="prettyprint">
+int angle = 0;
+int error_code = 0;
+error_code = camera_attr_get_lens_orientation(cam_data.g_camera, &angle);
+                               </pre>
+                               <p>If your camera device is opposite to the display, the right side is 90 degrees and If it is same as the display direction, right side is 270 degrees</p>
+                         <p>The returned value of "angle" is degress</p>
+                       <li>Default display settings</li>
+                               <p>Camera display settings are already set internally. For example, the Sencondary camera is already set flip for supporting mirror mode.</p>
+                               <p>If application sets any other values with camera_set_display_rotation, camera_get_display_flip, these default values will be changed.</p>
+                               <p>Therefore, remind that these valuses should be get the default display right after initializing the camera</p>
+                               <pre class="prettyprint">
+camera_rotation_e rotation = 0;
+camera_flip_e flip = 0
+int error_code = 0;
+//To get default display rotation value
+error_code = camera_get_display_rotation(cam_data.g_camera, &rotation);
+//To get default display flip value
+error_code = camera_get_display_flip(cam_data.g_camera, &flip);
+                               </pre>
+                       <li>Display Rotation</li>
+                        <p>The recommended display rotation can be calculated like below</p>
+                        <pre class="prettyprint">
+int lens_orientation = 0;
+int error_code = 0;
+camera_rotation_e display_rotation = CAMERA_ROTATION_NONE;
+int display_rotation_angle = 0;
+
+// To get recommanded display rotation value
+error_code = camera_attr_get_lens_orientation (cam_data.g_camera, &lens_orientation);
+display_rotation_angle = (360 - lens_orientation) % 360;
+
+// To convert to enum type and set display rotation
+switch(display_rotation_angle) {
+    case   0: display_rotation = CAMERA_ROTATION_NONE; break;
+    case  90: display_rotation = CAMERA_ROTATION_90; break;
+    case 180: display_rotation = CAMERA_ROTATION_180; break;
+    case 270: display_rotation = CAMERA_ROTATION_270; break;
+    default : display_rotation = CAMERA_ROTATION_NONE; break;
+}
+error_code = camera_set_display_rotation(cam_data.g_camera, display_rotation);
+                               </pre>
+                       <li>Display Flip</li>
+                        <p>According to the camera facing direction, you need to select flip api.</p>
+                        <p>Because the display flip api runs after display rotation api, you need to remind calculation carefully with camera facing direction.</p>
+                        <pre class="prettyprint">
+//If the facing direction of camera is same as display module, it is needed to apply flip for front camera, because of mirror effect
+int lens_orientation = 0;
+int error_code = 0;
+camera_flip_e camera_default_flip = MM_FLIP_NONE;
+
+// To get recommanded display rotation value
+error_code = camera_attr_get_lens_orientation (cam_data.g_camera, &lens_orientation);
+display_rotation_angle = (360 - lens_orientation) % 360;
+
+// To set mirror display
+if (display_rotation_angle == 90 || display_rotation_angle == 270) {
+    camera_default_flip = MM_FLIP_VERTICAL;
+} else {
+    camera_default_flip = MM_FLIP_HORIZONTAL;
+}
+
+// To set display flip
+error_code = camera_set_display_flip(cam_data.g_camera, camera_default_flip);
+  </pre>
+  </ol>
+ <table class="note">
+ <tbody>
+  <tr>
+  <th class="note">Note</th>
+  </tr>
+  <tr>
+   <td class="note">In case of an overlay surface, when the device orientation changes, the displayed camera preview does not rotate automatically. If you want to change the display orientation according to the device orientation, use the camera_set_display_rotation() function within the app_device_orientation_cb() callback function used by the application.
+    In case of an Evas surface, the Evas object for camera display is rotated by the window manager used by the application, not by the camera_set_display_rotation() function.</span> function.</td>
+  </tr>
+ </tbody>
+ </table>
+ </li>
+
  <h2 id="photo" name="photo">Taking a Photo</h2>
 
 <p>To take a photo:</p>