2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "face_priv.h"
22 static bool _validate_face_component_h(face_component_h face_component)
24 if ( face_component == NULL )
29 if ( face_component->magic != FACE_COMPONENT_MAGIC )
39 EXPORT_API int face_component_create(face_component_h *face_component)
41 if ( face_component == NULL )
43 LOG_ERROR("Out pointer is NULL. %s", _face_convert_error(FACE_ERROR_INVALID_PARAMTER));
44 return FACE_ERROR_INVALID_PARAMTER;
47 FaceComponent *facecomponent = NULL;
49 facecomponent = (FaceComponent *)calloc(1, sizeof(FaceComponent));
51 if ( facecomponent == NULL )
53 LOG_ERROR("Cannot allocate face component handle");
54 return FACE_ERROR_OUT_OF_MEMORY;
57 facecomponent->magic = FACE_COMPONENT_MAGIC;
59 *face_component = facecomponent;
61 return FACE_ERROR_NONE;
65 EXPORT_API int face_component_destroy(face_component_h face_component)
67 if ( _validate_face_component_h(face_component) == false )
69 LOG_ERROR("Invalid face component. %s", _face_convert_error(FACE_ERROR_INVALID_PARAMTER));
70 return FACE_ERROR_INVALID_PARAMTER;
73 face_component->magic = FACE_INVALID_MAGIC;
77 return FACE_ERROR_NONE;
81 EXPORT_API int face_component_get_face_rect(face_component_h face_component, face_rect_s *face)
83 if ( _validate_face_component_h(face_component) == false )
85 LOG_ERROR("Invalid component handle. %s", _face_convert_error(FACE_ERROR_INVALID_PARAMTER));
86 return FACE_ERROR_INVALID_PARAMTER;
91 LOG_ERROR("[%s] face is NULL", _face_convert_error(FACE_ERROR_INVALID_PARAMTER));
92 return FACE_ERROR_INVALID_PARAMTER;
95 if ( face_component->face.w <= 0 || face_component->face.h <= 0 )
97 LOG_ERROR("[%s] Face is not founded", _face_convert_error(FACE_ERROR_COMPONENT_NOT_FOUND));
98 return FACE_ERROR_COMPONENT_NOT_FOUND;
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;
106 return FACE_ERROR_NONE;
110 EXPORT_API int face_component_get_left_eye_point(face_component_h face_component, face_point_s *leye)
112 if ( _validate_face_component_h(face_component) == false )
114 LOG_ERROR("Invalid component handle. %s", _face_convert_error(FACE_ERROR_INVALID_PARAMTER));
115 return FACE_ERROR_INVALID_PARAMTER;
120 LOG_ERROR("[%s] leye is NULL", _face_convert_error(FACE_ERROR_INVALID_PARAMTER));
121 return FACE_ERROR_INVALID_PARAMTER;
124 if ( face_component->lefteye.x <= 0 || face_component->lefteye.y <= 0 )
126 LOG_ERROR("[%s] Left eye is not founded", _face_convert_error(FACE_ERROR_COMPONENT_NOT_FOUND));
127 return FACE_ERROR_COMPONENT_NOT_FOUND;
130 leye->x = face_component->lefteye.x;
131 leye->y = face_component->lefteye.y;
134 return FACE_ERROR_NONE;
138 EXPORT_API int face_component_get_right_eye_point(face_component_h face_component, face_point_s *reye)
140 if ( _validate_face_component_h(face_component) == false )
142 LOG_ERROR("Invalid component handle. %s", _face_convert_error(FACE_ERROR_INVALID_PARAMTER));
143 return FACE_ERROR_INVALID_PARAMTER;
148 LOG_ERROR("[%s] leye is NULL", _face_convert_error(FACE_ERROR_INVALID_PARAMTER));
149 return FACE_ERROR_INVALID_PARAMTER;
152 if ( face_component->righteye.x <= 0 || face_component->righteye.y <= 0 )
154 LOG_ERROR("[%s] Right eye is not founded", _face_convert_error(FACE_ERROR_COMPONENT_NOT_FOUND));
155 return FACE_ERROR_COMPONENT_NOT_FOUND;
158 reye->x = face_component->righteye.x;
159 reye->y = face_component->righteye.y;
161 return FACE_ERROR_NONE;
165 EXPORT_API int face_component_get_mouse_rect(face_component_h face_component, face_rect_s *mouse)
167 if ( _validate_face_component_h(face_component) == false )
169 LOG_ERROR("Invalid component handle. %s", _face_convert_error(FACE_ERROR_INVALID_PARAMTER));
170 return FACE_ERROR_INVALID_PARAMTER;
175 LOG_ERROR("[%s] mouse is NULL", _face_convert_error(FACE_ERROR_INVALID_PARAMTER));
176 return FACE_ERROR_INVALID_PARAMTER;
179 if ( face_component->mouse.w <= 0 || face_component->mouse.h <= 0 )
181 LOG_ERROR("[%s] Mouse position is not founded", _face_convert_error(FACE_ERROR_COMPONENT_NOT_FOUND));
182 return FACE_ERROR_COMPONENT_NOT_FOUND;
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;
190 return FACE_ERROR_NONE;