Add custom rotation angles in the test suite 93/161493/1
authorMykola Alieksieiev <m.alieksieie@samsung.com>
Thu, 23 Nov 2017 15:17:50 +0000 (17:17 +0200)
committerMykola Alieksieiev <m.alieksieie@samsung.com>
Thu, 23 Nov 2017 15:17:50 +0000 (17:17 +0200)
Change-Id: Ia0eb7e625baefb1f1ebb6d1d8a27826a9d84e293
Signed-off-by: Mykola Alieksieiev <m.alieksieie@samsung.com>
test/image_util_test.c

index 9bd1148..833bd09 100755 (executable)
@@ -35,6 +35,7 @@ media_packet_h g_src = NULL;
 char *g_path = NULL;
 unsigned int g_width = 0;
 unsigned int g_height = 0;
+image_util_rotation_e g_angle = IMAGE_UTIL_ROTATION_NONE;
 int g_format = -1;
 
 GCond g_thread_cond;
@@ -43,6 +44,7 @@ GMutex g_thread_mutex;
 enum {
        CURRENT_STATE_MAIN_MENU,
        CURRENT_STATE_SET_IMAGE_MENU,
+       CURRENT_STATE_SET_ROTATION_PARAMETER_MENU,
 };
 
 enum {
@@ -55,6 +57,7 @@ enum {
 
 int g_menu_state = CURRENT_STATE_MAIN_MENU;
 int g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_NONE;
+int g_menu_rotation_parameter = IMAGE_UTIL_ROTATION_NONE;
 
 void _wait()
 {
@@ -137,7 +140,7 @@ bool test_transform_completed_cb(media_packet_h *packet, image_util_error_e erro
 
        g_printf("test_transform_completed_cb============= [%d] \n", error);
        if (error == IMAGE_UTIL_ERROR_NONE) {
-               g_printf("<<<<< SUCCESS >>>>>");
+               g_printf("<<<<< SUCCESS >>>>>\n");
                output_fmt = (char *)malloc(sizeof(char) * IMAGE_FORMAT_LABEL_BUFFER_SIZE);
                if (output_fmt) {
                        if (media_packet_get_format(*packet, &dst_fmt) != MEDIA_PACKET_ERROR_NONE) {
@@ -178,7 +181,7 @@ bool test_transform_completed_cb(media_packet_h *packet, image_util_error_e erro
                        fclose(fpout);
                }
 
-               g_printf("write result \n");
+               g_printf("Result is written to %s\n", output_file);
                g_printf("Free (output_fmt) \n");
                IMAGE_UTIL_SAFE_FREE(output_fmt);
        } else {
@@ -254,7 +257,7 @@ create_media_packet()
                                        fclose(fp);
                                        return IMAGE_UTIL_ERROR_NO_SUCH_FILE;
                                }
-                               if (fread(src, 1, (int)size, fp) == size) {
+                               if (fread(src, 1, (size_t)size, fp) == size) {
                                        g_printf("#Success# fread\n");
                                        memcpy(ptr, src, (int)size);
                                        g_printf("memcpy\n");
@@ -327,7 +330,6 @@ static void _transform(const char *cmd)
        unsigned int width = 0;
        unsigned int height = 0;
        image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_RGB888;
-       image_util_rotation_e angle;
        int start_x;
        int start_y;
        int end_x;
@@ -355,20 +357,18 @@ static void _transform(const char *cmd)
        }
 
        if (!strcmp("rotate", cmd)) {
-               angle = 1;
-
-               ret = image_util_transform_set_rotation(g_handle, angle);
+               ret = image_util_transform_set_rotation(g_handle, g_angle);
                if (ret != IMAGE_UTIL_ERROR_NONE) {
-                       g_printf("[%d]Error image_util_set colorspace [%d]\n", __LINE__, ret);
+                       g_printf("[%d]Error image_util_set rotation [%d]\n", __LINE__, ret);
                        return;
                }
        }
 
        if (!strcmp("crop", cmd)) {
-               start_x = 500;
-               start_y = 500;
-               end_x = 700;
-               end_y = 700;
+               start_x = g_width/4;
+               start_y = g_height/3;
+               end_x = g_width*3/4;
+               end_y = g_height;
 
                ret = image_util_transform_set_crop_area(g_handle, start_x, start_y, end_x, end_y);
                if (ret != IMAGE_UTIL_ERROR_NONE) {
@@ -410,6 +410,21 @@ void reset_current_menu_state()
        return;
 }
 
+static void display_set_rotation_parameter_menu(void)
+{
+       g_print("\n");
+       g_print("====================================================\n");
+       g_print("    Enter number of rotate operation parameter\n");
+       g_print("----------------------------------------------------\n");
+       g_print("0. None\n");
+       g_print("1. Rotation 90 degrees\n");
+       g_print("2. Rotation 180 degrees\n");
+       g_print("3. Rotation 270 degrees\n");
+       g_print("4. Flip horizontal\n");
+       g_print("5. Flip vertical\n");
+       g_print("====================================================\n");
+}
+
 static void display_set_image_menu(void)
 {
        g_print("\n");
@@ -447,6 +462,17 @@ static void display_menu(void)
 
 }
 
+static void interpret_rotation_parameter_cmd(char *cmd)
+{
+       int choice = atoi(cmd);
+
+       if (choice < IMAGE_UTIL_ROTATION_NONE || choice > IMAGE_UTIL_ROTATION_FLIP_VERT) {
+               g_print("wrong rotation parameter\n");
+               display_set_rotation_parameter_menu();
+       }
+       g_angle = choice;
+}
+
 static void interpret_set_image_cmd(char *cmd)
 {
        int len = strlen(cmd);
@@ -518,7 +544,9 @@ static void interpret_cmd(char *cmd)
                        } else if (!strncmp(cmd, "5", len)) {
                                _transform("resize");
                        } else if (!strncmp(cmd, "6", len)) {
-                               _transform("rotate");
+                               g_menu_state = CURRENT_STATE_SET_ROTATION_PARAMETER_MENU;
+                               display_set_rotation_parameter_menu();
+                               return;
                        } else if (!strncmp(cmd, "7", len)) {
                                _transform("run");
                        } else if (!strncmp(cmd, "8", len)) {
@@ -535,6 +563,11 @@ static void interpret_cmd(char *cmd)
                display_menu();
        } else if (g_menu_state == CURRENT_STATE_SET_IMAGE_MENU) {
                interpret_set_image_cmd(cmd);
+       } else if (g_menu_state == CURRENT_STATE_SET_ROTATION_PARAMETER_MENU) {
+               interpret_rotation_parameter_cmd(cmd);
+               _transform("rotate");
+               reset_current_menu_state();
+               display_menu();
        } else {
                g_print("wrong menu state\n");
        }
@@ -571,13 +604,12 @@ int main(int argc, char **argv)
 
        g_handle = NULL;
        g_src = NULL;
-       g_path = (char *)g_malloc(MAX_STRING_LEN * sizeof(char *));
+       g_path = (char *)g_malloc(MAX_STRING_LEN * sizeof(char));
        if (g_path == NULL) {
                g_printf("memory allocation fail. \n");
                return ret;
        }
 
-       memset(g_path, 0x00, MAX_STRING_LEN);
        snprintf(g_path, MAX_STRING_LEN, "%s", argv[1]);
        g_width = atoi(argv[2]);
        g_height = atoi(argv[3]);