From: hj kim Date: Tue, 20 Feb 2018 04:25:25 +0000 (+0900) Subject: Modify mm_util_rotate_image() API to receive allocated buffer and buffer info X-Git-Tag: submit/tizen/20180223.061228~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=66588d980900bc2cb78b5f0c9eb2d3d20b26b8d5;p=platform%2Fcore%2Fmultimedia%2Flibmm-utility.git Modify mm_util_rotate_image() API to receive allocated buffer and buffer info Change-Id: Ie4bf988dc07230b2a0f66c7ce1a8d335434c8128 --- diff --git a/imgp/include/mm_util_imgp.h b/imgp/include/mm_util_imgp.h index bb139ee..1138cb8 100755 --- a/imgp/include/mm_util_imgp.h +++ b/imgp/include/mm_util_imgp.h @@ -226,7 +226,8 @@ int mm_util_resize_image(const unsigned char *src, unsigned int src_width, unsig * @see mm_util_color_format_e, mm_util_img_rotate_type * @since R1, 1.0 */ -int mm_util_rotate_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, mm_util_img_rotate_type angle); +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); + /** * This function crop the source image. diff --git a/imgp/mm_util_imgp.c b/imgp/mm_util_imgp.c index 7867343..d5ebcf5 100755 --- a/imgp/mm_util_imgp.c +++ b/imgp/mm_util_imgp.c @@ -290,53 +290,6 @@ static int __mm_util_get_crop_image_size(mm_util_color_format_e format, unsigned return ret; } -static int __mm_confirm_dst_width_height(unsigned int src_width, unsigned int src_height, unsigned int *dst_width, unsigned int *dst_height, mm_util_img_rotate_type angle) -{ - int ret = MM_UTIL_ERROR_NONE; - - 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_fenter(); - - switch (angle) { - case MM_UTIL_ROTATE_0: - case MM_UTIL_ROTATE_180: - case MM_UTIL_ROTATE_FLIP_HORZ: - case MM_UTIL_ROTATE_FLIP_VERT: - if (*dst_width != src_width) { - mm_util_debug("*dst_width: %d", *dst_width); - *dst_width = src_width; - mm_util_debug("#Confirmed# *dst_width: %d", *dst_width); - } - if (*dst_height != src_height) { - mm_util_debug("*dst_height: %d", *dst_height); - *dst_height = src_height; - mm_util_debug("#Confirmed# *dst_height: %d", *dst_height); - } - break; - case MM_UTIL_ROTATE_90: - case MM_UTIL_ROTATE_270: - if (*dst_width != src_height) { - mm_util_debug("*dst_width: %d", *dst_width); - *dst_width = src_height; - mm_util_debug("#Confirmed# *dst_width: %d", *dst_width); - } - if (*dst_height != src_width) { - mm_util_debug("*dst_height: %d", *dst_height); - *dst_height = src_width; - mm_util_debug("#Confirmed# *dst_height: %d", *dst_height); - } - break; - - default: - mm_util_error("Not supported rotate value"); - return MM_UTIL_ERROR_INVALID_PARAMETER; - } - - return ret; -} - static int __mm_set_imgp_info_s(imgp_info_s *_imgp_info_s, mm_util_color_format_e src_format, unsigned int src_width, unsigned int src_height, mm_util_color_format_e dst_format, unsigned int dst_width, unsigned int dst_height, mm_util_img_rotate_type angle) { int ret = MM_UTIL_ERROR_NONE; @@ -605,8 +558,8 @@ static int __mm_util_processing(mm_util_s *handle) 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; } else if (handle->set_resize) { dst_index++; mm_util_get_image_size(src_format, handle->dst_width, handle->dst_height, &res_buffer_size); @@ -629,6 +582,7 @@ static int __mm_util_processing(mm_util_s *handle) if (handle->set_convert) { dst_index++; + mm_util_get_image_size(handle->dst_format, src_width, src_height, &res_buffer_size); dst_buf[dst_index] = calloc(1, res_buffer_size); if (dst_buf[dst_index] == NULL) { @@ -648,30 +602,17 @@ static int __mm_util_processing(mm_util_s *handle) if (handle->set_rotate) { dst_index++; - switch (handle->rotation) { - case MM_UTIL_ROTATION_90: - case MM_UTIL_ROTATION_270: - mm_util_get_image_size(src_format, src_height, src_width, &res_buffer_size); - break; - default: - mm_util_get_image_size(src_format, src_width, src_height, &res_buffer_size); - break; - } - 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_rotate_image(dst_buf[src_index], src_width, src_height, src_format, dst_buf[dst_index], &handle->dst_width, &handle->dst_height, handle->rotation); + ret = mm_util_rotate_image(dst_buf[src_index], src_width, src_height, src_format, handle->rotation, &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_rotate_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 (dst_buf[dst_index] != NULL && res_buffer_size != 0) { @@ -1111,7 +1052,7 @@ ERROR: 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, unsigned char *dst, unsigned int *dst_width, unsigned int *dst_height, mm_util_img_rotate_type angle) +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 ret = MM_UTIL_ERROR_NONE; IMGPInfoFunc _mm_util_imgp_func = NULL; @@ -1127,10 +1068,11 @@ int mm_util_rotate_image(const unsigned char *src, unsigned int src_width, unsig mm_util_retvm_if(src_height == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_height"); 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((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); @@ -1147,14 +1089,15 @@ int mm_util_rotate_image(const unsigned char *src, unsigned int src_width, unsig goto ERROR; } - ret = __mm_confirm_dst_width_height(src_width, src_height, dst_width, dst_height, angle); - if (ret != MM_UTIL_ERROR_NONE) { - mm_util_error("dst_width || dest_height size Error"); - ret = MM_UTIL_ERROR_INVALID_PARAMETER; - goto ERROR; + if ((angle == MM_UTIL_ROTATE_90) || (angle == MM_UTIL_ROTATE_270)) { + res_w = src_height; + res_h = src_width; + } else { + res_w = src_width; + res_h = src_height; } - ret = __mm_set_imgp_info_s(_imgp_info_s, src_format, src_width, src_height, src_format, *dst_width, *dst_height, angle); + ret = __mm_set_imgp_info_s(_imgp_info_s, src_format, src_width, src_height, src_format, res_w, res_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"); @@ -1192,28 +1135,29 @@ int mm_util_rotate_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, start_x, start_y, _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 = _imgp_info_s->dst_width; - *dst_height = _imgp_info_s->dst_height; + + 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; } + *result_buf_width = res_w; + *result_buf_height = res_h; + /* Output result*/ - mm_util_debug("dst[%p] dst_w[%u] dst_h[%u] output_stride[%u] output_elevation[%u]", dst, _imgp_info_s->dst_width, _imgp_info_s->dst_height, _imgp_info_s->output_stride, _imgp_info_s->output_elevation); + 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; @@ -1234,6 +1178,9 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_wid 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(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 > 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); diff --git a/imgp/test/mm_util_imgp_testsuite.c b/imgp/test/mm_util_imgp_testsuite.c index 6b3577a..ffd889a 100755 --- a/imgp/test/mm_util_imgp_testsuite.c +++ b/imgp/test/mm_util_imgp_testsuite.c @@ -191,9 +191,11 @@ int main(int argc, char *argv[]) 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) - ret = mm_util_rotate_image(src, src_width, src_height, src_format, dst, &dst_width, &dst_height, rotation); - else if (strcmp(command, "crop") == 0) { + 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; + } else if (strcmp(command, "crop") == 0) { ret = mm_util_crop_image(src, src_width, src_height, src_format, start_x, start_y, dst_width, dst_height, &res_buffer, &res_w, &res_h, &res_buffer_size); IMGP_FREE(dst); dst = res_buffer;