From a91cf05de69a3ea213df6abc9270e86b862ed284 Mon Sep 17 00:00:00 2001 From: Ji Yong Min Date: Wed, 16 Dec 2015 14:00:20 +0900 Subject: [PATCH] Modify below issues - remove evas dependency, png/bmp decoding is replaced to new API of image-util - remove unused exif dependency - fix crash when face engine return error - add to support RGBA format (for new API of image-util) - remove unused source code like comment - fix some warnings found by static analyzer Change-Id: I93e6f8ecc9c5e35c0d66ad245ae7974965594771 Signed-off-by: Jiyong Min --- CMakeLists.txt | 4 +- libdcm-face/dcm-face.c | 7 +- libdcm-face/dcm-face_mediavision.c | 16 +- libdcm-face/include/dcm-face_type.h | 1 + libdcm-util/dcm_image_codec.cpp | 371 ++++++++------------------ libdcm-util/include/dcm_image_codec.h | 17 +- packaging/dcm-service.spec | 5 +- src/DcmFaceUtils.cpp | 16 +- src/DcmIpcUtils.cpp | 4 - src/DcmScanSvc.cpp | 50 ++-- svc/CMakeLists.txt | 2 +- svc/DcmMainSvc.cpp | 2 +- 12 files changed, 173 insertions(+), 322 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 480328c..cd3f779 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,8 +41,8 @@ MESSAGE("Build type: ${CMAKE_BUILD_TYPE}") INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/libdcm-util/include ${CMAKE_SOURCE_DIR}/libdcm-face/include) INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED glib-2.0 gthread-2.0 dlog ecore-evas evas sqlite3 capi-media-image-util capi-media-vision libexif media-thumbnail libmedia-utils -mmutil-imgp uuid vconf libtzplatform-config) +pkg_check_modules(pkgs REQUIRED glib-2.0 gthread-2.0 dlog sqlite3 capi-media-image-util capi-media-vision +media-thumbnail libmedia-utils mmutil-imgp uuid vconf libtzplatform-config) FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") diff --git a/libdcm-face/dcm-face.c b/libdcm-face/dcm-face.c index 3f117e2..57dda45 100755 --- a/libdcm-face/dcm-face.c +++ b/libdcm-face/dcm-face.c @@ -34,7 +34,11 @@ EXPORT_API int dcm_face_create(__inout dcm_face_h *handle) dcm_retvm_if(pFaceHandle == NULL, FACE_ERROR_OUT_OF_MEMORY, "malloc fail"); ret = _face_handle_create(&(pFaceHandle->fengine)); - dcm_retvm_if(ret != FACE_ERROR_NONE, ret, "fail to _face_handle_create"); + if (ret != FACE_ERROR_NONE) { + dcm_error("fail to _face_handle_create"); + dcm_face_destroy((dcm_face_h)pFaceHandle); + return ret; + } pFaceHandle->magic = FACE_MAGIC_VALID; @@ -91,6 +95,7 @@ EXPORT_API int dcm_face_set_image_info(dcm_face_h handle, face_image_colorspace_ switch (colorspace) { case FACE_IMAGE_COLORSPACE_YUV420: case FACE_IMAGE_COLORSPACE_RGB888: + case FACE_IMAGE_COLORSPACE_RGBA: data = (unsigned char *)calloc(1, size); memcpy(data, buffer, size); break; diff --git a/libdcm-face/dcm-face_mediavision.c b/libdcm-face/dcm-face_mediavision.c index c1f42f4..b93d8c1 100755 --- a/libdcm-face/dcm-face_mediavision.c +++ b/libdcm-face/dcm-face_mediavision.c @@ -64,20 +64,28 @@ static face_error_e __convert_to_mv_error_e(mv_error_e err) static int __convert_to_mv_colorspace_e(face_image_colorspace_e src, mv_colorspace_e *dst) { + int ret = FACE_ERROR_NONE; + switch (src) { case FACE_IMAGE_COLORSPACE_YUV420: *dst = MEDIA_VISION_COLORSPACE_I420; - return FACE_ERROR_NONE; + break; case FACE_IMAGE_COLORSPACE_RGB888: *dst = MEDIA_VISION_COLORSPACE_RGB888; - return FACE_ERROR_NONE; + break; + case FACE_IMAGE_COLORSPACE_RGBA: + *dst = MEDIA_VISION_COLORSPACE_RGBA; + break; default: *dst = MEDIA_VISION_COLORSPACE_INVALID; dcm_error("Unknown colorspace : %d", src); + ret = FACE_ERROR_INVALID_PARAMTER; break; } - return FACE_ERROR_INVALID_PARAMTER; + dcm_debug("dcm colorspace: %d, mv colorspace: %d", src, *dst); + + return ret; } void __face_detected_cb(mv_source_h source, mv_engine_config_h cfg, mv_rectangle_s *faces_locations, int number_of_faces, void *user_data) @@ -125,7 +133,7 @@ int _face_handle_create(__inout void **handle) dcm_debug_fenter(); - dcm_retvm_if(handle == NULL, FACE_ERROR_OUT_OF_MEMORY, "handle create fail"); + dcm_retvm_if(_handle == NULL, FACE_ERROR_OUT_OF_MEMORY, "handle create fail"); err = mv_create_engine_config(&(_handle->cfg)); if (err != MEDIA_VISION_ERROR_NONE) { diff --git a/libdcm-face/include/dcm-face_type.h b/libdcm-face/include/dcm-face_type.h index 4884cd4..3ac5d17 100755 --- a/libdcm-face/include/dcm-face_type.h +++ b/libdcm-face/include/dcm-face_type.h @@ -52,6 +52,7 @@ typedef enum { typedef enum { FACE_IMAGE_COLORSPACE_YUV420, /**< Y:U:V = 4:2:0 */ FACE_IMAGE_COLORSPACE_RGB888, /**< RGB565, high-byte is Blue */ + FACE_IMAGE_COLORSPACE_RGBA, /**< RGBA8888 */ } face_image_colorspace_e; /** diff --git a/libdcm-util/dcm_image_codec.cpp b/libdcm-util/dcm_image_codec.cpp index 9a3e06a..650a41a 100755 --- a/libdcm-util/dcm_image_codec.cpp +++ b/libdcm-util/dcm_image_codec.cpp @@ -15,193 +15,47 @@ * */ -#include -#include #include #include #include #include -#include #include #include #include #include -int __dcm_decode_image_with_evas(const char *origin_path, - int dest_width, int dest_height, - dcm_image_info *image_info) -{ - dcm_debug_fenter(); - - Ecore_Evas *resize_img_ee; - - resize_img_ee = ecore_evas_buffer_new(dest_width, dest_height); - if (!resize_img_ee) { - dcm_error("ecore_evas_buffer_new failed"); - return DCM_ERROR_CODEC_DECODE_FAILED; - } - - Evas *resize_img_e = ecore_evas_get(resize_img_ee); - if (!resize_img_e) { - dcm_error("ecore_evas_get failed"); - ecore_evas_free(resize_img_ee); - return DCM_ERROR_CODEC_DECODE_FAILED; - } - - Evas_Object *source_img = evas_object_image_add(resize_img_e); - if (!source_img) { - dcm_error("evas_object_image_add failed"); - ecore_evas_free(resize_img_ee); - return DCM_ERROR_CODEC_DECODE_FAILED; - } - - evas_object_image_file_set(source_img, origin_path, NULL); - - /* Get w/h of original image */ - int width = 0; - int height = 0; - - evas_object_image_size_get(source_img, &width, &height); - image_info->origin_width = width; - image_info->origin_height = height; +#define MIME_TYPE_JPEG "image/jpeg" +#define MIME_TYPE_PNG "image/png" +#define MIME_TYPE_BMP "image/bmp" - evas_object_image_load_orientation_set(source_img, 1); +#define OPT_IMAGE_WIDTH 2048 +#define OPT_IMAGE_HEIGHT 1536 - ecore_evas_resize(resize_img_ee, dest_width, dest_height); - - evas_object_image_load_size_set(source_img, dest_width, dest_height); - evas_object_image_fill_set(source_img, 0, 0, dest_width, dest_height); - evas_object_image_filled_set(source_img, 1); - - evas_object_resize(source_img, dest_width, dest_height); - evas_object_show(source_img); - - /* Set alpha from original */ - image_info->alpha = evas_object_image_alpha_get(source_img); - if (image_info->alpha) ecore_evas_alpha_set(resize_img_ee, EINA_TRUE); - - /* Create target buffer and copy origin resized img to it */ - Ecore_Evas *target_ee = ecore_evas_buffer_new(dest_width, dest_height); - if (!target_ee) { - dcm_error("ecore_evas_buffer_new failed"); - ecore_evas_free(resize_img_ee); - return DCM_ERROR_CODEC_DECODE_FAILED; - } - - Evas *target_evas = ecore_evas_get(target_ee); - if (!target_evas) { - dcm_error("ecore_evas_get failed"); - ecore_evas_free(resize_img_ee); - ecore_evas_free(target_ee); - return DCM_ERROR_CODEC_DECODE_FAILED; - } - - Evas_Object *ret_image = evas_object_image_add(target_evas); - evas_object_image_size_set(ret_image, dest_width, dest_height); - evas_object_image_fill_set(ret_image, 0, 0, dest_width, dest_height); - evas_object_image_filled_set(ret_image, EINA_TRUE); - - evas_object_image_data_set(ret_image, (int *)ecore_evas_buffer_pixels_get(resize_img_ee)); - evas_object_image_data_update_add(ret_image, 0, 0, dest_width, dest_height); - - unsigned int buf_size = 0; - int stride = evas_object_image_stride_get(ret_image); - buf_size = (sizeof(unsigned char) * stride * dest_height); - dcm_debug("buf_size: %d", buf_size); - - image_info->size = buf_size; - image_info->width = dest_width; - image_info->height = dest_height; - image_info->data = (unsigned char *)malloc(buf_size); - if (image_info->data == NULL) { - dcm_error("Failed to allocate memory" ); - ecore_evas_free(resize_img_ee); - ecore_evas_free(target_ee); - - return DCM_ERROR_OUT_OF_MEMORY; - } - - void *image_data = evas_object_image_data_get(ret_image, 1); - if (image_data != NULL) { - memcpy(image_info->data, image_data, buf_size); - } else { - dcm_error("image_data is NULL. evas_object_image_data_get failed"); - } - - ecore_evas_free(target_ee); - ecore_evas_free(resize_img_ee); - - dcm_debug_fleave(); - - return DCM_SUCCESS; -} - -static int __dcm_codec_get_image_orientation(const char *path, int *orientation) +static void _dcm_get_optimized_wh(unsigned int src_width, unsigned int src_height, unsigned int *calc_width, unsigned int *calc_height) { - int ret = DCM_SUCCESS; - ExifData *ed = NULL; - ExifEntry *entry = NULL; - int status = 0; - ExifByteOrder byte_order; - - DCM_CHECK_VAL(path, DCM_ERROR_INVALID_PARAMETER); - DCM_CHECK_VAL(orientation, DCM_ERROR_INVALID_PARAMETER); - - ed = exif_data_new_from_file(path); - if (ed == NULL) { - dcm_error("Failed to create new exif data!"); - ret = DCM_ERROR_EXIF_FAILED; - goto DCM_SVC_DB_GET_FACE_ORIENTATION_FAILED; - } - - entry = exif_data_get_entry(ed, EXIF_TAG_ORIENTATION); - if (entry == NULL) { - dcm_warn("Exif entry not exist!"); - *orientation = 0; - ret = DCM_SUCCESS; - goto DCM_SVC_DB_GET_FACE_ORIENTATION_FAILED; - } + *calc_width = 0; + *calc_height = 0; - byte_order = exif_data_get_byte_order(ed); - status = exif_get_short(entry->data, byte_order); - switch (status) { - case 1: - case 2: - *orientation = 0; - break; - case 3: - case 4: - *orientation = 180; - break; - case 5: - case 8: - *orientation = 270; - break; - case 6: - case 7: - *orientation = 90; - break; - default: - *orientation = 0; - break; + if (src_width <= OPT_IMAGE_WIDTH && src_height <= OPT_IMAGE_HEIGHT) { + dcm_debug("Original image is smaller than target image"); + *calc_width = src_width; + *calc_height = src_height; + return; } - dcm_debug("orientation: %d", *orientation); - -DCM_SVC_DB_GET_FACE_ORIENTATION_FAILED: - - if (ed != NULL) { - exif_data_unref(ed); - ed = NULL; + if (src_width > src_height) { + *calc_width = OPT_IMAGE_WIDTH; + *calc_height = (int)(src_height * (((double) OPT_IMAGE_WIDTH) / ((double) src_width))); + } else { + *calc_width = (int)(src_width * (((double) OPT_IMAGE_HEIGHT) / ((double) src_height))); + *calc_height = OPT_IMAGE_HEIGHT; } - - return ret; } -static int __dcm_codec_rotate_by_orientation(const unsigned char *source, unsigned char **image_buffer, unsigned int *buff_width, unsigned int *buff_height, dcm_image_codec_type_e decode_type, int *orientation) +static int _dcm_rotate_image(const unsigned char *source, unsigned char **image_buffer, unsigned int *buff_width, unsigned int *buff_height, dcm_image_codec_type_e decode_type, int orientation) { int ret = IMAGE_UTIL_ERROR_NONE; - image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_I420; + image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_RGBA8888; image_util_rotation_e rotate = IMAGE_UTIL_ROTATION_NONE; unsigned char *rotated_buffer = NULL; unsigned int rotated_buffer_size = 0; @@ -211,21 +65,27 @@ static int __dcm_codec_rotate_by_orientation(const unsigned char *source, unsign if (decode_type == DCM_IMAGE_CODEC_I420) { colorspace = IMAGE_UTIL_COLORSPACE_I420; - } else if (decode_type == DCM_IMAGE_CODEC_RGB888) { + } else if (decode_type == DCM_IMAGE_CODEC_RGB) { colorspace = IMAGE_UTIL_COLORSPACE_RGB888; + } else if (decode_type == DCM_IMAGE_CODEC_RGBA) { + colorspace = IMAGE_UTIL_COLORSPACE_RGBA8888; + } else { + return DCM_ERROR_UNSUPPORTED_IMAGE_TYPE; } /* Get rotate angle enum */ - if (*orientation == 180) { // 3-180 + if (orientation == DEGREE_180) { // 3-180 rotate = IMAGE_UTIL_ROTATION_180; - } else if (*orientation == 90) { // 6-90 + } else if (orientation == DEGREE_90) { // 6-90 rotate = IMAGE_UTIL_ROTATION_90; - } else if (*orientation == 270) { // 8-270 + } else if (orientation == DEGREE_270) { // 8-270 rotate = IMAGE_UTIL_ROTATION_270; } else { rotate = IMAGE_UTIL_ROTATION_NONE; } + dcm_debug("orientation: %d, rotate: %d", orientation, rotate); + if (rotate == IMAGE_UTIL_ROTATION_90 || rotate == IMAGE_UTIL_ROTATION_270) { rotated_width = *buff_height; rotated_height = *buff_width; @@ -282,124 +142,107 @@ static int __dcm_codec_rotate_by_orientation(const unsigned char *source, unsign return DCM_SUCCESS; } -static int __dcm_decode_image_with_size_orient(const char *file_path, unsigned int target_width, unsigned int target_height, - dcm_image_codec_type_e decode_type, unsigned char **image_buffer, unsigned int *buff_width, unsigned int *buff_height, int *orientation, unsigned int *size) +int dcm_decode_image(const char *file_path, + dcm_image_codec_type_e decode_type, const char* mimne_type, bool resize, + unsigned char **image_buffer, unsigned int *buff_width, unsigned int *buff_height, + int orientation, unsigned int *size) { int ret = IMAGE_UTIL_ERROR_NONE; - image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_I420; + image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_RGBA8888; unsigned char *decode_buffer = NULL; + unsigned int decode_width = 0, decode_height = 0; + unsigned char *resize_buffer = NULL; + unsigned int resize_buffer_size = 0; + image_util_decode_h handle = NULL; dcm_debug_fenter(); DCM_CHECK_VAL(file_path, DCM_ERROR_INVALID_PARAMETER); - if (decode_type == DCM_IMAGE_CODEC_I420) { - colorspace = IMAGE_UTIL_COLORSPACE_I420; - } else if (decode_type == DCM_IMAGE_CODEC_RGB888) { - colorspace = IMAGE_UTIL_COLORSPACE_RGB888; + ret = image_util_decode_create(&handle); + if (ret != IMAGE_UTIL_ERROR_NONE) { + dcm_error("Error image_util_decode_create ret : %d", ret); + return DCM_ERROR_IMAGE_UTIL_FAILED; } - /* Extract orientation from exif */ - ret = __dcm_codec_get_image_orientation(file_path, orientation); - if (ret != DCM_SUCCESS) { - dcm_error("Failed to extract orientation! err: %d", ret); - dcm_warn("Set orientation to default!"); - *orientation = 0; + if (strcmp(mimne_type, MIME_TYPE_PNG) == 0) { + DCM_CHECK_VAL((decode_type != DCM_IMAGE_CODEC_RGBA), DCM_ERROR_UNSUPPORTED_IMAGE_TYPE); + } else if (strcmp(mimne_type, MIME_TYPE_BMP) == 0) { + DCM_CHECK_VAL((decode_type != DCM_IMAGE_CODEC_RGBA), DCM_ERROR_UNSUPPORTED_IMAGE_TYPE); + } else if (strcmp(mimne_type, MIME_TYPE_JPEG) == 0) { + if (decode_type == DCM_IMAGE_CODEC_I420) { + colorspace = IMAGE_UTIL_COLORSPACE_I420; + } else if (decode_type == DCM_IMAGE_CODEC_RGB) { + colorspace = IMAGE_UTIL_COLORSPACE_RGB888; + } else if (decode_type == DCM_IMAGE_CODEC_RGBA) { + colorspace = IMAGE_UTIL_COLORSPACE_RGBA8888; + } else { + return DCM_ERROR_UNSUPPORTED_IMAGE_TYPE; + } + ret = image_util_decode_set_colorspace(handle, colorspace); + } else { + dcm_error("Failed not supported mime type! (%s)", mimne_type); + return DCM_ERROR_INVALID_PARAMETER; } - ret = image_util_decode_jpeg(file_path, colorspace, &decode_buffer, (int *)buff_width, (int *)buff_height, size); - dcm_debug("file:%s buffer:%p, size:%u, buff_width:%d, buff_height:%d", file_path, image_buffer, *size, *buff_width, *buff_height); + ret = image_util_decode_set_input_path(handle, file_path); if (ret != IMAGE_UTIL_ERROR_NONE) { - dcm_error("Error image_util_decode_jpeg ret : %d", ret); + dcm_error("Error image_util_decode_set_input_path ret : %d", ret); return DCM_ERROR_IMAGE_UTIL_FAILED; } - /* Rotate the decoded buffer according to orientation */ - if (*orientation == 0) { - *image_buffer = decode_buffer; - } else { - ret = __dcm_codec_rotate_by_orientation(decode_buffer, image_buffer, buff_width, buff_height, decode_type, orientation); - if (ret != DCM_SUCCESS) { - dcm_error("Failed to rotate image buffer! err: %d", ret); - return DCM_ERROR_CODEC_DECODE_FAILED; - } + ret = image_util_decode_set_output_buffer(handle, &decode_buffer); + if (ret != IMAGE_UTIL_ERROR_NONE) { + dcm_error("Error image_util_decode_set_output_buffer ret : %d", ret); + return DCM_ERROR_IMAGE_UTIL_FAILED; } - dcm_debug_fleave(); - - return DCM_SUCCESS; -} - -EXPORT_API -int dcm_decode_image_with_size_orient(const char *file_path, unsigned int target_width, unsigned int target_height, - dcm_image_codec_type_e decode_type, unsigned char **image_buffer, unsigned int *buff_width, unsigned int *buff_height, int *orientation, unsigned int *size) -{ - int ret = DCM_SUCCESS; - - ret = __dcm_decode_image_with_size_orient(file_path, target_width, target_height, decode_type, image_buffer, buff_width, buff_height, orientation, size); - if (ret != DCM_SUCCESS) { - dcm_error("Error _dcm_decode_image_with_size ret : %d", ret); + ret = image_util_decode_run(handle, (unsigned long *)&decode_width, (unsigned long *)&decode_height, (unsigned long long *)size); + if (ret != IMAGE_UTIL_ERROR_NONE) { + dcm_error("Error image_util_decode_run ret : %d", ret); + return DCM_ERROR_IMAGE_UTIL_FAILED; } - return ret; -} - -EXPORT_API -int dcm_decode_image_with_evas(const char *file_path, unsigned int target_width, unsigned int target_height, - dcm_image_codec_type_e decode_type, unsigned char **image_buffer, unsigned int *buff_width, unsigned int *buff_height, int *orientation, unsigned int *size) -{ - int ret = DCM_SUCCESS; - dcm_image_info image_info = {0, }; - image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_I420; - mm_util_img_format mm_colorspace = MM_UTIL_IMG_FMT_I420; - - DCM_CHECK_VAL(file_path, DCM_ERROR_INVALID_PARAMETER); + ret = image_util_decode_destroy(handle); + if (ret != IMAGE_UTIL_ERROR_NONE) { + dcm_error("Error image_util_decode_destroy ret : %d", ret); + return DCM_ERROR_IMAGE_UTIL_FAILED; + } - memset(&image_info, 0, sizeof(image_info)); - if (decode_type == DCM_IMAGE_CODEC_I420) { - colorspace = IMAGE_UTIL_COLORSPACE_I420; - mm_colorspace = MM_UTIL_IMG_FMT_I420; - } else if (decode_type == DCM_IMAGE_CODEC_RGB888) { - colorspace = IMAGE_UTIL_COLORSPACE_RGB888; - mm_colorspace = MM_UTIL_IMG_FMT_RGB888; - } - ret = __dcm_decode_image_with_evas(file_path, target_width, target_height, &image_info); - if (ret != DCM_SUCCESS) { - dcm_error("Error __dcm_decode_image_with_evas ret : %d", ret); - *buff_width = 0; - *buff_height = 0; - *orientation = 0; - *size = 0; - *image_buffer = NULL; - return DCM_ERROR_CODEC_DECODE_FAILED; + /* Get the optimized width/height to enhance performance for big size image */ + if (resize) { + _dcm_get_optimized_wh(decode_width, decode_height, buff_width, buff_height); + } else { + *buff_width = decode_width; + *buff_height = decode_height; } - *buff_width = image_info.width; - *buff_height = image_info.height; - *orientation = 0; - image_util_calculate_buffer_size(*buff_width, *buff_height, colorspace, size); - *image_buffer = (unsigned char *)malloc(sizeof(unsigned char) * (*size)); - if (*image_buffer == NULL) { - dcm_error("Error buffer allocation"); - DCM_SAFE_FREE(image_info.data); - return DCM_ERROR_CODEC_DECODE_FAILED; + /* Resize the big size image to enhance performance for big size image */ + if ((decode_width != *buff_width) || (decode_height != *buff_height)) { + ret = image_util_calculate_buffer_size(*buff_width, *buff_height, colorspace, &resize_buffer_size); + if (ret != DCM_SUCCESS) { + dcm_error("Failed to calculate image buffer size! err: %d", ret); + return DCM_ERROR_CODEC_DECODE_FAILED; + } + resize_buffer = (unsigned char *)malloc(sizeof(unsigned char) * (resize_buffer_size)); + mm_util_resize_image(decode_buffer, decode_width, decode_height, MM_UTIL_IMG_FMT_RGBA8888, resize_buffer, buff_width, buff_height); + } else { + resize_buffer = decode_buffer; } - int err = 0; - err = mm_util_convert_colorspace(image_info.data, - image_info.width, - image_info.height, - MM_UTIL_IMG_FMT_BGRA8888, - *image_buffer, - mm_colorspace); - - if (err < 0) { - dcm_error("Failed to change from argb888 to %d. (%d)", mm_colorspace, err); - DCM_SAFE_FREE(*image_buffer); - *image_buffer = NULL; - ret = DCM_ERROR_CODEC_DECODE_FAILED; + + /* Rotate the resized buffer according to orientation */ + if (orientation == 0) { + *image_buffer = resize_buffer; + } else { + ret = _dcm_rotate_image(resize_buffer, image_buffer, buff_width, buff_height, decode_type, orientation); + if (ret != DCM_SUCCESS) { + dcm_error("Failed to rotate image buffer! err: %d", ret); + return DCM_ERROR_CODEC_DECODE_FAILED; + } } - DCM_SAFE_FREE(image_info.data); - return ret; + dcm_debug_fleave(); + + return DCM_SUCCESS; } diff --git a/libdcm-util/include/dcm_image_codec.h b/libdcm-util/include/dcm_image_codec.h index a8eb061..0281a72 100755 --- a/libdcm-util/include/dcm_image_codec.h +++ b/libdcm-util/include/dcm_image_codec.h @@ -18,13 +18,19 @@ #ifndef _DCM_IMAGE_CODEC_H_ #define _DCM_IMAGE_CODEC_H_ +#define DEGREE_0 0 +#define DEGREE_90 1 +#define DEGREE_180 2 +#define DEGREE_270 3 + #ifdef __cplusplus extern "C" { #endif typedef enum { DCM_IMAGE_CODEC_I420, - DCM_IMAGE_CODEC_RGB888, + DCM_IMAGE_CODEC_RGB, + DCM_IMAGE_CODEC_RGBA, } dcm_image_codec_type_e; typedef struct { @@ -38,12 +44,9 @@ typedef struct { } dcm_image_info; -/* Decoding image with input width and height, if possible (width/height ratio is kept the same as original), and rotate the buffer according to orientation */ -int dcm_decode_image_with_size_orient(const char *file_path, unsigned int target_width, unsigned int target_height, - dcm_image_codec_type_e decode_type, unsigned char **image_buffer, unsigned int *buff_width, unsigned int *buff_height, int *orientation, unsigned int *size); - -int dcm_decode_image_with_evas(const char *file_path, unsigned int target_width, unsigned int target_height, - dcm_image_codec_type_e decode_type, unsigned char **image_buffer, unsigned int *buff_width, unsigned int *buff_height, int *orientation, unsigned int *size); +int dcm_decode_image(const char *file_path, dcm_image_codec_type_e decode_type, const char* mimne_type, + bool resize, unsigned char **image_buffer, unsigned int *buff_width, unsigned int *buff_height, + int orientation, unsigned int *size); #ifdef __cplusplus } diff --git a/packaging/dcm-service.spec b/packaging/dcm-service.spec index 6589b81..3c3e068 100755 --- a/packaging/dcm-service.spec +++ b/packaging/dcm-service.spec @@ -1,6 +1,6 @@ Name: dcm-service Summary: Multimedia DCM(Digital Contents Management) Service -Version: 0.0.1 +Version: 0.0.2 Release: 0 Group: Multimedia/Service License: Apache-2.0 @@ -14,9 +14,6 @@ BuildRequires: cmake BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(gthread-2.0) BuildRequires: pkgconfig(dlog) -BuildRequires: pkgconfig(ecore-evas) -BuildRequires: pkgconfig(evas) -BuildRequires: pkgconfig(libexif) BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgconfig(capi-media-image-util) BuildRequires: pkgconfig(capi-media-vision) diff --git a/src/DcmFaceUtils.cpp b/src/DcmFaceUtils.cpp index 853591b..4ff22d6 100755 --- a/src/DcmFaceUtils.cpp +++ b/src/DcmFaceUtils.cpp @@ -115,7 +115,12 @@ int DcmFaceUtils::runFaceRecognizeProcess(DcmScanItem *scan_item, DcmImageInfo * goto DCM_SVC_FACE_RECOGNIZE_BUFFER_FAILED; } - face_info = (face_info_s*)g_malloc0(sizeof(face_info_s)); + face_info = (face_info_s *)g_malloc0(sizeof(face_info_s)); + if (face_info == NULL) { + dcm_error("Failed to allocate face info"); + ret = DCM_ERROR_OUT_OF_MEMORY; + goto DCM_SVC_FACE_RECOGNIZE_BUFFER_FAILED; + } err = dcm_face_get_face_info(dcm_face_handle, face_info); if (err != FACE_ERROR_NONE) { @@ -175,10 +180,8 @@ int DcmFaceUtils::runFaceRecognizeProcess(DcmScanItem *scan_item, DcmImageInfo * } /* Send db updated notification */ - if (face != NULL) { - DcmFaceApi::freeDcmFaceItem(face); - face = NULL; - } + DcmFaceApi::freeDcmFaceItem(face); + face = NULL; } DCM_SVC_FACE_RECOGNIZE_BUFFER_FAILED: @@ -188,9 +191,8 @@ DCM_SVC_FACE_RECOGNIZE_BUFFER_FAILED: dcm_error("Failed to insert face item into face_scan_list! err: %d", err); } - if (face_info != NULL) { + if (face_info != NULL && face_info->count > 0) { dcm_face_destroy_face_info(face_info); - face_info = NULL; } if (face != NULL) { diff --git a/src/DcmIpcUtils.cpp b/src/DcmIpcUtils.cpp index c56a6ad..f90666b 100755 --- a/src/DcmIpcUtils.cpp +++ b/src/DcmIpcUtils.cpp @@ -127,10 +127,6 @@ int DcmIpcUtils::createSocket(int *socket_fd, DcmIpcPortType port) /* change permission of local socket file */ if (chmod(DCM_IPC_PATH[port], 0660) < 0) dcm_error("chmod failed [%s]", strerror(errno)); - /* - if (chown(DCM_IPC_PATH[port], 0, 5000) < 0) - dcm_dbgE("chown failed [%s]", strerror(errno)); - */ *socket_fd = sock; diff --git a/src/DcmScanSvc.cpp b/src/DcmScanSvc.cpp index 787e4a2..62f0afe 100755 --- a/src/DcmScanSvc.cpp +++ b/src/DcmScanSvc.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #define MIME_TYPE_JPEG "image/jpeg" #define MIME_TYPE_PNG "image/png" @@ -202,8 +201,6 @@ int DcmScanSvc::initialize() DcmFaceUtils::initialize(); - ecore_evas_init(); - return DCM_SUCCESS; } @@ -214,8 +211,6 @@ int DcmScanSvc::finalize() clearSingleItemList(); DcmFaceUtils::finalize(); - ecore_evas_shutdown(); - return DCM_SUCCESS; } @@ -265,7 +260,7 @@ int DcmScanSvc::runScanProcess(DcmScanItem *scan_item) DcmImageInfo image_info = {0, }; memset(&image_info, 0, sizeof(DcmImageInfo)); - dcm_image_codec_type_e image_format = DCM_IMAGE_CODEC_RGB888; + dcm_image_codec_type_e image_format = DCM_IMAGE_CODEC_RGBA; /* Process scan operation if the file exists */ if (g_file_test(scan_item->file_path, (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) == TRUE) { @@ -295,6 +290,7 @@ int DcmScanSvc::runScanProcess(DcmScanItem *scan_item) image_info.original_width = scan_item->image_width; image_info.original_height = scan_item->image_height; + image_info.orientation = scan_item->image_orientation; dcm_debug("scan media w : [%d], h : [%d], orientation : [%d]", image_info.original_width, image_info.original_height, scan_item->image_orientation); @@ -308,24 +304,21 @@ int DcmScanSvc::runScanProcess(DcmScanItem *scan_item) dcm_debug("ImgGetImageInfo type: %d, width: %d, height: %d", type, image_info.original_width, image_info.original_height); } - if (strcmp(scan_item->mime_type, MIME_TYPE_JPEG) == 0) { - ret = dcm_decode_image_with_size_orient((const char *) (scan_item->file_path), image_info.original_width, - image_info.original_height, image_format, &(image_info.pixel), &(image_info.buffer_width), &(image_info.buffer_height), &(image_info.orientation), &(image_info.size)); - if (ret != DCM_SUCCESS) { - dcm_error("Failed dcm_decode_image_with_size_orient! err: %d", ret); - return ret; - } - } else if ((strcmp(scan_item->mime_type, MIME_TYPE_PNG) == 0) || (strcmp(scan_item->mime_type, MIME_TYPE_BMP) == 0)) { - ret = dcm_decode_image_with_evas((const char *) (scan_item->file_path), image_info.original_width, - image_info.original_height, image_format, &(image_info.pixel), &(image_info.buffer_width), &(image_info.buffer_height), &(image_info.orientation), &(image_info.size)); + if ((strcmp(scan_item->mime_type, MIME_TYPE_JPEG) == 0) || + (strcmp(scan_item->mime_type, MIME_TYPE_PNG) == 0) || + (strcmp(scan_item->mime_type, MIME_TYPE_BMP) == 0)) { + ret = dcm_decode_image((const char *) (scan_item->file_path), + image_format, scan_item->mime_type, FALSE, &(image_info.pixel), + &(image_info.buffer_width), &(image_info.buffer_height), image_info.orientation, &(image_info.size)); if (ret != DCM_SUCCESS) { - dcm_error("Failed dcm_decode_image_with_evas! err: %d", ret); + dcm_error("Failed dcm_decode_image! err: %d", ret); return ret; } } else { dcm_error("Failed not supported type! (%s)", scan_item->mime_type); return DCM_ERROR_INVALID_PARAMETER; } + image_info.decode_type = (DcmImageDecodeType)image_format; dcm_debug("Image info width: %d, height: %d, buf_width: %d, buf_height: %d, orientation: %d", @@ -337,14 +330,13 @@ int DcmScanSvc::runScanProcess(DcmScanItem *scan_item) dcm_error("Failed to process face detection! err: %d", ret); } - /* Set sleep time after face recognition */ - usleep(500000); - +#if 0 /* Process color extract */ ret = DcmColorUtils::runColorExtractProcess(scan_item, &image_info); if (ret != DCM_SUCCESS) { dcm_error("Failed to process color extraction! err: %d", ret); } +#endif /* Free image buffer */ DCM_SAFE_FREE(image_info.pixel); @@ -577,6 +569,10 @@ gboolean DcmScanCallback::readyScanThreadIdle(gpointer data) DCM_CHECK_FALSE(ad->scan_thread_ready); async_queue_msg = (DcmIpcMsg*) g_malloc0(sizeof(DcmIpcMsg)); + if (async_queue_msg == NULL) { + dcm_error("memory allocation failed"); + return FALSE; + } async_queue_msg->msg_type = DCM_IPC_MSG_SCAN_READY; dcm_debug("scan thread ready : %p", ad->scan_thread_ready); @@ -625,13 +621,6 @@ gboolean DcmScanMain::runScanThread(void *data) DCM_CHECK_VAL(data, DCM_ERROR_INVALID_PARAMETER); - /* Init global variables */ - err = dcmScanSvc.initialize(); - if (err != DCM_SUCCESS) { - dcm_error("Failed to initialize scan thread global variable! err: %d", err); - goto DCM_SVC_SCAN_CREATE_SCAN_THREAD_FAILED; - } - /* Create TCP Socket to receive message from main thread */ err = DcmIpcUtils::createSocket(&socket_fd, DCM_IPC_PORT_SCAN_RECV); if (err != DCM_SUCCESS) { @@ -640,6 +629,13 @@ gboolean DcmScanMain::runScanThread(void *data) } dcm_sec_warn("scan thread recv socket: %d", socket_fd); + /* Init global variables */ + err = dcmScanSvc.initialize(); + if (err != DCM_SUCCESS) { + dcm_error("Failed to initialize scan thread global variable! err: %d", err); + goto DCM_SVC_SCAN_CREATE_SCAN_THREAD_FAILED; + } + /* Create a new main context for scan thread */ context = g_main_context_new(); dcmScanSvc.scan_thread_main_context = context; diff --git a/svc/CMakeLists.txt b/svc/CMakeLists.txt index fe59a47..5d54a51 100755 --- a/svc/CMakeLists.txt +++ b/svc/CMakeLists.txt @@ -2,7 +2,7 @@ SET(fw_name "dcm-service") SET(DCM_SERVER "dcm-svc") INCLUDE(FindPkgConfig) -pkg_check_modules(${DCM_SERVER} REQUIRED dlog glib-2.0 gthread-2.0 libmedia-utils libexif libtzplatform-config sqlite3) +pkg_check_modules(${DCM_SERVER} REQUIRED dlog glib-2.0 gthread-2.0 libmedia-utils libtzplatform-config sqlite3) FOREACH(flag ${${DCM_SERVER}_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") diff --git a/svc/DcmMainSvc.cpp b/svc/DcmMainSvc.cpp index cc2b792..0de091f 100755 --- a/svc/DcmMainSvc.cpp +++ b/svc/DcmMainSvc.cpp @@ -58,7 +58,7 @@ static DcmMainSvc* DcmMainSvc::getInstance(void) void DcmMainSvc::dcmServiceStartjobs(void) { - /* Send ready response to thumbnail-server */ + /* Send ready response to dcm launcher */ if (DcmIpcUtils::sendSocketMsg(DCM_IPC_MSG_SERVICE_READY, 0, NULL, DCM_IPC_PORT_THUMB_RECV) != DCM_SUCCESS) { dcm_error("Failed to send ready message"); } -- 2.34.1