From: hj kim Date: Fri, 5 Oct 2018 07:27:46 +0000 (+0900) Subject: Remove duplicated code and paramters in image-util and libmm-utility X-Git-Tag: submit/tizen/20181106.000712^2~40 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1717e91027b20f7e797283a955838f2ccce0f7ef;p=platform%2Fcore%2Fapi%2Fimage-util.git Remove duplicated code and paramters in image-util and libmm-utility Change-Id: I90920d4290a128745cc59d23790054e3ae3ab21c --- diff --git a/include/image_util_private.h b/include/image_util_private.h index 8c4c090..ea23b52 100755 --- a/include/image_util_private.h +++ b/include/image_util_private.h @@ -21,6 +21,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" @@ -105,21 +106,22 @@ typedef struct { typedef struct { media_packet_h src; media_packet_h dst; - image_util_colorspace_e colorspace; - image_util_rotation_e dest_rotation; - void *image_h; +// image_util_colorspace_e colorspace; dst_format +// image_util_rotation_e dest_rotation; +// void *image_h; + mm_util_s *image_h; image_util_cb_s *_util_cb; - unsigned int width; - unsigned int height; - image_util_rotation_e rotation; - unsigned int start_x; - unsigned int start_y; - unsigned int end_x; - unsigned int end_y; - bool set_convert; - bool set_resize; - bool set_rotate; - bool set_crop; +// unsigned int width; +// unsigned int height; +// image_util_rotation_e rotation; +// unsigned int start_x; +// unsigned int start_y; +// unsigned int end_x; +// unsigned int end_y; +// bool set_convert; +// bool set_resize; +// bool set_rotate; +// bool set_crop; } transformation_s; typedef struct { diff --git a/src/image_util.c b/src/image_util.c index 1d6be7a..81c908b 100755 --- a/src/image_util.c +++ b/src/image_util.c @@ -233,17 +233,46 @@ static void _image_util_transform_completed_cb(mm_util_color_image_h raw_image, return; } -static int _image_util_create_transform_handle(transformation_s * handle) +static int _image_util_create_transform_handle(transformation_s *handle) { - int err = MM_UTIL_ERROR_NONE; - mm_util_imgp_h image_h; + int ret = IMAGE_UTIL_ERROR_NONE; + mm_util_s *_handle = NULL; - err = mm_util_create(&image_h); - image_util_retvm_if((err != MM_UTIL_ERROR_NONE), _image_error_capi(ERR_TYPE_TRANSFORM, err), "Error - mm_util_create"); + image_util_retvm_if((handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "invalid handle"); - handle->image_h = image_h; + _handle = calloc(1, sizeof(mm_util_s)); + image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); - return IMAGE_UTIL_ERROR_NONE; + /* private values init */ + _handle->dst = NULL; + _handle->dst_format = 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->is_completed = FALSE; + _handle->is_finish = FALSE; + + _handle->set_convert = FALSE; + _handle->set_crop = FALSE; + _handle->set_resize = FALSE; + _handle->set_rotate = FALSE; + + /*These are a communicator for thread*/ + if (!_handle->queue) + _handle->queue = g_async_queue_new(); + + if (_handle->queue == NULL) { + image_util_error("g_async_queue_new failed"); + IMAGE_UTIL_SAFE_FREE(_handle); + return MM_UTIL_ERROR_INVALID_OPERATION; + } + + handle->image_h = _handle; + + return ret; } int image_util_transform_create(transformation_h * handle) @@ -257,19 +286,14 @@ int image_util_transform_create(transformation_h * handle) transformation_s *_handle = (transformation_s *) calloc(1, sizeof(transformation_s)); image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); - _handle->colorspace = _NOT_SUPPORTED_COLORSPACE; _handle->_util_cb = NULL; _handle->image_h = NULL; - _handle->set_convert = false; - _handle->set_resize = false; - _handle->set_rotate = false; - _handle->set_crop = false; err = _image_util_create_transform_handle(_handle); if (err != MM_UTIL_ERROR_NONE) { image_util_error("Error - create transform handle"); IMAGE_UTIL_SAFE_FREE(_handle); - return _image_error_capi(ERR_TYPE_TRANSFORM, err); + return MM_UTIL_ERROR_INVALID_OPERATION; } *handle = (transformation_h) _handle; @@ -296,70 +320,61 @@ int image_util_transform_set_hardware_acceleration(transformation_h handle, bool int image_util_transform_set_colorspace(transformation_h handle, image_util_colorspace_e colorspace) { - int err = MM_UTIL_ERROR_NONE; transformation_s *_handle = (transformation_s *) handle; image_util_debug("Set colorspace_convert_info [%d]", colorspace); image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((_handle->image_h == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Image Handle"); - err = mm_util_set_colorspace_convert(_handle->image_h, colorspace); - image_util_retvm_if((err != MM_UTIL_ERROR_NONE), _image_error_capi(ERR_TYPE_TRANSFORM, err), "Error - Set colorspace convert"); - - _handle->colorspace = colorspace; - _handle->set_convert = true; + _handle->image_h->dst_format = colorspace; + _handle->image_h->set_convert = true; return IMAGE_UTIL_ERROR_NONE; } int image_util_transform_set_resolution(transformation_h handle, unsigned int width, unsigned int height) { - int err = MM_UTIL_ERROR_NONE; transformation_s *_handle = (transformation_s *) handle; image_util_debug("Set resize_info w[%d] h[%d]", width, height); image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); - 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((_handle->image_h == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Image Handle"); + image_util_retvm_if((_handle->image_h->set_crop), IMAGE_UTIL_ERROR_INVALID_OPERATION, "Crop and Resize can't do at the same time"); image_util_retvm_if((_image_util_check_resolution(width, height) == false), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid resolution"); - err = mm_util_set_resolution(_handle->image_h, width, height); - image_util_retvm_if((err != MM_UTIL_ERROR_NONE), _image_error_capi(ERR_TYPE_TRANSFORM, err), "Error - Set resolution"); - - _handle->width = width; - _handle->height = height; - _handle->set_resize = true; + _handle->image_h->dst_width = width; + _handle->image_h->dst_height = height; + _handle->image_h->set_resize = true; return IMAGE_UTIL_ERROR_NONE; } int image_util_transform_set_rotation(transformation_h handle, image_util_rotation_e rotation) { - int err = MM_UTIL_ERROR_NONE; transformation_s *_handle = (transformation_s *) handle; image_util_debug("Set rotate_info [%d]", rotation); image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((_handle->image_h == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Image Handle"); - err = mm_util_set_rotation(_handle->image_h, rotation); - image_util_retvm_if((err != MM_UTIL_ERROR_NONE), _image_error_capi(ERR_TYPE_TRANSFORM, err), "Error - Set rotation"); - - _handle->rotation = rotation; - _handle->set_rotate = true; + _handle->image_h->rotation = rotation; + _handle->image_h->set_rotate = true; return IMAGE_UTIL_ERROR_NONE; } 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) { - int err = MM_UTIL_ERROR_NONE; transformation_s *_handle = (transformation_s *) handle; - int dest_width; - int dest_height; + int dest_width = 0; + 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((_handle->image_h == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Image Handle"); + image_util_retvm_if((_handle->image_h->set_resize), IMAGE_UTIL_ERROR_INVALID_OPERATION, "Crop and Resize can't do at the same time"); dest_width = end_x - start_x; dest_height = end_y - start_y; @@ -367,14 +382,12 @@ 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((_image_util_check_resolution(dest_width, dest_height) == false), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid dest resolution"); - err = mm_util_set_crop_area(_handle->image_h, start_x, start_y, end_x, end_y); - image_util_retvm_if((err != MM_UTIL_ERROR_NONE), _image_error_capi(ERR_TYPE_TRANSFORM, err), "Error - Set crop area"); - _handle->start_x = start_x; - _handle->start_y = start_y; - _handle->end_x = end_x; - _handle->end_y = end_y; - _handle->set_crop = true; + _handle->image_h->start_x = start_x; + _handle->image_h->start_y = start_y; + _handle->image_h->dst_width = dest_width; + _handle->image_h->dst_height = dest_height; + _handle->image_h->set_crop = true; return IMAGE_UTIL_ERROR_NONE; } @@ -384,16 +397,13 @@ int image_util_transform_get_colorspace(transformation_h handle, image_util_colo transformation_s *_handle = (transformation_s *) handle; image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((_handle->image_h == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Image Handle"); image_util_retvm_if((colorspace == NULL), IMAGE_UTIL_ERROR_INVALID_OPERATION, "colorspace parameter error"); + image_util_retvm_if((!_handle->image_h->set_convert), IMAGE_UTIL_ERROR_INVALID_OPERATION, "Did not set colorspace before"); - if (!_handle->set_convert) { - image_util_error("Did not set colorspace before"); - return IMAGE_UTIL_ERROR_INVALID_OPERATION; - } + image_util_debug("Get colorspace_convert_info [%d]", _handle->image_h->dst_format); - image_util_debug("Get colorspace_convert_info [%d]", _handle->colorspace); - - *colorspace = _handle->colorspace; + *colorspace = _handle->image_h->dst_format; return IMAGE_UTIL_ERROR_NONE; } @@ -403,17 +413,14 @@ int image_util_transform_get_resolution(transformation_h handle, unsigned int *w transformation_s *_handle = (transformation_s *) handle; image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((_handle->image_h == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Image Handle"); image_util_retvm_if((width == NULL || height == NULL), IMAGE_UTIL_ERROR_INVALID_OPERATION, "width or height parameter error"); + image_util_retvm_if((!_handle->image_h->set_resize), IMAGE_UTIL_ERROR_INVALID_OPERATION, "Did not set resolution before"); - if (!_handle->set_resize) { - image_util_error("Did not set resolution before"); - return IMAGE_UTIL_ERROR_INVALID_OPERATION; - } - - image_util_debug("Get resize_info w[%ui] h[%ui]", _handle->width, _handle->height); + image_util_debug("Get resize_info w[%ui] h[%ui]", _handle->image_h->dst_width, _handle->image_h->dst_height); - *width = _handle->width; - *height = _handle->height; + *width = _handle->image_h->dst_width; + *height = _handle->image_h->dst_height; return IMAGE_UTIL_ERROR_NONE; } @@ -423,16 +430,13 @@ int image_util_transform_get_rotation(transformation_h handle, image_util_rotati transformation_s *_handle = (transformation_s *) handle; image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((_handle->image_h == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Image Handle"); image_util_retvm_if((rotation == NULL), IMAGE_UTIL_ERROR_INVALID_OPERATION, "rotation parameter error"); + image_util_retvm_if((!_handle->image_h->set_rotate), IMAGE_UTIL_ERROR_INVALID_OPERATION, "Did not set rotation before"); - if (!_handle->set_rotate) { - image_util_error("Did not set rotation before"); - return IMAGE_UTIL_ERROR_INVALID_OPERATION; - } + image_util_debug("Get rotate_info [%d]", _handle->image_h->rotation); - image_util_debug("Get rotate_info [%d]", _handle->rotation); - - *rotation = _handle->rotation; + *rotation = _handle->image_h->rotation; return IMAGE_UTIL_ERROR_NONE; } @@ -442,17 +446,14 @@ int image_util_transform_get_crop_area(transformation_h handle, unsigned int *st transformation_s *_handle = (transformation_s *) handle; image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((_handle->image_h == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Image Handle"); 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->image_h->set_crop), IMAGE_UTIL_ERROR_INVALID_OPERATION, "Did not set crop area before"); - if (!_handle->set_crop) { - image_util_error("Did not set crop area before"); - return IMAGE_UTIL_ERROR_INVALID_OPERATION; - } - - *start_x = _handle->start_x; - *start_y = _handle->start_y; - *end_x = _handle->end_x; - *end_y = _handle->end_y; + *start_x = _handle->image_h->start_x; + *start_y = _handle->image_h->start_y; + *end_x = _handle->image_h->start_x + _handle->image_h->dst_width; + *end_y = _handle->image_h->start_x + _handle->image_h->dst_height; return IMAGE_UTIL_ERROR_NONE; } @@ -465,9 +466,10 @@ int image_util_transform_run(transformation_h handle, media_packet_h src, image_ image_util_fenter(); image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((_handle->image_h == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Image Handle"); image_util_retvm_if((completed_cb == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid callback"); image_util_retvm_if((src == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid source"); - image_util_retvm_if((!_handle->set_convert && !_handle->set_resize && !_handle->set_rotate && !_handle->set_crop), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid transform"); + image_util_retvm_if((!_handle->image_h->set_convert && !_handle->image_h->set_resize && !_handle->image_h->set_rotate && !_handle->image_h->set_crop), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid transform"); mm_util_color_image_h color_image = NULL; @@ -495,19 +497,32 @@ int image_util_transform_run(transformation_h handle, media_packet_h src, image_ int image_util_transform_destroy(transformation_h handle) { - int err = MM_UTIL_ERROR_NONE; transformation_s *_handle = (transformation_s *) handle; image_util_fenter(); image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((_handle->image_h == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Image Handle"); + + if (_handle->image_h->thread) { + _handle->image_h->is_finish = TRUE; + g_thread_join(_handle->image_h->thread); + } + + if (_handle->image_h->queue) { + g_async_queue_unref(_handle->image_h->queue); + _handle->image_h->queue = NULL; + } - err = mm_util_destroy(_handle->image_h); + IMAGE_UTIL_SAFE_FREE(_handle->image_h->_util_cb); + IMAGE_UTIL_SAFE_FREE(_handle->image_h); IMAGE_UTIL_SAFE_FREE(_handle->_util_cb); IMAGE_UTIL_SAFE_FREE(_handle); - return _image_error_capi(ERR_TYPE_TRANSFORM, err); + image_util_fleave(); + + return MM_UTIL_ERROR_NONE; } int image_util_calculate_buffer_size(int width, int height, image_util_colorspace_e colorspace, unsigned int *size)