Merge duplicate codes 56/280756/2
authorminje.ahn <minje.ahn@samsung.com>
Mon, 5 Sep 2022 00:24:59 +0000 (09:24 +0900)
committerminje.ahn <minje.ahn@samsung.com>
Mon, 5 Sep 2022 01:57:24 +0000 (10:57 +0900)
Change-Id: I2816dd102d890469488ad73c97dc1687bb7c9be0
Signed-off-by: minje.ahn <minje.ahn@samsung.com>
src/media-thumbnail.c

index 4d85f6471df5b07b5bc6d0f074e28b4aeca69704..658877951763f0201a9b2d856844a8e92647d94f 100755 (executable)
@@ -387,30 +387,18 @@ int create_video_thumbnail_to_buffer(const char *path,
        return err;
 }
 
-static int __get_image_info(const char *path, unsigned int *width, unsigned int *height)
+static int __adjust_thumb_ratio(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");
+       mm_util_img_codec_type image_type = 0;
 
        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(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "mm_util_extract_image_info: %d", err);
        thumb_retvm_if(image_type == IMG_CODEC_UNKNOWN_TYPE, MS_MEDIA_ERR_THUMB_UNSUPPORTED, "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;
+       __media_thumb_get_proper_thumb_size(image_w, image_h, width, height);
 
        return MS_MEDIA_ERR_NONE;
 }
@@ -418,20 +406,14 @@ static int __get_image_info(const char *path, unsigned int *width, unsigned int
 int create_image_thumbnail_to_file(const char *path, unsigned int width, unsigned int height, const char *thumb_path, bool auto_rotate)
 {
        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 = __adjust_thumb_ratio(path, &thumb_w, &thumb_h);
+       thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "__adjust_thumb_ratio failed");
 
        if (auto_rotate)
                err = mm_util_resize_and_rotate_P_P(path, thumb_w, thumb_h, thumb_path);
@@ -445,8 +427,6 @@ int create_image_thumbnail_to_file(const char *path, unsigned int width, unsigne
 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;
@@ -454,12 +434,8 @@ int create_image_thumbnail_to_buffer(const char *path, unsigned int width, unsig
        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 = __adjust_thumb_ratio(path, &thumb_w, &thumb_h);
+       thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "__adjust_thumb_ratio failed");
 
        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);