Check input parameter
[platform/core/api/image-util.git] / src / image_util.c
index cce4efa..510f251 100755 (executable)
@@ -158,30 +158,6 @@ static int __mm_util_create_color_image(mm_image_info_s **image, unsigned long w
        return ret;
 }
 
-static int __mm_util_get_color_image(mm_image_info_s *image, unsigned long *width, unsigned long *height, mm_util_color_format_e *color, void **data, size_t *size)
-{
-       int ret = IMAGE_UTIL_ERROR_NONE;
-
-       image_util_retvm_if((image == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid handle");
-
-       if (width != NULL)
-               *width = image->width;
-
-       if (height != NULL)
-               *height = image->height;
-
-       if (color != NULL)
-               *color = image->color;
-
-       if (data != NULL)
-               *data = image->data;
-
-       if (size != NULL)
-               *size = image->size;
-
-       return ret;
-}
-
 static void __mm_destroy_temp_buffer(unsigned char *buffer[])
 {
        int i = 0;
@@ -190,7 +166,7 @@ static void __mm_destroy_temp_buffer(unsigned char *buffer[])
                IMAGE_UTIL_SAFE_FREE(buffer[i]);
 }
 
-static int __mm_util_processing(mm_util_s *handle)
+static int __mm_util_transform(transformation_s *handle)
 {
        int ret = IMAGE_UTIL_ERROR_NONE;
        unsigned char *dst_buf[4] = {NULL,};
@@ -225,7 +201,7 @@ static int __mm_util_processing(mm_util_s *handle)
                if (ret != MM_UTIL_ERROR_NONE) {
                        __mm_destroy_temp_buffer(dst_buf);
                        image_util_error("mm_util_crop_image failed");
-                       return _image_error_capi(ERR_TYPE_TRANSFORM, ret);
+                       return _image_error_capi(ret);
                }
 
                dst_buf[dst_index] = res_buffer;
@@ -239,7 +215,7 @@ static int __mm_util_processing(mm_util_s *handle)
                if (ret != MM_UTIL_ERROR_NONE) {
                        __mm_destroy_temp_buffer(dst_buf);
                        image_util_error("mm_util_resize_image failed");
-                       return _image_error_capi(ERR_TYPE_TRANSFORM, ret);
+                       return _image_error_capi(ret);
                }
 
                dst_buf[dst_index] = res_buffer;
@@ -255,7 +231,7 @@ static int __mm_util_processing(mm_util_s *handle)
                if (ret != MM_UTIL_ERROR_NONE) {
                        __mm_destroy_temp_buffer(dst_buf);
                        image_util_error("mm_util_convert_colorspace failed");
-                       return _image_error_capi(ERR_TYPE_TRANSFORM, ret);
+                       return _image_error_capi(ret);
                }
 
                dst_buf[dst_index] = res_buffer_conv;
@@ -272,7 +248,7 @@ static int __mm_util_processing(mm_util_s *handle)
                if (ret != MM_UTIL_ERROR_NONE) {
                        __mm_destroy_temp_buffer(dst_buf);
                        image_util_error("mm_util_rotate_image failed");
-                       return _image_error_capi(ERR_TYPE_TRANSFORM, ret);
+                       return _image_error_capi(ret);
                }
 
                dst_buf[dst_index] = res_buffer_rotate;
@@ -296,26 +272,6 @@ static int __mm_util_processing(mm_util_s *handle)
        return ret;
 }
 
-static int __mm_util_transform_exec(mm_util_s *handle, mm_image_info_s *source_image)
-{
-       int ret = IMAGE_UTIL_ERROR_NONE;
-
-       image_util_retvm_if(handle == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "invalid handle");
-       image_util_retvm_if(source_image == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "invalid source_image");
-
-       image_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);
-       image_util_retvm_if(ret != IMAGE_UTIL_ERROR_NONE, ret, "__mm_util_processing failed [%d]", ret);
-
-       image_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;
-}
-
 static int __image_util_image_to_packet(mm_image_info_s *image, media_packet_h *packet)
 {
        int err = IMAGE_UTIL_ERROR_NONE;
@@ -330,8 +286,13 @@ static int __image_util_image_to_packet(mm_image_info_s *image, media_packet_h *
 
        image_util_fenter();
 
-       err = __mm_util_get_color_image(image, &width, &height, &format, &buffer, &buffer_size);
-       image_util_retvm_if((err != IMAGE_UTIL_ERROR_NONE), err, "__mm_util_get_color_image failed (%d)", err);
+       image_util_retvm_if((image == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid handle");
+
+       width = image->width;
+       height = image->height;
+       format = image->color;
+       buffer = image->data;
+       buffer_size = image->size;
 
        err = __create_media_format(__image_format_to_mimetype(format), (unsigned int)width, (unsigned int)height, &fmt);
        image_util_retvm_if((err != IMAGE_UTIL_ERROR_NONE), err, "__create_media_format failed (%d)", err);
@@ -387,7 +348,7 @@ static int __image_util_image_to_packet(mm_image_info_s *image, media_packet_h *
 
 gpointer __mm_util_thread_repeate(gpointer data)
 {
-       mm_util_s *handle = (mm_util_s *) data;
+       transformation_s *handle = (transformation_s *) data;
        int ret = IMAGE_UTIL_ERROR_NONE;
        mm_image_info_s *pop_data = NULL;
        media_packet_h packet = NULL;
@@ -404,11 +365,19 @@ gpointer __mm_util_thread_repeate(gpointer data)
                        continue;
                }
 
-               ret = __mm_util_transform_exec(handle, (mm_image_info_s *)pop_data); /* Need to block */
+               handle->src = pop_data;
+               handle->dst = NULL;
+
+               image_util_debug("orig_image: %p [%zu] %lu X %lu (%u)", pop_data->data, pop_data->size, pop_data->width, pop_data->height, pop_data->color);
+
+               ret = __mm_util_transform(handle);
+
+               image_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);
+
                if (ret == IMAGE_UTIL_ERROR_NONE)
-                       image_util_debug("Success - transform_exec");
+                       image_util_debug("Success - transform");
                else
-                       image_util_error("Error - transform_exec");
+                       image_util_error("Error - transform");
 
                if ((handle->_util_cb != NULL) && (handle->_util_cb->completed_cb != NULL)) {
                        image_util_debug("completed_cb is called");
@@ -424,7 +393,6 @@ gpointer __mm_util_thread_repeate(gpointer data)
                }
                __mm_util_destroy_color_image(pop_data);
                __mm_util_destroy_color_image(handle->dst);
-               handle->is_completed = FALSE;
        }
 
        image_util_debug("exit thread");
@@ -433,51 +401,6 @@ gpointer __mm_util_thread_repeate(gpointer data)
        return NULL;
 }
 
-static int __mm_util_create_thread(mm_util_s *handle)
-{
-       int ret = IMAGE_UTIL_ERROR_NONE;
-
-       image_util_retvm_if(handle == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "invalid handle");
-       image_util_retvm_if(handle->thread != NULL, IMAGE_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);
-       image_util_retvm_if(handle->thread == NULL, IMAGE_UTIL_ERROR_INVALID_OPERATION, "ERROR - create thread");
-
-       image_util_debug("New thread is created");
-
-       return ret;
-}
-
-static int __mm_util_transform(mm_util_imgp_h imgp_handle, mm_image_info_s *image)
-{
-       int ret = IMAGE_UTIL_ERROR_NONE;
-       mm_util_s *handle = (mm_util_s *) imgp_handle;
-
-       image_util_fenter();
-
-       image_util_retvm_if(handle == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "invalid handle");
-       image_util_retvm_if(image == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "invalid image");
-
-       image_util_debug("image: %p", image);
-
-       if (handle->queue) {
-               image_util_debug("g_async_queue_push");
-               g_async_queue_push(handle->queue, GINT_TO_POINTER(image));
-               ret = __mm_util_create_thread(handle);
-               if (ret != IMAGE_UTIL_ERROR_NONE) {
-                       image_util_error("ERROR - Create thread");
-                       return ret;
-               } else {
-                       image_util_debug("Success -__mm_util_create_thread");
-               }
-       }
-
-       image_util_fleave();
-
-       return ret;
-}
-
 static int _image_util_packet_to_image(media_packet_h packet, mm_image_info_s **color_image)
 {
        int err = IMAGE_UTIL_ERROR_NONE;
@@ -519,14 +442,13 @@ static int _image_util_packet_to_image(media_packet_h packet, mm_image_info_s **
        return IMAGE_UTIL_ERROR_NONE;
 }
 
-static int _image_util_create_transform_handle(transformation_s *handle)
+int image_util_transform_create(transformation_h * handle)
 {
-       int ret = IMAGE_UTIL_ERROR_NONE;
-       mm_util_s *_handle = NULL;
+       image_util_fenter();
 
-       image_util_retvm_if((handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "invalid handle");
+       image_util_retvm_if((handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
 
-       _handle = calloc(1, sizeof(mm_util_s));
+       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");
 
        /* private values init */
@@ -538,7 +460,6 @@ static int _image_util_create_transform_handle(transformation_s *handle)
        _handle->start_y = -1;
        _handle->dst_width = 0;
        _handle->dst_height = 0;
-       _handle->is_completed = FALSE;
        _handle->is_finish = FALSE;
 
        _handle->set_convert = FALSE;
@@ -556,31 +477,6 @@ static int _image_util_create_transform_handle(transformation_s *handle)
                return IMAGE_UTIL_ERROR_INVALID_OPERATION;
        }
 
-       handle->image_h = _handle;
-
-       return ret;
-}
-
-int image_util_transform_create(transformation_h * handle)
-{
-       int err = IMAGE_UTIL_ERROR_NONE;
-
-       image_util_fenter();
-
-       image_util_retvm_if((handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid 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->image_h = NULL;
-
-       err = _image_util_create_transform_handle(_handle);
-       if (err != IMAGE_UTIL_ERROR_NONE) {
-               image_util_error("Error - create transform handle");
-               IMAGE_UTIL_SAFE_FREE(_handle);
-               return IMAGE_UTIL_ERROR_INVALID_OPERATION;
-       }
-
        *handle = (transformation_h) _handle;
 
        return IMAGE_UTIL_ERROR_NONE;
@@ -610,10 +506,10 @@ int image_util_transform_set_colorspace(transformation_h handle, image_util_colo
        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");
+       image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
 
-       _handle->image_h->dst_format = colorspace;
-       _handle->image_h->set_convert = true;
+       _handle->dst_format = colorspace;
+       _handle->set_convert = true;
 
        return IMAGE_UTIL_ERROR_NONE;
 }
@@ -625,13 +521,12 @@ int image_util_transform_set_resolution(transformation_h handle, unsigned int wi
        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->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((_handle->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");
 
-       _handle->image_h->dst_width = width;
-       _handle->image_h->dst_height = height;
-       _handle->image_h->set_resize = true;
+       _handle->dst_width = width;
+       _handle->dst_height = height;
+       _handle->set_resize = true;
 
        return IMAGE_UTIL_ERROR_NONE;
 }
@@ -643,10 +538,9 @@ int image_util_transform_set_rotation(transformation_h handle, image_util_rotati
        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");
 
-       _handle->image_h->rotation = rotation;
-       _handle->image_h->set_rotate = true;
+       _handle->rotation = rotation;
+       _handle->set_rotate = true;
 
        return IMAGE_UTIL_ERROR_NONE;
 }
@@ -658,8 +552,7 @@ int image_util_transform_set_crop_area(transformation_h handle, unsigned int sta
        int dest_height = 0;
 
        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((_handle->image_h->set_resize), IMAGE_UTIL_ERROR_INVALID_OPERATION, "Crop and Resize can't do at the same time");
+       image_util_retvm_if((_handle->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;
@@ -668,11 +561,11 @@ int image_util_transform_set_crop_area(transformation_h handle, unsigned int sta
 
        image_util_retvm_if((_image_util_check_resolution(dest_width, dest_height) == false), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid dest resolution");
 
-       _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;
+       _handle->start_x = start_x;
+       _handle->start_y = start_y;
+       _handle->dst_width = dest_width;
+       _handle->dst_height = dest_height;
+       _handle->set_crop = true;
 
        return IMAGE_UTIL_ERROR_NONE;
 }
@@ -682,13 +575,12 @@ 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");
+       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->image_h->dst_format);
+       image_util_debug("Get colorspace_convert_info [%d]", _handle->dst_format);
 
-       *colorspace = _handle->image_h->dst_format;
+       *colorspace = _handle->dst_format;
 
        return IMAGE_UTIL_ERROR_NONE;
 }
@@ -698,14 +590,13 @@ 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");
+       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->image_h->dst_width, _handle->image_h->dst_height);
+       image_util_debug("Get resize_info w[%ui] h[%ui]", _handle->dst_width, _handle->dst_height);
 
-       *width = _handle->image_h->dst_width;
-       *height = _handle->image_h->dst_height;
+       *width = _handle->dst_width;
+       *height = _handle->dst_height;
 
        return IMAGE_UTIL_ERROR_NONE;
 }
@@ -715,13 +606,12 @@ 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");
+       image_util_retvm_if((!_handle->set_rotate), IMAGE_UTIL_ERROR_INVALID_OPERATION, "Did not set rotation before");
 
-       image_util_debug("Get rotate_info [%d]", _handle->image_h->rotation);
+       image_util_debug("Get rotate_info [%d]", _handle->rotation);
 
-       *rotation = _handle->image_h->rotation;
+       *rotation = _handle->rotation;
 
        return IMAGE_UTIL_ERROR_NONE;
 }
@@ -731,14 +621,13 @@ 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");
+       image_util_retvm_if((!_handle->set_crop), IMAGE_UTIL_ERROR_INVALID_OPERATION, "Did not set crop area before");
 
-       *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;
+       *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;
 
        return IMAGE_UTIL_ERROR_NONE;
 }
@@ -752,29 +641,41 @@ 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->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");
+       image_util_retvm_if((_handle->queue == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid queue");
+       image_util_retvm_if((!_handle->set_convert && !_handle->set_resize && !_handle->set_rotate && !_handle->set_crop), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid transform");
 
        err = _image_util_packet_to_image(src, &color_image);
        image_util_retvm_if((err != IMAGE_UTIL_ERROR_NONE), err, "_image_util_packet_to_image failed");
 
-       _handle->image_h->_util_cb = (image_util_cb_s *) calloc(1, sizeof(image_util_cb_s));
-       if (_handle->image_h->_util_cb == NULL) {
+       IMAGE_UTIL_SAFE_FREE(_handle->_util_cb);
+
+       _handle->_util_cb = (image_util_cb_s *) calloc(1, sizeof(image_util_cb_s));
+       if (_handle->_util_cb == NULL) {
                image_util_error("Memory allocation failed");
                __mm_util_destroy_color_image(color_image);
                return IMAGE_UTIL_ERROR_OUT_OF_MEMORY;
        }
 
-       _handle->image_h->_util_cb->user_data = user_data;
-       _handle->image_h->_util_cb->completed_cb = completed_cb;
+       _handle->_util_cb->user_data = user_data;
+       _handle->_util_cb->completed_cb = completed_cb;
 
-       err = __mm_util_transform(_handle->image_h, color_image);
-       if (err != IMAGE_UTIL_ERROR_NONE) {
-               image_util_error("Error - Run transform (%d)", err);
-               __mm_util_destroy_color_image(color_image);
-               return err;
+       image_util_debug("g_async_queue_push");
+       g_async_queue_push(_handle->queue, GINT_TO_POINTER(color_image));
+
+       if (!_handle->thread) {
+               /*create threads*/
+               _handle->thread = g_thread_new("transform_thread", (GThreadFunc)__mm_util_thread_repeate, (gpointer)_handle);
+               if (_handle->thread == NULL) {
+                       image_util_error("Fail - Create thread");
+                       __mm_util_destroy_color_image(color_image);
+                       return IMAGE_UTIL_ERROR_INVALID_OPERATION;
+               } else {
+                       image_util_debug("Success - Create thread");
+               }
+       } else {
+               image_util_debug("Thread alreay exist");
        }
 
        return IMAGE_UTIL_ERROR_NONE;
@@ -787,21 +688,18 @@ int image_util_transform_destroy(transformation_h 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->thread) {
+               _handle->is_finish = TRUE;
+               g_thread_join(_handle->thread);
        }
 
-       if (_handle->image_h->queue) {
-               g_async_queue_unref(_handle->image_h->queue);
-               _handle->image_h->queue = NULL;
+       if (_handle->queue) {
+               g_async_queue_unref(_handle->queue);
+               _handle->queue = NULL;
        }
 
-       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);
 
        image_util_fleave();
@@ -822,7 +720,7 @@ int image_util_calculate_buffer_size(int width, int height, image_util_colorspac
 
        *size = (unsigned int)size_ptr;
 
-       return _image_error_capi(ERR_TYPE_COMMON, err);
+       return _image_error_capi(err);
 }
 
 int image_util_extract_color_from_memory(const unsigned char *image_buffer, int width, int height, unsigned char *rgb_r, unsigned char *rgb_g, unsigned char *rgb_b)
@@ -860,7 +758,7 @@ int image_util_extract_color_from_memory(const unsigned char *image_buffer, int
                module = NULL;
        }
 
-       return _image_error_capi(ERR_TYPE_COMMON, ret);
+       return _image_error_capi(ret);
 }
 
 int image_util_foreach_supported_colorspace(image_util_type_e image_type, image_util_supported_colorspace_cb callback, void *user_data)