Modify mm_util_resize_image() API to receive allocated buffer and buffer info 53/170453/3
authorhj kim <backto.kim@samsung.com>
Tue, 20 Feb 2018 06:10:46 +0000 (15:10 +0900)
committerJiyong Min <jiyong.min@samsung.com>
Wed, 21 Feb 2018 04:52:55 +0000 (04:52 +0000)
Change-Id: I46bcdf8ef91f999cdddab5415d1daa5d371425c3

imgp/include/mm_util_imgp.h
imgp/mm_util_imgp.c
imgp/test/mm_util_imgp_testsuite.c

index 1138cb8..51f6b42 100755 (executable)
@@ -207,7 +207,8 @@ int mm_util_convert_colorspace(const unsigned char *src, unsigned int src_width,
  * @see         mm_util_color_format_e
  * @since       R1, 1.0
  */
-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);
+
 
 /**
  * This function rotates the source image.
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:
index ffd889a..c82c96f 100755 (executable)
@@ -187,11 +187,13 @@ int main(int argc, char *argv[])
 
        if (sync_mode) {
                fprintf(stderr, "SYNC\n");
-               if (strcmp(command, "convert") == 0)
+               if (strcmp(command, "convert") == 0) {
                        ret = mm_util_convert_colorspace(src, src_width, src_height, src_format, dst, dst_format);
-               else if (strcmp(command, "resize") == 0)
-                       ret = mm_util_resize_image(src, src_width, src_height, src_format, dst, &dst_width, &dst_height);
-               else if (strcmp(command, "rotate") == 0) {
+               } else if (strcmp(command, "resize") == 0) {
+                       ret = mm_util_resize_image(src, src_width, src_height, src_format, dst_width, dst_height, &res_buffer, &res_w, &res_h, &res_buffer_size);
+                       IMGP_FREE(dst);
+                       dst = res_buffer;
+               } else if (strcmp(command, "rotate") == 0) {
                        ret = mm_util_rotate_image(src, src_width, src_height, src_format, rotation, &res_buffer, &res_w, &res_h, &res_buffer_size);
                        IMGP_FREE(dst);
                        dst = res_buffer;