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;
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,};
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;
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;
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;
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;
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;
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);
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;
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");
}
__mm_util_destroy_color_image(pop_data);
__mm_util_destroy_color_image(handle->dst);
- handle->is_completed = FALSE;
}
image_util_debug("exit thread");
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;
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 */
_handle->start_y = -1;
_handle->dst_width = 0;
_handle->dst_height = 0;
- _handle->is_completed = FALSE;
_handle->is_finish = FALSE;
_handle->set_convert = FALSE;
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;
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;
}
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;
}
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;
}
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;
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;
}
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;
}
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;
}
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;
}
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;
}
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;
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();
*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)
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)