Modify parameter in imgage processing APIs to mm_util_image_h
[platform/core/multimedia/libmm-utility.git] / imgp / mm_util_imgp.c
old mode 100755 (executable)
new mode 100644 (file)
index af9f5e2..655960a
@@ -200,8 +200,8 @@ static int __mm_util_get_crop_image_size(mm_util_color_format_e format, unsigned
 
        mm_util_fenter();
 
-       mm_util_retvm_if(imgsize == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid imgsize");
-       mm_util_retvm_if(__check_valid_picture_size(width, height) != MM_UTIL_ERROR_NONE, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid width and height");
+       mm_util_retvm_if(imgsize == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid imgsize");
+       mm_util_retvm_if(__check_valid_picture_size(width, height) != MM_UTIL_ERROR_NONE, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid width and height");
 
        *imgsize = 0;
 
@@ -279,7 +279,7 @@ static int __mm_set_imgp_info_s(imgp_info_s *_imgp_info_s, mm_util_color_format_
 {
        int ret = MM_UTIL_ERROR_NONE;
 
-       mm_util_retvm_if(_imgp_info_s == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid _imgp_info_s");
+       mm_util_retvm_if(_imgp_info_s == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid _imgp_info_s");
 
        _imgp_info_s->src_format = src_format;
        _imgp_info_s->src_width = src_width;
@@ -475,31 +475,25 @@ static bool __mm_util_check_format(mm_util_color_format_e color_format)
        return FALSE;
 }
 
-int mm_util_convert_colorspace(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_color_format_e src_format, mm_util_color_format_e dst_format, unsigned char **dst, unsigned int *result_buf_width, unsigned int *result_buf_height, size_t *result_buf_size)
+int mm_util_convert_colorspace(mm_util_image_h src, mm_util_color_format_e color, mm_util_image_h *dst)
 {
        int ret = MM_UTIL_ERROR_NONE;
        IMGPInfoFunc _mm_util_imgp_func = NULL;
        GModule *_module = NULL;
        unsigned char *output_buffer = NULL;
-       unsigned int res_w = 0;
-       unsigned int res_h = 0;
-       unsigned char *res_buffer = NULL;
-       size_t res_buffer_size = 0;
-
-       mm_util_retvm_if(src == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src");
-       mm_util_retvm_if(dst == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst");
-       mm_util_retvm_if((IS_VALID_COLOR(src_format) == FALSE), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_format [%d]", src_format);
-       mm_util_retvm_if((IS_VALID_COLOR(dst_format) == FALSE), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_format [%d]", dst_format);
-       mm_util_retvm_if((__mm_util_check_format(src_format) == FALSE), MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported src_format [%d]", src_format);
-       mm_util_retvm_if((__mm_util_check_format(dst_format) == FALSE), MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported dst_format [%d]", dst_format);
-       mm_util_retvm_if(dst == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst");
-       mm_util_retvm_if(result_buf_width == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_width");
-       mm_util_retvm_if(result_buf_height == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_height");
-       mm_util_retvm_if(result_buf_size == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_size");
-
-       mm_util_debug("src_width [%d] src_height [%d] src_format[%d] dst_format[%d]", src_width, src_height, src_format, dst_format);
-
-       _mm_util_imgp_func = __mm_util_initialize(IMGP_CSC, src_format, dst_format, &_module);
+       mm_image_info_s *_src = (mm_image_info_s *)src;
+       mm_util_image_h _convert_image = NULL;
+
+       mm_util_fenter();
+
+       mm_util_retvm_if(!IS_VALID_IMAGE(src), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid src");
+       mm_util_retvm_if(!__mm_util_check_format(color), MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "Not supported format [%d]", color);
+       mm_util_retvm_if(!dst, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid dst");
+
+       mm_util_debug("[Input] format[%d]", color);
+       mm_image_debug_image(src, "Input");
+
+       _mm_util_imgp_func = __mm_util_initialize(IMGP_CSC, _src->color, color, &_module);
        if (_mm_util_imgp_func == NULL) {
                mm_util_error("ERROR - __mm_util_initialize");
                return MM_UTIL_ERROR_INVALID_OPERATION;
@@ -512,79 +506,73 @@ int mm_util_convert_colorspace(const unsigned char *src, unsigned int src_width,
                goto ERROR;
        }
 
-       res_w = src_width;
-       res_h = src_height;
-
-       ret = __mm_set_imgp_info_s(_imgp_info_s, src_format, src_width, src_height, dst_format, src_width, src_height, MM_UTIL_ROTATE_0);
+       ret = __mm_set_imgp_info_s(_imgp_info_s, _src->color, _src->width, _src->height, color, _src->width, _src->height, MM_UTIL_ROTATE_0);
        if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("__mm_set_imgp_info_s failed");
                ret = MM_UTIL_ERROR_INVALID_OPERATION;
                goto ERROR;
        }
 
-       ret = _mm_util_imgp_func(_imgp_info_s, src, &output_buffer, IMGP_CSC);
+       ret = _mm_util_imgp_func(_imgp_info_s, _src->data, &output_buffer, IMGP_CSC);
        if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("image processing failed");
                goto ERROR;
        }
 
        if ((_imgp_info_s->dst_width != _imgp_info_s->output_stride || _imgp_info_s->dst_height != _imgp_info_s->output_elevation)) {
-               ret = mm_util_crop_image(output_buffer, _imgp_info_s->output_stride, _imgp_info_s->output_elevation, dst_format, 0, 0, _imgp_info_s->dst_width, _imgp_info_s->dst_height, &res_buffer, &res_w, &res_h, &res_buffer_size);
+               ret = mm_image_create_image(_imgp_info_s->output_stride, _imgp_info_s->output_elevation, color, output_buffer, _imgp_info_s->buffer_size, &_convert_image);
                if (ret != MM_UTIL_ERROR_NONE) {
-                       mm_util_error("mm_util_crop_image failed");
-                       MMUTIL_SAFE_FREE(output_buffer);
+                       mm_util_error("mm_image_create_image failed");
                        ret = MM_UTIL_ERROR_INVALID_OPERATION;
                        goto ERROR;
                }
 
-               MMUTIL_SAFE_FREE(output_buffer);
-               *dst = res_buffer;
-               *result_buf_size = res_buffer_size;
+               ret = mm_util_crop_image(_convert_image, 0, 0, _imgp_info_s->dst_width, _imgp_info_s->dst_height, dst);
+               mm_image_destroy_image(_convert_image);
+               if (ret != MM_UTIL_ERROR_NONE) {
+                       mm_util_error("mm_util_crop_image failed");
+                       ret = MM_UTIL_ERROR_INVALID_OPERATION;
+                       goto ERROR;
+               }
        } else {
-               *dst = output_buffer;
-               *result_buf_size = _imgp_info_s->buffer_size;
+               ret = mm_image_create_image(_src->width, _src->height, color, output_buffer, _imgp_info_s->buffer_size, dst);
+               if (ret != MM_UTIL_ERROR_NONE) {
+                       mm_util_error("mm_image_create_image failed");
+                       ret = MM_UTIL_ERROR_INVALID_OPERATION;
+                       goto ERROR;
+               }
        }
 
-       *result_buf_width = res_w;
-       *result_buf_height = res_h;
-
-       mm_util_debug("dst[%p] result_buf_w[%u] result_buf_h[%u] output_stride[%u] output_elevation[%u]", dst, *result_buf_width, *result_buf_height, _imgp_info_s->output_stride, _imgp_info_s->output_elevation);
-
 ERROR:
        /* Finalize */
        __mm_util_imgp_finalize(_module, _imgp_info_s);
+       MMUTIL_SAFE_FREE(output_buffer);
 
        mm_util_fleave();
 
        return ret;
 }
 
-int mm_util_resize_image(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_color_format_e src_format, unsigned int dst_width, unsigned int dst_height, unsigned char **dst, unsigned int *result_buf_width, unsigned int *result_buf_height, size_t *result_buf_size)
+int mm_util_resize_image(mm_util_image_h src, unsigned int width, unsigned int height, mm_util_image_h *dst)
 {
        int ret = MM_UTIL_ERROR_NONE;
        IMGPInfoFunc _mm_util_imgp_func = NULL;
        GModule *_module = NULL;
        unsigned char *output_buffer = NULL;
-       unsigned int res_w = 0;
-       unsigned int res_h = 0;
-       unsigned char *res_buffer = NULL;
-       size_t res_buffer_size = 0;
-
-       mm_util_retvm_if(src == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src");
-       mm_util_retvm_if(src_width == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_width");
-       mm_util_retvm_if(src_height == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_height");
-       mm_util_retvm_if((IS_VALID_COLOR(src_format) == FALSE), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_format [%d]", src_format);
-       mm_util_retvm_if((__mm_util_check_format(src_format) == FALSE), MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported src_format [%d]", src_format);
-       mm_util_retvm_if(dst == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst");
-       mm_util_retvm_if(dst_width == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_width");
-       mm_util_retvm_if(dst_height == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_height");
-       mm_util_retvm_if(result_buf_width == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_width");
-       mm_util_retvm_if(result_buf_height == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_height");
-       mm_util_retvm_if(result_buf_size == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_size");
-
-       mm_util_debug("src_width [%d] src_height [%d] src_format[%d]", src_width, src_height, src_format);
-
-       _mm_util_imgp_func = __mm_util_initialize(IMGP_RSZ, src_format, 0, &_module);
+       mm_image_info_s *_src = (mm_image_info_s *)src;
+       mm_util_image_h _resize_image = NULL;
+
+       mm_util_fenter();
+
+       mm_util_retvm_if(!IS_VALID_IMAGE(src), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid src");
+       mm_util_retvm_if(width == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid width");
+       mm_util_retvm_if(height == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid height");
+       mm_util_retvm_if(!dst, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid dst");
+
+       mm_util_debug("[Input] width[%u] height[%u]", width, height);
+       mm_image_debug_image(src, "Input");
+
+       _mm_util_imgp_func = __mm_util_initialize(IMGP_RSZ, _src->color, 0, &_module);
        mm_util_retvm_if(_mm_util_imgp_func == NULL, MM_UTIL_ERROR_INVALID_OPERATION, "fail __mm_util_initialize");
 
        imgp_info_s *_imgp_info_s = (imgp_info_s *) calloc(1, sizeof(imgp_info_s));
@@ -594,10 +582,7 @@ int mm_util_resize_image(const unsigned char *src, unsigned int src_width, unsig
                goto ERROR;
        }
 
-       res_w = dst_width;
-       res_h = dst_height;
-
-       ret = __mm_set_imgp_info_s(_imgp_info_s, src_format, src_width, src_height, src_format, dst_width, dst_height, MM_UTIL_ROTATE_0);
+       ret = __mm_set_imgp_info_s(_imgp_info_s, _src->color, _src->width, _src->height, _src->color, width, height, MM_UTIL_ROTATE_0);
        if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("__mm_set_imgp_info_s failed [%d]", ret);
                ret = MM_UTIL_ERROR_INVALID_OPERATION;
@@ -612,7 +597,7 @@ int mm_util_resize_image(const unsigned char *src, unsigned int src_width, unsig
                }
        }
 
-       ret = _mm_util_imgp_func(_imgp_info_s, src, &output_buffer, IMGP_RSZ);
+       ret = _mm_util_imgp_func(_imgp_info_s, _src->data, &output_buffer, IMGP_RSZ);
        mm_util_debug("_mm_util_imgp_func, ret: %d", ret);
        if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("image processing failed");
@@ -620,62 +605,60 @@ int mm_util_resize_image(const unsigned char *src, unsigned int src_width, unsig
        }
 
        if ((_imgp_info_s->dst_width != _imgp_info_s->output_stride || _imgp_info_s->dst_height != _imgp_info_s->output_elevation)) {
-               ret = mm_util_crop_image(output_buffer, _imgp_info_s->output_stride, _imgp_info_s->output_elevation, src_format, 0, 0, _imgp_info_s->dst_width, _imgp_info_s->dst_height, &res_buffer, &res_w, &res_h, &res_buffer_size);
+               ret = mm_image_create_image(_imgp_info_s->output_stride, _imgp_info_s->output_elevation, _src->color, output_buffer, _imgp_info_s->buffer_size, &_resize_image);
                if (ret != MM_UTIL_ERROR_NONE) {
-                       mm_util_error("mm_util_crop_image failed");
-                       MMUTIL_SAFE_FREE(output_buffer);
+                       mm_util_error("mm_image_create_image failed");
                        ret = MM_UTIL_ERROR_INVALID_OPERATION;
                        goto ERROR;
                }
 
-               MMUTIL_SAFE_FREE(output_buffer);
-               *dst = res_buffer;
-               *result_buf_size = res_buffer_size;
-
+               ret = mm_util_crop_image(_resize_image, 0, 0, _imgp_info_s->dst_width, _imgp_info_s->dst_height, dst);
+               mm_image_destroy_image(_resize_image);
+               if (ret != MM_UTIL_ERROR_NONE) {
+                       mm_util_error("mm_util_crop_image failed");
+                       ret = MM_UTIL_ERROR_INVALID_OPERATION;
+                       goto ERROR;
+               }
        } else {
-               *dst = output_buffer;
-               *result_buf_size = _imgp_info_s->buffer_size;
+               ret = mm_image_create_image(width, height, _src->color, output_buffer, _imgp_info_s->buffer_size, dst);
+               if (ret != MM_UTIL_ERROR_NONE) {
+                       mm_util_error("mm_image_create_image failed");
+                       ret = MM_UTIL_ERROR_INVALID_OPERATION;
+                       goto ERROR;
+               }
        }
 
-       *result_buf_width = res_w;
-       *result_buf_height = res_h;
-
-       mm_util_debug("dst[%p] result_buf_w[%u] result_buf_h[%u] output_stride[%u] output_elevation[%u]", dst, *result_buf_width, *result_buf_height, _imgp_info_s->output_stride, _imgp_info_s->output_elevation);
-
 ERROR:
        /* Finalize */
        __mm_util_imgp_finalize(_module, _imgp_info_s);
+       MMUTIL_SAFE_FREE(output_buffer);
 
        mm_util_fleave();
 
        return ret;
 }
 
-int mm_util_rotate_image(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_color_format_e src_format, mm_util_img_rotate_type angle, unsigned char **dst, unsigned int *result_buf_width, unsigned int *result_buf_height, size_t *result_buf_size)
+int mm_util_rotate_image(mm_util_image_h src, mm_util_img_rotate_type angle, mm_util_image_h *dst)
 {
        int ret = MM_UTIL_ERROR_NONE;
        IMGPInfoFunc _mm_util_imgp_func = NULL;
        GModule *_module = NULL;
        unsigned char *output_buffer = NULL;
-       unsigned int res_w = 0;
-       unsigned int res_h = 0;
-       unsigned char *res_buffer = NULL;
-       size_t res_buffer_size = 0;
-
-       mm_util_retvm_if(src == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src");
-       mm_util_retvm_if(src_width == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_width");
-       mm_util_retvm_if(src_height == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_height");
-       mm_util_retvm_if((IS_VALID_COLOR(src_format) == FALSE), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_format [%d]", src_format);
-       mm_util_retvm_if((__mm_util_check_format(src_format) == FALSE), MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported src_format [%d]", src_format);
-       mm_util_retvm_if((angle < MM_UTIL_ROTATE_0) || (angle >= MM_UTIL_ROTATE_NUM), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid angle [%d]", angle);
-       mm_util_retvm_if(dst == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst");
-       mm_util_retvm_if(result_buf_width == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_width");
-       mm_util_retvm_if(result_buf_height == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_height");
-       mm_util_retvm_if(result_buf_size == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_size");
-
-       mm_util_debug("src_w[%u] src_h[%u] src_format[%u] angle[%u]", src_width, src_height, src_format, angle);
-
-       _mm_util_imgp_func = __mm_util_initialize(IMGP_ROT, src_format, 0, &_module);
+       unsigned int uint_w = 0;
+       unsigned int uint_h = 0;
+       mm_image_info_s *_src = (mm_image_info_s *)src;
+       mm_util_image_h _rotate_image = NULL;
+
+       mm_util_fenter();
+
+       mm_util_retvm_if(!IS_VALID_IMAGE(src), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid src");
+       mm_util_retvm_if((angle < MM_UTIL_ROTATE_0) || (angle >= MM_UTIL_ROTATE_NUM), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid angle [%d]", angle);
+       mm_util_retvm_if(!dst, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid dst");
+
+       mm_util_debug("[Input] angle[%d]", angle);
+       mm_image_debug_image(src, "Input");
+
+       _mm_util_imgp_func = __mm_util_initialize(IMGP_ROT, _src->color, 0, &_module);
        if (_mm_util_imgp_func == NULL) {
                mm_util_error("ERROR - __mm_util_initialize");
                return MM_UTIL_ERROR_INVALID_OPERATION;
@@ -689,14 +672,14 @@ int mm_util_rotate_image(const unsigned char *src, unsigned int src_width, unsig
        }
 
        if ((angle == MM_UTIL_ROTATE_90) || (angle == MM_UTIL_ROTATE_270)) {
-               res_w = src_height;
-               res_h = src_width;
+               uint_w = _src->height;
+               uint_h = _src->width;
        } else {
-               res_w = src_width;
-               res_h = src_height;
+               uint_w = _src->width;
+               uint_h = _src->height;
        }
 
-       ret = __mm_set_imgp_info_s(_imgp_info_s, src_format, src_width, src_height, src_format, res_w, res_h, angle);
+       ret = __mm_set_imgp_info_s(_imgp_info_s, _src->color, _src->width, _src->height, _src->color, uint_w, uint_h, angle);
        mm_util_debug("__mm_set_imgp_info_s");
        if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("__mm_set_imgp_info_s failed");
@@ -712,7 +695,7 @@ int mm_util_rotate_image(const unsigned char *src, unsigned int src_width, unsig
                }
        }
 
-       ret = _mm_util_imgp_func(_imgp_info_s, src, &output_buffer, IMGP_ROT);
+       ret = _mm_util_imgp_func(_imgp_info_s, _src->data, &output_buffer, IMGP_ROT);
        if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("image processing failed");
                goto ERROR;
@@ -731,122 +714,108 @@ int mm_util_rotate_image(const unsigned char *src, unsigned int src_width, unsig
                        start_x = 0;
                        start_y = _imgp_info_s->output_elevation - _imgp_info_s->dst_height;
                }
-               ret = mm_util_crop_image(output_buffer, _imgp_info_s->output_stride, _imgp_info_s->output_elevation, src_format, start_x, start_y, _imgp_info_s->dst_width, _imgp_info_s->dst_height, &res_buffer, &res_w, &res_h, &res_buffer_size);
+               ret = mm_image_create_image(_imgp_info_s->output_stride, _imgp_info_s->output_elevation, _src->color, output_buffer, _imgp_info_s->buffer_size, &_rotate_image);
                if (ret != MM_UTIL_ERROR_NONE) {
-                       mm_util_error("mm_util_crop_image failed");
-                       MMUTIL_SAFE_FREE(output_buffer);
+                       mm_util_error("mm_image_create_image failed");
                        ret = MM_UTIL_ERROR_INVALID_OPERATION;
                        goto ERROR;
                }
 
-               MMUTIL_SAFE_FREE(output_buffer);
-               *dst = res_buffer;
-               *result_buf_size = res_buffer_size;
+               ret = mm_util_crop_image(_rotate_image, 0, 0, start_x, start_y, dst);
+               mm_image_destroy_image(_rotate_image);
+               if (ret != MM_UTIL_ERROR_NONE) {
+                       mm_util_error("mm_util_crop_image failed");
+                       ret = MM_UTIL_ERROR_INVALID_OPERATION;
+                       goto ERROR;
+               }
        } else {
-               *dst = output_buffer;
-               *result_buf_size = _imgp_info_s->buffer_size;
+               ret = mm_image_create_image(uint_w, uint_h, _src->color, output_buffer, _imgp_info_s->buffer_size, dst);
+               if (ret != MM_UTIL_ERROR_NONE) {
+                       mm_util_error("mm_image_create_image failed");
+                       ret = MM_UTIL_ERROR_INVALID_OPERATION;
+                       goto ERROR;
+               }
        }
 
-       *result_buf_width = res_w;
-       *result_buf_height = res_h;
-
-       mm_util_debug("dst[%p] result_buf_w[%u] result_buf_h[%u] output_stride[%u] output_elevation[%u]", dst, *result_buf_width, *result_buf_height, _imgp_info_s->output_stride, _imgp_info_s->output_elevation);
-
 ERROR:
        /* Finalize */
        __mm_util_imgp_finalize(_module, _imgp_info_s);
+       MMUTIL_SAFE_FREE(output_buffer);
 
        mm_util_fleave();
 
        return ret;
 }
 
-int mm_util_crop_image(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_color_format_e src_format,
-unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_width, unsigned int crop_dest_height, unsigned char **dst, unsigned int *result_buf_width, unsigned int *result_buf_height, size_t *result_buf_size)
+int mm_util_crop_image(mm_util_image_h src, unsigned int start_x, unsigned int start_y, unsigned int width, unsigned int height, mm_util_image_h *dst)
 {
        int ret = MM_UTIL_ERROR_NONE;
-       size_t dst_buf_size = 0;
-       unsigned char *dst_buffer = NULL;
-       unsigned int res_w = 0;
-       unsigned int res_h = 0;
-
-       mm_util_retvm_if(src == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src");
-       mm_util_retvm_if(src_width == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_width");
-       mm_util_retvm_if(src_height == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_height");
-       mm_util_retvm_if((IS_VALID_COLOR(src_format) == FALSE), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_format [%d]", src_format);
-       mm_util_retvm_if((__mm_util_check_format(src_format) == FALSE), MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported src_format [%d]", src_format);
-       mm_util_retvm_if(dst == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst");
-       mm_util_retvm_if(result_buf_width == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_width");
-       mm_util_retvm_if(result_buf_height == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_height");
-       mm_util_retvm_if(result_buf_size == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_size");
-       mm_util_retvm_if((crop_start_x + crop_dest_width == 0), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid crop_width [%d]]", crop_dest_width);
-       mm_util_retvm_if((crop_start_y + crop_dest_height == 0), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid crop_height [%d]", crop_dest_height);
-       mm_util_retvm_if((crop_start_x + crop_dest_width > src_width), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid position [%d]]", crop_start_x);
-       mm_util_retvm_if((crop_start_y + crop_dest_height > src_height), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid position [%d]", crop_start_y);
-
-       mm_util_debug("[Input] src[%p] src_width[%u] src_height[%u] src_format[%d] crop_start_x[%u] crop_start_y[%u] crop_dest_width[%u] crop_dest_height[%u]",
-                                               src, src_width, src_height, src_format, crop_start_x, crop_start_y, crop_dest_width, crop_dest_height);
-
-       __mm_util_get_crop_image_size(src_format, crop_dest_width, crop_dest_height, &dst_buf_size);
-       mm_util_retvm_if(dst_buf_size == 0, MM_UTIL_ERROR_INVALID_OPERATION, "fail to get dst_buf_size");
-
-       dst_buffer = calloc(1, dst_buf_size);
-       mm_util_retvm_if(dst_buffer == NULL, MM_UTIL_ERROR_OUT_OF_MEMORY, "memory alloc fail");
-
-       res_w = crop_dest_width;
-       res_h = crop_dest_height;
-
-       switch (src_format) {
+       mm_image_info_s *_src = (mm_image_info_s *)src;
+       unsigned int _width = width;
+       unsigned int _height = height;
+       unsigned char *_buffer = NULL;
+       size_t _buffer_size = 0;
+
+       mm_util_fenter();
+
+       mm_util_retvm_if(!IS_VALID_IMAGE(src), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid src");
+       mm_util_retvm_if((start_x + width > _src->width), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid position [%u][%u]", start_x, width);
+       mm_util_retvm_if((start_y + height > _src->height), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid position [%u][%u]", start_y, height);
+       mm_util_retvm_if(!dst, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid dst");
+
+       mm_util_debug("[Input] start_x[%u] start_y[%u] width[%u] height[%u]", start_x, start_y, width, height);
+       mm_image_debug_image(src, "Input");
+
+       if (_src->color == MM_UTIL_COLOR_I420 || _src->color == MM_UTIL_COLOR_YUV420) {
+               if ((_width % 2) != 0) {
+                       mm_util_warn("#YUV Width value(%u) must be even at least# ", _width);
+                       _width = ((_width+1)>>1)<<1;
+                       mm_util_debug("Image isplay is suceeded when YUV crop width value %u", _width);
+               }
+
+               if ((_height % 2) != 0) { /* height value must be also even when crop yuv image */
+                       mm_util_warn("#YUV Height value(%u) must be even at least# ", _height);
+                       _height = ((_height+1)>>1)<<1;
+                       mm_util_debug("Image isplay is suceeded when YUV crop height value %u", _height);
+               }
+       }
+
+       __mm_util_get_crop_image_size(_src->color, _width, _height, &_buffer_size);
+       mm_util_retvm_if(!_buffer_size, MM_UTIL_ERROR_INVALID_OPERATION, "fail to get dst_buf_size");
+
+       _buffer = calloc(1, _buffer_size);
+       mm_util_retvm_if(!_buffer, MM_UTIL_ERROR_OUT_OF_MEMORY, "Memory allocation failed");
+
+       switch (_src->color) {
        case MM_UTIL_COLOR_RGB16: {
-               ret = __mm_util_crop_rgb16(src, src_width, src_height, crop_start_x, crop_start_y, res_w, res_h, dst_buffer);
+               ret = __mm_util_crop_rgb16(_src->data, _src->width, _src->height, start_x, start_y, _width, _height, _buffer);
                break;
                }
        case MM_UTIL_COLOR_RGB24: {
-               ret = __mm_util_crop_rgb24(src, src_width, src_height, crop_start_x, crop_start_y, res_w, res_h, dst_buffer);
+               ret = __mm_util_crop_rgb24(_src->data, _src->width, _src->height, start_x, start_y, _width, _height, _buffer);
                break;
                }
        case MM_UTIL_COLOR_ARGB:
        case MM_UTIL_COLOR_BGRA:
        case MM_UTIL_COLOR_RGBA:
        case MM_UTIL_COLOR_BGRX: {
-               ret = __mm_util_crop_rgb32(src, src_width, src_height, crop_start_x, crop_start_y, res_w, res_h, dst_buffer);
+               ret = __mm_util_crop_rgb32(_src->data, _src->width, _src->height, start_x, start_y, _width, _height, _buffer);
                break;
                }
        case MM_UTIL_COLOR_I420:
        case MM_UTIL_COLOR_YUV420: {
-               if ((crop_dest_width % 2) != 0) {
-                       mm_util_warn("#YUV Width value(%d) must be even at least# ", crop_dest_width);
-                       res_w = ((crop_dest_width+1)>>1)<<1;
-                       mm_util_debug("Image isplay is suceeded when YUV crop width value %d", res_w);
-               }
-
-               if ((crop_dest_height % 2) != 0) { /* height value must be also even when crop yuv image */
-                       mm_util_warn("#YUV Height value(%d) must be even at least# ", crop_dest_height);
-                       res_h = ((crop_dest_height+1)>>1)<<1;
-                       mm_util_debug("Image isplay is suceeded when YUV crop height value %d", res_h);
-               }
-
-               MMUTIL_SAFE_FREE(dst_buffer);
-               __mm_util_get_crop_image_size(src_format, res_w, res_h, &dst_buf_size);
-               mm_util_retvm_if(dst_buf_size == 0, MM_UTIL_ERROR_INVALID_OPERATION, "fail to get dst_buf_size");
-
-               dst_buffer = calloc(1, dst_buf_size);
-               mm_util_retvm_if(dst_buffer == NULL, MM_UTIL_ERROR_OUT_OF_MEMORY, "memory alloc fail");
-
-               ret = __mm_util_crop_yuv420(src, src_width, src_height, crop_start_x, crop_start_y, res_w, res_h, dst_buffer);
+               ret = __mm_util_crop_yuv420(_src->data, _src->width, _src->height, start_x, start_y, _width, _height, _buffer);
                break;
                }
        default:
                mm_util_debug("Not supported format");
-               MMUTIL_SAFE_FREE(dst_buffer);
-               ret = MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
+               MMUTIL_SAFE_FREE(_buffer);
+               return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
        }
 
-       *result_buf_size = dst_buf_size;
-       *dst = dst_buffer;
-       *result_buf_width = res_w;
-       *result_buf_height = res_h;
+       ret = mm_image_create_image(_width, _height, _src->color, _buffer, _buffer_size, dst);
 
+       MMUTIL_SAFE_FREE(_buffer);
        mm_util_fleave();
 
        return ret;
@@ -862,8 +831,8 @@ int mm_util_get_image_size(mm_util_color_format_e format, unsigned int width, un
 
        mm_util_fenter();
 
-       mm_util_retvm_if((imgsize == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid imgsize");
-       mm_util_retvm_if((IS_VALID_COLOR(format) == FALSE), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid format [%d]", format);
+       mm_util_retvm_if((imgsize == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid imgsize");
+       mm_util_retvm_if((IS_VALID_COLOR(format) == FALSE), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid format [%d]", format);
        mm_util_retvm_if((__check_valid_picture_size(width, height) != MM_UTIL_ERROR_NONE), MM_UTIL_ERROR_INVALID_PARAMETER, "image width & height is too big");
 
        *imgsize = 0;