Improve __mm_util_constitute_image() 90/238190/6
authorhj kim <backto.kim@samsung.com>
Thu, 9 Jul 2020 08:15:57 +0000 (17:15 +0900)
committerhj kim <backto.kim@samsung.com>
Fri, 10 Jul 2020 05:45:18 +0000 (05:45 +0000)
Modify to get map info in this function. because this function can get map info from input handle

Change-Id: If0885ee02d5c1a21f6db29fdf609e35d7fdc049b

magick/mm_util_magick.c

index b07d754..455e1b1 100644 (file)
@@ -116,16 +116,20 @@ static int __mm_util_get_map(mm_util_color_format_e format, char **map)
        return MM_UTIL_ERROR_NONE;
 }
 
-static Image * __mm_util_constitute_image(mm_util_image_h handle, const char *map)
+static Image * __mm_util_constitute_image(mm_util_image_h handle)
 {
+       int ret = MM_UTIL_ERROR_NONE;
        mm_image_info_s *_handle = (mm_image_info_s*)handle;
+       char *map = NULL;
        Image *_image = NULL;
        ExceptionInfo exception;
 
        mm_util_fenter();
 
-       mm_util_retvm_if(handle == NULL, NULL, "invalid handle");
-       mm_util_retvm_if(!MMUTIL_STRING_VALID(map), NULL, "invalid map");
+       mm_util_retvm_if(!handle, NULL, "invalid handle");
+
+       ret = __mm_util_get_map(_handle->color, &map);
+       mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, NULL, "fail to get map");
 
        GetExceptionInfo(&exception);
 
@@ -138,6 +142,7 @@ static Image * __mm_util_constitute_image(mm_util_image_h handle, const char *ma
        }
 
        DestroyExceptionInfo(&exception);
+       g_free(map);
 
        mm_util_fleave();
 
