Code Refactoring: apply unified color format 55/169655/4
authorJiyong Min <jiyong.min@samsung.com>
Thu, 8 Feb 2018 06:42:38 +0000 (15:42 +0900)
committerJiyong Min <jiyong.min@samsung.com>
Thu, 8 Feb 2018 07:14:03 +0000 (16:14 +0900)
 - Add 'mmutil_common' library to use color interface from libmm-utility
 - Apply unified color format

Change-Id: I0115413d99935e646e06c7e583da3dc44dc84642

CMakeLists.txt
packaging/capi-media-image-util.spec
src/image_util.c
src/image_util_private.c

index 5804257..7c1d64f 100755 (executable)
@@ -10,7 +10,7 @@ SET(service "media")
 SET(submodule "image-util")
 
 # for package file
-SET(dependents "dlog mmutil-bmp mmutil-gif mmutil-png mmutil-jpeg mmutil-imgp capi-base-common capi-media-tool glib-2.0 gmodule-2.0")
+SET(dependents "dlog mmutil-bmp mmutil-common mmutil-gif mmutil-png mmutil-jpeg mmutil-imgp capi-base-common capi-media-tool glib-2.0 gmodule-2.0")
 SET(pc_dependents "dlog capi-base-common capi-media-tool")
 
 SET(fw_name "${project_prefix}-${service}-${submodule}")
index 069633a..2598bc8 100755 (executable)
@@ -7,6 +7,7 @@ License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
 Source1001:     capi-media-image-util.manifest
 BuildRequires:  pkgconfig(dlog)
+BuildRequires:  pkgconfig(mmutil-common)
 BuildRequires:  pkgconfig(mmutil-jpeg)
 BuildRequires:  pkgconfig(mmutil-imgp)
 BuildRequires:  pkgconfig(mmutil-png)
index b82fad5..80f4f8f 100755 (executable)
 #include <gmodule.h>
 #include <inttypes.h>
 #include <mm_util_imgp.h>
+#include <mm_util_common.h>
 
 #include <image_util.h>
 #include <image_util_private.h>
 
 typedef struct {
-       mm_util_img_format image_format;
+       mm_util_color_format_e image_format;
        media_format_mimetype_e mimetype;
        const char *mimetype_name;
 } image_format_mimetype_pair_s;
 
