From: hj kim Date: Wed, 7 Feb 2018 04:34:43 +0000 (+0900) Subject: Code refactoring. unify duplicated code X-Git-Tag: submit/tizen/20180212.075159~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=47056f52e2945e6d098efc5aa0f648e47d1d4d11;p=platform%2Fcore%2Fmultimedia%2Flibmm-utility.git Code refactoring. unify duplicated code Change-Id: I64069b9568c59a9bfc306029dd3f10f644e65c31 --- diff --git a/imgp/mm_util_imgp.c b/imgp/mm_util_imgp.c index 081bfe9..32745ee 100755 --- a/imgp/mm_util_imgp.c +++ b/imgp/mm_util_imgp.c @@ -209,9 +209,9 @@ static gboolean __mm_select_resize_plugin(mm_util_img_format _format) return _bool; } -static gboolean __mm_select_rotate_plugin(mm_util_img_format _format, unsigned int width, unsigned int height, mm_util_img_rotate_type angle) +static gboolean __mm_select_rotate_plugin(mm_util_img_format _format) { - mm_util_debug("_format: %d (angle: %d)", _format, angle); + mm_util_debug("_format: %d", _format); if ((_format == MM_UTIL_IMG_FMT_YUV420) || (_format == MM_UTIL_IMG_FMT_I420) || (_format == MM_UTIL_IMG_FMT_NV12) || (_format == MM_UTIL_IMG_FMT_RGB888 || _format == MM_UTIL_IMG_FMT_RGB565)) { @@ -644,41 +644,16 @@ static GModule *__mm_util_imgp_initialize(imgp_plugin_type_e _imgp_plugin_type_e return module; } -static IMGPInfoFunc __mm_util_imgp_process(GModule *module) +static void __mm_util_imgp_finalize(GModule *module, imgp_info_s *_imgp_info_s) { - IMGPInfoFunc mm_util_imgp_func = NULL; - mm_util_fenter(); - - if (module == NULL) { - mm_util_error("module is NULL"); - return NULL; - } - - g_module_symbol(module, IMGP_FUNC_NAME, (gpointer *)&mm_util_imgp_func); - mm_util_debug("mm_util_imgp_func: %p", mm_util_imgp_func); - - return mm_util_imgp_func; -} - -static int __mm_util_imgp_finalize(GModule *module, imgp_info_s *_imgp_info_s) -{ - int ret = MM_UTIL_ERROR_NONE; - - if (module) { - mm_util_debug("module : %p", module); + if (module) g_module_close(module); - mm_util_debug("#End g_module_close#"); - module = NULL; - } else { - mm_util_error("#module is NULL#"); - ret = MM_UTIL_ERROR_INVALID_PARAMETER; - } MMUTIL_SAFE_G_FREE(_imgp_info_s->input_format_label); MMUTIL_SAFE_G_FREE(_imgp_info_s->output_format_label); MMUTIL_SAFE_FREE(_imgp_info_s); - return ret; + return; } static int __mm_util_crop_rgba32(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format, @@ -1354,107 +1329,127 @@ int mm_util_destroy(mm_util_imgp_h imgp_handle) return ret; } -int mm_util_convert_colorspace(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format, unsigned char *dst, mm_util_img_format dst_format) +static IMGPInfoFunc __mm_util_initialize(imgp_type_e function, mm_util_img_format src_format, mm_util_img_format dst_format, GModule **module) { - int ret = MM_UTIL_ERROR_NONE; - unsigned char *output_buffer = NULL; - unsigned int output_buffer_size = 0; + imgp_plugin_type_e _imgp_plugin_type_e = IMGP_GSTCS; + GModule *_module = NULL; + IMGPInfoFunc _func = NULL; - mm_util_fenter(); + if (function == IMGP_CSC) { + if (__mm_select_convert_plugin(src_format, dst_format)) + _imgp_plugin_type_e = IMGP_NEON; - if (!src || !dst) { - mm_util_error("invalid src or dst"); - return MM_UTIL_ERROR_INVALID_PARAMETER; + } else if (function == IMGP_RSZ) { + if (__mm_select_resize_plugin(src_format)) + _imgp_plugin_type_e = IMGP_NEON; + + } else if (function == IMGP_ROT) { + if (__mm_select_rotate_plugin(src_format)) + _imgp_plugin_type_e = IMGP_NEON; + + } else { + mm_util_error("invalid function : [%d]", function); } - if ((src_format < MM_UTIL_IMG_FMT_YUV420) || (src_format > MM_UTIL_IMG_FMT_NUM) || (dst_format < MM_UTIL_IMG_FMT_YUV420) || (dst_format > MM_UTIL_IMG_FMT_NUM)) { - mm_util_error("#ERROR# src_format : [%d] dst_format : [%d] value ", src_format, dst_format); - return MM_UTIL_ERROR_INVALID_PARAMETER; + mm_util_debug("plugin type: %d", _imgp_plugin_type_e); + + _module = __mm_util_imgp_initialize(_imgp_plugin_type_e); + mm_util_debug("__mm_util_imgp_initialize: %p", _module); + + if (_module == NULL) { /* when IMGP_NEON is NULL */ + _imgp_plugin_type_e = IMGP_GSTCS; + mm_util_debug("You use %s module", PATH_GSTCS_LIB); + _module = __mm_util_imgp_initialize(_imgp_plugin_type_e); } - if (__mm_cannot_convert_format(src_format, dst_format)) { - mm_util_error("#ERROR# Cannot Support Image Format Convert"); - return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT; + mm_util_debug("mm_util_imgp_func: %p", _module); + + if (_module == NULL) { + mm_util_error("invalid module"); + return NULL; } - mm_util_debug("(%d x %d)", src_width, src_height); + g_module_symbol(_module, IMGP_FUNC_NAME, (gpointer *)&_func); - imgp_info_s *_imgp_info_s = (imgp_info_s *) calloc(1, sizeof(imgp_info_s)); - if (_imgp_info_s == NULL) { - mm_util_error("ERROR - alloc handle"); - return MM_UTIL_ERROR_OUT_OF_MEMORY; + if (_func == NULL) { + mm_util_error("invalid function"); + g_module_close(_module); + return NULL; } + *module = _module; + + return _func; +} + +int mm_util_convert_colorspace(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format, unsigned char *dst, mm_util_img_format dst_format) +{ + int ret = MM_UTIL_ERROR_NONE; IMGPInfoFunc _mm_util_imgp_func = NULL; GModule *_module = NULL; - imgp_plugin_type_e _imgp_plugin_type_e = 0; + unsigned char *output_buffer = NULL; + unsigned int output_buffer_size = 0; - /* Initialize */ - if (__mm_select_convert_plugin(src_format, dst_format)) - _imgp_plugin_type_e = IMGP_NEON; - else - _imgp_plugin_type_e = IMGP_GSTCS; + mm_util_retvm_if(src == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src"); + mm_util_retvm_if(dst == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst"); + mm_util_retvm_if((src_format < MM_UTIL_IMG_FMT_YUV420) || (src_format >= MM_UTIL_IMG_FMT_NUM), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_format [%d]", src_format); + mm_util_retvm_if((dst_format < MM_UTIL_IMG_FMT_YUV420) || (dst_format >= MM_UTIL_IMG_FMT_NUM), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_format [%d]", dst_format); - mm_util_debug("plugin type: %d", _imgp_plugin_type_e); + if (__mm_cannot_convert_format(src_format, dst_format)) { + mm_util_error("#ERROR# Cannot Support Image Format Convert"); + return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT; + } - _module = __mm_util_imgp_initialize(_imgp_plugin_type_e); - mm_util_debug("__mm_util_imgp_initialize: %p", _module); + mm_util_debug("src_width [%d] src_height [%d] src_format[%d]", src_width, src_height, src_format); - if (_module == NULL) { /* when IMGP_NEON is NULL */ - _imgp_plugin_type_e = IMGP_GSTCS; - mm_util_debug("You use %s module", PATH_GSTCS_LIB); - _module = __mm_util_imgp_initialize(_imgp_plugin_type_e); + _mm_util_imgp_func = __mm_util_initialize(IMGP_CSC, src_format, dst_format, &_module); + if (_mm_util_imgp_func == NULL) { + mm_util_error("ERROR - __mm_util_initialize"); + return MM_UTIL_ERROR_INVALID_OPERATION; + } + + imgp_info_s *_imgp_info_s = (imgp_info_s *) calloc(1, sizeof(imgp_info_s)); + if (_imgp_info_s == NULL) { + mm_util_error("ERROR - alloc handle"); + ret = MM_UTIL_ERROR_OUT_OF_MEMORY; + goto ERROR; } - mm_util_debug("mm_util_imgp_func: %p", _module); ret = __mm_set_imgp_info_s(_imgp_info_s, src_format, src_width, src_height, dst_format, src_width, src_height, MM_UTIL_ROTATE_0); if (ret != MM_UTIL_ERROR_NONE) { mm_util_error("__mm_set_imgp_info_s failed"); - __mm_util_imgp_finalize(_module, _imgp_info_s); - return MM_UTIL_ERROR_INVALID_PARAMETER; + ret = MM_UTIL_ERROR_INVALID_OPERATION; + goto ERROR; } + mm_util_debug("Sucess __mm_set_imgp_info_s"); ret = __mm_util_get_buffer_size(dst_format, src_width, src_height, &output_buffer_size); if (ret != MM_UTIL_ERROR_NONE) { - mm_util_error("__mm_set_imgp_info_s failed"); - __mm_util_imgp_finalize(_module, _imgp_info_s); - return ret; + mm_util_error("__mm_util_get_buffer_size failed"); + goto ERROR; } output_buffer = (unsigned char *) calloc(1, output_buffer_size); if (output_buffer == NULL) { mm_util_error("memory allocation failed"); - __mm_util_imgp_finalize(_module, _imgp_info_s); - return MM_UTIL_ERROR_OUT_OF_MEMORY; + ret = MM_UTIL_ERROR_OUT_OF_MEMORY; + goto ERROR; } mm_util_debug("memory allocation outputbuffer: %p (%d)", output_buffer, output_buffer_size); - /* image processing */ - _mm_util_imgp_func = __mm_util_imgp_process(_module); - mm_util_debug("Sucess __mm_util_imgp_process"); - - if (_mm_util_imgp_func) { - ret = _mm_util_imgp_func(_imgp_info_s, src, output_buffer, IMGP_CSC); - if (ret != MM_UTIL_ERROR_NONE) { - mm_util_error("image processing failed"); - __mm_util_imgp_finalize(_module, _imgp_info_s); - MMUTIL_SAFE_FREE(output_buffer); - return ret; - } - } else { - mm_util_error("g_module_symbol failed"); - __mm_util_imgp_finalize(_module, _imgp_info_s); - MMUTIL_SAFE_FREE(output_buffer); - return MM_UTIL_ERROR_INVALID_PARAMETER; + ret = _mm_util_imgp_func(_imgp_info_s, src, output_buffer, IMGP_CSC); + if (ret != MM_UTIL_ERROR_NONE) { + mm_util_error("image processing failed"); + goto ERROR; } if ((_imgp_info_s->dst_width != _imgp_info_s->output_stride || _imgp_info_s->dst_height != _imgp_info_s->output_elevation) && __mm_is_rgb_format(src_format)) { ret = mm_util_crop_image(output_buffer, _imgp_info_s->output_stride, _imgp_info_s->output_elevation, dst_format, 0, 0, &_imgp_info_s->dst_width, &_imgp_info_s->dst_height, dst); if (ret != MM_UTIL_ERROR_NONE) { - mm_util_error("__mm_util_imgp_finalize failed"); - MMUTIL_SAFE_FREE(output_buffer); - return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT; + mm_util_error("mm_util_crop_image failed"); + ret = MM_UTIL_ERROR_INVALID_OPERATION; + goto ERROR; } } else { memcpy(dst, output_buffer, _imgp_info_s->buffer_size); @@ -1464,13 +1459,9 @@ int mm_util_convert_colorspace(const unsigned char *src, unsigned int src_width, 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); +ERROR: /* Finalize */ - ret = __mm_util_imgp_finalize(_module, _imgp_info_s); - if (ret != MM_UTIL_ERROR_NONE) { - mm_util_error("__mm_util_imgp_finalize failed"); - MMUTIL_SAFE_FREE(output_buffer); - return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT; - } + __mm_util_imgp_finalize(_module, _imgp_info_s); MMUTIL_SAFE_FREE(output_buffer); @@ -1482,66 +1473,40 @@ int mm_util_convert_colorspace(const unsigned char *src, unsigned int src_width, int mm_util_resize_image(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format, unsigned char *dst, unsigned int *dst_width, unsigned int *dst_height) { int ret = MM_UTIL_ERROR_NONE; + IMGPInfoFunc _mm_util_imgp_func = NULL; + GModule *_module = NULL; unsigned char *output_buffer = NULL; unsigned int output_buffer_size = 0; - mm_util_fenter(); + mm_util_retvm_if(src == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src"); + mm_util_retvm_if(src_width == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_width"); + mm_util_retvm_if(src_height == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_height"); + mm_util_retvm_if((src_format < MM_UTIL_IMG_FMT_YUV420) || (src_format >= MM_UTIL_IMG_FMT_NUM), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid 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"); - if (!src || !dst) { - mm_util_error("invalid argument"); - return MM_UTIL_ERROR_INVALID_PARAMETER; - } + mm_util_debug("src_width [%d] src_height [%d] src_format[%d]", src_width, src_height, src_format); - if ((src_format < MM_UTIL_IMG_FMT_YUV420) || (src_format > MM_UTIL_IMG_FMT_NUM)) { - mm_util_error("#ERROR# src_format value "); - return MM_UTIL_ERROR_INVALID_PARAMETER; - } - - if (!dst_width || !dst_height) { - mm_util_error("#ERROR# dst width/height buffer is NULL"); - return MM_UTIL_ERROR_INVALID_PARAMETER; - } - - if (!src_width || !src_height) { - mm_util_error("#ERROR# src_width || src_height valuei is 0 "); - return MM_UTIL_ERROR_INVALID_PARAMETER; + _mm_util_imgp_func = __mm_util_initialize(IMGP_RSZ, src_format, 0, &_module); + if (_mm_util_imgp_func == NULL) { + mm_util_error("ERROR - __mm_util_initialize"); + return MM_UTIL_ERROR_INVALID_OPERATION; } - mm_util_debug("(%d x %d)", src_width, src_height); - imgp_info_s *_imgp_info_s = (imgp_info_s *) calloc(1, sizeof(imgp_info_s)); if (_imgp_info_s == NULL) { mm_util_error("ERROR - alloc handle"); - return MM_UTIL_ERROR_OUT_OF_MEMORY; - } - - IMGPInfoFunc _mm_util_imgp_func = NULL; - GModule *_module = NULL; - imgp_plugin_type_e _imgp_plugin_type_e = 0; - - /* Initialize */ - if (__mm_select_resize_plugin(src_format)) - _imgp_plugin_type_e = IMGP_NEON; - else - _imgp_plugin_type_e = IMGP_GSTCS; - - mm_util_debug("plugin type: %d", _imgp_plugin_type_e); - - _module = __mm_util_imgp_initialize(_imgp_plugin_type_e); - mm_util_debug("__mm_util_imgp_initialize: %p", _module); - /* when IMGP_NEON is NULL */ - if (_module == NULL) { - _imgp_plugin_type_e = IMGP_GSTCS; - mm_util_debug("You use %s module", PATH_GSTCS_LIB); - _module = __mm_util_imgp_initialize(_imgp_plugin_type_e); + ret = MM_UTIL_ERROR_OUT_OF_MEMORY; + 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); if (ret != MM_UTIL_ERROR_NONE) { mm_util_error("__mm_set_imgp_info_s failed [%d]", ret); - __mm_util_imgp_finalize(_module, _imgp_info_s); - return MM_UTIL_ERROR_INVALID_PARAMETER; + ret = MM_UTIL_ERROR_INVALID_OPERATION; + goto ERROR; } mm_util_debug("Sucess __mm_set_imgp_info_s"); @@ -1549,44 +1514,31 @@ int mm_util_resize_image(const unsigned char *src, unsigned int src_width, unsig if (g_strrstr(g_module_name(_module), GST)) { if (__mm_gst_can_resize_format(_imgp_info_s->input_format_label) == FALSE) { mm_util_error("#RESIZE ERROR# IMAGE_NOT_SUPPORT_FORMAT"); - __mm_util_imgp_finalize(_module, _imgp_info_s); - return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT; + ret = MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT; + goto ERROR; } } ret = __mm_util_get_buffer_size(src_format, *dst_width, *dst_height, &output_buffer_size); if (ret != MM_UTIL_ERROR_NONE) { - mm_util_error("__mm_set_imgp_info_s failed"); - __mm_util_imgp_finalize(_module, _imgp_info_s); - return ret; + mm_util_error("__mm_util_get_buffer_size failed"); + goto ERROR; } output_buffer = (unsigned char *) calloc(1, output_buffer_size); if (output_buffer == NULL) { mm_util_error("memory allocation failed"); - __mm_util_imgp_finalize(_module, _imgp_info_s); - return MM_UTIL_ERROR_OUT_OF_MEMORY; + ret = MM_UTIL_ERROR_OUT_OF_MEMORY; + goto ERROR; } mm_util_debug("memory allocation outputbuffer: %p (%d)", output_buffer, output_buffer_size); - /* image processing */ - _mm_util_imgp_func = __mm_util_imgp_process(_module); - mm_util_debug("Sucess __mm_util_imgp_process"); - if (_mm_util_imgp_func) { - ret = _mm_util_imgp_func(_imgp_info_s, src, output_buffer, IMGP_RSZ); - mm_util_debug("_mm_util_imgp_func, ret: %d", ret); - if (ret != MM_UTIL_ERROR_NONE) { - mm_util_error("image processing failed"); - __mm_util_imgp_finalize(_module, _imgp_info_s); - MMUTIL_SAFE_FREE(output_buffer); - return ret; - } - } else { - mm_util_error("g_module_symbol failed"); - __mm_util_imgp_finalize(_module, _imgp_info_s); - MMUTIL_SAFE_FREE(output_buffer); - return MM_UTIL_ERROR_INVALID_PARAMETER; + ret = _mm_util_imgp_func(_imgp_info_s, src, output_buffer, IMGP_RSZ); + mm_util_debug("_mm_util_imgp_func, ret: %d", ret); + if (ret != MM_UTIL_ERROR_NONE) { + mm_util_error("image processing failed"); + goto ERROR; } if ((_imgp_info_s->dst_width != _imgp_info_s->output_stride || _imgp_info_s->dst_height != _imgp_info_s->output_elevation) && __mm_is_rgb_format(src_format)) { @@ -1603,13 +1555,9 @@ int mm_util_resize_image(const unsigned char *src, unsigned int src_width, unsig 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); +ERROR: /* Finalize */ - ret = __mm_util_imgp_finalize(_module, _imgp_info_s); - if (ret != MM_UTIL_ERROR_NONE) { - mm_util_error("__mm_util_imgp_finalize failed"); - MMUTIL_SAFE_FREE(output_buffer); - return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT; - } + __mm_util_imgp_finalize(_module, _imgp_info_s); MMUTIL_SAFE_FREE(output_buffer); @@ -1621,120 +1569,79 @@ int mm_util_resize_image(const unsigned char *src, unsigned int src_width, unsig int mm_util_rotate_image(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format, unsigned char *dst, unsigned int *dst_width, unsigned int *dst_height, mm_util_img_rotate_type angle) { int ret = MM_UTIL_ERROR_NONE; + IMGPInfoFunc _mm_util_imgp_func = NULL; + GModule *_module = NULL; unsigned char *output_buffer = NULL; unsigned int output_buffer_size = 0; - mm_util_fenter(); - - if (!src || !dst) { - mm_util_error("invalid argument"); - return MM_UTIL_ERROR_INVALID_PARAMETER; - } - - if ((src_format < MM_UTIL_IMG_FMT_YUV420) || (src_format > MM_UTIL_IMG_FMT_NUM)) { - mm_util_error("#ERROR# src_format value"); - return MM_UTIL_ERROR_INVALID_PARAMETER; - } - - if (!dst_width || !dst_height) { - mm_util_error("#ERROR# dst width/height buffer is NUL"); - return MM_UTIL_ERROR_INVALID_PARAMETER; - } + mm_util_retvm_if(src == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src"); + mm_util_retvm_if(src_width == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_width"); + mm_util_retvm_if(src_height == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_height"); + mm_util_retvm_if((src_format < MM_UTIL_IMG_FMT_YUV420) || (src_format >= MM_UTIL_IMG_FMT_NUM), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid 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); - if (!src_width || !src_height) { - mm_util_error("#ERROR# src_width || src_height value is 0 "); - return MM_UTIL_ERROR_INVALID_PARAMETER; - } + mm_util_debug("src_width [%d] src_height [%d] src_format[%d]", src_width, src_height, src_format); - if ((angle < MM_UTIL_ROTATE_0) || (angle > MM_UTIL_ROTATE_NUM)) { - mm_util_error("#ERROR# angle vaule"); - return MM_UTIL_ERROR_INVALID_PARAMETER; + _mm_util_imgp_func = __mm_util_initialize(IMGP_ROT, src_format, 0, &_module); + if (_mm_util_imgp_func == NULL) { + mm_util_error("ERROR - __mm_util_initialize"); + return MM_UTIL_ERROR_INVALID_OPERATION; } - mm_util_debug("(%d x %d)", src_width, src_height); - imgp_info_s *_imgp_info_s = (imgp_info_s *) calloc(1, sizeof(imgp_info_s)); if (_imgp_info_s == NULL) { mm_util_error("ERROR - alloc handle"); - return MM_UTIL_ERROR_INVALID_PARAMETER; - } - IMGPInfoFunc _mm_util_imgp_func = NULL; - GModule *_module = NULL; - imgp_plugin_type_e _imgp_plugin_type_e = 0; - - /* Initialize */ - if (__mm_select_rotate_plugin(src_format, src_width, src_height, angle)) - _imgp_plugin_type_e = IMGP_NEON; - else - _imgp_plugin_type_e = IMGP_GSTCS; - - mm_util_debug("plugin type: %d", _imgp_plugin_type_e); - - _module = __mm_util_imgp_initialize(_imgp_plugin_type_e); - mm_util_debug("__mm_util_imgp_initialize: %p", _module); - if (_module == NULL) { /* when IMGP_NEON is NULL */ - _imgp_plugin_type_e = IMGP_GSTCS; - mm_util_debug("You use %s module", PATH_GSTCS_LIB); - _module = __mm_util_imgp_initialize(_imgp_plugin_type_e); + ret = MM_UTIL_ERROR_OUT_OF_MEMORY; + goto ERROR; } mm_util_debug("__mm_confirm_dst_width_height"); 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"); - __mm_util_imgp_finalize(_module, _imgp_info_s); - return MM_UTIL_ERROR_INVALID_PARAMETER; + ret = MM_UTIL_ERROR_INVALID_PARAMETER; + goto ERROR; } ret = __mm_set_imgp_info_s(_imgp_info_s, src_format, src_width, src_height, src_format, *dst_width, *dst_height, angle); mm_util_debug("__mm_set_imgp_info_s"); if (ret != MM_UTIL_ERROR_NONE) { mm_util_error("__mm_set_imgp_info_s failed"); - __mm_util_imgp_finalize(_module, _imgp_info_s); - return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT; + ret = MM_UTIL_ERROR_INVALID_OPERATION; + goto ERROR; } mm_util_debug("Sucess __mm_set_imgp_info_s"); if (g_strrstr(g_module_name(_module), GST)) { if (__mm_gst_can_rotate_format(_imgp_info_s->input_format_label) == FALSE) { mm_util_error("#gstreamer ROTATE ERROR# IMAGE_NOT_SUPPORT_FORMAT"); - __mm_util_imgp_finalize(_module, _imgp_info_s); - return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT; + ret = MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT; + goto ERROR; } } ret = __mm_util_get_buffer_size(src_format, *dst_width, *dst_height, &output_buffer_size); if (ret != MM_UTIL_ERROR_NONE) { - mm_util_error("__mm_set_imgp_info_s failed"); - __mm_util_imgp_finalize(_module, _imgp_info_s); - return ret; + mm_util_error("__mm_util_get_buffer_size failed"); + goto ERROR; } output_buffer = (unsigned char *) calloc(1, output_buffer_size); if (output_buffer == NULL) { mm_util_error("memory allocation failed"); - __mm_util_imgp_finalize(_module, _imgp_info_s); - return MM_UTIL_ERROR_OUT_OF_MEMORY; + ret = MM_UTIL_ERROR_OUT_OF_MEMORY; + goto ERROR; } mm_util_debug("memory allocation outputbuffer: %p (%d)", output_buffer, output_buffer_size); - /* image processing */ - _mm_util_imgp_func = __mm_util_imgp_process(_module); - mm_util_debug("Sucess __mm_util_imgp_process"); - if (_mm_util_imgp_func) { - ret = _mm_util_imgp_func(_imgp_info_s, src, output_buffer, IMGP_ROT); - if (ret != MM_UTIL_ERROR_NONE) { - mm_util_error("image processing failed"); - __mm_util_imgp_finalize(_module, _imgp_info_s); - MMUTIL_SAFE_FREE(output_buffer); - return ret; - } - } else { - mm_util_error("g_module_symbol failed"); - __mm_util_imgp_finalize(_module, _imgp_info_s); - MMUTIL_SAFE_FREE(output_buffer); - return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT; + ret = _mm_util_imgp_func(_imgp_info_s, src, output_buffer, IMGP_ROT); + if (ret != MM_UTIL_ERROR_NONE) { + mm_util_error("image processing failed"); + goto ERROR; } if ((_imgp_info_s->dst_width != _imgp_info_s->output_stride || _imgp_info_s->dst_height != _imgp_info_s->output_elevation) && __mm_is_rgb_format(src_format)) { @@ -1763,13 +1670,9 @@ int mm_util_rotate_image(const unsigned char *src, unsigned int src_width, unsig 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); +ERROR: /* Finalize */ - ret = __mm_util_imgp_finalize(_module, _imgp_info_s); - if (ret != MM_UTIL_ERROR_NONE) { - mm_util_error("__mm_util_imgp_finalize failed"); - MMUTIL_SAFE_FREE(output_buffer); - return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT; - } + __mm_util_imgp_finalize(_module, _imgp_info_s); MMUTIL_SAFE_FREE(output_buffer); @@ -1783,22 +1686,13 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int *crop_dest_wi { int ret = MM_UTIL_ERROR_NONE; - mm_util_fenter(); - - if (!src || !dst) { - mm_util_error("invalid argument"); - return MM_UTIL_ERROR_INVALID_PARAMETER; - } - - if ((src_format < MM_UTIL_IMG_FMT_YUV420) || (src_format > MM_UTIL_IMG_FMT_NUM)) { - mm_util_error("#ERROR# src_format value"); - return MM_UTIL_ERROR_INVALID_PARAMETER; - } - - if ((crop_start_x + *crop_dest_width > src_width) || (crop_start_y + *crop_dest_height > src_height)) { - mm_util_error("#ERROR# dest width | height value"); - return MM_UTIL_ERROR_INVALID_PARAMETER; - } + mm_util_retvm_if(src == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src"); + mm_util_retvm_if(src_width == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_width"); + mm_util_retvm_if(src_height == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_height"); + mm_util_retvm_if((src_format < MM_UTIL_IMG_FMT_YUV420) || (src_format >= MM_UTIL_IMG_FMT_NUM), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_format [%d]", src_format); + mm_util_retvm_if(dst == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst"); + 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); mm_util_debug("[Input] src: [%p] src_width: [%ui] src_height: [%ui] src_format: [%d] crop_start_x: [%ui] crop_start_y: [%ui] crop_dest_width: [%ui] crop_dest_height: [%ui]", src, src_width, src_height, src_format, crop_start_x, crop_start_y, *crop_dest_width, *crop_dest_height); diff --git a/imgp/test/mm_util_imgp_testsuite.c b/imgp/test/mm_util_imgp_testsuite.c index f5d8cae..3b40c81 100755 --- a/imgp/test/mm_util_imgp_testsuite.c +++ b/imgp/test/mm_util_imgp_testsuite.c @@ -102,8 +102,8 @@ int main(int argc, char *argv[]) unsigned char *dst = NULL; if (argc < 12) { - fprintf(stderr, "Usage: %s sync {filename} {command} src_width src_height src_foramt dst_width dst_height dst_format roation crop_start_x crop_start_y \n", argv[0]); - fprintf(stderr, "Usage: %s async {filename} {command} src_width src_height src_foramt dst_width dst_height dst_format roation crop_start_x crop_start_y \n", argv[0]); + fprintf(stderr, "Usage: %s sync {filename} {command} src_width src_height src_foramt dst_width dst_height dst_format rotation crop_start_x crop_start_y \n", argv[0]); + fprintf(stderr, "Usage: %s async {filename} {command} src_width src_height src_foramt dst_width dst_height dst_format rotation crop_start_x crop_start_y \n", argv[0]); fprintf(stderr, "ex: %s sync test.rgb resize 1920 1080 7 1280 720 7 0 0 0 \n", argv[0]); return ret; }