#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)
{
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;
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;