added capture buffer api 31/106331/2 accepted/tizen_3.0.m2_mobile accepted/tizen_3.0.m2_tv accepted/tizen_3.0.m2_wearable tizen_3.0.m2 accepted/tizen/3.0.m2/mobile/20170104.143214 accepted/tizen/3.0.m2/tv/20170104.143602 accepted/tizen/3.0.m2/wearable/20170104.143958 accepted/tizen/3.0/common/20161222.181429 accepted/tizen/3.0/ivi/20161222.093521 accepted/tizen/3.0/mobile/20161222.093437 accepted/tizen/3.0/tv/20161222.093449 accepted/tizen/3.0/wearable/20161222.093512 accepted/tizen/common/20161221.183438 accepted/tizen/ivi/20161222.020401 accepted/tizen/mobile/20161222.020348 accepted/tizen/tv/20161222.020258 accepted/tizen/wearable/20161222.020357 submit/tizen/20161221.104155 submit/tizen_3.0.m2/20170104.093752 submit/tizen_3.0/20161221.104250
authorChangyeon Lee <cyeon.lee@samsung.com>
Tue, 20 Dec 2016 07:23:30 +0000 (16:23 +0900)
committerChangyeon Lee <cyeon.lee@samsung.com>
Wed, 21 Dec 2016 10:29:32 +0000 (19:29 +0900)
Change-Id: I43f6976b05a1e00099b4df0bcd2c6edb8966ce63

src/tbm_surface_internal.c
src/tbm_surface_internal.h

index bcb4509..2620ff0 100644 (file)
@@ -1891,4 +1891,113 @@ void tbm_surface_internal_dump_shm_buffer(void *ptr, int w, int h, int stride,
 
        TBM_LOG_I("Dump %s \n", buf_info->name);
 }
+
+int
+tbm_surface_internal_capture_buffer(tbm_surface_h surface, const char *path, const char *name, const char *type)
+{
+       TBM_RETURN_VAL_IF_FAIL(surface != NULL, 0);
+       TBM_RETURN_VAL_IF_FAIL(path != NULL, 0);
+       TBM_RETURN_VAL_IF_FAIL(name != NULL, 0);
+
+       tbm_surface_info_s info;
+       const char *postfix;
+       int ret;
+       char file[1024];
+
+       ret = tbm_surface_map(surface, TBM_SURF_OPTION_READ|TBM_SURF_OPTION_WRITE, &info);
+       TBM_RETURN_VAL_IF_FAIL(ret == TBM_SURFACE_ERROR_NONE, 0);
+
+       if (info.format == TBM_FORMAT_ARGB8888 || info.format == TBM_FORMAT_XRGB8888)
+               postfix = dump_postfix[0];
+       else
+               postfix = dump_postfix[1];
+
+       if (strcmp(postfix, type)) {
+               TBM_LOG_E("not support type(%s) %c%c%c%c buffer", type, FOURCC_STR(info.format));
+               tbm_surface_unmap(surface);
+               return 0;
+       }
+
+       snprintf(file, sizeof(file), "%s/%s.%s", path , name, postfix);
+
+       if (!access(file, 0)) {
+               TBM_LOG_E("can't capture  buffer, exist file %s", file);
+               tbm_surface_unmap(surface);
+               return 0;
+       }
+
+       switch (info.format) {
+       case TBM_FORMAT_ARGB8888:
+       case TBM_FORMAT_XRGB8888:
+               _tbm_surface_internal_dump_file_png(file, info.planes[0].ptr,
+                                                       info.planes[0].stride >> 2,
+                                                       info.height);
+               break;
+       case TBM_FORMAT_YVU420:
+       case TBM_FORMAT_YUV420:
+               _tbm_surface_internal_dump_file_raw(file, info.planes[0].ptr,
+                               info.planes[0].stride * info.height,
+                               info.planes[1].ptr,
+                               info.planes[1].stride * (info.height >> 1),
+                               info.planes[2].ptr,
+                               info.planes[2].stride * (info.height >> 1));
+               break;
+       case TBM_FORMAT_NV12:
+       case TBM_FORMAT_NV21:
+               _tbm_surface_internal_dump_file_raw(file, info.planes[0].ptr,
+                                       info.planes[0].stride * info.height,
+                                       info.planes[1].ptr,
+                                       info.planes[1].stride * (info.height >> 1),
+                                       NULL, 0);
+               break;
+       case TBM_FORMAT_YUYV:
+       case TBM_FORMAT_UYVY:
+               _tbm_surface_internal_dump_file_raw(file, info.planes[0].ptr,
+                                       info.planes[0].stride * info.height,
+                                       NULL, 0, NULL, 0);
+               break;
+       default:
+               TBM_LOG_E("can't dump %c%c%c%c buffer", FOURCC_STR(info.format));
+               tbm_surface_unmap(surface);
+               return 0;
+       }
+
+       tbm_surface_unmap(surface);
+
+       TBM_LOG_I("Capture %s \n", file);
+
+       return 1;
+}
+
+int
+tbm_surface_internal_capture_shm_buffer(void *ptr, int w, int h, int stride,
+                                               const char *path, const char *name, const char *type)
+{
+       TBM_RETURN_VAL_IF_FAIL(ptr != NULL, 0);
+       TBM_RETURN_VAL_IF_FAIL(w > 0, 0);
+       TBM_RETURN_VAL_IF_FAIL(h > 0, 0);
+       TBM_RETURN_VAL_IF_FAIL(stride > 0, 0);
+       TBM_RETURN_VAL_IF_FAIL(path != NULL, 0);
+       TBM_RETURN_VAL_IF_FAIL(name != NULL, 0);
+
+       char file[1024];
+
+       if (strcmp(dump_postfix[0], type)) {
+               TBM_LOG_E("Not supported type:%s'", type);
+               return 0;
+       }
+
+       if (!access(file, 0)) {
+               TBM_LOG_E("can't capture buffer, exist file %s", file);
+               return 0;
+       }
+
+       snprintf(file, sizeof(file), "%s/%s.%s", path , name, dump_postfix[0]);
+
+       _tbm_surface_internal_dump_file_png(file, ptr, stride, h);
+
+       TBM_LOG_I("Capture %s \n", file);
+
+       return 1;
+}
 /*LCOV_EXCL_STOP*/
