Modify mm_util_resize_image() API to receive allocated buffer and buffer info
[platform/core/multimedia/libmm-utility.git] / imgp / mm_util_imgp.c
index d5ebcf5..f1daaf6 100755 (executable)
@@ -562,22 +562,18 @@ static int __mm_util_processing(mm_util_s *handle)
                src_height = res_h;
        } else if (handle->set_resize) {
                dst_index++;
-               mm_util_get_image_size(src_format, handle->dst_width, handle->dst_height, &res_buffer_size);
-               dst_buf[dst_index] = calloc(1, res_buffer_size);
-               if (dst_buf[dst_index] == NULL) {
-                       mm_util_error("[multi func] memory allocation error");
-                       __mm_destroy_temp_buffer(dst_buf);
-                       return MM_UTIL_ERROR_INVALID_OPERATION;
-               }
-               ret = mm_util_resize_image(dst_buf[src_index], src_width, src_height, src_format, dst_buf[dst_index], &handle->dst_width, &handle->dst_height);
+
+               ret = mm_util_resize_image(dst_buf[src_index], src_width, src_height, src_format, handle->dst_width, handle->dst_height, &res_buffer, &res_w, &res_h, &res_buffer_size);
                if (ret != MM_UTIL_ERROR_NONE) {
                        __mm_destroy_temp_buffer(dst_buf);
                        mm_util_error("mm_util_resize_image failed");
                        return ret;
                }
+
+               dst_buf[dst_index] = res_buffer;
                src_index = dst_index;
-               src_width = handle->dst_width;
-               src_height = handle->dst_height;
+               src_width = res_w;
+               src_height = res_h;
        }
 
        if (handle->set_convert) {
@@ -965,7 +961,7 @@ ERROR:
        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 char *dst, unsigned int *dst_width, unsigned int *dst_height)
+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 ret = MM_UTIL_ERROR_NONE;
        IMGPInfoFunc _mm_util_imgp_func = NULL;
@@ -982,8 +978,8 @@ int mm_util_resize_image(const unsigned char *src, unsigned int src_width, unsig
        mm_util_retvm_if((IS_MM_UTIL_COLOR_FORMAT(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 == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_width");
-       mm_util_retvm_if(dst_height == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_height");
+       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_debug("src_width [%d] src_height [%d] src_format[%d]", src_width, src_height, src_format);
 
@@ -997,8 +993,10 @@ int mm_util_resize_image(const unsigned char *src, unsigned int src_width, unsig
                goto ERROR;
        }
 
-       mm_util_debug("__mm_set_imgp_info_s");
-       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);
+       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);
        if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("__mm_set_imgp_info_s failed [%d]", ret);
                ret = MM_UTIL_ERROR_INVALID_OPERATION;
@@ -1024,29 +1022,29 @@ int mm_util_resize_image(const unsigned char *src, unsigned int src_width, unsig
                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);
                if (ret != MM_UTIL_ERROR_NONE) {
                        mm_util_error("mm_util_crop_image failed");
+                       MMUTIL_SAFE_FREE(output_buffer);
                        ret = MM_UTIL_ERROR_INVALID_OPERATION;
                        goto ERROR;
                }
-               memcpy(dst, res_buffer, res_buffer_size);
-               *dst_width = res_w;
-               *dst_height = res_h;
+
+               MMUTIL_SAFE_FREE(output_buffer);
+               *dst = res_buffer;
+               *result_buf_size = res_buffer_size;
+
        } else {
-               memcpy(dst, output_buffer, _imgp_info_s->buffer_size);
-               *dst_width = _imgp_info_s->dst_width;
-               *dst_height = _imgp_info_s->dst_height;
+               *dst = output_buffer;
+               *result_buf_size = _imgp_info_s->buffer_size;
        }
 
-       /* Output result*/
-       mm_util_debug("dst: %p dst_width: %d, dst_height: %d, output_stride: %d, output_elevation: %d",
-                       dst, _imgp_info_s->dst_width, _imgp_info_s->dst_height, _imgp_info_s->output_stride, _imgp_info_s->output_elevation);
+       *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);
-       MMUTIL_SAFE_FREE(res_buffer);
-
        mm_util_fleave();
 
        return ret;
@@ -1151,7 +1149,6 @@ int mm_util_rotate_image(const unsigned char *src, unsigned int src_width, unsig
        *result_buf_width = res_w;
        *result_buf_height = res_h;
 
-       /* Output result*/
        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: