From: jiyong.min Date: Tue, 12 Mar 2019 08:39:58 +0000 (+0900) Subject: Modify parameter in imgage processing APIs to mm_util_image_h X-Git-Tag: submit/tizen/20190313.075153~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F06%2F201306%2F6;p=platform%2Fcore%2Fapi%2Fimage-util.git Modify parameter in imgage processing APIs to mm_util_image_h Change-Id: Ic39ef558640328f10f0c82e8285b8ecbac35e914 --- diff --git a/include/image_util_private.h b/include/image_util_private.h index eee2a04..05063d8 100755 --- a/include/image_util_private.h +++ b/include/image_util_private.h @@ -96,17 +96,14 @@ typedef struct { } image_util_cb_s; typedef struct { - mm_util_image_h src; - mm_util_image_h dst; - /* for converting colorspace */ - mm_util_color_format_e dst_format; + mm_util_color_format_e color; /* for image crop */ /* for resize */ - unsigned int start_x; - unsigned int start_y; - unsigned int dst_width; - unsigned int dst_height; + unsigned int x; + unsigned int y; + unsigned int width; + unsigned int height; /* for rotation */ mm_util_img_rotate_type rotation; diff --git a/src/image_util.c b/src/image_util.c index 000341c..d214d6b 100644 --- a/src/image_util.c +++ b/src/image_util.c @@ -147,110 +147,46 @@ static int __create_media_packet(media_format_h fmt, media_packet_h *new_pkt, vo return IMAGE_UTIL_ERROR_NONE; } -static void __mm_destroy_temp_buffer(unsigned char *buffer[]) -{ - int i = 0; - - for (i = 0; i < 4; i++) - IMAGE_UTIL_SAFE_FREE(buffer[i]); -} - -static int __mm_util_transform(transformation_s *handle) +static int __mm_util_transform(transformation_s *operation, mm_util_image_h origin, mm_util_image_h *transform) { int ret = IMAGE_UTIL_ERROR_NONE; - unsigned char *dst_buf[4] = {NULL,}; - unsigned int src_width = 0, src_height = 0; - mm_util_color_format_e src_format = -1; - unsigned int src_index = 0, dst_index = 0; - unsigned int res_w = 0; - unsigned int res_h = 0; - unsigned char *res_buffer = NULL; - unsigned char *res_buffer_conv = NULL; - unsigned char *res_buffer_rotate = NULL; - size_t src_size = 0; - size_t res_buffer_size = 0; - - image_util_retvm_if(handle == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "invalid handle"); - - image_util_debug("src: %p, dst: %p", handle->src, handle->dst); - - ret = mm_image_get_image(handle->src, &src_width, &src_height, &src_format, &dst_buf[src_index], &src_size); - image_util_retvm_if(ret != MM_UTIL_ERROR_NONE, _image_error_capi(ret), "mm_image_get_image failed"); - - if (handle->set_crop) { - dst_index++; - - ret = mm_util_crop_image(dst_buf[src_index], src_width, src_height, src_format, handle->start_x, handle->start_y, 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); - image_util_error("mm_util_crop_image failed"); - return _image_error_capi(ret); - } - - dst_buf[dst_index] = res_buffer; - src_index = dst_index; - src_width = res_w; - src_height = res_h; - } else if (handle->set_resize) { - dst_index++; - - 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); - image_util_error("mm_util_resize_image failed"); - return _image_error_capi(ret); - } - - dst_buf[dst_index] = res_buffer; - src_index = dst_index; - src_width = res_w; - src_height = res_h; - } + mm_util_image_h _src = origin; + mm_util_image_h _dst = NULL; - if (handle->set_convert) { - dst_index++; + image_util_retvm_if(!operation, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid operation"); + image_util_retvm_if(!mm_image_is_valid_image(origin), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid origin"); + image_util_retvm_if(!transform, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid transform"); - ret = mm_util_convert_colorspace(dst_buf[src_index], src_width, src_height, src_format, handle->dst_format, &res_buffer_conv, &res_w, &res_h, &res_buffer_size); - if (ret != MM_UTIL_ERROR_NONE) { - __mm_destroy_temp_buffer(dst_buf); - image_util_error("mm_util_convert_colorspace failed"); - return _image_error_capi(ret); - } + image_util_fenter(); - dst_buf[dst_index] = res_buffer_conv; - src_index = dst_index; - src_format = handle->dst_format; - src_width = res_w; - src_height = res_h; + if (operation->set_crop) { + ret = mm_util_crop_image(_src, operation->x, operation->y, operation->width, operation->height, &_dst); + image_util_retvm_if(ret != MM_UTIL_ERROR_NONE, _image_error_capi(ret), "mm_util_crop_image failed"); + _src = _dst; + } else if (operation->set_resize) { + ret = mm_util_resize_image(_src, operation->width, operation->height, &_dst); + image_util_retvm_if(ret != MM_UTIL_ERROR_NONE, _image_error_capi(ret), "mm_util_resize_image failed"); + _src = _dst; } - if (handle->set_rotate) { - dst_index++; - - ret = mm_util_rotate_image(dst_buf[src_index], src_width, src_height, src_format, handle->rotation, &res_buffer_rotate, &res_w, &res_h, &res_buffer_size); - if (ret != MM_UTIL_ERROR_NONE) { - __mm_destroy_temp_buffer(dst_buf); - image_util_error("mm_util_rotate_image failed"); - return _image_error_capi(ret); - } - - dst_buf[dst_index] = res_buffer_rotate; - src_index = dst_index; - src_width = res_w; - src_height = res_h; + if (operation->set_convert) { + ret = mm_util_convert_colorspace(_src, operation->color, &_dst); + if (origin != _src) + mm_image_destroy_image(_src); + image_util_retvm_if(ret != MM_UTIL_ERROR_NONE, _image_error_capi(ret), "mm_util_convert_colorspace failed"); + _src = _dst; } - if (dst_buf[dst_index] != NULL && res_buffer_size != 0) { - ret = mm_image_create_image(src_width, src_height, src_format, dst_buf[dst_index], res_buffer_size, &(handle->dst)); - if (ret != IMAGE_UTIL_ERROR_NONE) - image_util_error("mm_image_create_image failed"); - } else { - image_util_error("invalid result %p %zu", dst_buf[dst_index], res_buffer_size); - ret = IMAGE_UTIL_ERROR_INVALID_OPERATION; + if (operation->set_rotate) { + ret = mm_util_rotate_image(_src, operation->rotation, &_dst); + if (origin != _src) + mm_image_destroy_image(_src); + image_util_retvm_if(ret != MM_UTIL_ERROR_NONE, _image_error_capi(ret), "mm_util_rotate_image failed"); } - __mm_destroy_temp_buffer(dst_buf); - image_util_error("mm_util_processing was finished"); + *transform = _dst; + + image_util_fleave(); return ret; } @@ -315,29 +251,27 @@ gpointer __mm_util_thread_repeate(gpointer data) { transformation_s *handle = (transformation_s *) data; int ret = IMAGE_UTIL_ERROR_NONE; - mm_util_image_h pop_data = NULL; + mm_util_image_h origin_image = NULL; + mm_util_image_h transformed_image = NULL; media_packet_h packet = NULL; image_util_retvm_if(handle == NULL, NULL, "invalid handle"); while (!handle->is_finish) { image_util_debug("waiting..."); - pop_data = g_async_queue_timeout_pop(handle->queue, 300 * G_TIME_SPAN_MILLISECOND); + origin_image = g_async_queue_timeout_pop(handle->queue, 300 * G_TIME_SPAN_MILLISECOND); image_util_debug("get from data or timeout"); - if (pop_data == NULL) { + if (origin_image == NULL) { image_util_error("The data is null"); continue; } - handle->src = pop_data; - handle->dst = NULL; - - mm_image_debug_image(handle->src, "Origin"); + mm_image_debug_image(origin_image, "Origin"); - ret = __mm_util_transform(handle); + ret = __mm_util_transform(handle, origin_image, &transformed_image); if (ret == IMAGE_UTIL_ERROR_NONE) { - mm_image_debug_image(handle->dst, "Result"); + mm_image_debug_image(transformed_image, "Transformed"); image_util_debug("Success - transform"); } else { image_util_error("Error - transform"); @@ -345,7 +279,7 @@ gpointer __mm_util_thread_repeate(gpointer data) if ((handle->_util_cb != NULL) && (handle->_util_cb->completed_cb != NULL)) { image_util_debug("completed_cb is called"); - ret = __image_util_image_to_packet(handle->dst, &packet); + ret = __image_util_image_to_packet(transformed_image, &packet); if (ret != IMAGE_UTIL_ERROR_NONE) { image_util_error("__image_util_image_to_packet failed (%d)", ret); handle->_util_cb->completed_cb(NULL, ret, handle->_util_cb->user_data); @@ -355,8 +289,8 @@ gpointer __mm_util_thread_repeate(gpointer data) } else { image_util_error("There is no callback"); } - mm_image_destroy_image(pop_data); - mm_image_destroy_image(handle->dst); + mm_image_destroy_image(origin_image); + mm_image_destroy_image(transformed_image); } image_util_debug("exit thread"); @@ -416,14 +350,13 @@ int image_util_transform_create(transformation_h * handle) image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); /* private values init */ - _handle->dst = NULL; - _handle->dst_format = MM_UTIL_COLOR_NUM; + _handle->color = MM_UTIL_COLOR_NUM; _handle->rotation = MM_UTIL_ROTATE_0; - _handle->start_x = -1; - _handle->start_y = -1; - _handle->dst_width = 0; - _handle->dst_height = 0; + _handle->x = 0; + _handle->y = 0; + _handle->width = 0; + _handle->height = 0; _handle->is_finish = FALSE; _handle->set_convert = FALSE; @@ -472,7 +405,7 @@ int image_util_transform_set_colorspace(transformation_h handle, image_util_colo image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace"); - _handle->dst_format = colorspace; + _handle->color = colorspace; _handle->set_convert = true; return IMAGE_UTIL_ERROR_NONE; @@ -488,8 +421,8 @@ int image_util_transform_set_resolution(transformation_h handle, unsigned int wi image_util_retvm_if((_handle->set_crop), IMAGE_UTIL_ERROR_INVALID_OPERATION, "Crop and Resize can't do at the same time"); image_util_retvm_if((width == 0 || height == 0), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid resolution w : [%d] h : [%d]", width, height); - _handle->dst_width = width; - _handle->dst_height = height; + _handle->width = width; + _handle->height = height; _handle->set_resize = true; return IMAGE_UTIL_ERROR_NONE; @@ -512,11 +445,13 @@ int image_util_transform_set_rotation(transformation_h handle, image_util_rotati int image_util_transform_set_crop_area(transformation_h handle, unsigned int start_x, unsigned int start_y, unsigned int end_x, unsigned int end_y) { transformation_s *_handle = (transformation_s *) handle; - int dest_width = 0; - int dest_height = 0; + unsigned int dest_width = 0; + unsigned int dest_height = 0; image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); image_util_retvm_if((_handle->set_resize), IMAGE_UTIL_ERROR_INVALID_OPERATION, "Crop and Resize can't do at the same time"); + image_util_retvm_if((start_x >= end_x), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid position start_x : [%d] end_x : [%d]", start_x, end_x); + image_util_retvm_if((start_y >= end_y), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid position start_y : [%d] end_y : [%d]", start_y, end_y); dest_width = end_x - start_x; dest_height = end_y - start_y; @@ -524,10 +459,10 @@ int image_util_transform_set_crop_area(transformation_h handle, unsigned int sta image_util_debug("Set crop_info x[%d] y[%d] w[%d] h[%d]", start_x, start_y, dest_width, dest_height); image_util_retvm_if((dest_width <= 0 || dest_height <= 0), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid resolution w : [%d] h : [%d]", dest_width, dest_height); - _handle->start_x = start_x; - _handle->start_y = start_y; - _handle->dst_width = dest_width; - _handle->dst_height = dest_height; + _handle->x = start_x; + _handle->y = start_y; + _handle->width = dest_width; + _handle->height = dest_height; _handle->set_crop = true; return IMAGE_UTIL_ERROR_NONE; @@ -541,9 +476,9 @@ int image_util_transform_get_colorspace(transformation_h handle, image_util_colo image_util_retvm_if((colorspace == NULL), IMAGE_UTIL_ERROR_INVALID_OPERATION, "colorspace parameter error"); image_util_retvm_if((!_handle->set_convert), IMAGE_UTIL_ERROR_INVALID_OPERATION, "Did not set colorspace before"); - image_util_debug("Get colorspace_convert_info [%d]", _handle->dst_format); + image_util_debug("Get colorspace_convert_info [%d]", _handle->color); - *colorspace = _handle->dst_format; + *colorspace = _handle->color; return IMAGE_UTIL_ERROR_NONE; } @@ -556,10 +491,10 @@ int image_util_transform_get_resolution(transformation_h handle, unsigned int *w image_util_retvm_if((width == NULL || height == NULL), IMAGE_UTIL_ERROR_INVALID_OPERATION, "width or height parameter error"); image_util_retvm_if((!_handle->set_resize), IMAGE_UTIL_ERROR_INVALID_OPERATION, "Did not set resolution before"); - image_util_debug("Get resize_info w[%ui] h[%ui]", _handle->dst_width, _handle->dst_height); + image_util_debug("Get resize_info w[%ui] h[%ui]", _handle->width, _handle->height); - *width = _handle->dst_width; - *height = _handle->dst_height; + *width = _handle->width; + *height = _handle->height; return IMAGE_UTIL_ERROR_NONE; } @@ -587,10 +522,10 @@ int image_util_transform_get_crop_area(transformation_h handle, unsigned int *st image_util_retvm_if((start_x == NULL || start_y == NULL || end_x == NULL || end_y == NULL), IMAGE_UTIL_ERROR_INVALID_OPERATION, "crop area parameter error"); image_util_retvm_if((!_handle->set_crop), IMAGE_UTIL_ERROR_INVALID_OPERATION, "Did not set crop area before"); - *start_x = _handle->start_x; - *start_y = _handle->start_y; - *end_x = _handle->start_x + _handle->dst_width; - *end_y = _handle->start_x + _handle->dst_height; + *start_x = _handle->x; + *start_y = _handle->y; + *end_x = _handle->x + _handle->width; + *end_y = _handle->y + _handle->height; return IMAGE_UTIL_ERROR_NONE; }