11eb91a3bdb35c28fad532758defd04de691731c
[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_info_private.h>
19
20 int image_meta_destroy(image_meta_h image)
21 {
22         image_meta_s *_image = (image_meta_s*)image;
23         content_retvm_if(_image == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Image handle is null");
24
25         g_free(_image->media_id);
26         g_free(_image->date_taken);
27         g_free(_image->exposure_time);
28         g_free(_image->model);
29         g_free(_image);
30
31         return MEDIA_CONTENT_ERROR_NONE;
32 }
33
34 int image_meta_clone(image_meta_h *dst, image_meta_h src)
35 {
36         image_meta_s *_src = (image_meta_s*)src;
37
38         content_retip_if_fail(dst);
39         content_retip_if_fail(src);
40
41         image_meta_s *_dst = g_new0(image_meta_s, 1);
42
43         _dst->media_id = g_strdup(_src->media_id);
44         _dst->date_taken = g_strdup(_src->date_taken);
45         _dst->exposure_time = g_strdup(_src->exposure_time);
46         _dst->model = g_strdup(_src->model);
47         _dst->fnumber = _src->fnumber;
48         _dst->iso = _src->iso;
49         _dst->width = _src->width;
50         _dst->height = _src->height;
51         _dst->orientation = _src->orientation;
52
53         *dst = (image_meta_h)_dst;
54
55         return MEDIA_CONTENT_ERROR_NONE;
56 }
57
58 int image_meta_get_media_id(image_meta_h image, char **media_id)
59 {
60         image_meta_s *_image = (image_meta_s*)image;
61
62         content_retip_if_fail(image);
63         content_retip_if_fail(media_id);
64
65         *media_id = g_strdup(_image->media_id);
66
67         return MEDIA_CONTENT_ERROR_NONE;
68 }
69
70 int image_meta_get_width(image_meta_h image, int *width)
71 {
72         image_meta_s *_image = (image_meta_s*)image;
73         content_retvm_if(!_image || !width, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid parameter");
74
75         *width = _image->width;
76
77         return MEDIA_CONTENT_ERROR_NONE;
78 }
79 int image_meta_get_height(image_meta_h image, int *height)
80 {
81         image_meta_s *_image = (image_meta_s*)image;
82         content_retvm_if(!_image || !height, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid parameter");
83
84         *height = _image->height;
85
86         return MEDIA_CONTENT_ERROR_NONE;
87 }
88
89 int image_meta_get_orientation(image_meta_h image, media_content_orientation_e* orientation)
90 {
91         image_meta_s *_image = (image_meta_s*)image;
92         content_retvm_if(!_image || !orientation, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid parameter");
93
94         *orientation = _image->orientation;
95
96         return MEDIA_CONTENT_ERROR_NONE;
97 }
98
99 int image_meta_get_date_taken(image_meta_h image, char **date_taken)
100 {
101         image_meta_s *_image = (image_meta_s*)image;
102
103         content_retip_if_fail(image);
104         content_retip_if_fail(date_taken);
105
106         *date_taken = g_strdup(_image->date_taken);
107
108         return MEDIA_CONTENT_ERROR_NONE;
109 }
110
111 int image_meta_get_exposure_time(image_meta_h image, char **exposure_time)
112 {
113         image_meta_s *_image = (image_meta_s*)image;
114
115         content_retip_if_fail(image);
116         content_retip_if_fail(exposure_time);
117
118         *exposure_time = g_strdup(_image->exposure_time);
119
120         return MEDIA_CONTENT_ERROR_NONE;
121 }
122
123 int image_meta_get_fnumber(image_meta_h image, double *fnumber)
124 {
125         image_meta_s *_image = (image_meta_s*)image;
126         content_retvm_if(!_image || !fnumber, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid parameter");
127
128         *fnumber = _image->fnumber;
129
130         return MEDIA_CONTENT_ERROR_NONE;
131 }
132
133 int image_meta_get_iso(image_meta_h image, int *iso)
134 {
135         image_meta_s *_image = (image_meta_s*)image;
136         content_retvm_if(!_image || !iso, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid parameter");
137
138         *iso = _image->iso;
139
140         return MEDIA_CONTENT_ERROR_NONE;
141 }
142
143 int image_meta_get_model(image_meta_h image, char **model)
144 {
145         image_meta_s *_image = (image_meta_s*)image;
146
147         content_retip_if_fail(image);
148         content_retip_if_fail(model);
149
150         *model = g_strdup(_image->model);
151
152         return MEDIA_CONTENT_ERROR_NONE;
153 }
154
155 int image_meta_set_orientation(image_meta_h image, media_content_orientation_e orientation)
156 {
157         content_warn("DEPRECATION WARNING: image_meta_set_orientation() is deprecated and will be removed from next release.");
158         image_meta_s *_image = (image_meta_s*)image;
159         content_retvm_if(!_image, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid parameter");
160         content_retvm_if(orientation < MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE || orientation > MEDIA_CONTENT_ORIENTATION_ROT_270, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid orientation");
161
162         _image->orientation = orientation;
163
164         return MEDIA_CONTENT_ERROR_NONE;
165 }
166
167 int image_meta_update_to_db(image_meta_h image)
168 {
169         int ret = MEDIA_CONTENT_ERROR_NONE;
170         content_warn("DEPRECATION WARNING: image_meta_update_to_db() is deprecated and will be removed from next release.");
171         image_meta_s *_image = (image_meta_s*)image;
172         char *sql = NULL;
173
174         content_retvm_if(!_image || !STRING_VALID(_image->media_id), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid parameter");
175
176 #ifdef _USE_TVPD_MODE
177                 char *storage_id = NULL;
178                 ret = _media_db_get_storage_id_by_media_id(_image->media_id, &storage_id);
179                 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
180                 sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, storage_id, _image->orientation, _image->media_id);
181                 g_free(storage_id);
182 #else
183                 sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, _image->orientation, _image->media_id);
184 #endif
185                 ret = _content_query_sql(sql);
186                 SQLITE3_SAFE_FREE(sql);
187
188         return ret;
189 }