-static const image_format_mimetype_pair_s image_format_mimetype_table[MM_UTIL_IMG_FMT_NUM] = {
-       { MM_UTIL_IMG_FMT_YUV420,       MEDIA_FORMAT_YV12,              "MEDIA_FORMAT_YV12" },
-       { MM_UTIL_IMG_FMT_YUV422,       MEDIA_FORMAT_422P,              "MEDIA_FORMAT_422P" },
-       { MM_UTIL_IMG_FMT_I420,         MEDIA_FORMAT_I420,              "MEDIA_FORMAT_I420" },
-       { MM_UTIL_IMG_FMT_NV12,         -1,                                             "Not support" },
-       { MM_UTIL_IMG_FMT_UYVY,         MEDIA_FORMAT_UYVY,              "MEDIA_FORMAT_UYVY" },
-       { MM_UTIL_IMG_FMT_YUYV,         MEDIA_FORMAT_YUYV,              "MEDIA_FORMAT_YUYV" },
-       { MM_UTIL_IMG_FMT_RGB565,       MEDIA_FORMAT_RGB565,    "MEDIA_FORMAT_RGB565" },
-       { MM_UTIL_IMG_FMT_RGB888,       MEDIA_FORMAT_RGB888,    "MEDIA_FORMAT_RGB888" },
-       { MM_UTIL_IMG_FMT_ARGB8888,     MEDIA_FORMAT_ARGB,              "MEDIA_FORMAT_ARGB" },
-       { MM_UTIL_IMG_FMT_BGRA8888,     MEDIA_FORMAT_BGRA,              "MEDIA_FORMAT_BGRA" },
-       { MM_UTIL_IMG_FMT_RGBA8888,     MEDIA_FORMAT_RGBA,              "MEDIA_FORMAT_RGBA" },
-       { MM_UTIL_IMG_FMT_BGRX8888,     -1,                                             "Not support" },
-       { MM_UTIL_IMG_FMT_NV12_TILED,   MEDIA_FORMAT_NV12T,     "MEDIA_FORMAT_NV12T" },
-       { MM_UTIL_IMG_FMT_NV16,         MEDIA_FORMAT_NV16,              "MEDIA_FORMAT_NV16" },
-       { MM_UTIL_IMG_FMT_NV61,         -1,                                             "Not support" }
+static const image_format_mimetype_pair_s image_format_mimetype_table[MM_UTIL_COLOR_NUM] = {
+       { MM_UTIL_COLOR_YUV420, MEDIA_FORMAT_YV12,              "MEDIA_FORMAT_YV12" },
+       { MM_UTIL_COLOR_YUV422, MEDIA_FORMAT_422P,              "MEDIA_FORMAT_422P" },
+       { MM_UTIL_COLOR_I420,           MEDIA_FORMAT_I420,              "MEDIA_FORMAT_I420" },
+       { MM_UTIL_COLOR_NV12,           MEDIA_FORMAT_NV12,                                              "Not support" },
+       { MM_UTIL_COLOR_UYVY,           MEDIA_FORMAT_UYVY,              "MEDIA_FORMAT_UYVY" },
+       { MM_UTIL_COLOR_YUYV,           MEDIA_FORMAT_YUYV,              "MEDIA_FORMAT_YUYV" },
+       { MM_UTIL_COLOR_RGB16,  MEDIA_FORMAT_RGB565,    "MEDIA_FORMAT_RGB565" },
+       { MM_UTIL_COLOR_RGB24,  MEDIA_FORMAT_RGB888,    "MEDIA_FORMAT_RGB888" },
+       { MM_UTIL_COLOR_ARGB,   MEDIA_FORMAT_ARGB,              "MEDIA_FORMAT_ARGB" },
+       { MM_UTIL_COLOR_BGRA,   MEDIA_FORMAT_BGRA,              "MEDIA_FORMAT_BGRA" },
+       { MM_UTIL_COLOR_RGBA,   MEDIA_FORMAT_RGBA,              "MEDIA_FORMAT_RGBA" },
+       { MM_UTIL_COLOR_BGRX,   -1,                                             "Not support" },
+       { MM_UTIL_COLOR_NV12_TILED,     MEDIA_FORMAT_NV12T,     "MEDIA_FORMAT_NV12T" },
+       { MM_UTIL_COLOR_NV16,           MEDIA_FORMAT_NV16,              "MEDIA_FORMAT_NV16" },
+       { MM_UTIL_COLOR_NV61,           -1,                                             "Not support" }
 };
 
-static media_format_mimetype_e __image_format_to_mimetype(mm_util_img_format format)
+static media_format_mimetype_e __image_format_to_mimetype(mm_util_color_format_e format)
 {
        unsigned int i = 0;
        media_format_mimetype_e mimetype = -1;
 
-       for (i = 0; i < MM_UTIL_IMG_FMT_NUM; i++) {
+       for (i = 0; i < MM_UTIL_COLOR_NUM; i++) {
                if (image_format_mimetype_table[i].image_format == format) {
                        mimetype = image_format_mimetype_table[i].mimetype;
                        break;
@@ -62,12 +63,12 @@ static media_format_mimetype_e __image_format_to_mimetype(mm_util_img_format for
        return mimetype;
 }
 
-static mm_util_img_format __mimetype_to_image_format(media_format_mimetype_e mimetype)
+static mm_util_color_format_e __mimetype_to_image_format(media_format_mimetype_e mimetype)
 {
        unsigned int i = 0;
-       mm_util_img_format format = -1;
+       mm_util_color_format_e format = -1;
 
-       for (i = 0; i < MM_UTIL_IMG_FMT_NUM; i++) {
+       for (i = 0; i < MM_UTIL_COLOR_NUM; i++) {
                if (image_format_mimetype_table[i].mimetype == mimetype) {
                        format = image_format_mimetype_table[i].image_format;
                        break;
@@ -159,19 +160,10 @@ static int _image_util_packet_to_image(media_packet_h packet, mm_util_color_imag
                image_util_error("Invalid source packet");
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
        }
-       image_util_debug("_image_util_packet_to_image succeed");
 
-       err = mm_util_create_color_image(color_image);
+       err = mm_util_create_color_image(color_image, (unsigned long)width, (unsigned long)height, __mimetype_to_image_format(mimetype), ptr, (size_t)size);
        if (err != MM_UTIL_ERROR_NONE) {
-               image_util_error("Error - Run transform (%d)", err);
-               return _image_error_capi(ERR_TYPE_TRANSFORM, err);
-       }
-       image_util_debug("_image_util_packet_to_image succeed");
-
-       err = mm_util_set_color_image(*color_image, width, height, __mimetype_to_image_format(mimetype), ptr, size);
-       if (err != MM_UTIL_ERROR_NONE) {
-               image_util_error("mm_util_push_request_image failed (%d)", err);
-               mm_util_destroy_color_image(*color_image);
+               image_util_error("mm_util_create_color_image failed (%d)", err);
                return _image_error_capi(ERR_TYPE_TRANSFORM, err);
        }
 
@@ -183,8 +175,8 @@ static int _image_util_packet_to_image(media_packet_h packet, mm_util_color_imag
 static int _image_util_image_to_packet(mm_util_color_image_h image, media_packet_h *packet)
 {
        int err = IMAGE_UTIL_ERROR_NONE;
-       mm_util_img_format format = 0;
-       int width = 0, height = 0;
+       mm_util_color_format_e format = 0;
+       unsigned long width = 0, height = 0;
        void *buffer = NULL;
        size_t buffer_size = 0;
        media_format_h fmt = NULL;
@@ -198,7 +190,7 @@ static int _image_util_image_to_packet(mm_util_color_image_h image, media_packet
                return _image_error_capi(ERR_TYPE_TRANSFORM, err);
        }
 
-       err = __create_media_format(__image_format_to_mimetype(format), width, height, &fmt);
+       err = __create_media_format(__image_format_to_mimetype(format), (unsigned int)width, (unsigned int)height, &fmt);
        if (err != IMAGE_UTIL_ERROR_NONE) {
                image_util_error("mm_util_push_request_image failed (%d)", err);
                return err;
index 1ddb240..c929c1c 100755 (executable)
 #include <mm_util_bmp.h>
 
 static int _convert_colorspace_tbl[] = {
-       MM_UTIL_IMG_FMT_YUV420,         /* IMAGE_UTIL_COLORSPACE_YUV420 */
-       MM_UTIL_IMG_FMT_YUV422,         /* IMAGE_UTIL_COLORSPACE_YUV422 */
-       MM_UTIL_IMG_FMT_I420,           /* IMAGE_UTIL_COLORSPACE_I420 */
-       MM_UTIL_IMG_FMT_NV12,           /* IMAGE_UTIL_COLORSPACE_NV12 */
-       MM_UTIL_IMG_FMT_UYVY,           /* IMAGE_UTIL_COLORSPACE_UYVY */
-       MM_UTIL_IMG_FMT_YUYV,           /* IMAGE_UTIL_COLORSPACE_YUYV */
-       MM_UTIL_IMG_FMT_RGB565,         /* IMAGE_UTIL_COLORSPACE_RGB565 */
-       MM_UTIL_IMG_FMT_RGB888,         /* IMAGE_UTIL_COLORSPACE_RGB888 */
-       MM_UTIL_IMG_FMT_ARGB8888,       /* IMAGE_UTIL_COLORSPACE_ARGB8888 */
-       MM_UTIL_IMG_FMT_BGRA8888,       /* IMAGE_UTIL_COLORSPACE_BGRA8888 */
-       MM_UTIL_IMG_FMT_RGBA8888,       /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
-       MM_UTIL_IMG_FMT_BGRX8888,       /* IMAGE_UTIL_COLORSPACE_BGRX8888 */
-       MM_UTIL_JPEG_FMT_NV21,          /* IMAGE_UTIL_COLORSPACE_NV12 */
-       MM_UTIL_JPEG_FMT_NV16,          /* IMAGE_UTIL_COLORSPACE_NV16 */
-       MM_UTIL_JPEG_FMT_NV61,          /* IMAGE_UTIL_COLORSPACE_NV61 */
+       MM_UTIL_COLOR_YUV420,           /* IMAGE_UTIL_COLORSPACE_YUV420 */
+       MM_UTIL_COLOR_YUV422,           /* IMAGE_UTIL_COLORSPACE_YUV422 */
+       MM_UTIL_COLOR_I420,                     /* IMAGE_UTIL_COLORSPACE_I420 */
+       MM_UTIL_COLOR_NV12,                     /* IMAGE_UTIL_COLORSPACE_NV12 */
+       MM_UTIL_COLOR_UYVY,                     /* IMAGE_UTIL_COLORSPACE_UYVY */
+       MM_UTIL_COLOR_YUYV,                     /* IMAGE_UTIL_COLORSPACE_YUYV */
+       MM_UTIL_COLOR_RGB16,            /* IMAGE_UTIL_COLORSPACE_RGB565 */
+       MM_UTIL_COLOR_RGB24,            /* IMAGE_UTIL_COLORSPACE_RGB888 */
+       MM_UTIL_COLOR_ARGB,                     /* IMAGE_UTIL_COLORSPACE_ARGB8888 */
+       MM_UTIL_COLOR_BGRA,                     /* IMAGE_UTIL_COLORSPACE_BGRA8888 */
+       MM_UTIL_COLOR_RGBA,                     /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
+       MM_UTIL_COLOR_BGRX,                     /* IMAGE_UTIL_COLORSPACE_BGRX8888 */
+       MM_UTIL_COLOR_NV21,                     /* IMAGE_UTIL_COLORSPACE_NV12 */
+       MM_UTIL_COLOR_NV16,                     /* IMAGE_UTIL_COLORSPACE_NV16 */
+       MM_UTIL_COLOR_NV61,                     /* IMAGE_UTIL_COLORSPACE_NV61 */
 };
 
 static int _convert_jpeg_colorspace_tbl[] = {
-       MM_UTIL_JPEG_FMT_YUV420,        /* IMAGE_UTIL_COLORSPACE_YUV420 */
+       MM_UTIL_COLOR_YUV420,           /* IMAGE_UTIL_COLORSPACE_YUV420 */
        _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_YUV422 */
-       MM_UTIL_JPEG_FMT_YUV420,        /* IMAGE_UTIL_COLORSPACE_I420 */
-       MM_UTIL_JPEG_FMT_NV12,          /* IMAGE_UTIL_COLORSPACE_NV12 */
+       MM_UTIL_COLOR_YUV420,           /* IMAGE_UTIL_COLORSPACE_I420 */
+       MM_UTIL_COLOR_NV12,                     /* IMAGE_UTIL_COLORSPACE_NV12 */
        _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_UYVY */
        _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_YUYV */
        _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_RGB565 */
-       MM_UTIL_JPEG_FMT_RGB888,        /* IMAGE_UTIL_COLORSPACE_RGB888 */
-       MM_UTIL_JPEG_FMT_ARGB8888,      /* IMAGE_UTIL_COLORSPACE_ARGB8888 */
-       MM_UTIL_JPEG_FMT_BGRA8888,      /* IMAGE_UTIL_COLORSPACE_BGRA8888 */
-       MM_UTIL_JPEG_FMT_RGBA8888,      /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
+       MM_UTIL_COLOR_RGB24,            /* IMAGE_UTIL_COLORSPACE_RGB888 */
+       MM_UTIL_COLOR_ARGB,                     /* IMAGE_UTIL_COLORSPACE_ARGB8888 */
+       MM_UTIL_COLOR_BGRA,                     /* IMAGE_UTIL_COLORSPACE_BGRA8888 */
+       MM_UTIL_COLOR_RGBA,                     /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
        _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_BGRX8888 */
        _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV21 */
        _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV16 */
@@ -69,7 +69,7 @@ static int _convert_png_colorspace_tbl[] = {
        _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_RGB888 */
        _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_ARGB8888 */
        _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_BGRA8888 */
-       MM_UTIL_PNG_COLOR_TYPE_RGB_ALPHA,       /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
+       MM_UTIL_COLOR_RGBA,                     /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
        _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_BGRX8888 */
        _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV21 */
        _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV16 */
@@ -87,7 +87,7 @@ static int _convert_gif_colorspace_tbl[] = {
        _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_RGB888 */
        _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_ARGB8888 */
        _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_BGRA8888 */
-       MM_UTIL_GIF_FMT_RGBA8888,               /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
+       MM_UTIL_COLOR_RGBA,                     /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
        _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_BGRX8888 */
        _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV21 */
        _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV16 */
@@ -105,7 +105,7 @@ static int _convert_bmp_colorspace_tbl[] = {
        _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_RGB888 */
        _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_ARGB8888 */
        _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_BGRA8888 */
-       MM_UTIL_BMP_FMT_RGBA8888,       /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
+       MM_UTIL_COLOR_RGBA,                     /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
        _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_BGRX8888 */
        _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV21 */
        _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV16 */