summaryrefslogtreecommitdiff
path: root/test/test-thumb.c
blob: 69c619ad835c30ed5b988840dd9e93f0e2e7c88f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
 * libmedia-thumbnail
 *
 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <Evas.h>
#include <Ecore_Evas.h>
#include <mm_util_imgp.h>
#include <mm_util_jpeg.h>

#include "media-thumbnail.h"
#include "media-thumbnail-private.h"
#include "media-thumb-debug.h"
#include "media-thumb-ipc.h"
#include "media-thumb-util.h"

int save_to_file_with_evas(unsigned char *data, int w, int h, int is_bgra)
{
	ecore_evas_init();
	
	Ecore_Evas *ee =
		ecore_evas_buffer_new(w, h);
	Evas *evas = ecore_evas_get(ee);

	Evas_Object *img = NULL;
	img = evas_object_image_add(evas);

	if (img == NULL) {
		printf("image object is NULL\n");
		ecore_evas_free(ee);
		ecore_evas_shutdown();
		return -1;
	}

	evas_object_image_colorspace_set(img, EVAS_COLORSPACE_ARGB8888);
	evas_object_image_size_set(img, w, h);
	evas_object_image_fill_set(img, 0, 0, w, h);

	if (!is_bgra) {
	unsigned char *m = NULL;
	m = evas_object_image_data_get(img, 1);
#if 1				/* Use self-logic to convert from RGB888 to RGBA */
	int i = 0, j;
	for (j = 0; j < w * 3 * h;
		j += 3) {
		m[i++] = (data[j + 2]);
		m[i++] = (data[j + 1]);
		m[i++] = (data[j]);
		m[i++] = 0x0;
	}

#else				/* Use mmf api to convert from RGB888 to RGBA */
	int mm_ret = 0;
	if ((mm_ret =
		mm_util_convert_colorspace(data,
					w,
					h,
					MM_UTIL_IMG_FMT_RGB888,
					m,
					MM_UTIL_IMG_FMT_BGRA8888))
		< 0) {
		printf
			("Failed to change from rgb888 to argb8888 %d\n",
			mm_ret);
		return -1;
	}
#endif				/* End of use mmf api to convert from RGB888 to RGBA */

	evas_object_image_data_set(img, m);
	evas_object_image_data_update_add(img, 0, 0, w, h);
	} else {
	evas_object_image_data_set(img, data);
	evas_object_image_data_update_add(img, 0, 0, w, h);
	}

	if (evas_object_image_save
		(img, "/mnt/nfs/test.jpg", NULL,
		"quality=50 compress=2")) {
		printf("evas_object_image_save success\n");
	} else {
		printf("evas_object_image_save failed\n");
	}

	ecore_evas_shutdown();

	return 0;
}

int main(int argc, char *argv[])
{
	int mode;
	int err = -1;
	const char *origin_path = NULL;

	if ((argc != 3) && (argc != 4)) {
		printf("Usage: %s [test mode number] [path]\n", argv[0]);
		return -1;
	}

	mode = atoi(argv[1]);
	origin_path = argv[2];

	if (origin_path && (mode == 1)) {
		printf("Test _thumbnail_get_data\n");
		//const char *origin_path = "/opt/media/test/gif_test.gif";
		//const char *origin_path = "/opt/media/test/praha_01.gif";
		//const char *origin_path = "/opt/media/test/test_bmp.bmp";
		//const char *origin_path = "/opt/media/test/normal.jpg";
		//const char *origin_path = "/opt/media/test/high.jpg";
		//const char *origin_path = "/opt/media/test/front.jpg";
		//const char *origin_path = "/opt/media/test/no_rot_high.jpg";
		//const char *origin_path = "/opt/media/test/no_rot_front.jpg";
		//const char *origin_path = "/opt/media/test/movie1.mp4";
		//const char *origin_path = "/opt/media/test/movie2.avi";

		unsigned char *data = NULL;
		int thumb_size = 0;
		int thumb_w = 0;
		int thumb_h = 0;
		int origin_w = 0;
		int origin_h = 0;

		media_thumb_type thumb_type = MEDIA_THUMB_LARGE;
		//media_thumb_type thumb_type = MEDIA_THUMB_SMALL;
		media_thumb_format thumb_format = MEDIA_THUMB_BGRA;
		//media_thumb_format thumb_format = MEDIA_THUMB_RGB888;
		int is_bgra = 1;
		//int is_bgra = 0;

		long start = thumb_get_debug_time();

		err = _thumbnail_get_data(origin_path, thumb_type, thumb_format, &data, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h);
		if (err < 0) {
			printf("_thumbnail_get_data failed - %d\n", err);
			return -1;
		}
	
		printf("Size : %d, W:%d, H:%d\n", thumb_size, thumb_w, thumb_h);	
		printf("Origin W:%d, Origin H:%d\n", origin_w, origin_h);

		err = save_to_file_with_evas(data, thumb_w, thumb_h, is_bgra);
		if (err < 0) {
			printf("_thumbnail_get_data failed - %d\n", err);
			return -1;
		} else {
			printf("file save success\n");
		}

		SAFE_FREE(data);

		long end = thumb_get_debug_time();
		printf("Time : %f\n", ((double)(end - start) / (double)CLOCKS_PER_SEC));

	} else if (mode == 2) {
		printf("Test thumbnail_request_from_db\n");
		//const char *origin_path = "/opt/media/test/movie1.mp4";
		//const char *origin_path = "/opt/media/test/high.jpg";
		//const char *origin_path = "/opt/media/test/movie2.avi";
		char thumb_path[MAX_PATH_SIZE + 1];

		err = thumbnail_request_from_db(origin_path, thumb_path, sizeof(thumb_path));
		if (err < 0) {
			printf("thumbnail_request_from_db failed : %d\n", err);
			return -1;
		}

		printf("Success!! (%s)\n", thumb_path);
	} else if (mode == 3) {
		printf("Test thumbnail_request_save_to_file\n");
		const char *thumb_path = NULL;

		if (argv[3]) {
		thumb_path = argv[3];
		} else {
			printf("3 mode requires target path of thumbnail\n");
			return -1;
		}

		err = thumbnail_request_save_to_file(origin_path, MEDIA_THUMB_LARGE, thumb_path);
		if (err < 0) {
			printf("thumbnail_request_save_to_file failed : %d\n", err);
			return -1;
		}

		printf("Success!!\n");
	} else if (origin_path && mode == 4) {
		printf("Test thumbnail_generate_hash_code\n");
		char hash[255] = {0,};

		err = thumbnail_generate_hash_code(origin_path, hash, sizeof(hash));
		if (err < 0) {
			printf("thumbnail_generate_hash_code failed : %d\n", err);
			return -1;
		} else {
			printf("Hash : %s\n", hash);
		}

		printf("Success!!\n");
	} else if (mode == 5) {
		printf("Test thumbnail_request_extract_all_thumbs\n");

		err = thumbnail_request_extract_all_thumbs();
		if (err < 0) {
			printf("thumbnail_request_extract_all_thumbs failed : %d\n", err);
			return -1;
		} else {
			printf("thumbnail_request_extract_all_thumbs success!\n");
		}
	}

	return 0;
}