#include "media-thumb-util.h"
#include "media-thumb-internal.h"
#include "media-thumb-ipc.h"
-
-#if defined(WITH_DA_PROFILE)
-/* The maximum of resolution to be able to get thumbnail is 3000 x 2000, except for only jpeg */
-#define THUMB_MAX_ALLOWED_MEM_FOR_THUMB 6000000
+#if defined(USE_MEMORY_USAGE_REDUCTION)
+#include <mm_util_gif.h>
+#include <mm_util_jpeg.h>
+#include <libexif/exif-data.h>
#endif
+
#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)
return err;
}
-static int __get_image_info(const char *path, unsigned int *width, unsigned int *height)
+static int __get_image_info(const char *path, unsigned int *width, unsigned int *height, mm_util_img_codec_type *type)
{
int err = MS_MEDIA_ERR_NONE;
mm_util_img_codec_type image_type = 0;
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 defined(WITH_DA_PROFILE)
- if (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_UNSUPPORTED_CONTENT;
- }
-#endif
+ *type = image_type;
*width = image_w;
*height = image_h;
return MS_MEDIA_ERR_NONE;
}
+#if defined(USE_MEMORY_USAGE_REDUCTION)
+static mm_util_rotate_type_e __get_image_orientation(const char *path)
+{
+ ExifData *ed = NULL;
+ ExifEntry *entry = NULL;
+ short orientation = 0;
+ mm_util_rotate_type_e rotation = MM_UTIL_ROTATE_0;
+
+ ed = exif_data_new_from_file(path);
+ thumb_retvm_if(!ed, MM_UTIL_ROTATE_0, "no exif data");
+
+ entry = exif_data_get_entry(ed, EXIF_TAG_ORIENTATION);
+ if (!entry) {
+ thumb_info("no orientation entry");
+ exif_data_unref(ed);
+ return MM_UTIL_ROTATE_0;
+ }
+
+ orientation = exif_get_short(entry->data, exif_data_get_byte_order(ed));
+
+ /* exif orientation
+ * 0 - not available, 1- normal, 2 - hflip, 3 - rot_180,
+ * 4 - vflip, 5 - tranpose, 6 - rot_90, 7 - transverse, 8 - rot_270
+ */
+ switch (orientation) {
+ case 3:
+ rotation = MM_UTIL_ROTATE_180;
+ break;
+ case 6:
+ rotation = MM_UTIL_ROTATE_90;
+ break;
+ case 8:
+ rotation = MM_UTIL_ROTATE_270;
+ break;
+ default:
+ thumb_warn("not supported orientation[%d], rotation will be 0", orientation);
+ rotation = MM_UTIL_ROTATE_0;
+ break;
+ };
+
+ exif_data_unref(ed);
+ thumb_info("orientation: %d, rotation: %d", orientation, rotation);
+
+ return rotation;
+}
+#endif
+
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_h = 0;
unsigned int thumb_w = width;
unsigned int thumb_h = height;
+ mm_util_img_codec_type image_type = 0;
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);
+ err = __get_image_info(path, &image_w, &image_h, &image_type);
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);
+#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;
+ }
+#endif
+
if (auto_rotate)
err = mm_util_resize_and_rotate_P_P(path, thumb_w, thumb_h, thumb_path);
else
unsigned int thumb_w = width;
unsigned int thumb_h = height;
mm_util_image_h img = NULL;
+ mm_util_img_codec_type image_type = 0;
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);
+ err = __get_image_info(path, &image_w, &image_h, &image_type);
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);
+#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);
+ } 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;
+ } else
+#endif
+ {
+ 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);