From: hj kim Date: Thu, 1 Feb 2018 02:44:09 +0000 (+0900) Subject: Use new image_util(magicK) APIs instead of Old one X-Git-Tag: submit/tizen/20180131.074228~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F93%2F168893%2F1;p=platform%2Fcore%2Fmultimedia%2Flibmedia-service.git Use new image_util(magicK) APIs instead of Old one Change-Id: Ic05939470633836ff7ae678417888cfd245ba918 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index f099906..95b86dd 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,7 @@ EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH") INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED glib-2.0 dlog sqlite3 db-util libexif mm-fileinfo media-thumbnail libmedia-utils aul uuid vconf capi-media-image-util capi-system-info) +pkg_check_modules(pkgs REQUIRED glib-2.0 dlog sqlite3 db-util libexif mm-fileinfo media-thumbnail libmedia-utils aul uuid vconf capi-system-info mmutil-magick) FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") diff --git a/packaging/libmedia-service.spec b/packaging/libmedia-service.spec index dd81101..63e3d33 100644 --- a/packaging/libmedia-service.spec +++ b/packaging/libmedia-service.spec @@ -1,6 +1,6 @@ Name: libmedia-service Summary: Media information service library for multimedia applications -Version: 0.3.23 +Version: 0.3.24 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 and PD @@ -22,8 +22,8 @@ BuildRequires: pkgconfig(media-thumbnail) BuildRequires: pkgconfig(libmedia-utils) BuildRequires: pkgconfig(uuid) BuildRequires: pkgconfig(libtzplatform-config) -BuildRequires: pkgconfig(capi-media-image-util) BuildRequires: pkgconfig(capi-system-info) +BuildRequires: pkgconfig(mmutil-magick) %description This package is a library that provides the media information service for the multimedia applications. diff --git a/src/common/media-svc-util.c b/src/common/media-svc-util.c index 2c62a2f..167ffa6 100755 --- a/src/common/media-svc-util.c +++ b/src/common/media-svc-util.c @@ -43,8 +43,7 @@ #include #include #include -#include -#include +#include #include "media-util-err.h" #include "media-svc-util.h" #include "media-svc-db-utils.h" @@ -514,150 +513,25 @@ static int __media_svc_get_location_value(MMHandleType tag, double *longitude, d return MS_MEDIA_ERR_NONE; } -static int __media_svc_encode_jpeg(unsigned char *src, unsigned long width, unsigned long height, image_util_colorspace_e colorspace, int quality, unsigned char **dst, unsigned long long *dst_size) -{ - int res = IMAGE_UTIL_ERROR_NONE; - image_util_encode_h encoder = NULL; - unsigned char *encoded_data = NULL; - res = image_util_encode_create(IMAGE_UTIL_JPEG , &encoder); - if (res != IMAGE_UTIL_ERROR_NONE) { - media_svc_error("image_util_encode_create failed! (%d)", res); - return MS_MEDIA_ERR_INTERNAL; - } - res = image_util_encode_set_resolution(encoder, width, height); - if (res != IMAGE_UTIL_ERROR_NONE) { - media_svc_error("image_util_encode_set_resolution failed! (%d)", res); - image_util_encode_destroy(encoder); - return MS_MEDIA_ERR_INTERNAL; - } - res = image_util_encode_set_colorspace(encoder, colorspace); - if (res != IMAGE_UTIL_ERROR_NONE) { - media_svc_error("image_util_encode_set_colorspace failed! (%d)", res); - image_util_encode_destroy(encoder); - return MS_MEDIA_ERR_INTERNAL; - } - res = image_util_encode_set_quality(encoder, quality); - if (res != IMAGE_UTIL_ERROR_NONE) { - media_svc_error("image_util_encode_set_quality failed! (%d)", res); - image_util_encode_destroy(encoder); - return MS_MEDIA_ERR_INTERNAL; - } - res = image_util_encode_set_input_buffer(encoder, src); - if (res != IMAGE_UTIL_ERROR_NONE) { - media_svc_error("image_util_encode_set_input_buffer failed! (%d)", res); - image_util_encode_destroy(encoder); - return MS_MEDIA_ERR_INTERNAL; - } - res = image_util_encode_set_output_buffer(encoder, &encoded_data); - if (res != IMAGE_UTIL_ERROR_NONE) { - media_svc_error("image_util_decode_set_output_buffer failed! (%d)", res); - image_util_encode_destroy(encoder); - return MS_MEDIA_ERR_INTERNAL; - } - res = image_util_encode_run(encoder, dst_size); - if (res != IMAGE_UTIL_ERROR_NONE) { - media_svc_error("image_util_encode_run failed! (%d)", res); - image_util_encode_destroy(encoder); - return MS_MEDIA_ERR_INTERNAL; - } - if (encoded_data != NULL) { - *dst = (unsigned char *)calloc(1, *dst_size); - if (*dst == NULL) { - media_svc_error("memory allocation failed! (%lld)", *dst_size); - image_util_encode_destroy(encoder); - return MS_MEDIA_ERR_INTERNAL; - } - memcpy(*dst, encoded_data, *dst_size); - } - res = image_util_encode_destroy(encoder); - if (res != IMAGE_UTIL_ERROR_NONE) { - media_svc_error("image_util_encode_destroy failed! (%d)", res); - return MS_MEDIA_ERR_INTERNAL; - } - SAFE_FREE(encoded_data); - return MS_MEDIA_ERR_NONE; -} - -static int __media_svc_decode_jpeg(unsigned char *src, unsigned long long size, image_util_colorspace_e colorspace, unsigned char **dst, unsigned long *width, unsigned long *height, unsigned long long *dst_size) -{ - int res = IMAGE_UTIL_ERROR_NONE; - image_util_decode_h decoder = NULL; - res = image_util_decode_create(&decoder); - if (res != IMAGE_UTIL_ERROR_NONE) { - media_svc_error("image_util_decode_create failed! (%d)", res); - return MS_MEDIA_ERR_INTERNAL; - } - res = image_util_decode_set_input_buffer(decoder, src, size); - if (res != IMAGE_UTIL_ERROR_NONE) { - media_svc_error("image_util_decode_set_input_buffer failed! (%d)", res); - image_util_decode_destroy(decoder); - return MS_MEDIA_ERR_INTERNAL; - } - res = image_util_decode_set_colorspace(decoder, colorspace); - if (res != IMAGE_UTIL_ERROR_NONE) { - media_svc_error("image_util_decode_set_colorspace failed! (%d)", res); - image_util_decode_destroy(decoder); - return MS_MEDIA_ERR_INTERNAL; - } - res = image_util_decode_set_output_buffer(decoder, dst); - if (res != IMAGE_UTIL_ERROR_NONE) { - media_svc_error("image_util_decode_set_output_buffer failed! (%d)", res); - image_util_decode_destroy(decoder); - return MS_MEDIA_ERR_INTERNAL; - } - res = image_util_decode_run(decoder, width, height, dst_size); - if (res != IMAGE_UTIL_ERROR_NONE) { - media_svc_error("image_util_decode_run failed! (%d)", res); - image_util_decode_destroy(decoder); - return MS_MEDIA_ERR_INTERNAL; - } - - res = image_util_decode_destroy(decoder); - if (res != IMAGE_UTIL_ERROR_NONE) { - media_svc_error("image_util_decode_destroy failed! (%d)", res); - return MS_MEDIA_ERR_INTERNAL; - } - return MS_MEDIA_ERR_NONE; -} - -static int __media_svc_resize_artwork(unsigned char *image, unsigned int size, const char *img_format, unsigned char **resize_image, unsigned int *resize_size) +static int __media_svc_resize_artwork(const char *path, const char *img_format) { int ret = MS_MEDIA_ERR_NONE; - unsigned char *raw_image = NULL; - int width = 0; - int height = 0; - unsigned long long raw_size = 0; - void *resized_raw_image = NULL; - int resized_width = 0; - int resized_height = 0; - unsigned int buf_size = 0; - image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_RGB888; + unsigned int width = 0; + unsigned int height = 0; + unsigned int resized_width = 0; + unsigned int resized_height = 0; + ImgCodecType img_type = IMG_CODEC_NONE; if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) { - media_svc_debug("type [jpeg] size [%d]", size); - /* decoding */ - ret = __media_svc_decode_jpeg(image, (unsigned long long)size, colorspace, &raw_image, (unsigned long *)&width, (unsigned long *)&height, &raw_size); - if (ret != MS_MEDIA_ERR_NONE) { - media_svc_error("__media_svc_decode_jpeg failed"); - *resize_image = image; - *resize_size = size; - return MS_MEDIA_ERR_NONE; - } + media_svc_debug("type [jpeg]"); - if (raw_image == NULL) { - media_svc_error("raw_image is null"); - *resize_image = image; - *resize_size = size; - return MS_MEDIA_ERR_NONE; - } + ImgGetImageInfo(path, &img_type, &width, &height); if (width <= MEDIA_SVC_ARTWORK_SIZE || height <= MEDIA_SVC_ARTWORK_SIZE) { media_svc_debug("No need resizing"); - *resize_image = image; - *resize_size = size; - SAFE_FREE(raw_image); return MS_MEDIA_ERR_NONE; } + /* resizing */ if (width > height) { resized_height = MEDIA_SVC_ARTWORK_SIZE; @@ -667,57 +541,12 @@ static int __media_svc_resize_artwork(unsigned char *image, unsigned int size, c resized_height = height * MEDIA_SVC_ARTWORK_SIZE / width; } - image_util_calculate_buffer_size(resized_width, resized_height, colorspace, &buf_size); - - resized_raw_image = malloc(buf_size); + ret = mm_util_resize_P_P(path, resized_width, resized_height, path); - if (resized_raw_image == NULL) { - media_svc_error("malloc failed"); - *resize_image = image; - *resize_size = size; - SAFE_FREE(raw_image); - return MS_MEDIA_ERR_NONE; - } - - memset(resized_raw_image, 0, buf_size); - - ret = image_util_resize(resized_raw_image, &resized_width, &resized_height, raw_image, width, height, colorspace); - if (ret != MS_MEDIA_ERR_NONE) { - media_svc_error("image_util_resize failed"); - *resize_image = image; - *resize_size = size; - SAFE_FREE(raw_image); - SAFE_FREE(resized_raw_image); - return MS_MEDIA_ERR_NONE; - } - SAFE_FREE(raw_image); - - /* encoding */ - ret = __media_svc_encode_jpeg((unsigned char *)resized_raw_image, (unsigned long)resized_width, (unsigned long)resized_height, colorspace, 90, resize_image, (unsigned long long *)resize_size); - if (ret != MS_MEDIA_ERR_NONE) { - media_svc_error("__media_svc_encode_jpeg failed"); - *resize_image = image; - *resize_size = size; - SAFE_FREE(resized_raw_image); - return MS_MEDIA_ERR_NONE; - } - SAFE_FREE(resized_raw_image); - - if (*resize_image == NULL) { - media_svc_error("*resize_image is null"); - *resize_image = image; - *resize_size = size; - return MS_MEDIA_ERR_NONE; - } } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) { - media_svc_debug("type [png] size [%d]", size); - *resize_image = image; - *resize_size = size; - + media_svc_debug("type [png]"); } else { media_svc_debug("Not proper img format"); - *resize_image = image; - *resize_size = size; } return ret; @@ -1523,8 +1352,6 @@ int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s int album_id = 0; int ret = MS_MEDIA_ERR_NONE; int cdis_value = 0; - unsigned int resize_size = 0; - unsigned char *resize_image = NULL; /*Get Content Tag attribute ===========*/ mmf_error = mm_file_create_tag_attrs(&tag, content_info->path); @@ -1703,6 +1530,7 @@ int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s } else { /*media_svc_debug("artwork size2 [%d]", size); */ } + if (image != NULL && size > 0) { char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0"; int artwork_mime_size = -1; @@ -1712,24 +1540,26 @@ int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s ret = _media_svc_get_thumbnail_path(content_info->storage_type, thumb_path, content_info->path, p, uid); if (ret != MS_MEDIA_ERR_NONE) media_svc_error("Fail to Get Thumbnail Path"); - /* albumart resizing */ - __media_svc_resize_artwork(image, size, p, &resize_image, &resize_size); + + if (strlen(thumb_path) > 0) { + ret = __media_svc_save_image(image, size, thumb_path, uid); + if (ret != MS_MEDIA_ERR_NONE) { + media_svc_error("Fail to Save Image"); + } else { + /* albumart resizing */ + ret = __media_svc_resize_artwork(thumb_path, p); + if (ret != MS_MEDIA_ERR_NONE) { + media_svc_error("Fail to Make Thumbnail Image"); + _media_svc_remove_file(thumb_path); + + } else { + content_info->thumbnail_path = g_strdup(thumb_path); + } + } + } } else { SAFE_FREE(err_attr_name); } - - if (strlen(thumb_path) > 0) { - ret = __media_svc_save_image(resize_image, resize_size, thumb_path, uid); - if (ret != MS_MEDIA_ERR_NONE) - media_svc_error("Fail to Save Thumbnail Image"); - else - content_info->thumbnail_path = g_strdup(thumb_path); - } - - if (size != resize_size) { - media_svc_error("Albumart is resized"); - SAFE_FREE(resize_image); - } } }