4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
27 #include <Ecore_Evas.h>
28 #include <mm_util_imgp.h>
29 #include <mm_util_jpeg.h>
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"
37 int save_to_file_with_evas(unsigned char *data, int w, int h, int is_bgra)
42 ecore_evas_buffer_new(w, h);
43 Evas *evas = ecore_evas_get(ee);
45 Evas_Object *img = NULL;
46 img = evas_object_image_add(evas);
49 printf("image object is NULL\n");
51 ecore_evas_shutdown();
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);
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 */
64 for (j = 0; j < w * 3 * h;
66 m[i++] = (data[j + 2]);
67 m[i++] = (data[j + 1]);
72 #else /* Use mmf api to convert from RGB888 to RGBA */
75 mm_util_convert_colorspace(data,
78 MM_UTIL_IMG_FMT_RGB888,
80 MM_UTIL_IMG_FMT_BGRA8888))
83 ("Failed to change from rgb888 to argb8888 %d\n",
87 #endif /* End of use mmf api to convert from RGB888 to RGBA */
89 evas_object_image_data_set(img, m);
90 evas_object_image_data_update_add(img, 0, 0, w, h);
92 evas_object_image_data_set(img, data);
93 evas_object_image_data_update_add(img, 0, 0, w, h);
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");
101 printf("evas_object_image_save failed\n");
104 ecore_evas_shutdown();
109 int main(int argc, char *argv[])
113 const char *origin_path = NULL;
115 if ((argc != 3) && (argc != 4)) {
116 printf("Usage: %s [test mode number] [path]\n", argv[0]);
120 mode = atoi(argv[1]);
121 origin_path = argv[2];
123 if (origin_path && (mode == 1)) {
124 printf("Test _thumbnail_get_data\n");
126 unsigned char *data = NULL;
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;
141 long start = thumb_get_debug_time();
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));
145 printf("_thumbnail_get_data failed - %d\n", err);
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);
152 err = save_to_file_with_evas(data, thumb_w, thumb_h, is_bgra);
154 printf("_thumbnail_get_data failed - %d\n", err);
157 printf("file save success\n");
162 long end = thumb_get_debug_time();
163 printf("Time : %f\n", ((double)(end - start) / (double)CLOCKS_PER_SEC));
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];
172 err = thumbnail_request_from_db(origin_path, thumb_path, sizeof(thumb_path), tzplatform_getuid(TZ_USER_NAME));
174 printf("thumbnail_request_from_db failed : %d\n", err);
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;
184 thumb_path = argv[3];
186 printf("3 mode requires target path of thumbnail\n");
190 err = thumbnail_request_save_to_file(origin_path, MEDIA_THUMB_LARGE, thumb_path, tzplatform_getuid(TZ_USER_NAME));
192 printf("thumbnail_request_save_to_file failed : %d\n", err);
196 printf("Success!!\n");
197 } else if (origin_path && mode == 4) {
198 printf("Test thumbnail_generate_hash_code\n");
199 char hash[255] = {0,};
201 err = thumbnail_generate_hash_code(origin_path, hash, sizeof(hash));
203 printf("thumbnail_generate_hash_code failed : %d\n", err);
206 printf("Hash : %s\n", hash);
209 printf("Success!!\n");
210 } else if (mode == 5) {
211 printf("Test thumbnail_request_extract_all_thumbs\n");
213 err = thumbnail_request_extract_all_thumbs(tzplatform_getuid(TZ_USER_NAME));
215 printf("thumbnail_request_extract_all_thumbs failed : %d\n", err);
218 printf("thumbnail_request_extract_all_thumbs success!\n");
220 } else if (mode == 6) {
221 printf("Test thumbnail_request_cancel_media\n");
223 err = thumbnail_request_cancel_media(origin_path,tzplatform_getuid(TZ_USER_NAME));
225 printf("thumbnail_request_cancel_media failed : %d\n", err);
228 printf("thumbnail_request_cancel_media success!\n");
230 } else if (mode == 7) {
231 printf("Test thumbnail_request_cancel_all\n");
233 err = thumbnail_request_cancel_all();
235 printf("thumbnail_request_cancel_all failed : %d\n", err);
238 printf("thumbnail_request_cancel_all success!\n");
242 thumb_dbg("Test is Completed");