summaryrefslogtreecommitdiff
path: root/main/src/control/ivug-setas.cpp
blob: 18db6fe77cfde85d5ab326932fbe3b824a477bb5 (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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
/*
 * Copyright 2012  Samsung Electronics Co., Ltd
 *
 * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
 *
 * 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 <Elementary.h>

#include "ivug-common.h"

#include "ivug-debug.h"
#include "ivug-util.h"
#include "ivug-image.h"

#include "ivug-setas.h"

/*
	Used for storing cropped image.
*/
#define IVUG_HOME_SCREEN_TEMP_PATH	DATA_PATH"/.homescreen_tmp.jpg"
#define IVUG_LOCK_SCREEN_TEMP_PATH	DATA_PATH"/.lockscreen_tmp.jpg"


static Eina_Bool _crop_image(Evas_Object *photocam, Evas_Coord_Rectangle *rect, const char *save_file, const char *option)
{
	if (ivug_remove_file(save_file) == false)
	{
		MSG_SETAS_ERROR( "Delete file %s: failed", save_file);
		return EINA_FALSE;
	}

	Evas_Object *ret_image = NULL;

	ret_image = ivug_image_region_image_get(photocam, rect->x, rect->y, rect->w , rect->h);

	if(ret_image == NULL)
	{
		MSG_SETAS_ERROR("Region get faied.");
		return EINA_FALSE;
	}

	if (evas_object_image_save(ret_image, save_file, NULL, option) == EINA_FALSE)
	{
		MSG_SETAS_ERROR("evas_object_image_save error. %s", save_file);
		MSG_SETAS_ERROR("setas image save faied.");
		evas_object_del(ret_image);
		return EINA_FALSE;
	}

	evas_object_del(ret_image);

	return EINA_TRUE;
}


static Eina_Bool _photocam_image_save(Evas_Object *photocam, Evas_Coord_Rectangle *rect, const char* tmp_file, const char* final_file)
{
//2. Crop image and save it as tmp file
	Eina_Bool ret;

	if ( tmp_file == NULL )
	{
		if (ivug_remove_file(final_file) == false)		// Remove dest file
		{
			MSG_SETAS_ERROR( "Delete file %s failed", final_file);
			goto error;
		}

		ret = _crop_image(photocam, rect, final_file, "quality=100 compress=9");
		if(ret == EINA_FALSE)
		{
			MSG_SETAS_ERROR("crop image failed!");
			goto error;
		}

	}
	else
	{
	// save ½ÇÆнà ÇöÀçÀÇ image¸¦ º¸È£Çϱâ À§ÇØ ¸ÕÀú tmp¿¡ ÀúÀåÇÑ ´ÙÀ½ rename ÇÑ´Ù.
		ret = _crop_image(photocam, rect, tmp_file, "quality=100 compress=9");
		if(ret == EINA_FALSE)
		{
			MSG_SETAS_ERROR("crop image failed!");
			goto error;
		}

	//3. Delete the lockscreen file if exist
		if (ivug_remove_file(final_file) == false)
		{
			MSG_SETAS_ERROR( "Delete file %s failed", final_file);
			goto error;
		}

	//4. rename the tmp file to lock screen file
		if(ivug_rename_file(tmp_file, final_file) == false)
		{
			MSG_SETAS_ERROR( "Rename file %s to %s failed", tmp_file, final_file);
			goto error;
		}
	}

	return EINA_TRUE;
error:

	if(ivug_remove_file(tmp_file) == false)
	{
		MSG_SETAS_ERROR( "Delete file %s failed", tmp_file);
	}

	return EINA_FALSE;
}

Eina_Bool
_ivug_setas_save_home_screen(Evas_Object *photocam, Evas_Coord_Rectangle *rect, const char *dest)
{
	MSG_SETAS_HIGH("Change Home Screen");

	Eina_Bool ret = EINA_FALSE;

	ret = _photocam_image_save(photocam, rect, IVUG_HOME_SCREEN_TEMP_PATH, dest);

	if(ret == EINA_FALSE)
	{
		MSG_SETAS_ERROR("Create screen file failed");
		return EINA_FALSE;
	}

	return EINA_TRUE;
}

Eina_Bool
_ivug_setas_save_lock_screen(Evas_Object *photocam, Evas_Coord_Rectangle *rect, const char *dest)
{
	MSG_SETAS_HIGH("Change Lock Screen");

	Eina_Bool ret = EINA_FALSE;

	ret = _photocam_image_save(photocam, rect, IVUG_LOCK_SCREEN_TEMP_PATH, dest);

	if(ret == EINA_FALSE)
	{
		MSG_SETAS_ERROR( "Create screen file failed");
		return EINA_FALSE;
	}

	return EINA_TRUE;
}

Eina_Bool
_ivug_setas_save_homenlock_screen(Evas_Object *photocam, Evas_Coord_Rectangle *rect, const char *home, const char *lock)
{
	MSG_SETAS_HIGH("Change Home&Lock Screen");

// Set homescreen image
	Eina_Bool ret = EINA_FALSE;

	ret = _photocam_image_save(photocam, rect, IVUG_HOME_SCREEN_TEMP_PATH, home);

	if(ret == EINA_FALSE)
	{
		MSG_SETAS_ERROR( "Create screen file failed");
		return EINA_FALSE;
	}

	if (ivug_remove_file(IVUG_LOCK_SCREEN_TEMP_PATH) == false)
	{
		MSG_SETAS_ERROR( "Detele file %s: failed", IVUG_LOCK_SCREEN_TEMP_PATH);
		return EINA_FALSE;
	}

// Make a copy from home screen to lock screen
	if( ecore_file_cp(home, IVUG_LOCK_SCREEN_TEMP_PATH) == EINA_FALSE)
	{
		MSG_SETAS_ERROR( "File copy failed");
		return EINA_FALSE;
	}

	if(ivug_rename_file(IVUG_LOCK_SCREEN_TEMP_PATH, lock) == false)
	{
		MSG_SETAS_ERROR( "Rename file %s to %s failed", IVUG_LOCK_SCREEN_TEMP_PATH, lock );
		if(ivug_remove_file(IVUG_LOCK_SCREEN_TEMP_PATH)== false)
		{
			MSG_SETAS_ERROR( "delete tmp lock file failed %s", IVUG_LOCK_SCREEN_TEMP_PATH);
		}

		return EINA_FALSE;
	}

	sync();	//sync copied file.

	return EINA_TRUE;
}


#if 0
static Eina_Bool
_ivug_setas_view_create_croped_image(Evas_Object *photocam, const char *save_file,
	Evas_Coord_Rectangle rect, int width, int height, bool bFreeSize)
{
	IV_ASSERT(photocam != NULL);
	IV_ASSERT(save_file != NULL);

	if(bFreeSize == true)
	{
		width = rect.w;
		height = rect.h;
	}

	if(width <= 0 || height <= 0)
	{
		MSG_SETAS_ERROR("input size parameter is invalid, w = %d, h = %d", width, height);
		return EINA_FALSE;
	}

	Evas_Object *ret_image = NULL;

	MSG_SETAS_HIGH("SCissorbox Rect:(%d,%d,%d,%d) Final=(%d,%d)", rect.x, rect.y, rect.w, rect.h, width, height);

	ret_image = ivug_image_region_image_get(photocam, rect.x, rect.y, rect.w, rect.h);
	if(ret_image == NULL)
	{
		MSG_SETAS_ERROR("Region get faied.");
		return EINA_FALSE;
	}

	if (evas_object_image_save(ret_image, save_file, NULL, "quality=100 compress=9") == EINA_FALSE)
	{
		MSG_SETAS_ERROR("evas_object_image_save error. %s", save_file);
		evas_object_del(ret_image);
		return EINA_FALSE;
	}
	else
	{
		int fd = open(save_file, O_RDONLY);
		if(fd < 0)
		{
			MSG_SETAS_ERROR("%s open error[%d]", save_file, fd);
			evas_object_del(ret_image);
			return EINA_FALSE;
		}
		fsync(fd);
		int ret = close(fd);
		if(ret < 0)
		{
			MSG_SETAS_ERROR("%s open error[%d]", save_file, ret);
		}
	}

	evas_object_del(ret_image);

	return EINA_TRUE;
}


static void
_ivug_setas_save_callerimage(Evas_Object *photocam, Evas_Coord_Rectangle *rect, char *filepath)
{
	MSG_SETAS_HIGH("Save CallerID");

	char* save_file = SET_AS_CALL_ID_PATH;

	Evas_Coord_Rectangle box_rect;

	ivug_scissorbox_region_get(pSetAsView->select_box, &(box_rect.x), &(box_rect.y), &(box_rect.w), &(box_rect.h));

	Eina_Bool crop_sel_ret = _ivug_setas_view_create_croped_image(photocam,
			save_file, box_rect, pSetAsView->box_width, pSetAsView->box_height, pSetAsView->bFreeSize);
	if(crop_sel_ret == EINA_FALSE)
	{
		MSG_SETAS_ERROR( "Crop selector image failed!");
	}

	const char *lcd_file = SET_AS_CALL_ID_LCD_PATH;		// ?????

	Eina_Bool crop_lcd_ret = EINA_FALSE;

	crop_lcd_ret = _ivug_setas_view_create_fit_image(pSetAsView->layout, pSetAsView->photocam, lcd_file);
	if(crop_lcd_ret == EINA_FALSE)
	{
		MSG_SETAS_ERROR( "Crop lcd image failed!");
	}

	if(pSetAsView->mode == IVUG_SETAS_UG || pSetAsView->mode == IVUG_SETAS_APPSVC)
	{
		if ( crop_lcd_ret == EINA_TRUE && crop_sel_ret == EINA_TRUE )
		{
			_ivug_setas_view_send_result(gGetUGHandle(), "crop_image_path", save_file, "image_path", lcd_file);
		}
	}
}
#endif

Eina_Bool
_ivug_setas_save_cropimage(Evas_Object *photocam, Evas_Coord_Rectangle *rect, const char *filepath)
{
	MSG_SETAS_HIGH("Save Cropped");

	Eina_Bool ret = EINA_FALSE;

	ret = _photocam_image_save(photocam, rect, NULL, filepath);

	if(ret == EINA_FALSE)
	{
		MSG_SETAS_ERROR( "Create cropimage file failed");
		return EINA_FALSE;
	}

	return EINA_TRUE;
}