From 77c34422559e6301888391a32adc5fbef2141a6b Mon Sep 17 00:00:00 2001 From: hj kim Date: Mon, 8 Oct 2018 16:35:58 +0900 Subject: [PATCH] Move transform code to CAPI except gstreamer related code Change-Id: I50651b5fdec61a37c310cbe70359a83f4eabf3ca --- common/include/mm_util_color_image.h | 40 ---- common/mm_util_color_image.c | 73 ------- imgp/mm_util_imgp.c | 396 ----------------------------------- 3 files changed, 509 deletions(-) diff --git a/common/include/mm_util_color_image.h b/common/include/mm_util_color_image.h index 1687420..2d3e6eb 100755 --- a/common/include/mm_util_color_image.h +++ b/common/include/mm_util_color_image.h @@ -32,46 +32,6 @@ extern "C" { gboolean mm_util_is_valid_color_format(mm_util_color_format_e color); -/** - * - * @remark Creates the handle of color image with data - * - * @param image [in/out] The handle of the color image - * @param width [in] The width of color image - * @param height [in] The height of color image - * @param color [in] The color format of color image - * @param data [in] The data of color image - * @param size [in] The data-size of color image - * @return This function returns created color image handle - * if the result is 0, then handle creation succeed - * else if the result is -1, then handle creation failed - */ -int mm_util_create_color_image(mm_util_color_image_h *image, unsigned long width, unsigned long height, mm_util_color_format_e color, void *data, size_t size); - -/** - * - * @remark Gets the data of color image from handle - * - * @param image [in] The handle of the color image - * @param width [in/out] The width of color image - * @param height [in/out] The height of color image - * @param color [in/out] The color format of color image - * @param data [in/out] The data of color image - * @param size [in/out] The data-size of color image - * @return This function returns the result of getting the data from handle - * if the result is 0, then getting the data has succeed - * else if the result is -1, then getting the data has failed - */ -int mm_util_get_color_image(mm_util_color_image_h image, unsigned long *width, unsigned long *height, mm_util_color_format_e *color, void **data, size_t *size); - -/** - * - * @remark Destroys the handle of color image - * - * @param image [in] The handle of the color image - */ -void mm_util_destroy_color_image(mm_util_color_image_h image); - #ifdef __cplusplus } diff --git a/common/mm_util_color_image.c b/common/mm_util_color_image.c index 5d6b18f..fa60b06 100755 --- a/common/mm_util_color_image.c +++ b/common/mm_util_color_image.c @@ -29,76 +29,3 @@ gboolean mm_util_is_valid_color_format(mm_util_color_format_e color) } return TRUE; } - -int mm_util_create_color_image(mm_util_color_image_h *image, unsigned long width, unsigned long height, mm_util_color_format_e color, void *data, size_t size) -{ - int ret = MM_UTIL_ERROR_NONE; - mm_image_info_s *_color_image = NULL; - - mm_util_retvm_if((image == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid handle"); - mm_util_retvm_if((color >= MM_UTIL_COLOR_NUM), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid color"); - mm_util_retvm_if((data == NULL || size == 0), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid data"); - - _color_image = (mm_image_info_s *)calloc(1, sizeof(mm_image_info_s)); - mm_util_retvm_if((_color_image == NULL), MM_UTIL_ERROR_OUT_OF_MEMORY, "Memory allocation failed"); - - _color_image->data = calloc(1, size); - if (_color_image->data == NULL) { - mm_util_error("Memory allocation failed"); - mm_util_destroy_color_image(_color_image); - *image = NULL; - return MM_UTIL_ERROR_OUT_OF_MEMORY; - } - - memcpy(_color_image->data, data, size); - - _color_image->size = size; - _color_image->width = width; - _color_image->height = height; - _color_image->color = color; - - mm_util_sec_debug("w [%lu], h [%lu], color [%u], size [%zu], data [%p]", _color_image->width, _color_image->height, _color_image->color, _color_image->size, _color_image->data); - - *image = (mm_util_color_image_h)_color_image; - - return ret; -} - -int mm_util_get_color_image(mm_util_color_image_h image, unsigned long *width, unsigned long *height, mm_util_color_format_e *color, void **data, size_t *size) -{ - int ret = MM_UTIL_ERROR_NONE; - mm_image_info_s *_color_image = (mm_image_info_s *)image; - - mm_util_retvm_if((_color_image == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid handle"); - - if (width != NULL) - *width = _color_image->width; - - if (height != NULL) - *height = _color_image->height; - - if (color != NULL) - *color = _color_image->color; - - if (data != NULL) - *data = _color_image->data; - - if (size != NULL) - *size = _color_image->size; - - return ret; -} - - -void mm_util_destroy_color_image(mm_util_color_image_h image) -{ - mm_image_info_s *_color_image = (mm_image_info_s *)image; - - if (_color_image == NULL) { - mm_util_error("[ERROR] - image"); - return; - } - - MMUTIL_SAFE_FREE(_color_image->data); - MMUTIL_SAFE_FREE(_color_image); -} diff --git a/imgp/mm_util_imgp.c b/imgp/mm_util_imgp.c index 031c3da..41d0cd4 100755 --- a/imgp/mm_util_imgp.c +++ b/imgp/mm_util_imgp.c @@ -32,7 +32,6 @@ #define GST "gstcs" typedef gboolean(*IMGPInfoFunc) (imgp_info_s *, const unsigned char *, unsigned char **, imgp_plugin_type_e); -static int __mm_util_transform_exec(mm_util_s *handle, mm_image_info_s *source_image); static int check_valid_picture_size(int width, int height) { @@ -43,14 +42,6 @@ static int check_valid_picture_size(int width, int height) return MM_UTIL_ERROR_INVALID_PARAMETER; } -static void __mm_destroy_temp_buffer(unsigned char *buffer[]) -{ - int i = 0; - - for (i = 0; i < 4; i++) - MMUTIL_SAFE_FREE(buffer[i]); -} - static gboolean __mm_gst_can_resize_format(mm_util_color_format_e color_format) { gboolean _bool = FALSE; @@ -426,393 +417,6 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_wid return ret; } -#if 0 -static int __mm_util_handle_init(mm_util_s *handle) -{ - int ret = MM_UTIL_ERROR_NONE; - - mm_util_retvm_if(handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle"); - - /* 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) { - mm_util_error("g_async_queue_new failed"); - return MM_UTIL_ERROR_INVALID_OPERATION; - } - - return ret; -} -#endif - -gpointer _mm_util_thread_repeate(gpointer data) -{ - mm_util_s *handle = (mm_util_s *) data; - int ret = MM_UTIL_ERROR_NONE; - mm_util_color_image_h pop_data = NULL; - - mm_util_retvm_if(handle == NULL, NULL, "invalid handle"); - - while (!handle->is_finish) { - mm_util_debug("waiting..."); - pop_data = (mm_util_color_image_h)g_async_queue_timeout_pop(handle->queue, 300 * G_TIME_SPAN_MILLISECOND); - mm_util_debug("get from data or timeout"); - - if (pop_data == NULL) { - mm_util_error("The data is null"); - continue; - } - - ret = __mm_util_transform_exec(handle, (mm_image_info_s *)pop_data); /* Need to block */ - if (ret == MM_UTIL_ERROR_NONE) - mm_util_debug("Success - transform_exec"); - else - mm_util_error("Error - transform_exec"); - - if (handle->_util_cb->completed_cb) { - mm_util_debug("completed_cb is called"); - handle->_util_cb->completed_cb(handle->dst, ret, handle->_util_cb->user_data); - } - mm_util_destroy_color_image(pop_data); - mm_util_destroy_color_image(handle->dst); - handle->is_completed = FALSE; - } - - mm_util_debug("exit thread"); - handle->thread = NULL; - - return NULL; -} - -static int __mm_util_create_thread(mm_util_s *handle) -{ - int ret = MM_UTIL_ERROR_NONE; - - mm_util_retvm_if(handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle"); - mm_util_retvm_if(handle->thread != NULL, MM_UTIL_ERROR_NONE, "[NO-ERROR] Thread is already created"); - - /*create threads*/ - handle->thread = g_thread_new("transform_thread", (GThreadFunc)_mm_util_thread_repeate, (gpointer)handle); - mm_util_retvm_if(handle->thread == NULL, MM_UTIL_ERROR_INVALID_OPERATION, "ERROR - create thread"); - - mm_util_debug("New thread is created"); - - return ret; -} - -static int __mm_util_processing(mm_util_s *handle) -{ - int ret = MM_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 res_buffer_size = 0; - - mm_util_retvm_if(handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle"); - - mm_util_debug("src: %p, dst: %p", handle->src, handle->dst); - - dst_buf[src_index] = calloc(1, handle->src->size); - src_width = handle->src->width; - src_height = handle->src->height; - src_format = handle->src->color; - if (dst_buf[src_index] == NULL) { - mm_util_error("[multi func] memory allocation error"); - return MM_UTIL_ERROR_INVALID_OPERATION; - } - memcpy(dst_buf[src_index], handle->src->data, handle->src->size); - - 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); - mm_util_error("mm_util_crop_image failed"); - return 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); - mm_util_error("mm_util_resize_image failed"); - return ret; - } - - dst_buf[dst_index] = res_buffer; - src_index = dst_index; - src_width = res_w; - src_height = res_h; - } - - if (handle->set_convert) { - dst_index++; - - 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); - mm_util_error("mm_util_convert_colorspace failed"); - return ret; - } - - 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 (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); - mm_util_error("mm_util_rotate_image failed"); - return ret; - } - - dst_buf[dst_index] = res_buffer_rotate; - src_index = dst_index; - src_width = res_w; - src_height = res_h; - } - - if (dst_buf[dst_index] != NULL && res_buffer_size != 0) { - ret = mm_util_create_color_image((mm_util_color_image_h *)&(handle->dst), (unsigned long)src_width, (unsigned long)src_height, src_format, (void *)dst_buf[dst_index], res_buffer_size); - if (ret != MM_UTIL_ERROR_NONE) - mm_util_error("mm_util_create_color_image failed"); - } else { - mm_util_error("invalid result %p %zu", dst_buf[dst_index], res_buffer_size); - ret = MM_UTIL_ERROR_INVALID_OPERATION; - } - __mm_destroy_temp_buffer(dst_buf); - - mm_util_error("mm_util_processing was finished"); - - return ret; -} - -static int __mm_util_transform_exec(mm_util_s *handle, mm_image_info_s *source_image) -{ - int ret = MM_UTIL_ERROR_NONE; - - mm_util_retvm_if(handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle"); - mm_util_retvm_if(source_image == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid source_image"); - - mm_util_debug("orig_image: %p [%zu] %lu X %lu (%u)", source_image->data, source_image->size, - source_image->width, source_image->height, source_image->color); - - handle->src = source_image; - handle->dst = NULL; - - ret = __mm_util_processing(handle); - mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "__mm_util_processing failed [%d]", ret); - - mm_util_debug("result_image: %p [%zu] %lu X %lu (%u)", handle->dst->data, handle->dst->size, - handle->dst->width, handle->dst->height, handle->dst->color); - - return ret; -} - -#if 0 -static int -_mm_util_handle_finalize(mm_util_s *handle) -{ - int ret = MM_UTIL_ERROR_NONE; - - mm_util_retvm_if(handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle"); - - /* g_thread_exit(handle->thread); */ - if (handle->thread) { - handle->is_finish = TRUE; - g_thread_join(handle->thread); - } - - if (handle->queue) { - g_async_queue_unref(handle->queue); - handle->queue = NULL; - } - - mm_util_debug("Success - Finalize Handle"); - - return ret; -} - -int mm_util_create(mm_util_imgp_h *imgp_handle) -{ - int ret = MM_UTIL_ERROR_NONE; - - mm_util_retvm_if(imgp_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid imgp_handle"); - - mm_util_s *handle = calloc(1, sizeof(mm_util_s)); - if (!handle) { - mm_util_error("[ERROR] - _handle"); - return MM_UTIL_ERROR_INVALID_OPERATION; - } - - ret = __mm_util_handle_init(handle); - if (ret != MM_UTIL_ERROR_NONE) { - mm_util_error("_mm_util_handle_init failed"); - MMUTIL_SAFE_FREE(handle); - return ret; - } - - *imgp_handle = (mm_util_imgp_h)handle; - - return ret; -} - -int mm_util_set_colorspace_convert(mm_util_imgp_h imgp_handle, mm_util_color_format_e colorspace) -{ - int ret = MM_UTIL_ERROR_NONE; - mm_util_s *handle = (mm_util_s *) imgp_handle; - - mm_util_retvm_if(handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle"); - - handle->set_convert = TRUE; - handle->dst_format = colorspace; - mm_util_debug("imgp fmt: %d", handle->dst_format); - - return ret; -} - -int mm_util_set_resolution(mm_util_imgp_h imgp_handle, unsigned int width, unsigned int height) -{ - int ret = MM_UTIL_ERROR_NONE; - mm_util_s *handle = (mm_util_s *) imgp_handle; - - mm_util_retvm_if(handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle"); - - handle->set_resize = TRUE; - handle->dst_width = width; - handle->dst_height = height; - - return ret; -} - -int mm_util_set_rotation(mm_util_imgp_h imgp_handle, mm_util_img_rotate_type rotation) -{ - int ret = MM_UTIL_ERROR_NONE; - mm_util_s *handle = (mm_util_s *) imgp_handle; - - mm_util_retvm_if(handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle"); - - handle->set_rotate = TRUE; - handle->rotation = rotation; - - return ret; -} - -int mm_util_set_crop_area(mm_util_imgp_h imgp_handle, unsigned int start_x, unsigned int start_y, unsigned int end_x, unsigned int end_y) -{ - int ret = MM_UTIL_ERROR_NONE; - mm_util_s *handle = (mm_util_s *) imgp_handle; - - unsigned int dest_width = end_x - start_x; - unsigned int dest_height = end_y - start_y; - - mm_util_retvm_if(handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle"); - - handle->set_crop = TRUE; - handle->start_x = start_x; - handle->start_y = start_y; - handle->dst_width = dest_width; - handle->dst_height = dest_height; - - return ret; -} -#endif - -int mm_util_transform(mm_util_imgp_h imgp_handle, mm_util_color_image_h image, mm_util_completed_callback completed_callback, void *user_data) -{ - int ret = MM_UTIL_ERROR_NONE; - mm_util_s *handle = (mm_util_s *) imgp_handle; - - mm_util_fenter(); - - mm_util_retvm_if(handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle"); - mm_util_retvm_if(image == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid image"); - mm_util_retvm_if(completed_callback == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid completed_callback"); - - mm_util_debug("image: %p", image); - - MMUTIL_SAFE_FREE(handle->_util_cb); - handle->_util_cb = (mm_util_cb_s *)calloc(1, sizeof(mm_util_cb_s)); - if (handle->_util_cb) { - handle->_util_cb->completed_cb = completed_callback; - handle->_util_cb->user_data = user_data; - } else { - mm_util_error("[ERROR] _util_cb_s"); - } - - if (handle->queue) { - mm_util_debug("g_async_queue_push"); - g_async_queue_push(handle->queue, GINT_TO_POINTER(image)); - ret = __mm_util_create_thread(handle); - if (ret != MM_UTIL_ERROR_NONE) { - mm_util_error("ERROR - Create thread"); - return ret; - } else { - mm_util_debug("Success -__mm_util_create_thread"); - } - } - - mm_util_fleave(); - - return ret; -} - -#if 0 -int mm_util_destroy(mm_util_imgp_h imgp_handle) -{ - int ret = MM_UTIL_ERROR_NONE; - mm_util_s *handle = (mm_util_s *) imgp_handle; - - mm_util_fenter(); - - mm_util_retvm_if(handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle"); - mm_util_retvm_if(_mm_util_handle_finalize(handle) != MM_UTIL_ERROR_NONE, MM_UTIL_ERROR_INVALID_PARAMETER, "fail _mm_util_handle_finalize"); - - MMUTIL_SAFE_FREE(handle->_util_cb); - MMUTIL_SAFE_FREE(handle); - - mm_util_fleave(); - - return ret; -} -#endif static IMGPInfoFunc __mm_util_initialize(imgp_type_e function, mm_util_color_format_e src_format, mm_util_color_format_e dst_format, GModule **module) { imgp_plugin_type_e _imgp_plugin_type_e = IMGP_GSTCS; -- 2.7.4