839a350a7fe518c36cdea29bdf88575940df2112
[platform/core/api/media-content.git] / src / media_image.c
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18 #include <media_image.h>
19 #include <media_content.h>
20 #include <media_info_private.h>
21 #include <media-svc.h>
22
23
24 int image_meta_destroy(image_meta_h image)
25 {
26         int ret = MEDIA_CONTENT_ERROR_NONE;
27         image_meta_s *_image = (image_meta_s*)image;
28
29         if(_image)
30         {
31                 SAFE_FREE(_image->media_id);
32                 SAFE_FREE(_image->date_taken);
33                 SAFE_FREE(_image->burst_id);
34                 SAFE_FREE(_image);
35
36                 ret = MEDIA_CONTENT_ERROR_NONE;
37         }
38         else
39         {
40                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
41                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
42         }
43
44         return ret;
45 }
46
47 int image_meta_clone(image_meta_h *dst, image_meta_h src)
48 {
49         int ret = MEDIA_CONTENT_ERROR_NONE;
50         image_meta_s *_src = (image_meta_s*)src;
51
52         if(_src != NULL)
53         {
54                 image_meta_s *_dst = (image_meta_s*)calloc(1, sizeof(image_meta_s));
55                 if(NULL == _dst)
56                 {
57                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
58                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
59                 }
60
61                 if(STRING_VALID(_src->media_id))
62                 {
63                         _dst->media_id = strdup(_src->media_id);
64                         if(_dst->media_id == NULL)
65                         {
66                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
67                                 image_meta_destroy((image_meta_h)_dst);
68                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
69                         }
70                 }
71
72                 if(STRING_VALID(_src->date_taken))
73                 {
74                         _dst->date_taken = strdup(_src->date_taken);
75                         if(_dst->date_taken == NULL)
76                         {
77                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
78                                 image_meta_destroy((image_meta_h)_dst);
79                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
80                         }
81                 }
82
83                 if(STRING_VALID(_src->burst_id))
84                 {
85                         _dst->burst_id = strdup(_src->burst_id);
86                         if(_dst->burst_id == NULL)
87                         {
88                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
89                                 image_meta_destroy((image_meta_h)_dst);
90                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
91                         }
92                 }
93
94                 _dst->width = _src->width;
95                 _dst->height = _src->height;
96                 _dst->orientation = _src->orientation;
97
98                 *dst = (image_meta_h)_dst;
99
100                 ret = MEDIA_CONTENT_ERROR_NONE;
101         }
102         else
103         {
104                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
105                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
106         }
107
108         return ret;
109 }
110
111 int image_meta_get_media_id(image_meta_h image, char **media_id)
112 {
113         int ret = MEDIA_CONTENT_ERROR_NONE;
114         image_meta_s *_image = (image_meta_s*)image;
115
116         if(_image && media_id)
117         {
118                 if(STRING_VALID(_image->media_id))
119                 {
120                         char *new_string = strdup(_image->media_id);
121                         if(NULL == new_string)
122                         {
123                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
124                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
125                         }
126                         *media_id = new_string;
127                 }
128                 else
129                 {
130                         *media_id = NULL;
131                 }
132                 ret = MEDIA_CONTENT_ERROR_NONE;
133
134         }
135         else
136         {
137                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
138                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
139         }
140
141         return ret;
142
143 }
144
145 int image_meta_get_width(image_meta_h image, int *width)
146 {
147         int ret = MEDIA_CONTENT_ERROR_NONE;
148         image_meta_s *_image = (image_meta_s*)image;
149
150         if(_image && width)
151         {
152                 *width = _image->width;
153                 ret = MEDIA_CONTENT_ERROR_NONE;
154         }
155         else
156         {
157                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
158                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
159         }
160
161         return ret;
162 }
163 int image_meta_get_height(image_meta_h image, int *height)
164 {
165         int ret = MEDIA_CONTENT_ERROR_NONE;
166         image_meta_s *_image = (image_meta_s*)image;
167
168         if(_image && height)
169         {
170                 *height = _image->height;
171                 ret = MEDIA_CONTENT_ERROR_NONE;
172         }
173         else
174         {
175                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
176                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
177         }
178
179         return ret;
180 }
181
182 int image_meta_get_orientation(image_meta_h image, media_content_orientation_e* orientation)
183 {
184         int ret = MEDIA_CONTENT_ERROR_NONE;
185         image_meta_s *_image = (image_meta_s*)image;
186
187         if(_image && orientation)
188         {
189                 *orientation = _image->orientation;
190                 ret = MEDIA_CONTENT_ERROR_NONE;
191         }
192         else
193         {
194                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
195                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
196         }
197
198         return ret;
199 }
200
201 int image_meta_get_date_taken(image_meta_h image, char **date_taken)
202 {
203         int ret = MEDIA_CONTENT_ERROR_NONE;
204         image_meta_s *_image = (image_meta_s*)image;
205
206         if(_image && date_taken)
207         {
208                 if(STRING_VALID(_image->date_taken))
209                 {
210                         char *new_string = strdup(_image->date_taken);
211                         if(NULL == new_string)
212                         {
213                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
214                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
215                         }
216                         *date_taken = new_string;
217                 }
218                 else
219                 {
220                         *date_taken = NULL;
221                 }
222
223                 ret = MEDIA_CONTENT_ERROR_NONE;
224         }
225         else
226         {
227                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
228                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
229         }
230
231         return ret;
232 }
233
234 int image_meta_get_burst_id(image_meta_h image, char **burst_id)
235 {
236         int ret = MEDIA_CONTENT_ERROR_NONE;
237         image_meta_s *_image = (image_meta_s*)image;
238
239         if(_image && burst_id)
240         {
241                 if(STRING_VALID(_image->burst_id))
242                 {
243                         *burst_id = strdup(_image->burst_id);
244                         if(*burst_id == NULL)
245                         {
246                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
247                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
248                         }
249                 }
250                 else
251                 {
252                         *burst_id = NULL;
253                 }
254                 ret = MEDIA_CONTENT_ERROR_NONE;
255         }
256         else
257         {
258                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
259                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
260         }
261
262         return ret;
263 }
264
265 int image_meta_is_burst_shot(image_meta_h image, bool *is_burst_shot)
266 {
267         int ret = MEDIA_CONTENT_ERROR_NONE;
268         image_meta_s *_image = (image_meta_s*)image;
269
270         if(_image && is_burst_shot)
271         {
272                 if(STRING_VALID(_image->burst_id))
273                         *is_burst_shot = true;
274                 else
275                         *is_burst_shot = false;
276
277                 ret = MEDIA_CONTENT_ERROR_NONE;
278         }
279         else
280         {
281                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
282                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
283         }
284
285         return ret;
286 }
287 int image_meta_set_orientation(image_meta_h image, media_content_orientation_e orientation)
288 {
289         int ret = MEDIA_CONTENT_ERROR_NONE;
290         image_meta_s *_image = (image_meta_s*)image;
291
292         if(_image == NULL)
293         {
294                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
295                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
296         }
297
298         if((orientation < MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE) || (orientation > MEDIA_CONTENT_ORIENTATION_ROT_270))
299         {
300                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
301                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
302         }
303
304         _image->orientation = orientation;
305
306         return ret;
307 }
308
309 int image_meta_update_to_db(image_meta_h image)
310 {
311         int ret = MEDIA_CONTENT_ERROR_NONE;
312         image_meta_s *_image = (image_meta_s*)image;
313         char *sql = NULL;
314
315         if(_image != NULL && STRING_VALID(_image->media_id))
316         {
317                 sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, _image->orientation, _image->media_id);
318                 ret = _content_query_sql(sql);
319                 sqlite3_free(sql);
320         }
321         else
322         {
323                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
324                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
325         }
326
327         return ret;
328 }