summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinje Ahn <minje.ahn@samsung.com>2015-08-03 01:26:20 (GMT)
committerMinje Ahn <minje.ahn@samsung.com>2015-08-03 01:26:20 (GMT)
commit41f405edc8f31d877615c580ed6eb308d7eaebec (patch)
treeab4fad2f453bc02105c1f8ac09dadfb437de932e
parent318ec49c458b8f7acef0c192d046074250ebe231 (diff)
downloadlibmedia-thumbnail-41f405edc8f31d877615c580ed6eb308d7eaebec.zip
libmedia-thumbnail-41f405edc8f31d877615c580ed6eb308d7eaebec.tar.gz
libmedia-thumbnail-41f405edc8f31d877615c580ed6eb308d7eaebec.tar.bz2
- Some images can not create thumbnail using gdk-pixbuf. Change-Id: I67e08edd27547875de2045eae68e114dc1c0a3c2 Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
-rw-r--r--CMakeLists.txt2
-rw-r--r--packaging/libmedia-thumbnail.spec5
-rwxr-xr-xserver/thumb-server-internal.c39
-rwxr-xr-xsrc/include/media-thumb-internal.h10
-rwxr-xr-xsrc/include/util/media-thumb-util.h7
-rwxr-xr-xsrc/ipc/media-thumb-ipc.c41
-rwxr-xr-xsrc/media-thumb-internal.c420
-rwxr-xr-xsrc/util/media-thumb-util.c178
8 files changed, 398 insertions, 304 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 975f1d7..3563418 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -42,7 +42,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 mm-fileinfo aul libexif mmutil-imgp mmutil-jpeg heynoti libmedia-utils vconf libtzplatform-config gdk-pixbuf-2.0)
+pkg_check_modules(pkgs REQUIRED glib-2.0 gthread-2.0 dlog mm-fileinfo aul libexif ecore-evas evas mmutil-imgp mmutil-jpeg heynoti libmedia-utils vconf libtzplatform-config)
FOREACH(flag ${pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
diff --git a/packaging/libmedia-thumbnail.spec b/packaging/libmedia-thumbnail.spec
index b1bd9bf..f70b5e8 100644
--- a/packaging/libmedia-thumbnail.spec
+++ b/packaging/libmedia-thumbnail.spec
@@ -1,5 +1,5 @@
Name: libmedia-thumbnail
-Version: 0.1.80
+Version: 0.1.81
Release: 0
License: Apache-2.0
Summary: Media thumbnail service Library
@@ -17,11 +17,12 @@ BuildRequires: pkgconfig(mmutil-imgp)
BuildRequires: pkgconfig(mmutil-jpeg)
BuildRequires: pkgconfig(heynoti)
BuildRequires: pkgconfig(libexif)
+BuildRequires: pkgconfig(evas)
+BuildRequires: pkgconfig(ecore)
BuildRequires: pkgconfig(aul)
BuildRequires: pkgconfig(vconf)
BuildRequires: pkgconfig(libmedia-utils)
BuildRequires: pkgconfig(libtzplatform-config)
-BuildRequires: pkgconfig(gdk-pixbuf-2.0)
%description
Description: Media thumbnail service library for multimedia applications.
diff --git a/server/thumb-server-internal.c b/server/thumb-server-internal.c
index 3fd4bb5..de7f8fd 100755
--- a/server/thumb-server-internal.c
+++ b/server/thumb-server-internal.c
@@ -28,6 +28,7 @@
#include <dirent.h>
#include <stdio.h>
#include <string.h>
+#include <Ecore_Evas.h>
#include <vconf.h>
#include <grp.h>
#include <pwd.h>
@@ -52,6 +53,8 @@ void _thumb_daemon_stop_job();
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);
@@ -67,6 +70,8 @@ void _thumb_daemon_finish_jobs(void)
thumb_dbg("sqlite3 handle is alive. So disconnect to sqlite3");
}
+ /* Shutdown ecore-evas */
+ ecore_evas_shutdown();
g_main_loop_quit(g_thumb_server_mainloop);
return;
@@ -237,7 +242,7 @@ int _thumb_daemon_all_extract(uid_t uid)
strncpy(path, (const char *)sqlite3_column_text(sqlite_stmt, 0), sizeof(path));
path[sizeof(path) - 1] = '\0';
- thumb_dbg("Path : %s", path);
+ thumb_dbg_slog("Path : %s", path);
if (g_idx == 0) {
arr_path = (char**)malloc(sizeof(char*));
@@ -367,10 +372,9 @@ gboolean _thumb_server_read_socket(GIOChannel *src,
res_msg.request_id = recv_msg.request_id;
strncpy(res_msg.org_path, recv_msg.org_path, recv_msg.origin_path_size);
res_msg.origin_path_size = recv_msg.origin_path_size;
- res_msg.thumb_data = (unsigned char *)"\0";
if(res_msg.msg_type != THUMB_RESPONSE_RAW_DATA) {
- res_msg.dest_path_size = strlen(res_msg.dst_path) + 1;
- res_msg.thumb_size = 1;
+ res_msg.dest_path_size = strlen(res_msg.dst_path)+1;
+ res_msg.thumb_size = 0;
} else {
res_msg.dest_path_size = 1;
res_msg.dst_path[0] = '\0';
@@ -604,7 +608,7 @@ int _thumbnail_get_data(const char *origin_path,
if (size) *size = thumb_info.size;
if (width) *width = thumb_info.width;
if (height) *height = thumb_info.height;
- *data = thumb_info.gdkdata;
+ *data = thumb_info.data;
if (origin_width) *origin_width = thumb_info.origin_width;
if (origin_height) *origin_height = thumb_info.origin_height;
if (alpha) *alpha = thumb_info.alpha;
@@ -678,7 +682,7 @@ int _thumbnail_get_raw_data(const char *origin_path,
int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
{
int err = MS_MEDIA_ERR_NONE;
- GdkPixbuf *gdkdata = NULL;
+ unsigned char *data = NULL;
int thumb_size = 0;
int thumb_w = 0;
int thumb_h = 0;
@@ -698,9 +702,7 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
media_thumb_type thumb_type = req_msg->thumb_type;
const char *origin_path = req_msg->org_path;
- // Currently, The color space that is supported by the gdk-pixbuf is only RGB.
- media_thumb_format thumb_format = MEDIA_THUMB_RGB888;
-
+ media_thumb_format thumb_format = MEDIA_THUMB_BGRA;
thumb_path = res_msg->dst_path;
thumb_path[0] = '\0';
max_length = sizeof(res_msg->dst_path);
@@ -762,13 +764,11 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
_media_thumb_remove_file(thumb_path);
}
- err = _thumbnail_get_data(origin_path, thumb_type, thumb_format, &gdkdata, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h, &alpha, uid);
+ err = _thumbnail_get_data(origin_path, thumb_type, thumb_format, &data, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h, &alpha, uid);
if (err != MS_MEDIA_ERR_NONE) {
char *default_path = _media_thumb_get_default_path(uid);
- thumb_err("_thumbnail_get_data failed - %d\n", err);
- if ( gdkdata != NULL ){
- g_object_unref(gdkdata);
- }
+ thumb_err("_thumbnail_get_data failed - %d", err);
+ SAFE_FREE(data);
if(default_path) {
strncpy(thumb_path, default_path, max_length);
free(default_path);
@@ -801,13 +801,11 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
thumb_dbg("Thumb path is changed : %s", thumb_path);
}
- err = _media_thumb_save_to_file_with_gdk(gdkdata, thumb_w, thumb_h, alpha, thumb_path);
+ err = _media_thumb_save_to_file_with_evas(data, thumb_w, thumb_h, alpha, thumb_path);
if (err != MS_MEDIA_ERR_NONE) {
char *default_path = _media_thumb_get_default_path(uid);
- thumb_err("save_to_file_with_gdk failed - %d", err);
- if ( gdkdata != NULL ){
- g_object_unref(gdkdata);
- }
+ thumb_err("save_to_file_with_evas failed - %d", err);
+ SAFE_FREE(data);
if (msg_type == THUMB_REQUEST_DB_INSERT || msg_type == THUMB_REQUEST_ALL_MEDIA) {
if(default_path) {
@@ -836,7 +834,7 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
}
/* End of fsync */
- g_object_unref(gdkdata);
+ SAFE_FREE(data);
/* DB update if needed */
if (need_update_db == 1) {
@@ -894,6 +892,7 @@ _media_thumb_process_raw(thumbMsg *req_msg, thumbMsg *res_msg, thumbRawAddMsg *r
res_msg->thumb_size = thumb_size + sizeof(thumbRawAddMsg) - sizeof(unsigned char*);
//thumb_dbg("Size : %d, W:%d, H:%d", thumb_size, thumb_w, thumb_h);
+ SAFE_FREE(data);
return MS_MEDIA_ERR_NONE;
}
diff --git a/src/include/media-thumb-internal.h b/src/include/media-thumb-internal.h
index 0ab9eb7..ad50b04 100755
--- a/src/include/media-thumb-internal.h
+++ b/src/include/media-thumb-internal.h
@@ -25,7 +25,6 @@
#include "media-thumb-util.h"
#include "media-thumb-types.h"
#include "media-thumb-debug.h"
-#include <gdk-pixbuf/gdk-pixbuf.h>
#ifndef _MEDIA_THUMB_INTERNAL_H_
#define _MEDIA_THUMB_INTERNAL_H_
@@ -47,7 +46,6 @@ typedef struct {
int origin_height;
gboolean alpha;
unsigned char *data;
- GdkPixbuf *gdkdata;
} media_thumb_info;
enum Exif_Orientation {
@@ -87,4 +85,12 @@ int _media_thumb_video(const char *origin_path,
media_thumb_info *thumb_info,
uid_t uid);
+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/include/util/media-thumb-util.h b/src/include/util/media-thumb-util.h
index bee3b44..3bb71df 100755
--- a/src/include/util/media-thumb-util.h
+++ b/src/include/util/media-thumb-util.h
@@ -23,7 +23,6 @@
#include "media-thumb-debug.h"
#include "media-util.h"
#include <tzplatform_config.h>
-#include <gdk-pixbuf/gdk-pixbuf.h>
#ifndef _MEDIA_THUMB_UTIL_H_
#define _MEDIA_THUMB_UTIL_H_
@@ -62,12 +61,6 @@ char* _media_thumb_generate_hash_name(const char *file);
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_gdk(GdkPixbuf *data,
- int w,
- int h,
- gboolean alpha,
- char *thumb_path);
-
int _media_thumb_get_width(media_thumb_type thumb_type);
int _media_thumb_get_height(media_thumb_type thumb_type);
diff --git a/src/ipc/media-thumb-ipc.c b/src/ipc/media-thumb-ipc.c
index e98d629..7a94900 100755
--- a/src/ipc/media-thumb-ipc.c
+++ b/src/ipc/media-thumb-ipc.c
@@ -211,7 +211,7 @@ _media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg)
SAFE_FREE(buf);
- remain_size = msg->origin_path_size + msg->dest_path_size + msg->thumb_size + 2;
+ remain_size = msg->origin_path_size + msg->dest_path_size + msg->thumb_size;
buf = malloc(remain_size * sizeof(unsigned char));
memset(buf, 0, remain_size * sizeof(unsigned char));
@@ -231,11 +231,12 @@ _media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg)
}
strncpy(msg->org_path, (char *)buf, msg->origin_path_size);
- strncpy(msg->dst_path, (char *)buf + msg->origin_path_size + 1, msg->dest_path_size);
+ strncpy(msg->dst_path, (char *)buf + msg->origin_path_size, msg->dest_path_size);
+
SAFE_FREE(msg->thumb_data);
msg->thumb_data = malloc(msg->thumb_size);
memset(msg->thumb_data, 0, msg->thumb_size);
- memcpy(msg->thumb_data, buf + msg->origin_path_size + msg->dest_path_size + 2, msg->thumb_size);
+ memcpy(msg->thumb_data, buf + msg->origin_path_size + msg->dest_path_size, msg->thumb_size);
SAFE_FREE(buf);
SAFE_FREE(block_buf);
@@ -296,8 +297,8 @@ _media_thumb_set_buffer(thumbMsg *req_msg, unsigned char **buf, int *buf_size)
int header_size = 0;
header_size = sizeof(thumbMsg) -(MAX_FILEPATH_LEN * 2) - sizeof(unsigned char *);
- org_path_len = req_msg->origin_path_size + 1;
- dst_path_len = req_msg->dest_path_size + 1;
+ org_path_len = req_msg->origin_path_size;
+ dst_path_len = req_msg->dest_path_size;
thumb_data_len = req_msg->thumb_size;
//thumb_dbg("Basic Size : %d, org_path : %s[%d], dst_path : %s[%d], thumb_data_len : %d", header_size, req_msg->org_path, org_path_len, req_msg->dst_path, dst_path_len, thumb_data_len);
@@ -312,7 +313,8 @@ _media_thumb_set_buffer(thumbMsg *req_msg, unsigned char **buf, int *buf_size)
memcpy(*buf, req_msg, header_size);
memcpy((*buf)+header_size, req_msg->org_path, org_path_len);
memcpy((*buf)+header_size + org_path_len, req_msg->dst_path, dst_path_len);
- memcpy((*buf)+header_size + org_path_len + dst_path_len, req_msg->thumb_data, thumb_data_len);
+ if(thumb_data_len > 0)
+ memcpy((*buf)+header_size + org_path_len + dst_path_len, req_msg->thumb_data, thumb_data_len);
*buf_size = size;
@@ -328,20 +330,17 @@ _media_thumb_set_buffer_for_response(thumbMsg *req_msg, unsigned char **buf, int
int org_path_len = 0;
int dst_path_len = 0;
- int thumb_data_len = 0;
int size = 0;
int header_size = 0;
header_size = sizeof(thumbMsg) -(MAX_FILEPATH_LEN * 2) - sizeof(unsigned char *);
- org_path_len = req_msg->origin_path_size + 1;
- dst_path_len = req_msg->dest_path_size + 1;
- thumb_data_len = 1;
+ org_path_len = req_msg->origin_path_size;
+ dst_path_len = req_msg->dest_path_size;
- thumb_dbg("Basic Size : %d, org_path : %s[%d], dst_path : %s[%d], thumb_data_len : %d", header_size, req_msg->org_path, org_path_len, req_msg->dst_path, dst_path_len, thumb_data_len);
+ thumb_dbg("Basic Size : %d, org_path : %s[%d], dst_path : %s[%d]", header_size, req_msg->org_path, org_path_len, req_msg->dst_path, dst_path_len);
- size = header_size + org_path_len + dst_path_len + thumb_data_len;
+ size = header_size + org_path_len + dst_path_len;
*buf = malloc(size);
-
if (*buf == NULL) {
*buf_size = 0;
return 0;
@@ -349,7 +348,6 @@ _media_thumb_set_buffer_for_response(thumbMsg *req_msg, unsigned char **buf, int
memcpy(*buf, req_msg, header_size);
memcpy((*buf)+header_size, req_msg->org_path, org_path_len);
memcpy((*buf)+header_size + org_path_len, req_msg->dst_path, dst_path_len);
- memcpy((*buf)+header_size + org_path_len + dst_path_len, req_msg->thumb_data, thumb_data_len);
*buf_size = size;
@@ -431,11 +429,9 @@ _media_thumb_request(int msg_type, media_thumb_type thumb_type, const char *orig
req_msg.dst_path[strlen(req_msg.dst_path)] = '\0';
}
- req_msg.thumb_data = (unsigned char *) "\0";
-
req_msg.origin_path_size = strlen(req_msg.org_path) + 1;
req_msg.dest_path_size = strlen(req_msg.dst_path) + 1;
- req_msg.thumb_size = 1;
+ req_msg.thumb_size = 0;
if (req_msg.origin_path_size > MAX_PATH_SIZE || req_msg.dest_path_size > MAX_PATH_SIZE) {
thumb_err("path's length exceeds %d", MAX_PATH_SIZE);
@@ -650,11 +646,9 @@ int _media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const
strncpy(req_msg.org_path, origin_path, sizeof(req_msg.org_path));
req_msg.org_path[strlen(req_msg.org_path)] = '\0';
req_msg.dst_path[0] = '\0';
- req_msg.thumb_data = (unsigned char *)"\0";
-
- req_msg.origin_path_size = strlen(req_msg.org_path);
+ req_msg.origin_path_size = strlen(req_msg.org_path) + 1;
req_msg.dest_path_size = 1;
- req_msg.thumb_size = 1;
+ req_msg.thumb_size = 0;
if (req_msg.origin_path_size > MAX_PATH_SIZE || req_msg.dest_path_size > MAX_PATH_SIZE) {
thumb_err("path's length exceeds %d", MAX_PATH_SIZE);
@@ -768,11 +762,10 @@ int _media_thumb_request_raw_data_async(int msg_type, int request_id, const char
strncpy(req_msg.org_path, origin_path, sizeof(req_msg.org_path));
req_msg.org_path[strlen(req_msg.org_path)] = '\0';
req_msg.dst_path[0] = '\0';
- req_msg.thumb_data = (unsigned char *)"\0";
- req_msg.origin_path_size = strlen(req_msg.org_path);
+ req_msg.origin_path_size = strlen(req_msg.org_path) + 1;
req_msg.dest_path_size = 1;
- req_msg.thumb_size = 1;
+ req_msg.thumb_size = 0;
if (req_msg.origin_path_size > MAX_PATH_SIZE) {
thumb_err("path's length exceeds %d", MAX_PATH_SIZE);
diff --git a/src/media-thumb-internal.c b/src/media-thumb-internal.c
index a8c7fd7..5ed752d 100755
--- a/src/media-thumb-internal.c
+++ b/src/media-thumb-internal.c
@@ -41,10 +41,16 @@
#include <mm_error.h>
#include <mm_util_imgp.h>
#include <mm_util_jpeg.h>
+#include <Evas.h>
+#include <Ecore_Evas.h>
#include <libexif/exif-data.h>
-#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <sys/stat.h>
+#include <grp.h>
+#include <pwd.h>
+#include <sys/smack.h>
-#define MEDA_THUMB_ROUND_UP_4(num) (((num)+3)&~3)
+#define GLOBAL_USER 0 //#define tzplatform_getenv(TZ_GLOBAL) //TODO
+#define MEDIA_THUMB_ROUND_UP_8(num) (((num)+7)&~7)
int _media_thumb_get_proper_thumb_size(media_thumb_type thumb_type,
int orig_w, int orig_h,
@@ -82,8 +88,8 @@ int _media_thumb_get_proper_thumb_size(media_thumb_type thumb_type,
*thumb_w = *thumb_h * ratio;
}
- /* The width of RGB888 raw data has to be rounded by 4 */
- *thumb_w = MEDA_THUMB_ROUND_UP_4(*thumb_w);
+ /** 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);
@@ -117,7 +123,6 @@ int _media_thumb_get_exif_info(ExifData *ed, char *buf, int max_size, int *value
ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
short exif_value = exif_get_short(entry->data, mByteOrder);
- thumb_dbg("%s : %d", exif_tag_get_name_in_ifd(tag,ifd), exif_value);
*value = (int)exif_value;
} else {
/* Get the contents of the tag in human-readable form */
@@ -127,10 +132,6 @@ int _media_thumb_get_exif_info(ExifData *ed, char *buf, int max_size, int *value
}
exif_entry_get_value(entry, buf, max_size);
buf[strlen(buf)] = '\0';
-
- if (*buf) {
- thumb_dbg("%s: %s\n", exif_tag_get_name_in_ifd(tag, ifd), buf);
- }
}
}
@@ -461,49 +462,83 @@ int _media_thumb_resize_data(unsigned char *src_data,
return MS_MEDIA_ERR_NONE;
}
-int _media_thumb_get_wh_with_gdk(const char *origin_path, int *width, int *height)
+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;
+ }
- GdkPixbuf *pixbuf = NULL;
- GError *error = NULL;
+ Evas *evas = ecore_evas_get(ee);
+ if (!evas) {
+ thumb_err("ecore_evas_get fails");
+ ecore_evas_free(ee);
+ return MS_MEDIA_ERR_INTERNAL;
+ }
- pixbuf = gdk_pixbuf_new_from_file(origin_path, &error);
- if (error) {
- thumb_err ("Error loading image file %s",origin_path);
- g_error_free (error);
+ 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;
}
- /* Get w/h of original image */
- *width = gdk_pixbuf_get_width(pixbuf);
- *height = gdk_pixbuf_get_height(pixbuf);
+ 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_gdk(const char *origin_path,
+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)
{
- GdkPixbuf *pixbuf = NULL;
- GError *error = NULL;
+ 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;
+ }
- pixbuf = gdk_pixbuf_new_from_file(origin_path, &error);
- if (error) {
- thumb_err ("Error loading image file %s",origin_path);
- g_error_free (error);
+ 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 = gdk_pixbuf_get_width(pixbuf);
- int height = gdk_pixbuf_get_height(pixbuf);
+ 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);
+ 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);
+ }
- pixbuf = gdk_pixbuf_apply_embedded_orientation(pixbuf);
+ if (orientation != TRANSPOSE)
+ evas_object_image_load_orientation_set(source_img, 1);
int rotated_orig_w = 0;
int rotated_orig_h = 0;
@@ -515,6 +550,7 @@ int _media_thumb_decode_with_gdk(const char *origin_path,
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;
media_thumb_type thumb_type;
@@ -530,31 +566,81 @@ int _media_thumb_decode_with_gdk(const char *origin_path,
&thumb_width, &thumb_height);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_get_proper_thumb_size failed: %d", err);
- g_object_unref(pixbuf);
+ ecore_evas_free(resize_img_ee);
return err;
}
- pixbuf = gdk_pixbuf_scale_simple(pixbuf, thumb_width, thumb_height, GDK_INTERP_NEAREST);
+ ecore_evas_resize(resize_img_ee, thumb_width, thumb_height);
- unsigned int buf_size = 0;
+ 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);
- if (mm_util_get_image_size(MM_UTIL_IMG_FMT_BGRA8888, thumb_width,
- thumb_height, &buf_size) < 0) {
- thumb_err("Failed to get buffer size");
+ 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);
- g_object_unref(pixbuf);
+ 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 (mm_util_get_image_size(MM_UTIL_IMG_FMT_BGRA8888, thumb_width, thumb_height, &buf_size) < 0) {
+ thumb_err("mm_util_get_image_size failed");
+
+ ecore_evas_free(resize_img_ee);
+ ecore_evas_free(target_ee);
return MS_MEDIA_ERR_INTERNAL;
}
+ //thumb_dbg("mm_util_get_image_size : %d", buf_size);
thumb_info->size = buf_size;
- thumb_info->alpha = gdk_pixbuf_get_has_alpha(pixbuf);
thumb_info->width = thumb_width;
thumb_info->height = thumb_height;
- thumb_info->gdkdata = gdk_pixbuf_copy(pixbuf);
+ 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);
- g_object_unref(pixbuf);
- return MS_MEDIA_ERR_NONE;
+ 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");
+ }
+
+ ecore_evas_free(target_ee);
+ ecore_evas_free(resize_img_ee);
+
+ return err;
}
mm_util_img_format _media_thumb_get_format(media_thumb_format src_format)
@@ -583,7 +669,7 @@ int _media_thumb_convert_data(media_thumb_info *thumb_info,
thumb_dbg("src format:%d, dst format:%d", src_format, dst_format);
if (mm_util_get_image_size(dst_format, thumb_width, thumb_height, &buf_size) < 0) {
- thumb_err("Failed to get buffer size");
+ thumb_err("mm_util_get_image_size failed");
return MS_MEDIA_ERR_INTERNAL;
}
@@ -591,6 +677,11 @@ int _media_thumb_convert_data(media_thumb_info *thumb_info,
dst_data = (unsigned char *)malloc(buf_size);
+ if (dst_data == NULL) {
+ thumb_err("Failed to allocate memory");
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
+
if (src_format == MM_UTIL_IMG_FMT_RGB888 &&
dst_format == MM_UTIL_IMG_FMT_BGRA8888) {
@@ -644,7 +735,7 @@ int _media_thumb_convert_format(media_thumb_info *thumb_info,
src_mm_format = _media_thumb_get_format(src_format);
dst_mm_format = _media_thumb_get_format(dst_format);
- if (src_mm_format == -1 || dst_mm_format == -1) {
+ if ((int)src_mm_format == -1 || (int)dst_mm_format == -1) {
thumb_err("Format is invalid");
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
@@ -729,14 +820,14 @@ int _media_thumb_png(const char *origin_path,
media_thumb_info *thumb_info)
{
int err = MS_MEDIA_ERR_NONE;
- err = _media_thumb_decode_with_gdk(origin_path, thumb_width, thumb_height, thumb_info, 0, NORMAL);
+ 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_gdk failed : %d", err);
+ thumb_err("decode_with_evas failed : %d", err);
return err;
}
- err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_RGB888, format);
+ err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_BGRA, format);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_convert_format falied: %d", err);
SAFE_FREE(thumb_info->data);
@@ -753,14 +844,14 @@ int _media_thumb_bmp(const char *origin_path,
media_thumb_info *thumb_info)
{
int err = MS_MEDIA_ERR_NONE;
- err = _media_thumb_decode_with_gdk(origin_path, thumb_width, thumb_height, thumb_info, 0, NORMAL);
+ 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_gdk failed : %d", err);
+ thumb_err("decode_with_evas failed : %d", err);
return err;
}
- err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_RGB888, format);
+ err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_BGRA, format);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_convert_format falied: %d", err);
SAFE_FREE(thumb_info->data);
@@ -777,14 +868,14 @@ int _media_thumb_wbmp(const char *origin_path,
media_thumb_info *thumb_info)
{
int err = MS_MEDIA_ERR_NONE;
- err = _media_thumb_decode_with_gdk(origin_path, thumb_width, thumb_height, thumb_info, 0, NORMAL);
+ 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_gdk failed : %d", err);
+ thumb_err("decode_with_evas failed : %d", err);
return err;
}
- err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_RGB888, format);
+ err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_BGRA, format);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_convert_format falied: %d", err);
SAFE_FREE(thumb_info->data);
@@ -801,14 +892,14 @@ int _media_thumb_gif(const char *origin_path,
media_thumb_info *thumb_info)
{
int err = MS_MEDIA_ERR_NONE;
- err = _media_thumb_decode_with_gdk(origin_path, thumb_width, thumb_height, thumb_info, 0, NORMAL);
+ 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_gdk failed : %d", err);
+ thumb_err("decode_with_evas failed : %d", err);
return err;
}
- err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_RGB888, format);
+ err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_BGRA, format);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_convert_format falied: %d", err);
SAFE_FREE(thumb_info->data);
@@ -870,14 +961,14 @@ int _media_thumb_jpeg(const char *origin_path,
if (!thumb_done) {
- err = _media_thumb_decode_with_gdk(origin_path, thumb_width, thumb_height, thumb_info, 0, orientation);
+ 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_gdk failed : %d", err);
+ thumb_err("decode_with_evas failed : %d", err);
return err;
}
- err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_RGB888, format);
+ err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_BGRA, format);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_convert_format falied: %d", err);
SAFE_FREE(thumb_info->data);
@@ -898,16 +989,14 @@ int _media_thumb_jpeg_for_raw(const char *origin_path,
int err = MS_MEDIA_ERR_NONE;
int orientation = NORMAL;
- err = _media_thumb_decode_with_gdk(origin_path, thumb_width, thumb_height, thumb_info, 0, orientation);
+ 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_gdk failed : %d", err);
+ thumb_err("decode_with_evas failed : %d", err);
return err;
}
- /* Temporary process */
- thumb_info->data = gdk_pixbuf_get_pixels(thumb_info->gdkdata);
- err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_RGB888, format);
+ err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_BGRA, format);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_convert_format falied: %d", err);
SAFE_FREE(thumb_info->data);
@@ -920,7 +1009,7 @@ int _media_thumb_image(const char *origin_path,
int thumb_width,
int thumb_height,
media_thumb_format format,
- media_thumb_info *thumb_info,
+ media_thumb_info *thumb_info,
bool is_raw,
uid_t uid)
{
@@ -935,7 +1024,7 @@ int _media_thumb_image(const char *origin_path,
thumb_info->origin_width = origin_w = image_info.width;
thumb_info->origin_height = origin_h = image_info.height;
- thumb_dbg("image type is %d\n", image_type);
+ //thumb_dbg("image type is %d, width:%d, height:%d", image_type, origin_w, origin_h);
if ((image_type != IMG_CODEC_JPEG) &&
(origin_w * origin_h > THUMB_MAX_ALLOWED_MEM_FOR_THUMB)) {
@@ -968,9 +1057,9 @@ int _media_thumb_image(const char *origin_path,
int wbmp_width = 0;
int wbmp_height = 0;
- err = _media_thumb_get_wh_with_gdk(origin_path, &wbmp_width, &wbmp_height);
+ err = _media_thumb_get_wh_with_evas(origin_path, &wbmp_width, &wbmp_height);
if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_get_wh_with_gdk in WBMP : %d", err);
+ thumb_err("_media_thumb_get_wh_with_evas in WBMP : %d", err);
return err;
}
@@ -1012,7 +1101,6 @@ int _media_thumb_video(const char *origin_path,
int size = 0;
int width = 0;
int height = 0;
- GdkPixbuf *pixbuf;
bool drm_type = FALSE;
is_drm = drm_type;
@@ -1182,10 +1270,6 @@ int _media_thumb_video(const char *origin_path,
SAFE_FREE(thumb_info->data);
return err;
}
- pixbuf = gdk_pixbuf_new_from_data (thumb_info->data, GDK_COLORSPACE_RGB, FALSE, 8, thumb_info->width, thumb_info->height, 3*thumb_info->width, NULL, NULL);
- thumb_info->gdkdata = gdk_pixbuf_copy(pixbuf);
- g_object_unref(pixbuf);
-
} else {
thumb_dbg("no contents information");
frame = NULL;
@@ -1197,3 +1281,197 @@ int _media_thumb_video(const char *origin_path,
return err;
}
+static int _mkdir(const char *dir, mode_t mode) {
+ char tmp[256];
+ char *p = NULL;
+ size_t len;
+
+ snprintf(tmp, sizeof(tmp),"%s",dir);
+ len = strlen(tmp);
+ if(tmp[len - 1] == '/')
+ tmp[len - 1] = 0;
+ for(p = tmp + 1; *p; p++)
+ if(*p == '/') {
+ *p = 0;
+ mkdir(tmp, mode);
+ *p = '/';
+ }
+ return mkdir(tmp, mode);
+}
+
+static char* _media_thumb_mmc_get_path(uid_t uid)
+{
+ char *result_psswd = NULL;
+ struct group *grpinfo = NULL;
+ if(uid == getuid())
+ {
+ result_psswd = strdup(THUMB_MMC_PATH);
+ grpinfo = getgrnam("users");
+ if(grpinfo == NULL) {
+ thumb_err("getgrnam(users) returns NULL !");
+ if(result_psswd)
+ free(result_psswd);
+ return NULL;
+ }
+ }
+ else
+ {
+ struct passwd *userinfo = getpwuid(uid);
+ if(userinfo == NULL) {
+ thumb_err("getpwuid(%d) returns NULL !", uid);
+ return NULL;
+ }
+ grpinfo = getgrnam("users");
+ if(grpinfo == NULL) {
+ thumb_err("getgrnam(users) returns NULL !");
+ return NULL;
+ }
+ // Compare git_t type and not group name
+ if (grpinfo->gr_gid != userinfo->pw_gid) {
+ thumb_err("UID [%d] does not belong to 'users' group!", uid);
+ return NULL;
+ }
+ asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/mmc", userinfo->pw_dir);
+ }
+
+ _mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO);
+
+ return result_psswd;
+}
+
+static char* _media_thumb_phone_get_path(uid_t uid)
+{
+ char *result_psswd = NULL;
+ struct group *grpinfo = NULL;
+ if(uid == getuid())
+ {
+ result_psswd = strdup(THUMB_PHONE_PATH);
+ grpinfo = getgrnam("users");
+ if(grpinfo == NULL) {
+ thumb_err("getgrnam(users) returns NULL !");
+ if(result_psswd)
+ free(result_psswd);
+ return NULL;
+ }
+ }
+ else
+ {
+ struct passwd *userinfo = getpwuid(uid);
+ if(userinfo == NULL) {
+ thumb_err("getpwuid(%d) returns NULL !", uid);
+ return NULL;
+ }
+ grpinfo = getgrnam("users");
+ if(grpinfo == NULL) {
+ thumb_err("getgrnam(users) returns NULL !");
+ return NULL;
+ }
+ // Compare git_t type and not group name
+ if (grpinfo->gr_gid != userinfo->pw_gid) {
+ thumb_err("UID [%d] does not belong to 'users' group!", uid);
+ return NULL;
+ }
+ asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/phone", userinfo->pw_dir);
+ }
+
+ _mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO);
+
+ return result_psswd;
+}
+
+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;
+ char *thumb_dir = NULL;
+ char file_ext[255] = { 0 };
+ media_thumb_store_type store_type = -1;
+
+ if (file_full_path == NULL || thumb_hash_path == NULL
+ || max_thumb_path <= 0) {
+ thumb_err
+ ("file_full_path==NULL || thumb_hash_path == NULL || max_thumb_path <= 0");
+ return -1;
+ }
+
+ _media_thumb_get_file_ext(file_full_path, file_ext, sizeof(file_ext));
+
+ store_type = _media_thumb_get_store_type_by_path(file_full_path);
+ if (store_type == THUMB_PHONE) {
+ thumb_dir = _media_thumb_phone_get_path(uid);
+ } else if (store_type == THUMB_MMC) {
+ thumb_dir = _media_thumb_mmc_get_path(uid);
+ } else {
+ thumb_dir = _media_thumb_phone_get_path(uid);
+ }
+
+ hash_name = _media_thumb_generate_hash_name(file_full_path);
+
+ int ret_len;
+ ret_len =
+ snprintf(thumb_hash_path, max_thumb_path - 1, "%s/.%s-%s.jpg",
+ thumb_dir, file_ext, hash_name);
+ if(thumb_dir)
+ free(thumb_dir);
+ if (ret_len < 0) {
+ thumb_err("Error when snprintf");
+ return -1;
+ } else if (ret_len > max_thumb_path) {
+ thumb_err("Error for the length of thumb pathname");
+ return -1;
+ }
+
+ //thumb_dbg("thumb hash : %s", thumb_hash_path);
+
+ return 0;
+}
+
+
+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;
+ }
+} \ No newline at end of file
diff --git a/src/util/media-thumb-util.c b/src/util/media-thumb-util.c
index c86d55d..3ba1c06 100755
--- a/src/util/media-thumb-util.c
+++ b/src/util/media-thumb-util.c
@@ -26,12 +26,6 @@
#include <glib.h>
#include <aul.h>
#include <string.h>
-#include <sys/stat.h>
-#include <grp.h>
-#include <pwd.h>
-#include <sys/smack.h>
-
-#define GLOBAL_USER 0 //#define tzplatform_getenv(TZ_GLOBAL) //TODO
int _media_thumb_get_width(media_thumb_type thumb_type)
{
@@ -90,7 +84,7 @@ _media_thumb_get_file_type(const char *file_full_path)
("aul_get_mime_from_file fail.. Now trying to get type by extension");
char ext[255] = { 0 };
- int ret = _media_thumb_get_file_ext(file_full_path, ext, sizeof(ext));
+ ret = _media_thumb_get_file_ext(file_full_path, ext, sizeof(ext));
if (ret < 0) {
thumb_err("_media_thumb_get_file_ext failed");
return THUMB_NONE_TYPE;
@@ -155,174 +149,4 @@ int _media_thumb_remove_file(const char *path)
thumb_stderror("fail to remove file[%s] result");
return FALSE;
}
-}
-
-static int _mkdir(const char *dir, mode_t mode) {
- char tmp[256];
- char *p = NULL;
- size_t len;
-
- snprintf(tmp, sizeof(tmp),"%s",dir);
- len = strlen(tmp);
- if(tmp[len - 1] == '/')
- tmp[len - 1] = 0;
- for(p = tmp + 1; *p; p++)
- if(*p == '/') {
- *p = 0;
- mkdir(tmp, mode);
- *p = '/';
- }
- return mkdir(tmp, mode);
-}
-
-static char* _media_thumb_mmc_get_path(uid_t uid)
-{
- char *result_psswd = NULL;
- struct group *grpinfo = NULL;
- if(uid == getuid())
- {
- result_psswd = strdup(THUMB_MMC_PATH);
- grpinfo = getgrnam("users");
- if(grpinfo == NULL) {
- thumb_err("getgrnam(users) returns NULL !");
- if(result_psswd)
- free(result_psswd);
- return NULL;
- }
- }
- else
- {
- struct passwd *userinfo = getpwuid(uid);
- if(userinfo == NULL) {
- thumb_err("getpwuid(%d) returns NULL !", uid);
- return NULL;
- }
- grpinfo = getgrnam("users");
- if(grpinfo == NULL) {
- thumb_err("getgrnam(users) returns NULL !");
- return NULL;
- }
- // Compare git_t type and not group name
- if (grpinfo->gr_gid != userinfo->pw_gid) {
- thumb_err("UID [%d] does not belong to 'users' group!", uid);
- return NULL;
- }
- asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/mmc", userinfo->pw_dir);
- }
-
- _mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO);
-
- return result_psswd;
-}
-
-static char* _media_thumb_phone_get_path(uid_t uid)
-{
- char *result_psswd = NULL;
- struct group *grpinfo = NULL;
- if(uid == getuid())
- {
- result_psswd = strdup(THUMB_PHONE_PATH);
- grpinfo = getgrnam("users");
- if(grpinfo == NULL) {
- thumb_err("getgrnam(users) returns NULL !");
- if(result_psswd)
- free(result_psswd);
- return NULL;
- }
- }
- else
- {
- struct passwd *userinfo = getpwuid(uid);
- if(userinfo == NULL) {
- thumb_err("getpwuid(%d) returns NULL !", uid);
- return NULL;
- }
- grpinfo = getgrnam("users");
- if(grpinfo == NULL) {
- thumb_err("getgrnam(users) returns NULL !");
- return NULL;
- }
- // Compare git_t type and not group name
- if (grpinfo->gr_gid != userinfo->pw_gid) {
- thumb_err("UID [%d] does not belong to 'users' group!", uid);
- return NULL;
- }
- asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/phone", userinfo->pw_dir);
- }
-
- _mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO);
-
- return result_psswd;
-}
-
-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;
- char *thumb_dir = NULL;
- char file_ext[255] = { 0 };
- media_thumb_store_type store_type = -1;
-
- if (file_full_path == NULL || thumb_hash_path == NULL
- || max_thumb_path <= 0) {
- thumb_err
- ("file_full_path==NULL || thumb_hash_path == NULL || max_thumb_path <= 0");
- return -1;
- }
-
- _media_thumb_get_file_ext(file_full_path, file_ext, sizeof(file_ext));
-
- store_type = _media_thumb_get_store_type_by_path(file_full_path);
- if (store_type == THUMB_PHONE) {
- thumb_dir = _media_thumb_phone_get_path(uid);
- } else if (store_type == THUMB_MMC) {
- thumb_dir = _media_thumb_mmc_get_path(uid);
- } else {
- thumb_dir = _media_thumb_phone_get_path(uid);
- }
-
- hash_name = _media_thumb_generate_hash_name(file_full_path);
-
- int ret_len;
- ret_len =
- snprintf(thumb_hash_path, max_thumb_path - 1, "%s/.%s-%s.jpg",
- thumb_dir, file_ext, hash_name);
- if(thumb_dir)
- free(thumb_dir);
- if (ret_len < 0) {
- thumb_err("Error when snprintf");
- return -1;
- } else if (ret_len > max_thumb_path) {
- thumb_err("Error for the length of thumb pathname");
- return -1;
- }
-
- //thumb_dbg("thumb hash : %s", thumb_hash_path);
-
- return 0;
-}
-
-int _media_thumb_save_to_file_with_gdk(GdkPixbuf *data,
- int w,
- int h,
- gboolean alpha,
- char *thumb_path)
-{
- GError *error = NULL;
-
- gdk_pixbuf_save(data,thumb_path,"jpeg", &error, NULL);
- if (error) {
- thumb_dbg ("Error saving image file %s", thumb_path);
- g_error_free (error);
- return -1;
- }
-
- if(smack_setlabel(thumb_path, "User", SMACK_LABEL_ACCESS)){
- thumb_dbg("failed chsmack -a \"User\" %s", thumb_path);
- return -1;
- } else {
- thumb_dbg("chsmack -a \"User\" %s", thumb_path);
- }
-
- return 0;
} \ No newline at end of file