Added image_util_extract_color_from_buffer() API 90/51290/2 accepted/tizen/mobile/20151111.044109 accepted/tizen/tv/20151111.044116 accepted/tizen/wearable/20151111.044127 submit/tizen/20151110.064449 submit/tizen/20151110.064526
authorTae-Young Chung <ty83.chung@samsung.com>
Fri, 6 Nov 2015 08:03:24 +0000 (17:03 +0900)
committerTae-Young Chung <ty83.chung@samsung.com>
Sat, 7 Nov 2015 01:49:09 +0000 (10:49 +0900)
Change-Id: Ic7d73dec684868f4201365e4f1274434841969fc
Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
CMakeLists.txt
include/image_util.h
packaging/capi-media-image-util.spec
src/image_util.c
test/image_util_test.c

index a0a89368536367ec03d1dd4b9ec2d4357d53f6fe..3a85ffb636c1766ff62d66eb8b0762346e10532d 100755 (executable)
@@ -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}")
index 92f827c64b66fd3d87abcd1cd1ecf1019a7d3752..21921ee987e8f47cdf712109cb90363fae9e9be8 100755 (executable)
@@ -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);
 
 
 /**
index ca1b72b1f5f5f89ae15cd9ff58b8c931f16a8e52..78a98c9de975cc0ed84281d48cec0ebc502ab007 100755 (executable)
@@ -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
index 9c6d5d644d674615bff819e27c0b88ea521c3cb2..74ddf4d290ce9fa1f48468283156f1734c0f7584 100755 (executable)
@@ -18,6 +18,7 @@
 
 #include <mm_util_imgp.h>
 #include <mm_util_jpeg.h>
+#include <mm_util_imgcv.h>
 #include <image_util.h>
 #include <image_util_private.h>
 #include <stdio.h>
@@ -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);
+}
index 70a1922029e21e3a75b760d9d08096b8f8746911..b231850bcdd39c089f4521f40cde18b218b0f54f 100755 (executable)
@@ -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) {