From 02e2076eef52d4da40acab0ab4f57ea1fd1c4b7d Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Fri, 6 Nov 2015 17:03:24 +0900 Subject: [PATCH] Added image_util_extract_color_from_buffer() API Change-Id: Ic7d73dec684868f4201365e4f1274434841969fc Signed-off-by: Tae-Young Chung --- CMakeLists.txt | 2 +- include/image_util.h | 29 ++++++-- packaging/capi-media-image-util.spec | 4 +- src/image_util.c | 99 +++++++++++++++----------- test/image_util_test.c | 102 +++++++++++++-------------- 5 files changed, 135 insertions(+), 101 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a0a8936..3a85ffb 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ SET(service "media") SET(submodule "image-util") # for package file -SET(dependents "dlog mmutil-jpeg mmutil-imgp capi-base-common capi-media-tool") +SET(dependents "dlog mmutil-jpeg mmutil-imgp mmutil-imgcv capi-base-common capi-media-tool") SET(pc_dependents "dlog capi-base-common capi-media-tool") SET(fw_name "${project_prefix}-${service}-${submodule}") diff --git a/include/image_util.h b/include/image_util.h index 92f827c..21921ee 100755 --- a/include/image_util.h +++ b/include/image_util.h @@ -202,7 +202,7 @@ int image_util_transform_set_crop_area(transformation_h handle, unsigned int sta * @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Not supported format * * @pre image_util_transform_create().\n - image_util_transform_set_crop_area(). +* image_util_transform_set_crop_area(). * * @see image_util_transform_create() * @see image_util_transform_destroy() @@ -226,7 +226,7 @@ int image_util_transform_get_colorspace(transformation_h handle, image_util_colo * @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion * * @pre image_util_transform_create().\n - image_util_transform_set_resolution(). +* image_util_transform_set_resolution(). * * @see image_util_transform_create() * @see image_util_transform_destroy() @@ -249,7 +249,7 @@ int image_util_transform_get_resolution(transformation_h handle, unsigned int *w * @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion * * @pre image_util_transform_create().\n - image_util_transform_set_rotation(). +* image_util_transform_set_rotation(). * * @see image_util_transform_create() * @see image_util_transform_destroy() @@ -275,7 +275,7 @@ int image_util_transform_get_rotation(transformation_h handle, image_util_rotati * @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion * * @pre image_util_transform_create().\n - image_util_transform_set_crop_area(). +* image_util_transform_set_crop_area(). * * @see image_util_transform_create() * @see image_util_transform_destroy() @@ -729,6 +729,27 @@ int image_util_encode_jpeg(const unsigned char *buffer, int width, int height, i */ int image_util_encode_jpeg_to_memory(const unsigned char *image_buffer, int width, int height, image_util_colorspace_e colorspace, int quality, unsigned char **jpeg_buffer, unsigned int *jpeg_size); +/** +* @brief Extracts representative color from an image buffer +* @since_tizen 3.0 +* @remarks @a image_buffer should be RGB888 colorspace. +* +* @param[in] image_buffer The original image buffer +* @param[in] width The image width +* @param[in] height The image height +* @param[out] rgb_r The red color in RGB color space +* @param[out] rgb_g The green color in RGB color space +* @param[out] rgb_b The blue color in RGB color space +* +* @return 0 on success, +* otherwise a negative error value +* +* @retval #IMAGE_UTIL_ERROR_NONE Successful +* @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation +* +*/ +int image_util_extract_color_from_memory(const unsigned char *image_buffer, int width, int height, unsigned char *rgb_r, unsigned char *rgb_g, unsigned char *rgb_b); /** diff --git a/packaging/capi-media-image-util.spec b/packaging/capi-media-image-util.spec index ca1b72b..78a98c9 100755 --- a/packaging/capi-media-image-util.spec +++ b/packaging/capi-media-image-util.spec @@ -1,6 +1,6 @@ Name: capi-media-image-util Summary: A Image Utility library in Tizen Native API -Version: 0.1.5 +Version: 0.1.6 Release: 0 Group: Multimedia/API License: Apache-2.0 @@ -9,6 +9,7 @@ Source1001: capi-media-image-util.manifest BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(mmutil-jpeg) BuildRequires: pkgconfig(mmutil-imgp) +BuildRequires: pkgconfig(mmutil-imgcv) BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(capi-media-tool) BuildRequires: cmake @@ -24,6 +25,7 @@ Requires: pkgconfig(dlog) Requires: pkgconfig(mm-common) Requires: pkgconfig(mmutil-jpeg) Requires: pkgconfig(mmutil-imgp) +Requires: pkgconfig(mmutil-imgcv) Requires: pkgconfig(capi-base-common) %description devel diff --git a/src/image_util.c b/src/image_util.c index 9c6d5d6..74ddf4d 100755 --- a/src/image_util.c +++ b/src/image_util.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -78,30 +79,30 @@ static int _convert_image_util_error_code(const char *func, int code) int ret = IMAGE_UTIL_ERROR_INVALID_OPERATION; char *errorstr = NULL; switch (code) { - case MM_UTIL_ERROR_NONE: - ret = IMAGE_UTIL_ERROR_NONE; - errorstr = strdup("ERROR_NONE"); - break; - case MM_UTIL_ERROR_NO_SUCH_FILE: - ret = IMAGE_UTIL_ERROR_NO_SUCH_FILE; - errorstr = strdup("NO_SUCH_FILE"); - break; - case MM_UTIL_ERROR_INVALID_PARAMETER: - ret = IMAGE_UTIL_ERROR_INVALID_PARAMETER; - errorstr = strdup("INVALID_PARAMETER"); - break; - case MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT: - ret = IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT; - errorstr = strdup("NOT_SUPPORTED_FORMAT"); - break; - case MM_UTIL_ERROR_OUT_OF_MEMORY: - ret = IMAGE_UTIL_ERROR_OUT_OF_MEMORY; - errorstr = strdup("OUT_OF_MEMORY"); - break; - case MM_UTIL_ERROR_INVALID_OPERATION: - default: - ret = IMAGE_UTIL_ERROR_INVALID_OPERATION; - errorstr = strdup("INVALID_OPERATION"); + case MM_UTIL_ERROR_NONE: + ret = IMAGE_UTIL_ERROR_NONE; + errorstr = strdup("ERROR_NONE"); + break; + case MM_UTIL_ERROR_NO_SUCH_FILE: + ret = IMAGE_UTIL_ERROR_NO_SUCH_FILE; + errorstr = strdup("NO_SUCH_FILE"); + break; + case MM_UTIL_ERROR_INVALID_PARAMETER: + ret = IMAGE_UTIL_ERROR_INVALID_PARAMETER; + errorstr = strdup("INVALID_PARAMETER"); + break; + case MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT: + ret = IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT; + errorstr = strdup("NOT_SUPPORTED_FORMAT"); + break; + case MM_UTIL_ERROR_OUT_OF_MEMORY: + ret = IMAGE_UTIL_ERROR_OUT_OF_MEMORY; + errorstr = strdup("OUT_OF_MEMORY"); + break; + case MM_UTIL_ERROR_INVALID_OPERATION: + default: + ret = IMAGE_UTIL_ERROR_INVALID_OPERATION; + errorstr = strdup("INVALID_OPERATION"); } @@ -113,23 +114,23 @@ static int _convert_image_util_error_code(const char *func, int code) static image_util_error_e _image_util_error_convert(int error) { switch (error) { - case MM_UTIL_ERROR_NONE: - image_util_debug("Error None"); - return IMAGE_UTIL_ERROR_NONE; - case MM_UTIL_ERROR_INVALID_PARAMETER: - image_util_error("INVALID_PARAMETER(0x%08x)", IMAGE_UTIL_ERROR_INVALID_PARAMETER); - return IMAGE_UTIL_ERROR_INVALID_PARAMETER; - case MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT: - image_util_error("NOT_SUPPORTED_FORMAT(0x%08x)", IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT); - return IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT; - case MM_UTIL_ERROR_OUT_OF_MEMORY: - image_util_error("OUT_OF_MEMORY(0x%08x)", IMAGE_UTIL_ERROR_OUT_OF_MEMORY); - return IMAGE_UTIL_ERROR_OUT_OF_MEMORY; - break; - case MM_UTIL_ERROR_INVALID_OPERATION: - default: - image_util_error("INVALID_OPERATION(0x%08x)", error); - return IMAGE_UTIL_ERROR_INVALID_OPERATION; + case MM_UTIL_ERROR_NONE: + image_util_debug("Error None"); + return IMAGE_UTIL_ERROR_NONE; + case MM_UTIL_ERROR_INVALID_PARAMETER: + image_util_error("INVALID_PARAMETER(0x%08x)", IMAGE_UTIL_ERROR_INVALID_PARAMETER); + return IMAGE_UTIL_ERROR_INVALID_PARAMETER; + case MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT: + image_util_error("NOT_SUPPORTED_FORMAT(0x%08x)", IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT); + return IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT; + case MM_UTIL_ERROR_OUT_OF_MEMORY: + image_util_error("OUT_OF_MEMORY(0x%08x)", IMAGE_UTIL_ERROR_OUT_OF_MEMORY); + return IMAGE_UTIL_ERROR_OUT_OF_MEMORY; + break; + case MM_UTIL_ERROR_INVALID_OPERATION: + default: + image_util_error("INVALID_OPERATION(0x%08x)", error); + return IMAGE_UTIL_ERROR_INVALID_OPERATION; } } @@ -734,3 +735,19 @@ int image_util_encode_jpeg_to_memory(const unsigned char *image_buffer, int widt return _convert_image_util_error_code(__func__, err); } + +int image_util_extract_color_from_memory(const unsigned char *image_buffer, int width, int height, unsigned char *rgb_r, unsigned char *rgb_g, unsigned char *rgb_b) +{ + int ret = MM_UTIL_ERROR_NONE; + + image_util_retvm_if((image_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "image_buffer is null"); + + unsigned char r_color, g_color, b_color; + ret = mm_util_cv_extract_representative_color((void *)image_buffer, width, height, &r_color, & g_color, &b_color); + + *rgb_r = r_color; + *rgb_g = g_color; + *rgb_b = b_color; + + return _convert_image_util_error_code(__func__, ret); +} diff --git a/test/image_util_test.c b/test/image_util_test.c index 70a1922..b231850 100755 --- a/test/image_util_test.c +++ b/test/image_util_test.c @@ -80,46 +80,46 @@ _image_util_mapping_imgp_format_to_mime(image_util_colorspace_e colorspace) media_format_mimetype_e mimetype = -1; switch (colorspace) { - case IMAGE_UTIL_COLORSPACE_NV12: - mimetype = MEDIA_FORMAT_NV12; - break; - case IMAGE_UTIL_COLORSPACE_NV16: - mimetype = MEDIA_FORMAT_NV16; - break; - case IMAGE_UTIL_COLORSPACE_YUYV: - mimetype = MEDIA_FORMAT_YUYV; - break; - case IMAGE_UTIL_COLORSPACE_UYVY: - mimetype = MEDIA_FORMAT_UYVY; - break; - case IMAGE_UTIL_COLORSPACE_YUV422: - mimetype = MEDIA_FORMAT_422P; - break; - case IMAGE_UTIL_COLORSPACE_I420: - mimetype = MEDIA_FORMAT_I420; - break; - case IMAGE_UTIL_COLORSPACE_NV21: - mimetype = MEDIA_FORMAT_YV12; - break; - case IMAGE_UTIL_COLORSPACE_RGB565: - mimetype = MEDIA_FORMAT_RGB565; - break; - case IMAGE_UTIL_COLORSPACE_RGB888: - mimetype = MEDIA_FORMAT_RGB888; - break; - case IMAGE_UTIL_COLORSPACE_RGBA8888: - mimetype = MEDIA_FORMAT_RGBA; - break; - case IMAGE_UTIL_COLORSPACE_ARGB8888: - mimetype = MEDIA_FORMAT_ARGB; - break; - case IMAGE_UTIL_COLORSPACE_BGRA8888: - case IMAGE_UTIL_COLORSPACE_BGRX8888: - case IMAGE_UTIL_COLORSPACE_NV61: - default: - mimetype = -1; - g_printf("Not Supported Format"); - break; + case IMAGE_UTIL_COLORSPACE_NV12: + mimetype = MEDIA_FORMAT_NV12; + break; + case IMAGE_UTIL_COLORSPACE_NV16: + mimetype = MEDIA_FORMAT_NV16; + break; + case IMAGE_UTIL_COLORSPACE_YUYV: + mimetype = MEDIA_FORMAT_YUYV; + break; + case IMAGE_UTIL_COLORSPACE_UYVY: + mimetype = MEDIA_FORMAT_UYVY; + break; + case IMAGE_UTIL_COLORSPACE_YUV422: + mimetype = MEDIA_FORMAT_422P; + break; + case IMAGE_UTIL_COLORSPACE_I420: + mimetype = MEDIA_FORMAT_I420; + break; + case IMAGE_UTIL_COLORSPACE_NV21: + mimetype = MEDIA_FORMAT_YV12; + break; + case IMAGE_UTIL_COLORSPACE_RGB565: + mimetype = MEDIA_FORMAT_RGB565; + break; + case IMAGE_UTIL_COLORSPACE_RGB888: + mimetype = MEDIA_FORMAT_RGB888; + break; + case IMAGE_UTIL_COLORSPACE_RGBA8888: + mimetype = MEDIA_FORMAT_RGBA; + break; + case IMAGE_UTIL_COLORSPACE_ARGB8888: + mimetype = MEDIA_FORMAT_ARGB; + break; + case IMAGE_UTIL_COLORSPACE_BGRA8888: + case IMAGE_UTIL_COLORSPACE_BGRX8888: + case IMAGE_UTIL_COLORSPACE_NV61: + default: + mimetype = -1; + g_printf("Not Supported Format"); + break; } g_printf("imgp fmt: %d mimetype fmt: %d", colorspace, mimetype); @@ -281,18 +281,16 @@ static void _create() int ret = 0; if (g_handle != NULL) { ret = image_util_transform_destroy(g_handle); - if (ret != IMAGE_UTIL_ERROR_NONE) { + if (ret != IMAGE_UTIL_ERROR_NONE) g_printf("[%d]Error image_util_transform_destroy [%d]\n", __LINE__, ret); - } else { + else g_printf("[%d]Success image_util_transform_destroy [%d]\n", __LINE__, ret); - } } ret = image_util_transform_create(&g_handle); - if (ret != IMAGE_UTIL_ERROR_NONE) { + if (ret != IMAGE_UTIL_ERROR_NONE) g_printf("[%d]Error image_util_transform_create [%d]\n", __LINE__, ret); - } else { + else g_printf("[%d]Success image_util_transform_create [%d]\n", __LINE__, ret); - } } static void _set_image() @@ -303,11 +301,10 @@ static void _set_image() g_printf("[%d]Success source packet is destroyed \n", __LINE__); } ret = create_media_packet(); - if (ret == MM_ERROR_NONE) { + if (ret == MM_ERROR_NONE) g_printf("Success - Create_media_packet\n"); - } else { + else g_printf("Error - Create_media_packet\n"); - } } static void _destroy() @@ -316,11 +313,10 @@ static void _destroy() if (g_handle) { ret = image_util_transform_destroy(g_handle); - if (ret != IMAGE_UTIL_ERROR_NONE) { + if (ret != IMAGE_UTIL_ERROR_NONE) g_printf("[%d]Error image_util_transform_destroy [%d]\n", __LINE__, ret); - } else { + else g_printf("[%d]Success image_util_transform_destroy [%d]\n", __LINE__, ret); - } } else { g_printf("[%d]Error handle was already destroyed \n", __LINE__); } @@ -352,8 +348,6 @@ static void _transform(const char *cmd) if (!strcmp("resize", cmd)) { width = g_width/2; height = g_height/2; -// width = g_width; -// height = g_height; ret = image_util_transform_set_resolution(g_handle, width, height); if (ret != IMAGE_UTIL_ERROR_NONE) { -- 2.34.1