return IMAGE_UTIL_ERROR_NONE;
}
-static void __mm_destroy_temp_buffer(unsigned char *buffer[])
-{
- int i = 0;
-
- for (i = 0; i < 4; i++)
- IMAGE_UTIL_SAFE_FREE(buffer[i]);
-}
-
-static int __mm_util_transform(transformation_s *handle)
+static int __mm_util_transform(transformation_s *operation, mm_util_image_h origin, mm_util_image_h *transform)
{
int ret = IMAGE_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 src_size = 0;
- size_t res_buffer_size = 0;
-
- image_util_retvm_if(handle == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "invalid handle");
-
- image_util_debug("src: %p, dst: %p", handle->src, handle->dst);
-
- ret = mm_image_get_image(handle->src, &src_width, &src_height, &src_format, &dst_buf[src_index], &src_size);
- image_util_retvm_if(ret != MM_UTIL_ERROR_NONE, _image_error_capi(ret), "mm_image_get_image failed");
-
- 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);
- image_util_error("mm_util_crop_image failed");
- return _image_error_capi(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);
- image_util_error("mm_util_resize_image failed");
- return _image_error_capi(ret);
- }
-
- dst_buf[dst_index] = res_buffer;
- src_index = dst_index;
- src_width = res_w;
- src_height = res_h;
- }
+ mm_util_image_h _src = origin;
+ mm_util_image_h _dst = NULL;
- if (handle->set_convert) {
- dst_index++;
+ image_util_retvm_if(!operation, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid operation");
+ image_util_retvm_if(!mm_image_is_valid_image(origin), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid origin");
+ image_util_retvm_if(!transform, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid transform");
- 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);
- image_util_error("mm_util_convert_colorspace failed");
- return _image_error_capi(ret);
- }
+ image_util_fenter();
- 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 (operation->set_crop) {
+ ret = mm_util_crop_image(_src, operation->x, operation->y, operation->width, operation->height, &_dst);
+ image_util_retvm_if(ret != MM_UTIL_ERROR_NONE, _image_error_capi(ret), "mm_util_crop_image failed");
+ _src = _dst;
+ } else if (operation->set_resize) {
+ ret = mm_util_resize_image(_src, operation->width, operation->height, &_dst);
+ image_util_retvm_if(ret != MM_UTIL_ERROR_NONE, _image_error_capi(ret), "mm_util_resize_image failed");
+ _src = _dst;
}
- 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);
- image_util_error("mm_util_rotate_image failed");
- return _image_error_capi(ret);
- }
-
- dst_buf[dst_index] = res_buffer_rotate;
- src_index = dst_index;
- src_width = res_w;
- src_height = res_h;
+ if (operation->set_convert) {
+ ret = mm_util_convert_colorspace(_src, operation->color, &_dst);
+ if (origin != _src)
+ mm_image_destroy_image(_src);
+ image_util_retvm_if(ret != MM_UTIL_ERROR_NONE, _image_error_capi(ret), "mm_util_convert_colorspace failed");
+ _src = _dst;
}
- if (dst_buf[dst_index] != NULL && res_buffer_size != 0) {
- ret = mm_image_create_image(src_width, src_height, src_format, dst_buf[dst_index], res_buffer_size, &(handle->dst));
- if (ret != IMAGE_UTIL_ERROR_NONE)
- image_util_error("mm_image_create_image failed");
- } else {
- image_util_error("invalid result %p %zu", dst_buf[dst_index], res_buffer_size);
- ret = IMAGE_UTIL_ERROR_INVALID_OPERATION;
+ if (operation->set_rotate) {
+ ret = mm_util_rotate_image(_src, operation->rotation, &_dst);
+ if (origin != _src)
+ mm_image_destroy_image(_src);
+ image_util_retvm_if(ret != MM_UTIL_ERROR_NONE, _image_error_capi(ret), "mm_util_rotate_image failed");
}
- __mm_destroy_temp_buffer(dst_buf);
- image_util_error("mm_util_processing was finished");
+ *transform = _dst;
+
+ image_util_fleave();
return ret;
}
{
transformation_s *handle = (transformation_s *) data;
int ret = IMAGE_UTIL_ERROR_NONE;
- mm_util_image_h pop_data = NULL;
+ mm_util_image_h origin_image = NULL;
+ mm_util_image_h transformed_image = NULL;
media_packet_h packet = NULL;
image_util_retvm_if(handle == NULL, NULL, "invalid handle");
while (!handle->is_finish) {
image_util_debug("waiting...");
- pop_data = g_async_queue_timeout_pop(handle->queue, 300 * G_TIME_SPAN_MILLISECOND);
+ origin_image = g_async_queue_timeout_pop(handle->queue, 300 * G_TIME_SPAN_MILLISECOND);
image_util_debug("get from data or timeout");
- if (pop_data == NULL) {
+ if (origin_image == NULL) {
image_util_error("The data is null");
continue;
}
- handle->src = pop_data;
- handle->dst = NULL;
-
- mm_image_debug_image(handle->src, "Origin");
+ mm_image_debug_image(origin_image, "Origin");
- ret = __mm_util_transform(handle);
+ ret = __mm_util_transform(handle, origin_image, &transformed_image);
if (ret == IMAGE_UTIL_ERROR_NONE) {
- mm_image_debug_image(handle->dst, "Result");
+ mm_image_debug_image(transformed_image, "Transformed");
image_util_debug("Success - transform");
} else {
image_util_error("Error - transform");
if ((handle->_util_cb != NULL) && (handle->_util_cb->completed_cb != NULL)) {
image_util_debug("completed_cb is called");
- ret = __image_util_image_to_packet(handle->dst, &packet);
+ ret = __image_util_image_to_packet(transformed_image, &packet);
if (ret != IMAGE_UTIL_ERROR_NONE) {
image_util_error("__image_util_image_to_packet failed (%d)", ret);
handle->_util_cb->completed_cb(NULL, ret, handle->_util_cb->user_data);
} else {
image_util_error("There is no callback");
}
- mm_image_destroy_image(pop_data);
- mm_image_destroy_image(handle->dst);
+ mm_image_destroy_image(origin_image);
+ mm_image_destroy_image(transformed_image);
}
image_util_debug("exit thread");
image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
/* private values init */
- _handle->dst = NULL;
- _handle->dst_format = MM_UTIL_COLOR_NUM;
+ _handle->color = 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->x = 0;
+ _handle->y = 0;
+ _handle->width = 0;
+ _handle->height = 0;
_handle->is_finish = FALSE;
_handle->set_convert = FALSE;
image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
- _handle->dst_format = colorspace;
+ _handle->color = colorspace;
_handle->set_convert = true;
return IMAGE_UTIL_ERROR_NONE;
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((width == 0 || height == 0), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid resolution w : [%d] h : [%d]", width, height);
- _handle->dst_width = width;
- _handle->dst_height = height;
+ _handle->width = width;
+ _handle->height = height;
_handle->set_resize = true;
return IMAGE_UTIL_ERROR_NONE;
int image_util_transform_set_crop_area(transformation_h handle, unsigned int start_x, unsigned int start_y, unsigned int end_x, unsigned int end_y)
{
transformation_s *_handle = (transformation_s *) handle;
- int dest_width = 0;
- int dest_height = 0;
+ unsigned int dest_width = 0;
+ unsigned int dest_height = 0;
image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
image_util_retvm_if((_handle->set_resize), IMAGE_UTIL_ERROR_INVALID_OPERATION, "Crop and Resize can't do at the same time");
+ image_util_retvm_if((start_x >= end_x), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid position start_x : [%d] end_x : [%d]", start_x, end_x);
+ image_util_retvm_if((start_y >= end_y), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid position start_y : [%d] end_y : [%d]", start_y, end_y);
dest_width = end_x - start_x;
dest_height = end_y - start_y;
image_util_debug("Set crop_info x[%d] y[%d] w[%d] h[%d]", start_x, start_y, dest_width, dest_height);
image_util_retvm_if((dest_width <= 0 || dest_height <= 0), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid resolution w : [%d] h : [%d]", dest_width, dest_height);
- _handle->start_x = start_x;
- _handle->start_y = start_y;
- _handle->dst_width = dest_width;
- _handle->dst_height = dest_height;
+ _handle->x = start_x;
+ _handle->y = start_y;
+ _handle->width = dest_width;
+ _handle->height = dest_height;
_handle->set_crop = true;
return IMAGE_UTIL_ERROR_NONE;
image_util_retvm_if((colorspace == NULL), IMAGE_UTIL_ERROR_INVALID_OPERATION, "colorspace parameter error");
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->dst_format);
+ image_util_debug("Get colorspace_convert_info [%d]", _handle->color);
- *colorspace = _handle->dst_format;
+ *colorspace = _handle->color;
return IMAGE_UTIL_ERROR_NONE;
}
image_util_retvm_if((width == NULL || height == NULL), IMAGE_UTIL_ERROR_INVALID_OPERATION, "width or height parameter error");
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->dst_width, _handle->dst_height);
+ image_util_debug("Get resize_info w[%ui] h[%ui]", _handle->width, _handle->height);
- *width = _handle->dst_width;
- *height = _handle->dst_height;
+ *width = _handle->width;
+ *height = _handle->height;
return IMAGE_UTIL_ERROR_NONE;
}
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->set_crop), IMAGE_UTIL_ERROR_INVALID_OPERATION, "Did not set crop area before");
- *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;
+ *start_x = _handle->x;
+ *start_y = _handle->y;
+ *end_x = _handle->x + _handle->width;
+ *end_y = _handle->y + _handle->height;
return IMAGE_UTIL_ERROR_NONE;
}