Remove Ecore evas dependency
[platform/core/multimedia/libmedia-thumbnail.git] / test / test-thumb.c
1 /*
2  * libmedia-thumbnail
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <pthread.h>
26 #include <mm_util_imgp.h>
27 #include <mm_util_jpeg.h>
28
29 #include "media-thumbnail.h"
30 #include "media-thumbnail-private.h"
31 #include "media-thumb-debug.h"
32 #include "media-thumb-ipc.h"
33 #include "media-thumb-util.h"
34
35 int save_to_file_with_gdk(unsigned char *data, int w, int h, int is_bgra)
36 {
37         GError *error = NULL;
38         
39         gdk_pixbuf_save(data,"/mnt/nfs/test.jpg","jpeg", &error, NULL);
40         if (error) {
41                 thumb_dbg ("Error saving image file /mnt/nfs/test.jpg ");
42                 g_error_free (error);
43                 return -1;
44         }
45         return 0;
46 }
47
48 int main(int argc, char *argv[])
49 {
50         int mode;
51         int err = -1;
52         const char *origin_path = NULL;
53
54         if ((argc != 3) && (argc != 4)) {
55                 printf("Usage: %s [test mode number] [path]\n", argv[0]);
56                 return -1;
57         }
58
59         mode = atoi(argv[1]);
60         origin_path = argv[2];
61
62         if (origin_path && (mode == 1)) {
63                 printf("Test _thumbnail_get_data\n");
64
65                 GdkPixbuf *data = NULL;
66                 int thumb_size = 0;
67                 int thumb_w = 0;
68                 int thumb_h = 0;
69                 int origin_w = 0;
70                 int origin_h = 0;
71                 int alpha = FALSE;
72
73                 media_thumb_type thumb_type = MEDIA_THUMB_LARGE;
74                 //media_thumb_type thumb_type = MEDIA_THUMB_SMALL;
75                 media_thumb_format thumb_format = MEDIA_THUMB_BGRA;
76                 //media_thumb_format thumb_format = MEDIA_THUMB_RGB888;
77                 int is_bgra = 1;
78                 //int is_bgra = 0;
79
80                 long start = thumb_get_debug_time();
81
82                 err = _thumbnail_get_data(origin_path, thumb_type, thumb_format, &data, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h, &alpha, tzplatform_getuid(TZ_USER_NAME));
83                 if (err < 0) {
84                         printf("_thumbnail_get_data failed - %d\n", err);
85                         return -1;
86                 }
87         
88                 printf("Size : %d, W:%d, H:%d\n", thumb_size, thumb_w, thumb_h);        
89                 printf("Origin W:%d, Origin H:%d\n", origin_w, origin_h);
90
91                 err = save_to_file_with_gdk(data, thumb_w, thumb_h, is_bgra);
92                 if (err < 0) {
93                         printf("_thumbnail_get_data failed - %d\n", err);
94                         return -1;
95                 } else {
96                         printf("file save success\n");
97                 }
98
99                 SAFE_FREE(data);
100
101                 long end = thumb_get_debug_time();
102                 printf("Time : %f\n", ((double)(end - start) / (double)CLOCKS_PER_SEC));
103
104         } else if (mode == 2) {
105                 printf("Test thumbnail_request_from_db\n");
106                 //const char *origin_path = "/opt/media/test/movie1.mp4";
107                 //const char *origin_path = "/opt/media/test/high.jpg";
108                 //const char *origin_path = "/opt/media/test/movie2.avi";
109                 char thumb_path[MAX_PATH_SIZE + 1];
110
111                 err = thumbnail_request_from_db(origin_path, thumb_path, sizeof(thumb_path), tzplatform_getuid(TZ_USER_NAME));
112                 if (err < 0) {
113                         printf("thumbnail_request_from_db failed : %d\n", err);
114                         return -1;
115                 }
116
117                 printf("Success!! (%s)\n", thumb_path);
118         } else if (mode == 3) {
119                 printf("Test thumbnail_request_save_to_file\n");
120                 const char *thumb_path = NULL;
121
122                 if (argv[3]) {
123                 thumb_path = argv[3];
124                 } else {
125                         printf("3 mode requires target path of thumbnail\n");
126                         return -1;
127                 }
128
129                 err = thumbnail_request_save_to_file(origin_path, MEDIA_THUMB_LARGE, thumb_path, tzplatform_getuid(TZ_USER_NAME));
130                 if (err < 0) {
131                         printf("thumbnail_request_save_to_file failed : %d\n", err);
132                         return -1;
133                 }
134
135                 printf("Success!!\n");
136         } else if (origin_path && mode == 4) {
137                 printf("Test thumbnail_generate_hash_code\n");
138                 char hash[255] = {0,};
139
140                 err = thumbnail_generate_hash_code(origin_path, hash, sizeof(hash));
141                 if (err < 0) {
142                         printf("thumbnail_generate_hash_code failed : %d\n", err);
143                         return -1;
144                 } else {
145                         printf("Hash : %s\n", hash);
146                 }
147
148                 printf("Success!!\n");
149         } else if (mode == 5) {
150                 printf("Test thumbnail_request_extract_all_thumbs\n");
151
152                 err = thumbnail_request_extract_all_thumbs(tzplatform_getuid(TZ_USER_NAME));
153                 if (err < 0) {
154                         printf("thumbnail_request_extract_all_thumbs failed : %d\n", err);
155                         return -1;
156                 } else {
157                         printf("thumbnail_request_extract_all_thumbs success!\n");
158                 }
159         } else if (mode == 6) {
160                 printf("Test thumbnail_request_cancel_media\n");
161
162                 err = thumbnail_request_cancel_media(origin_path,tzplatform_getuid(TZ_USER_NAME));
163                 if (err < 0) {
164                         printf("thumbnail_request_cancel_media failed : %d\n", err);
165                         return -1;
166                 } else {
167                         printf("thumbnail_request_cancel_media success!\n");
168                 }
169         } else if (mode == 7) {
170                 printf("Test thumbnail_request_cancel_all\n");
171
172                 err = thumbnail_request_cancel_all();
173                 if (err < 0) {
174                         printf("thumbnail_request_cancel_all failed : %d\n", err);
175                         return -1;
176                 } else {
177                         printf("thumbnail_request_cancel_all success!\n");
178                 }
179         }
180
181         thumb_dbg("Test is Completed");
182
183         return 0;
184 }
185