diff options
author | hj kim <backto.kim@samsung.com> | 2020-03-06 16:58:00 +0900 |
---|---|---|
committer | hj kim <backto.kim@samsung.com> | 2020-03-13 06:57:42 +0000 |
commit | 0c6efd9728efa22bb69b5b6a31ea05bea1e129d2 (patch) | |
tree | 77ac72d12cecf3a719867ff55f2daa5da61bfb7b | |
parent | 7987cc930a4af11c432f21de47b826332590d8ca (diff) | |
download | libmedia-thumbnail-0c6efd9728efa22bb69b5b6a31ea05bea1e129d2.tar.gz libmedia-thumbnail-0c6efd9728efa22bb69b5b6a31ea05bea1e129d2.tar.bz2 libmedia-thumbnail-0c6efd9728efa22bb69b5b6a31ea05bea1e129d2.zip |
Create New APIs for Creating Image Thumbnail
To unify duplicated thumbnail extracting codes in libmedia-service, libmedia-thumbnail and thumbnail-uti
Change-Id: I4edd9296872b299d6d4fc218d284a6a3fa8f404c
-rwxr-xr-x | include/media-thumbnail.h | 2 | ||||
-rw-r--r-- | packaging/libmedia-thumbnail.spec | 2 | ||||
-rwxr-xr-x | server/thumb-server-internal.c | 43 | ||||
-rwxr-xr-x | src/include/media-thumb-internal.h | 12 | ||||
-rwxr-xr-x | src/include/util/media-thumb-util.h | 3 | ||||
-rwxr-xr-x | src/media-thumb-internal.c | 100 | ||||
-rwxr-xr-x | src/media-thumbnail.c | 84 |
7 files changed, 100 insertions, 146 deletions
diff --git a/include/media-thumbnail.h b/include/media-thumbnail.h index ec275d5..2022138 100755 --- a/include/media-thumbnail.h +++ b/include/media-thumbnail.h @@ -45,6 +45,8 @@ int thumbnail_request_cancel_raw_data(int request_id); int create_video_thumbnail_to_file(const char *path, unsigned int width, unsigned int height, const char *thumb_path, bool auto_rotate); int create_video_thumbnail_to_buffer(const char *path, unsigned int width, unsigned int height, unsigned char **thumb_buffer, size_t *thumb_size, unsigned int *thumb_width, unsigned int *thumb_height, bool auto_rotate); +int create_image_thumbnail_to_file(const char *path, unsigned int width, unsigned int height, const char *thumb_path); +int create_image_thumbnail_to_buffer(const char *path, unsigned int width, unsigned int height, unsigned char **thumb_buffer, size_t *thumb_size, unsigned int *thumb_width, unsigned int *thumb_height); diff --git a/packaging/libmedia-thumbnail.spec b/packaging/libmedia-thumbnail.spec index f297c1b..c218607 100644 --- a/packaging/libmedia-thumbnail.spec +++ b/packaging/libmedia-thumbnail.spec @@ -1,6 +1,6 @@ Name: libmedia-thumbnail Summary: Media thumbnail service library for multimedia applications -Version: 0.3.2 +Version: 0.3.3 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 and PD diff --git a/server/thumb-server-internal.c b/server/thumb-server-internal.c index d65adf7..294dc80 100755 --- a/server/thumb-server-internal.c +++ b/server/thumb-server-internal.c @@ -27,8 +27,6 @@ #include <fcntl.h> #include <unistd.h> #include <dirent.h> -#include <stdio.h> -#include <string.h> #include <tzplatform_config.h> #ifdef LOG_TAG @@ -48,16 +46,14 @@ static int __thumbnail_get_data(const char *origin_path, char *thumb_path) thumb_retvm_if(!origin_path, MS_MEDIA_ERR_INVALID_PARAMETER, "Original path is null"); thumb_retvm_if(!g_file_test(origin_path, G_FILE_TEST_IS_REGULAR), MS_MEDIA_ERR_INVALID_PARAMETER, "Original path(%s) does not exist", origin_path); - thumb_dbg("Origin path : %s", origin_path); + thumb_dbg_slog("Origin path : %s", origin_path); file_type = _media_thumb_get_file_type(origin_path); if (file_type == THUMB_IMAGE_TYPE) { - err = _media_thumb_image(origin_path, thumb_path, THUMB_DEFAULT_WIDTH, THUMB_DEFAULT_HEIGHT, NULL); - thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "_media_thumb_image failed"); + err = create_image_thumbnail_to_file(origin_path, CONTENT_THUMB_DEFAULT_WIDTH, CONTENT_THUMB_DEFAULT_HEIGHT, thumb_path); } else if (file_type == THUMB_VIDEO_TYPE) { err = create_video_thumbnail_to_file(origin_path, CONTENT_THUMB_DEFAULT_WIDTH, CONTENT_THUMB_DEFAULT_HEIGHT, thumb_path, true); - thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "create_video_thumbnail_to_file failed"); } else { thumb_err("invalid file type"); return MS_MEDIA_ERR_THUMB_UNSUPPORTED; @@ -65,49 +61,30 @@ static int __thumbnail_get_data(const char *origin_path, char *thumb_path) thumb_dbg("Thumb data is generated successfully"); - return MS_MEDIA_ERR_NONE; + return err; } static int __thumbnail_get_raw_data(const char *origin_path, unsigned int *width, unsigned int *height, unsigned char **data, size_t *size) { int err = MS_MEDIA_ERR_NONE; - unsigned int thumb_width = 0; - unsigned int thumb_height = 0; - - if (origin_path == NULL || *width == 0 || *height == 0) { - thumb_err("Invalid parameter"); - return MS_MEDIA_ERR_INVALID_PARAMETER; - } + int file_type = THUMB_NONE_TYPE; - if (!g_file_test(origin_path, G_FILE_TEST_IS_REGULAR)) { - thumb_err("Original path (%s) does not exist", origin_path); - return MS_MEDIA_ERR_INVALID_PARAMETER; - } + thumb_retvm_if(!origin_path, MS_MEDIA_ERR_INVALID_PARAMETER, "Original path is null"); + thumb_retvm_if(!g_file_test(origin_path, G_FILE_TEST_IS_REGULAR), MS_MEDIA_ERR_INVALID_PARAMETER, "Original path(%s) does not exist", origin_path); + thumb_dbg_slog("Origin path : %s", origin_path); - int file_type = THUMB_NONE_TYPE; - media_thumb_info thumb_info = {0,}; file_type = _media_thumb_get_file_type(origin_path); - thumb_width = *width; - thumb_height = *height; if (file_type == THUMB_IMAGE_TYPE) { - err = _media_thumb_image(origin_path, NULL, thumb_width, thumb_height, &thumb_info); - thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "_media_thumb_image failed"); + err = create_image_thumbnail_to_buffer(origin_path, *width, *height, data, size, width, height); } else if (file_type == THUMB_VIDEO_TYPE) { - err = create_video_thumbnail_to_buffer(origin_path, thumb_width, thumb_height, - &thumb_info.data, &thumb_info.size, &thumb_info.width, &thumb_info.height, true); - thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "create_video_thumbnail_to_buffer failed"); + err = create_video_thumbnail_to_buffer(origin_path, *width, *height, data, size, width, height, true); } else { thumb_err("invalid file type"); return MS_MEDIA_ERR_THUMB_UNSUPPORTED; } - if (size) *size = thumb_info.size; - *data = thumb_info.data; - *width = thumb_info.width; - *height = thumb_info.height; - - return MS_MEDIA_ERR_NONE; + return err; } static int __media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg) diff --git a/src/include/media-thumb-internal.h b/src/include/media-thumb-internal.h index 5b82b14..530f664 100755 --- a/src/include/media-thumb-internal.h +++ b/src/include/media-thumb-internal.h @@ -19,7 +19,6 @@ * */ -#include <stdbool.h> #include <media-util-err.h> #include "media-thumbnail.h" #include "media-thumb-util.h" @@ -27,16 +26,6 @@ #ifndef _MEDIA_THUMB_INTERNAL_H_ #define _MEDIA_THUMB_INTERNAL_H_ -/* The maximum of resolution to be able to get thumbnail is 3000 x 3000, except for only jpeg */ -#define THUMB_MAX_ALLOWED_MEM_FOR_THUMB 9000000 - -typedef struct { - size_t size; - unsigned int width; - unsigned int height; - unsigned char *data; -} media_thumb_info; - typedef struct { ThumbFunc func; void *user_data; @@ -47,7 +36,6 @@ typedef struct { void *user_data; } thumbRawUserData; -int _media_thumb_image(const char *origin_path, char *thumb_path, unsigned int thumb_width, unsigned int thumb_height, media_thumb_info *thumb_info); int _media_thumb_get_hash_name(const char *file_full_path, char *thumb_hash_path, size_t max_thumb_path, uid_t uid); #endif /*_MEDIA_THUMB_INTERNAL_H_*/ diff --git a/src/include/util/media-thumb-util.h b/src/include/util/media-thumb-util.h index 64515f2..59a85f7 100755 --- a/src/include/util/media-thumb-util.h +++ b/src/include/util/media-thumb-util.h @@ -19,7 +19,8 @@ * */ -#include "media-util.h" +#include <stdlib.h> +#include <string.h> #ifndef _MEDIA_THUMB_UTIL_H_ #define _MEDIA_THUMB_UTIL_H_ diff --git a/src/media-thumb-internal.c b/src/media-thumb-internal.c index bd6ff2d..3334a48 100755 --- a/src/media-thumb-internal.c +++ b/src/media-thumb-internal.c @@ -19,107 +19,9 @@ * */ +#include <media-util.h> #include "media-thumb-debug.h" -#include "media-thumb-util.h" #include "media-thumb-internal.h" -#include "media-thumb-ipc.h" -#include "media-thumb-db.h" - -#include <sys/types.h> -#include <fcntl.h> -#include <unistd.h> -#include <mm_util_magick.h> - -static void __media_thumb_get_proper_thumb_size(unsigned int origin_width, unsigned int origin_height, unsigned int *thumb_width, unsigned int *thumb_height) -{ - bool portrait = false; - double ratio = 0.0; - - thumb_retm_if(origin_width == 0, "Invalid origin_width"); - thumb_retm_if(origin_height == 0, "Invalid origin_height"); - thumb_retm_if(!thumb_width, "Invalid thumb_width"); - thumb_retm_if(!thumb_height, "Invalid thumb_height"); - - if (origin_width < origin_height) - portrait = true; - - /* Set smaller length to default size */ - if (portrait) { - if (origin_width < *thumb_width) - *thumb_width = origin_width; - ratio = (double)origin_height / (double)origin_width; - *thumb_height = *thumb_width * ratio; - } else { - if (origin_height < *thumb_height) - *thumb_height = origin_height; - ratio = (double)origin_width / (double)origin_height; - *thumb_width = *thumb_height * ratio; - } - - thumb_dbg("proper thumb w: %d h: %d", *thumb_width, *thumb_height); - - return; -} - -int _media_thumb_general(const char *origin_path, const char *thumb_path, int thumb_width, int thumb_height, media_thumb_info *thumb_info) -{ - int err = MS_MEDIA_ERR_NONE; - mm_util_image_h img = NULL; - unsigned char *buf = NULL; - unsigned int width = 0; - unsigned int height = 0; - size_t size = 0; - mm_util_color_format_e format = MM_UTIL_COLOR_NUM; - - if (thumb_path != NULL) { - err = mm_util_resize_P_P(origin_path, thumb_width, thumb_height, thumb_path); - } else { - err = mm_util_resize_P_B(origin_path, thumb_width, thumb_height, MM_UTIL_COLOR_BGRA, &img); - if (err != MM_UTIL_ERROR_NONE) { - thumb_err("mm_util_resize_P_B failed : %d", err); - return MS_MEDIA_ERR_INTERNAL; - } - - mm_image_get_image(img, &width, &height, &format, &buf, &size); - thumb_info->data = buf; - thumb_info->size = size; - thumb_info->width = width; - thumb_info->height = height; - mm_image_destroy_image(img); - } - - return err; -} - -int _media_thumb_image(const char *origin_path, char *thumb_path, unsigned int thumb_width, unsigned int thumb_height, media_thumb_info *thumb_info) -{ - int err = MS_MEDIA_ERR_NONE; - mm_util_img_codec_type image_type = 0; - unsigned int origin_w = 0; - unsigned int origin_h = 0; - - err = mm_util_extract_image_info(origin_path, &image_type, &origin_w, &origin_h); - if (err != MS_MEDIA_ERR_NONE) { - thumb_warn("Getting image info is failed err: %d", err); - return MS_MEDIA_ERR_INTERNAL; - } - - if ((image_type != IMG_CODEC_JPEG) && (origin_w * origin_h > THUMB_MAX_ALLOWED_MEM_FOR_THUMB)) { - thumb_warn("This original image is too big"); - return MS_MEDIA_ERR_THUMB_TOO_BIG; - } - - __media_thumb_get_proper_thumb_size(origin_w, origin_h, &thumb_width, &thumb_height); - - if (image_type != IMG_CODEC_UNKNOWN_TYPE) { - err = _media_thumb_general(origin_path, thumb_path, thumb_width, thumb_height, thumb_info); - } else { - thumb_warn("Unsupported image type"); - err = MS_MEDIA_ERR_THUMB_UNSUPPORTED; - } - - return err; -} int _media_thumb_get_hash_name(const char *file_full_path, char *thumb_hash_path, size_t max_thumb_path, uid_t uid) { diff --git a/src/media-thumbnail.c b/src/media-thumbnail.c index dc8a814..8fe3eb2 100755 --- a/src/media-thumbnail.c +++ b/src/media-thumbnail.c @@ -22,12 +22,15 @@ #include <glib.h> #include <mm_file.h> #include <mm_util_magick.h> +#include <media-util.h> #include "media-thumbnail.h" #include "media-thumb-debug.h" #include "media-thumb-util.h" #include "media-thumb-internal.h" #include "media-thumb-ipc.h" +/* The maximum of resolution to be able to get thumbnail is 3000 x 3000, except for only jpeg */ +#define THUMB_MAX_ALLOWED_MEM_FOR_THUMB 9000000 #define THUMB_MAX_ALLOWED_RESOLUTION 2000 int thumbnail_request_from_db_async(unsigned int request_id, const char *origin_path, ThumbFunc func, void *user_data, uid_t uid) @@ -468,3 +471,84 @@ int create_video_thumbnail_to_buffer(const char *path, unsigned int width, unsig return err; } + +static int __get_image_info(const char *path, unsigned int *width, unsigned int *height) +{ + int err = MS_MEDIA_ERR_NONE; + mm_util_img_codec_type image_type = 0; + unsigned int image_w = 0; + unsigned int image_h = 0; + + thumb_retvm_if(!path, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path"); + thumb_retvm_if(!width, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid width"); + thumb_retvm_if(!height, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid height"); + + err = mm_util_extract_image_info(path, &image_type, &image_w, &image_h); + thumb_retvm_if(err != MS_MEDIA_ERR_NONE, MS_MEDIA_ERR_INTERNAL, "Getting image info is failed err: %d", err); + thumb_retvm_if(image_type == IMG_CODEC_UNKNOWN_TYPE, MS_MEDIA_ERR_UNSUPPORTED_CONTENT, "Unsupported image codec"); + + /* + if ((image_type != IMG_CODEC_JPEG) && (image_w * image_h > THUMB_MAX_ALLOWED_MEM_FOR_THUMB)) { + thumb_warn("This original image is too big. w[%d] h[%d] size limit[%d]", image_w, image_h, THUMB_MAX_ALLOWED_MEM_FOR_THUMB); + return MS_MEDIA_ERR_THUMB_TOO_BIG; + } + */ + + *width = image_w; + *height = image_h; + + return MS_MEDIA_ERR_NONE; +} + +int create_image_thumbnail_to_file(const char *path, unsigned int width, unsigned int height, const char *thumb_path) +{ + int err = MS_MEDIA_ERR_NONE; + unsigned int image_w = 0; + unsigned int image_h = 0; + unsigned int thumb_w = width; + unsigned int thumb_h = height; + + err = __check_parameter_validity_for_file(path, width, height, thumb_path); + thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "Invalid parameter"); + + //Get image info + err = __get_image_info(path, &image_w, &image_h); + thumb_retvm_if(err != MM_UTIL_ERROR_NONE, err, "fail to __get_image_info [%d]", err); + + //Extract thumbnail + __media_thumb_get_proper_thumb_size(image_w, image_h, &thumb_w, &thumb_h); + + err = mm_util_resize_P_P(path, thumb_w, thumb_h, thumb_path); + thumb_retvm_if(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "mm_util_resize_P_P failed : %d", err); + + return MS_MEDIA_ERR_NONE; +} + +int create_image_thumbnail_to_buffer(const char *path, unsigned int width, unsigned int height, unsigned char **thumb_buffer, size_t *thumb_size, unsigned int *thumb_width, unsigned int *thumb_height) +{ + int err = MS_MEDIA_ERR_NONE; + unsigned int image_w = 0; + unsigned int image_h = 0; + unsigned int thumb_w = width; + unsigned int thumb_h = height; + mm_util_image_h img = NULL; + + err = __check_parameter_validity_for_buffer(path, width, height, thumb_buffer, thumb_size, thumb_width, thumb_height); + thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "Invalid parameter"); + + //Get image info + err = __get_image_info(path, &image_w, &image_h); + thumb_retvm_if(err != MM_UTIL_ERROR_NONE, err, "fail to __get_image_info [%d]", err); + + //Extract thumbnail + __media_thumb_get_proper_thumb_size(image_w, image_h, &thumb_w, &thumb_h); + + err = mm_util_resize_P_B(path, thumb_w, thumb_h, MM_UTIL_COLOR_BGRA, &img); + thumb_retvm_if(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "mm_util_resize_P_B failed : %d", err); + + err = mm_image_get_image(img, thumb_width, thumb_height, NULL, thumb_buffer, thumb_size); + + mm_image_destroy_image(img); + + return err; +} |