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