Fix failed TC
[framework/api/face.git] / src / face_component.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 #include "face.h"
18 #include "face_priv.h"
19
20 #include <stdlib.h>
21
22 static bool _validate_face_component_h(face_component_h face_component)
23 {
24         if ( face_component == NULL )
25         {
26                 return false;
27         }
28
29         if ( face_component->magic != FACE_COMPONENT_MAGIC )
30         {
31                 return false;
32         }
33
34         return true;
35
36 }
37
38
39 EXPORT_API int face_component_create(face_component_h *face_component)
40 {
41         if ( face_component == NULL )
42         {
43                 LOG_ERROR("Out pointer is NULL. %s", _face_convert_error(FACE_ERROR_INVALID_PARAMTER));
44                 return FACE_ERROR_INVALID_PARAMTER;
45         }
46
47         FaceComponent *facecomponent = NULL;
48
49         facecomponent = (FaceComponent *)calloc(1, sizeof(FaceComponent));
50
51         if ( facecomponent == NULL )
52         {
53                 LOG_ERROR("Cannot allocate face component handle");
54                 return FACE_ERROR_OUT_OF_MEMORY;
55         }
56
57         facecomponent->magic = FACE_COMPONENT_MAGIC;
58
59         *face_component = facecomponent;
60
61         return FACE_ERROR_NONE;
62
63 }
64
65 EXPORT_API int face_component_destroy(face_component_h face_component)
66 {
67         if ( _validate_face_component_h(face_component) == false )
68         {
69                 LOG_ERROR("Invalid face component. %s", _face_convert_error(FACE_ERROR_INVALID_PARAMTER));
70                 return FACE_ERROR_INVALID_PARAMTER;
71         }
72
73         face_component->magic = FACE_INVALID_MAGIC;
74
75         free(face_component);
76
77         return FACE_ERROR_NONE;
78 }
79
80
81 EXPORT_API int face_component_get_face_rect(face_component_h face_component, face_rect_s *face)
82 {
83         if ( _validate_face_component_h(face_component) == false )
84         {
85                 LOG_ERROR("Invalid component handle. %s", _face_convert_error(FACE_ERROR_INVALID_PARAMTER));
86                 return FACE_ERROR_INVALID_PARAMTER;
87         }
88
89         if ( face == NULL )
90         {
91                 LOG_ERROR("[%s] face is NULL", _face_convert_error(FACE_ERROR_INVALID_PARAMTER));
92                 return FACE_ERROR_INVALID_PARAMTER;
93         }
94
95         if ( face_component->face.w <= 0 || face_component->face.h <= 0 )
96         {
97                 LOG_ERROR("[%s] Face is not founded", _face_convert_error(FACE_ERROR_COMPONENT_NOT_FOUND));
98                 return FACE_ERROR_COMPONENT_NOT_FOUND;
99         }
100
101         face->x = face_component->face.x;
102         face->y = face_component->face.y;
103         face->w = face_component->face.w;
104         face->h = face_component->face.h;
105
106         return FACE_ERROR_NONE;
107
108 }
109
110 EXPORT_API int face_component_get_left_eye_point(face_component_h face_component, face_point_s *leye)
111 {
112         if ( _validate_face_component_h(face_component) == false )
113         {
114                 LOG_ERROR("Invalid component handle. %s", _face_convert_error(FACE_ERROR_INVALID_PARAMTER));
115                 return FACE_ERROR_INVALID_PARAMTER;
116         }
117
118         if ( leye == NULL )
119         {
120                 LOG_ERROR("[%s] leye is NULL", _face_convert_error(FACE_ERROR_INVALID_PARAMTER));
121                 return FACE_ERROR_INVALID_PARAMTER;
122         }
123
124         if ( face_component->lefteye.x <= 0 || face_component->lefteye.y <= 0 )
125         {
126                 LOG_ERROR("[%s] Left eye is not founded", _face_convert_error(FACE_ERROR_COMPONENT_NOT_FOUND));
127                 return FACE_ERROR_COMPONENT_NOT_FOUND;
128         }
129
130         leye->x = face_component->lefteye.x;
131         leye->y = face_component->lefteye.y;
132
133
134         return FACE_ERROR_NONE;
135
136 }
137
138 EXPORT_API int face_component_get_right_eye_point(face_component_h face_component, face_point_s *reye)
139 {
140         if ( _validate_face_component_h(face_component) == false )
141         {
142                 LOG_ERROR("Invalid component handle. %s", _face_convert_error(FACE_ERROR_INVALID_PARAMTER));
143                 return FACE_ERROR_INVALID_PARAMTER;
144         }
145
146         if ( reye == NULL )
147         {
148                 LOG_ERROR("[%s] leye is NULL", _face_convert_error(FACE_ERROR_INVALID_PARAMTER));
149                 return FACE_ERROR_INVALID_PARAMTER;
150         }
151
152         if ( face_component->righteye.x <= 0 || face_component->righteye.y <= 0 )
153         {
154                 LOG_ERROR("[%s] Right eye is not founded", _face_convert_error(FACE_ERROR_COMPONENT_NOT_FOUND));
155                 return FACE_ERROR_COMPONENT_NOT_FOUND;
156         }
157
158         reye->x = face_component->righteye.x;
159         reye->y = face_component->righteye.y;
160
161         return FACE_ERROR_NONE;
162
163 }
164
165 EXPORT_API int face_component_get_mouse_rect(face_component_h face_component, face_rect_s *mouse)
166 {
167         if ( _validate_face_component_h(face_component) == false )
168         {
169                 LOG_ERROR("Invalid component handle. %s", _face_convert_error(FACE_ERROR_INVALID_PARAMTER));
170                 return FACE_ERROR_INVALID_PARAMTER;
171         }
172
173         if ( mouse == NULL )
174         {
175                 LOG_ERROR("[%s] mouse is NULL", _face_convert_error(FACE_ERROR_INVALID_PARAMTER));
176                 return FACE_ERROR_INVALID_PARAMTER;
177         }
178
179         if ( face_component->mouse.w <= 0 || face_component->mouse.h <= 0 )
180         {
181                 LOG_ERROR("[%s] Mouse position is not founded", _face_convert_error(FACE_ERROR_COMPONENT_NOT_FOUND));
182                 return FACE_ERROR_COMPONENT_NOT_FOUND;
183         }
184
185         mouse->x = face_component->mouse.x;
186         mouse->y = face_component->mouse.y;
187         mouse->w = face_component->mouse.w;
188         mouse->h = face_component->mouse.h;
189
190         return FACE_ERROR_NONE;
191 }
192