Modify image transforms to use unified image handle 58/201058/4
authorjiyong.min <jiyong.min@samsung.com>
Fri, 8 Mar 2019 00:23:35 +0000 (09:23 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Fri, 8 Mar 2019 04:33:20 +0000 (13:33 +0900)
Change-Id: I561da87ac4619ec0b0b9968dd66c231b2ee79ad2

include/image_util_private.h
packaging/capi-media-image-util.spec
src/image_util.c

index 92af3d6..eee2a04 100755 (executable)
@@ -96,8 +96,8 @@ typedef struct {
 } image_util_cb_s;
 
 typedef struct {
-       mm_image_info_s *src;
-       mm_image_info_s *dst;
+       mm_util_image_h src;
+       mm_util_image_h dst;
 
        /* for converting colorspace */
        mm_util_color_format_e dst_format;
index f767fdc..3c7e11f 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       capi-media-image-util
 Summary:    A Image Utility library in Tizen Native API
-Version:    0.1.46
+Version:    0.1.47
 Release:    2
 Group:      Multimedia/API
 License:    Apache-2.0
index 64889c7..8ca58c8 100644 (file)
@@ -17,6 +17,7 @@
 #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>
@@ -112,48 +113,6 @@ static int __create_media_format(media_format_mimetype_e mimetype, unsigned int
        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;
@@ -174,20 +133,15 @@ static int __mm_util_transform(transformation_s *handle)
        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++;
@@ -253,9 +207,9 @@ static int __mm_util_transform(transformation_s *handle)
        }
 
        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;
@@ -272,7 +226,7 @@ static int __image_util_image_to_packet(mm_image_info_s *image, media_packet_h *
        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;
@@ -283,19 +237,21 @@ static int __image_util_image_to_packet(mm_image_info_s *image, media_packet_h *
 
        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;
        }
 
@@ -303,6 +259,7 @@ static int __image_util_image_to_packet(mm_image_info_s *image, media_packet_h *
        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;
        }
 
@@ -310,12 +267,14 @@ static int __image_util_image_to_packet(mm_image_info_s *image, media_packet_h *
        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);
@@ -328,6 +287,7 @@ static int __image_util_image_to_packet(mm_image_info_s *image, media_packet_h *
 
        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) {
@@ -345,7 +305,7 @@ gpointer __mm_util_thread_repeate(gpointer data)
 {
        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");
@@ -363,19 +323,15 @@ gpointer __mm_util_thread_repeate(gpointer data)
                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");
@@ -389,8 +345,8 @@ gpointer __mm_util_thread_repeate(gpointer data)
                } 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");
@@ -399,7 +355,7 @@ gpointer __mm_util_thread_repeate(gpointer data)
        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;
@@ -430,10 +386,10 @@ static int _image_util_packet_to_image(media_packet_h packet, mm_image_info_s **
        }
 
        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");
 
@@ -633,7 +589,7 @@ int image_util_transform_run(transformation_h handle, media_packet_h src, image_
 {
        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();
 
@@ -651,7 +607,7 @@ int image_util_transform_run(transformation_h handle, media_packet_h src, image_
        _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;
        }
 
@@ -666,7 +622,7 @@ int image_util_transform_run(transformation_h handle, media_packet_h src, image_
                _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");