@@ -516,23 +521,19 @@ int mm_util_rotate_B_B(mm_util_image_h src_handle, mm_util_rotate_type_e rotatio
 {
        int ret = MM_UTIL_ERROR_NONE;
        mm_image_info_s *_src_handle = (mm_image_info_s*)src_handle;
-       char *map = NULL;
        Image *_image = NULL;
        Image *_processed_image = NULL;
        ExceptionInfo exception;
 
-       mm_util_retvm_if(src_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle");
+       mm_util_retvm_if(!src_handle, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_handle");
        mm_util_retvm_if(!__mm_util_check_rotation(rotation), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid rotation [%d]", rotation);
-       mm_util_retvm_if(dst_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_handle");
+       mm_util_retvm_if(!dst_handle, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_handle");
 
        mm_util_debug("rotation [%d]", rotation);
 
-       ret = __mm_util_get_map(_src_handle->color, &map);
-       mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "fail to get map");
-
        __mm_util_init(&exception);
 
-       _image = __mm_util_constitute_image(src_handle, map);
+       _image = __mm_util_constitute_image(src_handle);
        if (_image == NULL) {
                mm_util_error("Error: __mm_util_constitute_image failed.");
                ret = MM_UTIL_ERROR_INVALID_OPERATION;
@@ -552,8 +553,6 @@ ERROR:
 
        __mm_util_finalize(_image, _processed_image, &exception);
 
-       g_free(map);
-
        mm_util_fleave();
 
        return ret;
@@ -562,24 +561,19 @@ ERROR:
 int mm_util_rotate_B_P(mm_util_image_h src_handle, mm_util_rotate_type_e rotation, const char *dst_path)
 {
        int ret = MM_UTIL_ERROR_NONE;
-       mm_image_info_s *_src_handle = (mm_image_info_s*)src_handle;
-       char *map = NULL;
        Image *_image = NULL;
        Image *_processed_image = NULL;
        ExceptionInfo exception;
 
-       mm_util_retvm_if(src_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle");
+       mm_util_retvm_if(!src_handle, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_handle");
        mm_util_retvm_if(!__mm_util_check_rotation(rotation), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid rotation [%d]", rotation);
        mm_util_retvm_if(!MMUTIL_STRING_VALID(dst_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_path");
 
        mm_util_sec_debug("rotation [%d] dst_path [%s]", rotation, dst_path);
 
-       ret = __mm_util_get_map(_src_handle->color, &map);
-       mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "fail to get map");
-
        __mm_util_init(&exception);
 
-       _image = __mm_util_constitute_image(src_handle, map);
+       _image = __mm_util_constitute_image(src_handle);
        if (_image == NULL) {
                mm_util_error("Error: __mm_util_constitute_image failed.");
                ret = MM_UTIL_ERROR_INVALID_OPERATION;
@@ -599,8 +593,6 @@ ERROR:
 
        __mm_util_finalize(_image, _processed_image, &exception);
 
-       g_free(map);
-
        mm_util_fleave();
 
        return ret;
@@ -615,7 +607,7 @@ int mm_util_rotate_P_B(const char *src_path, mm_util_rotate_type_e rotation, mm_
 
        mm_util_retvm_if(!MMUTIL_STRING_VALID(src_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_path");
        mm_util_retvm_if(!__mm_util_check_rotation(rotation), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid rotation [%d]", rotation);
-       mm_util_retvm_if(dst_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_handle");
+       mm_util_retvm_if(!dst_handle, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_handle");
 
        mm_util_sec_debug("src_path [%s] rotation [%d] req_format [%d]", src_path, rotation, req_format);
 
@@ -691,23 +683,19 @@ int mm_util_resize_B_B(mm_util_image_h src_handle, unsigned int req_width, unsig
 {
        int ret = MM_UTIL_ERROR_NONE;
        mm_image_info_s *_src_handle = (mm_image_info_s*)src_handle;
-       char *map = NULL;
        Image *_image = NULL;
        Image *_processed_image = NULL;
        ExceptionInfo exception;
 
-       mm_util_retvm_if(src_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle");
+       mm_util_retvm_if(!src_handle, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_handle");
        mm_util_retvm_if((req_width == 0) || (req_height == 0), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid size W[%d] H[%d]", req_width, req_height);
-       mm_util_retvm_if(dst_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_handle");
+       mm_util_retvm_if(!dst_handle, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_handle");
 
        mm_util_debug("req_width [%u] req_height [%u]", req_width, req_height);
 
-       ret = __mm_util_get_map(_src_handle->color, &map);
-       mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "fail to get map");
-
        __mm_util_init(&exception);
 
-       _image = __mm_util_constitute_image(src_handle, map);
+       _image = __mm_util_constitute_image(src_handle);
        if (_image == NULL) {
                mm_util_error("Error: __mm_util_constitute_image failed.");
                ret = MM_UTIL_ERROR_INVALID_OPERATION;
@@ -733,8 +721,6 @@ ERROR:
 
        __mm_util_finalize(_image, _processed_image, &exception);
 
-       g_free(map);
-
        mm_util_fleave();
 
        return ret;
@@ -743,24 +729,19 @@ ERROR:
 int mm_util_resize_B_P(mm_util_image_h src_handle, unsigned int req_width, unsigned int req_height, const char *dst_path)
 {
        int ret = MM_UTIL_ERROR_NONE;
-       mm_image_info_s *_src_handle = (mm_image_info_s*)src_handle;
-       char *map = NULL;
        Image *_image = NULL;
        Image *_processed_image = NULL;
        ExceptionInfo exception;
 
-       mm_util_retvm_if(src_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle");
+       mm_util_retvm_if(!src_handle, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_handle");
        mm_util_retvm_if((req_width == 0) || (req_height == 0), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid size W[%d] H[%d]", req_width, req_height);
        mm_util_retvm_if(!MMUTIL_STRING_VALID(dst_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_path");
 
        mm_util_sec_debug("req_width [%u] req_height [%u] dst_path [%s]", req_width, req_height, dst_path);
 
-       ret = __mm_util_get_map(_src_handle->color, &map);
-       mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "fail to get map");
-
        __mm_util_init(&exception);
 
-       _image = __mm_util_constitute_image(src_handle, map);
+       _image = __mm_util_constitute_image(src_handle);
        if (_image == NULL) {
                mm_util_error("Error: __mm_util_constitute_image failed.");
                ret = MM_UTIL_ERROR_INVALID_OPERATION;
@@ -786,8 +767,6 @@ ERROR:
 
        __mm_util_finalize(_image, _processed_image, &exception);
 
-       g_free(map);
-
        mm_util_fleave();
 
        return ret;
@@ -802,7 +781,7 @@ int mm_util_resize_P_B(const char *src_path, unsigned int req_width, unsigned in
 
        mm_util_retvm_if(!MMUTIL_STRING_VALID(src_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_path");
        mm_util_retvm_if((req_width == 0) || (req_height == 0), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid size W[%d] H[%d]", req_width, req_height);
-       mm_util_retvm_if(dst_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_handle");
+       mm_util_retvm_if(!dst_handle, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_handle");
 
        mm_util_sec_debug("src_path [%s] req_width [%u] req_height [%u]", src_path, req_width, req_height);
 
@@ -889,29 +868,23 @@ int mm_util_convert_B_B(mm_util_image_h src_handle, mm_util_color_format_e req_f
 {
        int ret = MM_UTIL_ERROR_NONE;
        mm_image_info_s *_src_handle = (mm_image_info_s*)src_handle;
-       char *map = NULL;
        Image *_image = NULL;
        ExceptionInfo exception;
 
-       mm_util_retvm_if(src_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle");
-       mm_util_retvm_if(dst_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_handle");
+       mm_util_retvm_if(!src_handle, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_handle");
+       mm_util_retvm_if(!dst_handle, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_handle");
 
        mm_util_debug("input format [%d] req_format [%d]", _src_handle->color, req_format);
 
-       ret = __mm_util_get_map(_src_handle->color, &map);
-       mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "fail to get map");
-
        __mm_util_init(&exception);
 
-       _image = __mm_util_constitute_image(src_handle, map);
+       _image = __mm_util_constitute_image(src_handle);
        if (_image == NULL) {
                mm_util_error("Error: __mm_util_constitute_image failed.");
                ret = MM_UTIL_ERROR_INVALID_OPERATION;
                goto ERROR;
        }
 
-       g_free(map);
-
        ret = __mm_util_dispatch_image(_image, req_format, dst_handle);
 
 ERROR:
@@ -988,7 +961,6 @@ int mm_util_encode_image_to_file(mm_util_image_h decoded_image, const char *path
 {
        int ret = MM_UTIL_ERROR_NONE;
        char *extension = NULL;
-       char *map = NULL;
        Image *_image = NULL;
        mm_util_image_h converted_image = NULL, source = NULL;
 
@@ -1021,15 +993,9 @@ int mm_util_encode_image_to_file(mm_util_image_h decoded_image, const char *path
 
        source = (converted_image) ? converted_image : decoded_image;
 
-       ret = __mm_util_get_map(((mm_image_info_s *)source)->color, &map);
-       if (ret != MM_UTIL_ERROR_NONE) {
-               mm_util_error("fail to get map");
-               goto ERROR;
-       }
-
        __mm_util_init(NULL);
 
-       _image = __mm_util_constitute_image(source, map);
+       _image = __mm_util_constitute_image(source);
        if (_image == NULL) {
                mm_util_error("Error: __mm_util_constitute_image failed.");
                ret = MM_UTIL_ERROR_INVALID_OPERATION;
@@ -1042,8 +1008,6 @@ ERROR:
 
        __mm_util_finalize(_image, NULL, NULL);
 
-       g_free(map);
-
        mm_image_destroy_image(converted_image);
 
        mm_util_fleave();