[ACR-1327] Modify the thumbnail size instead of returning the error 80/194480/5 accepted/tizen/unified/20181212.062510 submit/tizen/20181211.062513 submit/tizen/20190104.070559
authorMinje Ahn <minje.ahn@samsung.com>
Wed, 5 Dec 2018 02:04:23 +0000 (11:04 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Thu, 6 Dec 2018 05:46:58 +0000 (14:46 +0900)
If the width and height of the thumbnail to be generated exceeds the original resolution,
the value changes to the original resolution instead of returning the error.

Change-Id: I7708a74c87f7a7f63767a084c6db9b2d7057fa47
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
include/thumbnail_util.h
src/thumbnail_util.c

index 429b657d14954f07fa14755941c2eaa7a33c0401..c05c0fe79c3220cc94d497c6fa90e58fec1561c5 100755 (executable)
@@ -194,6 +194,8 @@ int thumbnail_util_destroy(thumbnail_h thumb) TIZEN_DEPRECATED_API;
  *          http://tizen.org/privilege/externalstorage is needed if input or output path points to external storage. \n
  *          The width and height of the thumbnail to be generated cannot exceed 2000. \n
  *          The width and height of the thumbnail to be generated cannot exceed the original resolution. \n
+ *          Since 5.5, if the width and height of the thumbnail to be generated exceeds the original resolution, the value changes to the original resolution. \n
+ *          In order to maintain the ratio, the requested size and generated size may be different. (Modify based on short axis)
  *
  * @param[in] path       The path of the original media file
  * @param[in] width      The width of the thumbnail
@@ -225,6 +227,8 @@ int thumbnail_util_extract_to_file(const char *path, unsigned int width, unsigne
  *          In the case of video file, color space of the generated thumbnail is RGB. \n
  *          In the case of image file, color space of the generated thumbnail is BGRA. \n
  *          The @a thumb_buffer should be released using free().
+ *          Since 5.5, if the width and height of the thumbnail to be generated exceeds the original resolution, the value changes to the original resolution. \n
+ *          In order to maintain the ratio, the requested size and generated size may be different. (Modify based on short axis)
  *
  * @param[in] path       The path of the original media file
  * @param[in] width      The width of the thumbnail
index a5ebca3563cbff8112a9ff9db617e8d0e2298a5d..81e232deaa03c9502911ebaa7fd6ea8c30524190 100755 (executable)
@@ -252,6 +252,32 @@ void _thumbnail_util_destroy_thumb_data(thumbnail_data_s *thumb)
        SAFE_FREE(thumb);
 }
 
+int __thumbnail_util_get_proper_thumb_size(int orig_w, int orig_h, int *thumb_w, int *thumb_h)
+{
+       bool portrait = false;
+       double ratio;
+
+       if (orig_w < orig_h)
+               portrait = true;
+
+       /* Set smaller length to default size */
+       if (portrait) {
+               if (orig_w < *thumb_w)
+                       *thumb_w = orig_w;
+               ratio = (double)orig_h / (double)orig_w;
+               *thumb_h = *thumb_w * ratio;
+       } else {
+               if (orig_h < *thumb_h)
+                       *thumb_h = orig_h;
+               ratio = (double)orig_w / (double)orig_h;
+               *thumb_w = *thumb_h * ratio;
+       }
+
+       thumbnail_util_debug("proper thumb w: %d h: %d", *thumb_w, *thumb_h);
+
+       return MS_MEDIA_ERR_NONE;
+}
+
 int _thumbnail_util_extract_video(thumbnail_data_s *thumb)
 {
        int ret = THUMBNAIL_UTIL_ERROR_NONE;
@@ -263,11 +289,16 @@ int _thumbnail_util_extract_video(thumbnail_data_s *thumb)
        int size = 0;
        int width = 0;
        int height = 0;
+       int thumb_width = 0;
+       int thumb_height = 0;
        int cdis_value = 0;
        mm_util_image_h img = NULL;
 
        thumbnail_util_retvm_if(thumb == NULL, THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER, "Data is NULL");
 
+       thumb_width = thumb->width;
+       thumb_height = thumb->height;
+
        //1. get CDIS
        ret = mm_file_create_tag_attrs(&tag, thumb->path);
        if (ret == FILEINFO_ERROR_NONE) {
@@ -329,8 +360,11 @@ int _thumbnail_util_extract_video(thumbnail_data_s *thumb)
                        goto ERROR;
                }
 
+               /* check thumb size */
+               __thumbnail_util_get_proper_thumb_size(width, height, &thumb_width, &thumb_height);
+
                if (thumb->extract_type == THUMBNAIL_UTIL_FILE) {
-                       ret = mm_util_resize_B_P(img, thumb->width, thumb->height, thumb->thumbnail_path);
+                       ret = mm_util_resize_B_P(img, thumb_width, thumb_height, thumb->thumbnail_path);
                        mm_util_destroy_handle(img);
                        if (ret != MM_UTIL_ERROR_NONE)
                                goto ERROR;
@@ -342,7 +376,7 @@ int _thumbnail_util_extract_video(thumbnail_data_s *thumb)
                        size_t res_buf_size = 0;
                        mm_util_color_format_e res_format = MM_UTIL_COLOR_NUM;
 
-                       ret = mm_util_resize_B_B(img, thumb->width, thumb->height, &res_img);
+                       ret = mm_util_resize_B_B(img, thumb_width, thumb_height, &res_img);
                        mm_util_destroy_handle(img);
                        if (ret != MM_UTIL_ERROR_NONE)
                                goto ERROR;
@@ -376,11 +410,26 @@ ERROR:
 int _thumbnail_util_extract(thumbnail_data_s *thumb)
 {
        int ret = 0;
+       unsigned int orig_width = 0;
+       unsigned int orig_height = 0;
+       int thumb_width = 0;
+       int thumb_height = 0;
+       mm_util_img_codec_type type = IMG_CODEC_UNKNOWN_TYPE;
+
        thumbnail_util_retvm_if(thumb == NULL, THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER, "Data is NULL");
 
        if (thumb->media_type == THUMBNAIL_UTIL_IMAGE) {
+               thumb_width = thumb->width;
+               thumb_height = thumb->height;
+               /* Get original resolution */
+               ret = mm_util_extract_image_info(thumb->path, &type, &orig_width, &orig_height);
+               thumbnail_util_retv_if(ret != MM_UTIL_ERROR_NONE, THUMBNAIL_UTIL_ERROR_INVALID_OPERATION);
+
+               ret = __thumbnail_util_get_proper_thumb_size((int)orig_width, (int)orig_height, &thumb_width, &thumb_height);
+               thumbnail_util_retv_if(ret != MM_UTIL_ERROR_NONE, THUMBNAIL_UTIL_ERROR_INVALID_OPERATION);
+
                if (thumb->extract_type == THUMBNAIL_UTIL_FILE) {
-                       ret = mm_util_resize_P_P(thumb->path, thumb->width, thumb->height, thumb->thumbnail_path);
+                       ret = mm_util_resize_P_P(thumb->path, thumb_width, thumb_height, thumb->thumbnail_path);
                        thumbnail_util_retv_if(ret != MM_UTIL_ERROR_NONE, THUMBNAIL_UTIL_ERROR_INVALID_OPERATION);
 
                } else {
@@ -391,7 +440,7 @@ int _thumbnail_util_extract(thumbnail_data_s *thumb)
                        size_t buf_size = 0;
                        mm_util_color_format_e format = MM_UTIL_COLOR_NUM;
 
-                       ret = mm_util_resize_P_B(thumb->path, thumb->width, thumb->height, MM_UTIL_COLOR_BGRA, &res_img);
+                       ret = mm_util_resize_P_B(thumb->path, thumb_width, thumb_height, MM_UTIL_COLOR_BGRA, &res_img);
                        thumbnail_util_retv_if(ret != MM_UTIL_ERROR_NONE, THUMBNAIL_UTIL_ERROR_INVALID_OPERATION);
 
                        ret = mm_util_get_image(res_img, &buf, &width, &height, &buf_size, &format);