diff options
Diffstat (limited to 'src/media-thumb-internal.c')
-rwxr-xr-x | src/media-thumb-internal.c | 100 |
1 files changed, 1 insertions, 99 deletions
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) { |