From 9643ccdb18141fc240827b6b0f36006a347553b3 Mon Sep 17 00:00:00 2001 From: hj kim Date: Thu, 1 Feb 2018 17:42:50 +0900 Subject: [PATCH] Use new image_util(magicK) APIs instead of Old one Change-Id: Ia554632d366dd26289ee9d543993793c22ee73d7 --- CMakeLists.txt | 4 +- include/dcm_svc_internal.h | 2 +- libdcm-face/dcm-face.c | 2 +- libdcm-face/dcm-face_mediavision.c | 2 +- libdcm-face/dcm-face_priv.h | 2 +- libdcm-face/include/dcm-face.h | 3 +- libdcm-util/dcm_image_codec.c | 305 ++++++-------------------- libdcm-util/include/dcm_image_codec.h | 4 +- packaging/dcm-service.spec | 2 +- src/dcm_svc_internal.c | 5 +- 10 files changed, 79 insertions(+), 252 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ed1199..7721000 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,8 +40,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 dlog sqlite3 capi-media-image-util capi-media-vision - libmedia-utils libtzplatform-config) +pkg_check_modules(pkgs REQUIRED glib-2.0 dlog sqlite3 capi-media-vision + libmedia-utils libtzplatform-config mmutil-magick) FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") diff --git a/include/dcm_svc_internal.h b/include/dcm_svc_internal.h index 677825d..08b3fe1 100755 --- a/include/dcm_svc_internal.h +++ b/include/dcm_svc_internal.h @@ -32,7 +32,7 @@ typedef struct { typedef struct { unsigned char *pixel; /* decoding results, must be freed after use */ - unsigned long long size; + size_t size; int orientation; /* orientation information extracted from exif */ unsigned int original_width; /* original image width */ unsigned int original_height; /* original image height */ diff --git a/libdcm-face/dcm-face.c b/libdcm-face/dcm-face.c index 31245ed..92784b7 100755 --- a/libdcm-face/dcm-face.c +++ b/libdcm-face/dcm-face.c @@ -70,7 +70,7 @@ EXPORT_API int dcm_face_destroy(__in dcm_face_h handle) return ret; } -EXPORT_API int dcm_face_set_image_info(dcm_face_h handle, face_image_colorspace_e colorspace, unsigned char *buffer, unsigned int width, unsigned int height, unsigned long long size) +EXPORT_API int dcm_face_set_image_info(dcm_face_h handle, face_image_colorspace_e colorspace, unsigned char *buffer, unsigned int width, unsigned int height, size_t size) { FaceHandleT *_handle = (FaceHandleT *)handle; unsigned char *data = NULL; diff --git a/libdcm-face/dcm-face_mediavision.c b/libdcm-face/dcm-face_mediavision.c index a2a90bc..6a35989 100755 --- a/libdcm-face/dcm-face_mediavision.c +++ b/libdcm-face/dcm-face_mediavision.c @@ -205,7 +205,7 @@ int _face_detect_faces(__in dcm_face_h handle, __out face_rect_s *face_rect[], _ __convert_to_mv_colorspace_e(handle->image_info->colorspace, &colorspace); - dcm_debug("face_detect image: %p, size: %llu, width: %d, height: %d, color: %d", handle->image_info->data, handle->image_info->size, handle->image_info->width, handle->image_info->height, colorspace); + dcm_debug("face_detect image: %p, size: %zu, width: %d, height: %d, color: %d", handle->image_info->data, handle->image_info->size, handle->image_info->width, handle->image_info->height, colorspace); err = mv_source_fill_by_buffer(_fengine->source, handle->image_info->data, (unsigned int)(handle->image_info->size), handle->image_info->width, handle->image_info->height, colorspace); if (err != MEDIA_VISION_ERROR_NONE) { diff --git a/libdcm-face/dcm-face_priv.h b/libdcm-face/dcm-face_priv.h index d3b2a24..887a625 100755 --- a/libdcm-face/dcm-face_priv.h +++ b/libdcm-face/dcm-face_priv.h @@ -36,7 +36,7 @@ typedef struct face_image_s { unsigned char *data; unsigned int width; unsigned int height; - unsigned long long size; + size_t size; face_image_colorspace_e colorspace; unsigned int magic; } FaceImage; diff --git a/libdcm-face/include/dcm-face.h b/libdcm-face/include/dcm-face.h index b411ba5..1b4d89d 100755 --- a/libdcm-face/include/dcm-face.h +++ b/libdcm-face/include/dcm-face.h @@ -16,6 +16,7 @@ #ifndef __TIZEN_DCM_FACE_H__ #define __TIZEN_DCM_FACE_H__ +#include #include #include "dcm-face_type.h" @@ -78,7 +79,7 @@ int dcm_face_get_prefered_colorspace(dcm_face_h handle, face_image_colorspace_e * @retval #MS_MEDIA_ERR_OUT_OF_MEMORY Out of memory * @see dcm_face_create() */ -int dcm_face_set_image_info(dcm_face_h handle, face_image_colorspace_e colorspace, unsigned char *buffer, unsigned int width, unsigned int height, unsigned long long size); +int dcm_face_set_image_info(dcm_face_h handle, face_image_colorspace_e colorspace, unsigned char *buffer, unsigned int width, unsigned int height, size_t size); /** * @brief Gets the face information of detected faces. diff --git a/libdcm-util/dcm_image_codec.c b/libdcm-util/dcm_image_codec.c index 2a51764..3809c52 100755 --- a/libdcm-util/dcm_image_codec.c +++ b/libdcm-util/dcm_image_codec.c @@ -16,10 +16,9 @@ */ -#include -#include #include #include +#include #define OPT_IMAGE_WIDTH 1280 #define OPT_IMAGE_HEIGHT 720 @@ -36,7 +35,7 @@ typedef enum { ROT_270 = 8 } dcm_exif_orientation_e; -static void __dcm_get_optimized_wh(unsigned int src_width, unsigned int src_height, unsigned int *calc_width, unsigned int *calc_height) +static bool __dcm_get_optimized_wh(unsigned int src_width, unsigned int src_height, unsigned int *calc_width, unsigned int *calc_height) { *calc_width = 0; *calc_height = 0; @@ -45,7 +44,7 @@ static void __dcm_get_optimized_wh(unsigned int src_width, unsigned int src_heig dcm_debug("Original image is smaller than target image"); *calc_width = src_width; *calc_height = src_height; - return; + return FALSE; } if (src_width > src_height) { @@ -55,263 +54,93 @@ static void __dcm_get_optimized_wh(unsigned int src_width, unsigned int src_heig *calc_width = (int)(src_width * (((double) OPT_IMAGE_HEIGHT) / ((double) src_height))); *calc_height = OPT_IMAGE_HEIGHT; } -} - -static int __dcm_rotate_image(const unsigned char *source, const dcm_image_format_e format, dcm_exif_orientation_e orientation, unsigned char **image_buffer, unsigned long long *size, unsigned int *buff_width, unsigned int *buff_height) -{ - int ret = IMAGE_UTIL_ERROR_NONE; - 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; - int rotated_width = 0, rotated_height = 0; - - DCM_CHECK_VAL(source, MS_MEDIA_ERR_INVALID_PARAMETER); - - if (format == DCM_IMAGE_FORMAT_I420) - colorspace = IMAGE_UTIL_COLORSPACE_I420; - else if (format == DCM_IMAGE_FORMAT_RGB) - colorspace = IMAGE_UTIL_COLORSPACE_RGB888; - else if (format == DCM_IMAGE_FORMAT_RGBA) - colorspace = IMAGE_UTIL_COLORSPACE_RGBA8888; - else - return MS_MEDIA_ERR_UNSUPPORTED_CONTENT; - - /* Get rotate angle enum */ - if (orientation == ROT_180) - rotate = IMAGE_UTIL_ROTATION_180; - else if (orientation == ROT_90) - rotate = IMAGE_UTIL_ROTATION_90; - else if (orientation == ROT_270) - rotate = IMAGE_UTIL_ROTATION_270; - else if (orientation == HFLIP) - rotate = IMAGE_UTIL_ROTATION_FLIP_HORZ; - else if (orientation == VFLIP) - rotate = IMAGE_UTIL_ROTATION_FLIP_VERT; - 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; - } else { - rotated_width = *buff_width; - rotated_height = *buff_height; - } - - /* Calculate the rotated buffer size */ - ret = image_util_calculate_buffer_size(rotated_width, rotated_height, colorspace, &rotated_buffer_size); - if (ret != IMAGE_UTIL_ERROR_NONE) { - dcm_error("Failed to calculate buffer size! err: %d", ret); - return MS_MEDIA_ERR_INTERNAL; - } - - /* Allocate rotated buffer */ - if (rotated_buffer_size <= 0) { - dcm_error("Invalid rotated buffer size!"); - return MS_MEDIA_ERR_INTERNAL; - } - - dcm_debug("rotate buffer size: %u", rotated_buffer_size); - rotated_buffer = (unsigned char *) g_malloc0(rotated_buffer_size); - if (rotated_buffer == NULL) { - dcm_error("rotated_buffer is NULL!"); - return MS_MEDIA_ERR_INTERNAL; - } - - *size = rotated_buffer_size; - - /* Rotate input buffer */ - ret = image_util_rotate(rotated_buffer, &rotated_width, &rotated_height, rotate, source, *buff_width, *buff_height, colorspace); - - if (ret != IMAGE_UTIL_ERROR_NONE || rotated_buffer == NULL) { - dcm_error("Failed to rotate image buffer! err: %d", ret); - DCM_SAFE_FREE(rotated_buffer); - return MS_MEDIA_ERR_INTERNAL; - } - - /* Decoded buffer size is set to rotated buffer size to match buffer */ - dcm_debug("After rotation: [width: %d] [height: %d]", rotated_width, rotated_height); - *buff_width = rotated_width; - *buff_height = rotated_height; - - /* Allocated data should be freed when scanning is finished for this rotated image */ - *image_buffer = rotated_buffer; - dcm_warn("rotated decode buffer: %p", *image_buffer); - - return MS_MEDIA_ERR_NONE; + return TRUE; } -static int __dcm_rotate_rgb(unsigned char *source, const unsigned long long *size, int format, unsigned int *ori_width, unsigned int *ori_height) -{ - unsigned int dpp = 0; /* data per pixel */ - unsigned int x = 0, y = 0; - unsigned int i = 0; - unsigned int width = 0, height = 0; - unsigned char *temp_buf = NULL; - size_t _size = (size_t)*size; - - if (format == DCM_IMAGE_FORMAT_RGBA) { - dpp = 4; - } else if (format == DCM_IMAGE_FORMAT_RGB) { - dpp = 3; - } else { - dcm_error("Invalid parameter"); - return MS_MEDIA_ERR_INVALID_PARAMETER; - } - - temp_buf = (unsigned char*)g_malloc0(_size); - if (temp_buf == NULL) { - dcm_error("Failed to allocate memory"); - return MS_MEDIA_ERR_OUT_OF_MEMORY; - } - - width = *ori_width; - height = *ori_height; - - /* rotate image to 90 degree clockwise */ - for (y = 0; y < height; y++) { - for (x = 0; x < width; x++) { - for (i = 0; i < dpp; i++) - temp_buf[(x * height + (height - y - 1)) * dpp + i] = source[(y * width + x) * dpp + i]; - } - } - - /* copy image from temp buffer to original buffer */ - memcpy(source, temp_buf, _size); - DCM_SAFE_FREE(temp_buf); - - /* swap width & height due to rotate 90 degree */ - *ori_width = height; - *ori_height = width; - - return MS_MEDIA_ERR_NONE; -} - -int dcm_decode_image(const char *file_path, const dcm_image_format_e format, - const char* mimne_type, const int orientation, const gboolean resize, - unsigned char **image_buffer, unsigned long long *size, +int dcm_decode_image(const char *file_path, const int orientation, const gboolean resize, unsigned char **image_buffer, size_t *size, unsigned int *buff_width, unsigned int *buff_height) { - int ret = IMAGE_UTIL_ERROR_NONE; - 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 buffer_size = 0; - image_util_decode_h handle = NULL; + int ret = MS_MEDIA_ERR_NONE; + unsigned int width = 0; + unsigned int height = 0; + unsigned int resized_width = 0; + unsigned int resized_height = 0; + mm_util_img_codec_type type = IMG_CODEC_UNKNOWN_TYPE; + mm_util_magick_rotate_type angle = MM_UTIL_ROTATE_NUM; + mm_util_image_h resize_dst_handle = NULL; + mm_util_image_h dst_handle = NULL; + mm_util_magick_format format = MM_UTIL_IMG_FMT_NUM; dcm_debug_fenter(); DCM_CHECK_VAL(file_path, MS_MEDIA_ERR_INVALID_PARAMETER); - ret = image_util_decode_create(&handle); - if (ret != IMAGE_UTIL_ERROR_NONE) { - dcm_error("Error image_util_decode_create ret : %d", ret); - return MS_MEDIA_ERR_INTERNAL; - } - - ret = image_util_decode_set_input_path(handle, file_path); - if (ret != IMAGE_UTIL_ERROR_NONE) { - dcm_error("Error image_util_decode_set_input_path ret : %d", ret); - image_util_decode_destroy(handle); - return MS_MEDIA_ERR_INTERNAL; - } - - if (strcmp(mimne_type, MIME_TYPE_JPEG) == 0) { - if (format == DCM_IMAGE_FORMAT_I420) { - colorspace = IMAGE_UTIL_COLORSPACE_I420; - } else if (format == DCM_IMAGE_FORMAT_RGB) { - colorspace = IMAGE_UTIL_COLORSPACE_RGB888; - } else if (format == DCM_IMAGE_FORMAT_RGBA) { - colorspace = IMAGE_UTIL_COLORSPACE_RGBA8888; - } else { - image_util_decode_destroy(handle); - return MS_MEDIA_ERR_UNSUPPORTED_CONTENT; - } - ret = image_util_decode_set_colorspace(handle, colorspace); - if (ret != IMAGE_UTIL_ERROR_NONE) { - dcm_error("Error image_util_decode_set_colorspace ret : %d", ret); - image_util_decode_destroy(handle); - return MS_MEDIA_ERR_INTERNAL; - } - } - - 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); - image_util_decode_destroy(handle); - return MS_MEDIA_ERR_INTERNAL; - } - - ret = image_util_decode_run(handle, (unsigned long *)&decode_width, (unsigned long *)&decode_height, size); - if (ret != IMAGE_UTIL_ERROR_NONE) { - dcm_error("Error image_util_decode_run ret : %d", ret); - image_util_decode_destroy(handle); - return MS_MEDIA_ERR_INTERNAL; - } - - ret = image_util_decode_destroy(handle); - if (ret != IMAGE_UTIL_ERROR_NONE) { - dcm_error("Error image_util_decode_destroy ret : %d", ret); + if (orientation == NOT_AVAILABLE || orientation == NORMAL) + angle = MM_UTIL_ROTATE_0; + else if (orientation == ROT_90) + angle = MM_UTIL_ROTATE_90; + else if (orientation == ROT_180) + angle = MM_UTIL_ROTATE_180; + else if (orientation == ROT_270) + angle = MM_UTIL_ROTATE_270; + else if (orientation == HFLIP) + angle = MM_UTIL_ROTATE_FLIP_HORZ; + else if (orientation == VFLIP) + angle = MM_UTIL_ROTATE_FLIP_VERT; + else { + dcm_error("Not supported angle [%d]", orientation); return MS_MEDIA_ERR_INTERNAL; } - - /* 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; - } - - /* 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, &buffer_size); - if (ret != IMAGE_UTIL_ERROR_NONE) { - dcm_error("Failed to calculate image buffer size! err: %d", ret); - return MS_MEDIA_ERR_INTERNAL; - } + /* Get the optimized width/height to enhance performance for big size image */ + ret = mm_util_extract_image_info(file_path, &type, &width, &height); + if (ret != MM_UTIL_ERROR_NONE) + dcm_error("Failed to get image info!err: %d", ret); + + if (__dcm_get_optimized_wh(width, height, &resized_width, &resized_height)) { + /* Resize the big size image to enhance performance for big size image */ + ret = mm_util_resize_P_B(file_path, resized_width, resized_height, MM_UTIL_IMG_FMT_RGBA8888, &resize_dst_handle); + if (ret != MM_UTIL_ERROR_NONE) { + dcm_error("Failed to resize image!err: %d", ret); + ret = MS_MEDIA_ERR_INTERNAL; + goto ERROR; + } - *size = buffer_size; - resize_buffer = (unsigned char *)g_malloc0(sizeof(unsigned char) * (buffer_size)); - if (resize_buffer != NULL) { - ret = image_util_resize(resize_buffer, (int *)buff_width, (int *)buff_height, decode_buffer, decode_width, decode_height, colorspace); - DCM_SAFE_FREE(decode_buffer); - if (ret != IMAGE_UTIL_ERROR_NONE) { - dcm_error("Failed to image_util_resize"); - DCM_SAFE_FREE(resize_buffer); - return MS_MEDIA_ERR_INTERNAL; + ret = mm_util_rotate_B_B(resize_dst_handle, angle, &dst_handle); + if (ret != MM_UTIL_ERROR_NONE) { + dcm_error("Failed to rotate image!err: %d", ret); + ret = MS_MEDIA_ERR_INTERNAL; + goto ERROR; } } else { - dcm_error("Failed to allocation"); - return MS_MEDIA_ERR_OUT_OF_MEMORY; + ret = mm_util_rotate_P_B(file_path, angle, MM_UTIL_IMG_FMT_RGBA8888, &dst_handle); + if (ret != MM_UTIL_ERROR_NONE) { + dcm_error("Failed to rotate image buffer! err: %d", ret); + ret = MS_MEDIA_ERR_INTERNAL; + goto ERROR; + } } } else { - resize_buffer = decode_buffer; - } - - /* Rotate the resized buffer according to orientation */ - if (orientation == NOT_AVAILABLE || orientation == NORMAL) { - *image_buffer = resize_buffer; - } else { - if ((format == DCM_IMAGE_FORMAT_RGBA) || (format == DCM_IMAGE_FORMAT_RGB)) { - ret = __dcm_rotate_rgb(resize_buffer, size, format, buff_width, buff_height); - *image_buffer = resize_buffer; - } else { - ret = __dcm_rotate_image(resize_buffer, format, orientation, image_buffer, size, buff_width, buff_height); - DCM_SAFE_FREE(resize_buffer); - } - if (ret != MS_MEDIA_ERR_NONE) { + ret = mm_util_rotate_P_B(file_path, angle, MM_UTIL_IMG_FMT_RGBA8888, &dst_handle); + if (ret != MM_UTIL_ERROR_NONE) { dcm_error("Failed to rotate image buffer! err: %d", ret); - return MS_MEDIA_ERR_INTERNAL; + ret = MS_MEDIA_ERR_INTERNAL; + goto ERROR; } } + mm_util_get_image(dst_handle, image_buffer, buff_width, buff_height, size, &format); + +ERROR: + if (resize_dst_handle != NULL) + mm_util_destroy_handle(resize_dst_handle); + + if (dst_handle != NULL) + mm_util_destroy_handle(dst_handle); + dcm_debug_fleave(); - return MS_MEDIA_ERR_NONE; + return ret; } diff --git a/libdcm-util/include/dcm_image_codec.h b/libdcm-util/include/dcm_image_codec.h index 2ee9ba8..d40e4db 100755 --- a/libdcm-util/include/dcm_image_codec.h +++ b/libdcm-util/include/dcm_image_codec.h @@ -34,9 +34,7 @@ typedef enum { DCM_IMAGE_FORMAT_RGBA, } dcm_image_format_e; -int dcm_decode_image(const char *file_path, const dcm_image_format_e format, - const char* mimne_type, const int orientation, const gboolean resize, - unsigned char **image_buffer, unsigned long long *size, +int dcm_decode_image(const char *file_path, const int orientation, const gboolean resize, unsigned char **image_buffer, size_t *size, unsigned int *buff_width, unsigned int *buff_height); #ifdef __cplusplus diff --git a/packaging/dcm-service.spec b/packaging/dcm-service.spec index 9c1c1a5..e586eea 100755 --- a/packaging/dcm-service.spec +++ b/packaging/dcm-service.spec @@ -14,10 +14,10 @@ BuildRequires: cmake BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(sqlite3) -BuildRequires: pkgconfig(capi-media-image-util) BuildRequires: pkgconfig(capi-media-vision) BuildRequires: pkgconfig(libmedia-utils) BuildRequires: pkgconfig(libtzplatform-config) +BuildRequires: pkgconfig(mmutil-magick) %description This package provides a media DCM(Digital Contents Management) service diff --git a/src/dcm_svc_internal.c b/src/dcm_svc_internal.c index e267261..f768491 100755 --- a/src/dcm_svc_internal.c +++ b/src/dcm_svc_internal.c @@ -54,7 +54,7 @@ static int __dcm_scan_process(dcm_svc_item_s *scan_item) image_info.orientation = scan_item->image_orientation; if (strcmp(scan_item->mime_type, MIME_TYPE_JPEG) == 0) { - image_info.decode_type = DCM_IMAGE_FORMAT_RGB; + image_info.decode_type = DCM_IMAGE_FORMAT_RGBA; } else if ((strcmp(scan_item->mime_type, MIME_TYPE_PNG) == 0) || (strcmp(scan_item->mime_type, MIME_TYPE_BMP) == 0)) { image_info.decode_type = DCM_IMAGE_FORMAT_RGBA; @@ -63,8 +63,7 @@ static int __dcm_scan_process(dcm_svc_item_s *scan_item) return MS_MEDIA_ERR_INVALID_PARAMETER; } - ret = dcm_decode_image((const char *) (scan_item->file_path), image_info.decode_type, scan_item->mime_type, - image_info.orientation, FALSE, &(image_info.pixel), &(image_info.size), &(image_info.buffer_width), &(image_info.buffer_height)); + ret = dcm_decode_image((const char *) (scan_item->file_path), image_info.orientation, FALSE, &(image_info.pixel), &(image_info.size), &(image_info.buffer_width), &(image_info.buffer_height)); dcm_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Failed dcm_decode_image(%d)", ret); dcm_info("Image info W[%d] H[%d] Orient[%d] buf_w[%d] buf_h[%d]", -- 2.34.1