From: Radek Kintop Date: Fri, 2 Oct 2015 15:58:05 +0000 (+0200) Subject: Documentation for wearable native circular Circular camera sample. X-Git-Tag: tizen_3.0/TD_SYNC/20161201~345 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a40f5f8b89743bdb65203145fe7101082808b6e0;p=sdk%2Fonline-doc.git Documentation for wearable native circular Circular camera sample. Change-Id: Iaa0edb9fcf90dc5812354d84d5922a71204caaa5 Signed-off-by: Radek Kintop --- diff --git a/org.tizen.sampledescriptions/html/images/circlecircular_camera_wn0.png b/org.tizen.sampledescriptions/html/images/circlecircular_camera_wn0.png new file mode 100644 index 0000000..2b2a153 Binary files /dev/null and b/org.tizen.sampledescriptions/html/images/circlecircular_camera_wn0.png differ diff --git a/org.tizen.sampledescriptions/html/images/circlecircular_camera_wn1.png b/org.tizen.sampledescriptions/html/images/circlecircular_camera_wn1.png new file mode 100644 index 0000000..960f036 Binary files /dev/null and b/org.tizen.sampledescriptions/html/images/circlecircular_camera_wn1.png differ diff --git a/org.tizen.sampledescriptions/html/images/circlecircular_camera_wn2.png b/org.tizen.sampledescriptions/html/images/circlecircular_camera_wn2.png new file mode 100644 index 0000000..90cf4b9 Binary files /dev/null and b/org.tizen.sampledescriptions/html/images/circlecircular_camera_wn2.png differ diff --git a/org.tizen.sampledescriptions/html/wearable_n/circlecircular_camera_sd_wn.htm b/org.tizen.sampledescriptions/html/wearable_n/circlecircular_camera_sd_wn.htm new file mode 100644 index 0000000..a1b8bc6 --- /dev/null +++ b/org.tizen.sampledescriptions/html/wearable_n/circlecircular_camera_sd_wn.htm @@ -0,0 +1,263 @@ + + + + + + + + + + + + + + The (Circle) Circular Camera Overview + + + + +
+
+ +
+
+

Wearable native

+
+ +

The (Circle) Circular Camera Sample Overview

+ +

The (Circle) Circular Camera sample application demonstrates how you can handle Camera API, among others how to start camera preview and capture images.

+ +

The following figure illustrates two screens of the (Circle) Circular Camera sample application: the camera preview window and the camera attributes menu views.

+ +

Figure 1: (Circle) Circular camera views

+

(Circle) Circular camera views (Circle) Circular camera views

+ +

Click the red camera button to capture a picture or press the preview to enter the camera attributes list.

+

From there you can set any camera attributes this application makes available for you.

+ +

Figure 2: (Circle) Circular camera UI structure

+

(Circle) Circular camera UI structure +

+ +

Prerequisites

+

To ensure proper application execution, the http://tizen.org/privilege/mediastorage and +the http://tizen.org/privilege/camera privileges +must be set. Also, there should be the camera device installed on your device.

+ +

Implementation

+ +

View module

+

The most important part of the view module is the camera preview surface creation. For this purpose you can use the +evas filled image.

+ +
+Evas_Object *preview_surface_create(Evas_Object *parent, previev_surface_long_press_cb cb)
+{
+  Evas_Object *surface = evas_object_image_filled_add(evas_object_evas_get(parent));
+	// Common initialization code
+  return surface;
+}
+
+ +

Controller module

+

The cam module is the essential part of this application. It allows for the various camera attributes to be set.

+

The initialization function takes the preview surface (shown in view section) as a parameter. It creates a camera handle and +adds callbacks for the following events: +

    +
  • state change,
  • +
  • operation interruption,
  • +
  • error.
  • +
+

+ +
+bool cam_init(const void *evas_display_surface)
+{
+	// Common initialization code
+
+  cmd.evas_display_surface = (void *)evas_display_surface;
+
+  ok = (CAMERA_ERROR_NONE == camera_create(CAMERA_DEVICE_CAMERA0, &cmd.camera));
+  ok &= (CAMERA_ERROR_NONE == camera_set_state_changed_cb(cmd.camera, __camera_state_changed_cb, NULL));
+  ok &= (CAMERA_ERROR_NONE == camera_set_interrupted_cb(cmd.camera, __camera_interrupted_cb, NULL));
+  ok &= (CAMERA_ERROR_NONE == camera_set_error_cb(cmd.camera, __camera_error_cb, NULL));
+
+  camera_get_capture_format(cmd.camera, &cmd.pixel_format);
+
+  return ok;
+}
+
+
+static void __camera_state_changed_cb(camera_state_e previous, camera_state_e current,
+											bool by_policy, void *user_data)
+{
+  dlog_print(DLOG_INFO, LOG_TAG, "Camera state has changed from: %d to: %d by policy: %d", previous, current, by_policy);
+}
+
+
+static void __camera_interrupted_cb(camera_policy_e policy, camera_state_e previous,
+										camera_state_e current, void *user_data)
+{
+  dlog_print(DLOG_INFO, LOG_TAG, "Camera state interrupted. State has changed from: %d to: %d by policy: %d",
+        previous, current, policy);
+}
+
+

It is important to free the camera handle and release its resources when an error occurs.

+
+static void __camera_error_cb(camera_error_e error, camera_state_e current_state, void *user_data)
+{
+  dlog_print(DLOG_ERROR, LOG_TAG, "Camera error: %s has occurred; current state: %d, deinitializing",
+        get_error_message(error), current_state);
+  cam_deinit();
+}
+
+

