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