Apply new mm_util_rotate_image() 24/170424/2
authorhj kim <backto.kim@samsung.com>
Tue, 20 Feb 2018 04:27:26 +0000 (13:27 +0900)
committerhj kim <backto.kim@samsung.com>
Tue, 20 Feb 2018 05:41:16 +0000 (05:41 +0000)
Change-Id: I0a46ee409f82946d0e6ea95ae65009b576abedfa

src/image_util_internal.c
test/image_util_test.c

index 771574ac8ed446fbd46375fbd7442964b14535a8..0591bad4bebd2a8dd655a44a820aa75b764f5afb 100755 (executable)
@@ -60,6 +60,10 @@ int image_util_resize(unsigned char *dest, int *dest_width, int *dest_height, co
 int image_util_rotate(unsigned char *dest, int *dest_width, int *dest_height, image_util_rotation_e dest_rotation, const unsigned char *src, int src_width, int src_height, image_util_colorspace_e colorspace)
 {
        int err = MM_UTIL_ERROR_NONE;
+       unsigned int res_w = 0;
+       unsigned int res_h = 0;
+       unsigned char *res_buffer = NULL;
+       size_t res_buffer_size = 0;
 
        image_util_retvm_if((dest == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "dest is null");
        image_util_retvm_if((src == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "src is null");
@@ -67,11 +71,11 @@ int image_util_rotate(unsigned char *dest, int *dest_width, int *dest_height, im
        image_util_retvm_if((dest_rotation < 0 || dest_rotation > IMAGE_UTIL_ROTATION_FLIP_VERT), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid rotation");
        image_util_retvm_if((dest_width == NULL || dest_height == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "dest_width or dest_height is null");
 
-       unsigned int dest_w, dest_h;
-       err = mm_util_rotate_image(src, src_width, src_height, TYPECAST_COLOR(colorspace), dest, &dest_w, &dest_h, dest_rotation);
+       err = mm_util_rotate_image(src, src_width, src_height, TYPECAST_COLOR(colorspace), dest_rotation, &res_buffer, &res_w, &res_h, &res_buffer_size);
        if (err == MM_UTIL_ERROR_NONE) {
-               *dest_width = (int)dest_w;
-               *dest_height = (int)dest_h;
+               memcpy(dest, res_buffer, res_buffer_size);
+               *dest_width = (int)res_w;
+               *dest_height = (int)res_h;
        }
        return _image_error_capi(ERR_TYPE_TRANSFORM, err);
 }
index a5e81c6ca5f5576f5aa6ce474abdfde07e4aaaeb..c593fadfb57e2393f8adee0679b848e2c578ebcf 100755 (executable)
@@ -19,6 +19,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <inttypes.h>
 #include <image_util.h>
 #include <image_util_type.h>
 
@@ -124,7 +125,8 @@ _image_util_mapping_imgp_format_to_mime(image_util_colorspace_e colorspace)
                break;
        }
 
-       g_printf("imgp fmt: %d mimetype fmt: %d", colorspace, mimetype);
+       g_printf("imgp fmt[%d] mimetype fmt[%d]\n", colorspace, mimetype);
+
        return mimetype;
 }
 
@@ -235,7 +237,7 @@ create_media_packet()
                        return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
                }
 
-               g_printf("media_format_set_video_info success! file:%s, w:%d, h:%d, %d\n", g_path, g_width, g_height, _image_util_mapping_imgp_format_to_mime(g_format));
+               g_printf("media_format_set_video_info success! file[%s] w[%d] h[%d] mime[%d]\n", g_path, g_width, g_height, _image_util_mapping_imgp_format_to_mime(g_format));
        } else {
                g_printf("media_format_create failed...");
        }
@@ -244,6 +246,8 @@ create_media_packet()
        if (ret == MEDIA_PACKET_ERROR_NONE) {
                g_printf("Success - media_packet_create_alloc\n");
                uint64_t size = 0;
+               size_t readed = 0;
+
                if (media_packet_get_buffer_size(g_src, &size) == MEDIA_PACKET_ERROR_NONE) {
                        if (media_packet_get_buffer_data_ptr(g_src, &ptr) == MEDIA_PACKET_ERROR_NONE) {
                                FILE *fp = fopen(g_path, "r");
@@ -257,12 +261,13 @@ create_media_packet()
                                        fclose(fp);
                                        return IMAGE_UTIL_ERROR_NO_SUCH_FILE;
                                }
-                               if (fread(src, 1, (size_t)size, fp) == size) {
+                               readed = fread(src, 1, (size_t)size, fp);
+                               if (readed <= size) {
                                        g_printf("#Success# fread\n");
                                        memcpy(ptr, src, (int)size);
                                        g_printf("memcpy\n");
                                } else {
-                                       g_printf("#Error# fread\n");
+                                       g_printf("#Error# fread readed[%zu] size[%" PRIu64 "]\n", readed, size);
                                }
                                fclose(fp);
                                IMAGE_UTIL_SAFE_FREE(src);
@@ -329,18 +334,16 @@ static void _transform(const char *cmd)
        int ret = 0;
        unsigned int width = 0;
        unsigned int height = 0;
-       image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_RGB888;
+       image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_ARGB8888;
        int start_x;
        int start_y;
        int end_x;
        int end_y;
 
        if (!strcmp("convert", cmd)) {
-               colorspace = IMAGE_UTIL_COLORSPACE_I420;
-
                ret = image_util_transform_set_colorspace(g_handle, colorspace);
                if (ret != IMAGE_UTIL_ERROR_NONE) {
-                       g_printf("[%d]error image_util_set colorspace [%d]\n", __LINE__, ret);
+                       g_printf("[%d]error image_util_transform_set_colorspace [%d]\n", __LINE__, ret);
                        return;
                }
        }
@@ -351,7 +354,7 @@ static void _transform(const char *cmd)
 
                ret = image_util_transform_set_resolution(g_handle, width, height);
                if (ret != IMAGE_UTIL_ERROR_NONE) {
-                       g_printf("[%d]Error image_util_set resolution [%d]\n", __LINE__, ret);
+                       g_printf("[%d]Error image_util_transform_set_resolution [%d]\n", __LINE__, ret);
                        return;
                }
        }
@@ -359,7 +362,7 @@ static void _transform(const char *cmd)
        if (!strcmp("rotate", cmd)) {
                ret = image_util_transform_set_rotation(g_handle, g_angle);
                if (ret != IMAGE_UTIL_ERROR_NONE) {
-                       g_printf("[%d]Error image_util_set rotation [%d]\n", __LINE__, ret);
+                       g_printf("[%d]Error image_util_transform_set_rotation [%d]\n", __LINE__, ret);
                        return;
                }
        }
@@ -372,7 +375,7 @@ static void _transform(const char *cmd)
 
                ret = image_util_transform_set_crop_area(g_handle, start_x, start_y, end_x, end_y);
                if (ret != IMAGE_UTIL_ERROR_NONE) {
-                       g_printf("[%d]Error image_util_set colorspace [%d]\n", __LINE__, ret);
+                       g_printf("[%d]Error image_util_transform_set_crop_area [%d]\n", __LINE__, ret);
                        return;
                }
        }
@@ -380,7 +383,7 @@ static void _transform(const char *cmd)
        if (!strcmp("run", cmd)) {
                ret = image_util_transform_run(g_handle, g_src, (image_util_transform_completed_cb)test_transform_completed_cb, NULL);
                if (ret != IMAGE_UTIL_ERROR_NONE) {
-                       g_printf("[%d]Error image_util_transform [%d]\n", __LINE__, ret);
+                       g_printf("[%d]Error image_util_transform_run [%d]\n", __LINE__, ret);
                        return;
                }
                _wait();
@@ -598,6 +601,7 @@ int main(int argc, char **argv)
        g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, NULL);
 
        if (argc < 4) {
+               g_printf("Do: export XDG_RUNTIME_DIR=/run \n");
                g_printf("Usage: image_utl_test filename width height format \n");
                return ret;
        }