index a90201f..10f4daf 100644 (file)
@@ -440,9 +440,9 @@ void tbm_surface_internal_dump_end(void);
  * The filename extension should be "png" for TBM_FORMAT_ARGB8888 and TBM_FORMAT_XRGB8888
  * or "yuv" for YUV formats.
  * @param[in] surface : a tbm surface
- * @param[in] type : a string used by a file name
+ * @param[in] name : a string used by a file name
  */
-void tbm_surface_internal_dump_buffer(tbm_surface_h surface, const char *type);
+void tbm_surface_internal_dump_buffer(tbm_surface_h surface, const char *name);
 
 /**
  * @brief Dump a shared memory buffer
@@ -452,9 +452,9 @@ void tbm_surface_internal_dump_buffer(tbm_surface_h surface, const char *type);
  * @param[in] w : a width of dump buffer
  * @param[in] h : a height of dump buffer
  * @param[in] stride : a stride of dump buffer
- * @param[in] type : a string used by a file name
+ * @param[in] name : a string used by a file name
  */
-void tbm_surface_internal_dump_shm_buffer(void *ptr, int w, int h, int stride, const char *type);
+void tbm_surface_internal_dump_shm_buffer(void *ptr, int w, int h, int stride, const char *name);
 
 /**
  * @brief check valid tbm surface.
@@ -464,6 +464,46 @@ void tbm_surface_internal_dump_shm_buffer(void *ptr, int w, int h, int stride, c
  */
 int tbm_surface_internal_is_valid(tbm_surface_h surface);
 
+/**
+ * @brief Capture a buffer
+ * @details
+ * This function supports only if a buffer has below formats.
+ * - TBM_FORMAT_ARGB8888
+ * - TBM_FORMAT_XRGB8888
+ * - TBM_FORMAT_YVU420
+ * - TBM_FORMAT_YUV420
+ * - TBM_FORMAT_NV12
+ * - TBM_FORMAT_NV21
+ * - TBM_FORMAT_YUYV
+ * - TBM_FORMAT_UYVY
+ * The type should be "png" for TBM_FORMAT_ARGB8888 and TBM_FORMAT_XRGB8888
+ * or "yuv" for YUV formats.
+ * @param[in] surface : a tbm surface
+ * @param[in] path : the given dump path
+ * @param[in] name : a string used by a file name
+ * @param[in] type : a string used by a file type ex)png, yuv
+ * @return 1 if success, otherwise 0.
+ */
+int tbm_surface_internal_capture_buffer(tbm_surface_h surface, const char *path,
+                                      const char *name, const char *type);
+
+/**
+ * @brief Capture a shared memory buffer
+ * @details
+ * This function supports shared memory buffer dump.
+ * The type should be "png".
+ * @param[in] ptr : a pointer of dump buffer
+ * @param[in] w : a width of dump buffer
+ * @param[in] h : a height of dump buffer
+ * @param[in] stride : a stride of dump buffer
+ * @param[in] path : the given dump path
+ * @param[in] name : a string used by a file name
+ * @param[in] type : a string used by a file type ex)png, yuv
+ * @return 1 if success, otherwise 0.
+ */
+int tbm_surface_internal_capture_shm_buffer(void *ptr, int w, int h, int stride,
+                                      const char *path, const char *name, const char *type);
+
 #ifdef __cplusplus
 }
 #endif