summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjiyong.min <jiyong.min@samsung.com>2023-02-14 15:02:21 +0900
committerjiyong.min <jiyong.min@samsung.com>2023-02-15 08:26:50 +0900
commitacfb6d0101a2688d30dc7b4692c257ba907330a1 (patch)
treee28335691b950cc23aeef368da23ca5606429354
parentc3adfb59ca994113c00209582f4d494a03ba1111 (diff)
downloadlibmedia-thumbnail-acfb6d0101a2688d30dc7b4692c257ba907330a1.tar.gz
libmedia-thumbnail-acfb6d0101a2688d30dc7b4692c257ba907330a1.tar.bz2
libmedia-thumbnail-acfb6d0101a2688d30dc7b4692c257ba907330a1.zip
Separate functions for 'USE_MEMORY_USAGE_REDUCTION'
Change-Id: I3967b917078d2cefb277a1627729005856a16ae7
-rw-r--r--packaging/libmedia-thumbnail.spec2
-rwxr-xr-xsrc/media-thumbnail.c177
2 files changed, 98 insertions, 81 deletions
diff --git a/packaging/libmedia-thumbnail.spec b/packaging/libmedia-thumbnail.spec
index 089cdd0..0aa7db8 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.5
+Version: 0.3.6
Release: 0
Group: Multimedia/Libraries
License: Apache-2.0 and PD
diff --git a/src/media-thumbnail.c b/src/media-thumbnail.c
index 3432bed..d95a455 100755
--- a/src/media-thumbnail.c
+++ b/src/media-thumbnail.c
@@ -588,6 +588,95 @@ static mm_util_rotate_type_e __get_image_orientation(const char *path)
return rotation;
}
+
+static int __create_gif_thumbnail_to_file(const char *path, unsigned int thumb_w, unsigned int thumb_h, const char *thumb_path)
+{
+ int err = MS_MEDIA_ERR_NONE;
+ mm_util_image_h decode_image = NULL;
+
+ err = mm_util_decode_from_gif_file(path, &decode_image);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "mm_util_decode_from_gif_file failed : %d", err);
+
+ err = mm_util_resize_B_P(decode_image, thumb_w, thumb_h, thumb_path);
+ mm_image_destroy_image(decode_image);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "mm_util_resize_B_P failed : %d", err);
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+static int __create_gif_thumbnail_to_buffer(const char *path, unsigned int thumb_w, unsigned int thumb_h, mm_util_image_h *thumbnail)
+{
+ int err = MS_MEDIA_ERR_NONE;
+ mm_util_image_h decode_image = NULL;
+
+ err = mm_util_decode_from_gif_file(path, &decode_image);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "mm_util_decode_from_gif_file failed : %d", err);
+
+ err = mm_util_resize_B_B(decode_image, thumb_w, thumb_h, thumbnail);
+ mm_image_destroy_image(decode_image);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "mm_util_resize_B_B failed : %d", err);
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+static int __decode_jpeg_with_downscale(const char *path, size_t image_size, size_t thumb_size, mm_util_image_h *decode_image)
+{
+ mm_util_jpeg_decode_downscale downscale = MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1;
+
+ // The downscale divide each width & height, so we should use squares 4(2*2), 16(4*4), 64(8*8).
+ if ((image_size >= thumb_size * 4) && (image_size < thumb_size * 16))
+ downscale = MM_UTIL_JPEG_DECODE_DOWNSCALE_1_2;
+ else if ((image_size >= thumb_size * 16) && (image_size < thumb_size * 64))
+ downscale = MM_UTIL_JPEG_DECODE_DOWNSCALE_1_4;
+ else if (image_size >= thumb_size * 64)
+ downscale = MM_UTIL_JPEG_DECODE_DOWNSCALE_1_8;
+
+ thumb_info("downscale: %d", downscale);
+
+ return mm_util_decode_from_jpeg_file(path, MM_UTIL_COLOR_RGB24, downscale, decode_image);
+}
+
+static int __create_jpeg_thumbnail_to_file(const char *path, size_t image_size, unsigned int thumb_w, unsigned int thumb_h, const char *thumb_path, bool auto_rotate)
+{
+ int err = MS_MEDIA_ERR_NONE;
+ mm_util_image_h decode_image = NULL;
+ mm_util_image_h resize_image = NULL;
+ mm_util_rotate_type_e rotation = __get_image_orientation(path);
+
+ err = __decode_jpeg_with_downscale(path, image_size, (size_t)(thumb_w * thumb_h), &decode_image);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "mm_util_decode_from_jpeg_file failed : %d", err);
+
+ if (auto_rotate && (rotation != MM_UTIL_ROTATE_0)) {
+ err = mm_util_resize_B_B(decode_image, thumb_w, thumb_h, &resize_image);
+ mm_image_destroy_image(decode_image);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "mm_util_resize_B_B failed : %d", err);
+
+ err = mm_util_rotate_B_P(resize_image, rotation, thumb_path);
+ mm_image_destroy_image(resize_image);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "mm_util_rotate_B_P failed : %d", err);
+ } else {
+ err = mm_util_resize_B_P(decode_image, thumb_w, thumb_h, thumb_path);
+ mm_image_destroy_image(decode_image);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "mm_util_resize_B_P failed : %d", err);
+ }
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+static int __create_jpeg_thumbnail_to_buffer(const char *path, size_t image_size, unsigned int thumb_w, unsigned int thumb_h, mm_util_image_h *thumbnail)
+{
+ int err = MS_MEDIA_ERR_NONE;
+ mm_util_image_h decode_image = NULL;
+
+ err = __decode_jpeg_with_downscale(path, image_size, (size_t)(thumb_w * thumb_h), &decode_image);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "mm_util_decode_from_jpeg_file failed : %d", err);
+
+ err = mm_util_resize_B_B(decode_image, thumb_w, thumb_h, thumbnail);
+ mm_image_destroy_image(decode_image);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "mm_util_resize_B_B failed : %d", err);
+
+ return MS_MEDIA_ERR_NONE;
+}
#endif
int create_image_thumbnail_to_file(const char *path, unsigned int width, unsigned int height, const char *thumb_path, bool auto_rotate)
@@ -610,55 +699,10 @@ int create_image_thumbnail_to_file(const char *path, unsigned int width, unsigne
__media_thumb_get_proper_thumb_size(image_w, image_h, &thumb_w, &thumb_h);
#if defined(USE_MEMORY_USAGE_REDUCTION)
- if (image_type == IMG_CODEC_GIF) {
- mm_util_image_h decode_image = NULL;
-
- err = mm_util_decode_from_gif_file(path, &decode_image);
- thumb_retvm_if(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "mm_util_decode_from_gif_file failed : %d", err);
-
- err = mm_util_resize_B_P(decode_image, thumb_w, thumb_h, thumb_path);
- mm_image_destroy_image(decode_image);
- thumb_retvm_if(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "mm_util_resize_B_P failed : %d", err);
-
- return MS_MEDIA_ERR_NONE;
- } else if (image_type == IMG_CODEC_JPEG) {
- mm_util_image_h decode_image = NULL;
- mm_util_image_h resize_image = NULL;
- mm_util_jpeg_decode_downscale downscale = MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1;
- unsigned int thumb_size = thumb_w * thumb_h;
- unsigned int image_size = image_w * image_h;
- mm_util_rotate_type_e rotation = __get_image_orientation(path);
-
- // The downscale divide each width & height, so we should use squares 4(2*2), 16(4*4), 64(8*8).
- if ((image_size >= thumb_size * 4) && (image_size < thumb_size * 16)) {
- downscale = MM_UTIL_JPEG_DECODE_DOWNSCALE_1_2;
- } else if ((image_size >= thumb_size * 16) && (image_size < thumb_size * 64)) {
- downscale = MM_UTIL_JPEG_DECODE_DOWNSCALE_1_4;
- } else if (image_size >= thumb_size * 64) {
- downscale = MM_UTIL_JPEG_DECODE_DOWNSCALE_1_8;
- }
-
- thumb_info("downscale: %d", downscale);
-
- err = mm_util_decode_from_jpeg_file(path, MM_UTIL_COLOR_RGB24, downscale, &decode_image);
- thumb_retvm_if(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "mm_util_decode_from_jpeg_file failed : %d", err);
-
- if (auto_rotate && (rotation != MM_UTIL_ROTATE_0)) {
- err = mm_util_resize_B_B(decode_image, thumb_w, thumb_h, &resize_image);
- mm_image_destroy_image(decode_image);
- thumb_retvm_if(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "mm_util_resize_B_B failed : %d", err);
-
- err = mm_util_rotate_B_P(resize_image, rotation, thumb_path);
- mm_image_destroy_image(resize_image);
- thumb_retvm_if(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "mm_util_rotate_B_P failed : %d", err);
- } else {
- err = mm_util_resize_B_P(decode_image, thumb_w, thumb_h, thumb_path);
- mm_image_destroy_image(decode_image);
- thumb_retvm_if(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "mm_util_resize_B_P failed : %d", err);
- }
-
- return MS_MEDIA_ERR_NONE;
- }
+ if (image_type == IMG_CODEC_GIF)
+ return __create_gif_thumbnail_to_file(path, thumb_w, thumb_h, thumb_path);
+ else if (image_type == IMG_CODEC_JPEG)
+ return __create_jpeg_thumbnail_to_file(path, (size_t)(image_w * image_h), thumb_w, thumb_h, thumb_path, auto_rotate);
#endif
if (auto_rotate)
@@ -692,38 +736,11 @@ int create_image_thumbnail_to_buffer(const char *path, unsigned int width, unsig
#if defined(USE_MEMORY_USAGE_REDUCTION)
if (image_type == IMG_CODEC_GIF) {
- mm_util_image_h decode_image = NULL;
-
- err = mm_util_decode_from_gif_file(path, &decode_image);
- thumb_retvm_if(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "mm_util_decode_from_gif_file failed : %d", err);
-
- err = mm_util_resize_B_B(decode_image, thumb_w, thumb_h, &img);
- mm_image_destroy_image(decode_image);
- thumb_retvm_if(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "mm_util_resize_B_B failed : %d", err);
+ err = __create_gif_thumbnail_to_buffer(path, thumb_w, thumb_h, &img);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "__create_gif_thumbnail_to_buffer failed : %d", err);
} else if (image_type == IMG_CODEC_JPEG) {
- mm_util_image_h decode_image = NULL;
- mm_util_jpeg_decode_downscale downscale = MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1;
- unsigned int thumb_size = thumb_w * thumb_h;
- unsigned int image_size = image_w * image_h;
-
- // The downscale divide each width & height, so we should use squares 4(2*2), 16(4*4), 64(8*8).
- if ((image_size >= thumb_size * 4) && (image_size < thumb_size * 16)) {
- downscale = MM_UTIL_JPEG_DECODE_DOWNSCALE_1_2;
- } else if ((image_size >= thumb_size * 16) && (image_size < thumb_size * 64)) {
- downscale = MM_UTIL_JPEG_DECODE_DOWNSCALE_1_4;
- } else if (image_size >= thumb_size * 64) {
- downscale = MM_UTIL_JPEG_DECODE_DOWNSCALE_1_8;
- }
-
- thumb_info("downscale: %d", downscale);
- err = mm_util_decode_from_jpeg_file(path, MM_UTIL_COLOR_RGB24, downscale, &decode_image);
- thumb_retvm_if(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "mm_util_decode_from_jpeg_file failed : %d", err);
-
- err = mm_util_resize_B_B(decode_image, thumb_w, thumb_h, &img);
- mm_image_destroy_image(decode_image);
- thumb_retvm_if(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "mm_util_resize_B_B failed : %d", err);
-
- return MS_MEDIA_ERR_NONE;
+ err = __create_jpeg_thumbnail_to_buffer(path, (size_t)(image_w * image_h), thumb_w, thumb_h, &img);
+ thumb_retvm_if(err != MM_UTIL_ERROR_NONE, MS_MEDIA_ERR_INTERNAL, "__create_jpeg_thumbnail_to_buffer failed : %d", err);
} else
#endif
{