summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinje Ahn <minje.ahn@samsung.com>2018-01-30 04:35:15 (GMT)
committerMinje ahn <minje.ahn@samsung.com>2018-01-31 06:10:35 (GMT)
commit96113cadb625d3960d04910107bd6c51153ed420 (patch)
treedccb5a4a8b557cda32b45a1e88a98d8f830c6feb
parent6fd9ba41fd0ee715c77f37f0211435f8e44562bc (diff)
downloadlibmedia-thumbnail-96113cadb625d3960d04910107bd6c51153ed420.zip
libmedia-thumbnail-96113cadb625d3960d04910107bd6c51153ed420.tar.gz
libmedia-thumbnail-96113cadb625d3960d04910107bd6c51153ed420.tar.bz2
Modified image thumbnail processrefs/changes/40/168640/4
Change evas to graphicsmagick Remove EXIF checking process Change-Id: I80dadfb735f7ce82ab80f0c72eeec4524d401291 Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
-rwxr-xr-xCMakeLists.txt2
-rw-r--r--packaging/libmedia-thumbnail.spec5
-rwxr-xr-xserver/include/thumb-server-internal.h9
-rwxr-xr-xserver/thumb-server-internal.c106
-rwxr-xr-xserver/thumb-server.c3
-rwxr-xr-xsrc/codec/img-codec-parser.c2
-rwxr-xr-xsrc/include/media-thumb-internal.h20
-rwxr-xr-xsrc/media-thumb-internal.c1007
-rw-r--r--test/CMakeLists.txt2
9 files changed, 57 insertions, 1099 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2c95a0a..3966844 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -38,7 +38,7 @@ MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src/include ${CMAKE_SOURCE_DIR}/src/include/util ${CMAKE_SOURCE_DIR}/src/include/codec ${CMAKE_SOURCE_DIR}/src/include/util ${CMAKE_SOURCE_DIR}/src/include/ipc ${CMAKE_SOURCE_DIR}/server/include ${CMAKE_SOURCE_DIR}/md5)
INCLUDE(FindPkgConfig)
- pkg_check_modules(pkgs REQUIRED glib-2.0 gthread-2.0 dlog sqlite3 mm-fileinfo aul libexif ecore-evas evas capi-media-image-util libmedia-utils libtzplatform-config db-util mmutil-magick)
+ pkg_check_modules(pkgs REQUIRED glib-2.0 gthread-2.0 dlog sqlite3 mm-fileinfo aul capi-media-image-util libmedia-utils libtzplatform-config db-util mmutil-magick)
FOREACH(flag ${pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
diff --git a/packaging/libmedia-thumbnail.spec b/packaging/libmedia-thumbnail.spec
index 448123e..a6e1691 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.2.17
+Version: 0.2.18
Release: 0
Group: Multimedia/Libraries
License: Apache-2.0 and PD
@@ -14,9 +14,6 @@ BuildRequires: cmake
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(mm-fileinfo)
BuildRequires: pkgconfig(capi-media-image-util)
-BuildRequires: pkgconfig(libexif)
-BuildRequires: pkgconfig(evas)
-BuildRequires: pkgconfig(ecore)
BuildRequires: pkgconfig(aul)
BuildRequires: pkgconfig(libmedia-utils)
BuildRequires: pkgconfig(libtzplatform-config)
diff --git a/server/include/thumb-server-internal.h b/server/include/thumb-server-internal.h
index 5e0c47f..927f9e0 100755
--- a/server/include/thumb-server-internal.h
+++ b/server/include/thumb-server-internal.h
@@ -27,17 +27,10 @@
#define _THUMB_DAEMON_INTERNAL_H_
gboolean _thumb_daemon_start_jobs(gpointer data);
-void _thumb_daemon_finish_jobs(void);
gboolean _thumb_server_prepare_socket(int *sock_fd);
gboolean _thumb_server_read_socket(GIOChannel *src, GIOCondition condition, gpointer data);
-int _thumbnail_get_data(const char *origin_path,
- char *thumb_path,
- unsigned char **data,
- int *width,
- int *height,
- int *alpha,
- bool *is_saved);
+int _thumbnail_get_data(const char *origin_path, char *thumb_path);
int _thumbnail_get_raw_data(const char *origin_path, int *width, int *height, unsigned char **data, int *size);
diff --git a/server/thumb-server-internal.c b/server/thumb-server-internal.c
index 2c84120..22a0ff8 100755
--- a/server/thumb-server-internal.c
+++ b/server/thumb-server-internal.c
@@ -28,7 +28,6 @@
#include <dirent.h>
#include <stdio.h>
#include <string.h>
-#include <Ecore_Evas.h>
#include <tzplatform_config.h>
#ifdef LOG_TAG
@@ -50,23 +49,11 @@ static gboolean _thumb_server_send_deny_message(int sockfd);
gboolean _thumb_daemon_start_jobs(gpointer data)
{
thumb_dbg("");
- /* Initialize ecore-evas to use evas library */
- ecore_evas_init();
-
__thumb_server_send_msg_to_agent(MS_MSG_THUMB_SERVER_READY);
return FALSE;
}
-void _thumb_daemon_finish_jobs(void)
-{
- /* Shutdown ecore-evas */
- ecore_evas_shutdown();
- g_main_loop_quit(g_thumb_server_mainloop);
-
- return;
-}
-
int _thumb_daemon_process_job(thumbMsg *req_msg, thumbMsg *res_msg)
{
int err = MS_MEDIA_ERR_NONE;
@@ -150,7 +137,7 @@ gboolean _thumb_server_read_socket(GIOChannel *src, GIOCondition condition, gpoi
int buf_size = 0;
int sending_block = 0;
- int block_size = sizeof(res_msg) - MAX_FILEPATH_LEN*2 - sizeof(unsigned char *);
+ int block_size = sizeof(res_msg) - MAX_FILEPATH_LEN * 2 - sizeof(unsigned char *);
unsigned char *buf = NULL;
_media_thumb_set_buffer(&res_msg, &buf, &buf_size);
@@ -257,51 +244,36 @@ gboolean _thumb_server_prepare_socket(int *sock_fd)
return TRUE;
}
-int _thumbnail_get_data(const char *origin_path,
- char *thumb_path,
- unsigned char **data,
- int *width,
- int *height,
- int *alpha,
- bool *is_saved)
+int _thumbnail_get_data(const char *origin_path, char *thumb_path)
{
int err = MS_MEDIA_ERR_NONE;
+ int file_type = THUMB_NONE_TYPE;
- if (origin_path == NULL || width == NULL || height == NULL) {
- thumb_err("Invalid parameter");
+ if (origin_path == NULL) {
+ thumb_err("Original path is null");
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
- if (!g_file_test(origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
+ if (!g_file_test(origin_path, G_FILE_TEST_IS_REGULAR)) {
thumb_err("Original path (%s) does not exist", origin_path);
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
thumb_dbg("Origin path : %s", origin_path);
-
- int file_type = THUMB_NONE_TYPE;
- media_thumb_info thumb_info = {0,};
file_type = _media_thumb_get_file_type(origin_path);
- thumb_info.is_raw = FALSE;
if (file_type == THUMB_IMAGE_TYPE) {
- err = _media_thumb_image(origin_path, thumb_path, THUMB_DEFAULT_WIDTH, THUMB_DEFAULT_HEIGHT, &thumb_info);
+ err = _media_thumb_image(origin_path, thumb_path, THUMB_DEFAULT_WIDTH, THUMB_DEFAULT_HEIGHT, NULL);
thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "_media_thumb_image failed");
} else if (file_type == THUMB_VIDEO_TYPE) {
- err = _media_thumb_video(origin_path, thumb_path, THUMB_DEFAULT_WIDTH, THUMB_DEFAULT_HEIGHT, &thumb_info);
+ err = _media_thumb_video(origin_path, thumb_path, THUMB_DEFAULT_WIDTH, THUMB_DEFAULT_HEIGHT, NULL);
thumb_retvm_if(err != MS_MEDIA_ERR_NONE, MS_MEDIA_ERR_INTERNAL, "_media_thumb_video failed");
} else {
thumb_err("invalid file type");
return MS_MEDIA_ERR_THUMB_UNSUPPORTED;
}
- if (width) *width = thumb_info.width;
- if (height) *height = thumb_info.height;
- *data = thumb_info.data;
- if (alpha) *alpha = thumb_info.alpha;
- if (is_saved) *is_saved = thumb_info.is_saved;
-
- thumb_dbg("Thumb data is generated successfully (Size:%d, W:%d, H:%d) %p", thumb_info.size, *width, *height, *data);
+ thumb_dbg("Thumb data is generated successfully");
return MS_MEDIA_ERR_NONE;
}
@@ -311,7 +283,6 @@ int _thumbnail_get_raw_data(const char *origin_path, int *width, int *height, un
int err = MS_MEDIA_ERR_NONE;
int thumb_width = -1;
int thumb_height = -1;
- const char * thumb_path = NULL;
if (origin_path == NULL || *width <= 0 || *height <= 0) {
thumb_err("Invalid parameter");
@@ -328,10 +299,9 @@ int _thumbnail_get_raw_data(const char *origin_path, int *width, int *height, un
file_type = _media_thumb_get_file_type(origin_path);
thumb_width = *width;
thumb_height = *height;
- thumb_info.is_raw = TRUE;
if (file_type == THUMB_IMAGE_TYPE) {
- err = _media_thumb_image(origin_path, thumb_path, thumb_width, thumb_height, &thumb_info);
+ err = _media_thumb_image(origin_path, NULL, thumb_width, thumb_height, &thumb_info);
thumb_retvm_if(err != MS_MEDIA_ERR_NONE, err, "_media_thumb_image failed");
} else if (file_type == THUMB_VIDEO_TYPE) {
err = _media_thumb_video(origin_path, NULL, thumb_width, thumb_height, &thumb_info);
@@ -352,12 +322,7 @@ int _thumbnail_get_raw_data(const char *origin_path, int *width, int *height, un
int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg)
{
int err = MS_MEDIA_ERR_NONE;
- unsigned char *data = NULL;
- int thumb_w = 0;
- int thumb_h = 0;
char *thumb_path = NULL;
- int alpha = 0;
- bool is_saved = FALSE;
thumb_retvm_if(req_msg == NULL || res_msg == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid msg");
@@ -390,15 +355,14 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg)
thumb_dbg_slog("Thumb path : %s", thumb_path);
- if (g_file_test(thumb_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
+ if (g_file_test(thumb_path, G_FILE_TEST_IS_REGULAR)) {
thumb_warn("thumb path already exists in file system.. remove the existed file");
_media_thumb_remove_file(thumb_path);
}
- err = _thumbnail_get_data(origin_path, thumb_path, &data, &thumb_w, &thumb_h, &alpha, &is_saved);
+ err = _thumbnail_get_data(origin_path, thumb_path);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_thumbnail_get_data failed - %d", err);
- SAFE_FREE(data);
SAFE_STRLCPY(thumb_path, THUMB_EMPTY_STR, MAX_FILEPATH_LEN);
res_msg->status = err;
@@ -407,52 +371,6 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg)
res_msg->msg_type = THUMB_RESPONSE;
- /* If the image is transparent PNG format, make png file as thumbnail of this image */
- if (alpha) {
- char file_ext[10];
- err = _media_thumb_get_file_ext(origin_path, file_ext, sizeof(file_ext));
- if (strncasecmp(file_ext, "png", 3) == 0) {
- int len = strlen(thumb_path);
- thumb_path[len - 3] = 'p';
- thumb_path[len - 2] = 'n';
- thumb_path[len - 1] = 'g';
- }
- thumb_dbg_slog("Thumb path is changed : %s", thumb_path);
- }
-
- if (is_saved == FALSE && data != NULL) {
- err = _media_thumb_save_to_file_with_evas(data, thumb_w, thumb_h, alpha, thumb_path);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("save_to_file_with_evas failed - %d", err);
- SAFE_FREE(data);
-
- SAFE_STRLCPY(thumb_path, THUMB_EMPTY_STR, MAX_FILEPATH_LEN);
- res_msg->status = err;
- return err;
- } else {
- thumb_dbg("file save success");
- }
- } else {
- thumb_dbg("file is already saved");
- }
-
- /* fsync */
- int fd = 0;
- fd = open(thumb_path, O_WRONLY);
- if (fd < 0) {
- thumb_warn("open failed");
- } else {
- err = fsync(fd);
- if (err == -1) {
- thumb_warn("fsync failed");
- res_msg->status = MS_MEDIA_ERR_INTERNAL;
- }
-
- close(fd);
- }
- /* End of fsync */
-
- SAFE_FREE(data);
DB_UPDATE:
err = _media_thumb_update_db(origin_path, thumb_path, req_msg->uid);
if (err != MS_MEDIA_ERR_NONE) {
diff --git a/server/thumb-server.c b/server/thumb-server.c
index 7de7eda..4a24e0a 100755
--- a/server/thumb-server.c
+++ b/server/thumb-server.c
@@ -80,8 +80,7 @@ int main(void)
/*close socket*/
close(sockfd);
- _thumb_daemon_finish_jobs();
-
+ g_main_loop_quit(g_thumb_server_mainloop);
g_main_loop_unref(g_thumb_server_mainloop);
ms_cynara_finish();
diff --git a/src/codec/img-codec-parser.c b/src/codec/img-codec-parser.c
index 75f0a06..498751a 100755
--- a/src/codec/img-codec-parser.c
+++ b/src/codec/img-codec-parser.c
@@ -606,7 +606,7 @@ int ImgGetImageInfoForThumb(const char *filePath, ImgCodecType *type, unsigned i
thumb_warn("_media_thumb_get_file_ext failed");
};
- ret = _ImgGetImageInfo(hFile, fileAttrib.fileSize, file_ext, type, width, height, TRUE);
+ ret = _ImgGetImageInfo(hFile, fileAttrib.fileSize, file_ext, type, width, height, FALSE);
DrmSeekFile(hFile, SEEK_SET, 0);
diff --git a/src/include/media-thumb-internal.h b/src/include/media-thumb-internal.h
index 94f9e8f..b0f84fe 100755
--- a/src/include/media-thumb-internal.h
+++ b/src/include/media-thumb-internal.h
@@ -34,26 +34,9 @@ typedef struct {
int size;
int width;
int height;
- int origin_width;
- int origin_height;
- int alpha;
unsigned char *data;
- bool is_saved;
- bool is_raw;
} media_thumb_info;
-enum Exif_Orientation {
- NOT_AVAILABLE = 0,
- NORMAL = 1,
- HFLIP = 2,
- ROT_180 = 3,
- VFLIP = 4,
- TRANSPOSE = 5,
- ROT_90 = 6,
- TRANSVERSE = 7,
- ROT_270 = 8
-};
-
typedef struct {
ThumbFunc func;
void *user_data;
@@ -64,9 +47,8 @@ typedef struct {
void *user_data;
} 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_image(const char *origin_path, char *thumb_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);
#endif /*_MEDIA_THUMB_INTERNAL_H_*/
diff --git a/src/media-thumb-internal.c b/src/media-thumb-internal.c
index b0069d4..ae46eeb 100755
--- a/src/media-thumb-internal.c
+++ b/src/media-thumb-internal.c
@@ -37,251 +37,8 @@
#include <unistd.h>
#include <mm_file.h>
-#include <image_util.h>
-#include <Evas.h>
-#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)
-{
- int err = IMAGE_UTIL_ERROR_NONE;
-
- err = image_util_calculate_buffer_size(width, height, format, imgsize);
- if (err != IMAGE_UTIL_ERROR_NONE) {
- thumb_err("image_util_calculate_buffer_size failed");
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_thumb_rgb_to_argb(const unsigned char *src_data, const int src_size,
- unsigned char **dst_data,
- unsigned int *buf_size,
- int width,
- int height)
-{
- int err = MS_MEDIA_ERR_NONE;
- int i = 0, j;
-
- if (__media_thumb_get_buffer_size(IMAGE_UTIL_COLORSPACE_BGRA8888, width, height, buf_size) < 0) {
- thumb_err("__media_thumb_get_buffer_size failed");
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- thumb_dbg("__media_thumb_get_buffer_size : %d", *buf_size);
-
- *dst_data = (unsigned char *)malloc(*buf_size);
- if (*dst_data == NULL) {
- thumb_err("Failed to allocate memory");
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
-
- for (j = 0; ((j < src_size) && (i < *buf_size)); j += 3) {
- (*dst_data)[i++] = (src_data[j + 2]);
- (*dst_data)[i++] = (src_data[j + 1]);
- (*dst_data)[i++] = (src_data[j]);
- (*dst_data)[i++] = 0x0;
- }
-
- thumb_dbg("_media_thumb_rgb_to_argb success");
-
- return err;
-}
-
-int _media_thumb_resize_with_evas(const void *image, int thumb_width, int thumb_height, media_thumb_info *thumb_info)
-{
- Ecore_Evas *resize_img_ee;
-
- if (image == NULL) {
- thumb_err("Invalid parameter");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
- resize_img_ee = ecore_evas_buffer_new(thumb_width, thumb_height);
- if (!resize_img_ee) {
- thumb_err("ecore_evas_buffer_new failed");
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- Evas *resize_img_e = ecore_evas_get(resize_img_ee);
- if (!resize_img_e) {
- thumb_err("ecore_evas_get failed");
- ecore_evas_free(resize_img_ee);
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- Evas_Object *source_img = evas_object_image_add(resize_img_e);
- if (!source_img) {
- thumb_err("evas_object_image_add failed");
- ecore_evas_free(resize_img_ee);
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- evas_object_image_size_set(source_img, thumb_info->origin_width, thumb_info->origin_height);
- evas_object_image_colorspace_set(source_img, EVAS_COLORSPACE_ARGB8888);
- evas_object_image_fill_set(source_img, 0, 0, thumb_info->origin_width, thumb_info->origin_height);
- evas_object_image_filled_set(source_img, EINA_TRUE);
-
- evas_object_image_data_set(source_img, (int *)image);
- evas_object_image_data_update_add(source_img, 0, 0, thumb_info->origin_width, thumb_info->origin_height);
-
- if (thumb_info->origin_width * thumb_info->origin_height > THUMB_MAX_ALLOWED_MEM_FOR_THUMB) {
- thumb_warn("This is too large image. so this's scale is going to be down");
- evas_object_image_load_scale_down_set(source_img, 10);
- }
-
- ecore_evas_resize(resize_img_ee, thumb_width, thumb_height);
-
- evas_object_image_load_size_set(source_img, thumb_width, thumb_height);
- evas_object_image_fill_set(source_img, 0, 0, thumb_width, thumb_height);
- evas_object_image_filled_set(source_img, EINA_TRUE);
-
- evas_object_resize(source_img, thumb_width, thumb_height);
- evas_object_show(source_img);
-
- /* Set alpha from original */
- thumb_info->alpha = evas_object_image_alpha_get(source_img);
- if (thumb_info->alpha)
- ecore_evas_alpha_set(resize_img_ee, EINA_TRUE);
-
- /* Create target buffer and copy origin resized img to it */
- Ecore_Evas *target_ee = ecore_evas_buffer_new(thumb_width, thumb_height);
- if (!target_ee) {
- thumb_err("ecore_evas_buffer_new failed");
- ecore_evas_free(resize_img_ee);
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- Evas *target_evas = ecore_evas_get(target_ee);
- if (!target_evas) {
- thumb_err("ecore_evas_get failed");
- ecore_evas_free(resize_img_ee);
- ecore_evas_free(target_ee);
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- Evas_Object *ret_image = evas_object_image_add(target_evas);
- evas_object_image_size_set(ret_image, thumb_width, thumb_height);
- evas_object_image_fill_set(ret_image, 0, 0, thumb_width, thumb_height);
- evas_object_image_filled_set(ret_image, EINA_TRUE);
-
- evas_object_image_data_set(ret_image, (int *)ecore_evas_buffer_pixels_get(resize_img_ee));
- evas_object_image_data_update_add(ret_image, 0, 0, thumb_width, thumb_height);
-
- unsigned int buf_size = 0;
- if (__media_thumb_get_buffer_size(IMAGE_UTIL_COLORSPACE_BGRA8888, thumb_width, thumb_height, &buf_size) < 0) {
- thumb_err("__media_thumb_get_buffer_size failed");
-
- ecore_evas_free(resize_img_ee);
- ecore_evas_free(target_ee);
-
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- thumb_info->size = buf_size;
- thumb_info->width = thumb_width;
- thumb_info->height = thumb_height;
- thumb_info->data = malloc(buf_size);
- if (thumb_info->data == NULL) {
- thumb_err("Failed to allocate memory");
- ecore_evas_free(resize_img_ee);
- ecore_evas_free(target_ee);
-
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
-
- void *image_data = evas_object_image_data_get(ret_image, EINA_TRUE);
- if (image_data != NULL) {
- memcpy(thumb_info->data, image_data, buf_size);
- } else {
- thumb_err("image_data is NULL. evas_object_image_data_get failed");
- }
-
- ecore_evas_free(target_ee);
- ecore_evas_free(resize_img_ee);
-
- thumb_dbg("_media_thumb_resize_with_evas success");
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_thumb_rotate_argb(unsigned char *source, const unsigned int size, int format, int *ori_width, int *ori_height)
-{
- int dpp = 0; /* data per pixel */
- int x = 0, y = 0;
- int i = 0;
- int width = 0, height = 0;
- unsigned char *temp_buf = NULL;
-
- if (format == IMAGE_UTIL_COLORSPACE_BGRA8888) {
- dpp = 4;
- } else if (format == IMAGE_UTIL_COLORSPACE_RGB888) {
- dpp = 3;
- } else {
- thumb_err("Invalid parameter");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- temp_buf = malloc(size);
- if (temp_buf == NULL) {
- thumb_err("Failed to allocate memory");
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
- /* initialize */
- memset(temp_buf, 0x00, size);
- width = *ori_width;
- height = *ori_height;
-
- /* rotate image to 90 degree clockwise */
- for (y = 0; y < height; y++) {
- for (x = 0; x < width; x++) {
- for (i = 0; i < dpp; i++) {
- temp_buf[(x * height + (height - y - 1)) * dpp + i] = source[(y * width + x) * dpp + i];
- }
- }
- }
-
- /* copy image from temp buffer to original buffer */
- memcpy(source, temp_buf, size);
- SAFE_FREE(temp_buf);
-
- /* swap width & height due to rotate 90 degree */
- *ori_width = height;
- *ori_height = width;
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_thumb_rotate_thumb(unsigned char *data, int size, int *width, int *height, int orientation, int format)
-{
- int err = MS_MEDIA_ERR_NONE;
- int i = 0, count = 0;
-
- if (orientation == IMAGE_UTIL_ROTATION_90) {
- count = 1;
- } else if (orientation == IMAGE_UTIL_ROTATION_180) {
- count = 2;
- } else if (orientation == IMAGE_UTIL_ROTATION_270) {
- count = 3;
- }
-
- for (i = 0; i < count; i++) {
- err = _media_thumb_rotate_argb(data, size, format, width, height);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("Failed to rotate video thumbnail %d", err);
- return err;
- }
-// thumb_dbg("[%d rotate] width:%d, height:%d", (i + 1) * 90, thumb_info->width, thumb_info->height);
- }
-
- thumb_dbg("_media_thumb_rotate_thumb success");
- return MS_MEDIA_ERR_NONE;
-}
-
int _media_thumb_get_proper_thumb_size(int orig_w, int orig_h, int *thumb_w, int *thumb_h)
{
BOOL portrait = FALSE;
@@ -304,689 +61,44 @@ int _media_thumb_get_proper_thumb_size(int orig_w, int orig_h, int *thumb_w, int
*thumb_w = *thumb_h * ratio;
}
- /** CAUTION :: The width of RGB888 raw data has to be rounded by 8 **/
- *thumb_w = MEDIA_THUMB_ROUND_UP_8(*thumb_w);
-
thumb_dbg("proper thumb w: %d h: %d", *thumb_w, *thumb_h);
return MS_MEDIA_ERR_NONE;
}
-int _media_thumb_get_exif_info(ExifData *ed, int *value, int ifdtype, long tagtype)
-{
- ExifEntry *entry;
- ExifIfd ifd;
- ExifTag tag;
-
- if (ed == NULL) {
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- ifd = ifdtype;
- tag = tagtype;
-
- entry = exif_content_get_entry(ed->ifd[ifd], tag);
- if (entry) {
- if (tag == EXIF_TAG_ORIENTATION ||
- tag == EXIF_TAG_PIXEL_X_DIMENSION ||
- tag == EXIF_TAG_PIXEL_Y_DIMENSION) {
-
- if (value == NULL) {
- thumb_err("value is NULL");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
- short exif_value = exif_get_short(entry->data, mByteOrder);
- *value = (int)exif_value;
- }
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-static int __media_thumb_safe_atoi(char *buffer, int *si)
-{
- char *end = NULL;
- errno = 0;
- thumb_retvm_if(buffer == NULL || si == NULL, MS_MEDIA_ERR_INTERNAL, "invalid parameter");
-
- const long sl = strtol(buffer, &end, 10);
-
- thumb_retvm_if(end == buffer, MS_MEDIA_ERR_INTERNAL, "not a decimal number");
- thumb_retvm_if('\0' != *end, MS_MEDIA_ERR_INTERNAL, "extra characters at end of input: %s", end);
- thumb_retvm_if((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno), MS_MEDIA_ERR_INTERNAL, "out of range of type long");
- thumb_retvm_if(sl > INT_MAX, MS_MEDIA_ERR_INTERNAL, "greater than INT_MAX");
- thumb_retvm_if(sl < INT_MIN, MS_MEDIA_ERR_INTERNAL, "less than INT_MIN");
-
- *si = (int)sl;
-
- return MS_MEDIA_ERR_NONE;
-}
-
-static int _media_thumb_get_data_from_exif(ExifData *ed,
- void **thumb_data,
- int *thumb_size,
- int *thumb_width,
- int *thumb_height,
- int *origin_width,
- int *origin_height)
-{
- ExifEntry *entry;
- ExifIfd ifd;
- ExifTag tag;
-
- ExifByteOrder byte_order = exif_data_get_byte_order(ed);
-
- ifd = EXIF_IFD_1;
- tag = EXIF_TAG_COMPRESSION;
-
- entry = exif_content_get_entry(ed->ifd[ifd], tag);
-
- if (entry) {
- /* Get the contents of the tag in human-readable form */
- ExifShort value = exif_get_short(entry->data, byte_order);
- //thumb_dbg("%s: %d", exif_tag_get_name_in_ifd(tag,ifd), value);
-
- if (value == 6) {
- thumb_dbg("There's jpeg thumb in this image");
- } else {
- thumb_dbg("There's NO jpeg thumb in this image");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
- } else {
- thumb_dbg("entry is NULL");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- /* copy the real thumbnail data from exif data */
- if (ed->data && ed->size) {
- /* NOTICE : ExifData->size type is unsigned int, But Internal IPC, and CAPI use int */
- if (ed->size > INT_MAX) {
- thumb_err("EXIF thumbnail size is over INT_MAX");
- return MS_MEDIA_ERR_THUMB_TOO_BIG;
- }
-
- *thumb_data = (char *)malloc(ed->size);
-
- if (*thumb_data == NULL) {
- thumb_dbg("malloc failed!");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- memcpy(*thumb_data, (void *)ed->data, ed->size);
- *thumb_size = ed->size;
- } else {
- thumb_dbg("data is NULL");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- /* Get width and height of thumbnail */
- tag = EXIF_TAG_IMAGE_WIDTH;
- entry = exif_content_get_entry(ed->ifd[ifd], tag);
-
- if (entry) {
- /* Get the contents of the tag in human-readable form */
- char width[10] = {0,};
- exif_entry_get_value(entry, width, 10);
- __media_thumb_safe_atoi(width, thumb_width);
- } else {
- thumb_warn("EXIF_TAG_IMAGE_WIDTH does not exist");
- *thumb_width = 0;
- }
-
- tag = EXIF_TAG_IMAGE_LENGTH;
- entry = exif_content_get_entry(ed->ifd[ifd], tag);
- if (entry) {
- /* Get the contents of the tag in human-readable form */
- char height[10] = {0, };
- exif_entry_get_value(entry, height, 10);
- __media_thumb_safe_atoi(height, thumb_height);
- } else {
- thumb_warn("EXIF_TAG_IMAGE_LENGTH does not exist");
- *thumb_height = 0;
- }
-
- thumb_dbg("thumb width : height [%d:%d]", *thumb_width, *thumb_height);
-
- /* Get width and height of original image from exif */
- ifd = EXIF_IFD_EXIF;
- tag = EXIF_TAG_PIXEL_X_DIMENSION;
- entry = exif_content_get_entry(ed->ifd[ifd], tag);
-
- if (entry) {
- char width[10] = {0,};
- exif_entry_get_value(entry, width, 10);
- __media_thumb_safe_atoi(width, origin_width);
- } else {
- thumb_warn("EXIF_TAG_PIXEL_X_DIMENSION does not exist");
- *origin_width = 0;
- }
-
- tag = EXIF_TAG_PIXEL_Y_DIMENSION;
- entry = exif_content_get_entry(ed->ifd[ifd], tag);
-
- if (entry) {
- char height[10] = {0, };
- exif_entry_get_value(entry, height, 10);
- __media_thumb_safe_atoi(height, origin_height);
- } else {
- thumb_warn("EXIF_TAG_PIXEL_Y_DIMENSION does not exist");
- *origin_height = 0;
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-static int __media_thumb_decode_jpeg(unsigned char *src, unsigned long long size, image_util_colorspace_e colorspace, unsigned char **dst, unsigned long *width, unsigned long *height, unsigned long long *dst_size)
-{
- int err = IMAGE_UTIL_ERROR_NONE;
- image_util_decode_h decoder = NULL;
-
- if (!dst || !width || !height || !dst_size) {
- thumb_err("Invalide parameter");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- err = image_util_decode_create(&decoder);
- if (err != IMAGE_UTIL_ERROR_NONE) {
- thumb_err("image_util_decode_create failed! (%d)", err);
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- err = image_util_decode_set_input_buffer(decoder, src, size);
- if (err != IMAGE_UTIL_ERROR_NONE) {
- thumb_err("image_util_decode_set_input_buffer failed! (%d)", err);
- image_util_decode_destroy(decoder);
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- err = image_util_decode_set_colorspace(decoder, colorspace);
- if (err != IMAGE_UTIL_ERROR_NONE) {
- thumb_err("image_util_decode_set_colorspace failed! (%d)", err);
- image_util_decode_destroy(decoder);
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- err = image_util_decode_set_output_buffer(decoder, dst);
- if (err != IMAGE_UTIL_ERROR_NONE) {
- thumb_err("image_util_decode_set_output_buffer failed! (%d)", err);
- image_util_decode_destroy(decoder);
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- err = image_util_decode_run(decoder, width, height, dst_size);
- if (err != IMAGE_UTIL_ERROR_NONE) {
- thumb_err("image_util_decode_run failed! (%d)", err);
- image_util_decode_destroy(decoder);
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- err = image_util_decode_destroy(decoder);
- if (err != IMAGE_UTIL_ERROR_NONE) {
- thumb_err("image_util_decode_destroy failed! (%d)", err);
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-
-int _media_thumb_get_thumb_from_exif(ExifData *ed,
- const char *file_full_path,
- const char *thumb_path,
- int orientation,
- int required_width,
- int required_height,
- media_thumb_info *thumb_info)
+int _media_thumb_general(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;
- int size = 0;
- int thumb_width = 0;
- int thumb_height = 0;
- unsigned long long thumb_size = 0;
- unsigned char *raw_image = NULL;
- int origin_width = 0;
- int origin_height = 0;
- void *thumb = NULL;
- bool is_rotated = (orientation == ROT_90 || orientation == ROT_180 || orientation == ROT_270) ? TRUE : FALSE;
-
- if (ed == NULL) {
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- err = _media_thumb_get_data_from_exif(ed,
- &thumb,
- &size,
- &thumb_width,
- &thumb_height,
- &origin_width,
- &origin_height);
-
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("There is no exif data");
- return err;
- }
-
- thumb_dbg("thumb width : height [%d:%d]", thumb_width, thumb_height);
- thumb_dbg("origin width : height [%d:%d]", origin_width, origin_height);
- thumb_info->origin_height = origin_height;
- thumb_info->origin_width = origin_width;
-
- if (thumb_width < required_width) {
- thumb_err("Thumb data in exif is too small");
- SAFE_FREE(thumb);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- if (is_rotated) {
- err = __media_thumb_decode_jpeg(thumb, size, IMAGE_UTIL_COLORSPACE_RGB888, &raw_image, (unsigned long *)&thumb_width, (unsigned long *)&thumb_height, &thumb_size);
- SAFE_FREE(thumb);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("__media_thumb_decode_jpeg failed : %d", err);
- return err;
- }
-
- int rot_type = IMAGE_UTIL_ROTATION_NONE;
- if (orientation == ROT_90) {
- rot_type = IMAGE_UTIL_ROTATION_90;
- } else if (orientation == ROT_180) {
- rot_type = IMAGE_UTIL_ROTATION_180;
- } else if (orientation == ROT_270) {
- rot_type = IMAGE_UTIL_ROTATION_270;
- }
- err = _media_thumb_rotate_thumb(raw_image, thumb_size, &thumb_width, &thumb_height, rot_type, IMAGE_UTIL_COLORSPACE_RGB888);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_rotate_thumb falied: %d", err);
- SAFE_FREE(thumb_info->data);
- SAFE_FREE(raw_image);
- return err;
- }
-
- thumb_info->data = raw_image;
- thumb_info->size = thumb_size;
- thumb_info->width = thumb_width;
- thumb_info->height = thumb_height;
+ mm_util_image_h img = NULL;
+ unsigned char *buf = NULL;
+ unsigned int width = 0;
+ unsigned int height = 0;
+ size_t size = 0;
+ mm_util_magick_format format = MM_UTIL_IMG_FMT_NUM;
+
+ if (thumb_path != NULL) {
+ err = mm_util_resize_P_P(origin_path, thumb_width, thumb_height, thumb_path);
} else {
- /*in this case, just write raw data in file */
- thumb_dbg_slog("Thumb is :%s", thumb_path);
-
- int nwrite;
- int fd = open(thumb_path, O_RDWR | O_CREAT | O_EXCL | O_SYNC, 0644);
- if (fd < 0) {
- if (errno == EEXIST) {
- thumb_err("thumb alread exist!");
- } else {
- thumb_err("open failed");
- SAFE_FREE(thumb);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
- } else {
- nwrite = write(fd, thumb, size);
- if (nwrite < 0) {
- thumb_err("write failed");
- close(fd);
-
- SAFE_FREE(thumb);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
- close(fd);
+ err = mm_util_resize_P_B(origin_path, thumb_width, thumb_height, MM_UTIL_IMG_FMT_BGRA8888, &img);
+ if (err != MM_UTIL_ERROR_NONE) {
+ thumb_err("mm_util_resize_P_B failed : %d", err);
+ return MS_MEDIA_ERR_INTERNAL;
}
- SAFE_FREE(thumb);
- thumb_info->data = NULL;
+ mm_util_get_image(img, &buf, &width, &height, &size, &format);
+ thumb_info->data = calloc(1, size);
+ memcpy(thumb_info->data, buf, size);
thumb_info->size = size;
- thumb_info->width = thumb_width;
- thumb_info->height = thumb_height;
- thumb_info->is_saved = TRUE;
- }
-
- return err;
-}
-
-int _media_thumb_get_wh_with_evas(const char *origin_path, int *width, int *height)
-{
- /* using evas to get w/h */
- Ecore_Evas *ee = ecore_evas_buffer_new(0, 0);
- if (!ee) {
- thumb_err("ecore_evas_buffer_new fails");
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- Evas *evas = ecore_evas_get(ee);
- if (!evas) {
- thumb_err("ecore_evas_get fails");
- ecore_evas_free(ee);
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- Evas_Object *image_object = evas_object_image_add(evas);
- if (!image_object) {
- thumb_err("evas_object_image_add fails");
- ecore_evas_free(ee);
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- evas_object_image_file_set(image_object, origin_path, NULL);
- evas_object_image_size_get(image_object, width, height);
-
- thumb_dbg("Width:%d, Height:%d", *width, *height);
-
- ecore_evas_free(ee);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_thumb_decode_with_evas(const char *origin_path,
- int thumb_width, int thumb_height,
- media_thumb_info *thumb_info, int need_scale, int orientation)
-{
- Ecore_Evas *resize_img_ee;
-
- resize_img_ee = ecore_evas_buffer_new(thumb_width, thumb_height);
- if (!resize_img_ee) {
- thumb_err("ecore_evas_buffer_new failed");
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- Evas *resize_img_e = ecore_evas_get(resize_img_ee);
- if (!resize_img_e) {
- thumb_err("ecore_evas_get failed");
- ecore_evas_free(resize_img_ee);
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- Evas_Object *source_img = evas_object_image_add(resize_img_e);
- if (!source_img) {
- thumb_err("evas_object_image_add failed");
- ecore_evas_free(resize_img_ee);
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- evas_object_image_file_set(source_img, origin_path, NULL);
-
- /* Get w/h of original image */
- int width = 0;
- int height = 0;
-
- evas_object_image_size_get(source_img, &width, &height);
- thumb_info->origin_width = width;
- thumb_info->origin_height = height;
- //thumb_dbg("origin width:%d, origin height:%d", width, height);
-
- /* This case for only JPEG format.. JPEG can be partially processed.. */
- if ((need_scale == 1) && (width * height > THUMB_MAX_ALLOWED_MEM_FOR_THUMB)) {
- thumb_warn("This is too large image. so this's scale is going to be down");
- evas_object_image_load_scale_down_set(source_img, 10);
- }
-
- if (orientation != TRANSPOSE)
- evas_object_image_load_orientation_set(source_img, 1);
-
- int rotated_orig_w = 0;
- int rotated_orig_h = 0;
-
- if (orientation == ROT_90 || orientation == ROT_270) {
- rotated_orig_w = height;
- rotated_orig_h = width;
- } else {
- rotated_orig_w = width;
- rotated_orig_h = height;
- }
- //thumb_dbg("rotated - origin width:%d, origin height:%d", rotated_orig_w, rotated_orig_h);
-
- int err = MS_MEDIA_ERR_NONE;
-
- err = _media_thumb_get_proper_thumb_size(rotated_orig_w, rotated_orig_h, &thumb_width, &thumb_height);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_get_proper_thumb_size failed: %d", err);
- ecore_evas_free(resize_img_ee);
- return err;
- }
-
- ecore_evas_resize(resize_img_ee, thumb_width, thumb_height);
-
- evas_object_image_load_size_set(source_img, thumb_width, thumb_height);
- evas_object_image_fill_set(source_img, 0, 0, thumb_width, thumb_height);
- evas_object_image_filled_set(source_img, 1);
-
- evas_object_resize(source_img, thumb_width, thumb_height);
- evas_object_show(source_img);
-
- /* Set alpha from original */
- thumb_info->alpha = evas_object_image_alpha_get(source_img);
- if (thumb_info->alpha) ecore_evas_alpha_set(resize_img_ee, EINA_TRUE);
-
- /* Create target buffer and copy origin resized img to it */
- Ecore_Evas *target_ee = ecore_evas_buffer_new(thumb_width, thumb_height);
- if (!target_ee) {
- thumb_err("ecore_evas_buffer_new failed");
- ecore_evas_free(resize_img_ee);
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- Evas *target_evas = ecore_evas_get(target_ee);
- if (!target_evas) {
- thumb_err("ecore_evas_get failed");
- ecore_evas_free(resize_img_ee);
- ecore_evas_free(target_ee);
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- Evas_Object *ret_image = evas_object_image_add(target_evas);
- evas_object_image_size_set(ret_image, thumb_width, thumb_height);
- evas_object_image_fill_set(ret_image, 0, 0, thumb_width, thumb_height);
- evas_object_image_filled_set(ret_image, EINA_TRUE);
-
- evas_object_image_data_set(ret_image, (int *)ecore_evas_buffer_pixels_get(resize_img_ee));
- evas_object_image_data_update_add(ret_image, 0, 0, thumb_width, thumb_height);
-
- unsigned int buf_size = 0;
- if (__media_thumb_get_buffer_size(IMAGE_UTIL_COLORSPACE_BGRA8888, thumb_width, thumb_height, &buf_size) < 0) {
- thumb_err("__media_thumb_get_buffer_size failed");
-
- ecore_evas_free(resize_img_ee);
- ecore_evas_free(target_ee);
-
- return MS_MEDIA_ERR_INTERNAL;
- }
- //thumb_dbg("__media_thumb_get_buffer_size : %d", buf_size);
-
- thumb_info->size = buf_size;
- thumb_info->width = thumb_width;
- thumb_info->height = thumb_height;
- thumb_info->data = malloc(buf_size);
- if (thumb_info->data == NULL) {
- thumb_err("Failed to allocate memory");
- ecore_evas_free(resize_img_ee);
- ecore_evas_free(target_ee);
-
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
-
- void *image_data = evas_object_image_data_get(ret_image, 1);
- if (image_data != NULL) {
- memcpy(thumb_info->data, image_data, buf_size);
- } else {
- thumb_err("image_data is NULL. evas_object_image_data_get failed");
+ thumb_info->width = width;
+ thumb_info->height = height;
+ SAFE_FREE(buf);
+ mm_util_destroy_handle(img);
}
- ecore_evas_free(target_ee);
- ecore_evas_free(resize_img_ee);
-
return err;
}
-int _media_thumb_convert_data(media_thumb_info *thumb_info, int thumb_width, int thumb_height)
-{
- int err = MS_MEDIA_ERR_NONE;
- unsigned int buf_size = 0;
- unsigned char *src_data = thumb_info->data;
- unsigned char *dst_data = NULL;
- int i = 0, j;
-
- if (__media_thumb_get_buffer_size(IMAGE_UTIL_COLORSPACE_BGRA8888, thumb_width, thumb_height, &buf_size) < 0) {
- thumb_err("__media_thumb_get_buffer_size failed");
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- thumb_dbg("__media_thumb_get_buffer_size : %d", buf_size);
-
- dst_data = (unsigned char *)malloc(buf_size);
- if (dst_data == NULL) {
- thumb_err("Failed to allocate memory");
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
-
- for (j = 0; j < thumb_width * 3 * thumb_height; j += 3) {
- dst_data[i++] = (src_data[j + 2]);
- dst_data[i++] = (src_data[j + 1]);
- dst_data[i++] = (src_data[j]);
- dst_data[i++] = 0x0;
- }
-
- SAFE_FREE(thumb_info->data);
- thumb_info->data = dst_data;
- thumb_info->size = buf_size;
-
- thumb_dbg("_media_thumb_convert_data success");
-
- return err;
-}
-
-int _media_thumb_agif(const char *origin_path, int thumb_width, int thumb_height, media_thumb_info *thumb_info)
-{
- int err = MS_MEDIA_ERR_NONE;
- unsigned int *thumb = NULL;
- unsigned char *dst_image = NULL;
- unsigned int dst_size = 0;
- unsigned int thumb_size = 0;
-
- thumb = ImgGetFirstFrameAGIFAtSize(origin_path, thumb_info->origin_width, thumb_info->origin_height);
- if (!thumb) {
- thumb_err("Frame data is NULL!!");
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- err = __media_thumb_get_buffer_size(IMAGE_UTIL_COLORSPACE_RGB888, thumb_info->origin_width, thumb_info->origin_height, &thumb_size);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("__media_thumb_get_buffer_size failed: %d", err);
- SAFE_FREE(thumb);
- return err;
- }
-
- err = _media_thumb_get_proper_thumb_size(thumb_info->origin_width, thumb_info->origin_height, &thumb_width, &thumb_height);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_get_proper_thumb_size failed: %d", err);
- SAFE_FREE(thumb);
- return err;
- }
-
- err = _media_thumb_rgb_to_argb((unsigned char *) thumb, thumb_size, &dst_image, &dst_size, thumb_info->origin_width, thumb_info->origin_height);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_convert_data falied: %d", err);
- SAFE_FREE(thumb);
- return err;
- }
-
- err = _media_thumb_resize_with_evas(dst_image, thumb_width, thumb_height, thumb_info);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_resize_data failed: %d", err);
- SAFE_FREE(thumb_info->data);
- SAFE_FREE(thumb);
- return err;
- }
-
- SAFE_FREE(thumb);
-
- return err;
-}
-
-int _media_thumb_general(const char *origin_path, int thumb_width, int thumb_height, media_thumb_info *thumb_info)
-{
- int err = MS_MEDIA_ERR_NONE;
-
- err = _media_thumb_decode_with_evas(origin_path, thumb_width, thumb_height, thumb_info, 1, NORMAL);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("decode_with_evas failed : %d", err);
- return err;
- }
-
- return err;
-}
-
-int _media_thumb_jpeg(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;
- int thumb_done = 0;
- int orientation = NORMAL;
- ExifData *ed = NULL;
-
- if (!thumb_info->is_raw) {
- /* Load an ExifData object from an EXIF file */
- ed = exif_data_new_from_file(origin_path);
-
- if (ed) {
- /* First, Get orientation from exif */
- err = _media_thumb_get_exif_info(ed, &orientation, EXIF_IFD_0, EXIF_TAG_ORIENTATION);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_warn("_media_thumb_get_exif_info failed");
- }
-
- /* Second, Get thumb from exif */
- err = _media_thumb_get_thumb_from_exif(ed, origin_path, thumb_path, orientation, thumb_width, thumb_height, thumb_info);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_dbg("_media_thumb_get_thumb_from_exif failed");
- } else {
- thumb_done = 1;
- thumb_dbg("_media_thumb_get_thumb_from_exif succeed");
-
- /* The case that original image's size is not in exif header. Use evas to get w/h */
- if (thumb_info->origin_width == 0 || thumb_info->origin_height == 0) {
- thumb_warn("original image's size is not in exif header. Use evas to get w/h");
- err = _media_thumb_get_wh_with_evas(origin_path, &(thumb_info->origin_width), &(thumb_info->origin_height));
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("Couldn't get w/h using evas : %s", origin_path);
- } else {
- thumb_dbg("origin w : %d, origin h : %d", thumb_info->origin_width, thumb_info->origin_height);
- }
- }
-
- if (thumb_info->is_saved == FALSE) {
- err = _media_thumb_convert_data(thumb_info, thumb_info->width, thumb_info->height);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_convert_data failed : %d", err);
- exif_data_unref(ed);
- return err;
- }
- }
- }
-
- exif_data_unref(ed);
- }
- } else {
- ed = exif_data_new_from_file(origin_path);
- if (ed) {
- err = _media_thumb_get_exif_info(ed, &orientation, EXIF_IFD_0, EXIF_TAG_ORIENTATION);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_warn("_media_thumb_get_exif_info failed");
- }
- exif_data_unref(ed);
- }
- }
-
- if (!thumb_done) {
- err = _media_thumb_decode_with_evas(origin_path, thumb_width, thumb_height, thumb_info, 1, orientation);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("decode_with_evas failed : %d", err);
- return err;
- }
- }
-
- return err;
-}
-
-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_image(const char *origin_path, char *thumb_path, int thumb_width, int thumb_height, media_thumb_info *thumb_info)
{
int err = MS_MEDIA_ERR_NONE;
ImgCodecType image_type = 0;
@@ -998,20 +110,27 @@ int _media_thumb_image(const char *origin_path, const char *thumb_path, int thum
thumb_warn("Getting image info is failed err: %d", err);
}
- thumb_info->origin_width = origin_w;
- thumb_info->origin_height = origin_h;
-
if ((image_type != IMG_CODEC_JPEG) && (origin_w * origin_h > THUMB_MAX_ALLOWED_MEM_FOR_THUMB)) {
thumb_warn("This original image is too big");
return MS_MEDIA_ERR_THUMB_TOO_BIG;
}
- if (image_type == IMG_CODEC_AGIF) {
- err = _media_thumb_agif(origin_path, thumb_width, thumb_height, thumb_info);
- } else if (image_type == IMG_CODEC_JPEG) {
- err = _media_thumb_jpeg(origin_path, thumb_path, thumb_width, thumb_height, thumb_info);
- } else if (image_type == IMG_CODEC_PNG || image_type == IMG_CODEC_GIF || image_type == IMG_CODEC_BMP || image_type == IMG_CODEC_WBMP) {
- err = _media_thumb_general(origin_path, thumb_width, thumb_height, thumb_info);
+ _media_thumb_get_proper_thumb_size(origin_w, origin_h, &thumb_width, &thumb_height);
+
+ if (image_type == IMG_CODEC_PNG) {
+ if (thumb_path != NULL) {
+ char file_ext[10];
+ err = _media_thumb_get_file_ext(origin_path, file_ext, sizeof(file_ext));
+ if (strncasecmp(file_ext, "png", 3) == 0) {
+ int len = strlen(thumb_path);
+ thumb_path[len - 3] = 'p';
+ thumb_path[len - 2] = 'n';
+ thumb_path[len - 1] = 'g';
+ }
+ }
+ err = _media_thumb_general(origin_path, thumb_path, thumb_width, thumb_height, thumb_info);
+ } else if (image_type == IMG_CODEC_JPEG || image_type == IMG_CODEC_AGIF || image_type == IMG_CODEC_GIF || image_type == IMG_CODEC_BMP || image_type == IMG_CODEC_WBMP) {
+ err = _media_thumb_general(origin_path, thumb_path, thumb_width, thumb_height, thumb_info);
} else {
thumb_warn("Unsupported image type");
return MS_MEDIA_ERR_THUMB_UNSUPPORTED;
@@ -1128,8 +247,6 @@ int _media_thumb_video(const char *origin_path, const char *thumb_path, int thum
goto ERROR;
}
- thumb_info->is_saved = true;
-
err = _media_thumb_get_proper_thumb_size(width, height, &thumb_width, &thumb_height);
if (thumb_width <= 0 || thumb_height <= 0) {
thumb_err("Failed to get thumb size");
@@ -1218,7 +335,6 @@ ERROR:
int _media_thumb_get_hash_name(const char *file_full_path, char *thumb_hash_path, size_t max_thumb_path, uid_t uid)
{
char *hash_name = NULL;
- /*char *thumb_dir = NULL;*/
char file_ext[255] = { 0 };
char *get_path = NULL;
int ret_len = 0;
@@ -1254,53 +370,6 @@ int _media_thumb_get_hash_name(const char *file_full_path, char *thumb_hash_path
thumb_err("invalid hash path ret_len[%d]", ret_len);
return MS_MEDIA_ERR_INTERNAL;
}
- //thumb_dbg("thumb hash : %s", thumb_hash_path);
return MS_MEDIA_ERR_NONE;
}
-
-
-int _media_thumb_save_to_file_with_evas(unsigned char *data, int w, int h, int alpha, char *thumb_path)
-{
- Ecore_Evas *ee = ecore_evas_buffer_new(w, h);
- if (ee == NULL) {
- thumb_err("ecore_evas_buffer_new failed");
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- Evas *evas = ecore_evas_get(ee);
- if (evas == NULL) {
- thumb_err("ecore_evas_get failed");
- ecore_evas_free(ee);
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- Evas_Object *img = NULL;
- img = evas_object_image_add(evas);
-
- if (img == NULL) {
- thumb_err("evas_object_image_add failed");
- ecore_evas_free(ee);
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- evas_object_image_colorspace_set(img, EVAS_COLORSPACE_ARGB8888);
- evas_object_image_size_set(img, w, h);
- evas_object_image_fill_set(img, 0, 0, w, h);
-
- if (alpha) evas_object_image_alpha_set(img, 1);
-
- evas_object_image_data_set(img, data);
- evas_object_image_data_update_add(img, 0, 0, w, h);
-
- if (evas_object_image_save(img, thumb_path, NULL, "quality=90 compress=1")) {
- thumb_dbg("evas_object_image_save success");
- ecore_evas_free(ee);
-
- return MS_MEDIA_ERR_NONE;
- } else {
- thumb_err("evas_object_image_save failed");
- ecore_evas_free(ee);
- return MS_MEDIA_ERR_INTERNAL;
- }
-}
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 51c570d..e762c17 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -1,7 +1,7 @@
SET(TEST-THUMB "test-thumb.c")
INCLUDE(FindPkgConfig)
- pkg_check_modules(pkgs REQUIRED glib-2.0 gthread-2.0 dlog mm-fileinfo aul libexif ecore-evas evas libmedia-utils libtzplatform-config)
+ pkg_check_modules(pkgs REQUIRED glib-2.0 gthread-2.0 dlog mm-fileinfo aul libmedia-utils libtzplatform-config)
FOREACH(flag ${pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")