9fd53082d2f8aa03567bc8c2b93251ec90c13d1a
[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 <Evas.h>
27 #include <Ecore_Evas.h>
28 #include <mm_util_imgp.h>
29 #include <mm_util_jpeg.h>
30
31 #include "media-thumbnail.h"
32 #include "media-thumbnail-private.h"
33 #include "media-thumb-debug.h"
34 #include "media-thumb-ipc.h"
35 #include "media-thumb-util.h"
36
37 int save_to_file_with_evas(unsigned char *data, int w, int h, int is_bgra)
38 {
39         ecore_evas_init();
40         
41         Ecore_Evas *ee =
42                 ecore_evas_buffer_new(w, h);
43         Evas *evas = ecore_evas_get(ee);
44
45         Evas_Object *img = NULL;
46         img = evas_object_image_add(evas);
47
48         if (img == NULL) {
49                 printf("image object is NULL\n");
50                 ecore_evas_free(ee);
51                 ecore_evas_shutdown();
52                 return -1;
53         }
54
55         evas_object_image_colorspace_set(img, EVAS_COLORSPACE_ARGB8888);
56         evas_object_image_size_set(img, w, h);
57         evas_object_image_fill_set(img, 0, 0, w, h);
58
59         if (!is_bgra) {
60         unsigned char *m = NULL;
61         m = evas_object_image_data_get(img, 1);
62 #if 1                           /* Use self-logic to convert from RGB888 to RGBA */
63         int i = 0, j;
64         for (j = 0; j < w * 3 * h;
65                 j += 3) {
66                 m[i++] = (data[j + 2]);
67                 m[i++] = (data[j + 1]);
68                 m[i++] = (data[j]);
69                 m[i++] = 0x0;
70         }
71
72 #else                           /* Use mmf api to convert from RGB888 to RGBA */
73         int mm_ret = 0;
74         if ((mm_ret =
75                 mm_util_convert_colorspace(data,
76                                         w,
77                                         h,
78                                         MM_UTIL_IMG_FMT_RGB888,
79                                         m,
80                                         MM_UTIL_IMG_FMT_BGRA8888))
81                 < 0) {
82                 printf
83                         ("Failed to change from rgb888 to argb8888 %d\n",
84                         mm_ret);
85                 return -1;
86         }
87 #endif                          /* End of use mmf api to convert from RGB888 to RGBA */
88
89         evas_object_image_data_set(img, m);
90         evas_object_image_data_update_add(img, 0, 0, w, h);
91         } else {
92         evas_object_image_data_set(img, data);
93         evas_object_image_data_update_add(img, 0, 0, w, h);
94         }
95
96         if (evas_object_image_save
97                 (img, "/mnt/nfs/test.jpg", NULL,
98                 "quality=50 compress=2")) {
99                 printf("evas_object_image_save success\n");
100         } else {
101                 printf("evas_object_image_save failed\n");
102         }
103
104         ecore_evas_shutdown();
105
106         return 0;
107 }
108
109 int main(int argc, char *argv[])
110 {
111         int mode;
112         int err = -1;
113         const char *origin_path = NULL;
114
115         if ((argc != 3) && (argc != 4)) {
116                 printf("Usage: %s [test mode number] [path]\n", argv[0]);
117                 return -1;
118         }
119
120         mode = atoi(argv[1]);
121         origin_path = argv[2];
122
123         if (origin_path && (mode == 1)) {
124                 printf("Test _thumbnail_get_data\n");
125
126                 unsigned char *data = NULL;
127                 int thumb_size = 0;
128                 int thumb_w = 0;
129                 int thumb_h = 0;
130                 int origin_w = 0;
131                 int origin_h = 0;
132                 int alpha = FALSE;
133
134                 media_thumb_type thumb_type = MEDIA_THUMB_LARGE;
135                 //media_thumb_type thumb_type = MEDIA_THUMB_SMALL;
136                 media_thumb_format thumb_format = MEDIA_THUMB_BGRA;
137                 //media_thumb_format thumb_format = MEDIA_THUMB_RGB888;
138                 int is_bgra = 1;
139                 //int is_bgra = 0;
140
141                 long start = thumb_get_debug_time();
142
143                 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));
144                 if (err < 0) {
145                         printf("_thumbnail_get_data failed - %d\n", err);
146                         return -1;
147                 }
148         
149                 printf("Size : %d, W:%d, H:%d\n", thumb_size, thumb_w, thumb_h);        
150                 printf("Origin W:%d, Origin H:%d\n", origin_w, origin_h);
151
152                 err = save_to_file_with_evas(data, thumb_w, thumb_h, is_bgra);
153                 if (err < 0) {
154                         printf("_thumbnail_get_data failed - %d\n", err);
155                         return -1;
156                 } else {
157                         printf("file save success\n");
158                 }
159
160                 SAFE_FREE(data);
161
162                 long end = thumb_get_debug_time();
163                 printf("Time : %f\n", ((double)(end - start) / (double)CLOCKS_PER_SEC));
164
165         } else if (mode == 2) {
166                 printf("Test thumbnail_request_from_db\n");
167                 //const char *origin_path = "/opt/media/test/movie1.mp4";
168                 //const char *origin_path = "/opt/media/test/high.jpg";
169                 //const char *origin_path = "/opt/media/test/movie2.avi";
170                 char thumb_path[MAX_PATH_SIZE + 1];
171
172                 err = thumbnail_request_from_db(origin_path, thumb_path, sizeof(thumb_path), tzplatform_getuid(TZ_USER_NAME));
173                 if (err < 0) {
174                         printf("thumbnail_request_from_db failed : %d\n", err);
175                         return -1;
176                 }
177
178                 printf("Success!! (%s)\n", thumb_path);
179         } else if (mode == 3) {
180                 printf("Test thumbnail_request_save_to_file\n");
181                 const char *thumb_path = NULL;
182
183                 if (argv[3]) {
184                 thumb_path = argv[3];
185                 } else {
186                         printf("3 mode requires target path of thumbnail\n");
187                         return -1;
188                 }
189
190                 err = thumbnail_request_save_to_file(origin_path, MEDIA_THUMB_LARGE, thumb_path, tzplatform_getuid(TZ_USER_NAME));
191                 if (err < 0) {
192                         printf("thumbnail_request_save_to_file failed : %d\n", err);
193                         return -1;
194                 }
195
196                 printf("Success!!\n");
197         } else if (origin_path && mode == 4) {
198                 printf("Test thumbnail_generate_hash_code\n");
199                 char hash[255] = {0,};
200
201                 err = thumbnail_generate_hash_code(origin_path, hash, sizeof(hash));
202                 if (err < 0) {
203                         printf("thumbnail_generate_hash_code failed : %d\n", err);
204                         return -1;
205                 } else {
206                         printf("Hash : %s\n", hash);
207                 }
208
209                 printf("Success!!\n");
210         } else if (mode == 5) {
211                 printf("Test thumbnail_request_extract_all_thumbs\n");
212
213                 err = thumbnail_request_extract_all_thumbs(tzplatform_getuid(TZ_USER_NAME));
214                 if (err < 0) {
215                         printf("thumbnail_request_extract_all_thumbs failed : %d\n", err);
216                         return -1;
217                 } else {
218                         printf("thumbnail_request_extract_all_thumbs success!\n");
219                 }
220         } else if (mode == 6) {
221                 printf("Test thumbnail_request_cancel_media\n");
222
223                 err = thumbnail_request_cancel_media(origin_path,tzplatform_getuid(TZ_USER_NAME));
224                 if (err < 0) {
225                         printf("thumbnail_request_cancel_media failed : %d\n", err);
226                         return -1;
227                 } else {
228                         printf("thumbnail_request_cancel_media success!\n");
229                 }
230         } else if (mode == 7) {
231                 printf("Test thumbnail_request_cancel_all\n");
232
233                 err = thumbnail_request_cancel_all();
234                 if (err < 0) {
235                         printf("thumbnail_request_cancel_all failed : %d\n", err);
236                         return -1;
237                 } else {
238                         printf("thumbnail_request_cancel_all success!\n");
239                 }
240         }
241
242         thumb_dbg("Test is Completed");
243
244         return 0;
245 }
246