Once the initialization is succesfully finished, the preview function can be called. Please note that +the camera state is always checked at the beginning. Starting the preview will fail unless the camera is in one of the following states: +

    +
  • CAMERA_STATE_CREATED,
  • +
  • CAMERA_STATE_CAPTURED.
  • +
+You might also notice how the preview surface (previously passed as an argument to the initialization function) is used in +camera_set_display() +function. The GET_DISPLAY() API macro has to be used as it is a portable way to convert the +Evas_Object * +to the +camera_display_h +.

+
+bool cam_start_preview(void)
+{
+  camera_state_e state = CAMERA_STATE_NONE;
+  int width = 0;
+  int height = 0;
+
+  camera_get_state(cmd.camera, &state);
+
+  if (state == CAMERA_STATE_PREVIEW)
+    return true;
+
+  if (state != CAMERA_STATE_CREATED && state != CAMERA_STATE_CAPTURED)
+    return false;
+
+  if (CAMERA_ERROR_NONE == camera_get_recommended_preview_resolution(cmd.camera, &width, &height)) {
+    camera_set_preview_resolution(cmd.camera, width, height);
+  } else {
+    return false;
+  }
+
+  camera_set_display(cmd.camera, CAMERA_DISPLAY_TYPE_EVAS, GET_DISPLAY(cmd.evas_display_surface));
+  camera_set_display_mode(cmd.camera, CAMERA_DISPLAY_MODE_FULL);
+  camera_set_display_visible(cmd.camera, true);
+  camera_start_focusing(cmd.camera, true);
+
+  return (CAMERA_ERROR_NONE == camera_start_preview(cmd.camera));
+}
+
+ +

Once the preview is successfully set up, the camera view is visible on the screen and it is possible to capture photos.

+

Photo taking is implemented in cam_start_capturing(), +__camera_capturing_cb() and +__camera_capture_completed_cb() functions.

+ +
+bool cam_start_capturing(void)
+{
+  camera_state_e state = CAMERA_STATE_NONE;
+
+  if (CAMERA_PIXEL_FORMAT_INVALID == cmd.pixel_format) {
+    dlog_print(DLOG_ERROR, LOG_TAG, "Error - capture format hasn't been selected");
+    return false;
+  }
+
+  camera_get_state(cmd.camera, &state);
+
+  if (state == CAMERA_STATE_CAPTURING)
+    return true;
+
+  if (state == CAMERA_STATE_NONE || (state != CAMERA_STATE_PREVIEW && !cam_start_preview()))
+    return false;
+
+  if (!max_width || !max_height)
+    camera_foreach_supported_capture_resolution(cmd.camera, __supported_capture_resolution_cb, NULL);
+
+  if (max_width && max_height)
+    camera_set_capture_resolution(cmd.camera, max_width, max_height);
+
+  return (CAMERA_ERROR_NONE == camera_start_capture(cmd.camera, __camera_capturing_cb, __camera_capture_completed_cb, NULL));
+}
+
+

Once the camera device has filled the image buffer, the +__camera_capturing_cb() +callback is called. This is the place to save the captured photo. The +camera_image_data_s +structure contains a raw image data buffer and information about its dimensions and buffer length. +This application allows the user to select between different types of camera images format. One of them is +CAMERA_PIXEL_FORMAT_JPEG which is already encoded. +The rest of the formats are raw types. This is why jpeg format is distinguished in the following code.

+
+static void __camera_capturing_cb(camera_image_data_s *image, camera_image_data_s *postview,
+                    camera_image_data_s *thumbnail, void *user_data)
+{
+  FILE *f = NULL;
+  int w = 0;
+  char currently_saved_file[PATH_MAX] = {0,};
+
+  if (cmd.pixel_format == CAMERA_PIXEL_FORMAT_INVALID || !image)
+    return;
+
+  if (image->format == CAMERA_PIXEL_FORMAT_JPEG) {
+    snprintf(currently_saved_file, PATH_MAX, SAVE_FILE_PATH_PATTERN, time(NULL));
+    f = fopen(currently_saved_file, "w+");
+    if (!f) {
+      dlog_print(DLOG_ERROR, LOG_TAG, "Could not obtain handle for file %s ", currently_saved_file);
+      return;
+    }
+
+    do {
+      w += fwrite(image->data + w, sizeof(unsigned char), image->size - w, f);
+    } while (w < image->size);
+
+    fclose(f);
+  } else {
+    __encode_to_jpeg(image->data, image->width, image->height, currently_saved_file);
+  }
+}
+
+ +

When the capture callback returns and the camera's internal state is updated, another callback is invoked - +__camera_capture_completed_cb(). This +gives the developer a chance to change the camera state from CAMERA_STATE_CAPTURED +to +CAMERA_STATE_PREVIEW and allows the camera +view to be continuously displayed again.

+
+static void __camera_capture_completed_cb(void *user_data)
+{
+  cam_start_preview();
+}
+
+ + + +
+ +Go to top + + + + + + + diff --git a/org.tizen.sampledescriptions/html/wearable_n/sd_wn.htm b/org.tizen.sampledescriptions/html/wearable_n/sd_wn.htm index 3ea839e..b2c970c 100644 --- a/org.tizen.sampledescriptions/html/wearable_n/sd_wn.htm +++ b/org.tizen.sampledescriptions/html/wearable_n/sd_wn.htm @@ -64,6 +64,9 @@ (Circle) Ambient Analog Watch Demonstrates how you can implement a simple watch application with ambient mode support. + + (Circle) Circular camera + Demonstrates how you can handle Camera API, among others how to start camera preview and capture images. (Circle) Email