summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMinje Ahn <minje.ahn@samsung.com>2018-01-25 00:57:30 (GMT)
committerMinje Ahn <minje.ahn@samsung.com>2018-01-31 05:58:04 (GMT)
commit6fd9ba41fd0ee715c77f37f0211435f8e44562bc (patch)
treec2b3f07600af5e7d3e68e9ba2eb5ab5374c19eaf /src
parenteecae1bb5a57f33fc65c203afc8024266f03356d (diff)
downloadlibmedia-thumbnail-6fd9ba41fd0ee715c77f37f0211435f8e44562bc.zip
libmedia-thumbnail-6fd9ba41fd0ee715c77f37f0211435f8e44562bc.tar.gz
libmedia-thumbnail-6fd9ba41fd0ee715c77f37f0211435f8e44562bc.tar.bz2
Modify video thumbnail processrefs/changes/82/168182/4
Change-Id: Iddde97e813d5d5ea1d67524cf1063561d65f7c91 Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
Diffstat (limited to 'src')
-rwxr-xr-xsrc/include/media-thumb-internal.h2
-rwxr-xr-xsrc/include/util/media-thumb-util.h2
-rwxr-xr-xsrc/media-thumb-internal.c172
3 files changed, 106 insertions, 70 deletions
diff --git a/src/include/media-thumb-internal.h b/src/include/media-thumb-internal.h
index 43d9b41..94f9e8f 100755
--- a/src/include/media-thumb-internal.h
+++ b/src/include/media-thumb-internal.h
@@ -65,7 +65,7 @@ typedef struct {
} thumbRawUserData;
int _media_thumb_image(const char *origin_path, const char *thumb_path, int thumb_width, int thumb_height, media_thumb_info *thumb_info);
-int _media_thumb_video(const char *origin_path, int thumb_width, int thumb_height, media_thumb_info *thumb_info);
+int _media_thumb_video(const char *origin_path, const char *thumb_path, int thumb_width, int thumb_height, media_thumb_info *thumb_info);
int _media_thumb_get_hash_name(const char *file_full_path, char *thumb_hash_path, size_t max_thumb_path, uid_t uid);
int _media_thumb_save_to_file_with_evas(unsigned char *data, int w, int h, int alpha, char *thumb_path);
diff --git a/src/include/util/media-thumb-util.h b/src/include/util/media-thumb-util.h
index c71d6a3..a166bcb 100755
--- a/src/include/util/media-thumb-util.h
+++ b/src/include/util/media-thumb-util.h
@@ -25,6 +25,8 @@
#define _MEDIA_THUMB_UTIL_H_
#define SAFE_FREE(src) { if (src) {free(src); src = NULL; } }
+#define STRING_VALID(str) \
+ ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
#define THUMB_MALLOC(src, size) { if (size <= 0) {src = NULL; } \
else { src = malloc(size); if (src) memset(src, 0x0, size); } }
#define SAFE_STRLCPY(dst, src, n) g_strlcpy(dst, src, n);
diff --git a/src/media-thumb-internal.c b/src/media-thumb-internal.c
index e77a6a2..b0069d4 100755
--- a/src/media-thumb-internal.c
+++ b/src/media-thumb-internal.c
@@ -42,6 +42,8 @@
#include <Ecore_Evas.h>
#include <libexif/exif-data.h>
+#include <mm_util_magick.h>
+
#define MEDIA_THUMB_ROUND_UP_8(num) (((num)+7)&~7)
static int __media_thumb_get_buffer_size(image_util_colorspace_e format, unsigned int width, unsigned int height, unsigned int *imgsize)
@@ -1018,45 +1020,55 @@ int _media_thumb_image(const char *origin_path, const char *thumb_path, int thum
return err;
}
-int _media_thumb_video(const char *origin_path, int thumb_width, int thumb_height, media_thumb_info *thumb_info)
+int _media_thumb_video(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;
MMHandleType content = (MMHandleType) NULL;
+ MMHandleType tag = (MMHandleType) NULL;
+
+ char *p = NULL;
+ int cdis_value = 0;
void *frame = NULL;
int video_track_num = 0;
char *err_msg = NULL;
int size = 0;
int width = 0;
int height = 0;
+ mm_util_image_h img = NULL;
+ mm_util_image_h resize_img = NULL;
+ mm_util_image_h dst_img = NULL;
- /* Get Content Tag attribute for orientatin */
- MMHandleType tag = (MMHandleType) NULL;
- char *p = NULL;
- int cdis_value = 0;
+ unsigned char *res_buf = NULL;
+ size_t res_size = 0;
+ unsigned int res_width = 0;
+ unsigned int res_height = 0;
+ mm_util_magick_format res_format;
+
+ /* Get Content Tag attribute for orientation */
err = mm_file_create_tag_attrs(&tag, origin_path);
- image_util_rotation_e rot_type = IMAGE_UTIL_ROTATION_NONE;
+ mm_util_magick_rotate_type rot_type = MM_UTIL_ROTATE_NUM;
if (err == FILEINFO_ERROR_NONE) {
err = mm_file_get_attrs(tag, &err_msg, MM_FILE_TAG_ROTATE, &p, &size, NULL);
if (err == FILEINFO_ERROR_NONE && size >= 0) {
if (p == NULL) {
- rot_type = IMAGE_UTIL_ROTATION_NONE;
+ rot_type = MM_UTIL_ROTATE_0;
} else {
if (strncmp(p, "90", size) == 0) {
- rot_type = IMAGE_UTIL_ROTATION_90;
+ rot_type = MM_UTIL_ROTATE_90;
} else if (strncmp(p, "180", size) == 0) {
- rot_type = IMAGE_UTIL_ROTATION_180;
+ rot_type = MM_UTIL_ROTATE_180;
} else if (strncmp(p, "270", size) == 0) {
- rot_type = IMAGE_UTIL_ROTATION_270;
+ rot_type = MM_UTIL_ROTATE_270;
} else {
- rot_type = IMAGE_UTIL_ROTATION_NONE;
+ rot_type = MM_UTIL_ROTATE_0;
}
}
thumb_dbg("There is tag rotate : %d", rot_type);
} else {
thumb_dbg("There is NOT tag rotate");
- rot_type = IMAGE_UTIL_ROTATION_NONE;
+ rot_type = MM_UTIL_ROTATE_0;
SAFE_FREE(err_msg);
}
@@ -1067,7 +1079,7 @@ int _media_thumb_video(const char *origin_path, int thumb_width, int thumb_heigh
}
} else {
- rot_type = IMAGE_UTIL_ROTATION_NONE;
+ rot_type = MM_UTIL_ROTATE_0;
cdis_value = 0;
}
@@ -1092,8 +1104,7 @@ int _media_thumb_video(const char *origin_path, int thumb_width, int thumb_heigh
if (err != FILEINFO_ERROR_NONE) {
thumb_err("mm_file_get_attrs fails : %s", err_msg);
SAFE_FREE(err_msg);
- mm_file_destroy_content_attrs(content);
- return MS_MEDIA_ERR_INTERNAL;
+ goto ERROR;
}
if (video_track_num > 0) {
@@ -1108,76 +1119,99 @@ int _media_thumb_video(const char *origin_path, int thumb_width, int thumb_heigh
if (err != FILEINFO_ERROR_NONE) {
thumb_err("mm_file_get_attrs fails : %s", err_msg);
SAFE_FREE(err_msg);
- mm_file_destroy_content_attrs(content);
- return MS_MEDIA_ERR_INTERNAL;
+ goto ERROR;
}
- thumb_dbg("video width: %d", width);
- thumb_dbg("video height: %d", height);
- thumb_dbg("thumbnail size: %d", size);
- thumb_dbg("frame: %p", frame);
- thumb_dbg("orientation: %d", rot_type);
-
+ thumb_dbg("W[%d] H[%d] Size[%d] Frame[%p] Rotate[%d]", width, height, size, frame, rot_type);
if (frame == NULL || width == 0 || height == 0) {
thumb_err("Failed to get frame data");
- mm_file_destroy_content_attrs(content);
- return MS_MEDIA_ERR_INTERNAL;
+ goto ERROR;
}
- thumb_info->origin_width = width;
- thumb_info->origin_height = height;
+ thumb_info->is_saved = true;
err = _media_thumb_get_proper_thumb_size(width, height, &thumb_width, &thumb_height);
-
- unsigned int new_size = 0;
- unsigned char *new_frame = NULL;
- err = _media_thumb_rgb_to_argb(frame, size, &new_frame, &new_size, width, height);
- if ((err != MS_MEDIA_ERR_NONE) || (new_frame == NULL)) {
- thumb_err("_media_thumb_convert_video falied: %d", err);
- mm_file_destroy_content_attrs(content);
- SAFE_FREE(new_frame);
- return err;
+ if (thumb_width <= 0 || thumb_height <= 0) {
+ thumb_err("Failed to get thumb size");
+ goto ERROR;
}
- mm_file_destroy_content_attrs(content);
- thumb_dbg("original size - width:%d, height:%d", width, height);
- thumb_dbg("proper thumb size - width:%d, height:%d", thumb_width, thumb_height);
+ thumb_dbg("Origin:W[%d] H[%d] Proper:W[%d] H[%d]", width, height, thumb_width, thumb_height);
+
+ err = mm_util_create_handle(&img, (unsigned char *)frame, width, height, size, MM_UTIL_IMG_FMT_RGB888);
if (width > thumb_width || height > thumb_height) {
- err = _media_thumb_resize_with_evas(new_frame, thumb_width, thumb_height, thumb_info);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_resize_video_with_evas falied: %d", err);
- SAFE_FREE(new_frame);
- return err;
+ if (rot_type != MM_UTIL_ROTATE_0) {
+ if (STRING_VALID(thumb_path)) {
+ err = mm_util_resize_B_B(img, thumb_width, thumb_height, &resize_img);
+ if (err != MM_UTIL_ERROR_NONE)
+ goto ERROR;
+ err = mm_util_rotate_B_P(resize_img, rot_type, thumb_path);
+ } else {
+ err = mm_util_resize_B_B(img, thumb_width, thumb_height, &resize_img);
+ if (err != MM_UTIL_ERROR_NONE)
+ goto ERROR;
+ err = mm_util_rotate_B_B(resize_img, rot_type, &dst_img);
+ if (err != MM_UTIL_ERROR_NONE)
+ goto ERROR;
+ mm_util_get_image(dst_img, &res_buf, &res_width, &res_height, &res_size, &res_format);
+ thumb_info->data = calloc(1, res_size);
+ memcpy(thumb_info->data, res_buf, res_size);
+ thumb_info->size = res_size;
+ thumb_info->width = res_width;
+ thumb_info->height = res_height;
+ SAFE_FREE(res_buf);
+ }
+ } else {
+ if (STRING_VALID(thumb_path)) {
+ err = mm_util_resize_B_P(img, thumb_width, thumb_height, thumb_path);
+ } else {
+ err = mm_util_resize_B_B(img, thumb_width, thumb_height, &resize_img);
+ if (err != MM_UTIL_ERROR_NONE)
+ goto ERROR;
+ mm_util_get_image(resize_img, &res_buf, &res_width, &res_height, &res_size, &res_format);
+ thumb_info->data = calloc(1, res_size);
+ memcpy(thumb_info->data, res_buf, res_size);
+ thumb_info->size = res_size;
+ thumb_info->width = res_width;
+ thumb_info->height = res_height;
+ SAFE_FREE(res_buf);
+ }
}
} else {
- thumb_info->size = new_size;
- thumb_info->width = width;
- thumb_info->height = height;
- thumb_info->data = malloc(new_size);
- if (thumb_info->data == NULL) {
- thumb_err("memory allcation failed");
- SAFE_FREE(new_frame);
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
- memcpy(thumb_info->data, new_frame, new_size);
- }
- SAFE_FREE(new_frame);
-
- if (rot_type == IMAGE_UTIL_ROTATION_90 || rot_type == IMAGE_UTIL_ROTATION_180 || rot_type == IMAGE_UTIL_ROTATION_270) {
- err = _media_thumb_rotate_thumb(thumb_info->data, thumb_info->size, &(thumb_info->width), &(thumb_info->height), rot_type, IMAGE_UTIL_COLORSPACE_BGRA8888);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_rotate_thumb falied: %d", err);
- SAFE_FREE(thumb_info->data);
- return err;
+ if (rot_type != MM_UTIL_ROTATE_0) {
+ if (STRING_VALID(thumb_path)) {
+ err = mm_util_rotate_B_P(img, rot_type, thumb_path);
+ } else {
+ err = mm_util_rotate_B_B(img, rot_type, &dst_img);
+ if (err != MM_UTIL_ERROR_NONE)
+ goto ERROR;
+ mm_util_get_image(dst_img, &res_buf, &res_width, &res_height, &res_size, &res_format);
+ thumb_info->data = calloc(1, res_size);
+ memcpy(thumb_info->data, res_buf, res_size);
+ thumb_info->size = res_size;
+ thumb_info->width = res_width;
+ thumb_info->height = res_height;
+ SAFE_FREE(res_buf);
+ }
+ } else {
+ if (STRING_VALID(thumb_path)) {
+ err = mm_util_resize_B_P(img, width, height, thumb_path);
+ } else {
+ thumb_info->data = calloc(1, size);
+ memcpy(thumb_info->data, frame, size);
+ thumb_info->size = size;
+ thumb_info->width = width;
+ thumb_info->height = height;
+ }
}
}
- } else {
- thumb_dbg("no contents information");
- frame = NULL;
- mm_file_destroy_content_attrs(content);
-
- return MS_MEDIA_ERR_INTERNAL;
}
+ERROR:
+ mm_util_destroy_handle(img);
+ mm_util_destroy_handle(resize_img);
+ mm_util_destroy_handle(dst_img);
+ mm_file_destroy_content_attrs(content);
+
return err;
}