#include <gmodule.h>
#include <inttypes.h>
#include <mm_util_imgp.h>
+#include <mm_util_image.h>
#include <image_util.h>
#include <image_util_private.h>
return IMAGE_UTIL_ERROR_NONE;
}
-static void __mm_util_destroy_color_image(mm_image_info_s *image)
-{
- image_util_retm_if((image == NULL), "Invalid handle");
-
- IMAGE_UTIL_SAFE_FREE(image->data);
- IMAGE_UTIL_SAFE_FREE(image);
-}
-
-static int __mm_util_create_color_image(mm_image_info_s **image, unsigned int width, unsigned int height, mm_util_color_format_e color, void *data, size_t size)
-{
- int ret = IMAGE_UTIL_ERROR_NONE;
- mm_image_info_s *_color_image = NULL;
-
- image_util_retvm_if((image == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid handle");
- image_util_retvm_if((color >= MM_UTIL_COLOR_NUM), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid color");
- image_util_retvm_if((data == NULL || size == 0), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid data");
-
- _color_image = (mm_image_info_s *)calloc(1, sizeof(mm_image_info_s));
- image_util_retvm_if((_color_image == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "Memory allocation failed");
-
- _color_image->data = calloc(1, size);
- if (_color_image->data == NULL) {
- image_util_error("Memory allocation failed");
- __mm_util_destroy_color_image(_color_image);
- *image = NULL;
- return IMAGE_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;
-
- image_util_debug("w [%u], h [%u], color [%u], size [%zu], data [%p]", _color_image->width, _color_image->height, _color_image->color, _color_image->size, _color_image->data);
-
- *image = _color_image;
-
- return ret;
-}
-
static void __mm_destroy_temp_buffer(unsigned char *buffer[])
{
int i = 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);
- dst_buf[src_index] = calloc(1, handle->src->size);
- src_width = handle->src->width;
- src_height = handle->src->height;
- src_format = handle->src->color;
-
- image_util_retvm_if(dst_buf[src_index] == NULL, IMAGE_UTIL_ERROR_INVALID_OPERATION, "[multi func] memory allocation error");
-
- memcpy(dst_buf[src_index], handle->src->data, handle->src->size);
+ 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++;
}
if (dst_buf[dst_index] != NULL && res_buffer_size != 0) {
- ret = __mm_util_create_color_image(&(handle->dst), src_width, src_height, src_format, (void *)dst_buf[dst_index], res_buffer_size);
+ 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_util_create_color_image failed");
+ 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;
int err = IMAGE_UTIL_ERROR_NONE;
mm_util_color_format_e format = 0;
unsigned int width = 0, height = 0;
- void *buffer = NULL;
+ unsigned char *buffer = NULL;
size_t buffer_size = 0;
media_format_h fmt = NULL;
void *packet_ptr = NULL;
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 = mm_image_get_image((mm_util_image_h)image, &width, &height, &format, &buffer, &buffer_size);
+ image_util_retvm_if((err != MM_UTIL_ERROR_NONE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "mm_image_get_image failed");
- 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);
+ err = __create_media_format(__image_format_to_mimetype(format), width, height, &fmt);
+ if (err != IMAGE_UTIL_ERROR_NONE) {
+ image_util_error("__create_media_format failed (%d)", err);
+ IMAGE_UTIL_SAFE_FREE(buffer);
+ return IMAGE_UTIL_ERROR_INVALID_OPERATION;
+ }
err = media_packet_create_alloc(fmt, NULL, NULL, packet);
if (err != MEDIA_PACKET_ERROR_NONE) {
image_util_error("media_packet_create_alloc failed (%d)", err);
media_format_unref(fmt);
+ IMAGE_UTIL_SAFE_FREE(buffer);
return IMAGE_UTIL_ERROR_INVALID_OPERATION;
}
if (err != MEDIA_PACKET_ERROR_NONE) {
image_util_error("media_packet_get_buffer_size failed (%d)", err);
media_packet_destroy(*packet);
+ IMAGE_UTIL_SAFE_FREE(buffer);
return IMAGE_UTIL_ERROR_INVALID_OPERATION;
}
if (err != MEDIA_PACKET_ERROR_NONE) {
image_util_error("media_packet_get_buffer_data_ptr failed");
media_packet_destroy(*packet);
+ IMAGE_UTIL_SAFE_FREE(buffer);
return IMAGE_UTIL_ERROR_INVALID_OPERATION;
}
if (packet_ptr == NULL || packet_size == 0) {
image_util_error("media_packet creation failed (%p, %" PRIu64 ")", packet_ptr, packet_size);
media_packet_destroy(*packet);
+ IMAGE_UTIL_SAFE_FREE(buffer);
return IMAGE_UTIL_ERROR_INVALID_OPERATION;
}
image_util_debug("Success - media_packet is created (%p, %" PRIu64 ")", packet_ptr, packet_size);
image_util_debug("Size: result(%zu) media_packet(%" PRIu64 ") copied(%zu)", buffer_size, packet_size, size);
memcpy(packet_ptr, buffer, size);
+ IMAGE_UTIL_SAFE_FREE(buffer);
err = media_packet_set_buffer_size(*packet, (uint64_t)size);
if (err != MEDIA_PACKET_ERROR_NONE) {
{
transformation_s *handle = (transformation_s *) data;
int ret = IMAGE_UTIL_ERROR_NONE;
- mm_image_info_s *pop_data = NULL;
+ mm_util_image_h pop_data = NULL;
media_packet_h packet = NULL;
image_util_retvm_if(handle == NULL, NULL, "invalid handle");
handle->src = pop_data;
handle->dst = NULL;
- image_util_debug("orig_image: %p [%zu] %u X %u (%u)", pop_data->data, pop_data->size, pop_data->width, pop_data->height, pop_data->color);
+ mm_image_debug_image(handle->src, "Origin");
ret = __mm_util_transform(handle);
-
- if (handle->dst != NULL)
- image_util_debug("result_image: %p [%zu] %u X %u (%u)", handle->dst->data, handle->dst->size, handle->dst->width, handle->dst->height, handle->dst->color);
- else
- image_util_error("Error - handle->dst is NULL");
-
- if (ret == IMAGE_UTIL_ERROR_NONE)
+ if (ret == IMAGE_UTIL_ERROR_NONE) {
+ mm_image_debug_image(handle->dst, "Result");
image_util_debug("Success - transform");
- else
+ } else {
image_util_error("Error - transform");
+ }
if ((handle->_util_cb != NULL) && (handle->_util_cb->completed_cb != NULL)) {
image_util_debug("completed_cb is called");
} else {
image_util_error("There is no callback");
}
- __mm_util_destroy_color_image(pop_data);
- __mm_util_destroy_color_image(handle->dst);
+ mm_image_destroy_image(pop_data);
+ mm_image_destroy_image(handle->dst);
}
image_util_debug("exit thread");
return NULL;
}
-static int _image_util_packet_to_image(media_packet_h packet, mm_image_info_s **color_image)
+static int _image_util_packet_to_image(media_packet_h packet, mm_util_image_h *color_image)
{
int err = IMAGE_UTIL_ERROR_NONE;
media_format_mimetype_e mimetype = 0;
}
image_util_debug("[Fotmat: %u] W x H : %d x %d", mimetype, width, height);
- image_util_retvm_if(((width == 0) || (height == 0) || (size == 0) || (ptr == NULL)), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid source packet");
+ image_util_retvm_if(((width <= 0) || (height <= 0) || (size == 0) || (ptr == NULL)), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid source packet");
- err = __mm_util_create_color_image(color_image, (unsigned int)width, (unsigned int)height, __mimetype_to_image_format(mimetype), ptr, (size_t)size);
- image_util_retvm_if((err != IMAGE_UTIL_ERROR_NONE), err, "__mm_util_create_color_image failed (%d)", err);
+ err = mm_image_create_image(width, height, __mimetype_to_image_format(mimetype), ptr, (size_t)size, color_image);
+ image_util_retvm_if((err != IMAGE_UTIL_ERROR_NONE), err, "mm_image_create_image failed (%d)", err);
image_util_debug("_image_util_packet_to_image succeed");
{
int err = IMAGE_UTIL_ERROR_NONE;
transformation_s *_handle = (transformation_s *) handle;
- mm_image_info_s *color_image = NULL;
+ mm_util_image_h color_image = NULL;
image_util_fenter();
_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);
+ mm_image_destroy_image(color_image);
return IMAGE_UTIL_ERROR_OUT_OF_MEMORY;
}
_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);
+ mm_image_destroy_image(color_image);
return IMAGE_UTIL_ERROR_INVALID_OPERATION;
} else {
image_util_debug("Success - Create thread");