summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChangyeon Lee <cyeon.lee@samsung.com>2016-12-20 16:23:30 +0900
committerChangyeon Lee <cyeon.lee@samsung.com>2016-12-21 19:29:32 +0900
commit70a0e7b8122032f7893f8fbdfbbc3cf9e37d1598 (patch)
treeab8ac07276b9c9ac18e5811782f38ed14fbb25ff
parentd5ffc98a8531e69c2f9994f6d91532721c87b498 (diff)
downloadlibtbm-accepted/tizen_3.0.m2_mobile.tar.gz
libtbm-accepted/tizen_3.0.m2_mobile.tar.bz2
libtbm-accepted/tizen_3.0.m2_mobile.zip
Change-Id: I43f6976b05a1e00099b4df0bcd2c6edb8966ce63
-rw-r--r--src/tbm_surface_internal.c109
-rw-r--r--src/tbm_surface_internal.h48
2 files changed, 153 insertions, 4 deletions
diff --git a/src/tbm_surface_internal.c b/src/tbm_surface_internal.c
index bcb4509..2620ff0 100644
--- a/src/tbm_surface_internal.c
+++ b/src/tbm_surface_internal.c
@@ -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*/
diff --git a/src/tbm_surface_internal.h b/src/tbm_surface_internal.h
index a90201f..10f4daf 100644
--- a/src/tbm_surface_internal.h
+++ b/src/tbm_surface_internal.h
@@ -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