summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt22
-rwxr-xr-xinclude/media-thumb-types.h35
-rwxr-xr-xinclude/media-thumbnail.h5
-rw-r--r--packaging/libmedia-thumbnail.spec36
-rwxr-xr-xserver/CMakeLists.txt19
-rwxr-xr-xserver/include/thumb-server-internal.h12
-rwxr-xr-xserver/thumb-server-internal.c184
-rwxr-xr-xserver/thumb-server.c32
-rwxr-xr-x[-rw-r--r--]src/codec/IfegDecodeAGIF.c226
-rwxr-xr-x[-rw-r--r--]src/codec/img-codec-osal.c2
-rwxr-xr-x[-rw-r--r--]src/codec/img-codec-parser.c711
-rwxr-xr-x[-rw-r--r--]src/codec/img-codec.c23
-rwxr-xr-x[-rw-r--r--]src/include/codec/AGifFrameInfo.h4
-rwxr-xr-x[-rw-r--r--]src/include/codec/img-codec-common.h27
-rwxr-xr-x[-rw-r--r--]src/include/codec/img-codec-parser.h25
-rwxr-xr-x[-rw-r--r--]src/include/codec/img-codec.h2
-rwxr-xr-xsrc/include/ipc/media-thumb-ipc.h4
-rwxr-xr-xsrc/include/media-thumb-internal.h15
-rwxr-xr-xsrc/include/util/media-thumb-db.h2
-rwxr-xr-xsrc/include/util/media-thumb-util.h17
-rwxr-xr-xsrc/ipc/media-thumb-ipc.c11
-rwxr-xr-xsrc/media-thumb-internal.c674
-rwxr-xr-xsrc/media-thumbnail.c83
-rwxr-xr-xsrc/util/media-thumb-db.c10
-rwxr-xr-xsrc/util/media-thumb-debug.c3
-rwxr-xr-xsrc/util/media-thumb-util.c65
-rw-r--r--test/CMakeLists.txt13
-rwxr-xr-xtest/test-thumb.c145
28 files changed, 1079 insertions, 1328 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3563418..b871878 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,31 +7,28 @@ SET(MEDIATHUMB-LIB "media-thumbnail")
SET(MEDIAHASH-LIB "media-hash")
SET(SRCS
src/media-thumbnail.c
- src/media-thumb-internal.c
src/util/media-thumb-debug.c
src/util/media-thumb-util.c
- src/util/media-thumb-db.c
+ src/ipc/media-thumb-ipc.c
src/codec/IfegDecodeAGIF.c
src/codec/img-codec.c
src/codec/img-codec-osal.c
src/codec/img-codec-parser.c
- src/ipc/media-thumb-ipc.c
)
SET(HASH_SRCS
md5/md5.c
md5/media-thumb-hash.c
)
-SET(THUMB-SERVER server/thumb-server.c server/thumb-server-internal.c)
-SET(TEST-THUMB test/test-thumb.c)
-
SET(VENDOR "samsung")
SET(PACKAGE ${PROJECT_NAME})
SET(PKGNAME "com.${VENDOR}.${PACKAGE}")
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
SET(BINDIR "${PREFIX}/bin")
+SET(LOCALBINDIR "${PREFIX}/local/bin")
SET(DATADIR "${PREFIX}/share")
SET(EXEC_PREFIX "\${prefix}")
+SET(LIBDIR "\${prefix}/lib")
SET(INCLUDEDIR "\${prefix}/include")
IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
@@ -42,7 +39,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 ecore-evas evas mmutil-imgp mmutil-jpeg heynoti libmedia-utils vconf libtzplatform-config)
+ pkg_check_modules(pkgs REQUIRED glib-2.0 gthread-2.0 dlog sqlite3 mm-fileinfo aul libexif ecore-evas evas mmutil-imgp mmutil-jpeg libmedia-utils vconf libtzplatform-config)
FOREACH(flag ${pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -82,15 +79,10 @@ SET_TARGET_PROPERTIES(${MEDIATHUMB-LIB} PROPERTIES VERSION ${VERSION})
INSTALL(TARGETS ${MEDIATHUMB-LIB} LIBRARY DESTINATION ${LIB_INSTALL_DIR})
INSTALL(TARGETS ${MEDIAHASH-LIB} LIBRARY DESTINATION ${LIB_INSTALL_DIR})
-ADD_EXECUTABLE(media-thumbnail-server ${THUMB-SERVER})
-TARGET_LINK_LIBRARIES(media-thumbnail-server ${pkgs_LDFLAGS} ${MEDIATHUMB-LIB} )
-INSTALL(TARGETS media-thumbnail-server DESTINATION ${BINDIR})
-
-#ADD_EXECUTABLE(test-thumb ${TEST-THUMB})
-#TARGET_LINK_LIBRARIES(test-thumb ${pkgs_LDFLAGS} ${MEDIATHUMB-LIB} )
-#INSTALL(TARGETS test-thumb DESTINATION ${BINDIR})
+ADD_SUBDIRECTORY(server)
+ADD_SUBDIRECTORY(test)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/media-thumbnail.h DESTINATION include/${MEDIATHUMB-LIB})
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/media-thumb-types.h DESTINATION include/${MEDIATHUMB-LIB})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/include/codec/img-codec-parser.h DESTINATION include/${MEDIATHUMB-LIB})
#INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/thumbsvr DESTINATION /etc/init.d)
diff --git a/include/media-thumb-types.h b/include/media-thumb-types.h
deleted file mode 100755
index b3a6d1d..0000000
--- a/include/media-thumb-types.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * libmedia-thumbnail
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _MEDIA_THUMB_TYPES_H_
-#define _MEDIA_THUMB_TYPES_H_
-
-typedef enum {
- MEDIA_THUMB_LARGE,
- MEDIA_THUMB_SMALL,
-} media_thumb_type;
-
-typedef enum {
- MEDIA_THUMB_BGRA, /* BGRA, especially provided for evas users */
- MEDIA_THUMB_RGB888, /* RGB888 */
-} media_thumb_format;
-
-#endif /*_MEDIA_THUMB_TYPES_H_*/
diff --git a/include/media-thumbnail.h b/include/media-thumbnail.h
index c22dda3..7bda30c 100755
--- a/include/media-thumbnail.h
+++ b/include/media-thumbnail.h
@@ -25,7 +25,6 @@
#include <sys/types.h>
#include <stdbool.h>
-#include "media-thumb-types.h"
#ifdef __cplusplus
extern "C" {
@@ -38,14 +37,10 @@ typedef int (*ThumbFunc) (int error_code, char* path, void* data);
typedef void (*ThumbRawFunc) (int error_code, int request_id, const char* org_path, int thumb_width, int thumb_height, unsigned char* thumb_data, int thumb_size, void* data);
-int thumbnail_request_from_db(const char *origin_path, char *thumb_path, int max_length, uid_t uid);
-
int thumbnail_request_from_db_async(const char *origin_path, ThumbFunc func, void *user_data, uid_t uid);
int thumbnail_request_extract_raw_data_async(int request_id, const char *origin_path, int width, int height, ThumbRawFunc func, void *user_data, uid_t uid);
-int thumbnail_request_save_to_file(const char *origin_path, media_thumb_type thumb_type, const char *thumb_path, uid_t uid);
-
int thumbnail_request_extract_all_thumbs(uid_t uid);
int thumbnail_request_from_db_with_size(const char *origin_path, char *thumb_path, int max_length, int *origin_width, int *origin_height, uid_t uid);
diff --git a/packaging/libmedia-thumbnail.spec b/packaging/libmedia-thumbnail.spec
index f70b5e8..6659e24 100644
--- a/packaging/libmedia-thumbnail.spec
+++ b/packaging/libmedia-thumbnail.spec
@@ -1,13 +1,13 @@
-Name: libmedia-thumbnail
-Version: 0.1.81
-Release: 0
-License: Apache-2.0
-Summary: Media thumbnail service Library
-Group: Multimedia/Libraries
-Source0: %{name}-%{version}.tar.gz
-Source1001: %{name}.manifest
-Source1002: %{name}-devel.manifest
-Source1003: media-thumbnail-server.manifest
+Name: libmedia-thumbnail
+Summary: Media thumbnail service library for multimedia applications.
+Version: 0.1.82
+Release: 0
+Group: Multimedia/Libraries
+License: Apache-2.0
+Source0: %{name}-%{version}.tar.gz
+Source1001: %{name}.manifest
+Source1002: %{name}-devel.manifest
+Source1003: media-thumbnail-server.manifest
Requires: media-server
BuildRequires: cmake
@@ -15,7 +15,6 @@ BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(mm-fileinfo)
BuildRequires: pkgconfig(mmutil-imgp)
BuildRequires: pkgconfig(mmutil-jpeg)
-BuildRequires: pkgconfig(heynoti)
BuildRequires: pkgconfig(libexif)
BuildRequires: pkgconfig(evas)
BuildRequires: pkgconfig(ecore)
@@ -23,24 +22,29 @@ BuildRequires: pkgconfig(aul)
BuildRequires: pkgconfig(vconf)
BuildRequires: pkgconfig(libmedia-utils)
BuildRequires: pkgconfig(libtzplatform-config)
+BuildRequires: pkgconfig(sqlite3)
%description
Description: Media thumbnail service library for multimedia applications.
+
%package devel
-Summary: Media Thumbnail Service Library (development)
-Requires: %{name} = %{version}-%{release}
+Summary: Media thumbnail service library for multimedia applications. (development)
+Requires: %{name} = %{version}-%{release}
+Group: Development/Libraries
%description devel
-Media thumbnail service library for multimedia applications. (development)
+Description: Media thumbnail service library for multimedia applications. (development)
%package -n media-thumbnail-server
-Summary: Thumbnail generator
-Requires: %{name} = %{version}-%{release}
+Summary: Thumbnail generator.
+Requires: %{name} = %{version}-%{release}
+Group: Development/Libraries
%description -n media-thumbnail-server
Description: Media Thumbnail Server.
+
%prep
%setup -q
cp %{SOURCE1001} %{SOURCE1002} %{SOURCE1003} .
diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt
new file mode 100755
index 0000000..268e223
--- /dev/null
+++ b/server/CMakeLists.txt
@@ -0,0 +1,19 @@
+SET(THUMB-SERVER
+ ../src/util/media-thumb-db.c
+ ../src/media-thumb-internal.c
+ thumb-server.c
+ thumb-server-internal.c)
+
+INCLUDE(FindPkgConfig)
+ pkg_check_modules(pkgs REQUIRED glib-2.0 gthread-2.0 dlog mm-fileinfo aul libexif ecore-evas evas mmutil-imgp mmutil-jpeg libmedia-utils vconf libtzplatform-config)
+
+FOREACH(flag ${pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--hash-style=both -pie")
+
+ADD_EXECUTABLE(media-thumbnail-server ${THUMB-SERVER})
+TARGET_LINK_LIBRARIES(media-thumbnail-server ${pkgs_LDFLAGS} ${MEDIATHUMB-LIB} )
+INSTALL(TARGETS media-thumbnail-server DESTINATION ${BINDIR})
diff --git a/server/include/thumb-server-internal.h b/server/include/thumb-server-internal.h
index cd754e8..ac9a8ab 100755
--- a/server/include/thumb-server-internal.h
+++ b/server/include/thumb-server-internal.h
@@ -20,6 +20,7 @@
*/
#include <glib.h>
+#include <vconf.h>
#include "media-thumb-ipc.h"
#include "media-thumb-db.h"
@@ -47,8 +48,8 @@ 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,
- media_thumb_type thumb_type,
media_thumb_format format,
+ char *thumb_path,
unsigned char **data,
int *size,
int *width,
@@ -56,18 +57,17 @@ int _thumbnail_get_data(const char *origin_path,
int *origin_width,
int *origin_height,
int *alpha,
- uid_t uid);
+ bool *is_saved);
int _thumbnail_get_raw_data(const char *origin_path,
media_thumb_format format,
- unsigned char **data,
- int *size,
int *width,
int *height,
- uid_t uid);
+ unsigned char **data,
+ int *size);
int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid);
-int _media_thumb_process_raw(thumbMsg *req_msg, thumbMsg *res_msg, thumbRawAddMsg *res_raw_msg, uid_t uid);
+int _media_thumb_process_raw(thumbMsg *req_msg, thumbMsg *res_msg, thumbRawAddMsg *res_raw_msg);
#endif /*_THUMB_DAEMON_INTERNAL_H_*/
diff --git a/server/thumb-server-internal.c b/server/thumb-server-internal.c
index de7f8fd..c2f32c7 100755
--- a/server/thumb-server-internal.c
+++ b/server/thumb-server-internal.c
@@ -19,6 +19,7 @@
*
*/
+ #define _GNU_SOURCE
#include "thumb-server-internal.h"
#include "media-thumb-util.h"
#include "media-thumb-debug.h"
@@ -38,6 +39,8 @@
#endif
#define LOG_TAG "MEDIA_THUMBNAIL_SERVER"
+#define THUMB_DEFAULT_WIDTH 320
+#define THUMB_DEFAULT_HEIGHT 240
#define THUMB_BLOCK_SIZE 512
static __thread char **arr_path;
@@ -177,11 +180,11 @@ int _thumb_daemon_process_job(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
return err;
}
-static int __thumb_daemon_process_job_raw(thumbMsg *req_msg, thumbMsg *res_msg, thumbRawAddMsg *res_raw_msg, uid_t uid)
+static int __thumb_daemon_process_job_raw(thumbMsg *req_msg, thumbMsg *res_msg, thumbRawAddMsg *res_raw_msg)
{
int err = MS_MEDIA_ERR_NONE;
- err = _media_thumb_process_raw(req_msg, res_msg, res_raw_msg, uid);
+ err = _media_thumb_process_raw(req_msg, res_msg, res_raw_msg);
if (err != MS_MEDIA_ERR_NONE) {
if (err != MS_MEDIA_ERR_FILE_NOT_EXIST) {
thumb_warn("_media_thumb_process is failed: %d, So use default thumb", err);
@@ -278,31 +281,33 @@ int _thumb_daemon_process_queue_jobs(gpointer data)
memset(&res_msg, 0x00, sizeof(thumbMsg));
recv_msg.msg_type = THUMB_REQUEST_DB_INSERT;
- recv_msg.thumb_type = MEDIA_THUMB_LARGE;
strncpy(recv_msg.org_path, path, sizeof(recv_msg.org_path));
recv_msg.org_path[sizeof(recv_msg.org_path) - 1] = '\0';
- _thumb_daemon_process_job(&recv_msg, &res_msg,uid );
+ err = _thumb_daemon_process_job(&recv_msg, &res_msg,uid );
+ if (err == MS_MEDIA_ERR_FILE_NOT_EXIST) {
+ thumb_err("Thumbnail processing is failed : %d", err);
+ } else {
+ if (res_msg.status == THUMB_SUCCESS) {
- if (res_msg.status == THUMB_SUCCESS) {
+ err = _media_thumb_db_connect(uid);
+ if (err != MS_MEDIA_ERR_NONE) {
+ thumb_err("_media_thumb_mb_svc_connect failed: %d", err);
+ return TRUE;
+ }
- err = _media_thumb_db_connect(uid);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_mb_svc_connect failed: %d", err);
- return TRUE;
- }
+ /* Need to update DB once generating thumb is done */
+ err = _media_thumb_update_db(recv_msg.org_path,
+ res_msg.dst_path,
+ res_msg.origin_width,
+ res_msg.origin_height,
+ uid);
+ if (err != MS_MEDIA_ERR_NONE) {
+ thumb_err("_media_thumb_update_db failed : %d", err);
+ }
- /* Need to update DB once generating thumb is done */
- err = _media_thumb_update_db(recv_msg.org_path,
- res_msg.dst_path,
- res_msg.origin_width,
- res_msg.origin_height,
- uid);
- if (err < 0) {
- thumb_err("_media_thumb_update_db failed : %d", err);
+ _media_thumb_db_disconnect();
}
-
- _media_thumb_db_disconnect();
}
SAFE_FREE(path);
@@ -328,7 +333,6 @@ gboolean _thumb_server_read_socket(GIOChannel *src,
{
struct sockaddr_un client_addr;
unsigned int client_addr_len;
- int client_sock;
thumbMsg recv_msg;
thumbMsg res_msg;
thumbRawAddMsg res_raw_msg;
@@ -353,14 +357,14 @@ gboolean _thumb_server_read_socket(GIOChannel *src,
return TRUE;
}
- thumb_warn("Received [%d] %s(%d) from PID(%d) \n", recv_msg.msg_type, recv_msg.org_path, strlen(recv_msg.org_path), recv_msg.pid);
+ thumb_warn_slog("Received [%d] %s(%d) from PID(%d)", recv_msg.msg_type, recv_msg.org_path, strlen(recv_msg.org_path), recv_msg.pid);
if (recv_msg.msg_type == THUMB_REQUEST_ALL_MEDIA) {
thumb_dbg("All thumbnails are being extracted now");
_thumb_daemon_all_extract(recv_msg.uid);
g_idle_add(_thumb_daemon_process_queue_jobs, NULL);
} else if(recv_msg.msg_type == THUMB_REQUEST_RAW_DATA) {
- __thumb_daemon_process_job_raw(&recv_msg, &res_msg, &res_raw_msg, recv_msg.uid);
+ __thumb_daemon_process_job_raw(&recv_msg, &res_msg, &res_raw_msg);
} else if(recv_msg.msg_type == THUMB_REQUEST_KILL_SERVER) {
thumb_warn("received KILL msg from thumbnail agent.");
} else {
@@ -480,24 +484,6 @@ gboolean _thumb_server_prepare_socket(int *sock_fd)
return TRUE;
}
-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_get_default_path(uid_t uid)
{
char *result_psswd = NULL;
@@ -533,15 +519,12 @@ static char* _media_thumb_get_default_path(uid_t uid)
asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/phone", userinfo->pw_dir);
}
- /* create dir */
- _mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO);
-
return result_psswd;
}
-int _thumbnail_get_data(const char *origin_path,
- media_thumb_type thumb_type,
- media_thumb_format format,
+int _thumbnail_get_data(const char *origin_path,
+ media_thumb_format format,
+ char *thumb_path,
unsigned char **data,
int *size,
int *width,
@@ -549,7 +532,7 @@ int _thumbnail_get_data(const char *origin_path,
int *origin_width,
int *origin_height,
int *alpha,
- uid_t uid)
+ bool *is_saved)
{
int err = MS_MEDIA_ERR_NONE;
int thumb_width = -1;
@@ -572,37 +555,33 @@ int _thumbnail_get_data(const char *origin_path,
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
- thumb_width = _media_thumb_get_width(thumb_type);
- if (thumb_width < 0) {
- thumb_err("media_thumb_type is invalid");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- thumb_height = _media_thumb_get_height(thumb_type);
- if (thumb_height < 0) {
- thumb_err("media_thumb_type is invalid");
- 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_width = *width;
+ thumb_height = *height;
+ if(thumb_width == 0) {
+ thumb_width = THUMB_DEFAULT_WIDTH;
+ thumb_height = THUMB_DEFAULT_HEIGHT;
+ }
if (file_type == THUMB_IMAGE_TYPE) {
- err = _media_thumb_image(origin_path, thumb_width, thumb_height, format, &thumb_info, false, uid);
+ err = _media_thumb_image(origin_path, thumb_path, thumb_width, thumb_height, format, &thumb_info, FALSE);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_image failed");
return err;
}
-
} else if (file_type == THUMB_VIDEO_TYPE) {
- err = _media_thumb_video(origin_path, thumb_width, thumb_height, format, &thumb_info,uid);
+ err = _media_thumb_video(origin_path, thumb_width, thumb_height, format, &thumb_info);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_image failed");
return err;
}
+ } else {
+ thumb_err("invalid file type");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
}
if (size) *size = thumb_info.size;
@@ -612,6 +591,7 @@ int _thumbnail_get_data(const char *origin_path,
if (origin_width) *origin_width = thumb_info.origin_width;
if (origin_height) *origin_height = thumb_info.origin_height;
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) 0x%x",
*size, *width, *height, *data);
@@ -621,15 +601,15 @@ int _thumbnail_get_data(const char *origin_path,
int _thumbnail_get_raw_data(const char *origin_path,
media_thumb_format format,
- unsigned char **data,
- int *size,
int *width,
int *height,
- uid_t uid)
+ unsigned char **data,
+ int *size)
{
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");
@@ -647,7 +627,7 @@ int _thumbnail_get_raw_data(const char *origin_path,
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
- thumb_dbg("Origin path : %s", origin_path);
+// thumb_dbg_slog("Origin path : %s", origin_path);
int file_type = THUMB_NONE_TYPE;
media_thumb_info thumb_info = {0,};
@@ -656,23 +636,26 @@ int _thumbnail_get_raw_data(const char *origin_path,
thumb_height = *height;
if (file_type == THUMB_IMAGE_TYPE) {
- err = _media_thumb_image(origin_path, thumb_width, thumb_height, format, &thumb_info, true, uid);
+ err = _media_thumb_image(origin_path, thumb_path, thumb_width, thumb_height, format, &thumb_info, TRUE);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_image failed");
return err;
}
} else if (file_type == THUMB_VIDEO_TYPE) {
- err = _media_thumb_video(origin_path, thumb_width, thumb_height, format, &thumb_info,uid);
+ err = _media_thumb_video(origin_path, thumb_width, thumb_height, format, &thumb_info);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_image failed");
return err;
}
+ } else {
+ thumb_err("invalid file type");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
}
if (size) *size = thumb_info.size;
- if (width) *width = thumb_info.width;
- if (height) *height = thumb_info.height;
*data = thumb_info.data;
+ *width = thumb_info.width;
+ *height = thumb_info.height;
//thumb_dbg("Thumb data is generated successfully (Size:%d, W:%d, H:%d) 0x%x", *size, *width, *height, *data);
@@ -692,6 +675,7 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
char *thumb_path = NULL;
int need_update_db = 0;
int alpha = 0;
+ bool is_saved = FALSE;
if (req_msg == NULL || res_msg == NULL) {
thumb_err("Invalid msg!");
@@ -699,18 +683,24 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
}
int msg_type = req_msg->msg_type;
- media_thumb_type thumb_type = req_msg->thumb_type;
const char *origin_path = req_msg->org_path;
media_thumb_format thumb_format = MEDIA_THUMB_BGRA;
+ thumb_w = req_msg->thumb_width;
+ thumb_h = req_msg->thumb_height;
thumb_path = res_msg->dst_path;
thumb_path[0] = '\0';
max_length = sizeof(res_msg->dst_path);
+ if (!g_file_test(origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
+ thumb_err("origin_path does not exist in file system.");
+ return MS_MEDIA_ERR_FILE_NOT_EXIST;
+ }
+
err = _media_thumb_db_connect(uid);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_mb_svc_connect failed: %d", err);
- return MS_MEDIA_ERR_DB_CONNECT_FAIL;
+ return err;
}
if (msg_type == THUMB_REQUEST_DB_INSERT) {
@@ -726,7 +716,7 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
if (err != MS_MEDIA_ERR_NONE) {
char *default_path = _media_thumb_get_default_path(uid);
if(default_path) {
- thumb_err("_media_thumb_get_hash_name failed - %d\n", err);
+ thumb_err("_media_thumb_get_hash_name failed - %d", err);
strncpy(thumb_path, default_path, max_length);
free(default_path);
}
@@ -746,7 +736,7 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
if (err != MS_MEDIA_ERR_NONE) {
char *default_path = _media_thumb_get_default_path(uid);
if(default_path) {
- thumb_err("_media_thumb_get_hash_name failed - %d\n", err);
+ thumb_err("_media_thumb_get_hash_name failed - %d", err);
strncpy(thumb_path, default_path, max_length);
free(default_path);
}
@@ -764,17 +754,19 @@ 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, &data, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h, &alpha, uid);
+ err = _thumbnail_get_data(origin_path, thumb_format, thumb_path, &data, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h, &alpha, &is_saved);
if (err != MS_MEDIA_ERR_NONE) {
char *default_path = _media_thumb_get_default_path(uid);
thumb_err("_thumbnail_get_data failed - %d", err);
SAFE_FREE(data);
+
if(default_path) {
strncpy(thumb_path, default_path, max_length);
free(default_path);
}
- _media_thumb_db_disconnect();
- return err;
+ goto DB_UPDATE;
+// _media_thumb_db_disconnect();
+// return err;
}
//thumb_dbg("Size : %d, W:%d, H:%d", thumb_size, thumb_w, thumb_h);
@@ -798,25 +790,29 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
thumb_path[len - 2] = 'n';
thumb_path[len - 1] = 'g';
}
- thumb_dbg("Thumb path is changed : %s", thumb_path);
+ thumb_dbg_slog("Thumb path is changed : %s", 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_evas failed - %d", err);
- SAFE_FREE(data);
+ 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) {
+ char *default_path = _media_thumb_get_default_path(uid);
+ 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) {
- strncpy(thumb_path, default_path, max_length);
- free(default_path);
+ if (msg_type == THUMB_REQUEST_DB_INSERT || msg_type == THUMB_REQUEST_ALL_MEDIA) {
+ if(default_path) {
+ strncpy(thumb_path, default_path, max_length);
+ free(default_path);
+ }
}
+ _media_thumb_db_disconnect();
+ return err;
+ } else {
+ thumb_dbg("file save success");
}
- _media_thumb_db_disconnect();
- return err;
} else {
- thumb_dbg("file save success");
+ thumb_dbg("file is already saved");
}
/* fsync */
@@ -835,7 +831,7 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
/* End of fsync */
SAFE_FREE(data);
-
+DB_UPDATE:
/* DB update if needed */
if (need_update_db == 1) {
err = _media_thumb_update_db(origin_path, thumb_path, res_msg->origin_width, res_msg->origin_height, uid);
@@ -850,7 +846,7 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg, uid_t uid)
}
int
-_media_thumb_process_raw(thumbMsg *req_msg, thumbMsg *res_msg, thumbRawAddMsg *res_raw_msg, uid_t uid)
+_media_thumb_process_raw(thumbMsg *req_msg, thumbMsg *res_msg, thumbRawAddMsg *res_raw_msg)
{
int err = MS_MEDIA_ERR_NONE;
unsigned char *data = NULL;
@@ -876,7 +872,7 @@ _media_thumb_process_raw(thumbMsg *req_msg, thumbMsg *res_msg, thumbRawAddMsg *r
return MS_MEDIA_ERR_FILE_NOT_EXIST;
}
- err = _thumbnail_get_raw_data(origin_path, thumb_format, &data, &thumb_size, &thumb_w, &thumb_h, uid);
+ err = _thumbnail_get_raw_data(origin_path, thumb_format, &thumb_w, &thumb_h, &data, &thumb_size);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_thumbnail_get_data failed - %d", err);
diff --git a/server/thumb-server.c b/server/thumb-server.c
index b64a3d6..3a9a113 100755
--- a/server/thumb-server.c
+++ b/server/thumb-server.c
@@ -25,7 +25,6 @@
#include "media-thumb-util.h"
#include "thumb-server-internal.h"
#include <pthread.h>
-#include <heynoti.h>
#include <vconf.h>
#ifdef LOG_TAG
@@ -33,10 +32,10 @@
#endif
#define LOG_TAG "MEDIA_THUMBNAIL_SERVER"
-#define POWEROFF_NOTI_NAME "power_off_start" /*poeroff noti from system-server*/
extern GMainLoop *g_thumb_server_mainloop;
+#if 0
static void _media_thumb_signal_handler(void *user_data)
{
thumb_dbg("Singal Hander for HEYNOTI \"power_off_start\"");
@@ -48,32 +47,17 @@ static void _media_thumb_signal_handler(void *user_data)
return;
}
+#endif
int main(void)
{
int sockfd = -1;
+ int err = 0;
GSource *source = NULL;
GIOChannel *channel = NULL;
GMainContext *context = NULL;
- /*heynoti for power off*/
- int err = 0;
- int heynoti_id = heynoti_init();
-
- if (heynoti_id < 0) {
- thumb_err("heynoti_init failed");
- } else {
- err = heynoti_subscribe(heynoti_id, POWEROFF_NOTI_NAME, _media_thumb_signal_handler, NULL);
- if (err < 0) {
- thumb_err("heynoti_attach_handler failed: %d", err);
- } else {
- err = heynoti_attach_handler(heynoti_id);
- if (err < 0)
- thumb_err("heynoti_attach_handler failed: %d", err);
- }
- }
-
/* Set VCONFKEY_SYSMAN_MMC_FORMAT callback to get noti for SD card format */
err = vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_FORMAT, (vconf_callback_fn) _thumb_daemon_vconf_cb, NULL);
if (err == -1)
@@ -91,6 +75,7 @@ int main(void)
}
g_thumb_server_mainloop = g_main_loop_new(context, FALSE);
+ context = g_main_loop_get_context(g_thumb_server_mainloop);
/* Create new channel to watch udp socket */
channel = g_io_channel_unix_new(sockfd);
@@ -100,10 +85,10 @@ int main(void)
g_source_set_callback(source, (GSourceFunc)_thumb_server_read_socket, NULL, NULL);
g_source_attach(source, context);
- GSource *source_init = NULL;
- source_init = g_idle_source_new ();
- g_source_set_callback (source_init, _thumb_daemon_start_jobs, NULL, NULL);
- g_source_attach (source_init, context);
+ GSource *source_evas_init = NULL;
+ source_evas_init = g_idle_source_new ();
+ g_source_set_callback (source_evas_init, _thumb_daemon_start_jobs, NULL, NULL);
+ g_source_attach (source_evas_init, context);
/* Would be used when glib 2.32 is installed
GSource *sig_handler_src = NULL;
@@ -121,6 +106,7 @@ int main(void)
g_io_channel_shutdown(channel, FALSE, NULL);
g_io_channel_unref(channel);
_thumb_daemon_finish_jobs();
+ g_main_loop_unref(g_thumb_server_mainloop);
return 0;
}
diff --git a/src/codec/IfegDecodeAGIF.c b/src/codec/IfegDecodeAGIF.c
index e1e5a11..6fc2f1a 100644..100755
--- a/src/codec/IfegDecodeAGIF.c
+++ b/src/codec/IfegDecodeAGIF.c
@@ -35,17 +35,13 @@ int image_top_pos_N = 0;
AGifFrameInfo *FastImgCreateAGIFFrameData(unsigned int width, unsigned int height, unsigned char *pEncodedData, unsigned int file_size, unsigned int ui_backcolor, BOOL bLoop)
{
- int header_temp;
+ unsigned int header_temp;
int backcolor_index;
unsigned int image_backcolor;
unsigned int backcolor_parsing;
- unsigned int transcolor_565 = 0;
int transparent = 0;
int transIndex = 0;
- int local_color_table_flag;
-
int inputPos = 0;
- int inputPos_temp = 0;
AGifFrameInfo *pFrameData;
if (0 == (pFrameData = IfegMemAlloc(sizeof(AGifFrameInfo)))) {
@@ -59,9 +55,9 @@ AGifFrameInfo *FastImgCreateAGIFFrameData(unsigned int width, unsigned int heigh
pFrameData->logi_wdt = pEncodedData[6] | (pEncodedData[7]<<8);
pFrameData->logi_hgt = pEncodedData[8] | (pEncodedData[9]<<8);
#ifdef INTERNAL_IMGCODEC
- thumb_dbg("logi_wdt:%d, logi_hgt:%d\n", pFrameData->logi_wdt, pFrameData->logi_hgt);
+ thumb_dbg("logi_wdt:%d, logi_hgt:%d", pFrameData->logi_wdt, pFrameData->logi_hgt);
#else
- thumb_dbg("logi_wdt:%d, logi_hgt:%d\n", pFrameData->logi_wdt, pFrameData->logi_hgt);
+ thumb_dbg("logi_wdt:%d, logi_hgt:%d", pFrameData->logi_wdt, pFrameData->logi_hgt);
if ((pFrameData->logi_wdt > MAXWIDTH) || (pFrameData->logi_hgt > MAXHEIGHT)) {
if (pFrameData) {
IfegMemFree(pFrameData);
@@ -78,7 +74,7 @@ AGifFrameInfo *FastImgCreateAGIFFrameData(unsigned int width, unsigned int heigh
} else {
header_temp = 0;
}
-
+
if (file_size > 30+header_temp && pEncodedData[14+header_temp] == 0xFF) {
pFrameData->nLoopCount = pEncodedData[30+header_temp]<<8 | pEncodedData[29+header_temp];
} else if (file_size > 30+8+header_temp && pEncodedData[14+8+header_temp] == 0xFF) {
@@ -86,38 +82,22 @@ AGifFrameInfo *FastImgCreateAGIFFrameData(unsigned int width, unsigned int heigh
} else {
pFrameData->nLoopCount = -1;
}
-
+
pFrameData->nRepeatCount = 0;
- thumb_dbg("10st data : 0x%x , global color table num : %d\n", pEncodedData[10], header_temp);
- thumb_dbg("13: 0x%x ,14: 0x%x, 15: 0x%x, nRepeatCount : %d, nLoopCount : %d\n", pEncodedData[13+header_temp], pEncodedData[14+header_temp], pEncodedData[15+header_temp], pFrameData->nRepeatCount, pFrameData->nLoopCount);
+ thumb_dbg("10st data : 0x%x , global color table num : %d", pEncodedData[10], header_temp);
+ thumb_dbg("13: 0x%x ,14: 0x%x, 15: 0x%x, nRepeatCount : %d, nLoopCount : %d", pEncodedData[13+header_temp], pEncodedData[14+header_temp], pEncodedData[15+header_temp], pFrameData->nRepeatCount, pFrameData->nLoopCount);
backcolor_index = pEncodedData[11];
if (pEncodedData[14+header_temp] == 0xF9) {
- inputPos_temp = 14+header_temp+17;
transparent = pEncodedData[16+header_temp] & 0x01;
transIndex = pEncodedData[19+header_temp];
- local_color_table_flag = pEncodedData[30+header_temp] & 0x80;
-
- if (local_color_table_flag == 0x80) {
- transcolor_565 = ((pEncodedData[inputPos_temp+transIndex*3]>>3)<<11)|((pEncodedData[inputPos_temp+transIndex*3+1]>>2)<<5)|(pEncodedData[inputPos_temp+transIndex*3+2]>>3);
- } else {
- transcolor_565 = ((pEncodedData[13+transIndex*3]>>3)<<11)|((pEncodedData[13+transIndex*3+1]>>2)<<5)|(pEncodedData[13+transIndex*3+2]>>3);
- }
backcolor_parsing = (unsigned short)((pEncodedData[inputPos+backcolor_index*3] >> 3)<<11) | ((pEncodedData[inputPos+backcolor_index*3+1] >> 2)<<5) | (pEncodedData[inputPos+backcolor_index*3+2] >> 3);
} else if (pEncodedData[14+19+header_temp] == 0xF9) {
- inputPos_temp = 14+19+header_temp+17;
transparent = pEncodedData[35+header_temp] & 0x01;
transIndex = pEncodedData[38+header_temp];
- local_color_table_flag = pEncodedData[49+header_temp] & 0x80;
-
- if (local_color_table_flag == 0x80) {
- transcolor_565 = ((pEncodedData[inputPos_temp+transIndex*3]>>3)<<11)|((pEncodedData[inputPos_temp+transIndex*3+1]>>2)<<5)|(pEncodedData[inputPos_temp+transIndex*3+2]>>3);
- } else {
- transcolor_565 = ((pEncodedData[13+transIndex*3]>>3)<<11)|((pEncodedData[13+transIndex*3+1]>>2)<<5)|(pEncodedData[13+transIndex*3+2]>>3);
- }
backcolor_parsing = (unsigned short)((pEncodedData[inputPos+backcolor_index*3] >> 3)<<11) | ((pEncodedData[inputPos+backcolor_index*3+1] >> 2)<<5) | (pEncodedData[inputPos+backcolor_index*3+2] >> 3);
} else if ((pEncodedData[10]&0x80) != 0x80) { /* global color table */
@@ -372,6 +352,34 @@ void FastImgDestroyAGIFFrameData(AGifFrameInfo *pFrameData)
} \
}
+#define __get_next_code_first_nbits_left_0_nobuffer(pInputStream) \
+{\
+ {\
+ if (navail_bytes == 0) {\
+ navail_bytes = (pInputStream)[inputPos++];\
+ if ((inputPos + navail_bytes) > filesize) {\
+ if (decoderline) {\
+ IfegMemFree(decoderline);\
+ decoderline = 0;\
+ } \
+ if (pDecBuf) {\
+ IfegMemFree(pDecBuf);\
+ pDecBuf = 0;\
+ } \
+ if (done_prefix) {\
+ IfegMemFree(done_prefix);\
+ done_prefix = 0;\
+ } \
+ return -1;\
+ } \
+ } \
+ b1 = (pInputStream)[inputPos++];\
+ ret = b1;\
+ nbits_left = 8;\
+ --navail_bytes;\
+ } \
+}
+
#define __get_next_code_first_nbits_left_not_0(pInputStream) \
{\
{\
@@ -406,6 +414,37 @@ void FastImgDestroyAGIFFrameData(AGifFrameInfo *pFrameData)
c = ret;\
}
+#define __get_next_code_first_while_nobuffer(pInputStream) \
+{\
+ while (curr_size > nbits_left) {\
+ if (navail_bytes == 0) {\
+ navail_bytes = (pInputStream)[inputPos++];\
+ if ((inputPos + navail_bytes) > filesize) {\
+ if (decoderline) {\
+ IfegMemFree(decoderline);\
+ decoderline = 0;\
+ } \
+ if (pDecBuf) {\
+ IfegMemFree(pDecBuf);\
+ pDecBuf = 0;\
+ } \
+ if (done_prefix) {\
+ IfegMemFree(done_prefix);\
+ done_prefix = 0;\
+ } \
+ return -1;\
+ } \
+ } \
+ b1 = (pInputStream)[inputPos++];\
+ ret |= b1 << nbits_left;\
+ nbits_left += 8;\
+ --navail_bytes;\
+ } \
+ nbits_left -= curr_size;\
+ ret &= (1<<curr_size)-1;\
+ c = ret;\
+}
+
#define __get_next_code_second_nbits_left_0(pInputStream) \
{\
{\
@@ -479,7 +518,6 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
int spCount = 0;
int logi_wdt; /* logical screen width */
int logi_hgt;
- int logi_image_size;
int image_backcolor;
int ui_backcolor;
int backcolor;
@@ -501,8 +539,6 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
int flag = 0;
unsigned int end;
- int count = 0;
-
unsigned char *pDecBuf = 0;
int expected_width = pFrameData->width;
@@ -522,12 +558,19 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
unsigned int *global_dacbox = pFrameData->pGlobal_table;
register unsigned char *pInputStream = pFrameData->pEncodedData;
void *pOutBits = pFrameData->pOutBits;
- unsigned short *prefix = pFrameData->pPrefix;
- unsigned char *dstack = pFrameData->pDstack;
- unsigned char *suffix = pFrameData->pSuffix;
+ unsigned short *prefix = pFrameData->pPrefix;
+ unsigned char *dstack = pFrameData->pDstack;
+ unsigned char *suffix = pFrameData->pSuffix;
+ unsigned char *done_prefix = 0;
inputPos = pFrameData->offset;
+ done_prefix = IfegMemAlloc(sizeof(unsigned char)*(MAX_CODES+1));
+ if (done_prefix == 0)
+ {
+ thumb_err("Failed to allocate memory for check buffer.");
+ return -1;
+ }
IfegMemset(prefix, 0, sizeof(unsigned short)*(MAX_CODES+1));
IfegMemset(dstack, 0, sizeof(unsigned char)*(MAX_CODES+1));
IfegMemset(suffix, 0, sizeof(unsigned char)*(MAX_CODES+1));
@@ -561,13 +604,14 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
IfegMemFree(pDecBuf);
pDecBuf = 0;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return -1;
}
/* Regard the width/height of image block as the size of thumbnails. */
pFrameData->logi_wdt = logi_wdt = expected_width;
pFrameData->logi_hgt = logi_hgt = expected_height;
- logi_image_size = logi_wdt * logi_hgt;
/* ouput resized image size */
if (logi_wdt <= expected_width && logi_hgt <= expected_height) {
@@ -588,6 +632,8 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
IfegMemFree(pDecBuf);
pDecBuf = 0;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return 0;
}
@@ -661,8 +707,12 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
for (i = 0; i < expected_width * expected_height; i++) {
*pImage16++ = ui_backcolor;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return 1;
} else {
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return 0;
}
}
@@ -678,6 +728,8 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
pDecBuf = 0;
}
if (pFrameData->imgCount == 0) {
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return -1;
}
pFrameData->imgCount = 0;
@@ -696,11 +748,13 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
for (i = 0; i < expected_width * expected_height; i++) {
*pImage16++ = ui_backcolor;
}
-
+
inputPos = pFrameData->offset;
continue;
} else {
/* if there is last frame and bLoop is FALSE, return 2. */
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return 2;
}
#else
@@ -710,8 +764,12 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
for (i = 0; i < expected_width * expected_height; i++) {
*pImage16++ = backcolor;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return 1;
} else {
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return 0;
}
#endif
@@ -728,6 +786,8 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
IfegMemFree(pDecBuf);
pDecBuf = 0;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return -1;
}
@@ -735,7 +795,7 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
transparent = pInputStream[inputPos++] & 0x01; /* does it use? 1:on 0:off */
pFrameData->delay = (pInputStream[inputPos] | (pInputStream[inputPos+1] << 8))*10;
inputPos += 2; /* Delay time (skip) */
- transIndex = pInputStream[inputPos++];
+ transIndex = pInputStream[inputPos++];
inputPos++; /* block end */
break;
@@ -751,6 +811,8 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
IfegMemFree(pDecBuf);
pDecBuf = 0;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return -1;
}
}
@@ -768,6 +830,8 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
IfegMemFree(pDecBuf);
pDecBuf = 0;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return -1;
}
}
@@ -786,6 +850,8 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
IfegMemFree(pDecBuf);
pDecBuf = 0;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return -1;
}
}
@@ -821,6 +887,8 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
IfegMemFree(pDecBuf);
pDecBuf = 0;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return -1;
}
#endif
@@ -846,13 +914,15 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
IfegMemFree(pDecBuf);
pDecBuf = 0;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return 0;
}
IfegMemset(decoderline, 0, orgwdt);
decwdt = ((orgwdt * resized_width+logi_wdt-1) / logi_wdt);
dechgt = ((orghgt * resized_height+logi_hgt-1) / logi_hgt);
-
+
if (!decwdt || !dechgt) {
if (decoderline != 0) {
IfegMemFree(decoderline);
@@ -862,6 +932,8 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
IfegMemFree(pDecBuf);
pDecBuf = 0;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return 0;
}
@@ -878,6 +950,8 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
IfegMemFree(pDecBuf);
pDecBuf = 0;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return 0;
}
IfegMemset(pDecBuf, 0, decwdt * dechgt * 4);
@@ -903,8 +977,6 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
numcolors = (buffer[8] & 0x7) + 1;
numcolors = 1 << numcolors;
- count = 0;
-
/* Make color table */
for (i = 0 ; i < numcolors; i++) {
dacbox[i] = ((pInputStream[inputPos++] >> 2)<<16);
@@ -936,6 +1008,8 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
IfegMemFree(pDecBuf);
pDecBuf = 0;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
return -1;
}
@@ -961,20 +1035,20 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
/* __get_next_code(pInputStream) */
if (navail_bytes < 2) {
if (nbits_left == 0) {
- __get_next_code_first_nbits_left_0(pInputStream)
+ __get_next_code_first_nbits_left_0_nobuffer(pInputStream)
} else
__get_next_code_first_nbits_left_not_0(pInputStream)
- __get_next_code_first_while(pInputStream)
+ __get_next_code_first_while_nobuffer(pInputStream)
} else {
- if (nbits_left == 0)
+ if (nbits_left == 0)
__get_next_code_second_nbits_left_0(pInputStream)
else
__get_next_code_second_nbits_left_not_0(pInputStream)
-
+
__get_next_code_second_while(pInputStream)
- }
-
+ }
+
if (c == ending) {
break;
}
@@ -989,20 +1063,20 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
/* __get_next_code(pInputStream); */
if (navail_bytes < 2) {
if (nbits_left == 0)
- __get_next_code_first_nbits_left_0(pInputStream)
+ __get_next_code_first_nbits_left_0_nobuffer(pInputStream)
else
__get_next_code_first_nbits_left_not_0(pInputStream)
- __get_next_code_first_while(pInputStream)
+ __get_next_code_first_while_nobuffer(pInputStream)
} else {
- if (nbits_left == 0)
+ if (nbits_left == 0)
__get_next_code_second_nbits_left_0(pInputStream)
else
__get_next_code_second_nbits_left_not_0(pInputStream)
__get_next_code_second_while(pInputStream)
}
-
+
} while (c == clear);
if (c == ending) {
@@ -1324,12 +1398,12 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
/* __get_next_code(pInputStream) */
if (navail_bytes < 2) {
if (nbits_left == 0)
- __get_next_code_first_nbits_left_0(pInputStream)
+ __get_next_code_first_nbits_left_0_nobuffer(pInputStream)
else
__get_next_code_first_nbits_left_not_0(pInputStream)
- __get_next_code_first_while(pInputStream)
+ __get_next_code_first_while_nobuffer(pInputStream)
} else {
- if (nbits_left == 0)
+ if (nbits_left == 0)
__get_next_code_second_nbits_left_0(pInputStream)
else
__get_next_code_second_nbits_left_not_0(pInputStream)
@@ -1351,18 +1425,18 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
/* __get_next_code(pInputStream); */
if (navail_bytes < 2) {
if (nbits_left == 0)
- __get_next_code_first_nbits_left_0(pInputStream)
+ __get_next_code_first_nbits_left_0_nobuffer(pInputStream)
else
__get_next_code_first_nbits_left_not_0(pInputStream)
- __get_next_code_first_while(pInputStream)
+ __get_next_code_first_while_nobuffer(pInputStream)
} else {
- if (nbits_left == 0)
+ if (nbits_left == 0)
__get_next_code_second_nbits_left_0(pInputStream)
else
__get_next_code_second_nbits_left_not_0(pInputStream)
__get_next_code_second_while(pInputStream)
- }
+ }
} while (c == clear);
if (c == ending) {
@@ -1382,8 +1456,26 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
code = oc;
*sp++ = (unsigned char)fc;
}
+
+ IfegMemset(done_prefix, 0, sizeof(unsigned char)*(MAX_CODES+1));
while (code >= newcodes) {
*sp++ = suffix[code];
+ if ((code == prefix[code]) || (done_prefix[code] == 1))
+ {
+ thumb_err("Circular entry in table.");
+ if (decoderline != 0) {
+ IfegMemFree(decoderline);
+ decoderline = 0;
+ }
+ if (pDecBuf != 0) {
+ IfegMemFree(pDecBuf);
+ pDecBuf = 0;
+ }
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
+ return 0;
+ }
+ done_prefix[code] = 1;
code = prefix[code];
}
@@ -1542,6 +1634,8 @@ int __FastImgGetNextFrameAGIF_NoBuffer(AGifFrameInfo *pFrameData, BOOL bCenterAl
IfegMemFree(pDecBuf);
pDecBuf = 0;
}
+ IfegMemFree(done_prefix);
+ done_prefix = 0;
pFrameData->offset = inputPos;
pFrameData->imgCount++;
@@ -1594,11 +1688,9 @@ int __FastImgGetNextFrameAGIF_UseBuffer(AGifFrameInfo *pFrameData, BOOL bCenterA
int spCount = 0;
int logi_wdt; /* logical screen width */
int logi_hgt;
- int logi_image_size;
int ui_backcolor565;
int backcolor565;
- int ui_backcolor888;
int backcolor888;
int image_left_pos; /* left position of image in Logical screeen */
@@ -1622,8 +1714,6 @@ int __FastImgGetNextFrameAGIF_UseBuffer(AGifFrameInfo *pFrameData, BOOL bCenterA
int flag = 0;
unsigned int end;
- int count = 0;
-
unsigned char *pDecBuf = 0;
int expected_width = pFrameData->width;
@@ -1642,9 +1732,9 @@ int __FastImgGetNextFrameAGIF_UseBuffer(AGifFrameInfo *pFrameData, BOOL bCenterA
unsigned int *global_dacbox = pFrameData->pGlobal_table;
unsigned char *pInputStream = pFrameData->pEncodedData;
void *pOutBits = pFrameData->pOutBits;
- unsigned short *prefix = pFrameData->pPrefix;
- unsigned char *dstack = pFrameData->pDstack;
- unsigned char *suffix = pFrameData->pSuffix;
+ unsigned short *prefix = pFrameData->pPrefix;
+ unsigned char *dstack = pFrameData->pDstack;
+ unsigned char *suffix = pFrameData->pSuffix;
int filesize = pFrameData->inputSize;
inputPos = pFrameData->offset;
@@ -1654,13 +1744,9 @@ int __FastImgGetNextFrameAGIF_UseBuffer(AGifFrameInfo *pFrameData, BOOL bCenterA
IfegMemset(suffix, 0, sizeof(unsigned char)*(MAX_CODES+1));
ui_backcolor565 = pFrameData->ui_backcolor;
- ui_backcolor888 =
- ((ui_backcolor565&0xf800) << 6)|
- ((ui_backcolor565&0x7e0) << 3)|
- ((ui_backcolor565&0x1f) << 1);
backcolor565 = pFrameData->backcolor;
- backcolor888 =
+ backcolor888 =
((backcolor565&0xf800) << 6)|
((backcolor565&0x7e0) << 3)|
((backcolor565&0x1f) << 1);
@@ -1696,8 +1782,6 @@ int __FastImgGetNextFrameAGIF_UseBuffer(AGifFrameInfo *pFrameData, BOOL bCenterA
pFrameData->logi_wdt = logi_wdt = buffer[6] | (buffer[7] << 8);
pFrameData->logi_hgt = logi_hgt = buffer[8] | (buffer[9] << 8);
- logi_image_size = logi_wdt * logi_hgt;
-
/* ouput resized image size */
if (logi_wdt <= expected_width && logi_hgt <= expected_height) {
resized_width = logi_wdt;
@@ -2034,8 +2118,6 @@ int __FastImgGetNextFrameAGIF_UseBuffer(AGifFrameInfo *pFrameData, BOOL bCenterA
numcolors = (buffer[8] & 0x7) + 1;
numcolors = 1 << numcolors;
- count = 0;
-
/* Make color table */
for (i = 0; i < numcolors; i++) {
dacbox[i] = ((pInputStream[inputPos++] >> 2) << 16);
diff --git a/src/codec/img-codec-osal.c b/src/codec/img-codec-osal.c
index 9a257fa..cefe59f 100644..100755
--- a/src/codec/img-codec-osal.c
+++ b/src/codec/img-codec-osal.c
@@ -69,8 +69,8 @@ HFile DrmOpenFile(const char *szPathName)
FILE *fp = fopen(szPathName, "rb");
if (fp == NULL) {
- thumb_err("file open error: %s", szPathName);
return (HFile) INVALID_HOBJ;
+ thumb_err("file open error: %s", szPathName);
}
return fp;
diff --git a/src/codec/img-codec-parser.c b/src/codec/img-codec-parser.c
index dd04455..2d8d348 100644..100755
--- a/src/codec/img-codec-parser.c
+++ b/src/codec/img-codec-parser.c
@@ -33,6 +33,21 @@
#include "img-codec-common.h"
#include "img-codec-parser.h"
+#define MINIMUM_HEADER_BYTES 8
+
+#define PNG_HEADER_LENGTH 8
+#define JPG_HEADER_LENGTH 2
+#define GIF_HEADER_LENGTH 3
+#define TIFF_HEADER_LENGTH 2
+#define BMP_HEADER_LENGTH 2
+#define WBMP_HEADER_LENGTH 2
+#define TIFF_IMAGE_WIDTH 0x100
+#define TIFF_IMAGE_HEIGHT 0x101
+
+#define JPG_HEADER_TYPE_LENGTH 2
+#define JPG_BLOCK_SIZE_LENGTH 2
+#define JPG_IMAGE_SIZE_LENGTH 8
+
#define FILE_READ_SIZE 4096
typedef struct _stream {
HFile fd;
@@ -44,61 +59,11 @@ typedef struct _stream {
unsigned char *buffer;
} IFEGSTREAMCTRL;
-ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
- ImgImageInfo *imgInfo);
-BOOL process_EXIF(unsigned char *ExifSection, unsigned int length,
- unsigned int *pOrientataion);
-
-ImgCodecType ImgGetInfoHFile(HFile hFile, unsigned long fileSize,
- ImgImageInfo *imgInfo)
-{
- ImgCodecType result = 0;
- SysAssert(hFile);
- SysAssert(fileSize);
-
- if (imgInfo == NULL) {
- result = _ImgGetInfoStreaming(hFile, fileSize, NULL);
- } else {
- result = _ImgGetInfoStreaming(hFile, fileSize, imgInfo);
- }
-
- DrmSeekFile(hFile, SEEK_SET, 0);
-
- return result;
-
-}
-
-ImgCodecType ImgGetInfoFile(const char *filePath, ImgImageInfo * imgInfo)
-{
- HFile hFile;
- FmFileAttribute fileAttrib;
- ImgCodecType result;
- SysAssert(filePath);
- hFile = DrmOpenFile(filePath);
-
- if (hFile == (HFile) INVALID_HOBJ) {
- return IMG_CODEC_NONE;
- }
- DrmGetFileAttributes(filePath, &fileAttrib);
-
- if ((fileAttrib.fileSize == 0)) {
- DrmCloseFile(hFile);
- return IMG_CODEC_NONE;
- }
-
- result = ImgGetInfoHFile(hFile, fileAttrib.fileSize, imgInfo);
-
- DrmCloseFile(hFile);
-
- return result;
-
-}
-
-static unsigned char gIfegPNGHeader[] = {
- 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
+static unsigned char gIfegPNGHeader[] = {0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
static unsigned char gIfegJPEGHeader[] = { 0xFF, 0xD8 };
static unsigned char gIfegGIFHeader[] = { "GIF" };
static unsigned char gIfegBMPHeader[] = { 0x42, 0x4D };
+static unsigned char gIfegWBMPHeader[] = { 0x00, 0x00 };
static int _CheckBuffer(IFEGSTREAMCTRL *pIfegstreamctrl, unsigned int size)
{
@@ -160,277 +125,118 @@ static unsigned int _IfegReadUINT(unsigned char *pBuffer)
((*(pBuffer + 2)) << 8) | (*(pBuffer + 3)));
}
-ImgCodecType ImgGetInfo(unsigned char *pEncodedData, unsigned long fileSize,
- ImgImageInfo *imgInfo)
+static int _ImgGetImageInfo(HFile hFile, unsigned long fileSize, char *fileExt, ImgCodecType *type, unsigned int *width, unsigned int *height, bool fast_mode)
{
- unsigned int width = 0, height = 0;
-
- /* Initialize values */
- if (imgInfo) {
- imgInfo->width = 0;
- imgInfo->height = 0;
- imgInfo->numberOfFrame = 1;
- imgInfo->bOrientation = 0;
- }
-
- SysAssert(pEncodedData);
- SysAssert(fileSize);
+ unsigned int fileleft;
+ unsigned long fileread;
+ unsigned char EncodedDataBuffer[4096];
- /*********************** PNG *************************/
- if (AcMemcmp(pEncodedData, gIfegPNGHeader, PNG_HEADER_LENGTH) == 0) {
- unsigned char tmp;
+ unsigned int *pWidth = NULL;
+ unsigned int *pHeight = NULL;
+ int ret = MS_MEDIA_ERR_NONE;
- if (fileSize < 40) {
- thumb_warn("IMG_CODEC_UNKNOWN_TYPE in PNG");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
- /* Get Image Width */
- width = _IfegReadUINT((pEncodedData + 16));
+ if (type == NULL || width == NULL ||height == NULL ) {
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ } else {
+ pWidth = width;
+ pHeight = height;
- /* Get Image Height */
- height = _IfegReadUINT((pEncodedData + 20));
+ *type = IMG_CODEC_UNKNOWN_TYPE;
+ *pWidth = 0;
+ *pHeight = 0;
+ }
- /* Read Interlace byte */
- tmp = *(pEncodedData + 28);
- /* If image is interlaced then multiple should be 2 */
- if (tmp) {
- thumb_dbg("Interlaced PNG Image.");
- }
+ AcMemset(EncodedDataBuffer, 0, 4096);
- thumb_dbg("type: IMG_CODEC_PNG");
+ SysAssert((const char *)&fileSize);
- if (imgInfo) {
- imgInfo->width = width;
- imgInfo->height = height;
- }
- return IMG_CODEC_PNG;
+ if (DrmReadFile(hFile, EncodedDataBuffer, 8, &fileread) == FALSE) {
+ thumb_err("DrmReadFile was failed");
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
}
- /*********************** BMP *************************/
- else if (AcMemcmp(pEncodedData, gIfegBMPHeader, BMP_HEADER_LENGTH) == 0) {
- /* Parse BMP File and get image width and image height */
- if (fileSize < 26) {
- thumb_warn("IMG_CODEC_UNKNOWN_TYPE in BMP");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
- if (imgInfo) {
- imgInfo->width =
- pEncodedData[18] | (pEncodedData[19] << 8) |
- (pEncodedData[20] << 16) | (pEncodedData[21] << 24);
- imgInfo->height =
- pEncodedData[22] | (pEncodedData[23] << 8) |
- (pEncodedData[24] << 16) | (pEncodedData[25] << 24);
- }
-
- thumb_dbg("type : IMG_CODEC_BMP");
- return IMG_CODEC_BMP;
-
+ if (fileread < MINIMUM_HEADER_BYTES) {
+ thumb_warn("IMG_CODEC_UNKNOWN_TYPE");
+ return ret;
}
- /*********************** GIF *************************/
- else if (AcMemcmp(pEncodedData, gIfegGIFHeader, GIF_HEADER_LENGTH) == 0) {
- int length;
- int inputPos = 0;
- int temp;
- int finished;
- int imagecount = 0;
-
- if ((unsigned int)inputPos + 13 > fileSize) {
- thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
-
- if (pEncodedData[0] != 'G' || pEncodedData[1] != 'I'
- || pEncodedData[2] != 'F' || pEncodedData[3] < '0'
- || pEncodedData[3] > '9' || pEncodedData[4] < '0'
- || pEncodedData[4] > '9' || pEncodedData[5] < 'A'
- || pEncodedData[5] > 'z') {
- thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
- /* get Logical width, height */
- if (imgInfo) {
- imgInfo->width =
- pEncodedData[6] | (pEncodedData[7] << 8);
- imgInfo->height =
- pEncodedData[8] | (pEncodedData[9] << 8);
- }
- if ((pEncodedData[10] & 0x80) != 0) /* Global color table */ {
- temp = (pEncodedData[10] & 0x7) + 1;
- length = (1 << temp) * 3;
- inputPos += length;
- if ((unsigned int)inputPos > fileSize) {
- thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
- }
+ if (AcMemcmp(EncodedDataBuffer, gIfegJPEGHeader, JPG_HEADER_LENGTH) == 0) {
+ if (fast_mode == FALSE) {
+ unsigned char header_type[JPG_HEADER_TYPE_LENGTH];
+ unsigned char block_size[JPG_BLOCK_SIZE_LENGTH];
+ unsigned char image_size[JPG_IMAGE_SIZE_LENGTH];
- inputPos += 13;
- finished = 0;
+ rewind(hFile);
- /* still gif image (image_cnt = 1) */
- while (!finished) {
- if ((unsigned int)inputPos > fileSize)
- break;
+ unsigned short block_length = EncodedDataBuffer[4] * 256 + EncodedDataBuffer[5];
+ thumb_dbg("block length : %d", block_length);
+ unsigned int i = 4;
- switch (pEncodedData[inputPos++]) {
- case 0x3b: /* End of the GIF dataset */
- finished = 1;
- break;
+ if (DrmSeekFile(hFile, SEEK_CUR, block_length+4) == FALSE) {
+ thumb_err("DrmSeekFile was failed");
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
+ }
- case 0x21: /* Extension Block */
- switch (pEncodedData[inputPos++]) {
- case 0xf9: /* Graphic control extension block */
- if (4 != pEncodedData[inputPos++]) { /* data length : fixed 4 bytes */
- thumb_warn
- ("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
- inputPos += 4;
- inputPos++; /* block end */
+ while (i < fileSize) {
+ i += block_length;
+ if (i >= fileSize) {
+ thumb_warn("Failed to get w / h from jpeg at index [%d]", i);
break;
+ }
- case 0x01: /* Plain Text block */
- case 0xfe: /* Comment Extension block */
- case 0xff: /* Appliation Extension block */
- while ((length = pEncodedData[inputPos++]) > 0) { /* get the data length */
- inputPos += (length);
- if ((unsigned int)inputPos >
- fileSize) {
- thumb_warn
- ("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return
- IMG_CODEC_UNKNOWN_TYPE;
- }
- }
- break;
+ AcMemset(header_type, 0, JPG_HEADER_TYPE_LENGTH);
+ if (DrmReadFile(hFile, header_type, (ULONG)JPG_HEADER_TYPE_LENGTH, &fileread) == FALSE) {
+ thumb_err("DrmReadFile was failed");
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
+ }
- default:
+ if (header_type[0] != 0xFF) {
+ thumb_warn("Failed to get w / h from jpeg at index [%d]", i);
break;
}
- break;
-
- case 0x2c: /* Start of an image object. Read the image description. */
-
- if ((unsigned int)inputPos + 9 > fileSize) {
- thumb_warn
- ("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
- /* Color Resolution */
- if ((pEncodedData[inputPos + 8] & 0x80) != 0) { /* Logical color table */
- temp =
- (pEncodedData[inputPos + 8] & 0x7) +
- 1;
- length = (1 << temp) * 3;
- inputPos += length;
- if ((unsigned int)inputPos > fileSize) {
- thumb_warn
- ("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
+ if (header_type[1] == 0xC0 || header_type[1] == 0xC2) {
+ AcMemset(image_size, 0, JPG_IMAGE_SIZE_LENGTH);
+ if (DrmReadFile(hFile, image_size, (ULONG)JPG_IMAGE_SIZE_LENGTH, &fileread) == FALSE) {
+ thumb_err("DrmReadFile was failed");
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
}
- }
-
- inputPos += 9;
- temp = pEncodedData[inputPos++];
- if (temp < 2 || 9 < temp) {
- thumb_warn
- ("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
-
- do {
- length = pEncodedData[inputPos++];
- inputPos += length;
- if ((unsigned int)inputPos > fileSize) {
- thumb_warn
- ("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
+ *pWidth = image_size[5] * 256 + image_size[6];
+ *pHeight = image_size[3] * 256 + image_size[4];
+ break;
+ } else {
+ i += 2;
+ AcMemset(block_size, 0, JPG_BLOCK_SIZE_LENGTH);
+ if (DrmReadFile(hFile, block_size, (ULONG)JPG_BLOCK_SIZE_LENGTH, &fileread) == FALSE) {
+ thumb_err("DrmReadFile was failed");
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
}
- } while (length);
- if (!imagecount)
- imagecount++;
- else {
- if (imgInfo)
- imgInfo->numberOfFrame = 2;
- return IMG_CODEC_AGIF;
+ block_length = block_size[0] * 256 + block_size[1];
+ thumb_dbg("new block length : %d", block_length);
+ if (DrmSeekFile(hFile, SEEK_CUR, block_length-JPG_BLOCK_SIZE_LENGTH) == FALSE) {
+ thumb_err("DrmSeekFile was failed");
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
+ }
}
- break;
-
- default:
- finished = 0;
- break;
-
- } /* end of switch (pEncodedData[inputPos++]) */
- } /* end of while (pImage->bitmapCount > image_cnt && !finished) */
-
- return IMG_CODEC_GIF;
- }
-
- thumb_warn("IMG_CODEC_UNKNOWN_TYPE");
- return IMG_CODEC_UNKNOWN_TYPE;
-}
-
-ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
- ImgImageInfo *imgInfo)
-{
- unsigned int fileleft;
- unsigned long fileread;
- unsigned char EncodedDataBuffer[4096];
-
- unsigned int *pNumberOfFrames = NULL;
- unsigned int *pWidth = NULL;
- unsigned int *pHeight = NULL;
- unsigned int *pOrientation = NULL;
-
- if (imgInfo == NULL) {
- pNumberOfFrames = NULL;
- pWidth = NULL;
- pHeight = NULL;
- pOrientation = NULL;
- } else {
- pWidth = &(imgInfo->width);
- pHeight = &(imgInfo->height);
- pOrientation = &(imgInfo->bOrientation);
- pNumberOfFrames = &(imgInfo->numberOfFrame);
-
- *pWidth = 0;
- *pHeight = 0;
- *pOrientation = 0;
- }
-
- AcMemset(EncodedDataBuffer, 0, 4096);
-
- /* Initialize values */
- if (pNumberOfFrames) {
- *pNumberOfFrames = 1;
- }
-
- SysAssert((const char *)&fileSize);
-
- if (DrmReadFile(hFile, EncodedDataBuffer, 8, &fileread) == FALSE) {
- thumb_err("DrmReadFile was failed");
- return IMG_CODEC_NONE;
- }
-
- if (fileread < MINIMUM_HEADER_BYTES) {
- thumb_warn("IMG_CODEC_UNKNOWN_TYPE");
- return IMG_CODEC_UNKNOWN_TYPE;
+ }
+ thumb_dbg("Jpeg w: %d, h: %d", *pWidth, *pHeight);
+ }
+ thumb_dbg("IMG_CODEC_JPEG");
+ *type = IMG_CODEC_JPEG;
}
/*********************** PNG *************************/
- if (AcMemcmp(EncodedDataBuffer, gIfegPNGHeader, PNG_HEADER_LENGTH) == 0) {
+ else if (AcMemcmp(EncodedDataBuffer, gIfegPNGHeader, PNG_HEADER_LENGTH) == 0) {
unsigned char tmp;
if (DrmReadFile(hFile, EncodedDataBuffer, 32, &fileread) ==
FALSE) {
thumb_err("DrmReadFile was failed");
- return IMG_CODEC_NONE;
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
}
if (fileread < 32) {
thumb_warn("IMG_CODEC_UNKNOWN_TYPE in PNG");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
/* Get Image Width */
if (pWidth) {
@@ -448,25 +254,19 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
if (tmp) {
thumb_dbg("Interlaced PNG Image.");
}
- thumb_dbg("IMG_CODEC_PNG\n");
- return IMG_CODEC_PNG;
+ thumb_dbg("IMG_CODEC_PNG");
+ *type = IMG_CODEC_PNG;
}
/*********************** BMP *************************/
- else if (AcMemcmp(EncodedDataBuffer, gIfegBMPHeader, BMP_HEADER_LENGTH)
- == 0) {
+ else if (AcMemcmp(EncodedDataBuffer, gIfegBMPHeader, BMP_HEADER_LENGTH) == 0) {
/* Parse BMP File and get image width and image height */
- if (DrmReadFile(hFile, &EncodedDataBuffer[8], 18, &fileread) ==
- FALSE) {
+ if (DrmReadFile(hFile, &EncodedDataBuffer[8], 18, &fileread) == FALSE) {
thumb_err("DrmReadFile was failed");
- return IMG_CODEC_NONE;
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
}
if (fileread < 18) {
thumb_warn("IMG_CODEC_UNKNOWN_TYPE in BMP");
- return IMG_CODEC_UNKNOWN_TYPE;
- }
- if (pWidth == NULL || pHeight == NULL
- || pNumberOfFrames == NULL) {
- return IMG_CODEC_BMP;
+ return ret;
}
if (pWidth) {
*pWidth =
@@ -482,7 +282,7 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
}
thumb_dbg("IMG_CODEC_BMP");
- return IMG_CODEC_BMP;
+ *type = IMG_CODEC_BMP;
}
/*********************** GIF *************************/
else if (AcMemcmp(EncodedDataBuffer, gIfegGIFHeader, GIF_HEADER_LENGTH) == 0) {
@@ -495,17 +295,16 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
if (13 > fileSize) {
thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
if (DrmReadFile(hFile, &EncodedDataBuffer[8], 5, &fileread) == FALSE) {
thumb_err("DrmReadFile was failed");
-
- return IMG_CODEC_NONE;
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
}
if (fileread < 5) {
thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
if (EncodedDataBuffer[0] != 'G' || EncodedDataBuffer[1] != 'I'
@@ -514,17 +313,11 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
|| EncodedDataBuffer[4] > '9' || EncodedDataBuffer[5] < 'A'
|| EncodedDataBuffer[5] > 'z') {
thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
- if (!(pWidth && pHeight)) {
- return IMG_CODEC_UNKNOWN_TYPE;
- } else {
- *pWidth =
- EncodedDataBuffer[6] | (EncodedDataBuffer[7] << 8);
- *pHeight =
- EncodedDataBuffer[8] | (EncodedDataBuffer[9] << 8);
- }
+ *pWidth = EncodedDataBuffer[6] | (EncodedDataBuffer[7] << 8);
+ *pHeight = EncodedDataBuffer[8] | (EncodedDataBuffer[9] << 8);
thumb_dbg("Logical width : %d, Height : %d", *pWidth, *pHeight);
@@ -534,22 +327,21 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
if ((tablelength * sizeof(char)) > sizeof(EncodedDataBuffer)) {
thumb_warn("_ImgGetInfoStreaming :table length is more than buffer length");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
if (13 + tablelength > fileSize) {
thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
/* coverity[ -tainted_data_argument : EncodedDataBuffer ] */
if (DrmReadFile(hFile, EncodedDataBuffer, tablelength, &fileread) == FALSE) {
thumb_err("DrmReadFile was failed");
-
- return IMG_CODEC_NONE;
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
}
if (fileread < tablelength) {
thumb_warn("IMG_CODEC_UNKNOWN_TYPE in GIF");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
}
@@ -567,7 +359,7 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
break;
if (_CheckBuffer(&ifegstreamctrl, 1) == 0) {
thumb_warn("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
switch (EncodedDataBuffer[ifegstreamctrl.buffpos++]) {
@@ -579,7 +371,7 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
case 0x21: /* Extension Block */
if (_CheckBuffer(&ifegstreamctrl, 1) == 0) {
thumb_warn("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
switch (EncodedDataBuffer[ifegstreamctrl.buffpos++]) {
@@ -587,11 +379,11 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
case 0xf9: /* Graphic control extension block */
if (_CheckBuffer(&ifegstreamctrl, 6) == 0) {
thumb_warn("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
- if (4 != EncodedDataBuffer[ifegstreamctrl.buffpos++]) { /* data length : fixed 4 bytes */
- return 0;
+ if (4 != EncodedDataBuffer[ifegstreamctrl.buffpos++]) { /* data length : fixed 4 bytes */
+ *type = 0;
}
ifegstreamctrl.buffpos += 4;
ifegstreamctrl.buffpos++; /* block end */
@@ -602,24 +394,25 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
case 0xff: /* Appliation Extension block */
if (_CheckBuffer(&ifegstreamctrl, 1) == 0) {
thumb_warn("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
if (ifegstreamctrl.buffpos > sizeof(EncodedDataBuffer)) {
thumb_warn("buffer position exceeds buffer max length ");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
- while ((ifegstreamctrl.buffpos < sizeof(EncodedDataBuffer)) && ((length = EncodedDataBuffer[ifegstreamctrl.buffpos++]) > 0)) { /* get the data length */
+ while ((ifegstreamctrl.buffpos < sizeof(EncodedDataBuffer))
+ && ((length = EncodedDataBuffer[ifegstreamctrl.buffpos++]) > 0)) { /* get the data length */
if (_CheckBuffer(&ifegstreamctrl, length) == 0) {
thumb_warn("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
/* Check integer overflow */
if (ifegstreamctrl.buffpos > 0xffffffff - length) {
thumb_err("Prevent integer overflow..");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
ifegstreamctrl.buffpos += (length);
@@ -637,41 +430,16 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
if (_CheckBuffer(&ifegstreamctrl, 9) == 0) {
thumb_warn("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
#if 1
if (imagecount == 0) {
/* Regard the width/height of the first image block as the size of thumbnails. */
- int img_block_w, img_block_h,
- img_block_left, img_block_top;
- img_block_left =
- EncodedDataBuffer[ifegstreamctrl.
- buffpos] |
- (EncodedDataBuffer
- [ifegstreamctrl.buffpos + 1] << 8);
- img_block_top =
- EncodedDataBuffer[ifegstreamctrl.
- buffpos +
- 2] |
- (EncodedDataBuffer
- [ifegstreamctrl.buffpos + 3] << 8);
-
- img_block_w =
- EncodedDataBuffer[ifegstreamctrl.
- buffpos +
- 4] |
- (EncodedDataBuffer
- [ifegstreamctrl.buffpos + 5] << 8);
- img_block_h =
- EncodedDataBuffer[ifegstreamctrl.
- buffpos +
- 6] |
- (EncodedDataBuffer
- [ifegstreamctrl.buffpos + 7] << 8);
- thumb_dbg
- ("Image block width : %d, Height : %d, left:%d, top:%d\n",
- img_block_w, img_block_h,
- img_block_left, img_block_top);
+ int img_block_w, img_block_h;
+
+ img_block_w = EncodedDataBuffer[ifegstreamctrl.buffpos + 4] |(EncodedDataBuffer[ifegstreamctrl.buffpos + 5] << 8);
+ img_block_h = EncodedDataBuffer[ifegstreamctrl.buffpos + 6] |(EncodedDataBuffer[ifegstreamctrl.buffpos + 7] << 8);
+ thumb_dbg ("Image block width : %d, Height : %d, left:%d, top:%d", img_block_w, img_block_h);
*pWidth = img_block_w;
*pHeight = img_block_h;
@@ -679,17 +447,11 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
#endif
/* Color Resolution */
if ((EncodedDataBuffer[ifegstreamctrl.buffpos + 8] & 0x80) != 0) { /* Logical color table */
- temp =
- (EncodedDataBuffer
- [ifegstreamctrl.buffpos +
- 8] & 0x7) + 1;
+ temp = (EncodedDataBuffer[ifegstreamctrl.buffpos + 8] & 0x7) + 1;
length = (1 << temp) * 3;
- if (_CheckBuffer
- (&ifegstreamctrl,
- length + 9) == 0) {
- thumb_warn
- ("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ if (_CheckBuffer(&ifegstreamctrl, length + 9) == 0) {
+ thumb_warn("_CheckBuffer was failed");
+ return ret;
}
ifegstreamctrl.buffpos += length;
@@ -700,18 +462,18 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
if (_CheckBuffer(&ifegstreamctrl, 1) == 0) {
thumb_warn("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
temp = EncodedDataBuffer[ifegstreamctrl.buffpos++];
if (temp < 2 || 9 < temp) {
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
do {
if (_CheckBuffer(&ifegstreamctrl, 1) == 0) {
thumb_warn("_CheckBuffer was failed");
- return IMG_CODEC_UNKNOWN_TYPE;
+ return ret;
}
length =EncodedDataBuffer[ifegstreamctrl.buffpos++];
@@ -722,13 +484,11 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
ifegstreamctrl.buffend;
if (DrmSeekFile(ifegstreamctrl.fd, SEEK_CUR, length) == FALSE) {
if (imagecount) {
- if (pNumberOfFrames)
- *pNumberOfFrames
- = 2;
thumb_dbg("IMG_CODEC_AGIF");
- return IMG_CODEC_AGIF;
+ *type = IMG_CODEC_AGIF;
+ return ret;
}
- return IMG_CODEC_UNKNOWN_TYPE;
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
}
ifegstreamctrl.filepos += length;
ifegstreamctrl.buffpos = 0;
@@ -742,10 +502,9 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
if (!imagecount)
imagecount++;
else {
- if (pNumberOfFrames)
- *pNumberOfFrames = 2;
thumb_dbg("IMG_CODEC_AGIF");
- return IMG_CODEC_AGIF;
+ *type = IMG_CODEC_AGIF;
+ return ret;
}
break;
@@ -755,102 +514,122 @@ ImgCodecType _ImgGetInfoStreaming(HFile hFile, unsigned long fileSize,
}
}
- if (pNumberOfFrames) {
- *pNumberOfFrames = 1;
- }
thumb_dbg("IMG_CODEC_GIF");
- return IMG_CODEC_GIF;
+ *type = IMG_CODEC_GIF;
}
+ /*********************** WBMP *************************/
+ else if ((AcMemcmp(EncodedDataBuffer, gIfegWBMPHeader, WBMP_HEADER_LENGTH) == 0)
+ && (strcasecmp(fileExt, "wbmp") == 0)) {
+ /* Parse BMP File and get image width and image height */
+/* if (DrmReadFile(hFile, &EncodedDataBuffer[2], 2, &fileread) == FALSE) {
+ thumb_err("DrmReadFile was failed");
+ return MS_MEDIA_ERR_FILE_READ_FAIL;
+ }
+ if (fileread < 2) {
+ thumb_warn("IMG_CODEC_UNKNOWN_TYPE in WBMP");
+ return ret;
+ }*/
+ if (pWidth) {
+ *pWidth = EncodedDataBuffer[2];
+ }
+ if (pHeight) {
+ *pHeight = EncodedDataBuffer[3];
+ }
+ thumb_dbg("WBMP w: %d, h: %d", *pWidth, *pHeight);
- /*********************** Jpeg *************************/
- else if (AcMemcmp(EncodedDataBuffer, gIfegJPEGHeader, JPG_HEADER_LENGTH)
- == 0) {
-#if 1
- /*
- IFEGSTREAMCTRL ifegstreamctrl;
- if( DrmReadFile(hFile, &EncodedDataBuffer[8], FILE_READ_SIZE-8, &fileread) == FALSE )
- {
- thumb_err( "DrmReadFile was failed");
-
- return IMG_CODEC_NONE;
- }
-
- ifegstreamctrl.fd = hFile;
- ifegstreamctrl.filesize = fileSize;
- ifegstreamctrl.filepos = fileread+8;
- ifegstreamctrl.buffpos = 2;
- ifegstreamctrl.buffend = 8+fileread;
- ifegstreamctrl.buffer = EncodedDataBuffer;
- */
-
-#else /* Get w / h from jpeg header */
-
-#ifdef _PERFORMANCE_CHECK_
- long start = 0L, end = 0L;
- start = mediainfo_get_debug_time();
-#endif
- unsigned char *img_buf = NULL;
- img_buf = (unsigned char *)malloc(fileSize);
+ thumb_dbg("IMG_CODEC_WBMP");
+ *type = IMG_CODEC_WBMP;
+ }
+ return ret;
+}
- rewind(hFile);
- if (DrmReadFile(hFile, img_buf, fileSize, &fileread) == FALSE) {
- thumb_err("DrmReadFile was failed");
+static int _ImgGetFileExt(const char *file_path, char *file_ext, int max_len)
+{
+ int i = 0;
- return IMG_CODEC_NONE;
+ for (i = (int)strlen(file_path); i >= 0; i--) {
+ if ((file_path[i] == '.') && (i < (int)strlen(file_path))) {
+ strncpy(file_ext, &file_path[i + 1], max_len);
+ return 0;
}
- unsigned short block_length = img_buf[4] * 256 + img_buf[5];
- thumb_dbg("block length : %d", block_length);
- int i = 4;
+ /* meet the dir. no ext */
+ if (file_path[i] == '/') {
+ return -1;
+ }
+ }
- while (i < fileSize) {
- i += block_length;
- if (i >= fileSize) {
- thumb_warn
- ("Failed to get w / h from jpeg at index [%d]",
- i);
- break;
- }
+ return -1;
+}
- if (img_buf[i] != 0xFF) {
- thumb_warn
- ("Failed to get w / h from jpeg at index [%d]",
- i);
- break;
- }
+int ImgGetImageInfo(const char *filePath, ImgCodecType *type, unsigned int *width, unsigned int *height)
+{
+ HFile hFile;
+ FmFileAttribute fileAttrib;
+ char file_ext[10] = {0,};
+ int err, ret = 0;
- if (img_buf[i + 1] == 0xC0) {
- *pWidth = img_buf[i + 5] * 256 + img_buf[i + 6];
- *pHeight =
- img_buf[i + 7] * 256 + img_buf[i + 8];
- break;
- } else {
- i += 2;
- block_length =
- img_buf[i] * 256 + img_buf[i + 1];
- thumb_dbg("new block length : %d",
- block_length);
- }
- }
- thumb_dbg("Jpeg w: %d, h: %d", *pWidth, *pHeight);
-
- if (img_buf)
- free(img_buf);
-
-#if defined(_PERFORMANCE_CHECK_) && defined(_USE_LOG_FILE_)
- end = mediainfo_get_debug_time();
- double get_size =
- ((double)(end - start) / (double)CLOCKS_PER_SEC);
- thumb_dbg("get_size from jpeg header : %f", get_size);
- mediainfo_init_file_debug();
- mediainfo_file_dbg("get_size from jpeg header : %f", get_size);
- mediainfo_close_file_debug();
-#endif
+ SysAssert(filePath);
+ hFile = DrmOpenFile(filePath);
+
+ if (hFile == (HFile) INVALID_HOBJ) {
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
-#endif /* End of Get w / h from jpeg header */
+ DrmGetFileAttributes(filePath, &fileAttrib);
- thumb_dbg("IMG_CODEC_JPEG");
- return IMG_CODEC_JPEG;
+ if ((fileAttrib.fileSize == 0)) {
+ DrmCloseFile(hFile);
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ err = _ImgGetFileExt(filePath, file_ext, sizeof(file_ext));
+ if (err < 0) {
+ thumb_warn("_media_thumb_get_file_ext failed");
}
- return IMG_CODEC_UNKNOWN_TYPE;
+
+ ret = _ImgGetImageInfo(hFile, fileAttrib.fileSize, file_ext, type, width, height, FALSE);
+
+ DrmSeekFile(hFile, SEEK_SET, 0);
+
+ DrmCloseFile(hFile);
+
+ return ret;
+
+}
+
+int ImgGetImageInfoForThumb(const char *filePath, ImgCodecType *type, unsigned int *width, unsigned int *height)
+{
+ HFile hFile;
+ FmFileAttribute fileAttrib;
+ char file_ext[10] = {0,};
+ int err, ret = 0;
+
+ SysAssert(filePath);
+ hFile = DrmOpenFile(filePath);
+
+ if (hFile == (HFile) INVALID_HOBJ) {
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ DrmGetFileAttributes(filePath, &fileAttrib);
+
+ if ((fileAttrib.fileSize == 0)) {
+ DrmCloseFile(hFile);
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+
+ err = _ImgGetFileExt(filePath, file_ext, sizeof(file_ext));
+ if (err < 0) {
+ thumb_warn("_media_thumb_get_file_ext failed");
+ };
+
+ ret = _ImgGetImageInfo(hFile, fileAttrib.fileSize, file_ext, type, width, height, TRUE);
+
+ DrmSeekFile(hFile, SEEK_SET, 0);
+
+ DrmCloseFile(hFile);
+
+ return ret;
+
}
diff --git a/src/codec/img-codec.c b/src/codec/img-codec.c
index fadd8c2..a27495c 100644..100755
--- a/src/codec/img-codec.c
+++ b/src/codec/img-codec.c
@@ -25,7 +25,7 @@
#include <mm_util_imgp.h>
unsigned int *ImgGetFirstFrameAGIFAtSize(const char *szFileName,
- ImgImageInfo *image_info)
+ unsigned int width, unsigned int height)
{
AGifFrameInfo *pFrameInfo = 0;
void *pDecodedRGB888Buf = 0;
@@ -37,15 +37,15 @@ unsigned int *ImgGetFirstFrameAGIFAtSize(const char *szFileName,
return NULL;
}
- if (image_info == NULL) {
+ if (width == 0 || height == 0) {
thumb_err
- ("ImgGetFirstFrameAGIFAtSize: Input ImgImageInfo is NULL");
+ ("ImgGetFirstFrameAGIFAtSize: Input width or height is zero");
return NULL;
}
pFrameInfo =
- ImgCreateAGIFFrame(szFileName, image_info->width,
- image_info->height, 0, FALSE);
+ ImgCreateAGIFFrame(szFileName, width,
+ height, 0, FALSE);
if (pFrameInfo && pFrameInfo->pOutBits) {
ImgGetNextAGIFFrame(pFrameInfo, TRUE);
@@ -61,13 +61,17 @@ unsigned int *ImgGetFirstFrameAGIFAtSize(const char *szFileName,
unsigned int i = 0;
- if (mm_util_get_image_size(MM_UTIL_IMG_FMT_RGB888, image_info->width, image_info->height, &i) < 0) {
+ if (mm_util_get_image_size(MM_UTIL_IMG_FMT_RGB888, width, height, &i) < 0) {
thumb_err("ImgGetFirstFrameAGIFAtSize: Failed to get buffer size");
return NULL;
}
thumb_dbg("ImgGetFirstFrameAGIFAtSize: raw data size : %d)", i);
raw_data = (unsigned char *)malloc(i);
+ if (raw_data == NULL) {
+ thumb_err("ImgGetFirstFrameAGIFAtSize: Failed to allocate memory");
+ return NULL;
+ }
memset(raw_data, 0, i);
unsigned char *dest = raw_data;
while (i--) {
@@ -162,8 +166,6 @@ AGifFrameInfo *ImgCreateAGIFFrame(const char *szFileName, unsigned int width,
return FALSE;
}
- SysRequireEx(szFileName != NULL, FALSE);
-
hFile = DrmOpenFile(szFileName);
if (hFile == (HFile) INVALID_HOBJ) {
thumb_err("ImgCreateAGIFFrame: Cannot open file");
@@ -180,13 +182,14 @@ AGifFrameInfo *ImgCreateAGIFFrame(const char *szFileName, unsigned int width,
cFileSize = fileAttrib.fileSize;
/* A size of allocated memory - w * h *2 means RGB565 and 4096 means the max of header length */
- mem_alloc_size = width * height * 2 + MAX_GIF_HEADER_SIZE;
-
+// mem_alloc_size = width * height * 2 + MAX_GIF_HEADER_SIZE;
+ mem_alloc_size = cFileSize;
if ((pEncodedData = (unsigned char *)malloc(mem_alloc_size)) == NULL) {
thumb_err("Memory Allocation to pEncodedData failed");
DrmCloseFile(hFile);
return NULL;
}
+ memset(pEncodedData,0,mem_alloc_size);
/* coverity[ -tainted_data_argument : pEncodedData ] */
if (DrmReadFile(hFile, pEncodedData, mem_alloc_size, &size) == FALSE) {
thumb_err("DrmReadFile was failed");
diff --git a/src/include/codec/AGifFrameInfo.h b/src/include/codec/AGifFrameInfo.h
index 0f5aa81..e9c69b8 100644..100755
--- a/src/include/codec/AGifFrameInfo.h
+++ b/src/include/codec/AGifFrameInfo.h
@@ -55,8 +55,8 @@ typedef struct tagFrameInfo
unsigned short delay;
#ifdef INTERNAL_IMGCODEC
- unsigned int nRepeatCount;
- unsigned int nLoopCount;
+ int nRepeatCount;
+ int nLoopCount;
unsigned char bOneFrame;
#endif
diff --git a/src/include/codec/img-codec-common.h b/src/include/codec/img-codec-common.h
index 4cb8922..91887f5 100644..100755
--- a/src/include/codec/img-codec-common.h
+++ b/src/include/codec/img-codec-common.h
@@ -37,19 +37,20 @@ extern "C" {
#define IMG_MAX_IMAGE_FILE_SIZE (10 * 1024 * 1024)
//////////////////////////////////////////////////////////////
+#if 0
#define ImgDebug(type, fmt, arg...) \
do { \
fprintf(stderr, "[Media-SVC]"fmt, ##arg); \
}while(0)
-
-#if 1
+
+
#define SysRequireEx(expr, retValue) \
if (!(expr)) { \
fprintf(stderr, "[Media-SVC][%s] INVALID_PARAM (%d lines in %s)\n",__FUNCTION__, __LINE__, __FILE__); \
return (retValue); \
}
-#define SysDebug(X) ImgDebug X
-
+#define SysDebug(X) ImgDebug X
+
#define SysAssert(expr)
#else
#define SysRequireEx(expr, retValue)
@@ -73,24 +74,6 @@ typedef enum
IMG_INFO_MEM_ALLOC_FAIL = -6
}ImgFastCodecInfo;
-
-
-typedef enum
-{
- IMG_CODEC_UNKNOWN_TYPE = -2,
- IMG_CODEC_BIG_PROGRESSIVE_JPEG = -1,
- IMG_CODEC_NONE = 0,
- IMG_CODEC_GIF = ( 1 << 0),
- IMG_CODEC_PNG = ( 1 << 1),
- IMG_CODEC_WBMP = ( 1 << 2),
- IMG_CODEC_JPEG = ( 1 << 3),
- IMG_CODEC_BMP = ( 1 << 4),
- IMG_CODEC_TIF = ( 1 << 5),
- IMG_CODEC_AGIF = ( 1 << 6),
- IMG_CODEC_PROGRESSIVE_JPEG = ( 1 << 7),
- IMG_CODEC_DRM = ( 1 << 8),
-} ImgCodecType;
-
typedef enum inputFlag
{
IMG_RGB_888_OUTPUT = 0x0001,
diff --git a/src/include/codec/img-codec-parser.h b/src/include/codec/img-codec-parser.h
index 097f24d..b412416 100644..100755
--- a/src/include/codec/img-codec-parser.h
+++ b/src/include/codec/img-codec-parser.h
@@ -30,15 +30,32 @@ extern "C" {
#define PNG_HEADER_LENGTH 8
#define JPG_HEADER_LENGTH 2
-#define GIF_HEADER_LENGTH 3
+#define GIF_HEADER_LENGTH 3
#define TIFF_HEADER_LENGTH 2
#define BMP_HEADER_LENGTH 2
+#define WBMP_HEADER_LENGTH 2
#define TIFF_IMAGE_WIDTH 0x100
#define TIFF_IMAGE_HEIGHT 0x101
-ImgCodecType ImgGetInfo(unsigned char* pEncodedData, unsigned long fileSize, ImgImageInfo* imgInfo);
-ImgCodecType ImgGetInfoFile(const char*filePath, ImgImageInfo *imgInfo);
-ImgCodecType ImgGetInfoHFile(HFile hFile, unsigned long fileSize, ImgImageInfo* imgInfo);
+typedef enum
+{
+ IMG_CODEC_UNKNOWN_TYPE = -2,
+ IMG_CODEC_BIG_PROGRESSIVE_JPEG = -1,
+ IMG_CODEC_NONE = 0,
+ IMG_CODEC_GIF = ( 1 << 0),
+ IMG_CODEC_PNG = ( 1 << 1),
+ IMG_CODEC_WBMP = ( 1 << 2),
+ IMG_CODEC_JPEG = ( 1 << 3),
+ IMG_CODEC_BMP = ( 1 << 4),
+ IMG_CODEC_TIF = ( 1 << 5),
+ IMG_CODEC_AGIF = ( 1 << 6),
+ IMG_CODEC_PROGRESSIVE_JPEG = ( 1 << 7),
+ IMG_CODEC_DRM = ( 1 << 8),
+} ImgCodecType;
+
+//ImgCodecType ImgGetInfoFile(const char*filePath, ImgImageInfo *imgInfo);
+int ImgGetImageInfo(const char *filePath, ImgCodecType *type, unsigned int *width, unsigned int *height);
+int ImgGetImageInfoForThumb(const char *filePath, ImgCodecType *type, unsigned int *width, unsigned int *height);
#ifdef __cplusplus
}
diff --git a/src/include/codec/img-codec.h b/src/include/codec/img-codec.h
index 708c5ce..d365705 100644..100755
--- a/src/include/codec/img-codec.h
+++ b/src/include/codec/img-codec.h
@@ -30,7 +30,7 @@
extern "C" {
#endif /* __cplusplus */
-unsigned int* ImgGetFirstFrameAGIFAtSize(const char *szFileName, ImgImageInfo *image_info);
+unsigned int* ImgGetFirstFrameAGIFAtSize(const char *szFileName, unsigned int width, unsigned int height);
int ImgConvertRGB565ToRGB888(void *pBuf_rgb565, void **pBuf_rgb888, int width, int height);
diff --git a/src/include/ipc/media-thumb-ipc.h b/src/include/ipc/media-thumb-ipc.h
index fcd4560..7251ed9 100755
--- a/src/include/ipc/media-thumb-ipc.h
+++ b/src/include/ipc/media-thumb-ipc.h
@@ -30,8 +30,6 @@
#include <signal.h>
#include <sys/types.h>
-#include "media-thumb-debug.h"
-#include "media-thumb-types.h"
#include "media-thumb-internal.h"
#include "media-util-ipc.h"
#include "media-server-ipc.h"
@@ -72,7 +70,6 @@ int _media_thumb_set_buffer_for_response(thumbMsg *req_msg, unsigned char **buf,
int _media_thumb_set_add_raw_data_buffer(thumbRawAddMsg *req_msg, unsigned char **buf, int *buf_size);
int _media_thumb_request(int msg_type,
- media_thumb_type thumb_type,
const char *origin_path,
char *thumb_path,
int max_length,
@@ -80,7 +77,6 @@ int _media_thumb_request(int msg_type,
uid_t uid);
int _media_thumb_request_async(int msg_type,
- media_thumb_type thumb_type,
const char *origin_path,
thumbUserData *userData,
uid_t uid);
diff --git a/src/include/media-thumb-internal.h b/src/include/media-thumb-internal.h
index ad50b04..b059658 100755
--- a/src/include/media-thumb-internal.h
+++ b/src/include/media-thumb-internal.h
@@ -23,8 +23,6 @@
#include <media-util-err.h>
#include "media-thumbnail.h"
#include "media-thumb-util.h"
-#include "media-thumb-types.h"
-#include "media-thumb-debug.h"
#ifndef _MEDIA_THUMB_INTERNAL_H_
#define _MEDIA_THUMB_INTERNAL_H_
@@ -44,8 +42,9 @@ typedef struct {
int height;
int origin_width;
int origin_height;
- gboolean alpha;
+ int alpha;
unsigned char *data;
+ bool is_saved;
} media_thumb_info;
enum Exif_Orientation {
@@ -71,21 +70,21 @@ typedef struct {
} thumbRawUserData;
int _media_thumb_image(const char *origin_path,
+ const char *thumb_path,
int thumb_width,
int thumb_height,
media_thumb_format format,
media_thumb_info *thumb_info,
- bool is_raw,
- uid_t uid);
+ bool is_req_raw);
int _media_thumb_video(const char *origin_path,
int thumb_width,
int thumb_height,
media_thumb_format format,
- media_thumb_info *thumb_info,
- uid_t uid);
+ 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_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,
diff --git a/src/include/util/media-thumb-db.h b/src/include/util/media-thumb-db.h
index fcd284f..23ac277 100755
--- a/src/include/util/media-thumb-db.h
+++ b/src/include/util/media-thumb-db.h
@@ -21,8 +21,6 @@
#include <sqlite3.h>
#include <media-util.h>
-#include "media-thumb-types.h"
-#include "media-thumb-debug.h"
#ifndef _MEDIA_THUMB_DB_H_
#define _MEDIA_THUMB_DB_H_
diff --git a/src/include/util/media-thumb-util.h b/src/include/util/media-thumb-util.h
index 3bb71df..de6d9f6 100755
--- a/src/include/util/media-thumb-util.h
+++ b/src/include/util/media-thumb-util.h
@@ -19,8 +19,6 @@
*
*/
-#include "media-thumb-types.h"
-#include "media-thumb-debug.h"
#include "media-util.h"
#include <tzplatform_config.h>
@@ -28,6 +26,13 @@
#define _MEDIA_THUMB_UTIL_H_
#define SAFE_FREE(src) { if(src) {free(src); src = NULL;}}
+#define THUMB_MALLOC(src, size) { if (size <= 0) {src = NULL;} \
+ else { src = malloc(size); if(src) memset(src, 0x0, size);} }
+
+typedef enum {
+ MEDIA_THUMB_BGRA, /* BGRA, especially provided for evas users */
+ MEDIA_THUMB_RGB888, /* RGB888 */
+} media_thumb_format;
#define THUMB_NONE_TYPE -1 /* None */
#define THUMB_IMAGE_TYPE 0 /* Image */
@@ -47,23 +52,17 @@ typedef enum
THUMB_MMC /**< Stored only in MMC */
} media_thumb_store_type;
-int _media_thumb_get_length(media_thumb_type thumb_type);
-
int _media_thumb_get_store_type_by_path(const char *full_path);
int _media_thumb_get_file_ext(const char *file_path, char *file_ext, int max_len);
int _media_thumb_get_file_type(const char *file_full_path);
-int _media_thumb_remove_file(const char *path);
-
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_get_width(media_thumb_type thumb_type);
-
-int _media_thumb_get_height(media_thumb_type thumb_type);
+int _media_thumb_remove_file(const char *path);
#endif /*_MEDIA_THUMB_UTIL_H_*/
diff --git a/src/ipc/media-thumb-ipc.c b/src/ipc/media-thumb-ipc.c
index 7a94900..7920fe7 100755
--- a/src/ipc/media-thumb-ipc.c
+++ b/src/ipc/media-thumb-ipc.c
@@ -379,7 +379,7 @@ _media_thumb_set_add_raw_data_buffer(thumbRawAddMsg *req_msg, unsigned char **bu
}
int
-_media_thumb_request(int msg_type, media_thumb_type thumb_type, const char *origin_path, char *thumb_path, int max_length, media_thumb_info *thumb_info, uid_t uid)
+_media_thumb_request(int msg_type, const char *origin_path, char *thumb_path, int max_length, media_thumb_info *thumb_info, uid_t uid)
{
int sock = -1;
struct sockaddr_un serv_addr;
@@ -419,7 +419,6 @@ _media_thumb_request(int msg_type, media_thumb_type thumb_type, const char *orig
/* Set requset message */
req_msg.msg_type = msg_type;
- req_msg.thumb_type = thumb_type;
req_msg.uid = uid;
strncpy(req_msg.org_path, origin_path, sizeof(req_msg.org_path));
req_msg.org_path[strlen(req_msg.org_path)] = '\0';
@@ -585,7 +584,7 @@ gboolean _media_thumb_raw_data_write_socket(GIOChannel *src, GIOCondition condit
return FALSE;
}
-int _media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const char *origin_path, thumbUserData *userData, uid_t uid)
+int _media_thumb_request_async(int msg_type, const char *origin_path, thumbUserData *userData, uid_t uid)
{
int err = MS_MEDIA_ERR_NONE;
int sock = -1;
@@ -623,8 +622,6 @@ int _media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const
}
if (msg_type != THUMB_REQUEST_CANCEL_MEDIA) {
- //source_id = g_io_add_watch(channel, G_IO_IN, _media_thumb_write_socket, userData );
-
/* Create new channel to watch udp socket */
GSource *source = NULL;
source = g_io_create_watch(channel, G_IO_IN);
@@ -640,7 +637,6 @@ int _media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const
pid = getpid();
req_msg.pid = pid;
req_msg.msg_type = msg_type;
- req_msg.thumb_type = thumb_type;
req_msg.uid = uid;
strncpy(req_msg.org_path, origin_path, sizeof(req_msg.org_path));
@@ -677,8 +673,6 @@ int _media_thumb_request_async(int msg_type, media_thumb_type thumb_type, const
if (msg_type == THUMB_REQUEST_CANCEL_MEDIA) {
g_io_channel_shutdown(channel, TRUE, NULL);
-
- //thumb_dbg("Cancel : %s[%d]", origin_path, sock);
__media_thumb_pop_req_queue(origin_path, TRUE);
} else if (msg_type == THUMB_REQUEST_DB_INSERT) {
if (g_request_queue == NULL) {
@@ -753,7 +747,6 @@ int _media_thumb_request_raw_data_async(int msg_type, int request_id, const char
pid = getpid();
req_msg.pid = pid;
req_msg.msg_type = msg_type;
- req_msg.thumb_type = MEDIA_THUMB_LARGE;
req_msg.request_id = request_id;
req_msg.thumb_width = width;
req_msg.thumb_height = height;
diff --git a/src/media-thumb-internal.c b/src/media-thumb-internal.c
index 5ed752d..04c92c4 100755
--- a/src/media-thumb-internal.c
+++ b/src/media-thumb-internal.c
@@ -52,12 +52,17 @@
#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,
+int _media_thumb_resize_data(unsigned char *src_data,
+ int src_width,
+ int src_height,
+ mm_util_img_format src_format,
+ media_thumb_info *thumb_info,
+ int dst_width,
+ int dst_height);
+
+int _media_thumb_get_proper_thumb_size(int orig_w, int orig_h,
int *thumb_w, int *thumb_h)
{
- thumb_dbg("orig w: %d orig h: %d thumb type: %d", orig_w, orig_h, thumb_type);
-
BOOL portrait = FALSE;
double ratio;
@@ -67,23 +72,13 @@ int _media_thumb_get_proper_thumb_size(media_thumb_type thumb_type,
/* Set smaller length to default size */
if (portrait) {
- if (orig_w < _media_thumb_get_width(thumb_type)) {
+ if (orig_w < *thumb_w)
*thumb_w = orig_w;
- } else {
- *thumb_w = _media_thumb_get_width(thumb_type);
- }
-
ratio = (double)orig_h / (double)orig_w;
*thumb_h = *thumb_w * ratio;
-
} else {
-
- if (orig_h < _media_thumb_get_width(thumb_type)) {
+ if (orig_h < *thumb_h)
*thumb_h = orig_h;
- } else {
- *thumb_h = _media_thumb_get_width(thumb_type);
- }
-
ratio = (double)orig_w / (double)orig_h;
*thumb_w = *thumb_h * ratio;
}
@@ -138,27 +133,18 @@ int _media_thumb_get_exif_info(ExifData *ed, char *buf, int max_size, int *value
return MS_MEDIA_ERR_NONE;
}
-int _media_thumb_get_thumb_from_exif(ExifData *ed,
- const char *file_full_path,
- int orientation,
- int required_width,
- int required_height,
- media_thumb_info *thumb_info, uid_t uid)
+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;
- int err = -1;
- int size = 0;
- int thumb_width = 0;
- int thumb_height = 0;
- void *thumb = NULL;
-
- if (ed == NULL) {
- return -1;
- }
-
ExifByteOrder byte_order = exif_data_get_byte_order(ed);
ifd = EXIF_IFD_1;
@@ -182,241 +168,239 @@ int _media_thumb_get_thumb_from_exif(ExifData *ed,
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
+ /* copy the real thumbnail data from exif data */
+ if (ed->data && ed->size) {
+ //thumb_dbg("Size: %d, thumb: 0x%x", ed->size, ed->data);
+ *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 */
- ExifShort value = exif_get_short(entry->data, byte_order);
- //thumb_dbg("%s: %d\n", exif_tag_get_name_in_ifd(tag,ifd), value);
+ char width[10] = {0,};
+ exif_entry_get_value(entry,width,10);
- thumb_width = value;
+ *thumb_width = atoi(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 */
- ExifShort value = exif_get_short(entry->data, byte_order);
- //thumb_dbg("%s: %d\n", exif_tag_get_name_in_ifd(tag,ifd), value);
-
- thumb_height = value;
- }
+ char height[10] = {0,};
+ exif_entry_get_value(entry,height,10);
- if (ed->data && ed->size) {
- //thumb_dbg("Size: %d, thumb: 0x%x\n", ed->size, ed->data);
- thumb = (char *)malloc(ed->size);
-
- if (thumb == NULL) {
- thumb_dbg("malloc failed!");
- return -1;
- }
-
- memcpy(thumb, (void *)ed->data, ed->size);
- size = ed->size;
+ *thumb_height = atoi(height);
} else {
- thumb_dbg("data is NULL");
- return -1;
+ 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) {
- ExifShort value = exif_get_short(entry->data, byte_order);
- //thumb_dbg("%s: %d\n", exif_tag_get_name_in_ifd(tag,ifd), value);
- thumb_info->origin_width = value;
+ char width[10] = {0,};
+ exif_entry_get_value(entry,width,10);
+
+ *origin_width = atoi(width);
} else {
- thumb_dbg("entry is NULL");
+ 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) {
- ExifShort value = exif_get_short(entry->data, byte_order);
- //thumb_dbg("%s: %d\n", exif_tag_get_name_in_ifd(tag,ifd), value);
- thumb_info->origin_height = value;
- } else {
- thumb_dbg("entry is NULL");
- }
-
- char thumb_path[1024];
+ char height[10] = {0,};
+ exif_entry_get_value(entry,height,10);
- err =
- _media_thumb_get_hash_name(file_full_path,
- thumb_path,
- sizeof(thumb_path), uid);
- if (err < 0) {
- thumb_dbg("_media_thumb_get_hash_name failed\n");
- SAFE_FREE(thumb);
- return err;
- }
-
- thumb_dbg("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_dbg("thumb alread exist!");
- } else {
- thumb_dbg("open failed\n");
- SAFE_FREE(thumb);
- return -1;
- }
+ *origin_height = atoi(height);
} else {
- nwrite = write(fd, thumb, size);
- if (nwrite < 0) {
- thumb_dbg("write failed\n");
- close(fd);
-
- SAFE_FREE(thumb);
- return -1;
- }
- close(fd);
+ thumb_warn("EXIF_TAG_PIXEL_Y_DIMENSION does not exist");
+ *origin_height = 0;
}
- SAFE_FREE(thumb);
+ 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 err = MS_MEDIA_ERR_NONE;
+ int size = 0;
+ int thumb_width = 0;
+ int thumb_height = 0;
+ 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;
mm_util_jpeg_yuv_data decoded = {0,};
- err = mm_util_decode_from_jpeg_file(&decoded, thumb_path, MM_UTIL_JPEG_FMT_RGB888);
- if (err < 0) {
- thumb_dbg("mm_util_decode_from_jpeg_turbo_memory failed : %d", err);
- return err;
+ if (ed == NULL) {
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
}
- //thumb_dbg("size:%d, w:%d, h:%d\n", decoded.size, decoded.width, decoded.height);
-
- thumb_width = decoded.width;
- thumb_height = decoded.height;
-
- media_thumb_type thumb_type;
- int need_resize = 0;
- unsigned int buf_size = decoded.size;
-
- if (required_width == _media_thumb_get_width(MEDIA_THUMB_LARGE)) {
- thumb_type = MEDIA_THUMB_LARGE;
- } else {
- thumb_type = MEDIA_THUMB_SMALL;
- }
+ err = _media_thumb_get_data_from_exif(ed,
+ &thumb,
+ &size,
+ &thumb_width,
+ &thumb_height,
+ &origin_width,
+ &origin_height);
- if (thumb_type == MEDIA_THUMB_LARGE) {
- if (thumb_width < _media_thumb_get_width(MEDIA_THUMB_LARGE)) {
- thumb_dbg("Thumb data in exif is too small for MEDIA_THUMB_LARGE");
- SAFE_FREE(decoded.data);
- return -1;
- }
- } else {
- if (thumb_width > _media_thumb_get_width(MEDIA_THUMB_SMALL)) {
- need_resize = 1;
- }
+ if (err != MS_MEDIA_ERR_NONE) {
+ thumb_err("There is no exif data");
+ return err;
}
- if (need_resize == 1) {
- int resized_w = _media_thumb_get_width(MEDIA_THUMB_LARGE);
- int resized_h = _media_thumb_get_height(MEDIA_THUMB_LARGE);
+ 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;
- err = mm_util_get_image_size(MM_UTIL_IMG_FMT_RGB888, resized_w, resized_h, &buf_size);
- if (err < 0) {
- thumb_dbg("mm_util_get_image_size failed : %d", err);
+ if (thumb_width < required_width) {
+ thumb_err("Thumb data in exif is too small");
+ SAFE_FREE(thumb);
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
- SAFE_FREE(decoded.data);
+ if (is_rotated) {
+ err = mm_util_decode_from_jpeg_memory(&decoded, thumb, size, MM_UTIL_JPEG_FMT_RGB888);
+ SAFE_FREE(thumb);
+ if (err != MS_MEDIA_ERR_NONE) {
+ thumb_err("mm_util_decode_from_jpeg_turbo_memory failed : %d", err);
return err;
}
- //thumb_dbg("size(RGB888) : %d", buf_size);
-
- unsigned char *dst = (unsigned char *)malloc(buf_size);
- if (dst == NULL) {
- thumb_err("Failed to allocate memory!");
- SAFE_FREE(decoded.data);
- return -1;
- }
+ thumb_width = decoded.width;
+ thumb_height = decoded.height;
- if (mm_util_resize_image(decoded.data, thumb_width,
- thumb_height, MM_UTIL_IMG_FMT_RGB888,
- dst, (unsigned int *)&resized_w,
- (unsigned int *)&resized_h) < 0) {
- thumb_err("Failed to resize the thumbnails");
+ if (is_rotated) {
+ /* Start to decode to rotate */
+ unsigned char *rotated = NULL;
+ unsigned int r_w = decoded.height;
+ unsigned int r_h = decoded.width;
+ unsigned int r_size = 0;
+ mm_util_img_rotate_type rot_type = MM_UTIL_ROTATE_0;
- SAFE_FREE(decoded.data);
- SAFE_FREE(dst);
+ int i, rotate_cnt = 0;
- return -1;
- }
+ rot_type = MM_UTIL_ROTATE_90;
+ if (orientation == ROT_90) {
+ rotate_cnt = 1;
+ } else if (orientation == ROT_180) {
+ rotate_cnt = 2;
+ } else if (orientation == ROT_270) {
+ rotate_cnt = 3;
+ }
- SAFE_FREE(decoded.data);
- decoded.data = dst;
- decoded.width = thumb_width = resized_w;
- decoded.height = thumb_height = resized_h;
- }
+ for (i = 0; i < rotate_cnt; i++) {
+ if (i == 1) {
+ r_w = decoded.width;
+ r_h = decoded.height;
+ }
- if (orientation == ROT_90 || orientation == ROT_180 || orientation == ROT_270) {
- /* Start to decode to rotate */
- unsigned char *rotated = NULL;
- unsigned int r_w = decoded.height;
- unsigned int r_h = decoded.width;
- unsigned int r_size = 0;
- mm_util_img_rotate_type rot_type = MM_UTIL_ROTATE_0;
+ err = mm_util_get_image_size(MM_UTIL_IMG_FMT_RGB888, r_w, r_h, &r_size);
+ if (err != MS_MEDIA_ERR_NONE) {
+ thumb_err("mm_util_get_image_size failed : %d", err);
+ SAFE_FREE(decoded.data);
+ return err;
+ }
- if (orientation == ROT_90) {
- rot_type = MM_UTIL_ROTATE_90;
- } else if (orientation == ROT_180) {
- rot_type = MM_UTIL_ROTATE_180;
- r_w = decoded.width;
- r_h = decoded.height;
- } else if (orientation == ROT_270) {
- rot_type = MM_UTIL_ROTATE_270;
- }
+ rotated = (unsigned char *)malloc(r_size);
+ err = mm_util_rotate_image(decoded.data, decoded.width, decoded.height,
+ MM_UTIL_IMG_FMT_RGB888,
+ rotated, &r_w, &r_h,
+ rot_type);
- err = mm_util_get_image_size(MM_UTIL_IMG_FMT_RGB888, r_w, r_h, &r_size);
- if (err < 0) {
- thumb_dbg("mm_util_get_image_size failed : %d", err);
- SAFE_FREE(decoded.data);
- return err;
- }
+ if (err != MS_MEDIA_ERR_NONE) {
+ thumb_err("mm_util_rotate_image failed : %d", err);
+ SAFE_FREE(decoded.data);
+ SAFE_FREE(rotated);
+ return err;
+ } else {
+ thumb_err("mm_util_rotate_image succeed");
+ }
- //thumb_dbg("Size of Rotated : %d", r_size);
+ SAFE_FREE(decoded.data);
+ decoded.data = rotated;
+ decoded.width = r_w;
+ decoded.height = r_h;
+ }
- rotated = (unsigned char *)malloc(r_size);
- err = mm_util_rotate_image(decoded.data, decoded.width, decoded.height,
- MM_UTIL_IMG_FMT_RGB888,
- rotated, &r_w, &r_h,
- rot_type);
-
- if (err < 0) {
- thumb_err("mm_util_rotate_image failed : %d", err);
- SAFE_FREE(decoded.data);
- SAFE_FREE(rotated);
- return err;
+ //thumb_dbg("Width : %d, Height : %d", r_w, r_h);
+ thumb_info->data = rotated;
+ thumb_info->size = r_size;
+ thumb_info->width = r_w;
+ thumb_info->height = r_h;
} else {
- thumb_dbg("mm_util_rotate_image succeed");
+ thumb_warn("Unknown orientation");
+ SAFE_FREE(decoded.data);
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
}
+ }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(decoded.data);
+ SAFE_FREE(thumb);
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+ close(fd);
+ }
- //thumb_dbg("Width : %d, Height : %d", r_w, r_h);
- thumb_info->data = rotated;
- thumb_info->size = r_size;
- thumb_info->width = r_w;
- thumb_info->height = r_h;
- } else if (orientation == NORMAL) {
- thumb_info->data = decoded.data;
- thumb_info->size = buf_size;
+ SAFE_FREE(thumb);
+ thumb_info->data = NULL;
+ thumb_info->size = size;
thumb_info->width = thumb_width;
thumb_info->height = thumb_height;
- } else {
- thumb_warn("Unknown orientation");
- SAFE_FREE(decoded.data);
- return -1;
+ thumb_info->is_saved = TRUE;
}
- return 0;
+ return err;
}
int _media_thumb_resize_data(unsigned char *src_data,
@@ -455,8 +439,12 @@ int _media_thumb_resize_data(unsigned char *src_data,
thumb_info->width = thumb_width;
thumb_info->height = thumb_height;
thumb_info->data = malloc(buf_size);
- memcpy(thumb_info->data, dst, buf_size);
-
+ if(thumb_info->data != NULL) {
+ memcpy(thumb_info->data, dst, buf_size);
+ } else {
+ thumb_err("malloc fails");
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
SAFE_FREE(dst);
return MS_MEDIA_ERR_NONE;
@@ -553,17 +541,8 @@ int _media_thumb_decode_with_evas(const char *origin_path,
//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;
-
- if (thumb_width == _media_thumb_get_width(MEDIA_THUMB_LARGE)) {
- thumb_type = MEDIA_THUMB_LARGE;
- } else {
- thumb_type = MEDIA_THUMB_SMALL;
- }
- err = _media_thumb_get_proper_thumb_size(thumb_type,
- rotated_orig_w, rotated_orig_h,
- &thumb_width, &thumb_height);
+ 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);
@@ -755,7 +734,8 @@ int _media_thumb_convert_format(media_thumb_info *thumb_info,
}
int _media_thumb_agif(const char *origin_path,
- ImgImageInfo *image_info,
+ int image_width,
+ int image_height,
int thumb_width,
int thumb_height,
media_thumb_format format,
@@ -763,24 +743,15 @@ int _media_thumb_agif(const char *origin_path,
{
int err = MS_MEDIA_ERR_NONE;
unsigned int *thumb = NULL;
- media_thumb_type thumb_type;
- thumb = ImgGetFirstFrameAGIFAtSize(origin_path, image_info);
+ thumb = ImgGetFirstFrameAGIFAtSize(origin_path, image_width, image_height);
if (!thumb) {
thumb_err("Frame data is NULL!!");
return MS_MEDIA_ERR_INTERNAL;
}
- if (thumb_width == _media_thumb_get_width(MEDIA_THUMB_LARGE)) {
- thumb_type = MEDIA_THUMB_LARGE;
- } else {
- thumb_type = MEDIA_THUMB_SMALL;
- }
-
- err = _media_thumb_get_proper_thumb_size(thumb_type,
- thumb_info->origin_width, thumb_info->origin_height,
- &thumb_width, &thumb_height);
+ 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);
@@ -788,8 +759,8 @@ int _media_thumb_agif(const char *origin_path,
}
err = _media_thumb_resize_data((unsigned char *)thumb,
- image_info->width,
- image_info->height,
+ image_width,
+ image_height,
MM_UTIL_IMG_FMT_RGB888,
thumb_info,
thumb_width,
@@ -910,11 +881,11 @@ int _media_thumb_gif(const char *origin_path,
}
int _media_thumb_jpeg(const char *origin_path,
+ const char *thumb_path,
int thumb_width,
int thumb_height,
media_thumb_format format,
- media_thumb_info *thumb_info,
- uid_t uid)
+ media_thumb_info *thumb_info)
{
int err = MS_MEDIA_ERR_NONE;
ExifData *ed = NULL;
@@ -933,7 +904,7 @@ int _media_thumb_jpeg(const char *origin_path,
}
/* Second, Get thumb from exif */
- err = _media_thumb_get_thumb_from_exif(ed, origin_path, orientation, thumb_width, thumb_height, thumb_info, uid);
+ 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");
@@ -941,18 +912,31 @@ int _media_thumb_jpeg(const char *origin_path,
thumb_done = 1;
thumb_dbg("_media_thumb_get_thumb_from_exif succeed");
- mm_util_img_format dst_format = _media_thumb_get_format(format);
+ /* 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) {
+ mm_util_img_format dst_format = _media_thumb_get_format(format);
- err = _media_thumb_convert_data(thumb_info,
- thumb_info->width,
- thumb_info->height,
- MM_UTIL_IMG_FMT_RGB888,
- dst_format);
+ err = _media_thumb_convert_data(thumb_info,
+ thumb_info->width,
+ thumb_info->height,
+ MM_UTIL_IMG_FMT_RGB888,
+ dst_format);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_convert_data failed : %d", err);
- exif_data_unref(ed);
- return err;
+ if (err != MS_MEDIA_ERR_NONE) {
+ thumb_err("_media_thumb_convert_data failed : %d", err);
+ exif_data_unref(ed);
+ return err;
+ }
}
}
@@ -980,11 +964,11 @@ int _media_thumb_jpeg(const char *origin_path,
}
int _media_thumb_jpeg_for_raw(const char *origin_path,
+ const char *thumb_path,
int thumb_width,
int thumb_height,
media_thumb_format format,
- media_thumb_info *thumb_info,
- uid_t uid)
+ media_thumb_info *thumb_info)
{
int err = MS_MEDIA_ERR_NONE;
int orientation = NORMAL;
@@ -1006,23 +990,26 @@ int _media_thumb_jpeg_for_raw(const char *origin_path,
}
int _media_thumb_image(const char *origin_path,
+ const char *thumb_path,
int thumb_width,
int thumb_height,
media_thumb_format format,
media_thumb_info *thumb_info,
- bool is_raw,
- uid_t uid)
+ bool is_req_raw)
{
int err = MS_MEDIA_ERR_NONE;
- int image_type = 0;
- int origin_w = 0;
- int origin_h = 0;
- ImgImageInfo image_info = { 0 };
+ ImgCodecType image_type = 0;
+ unsigned int origin_w = 0;
+ unsigned int origin_h = 0;
- image_type = ImgGetInfoFile(origin_path, &image_info);
+ err = ImgGetImageInfoForThumb(origin_path, &image_type, &origin_w, &origin_h);
+
+ if (err != MS_MEDIA_ERR_NONE){
+ thumb_warn("Getting image info is failed err: %d", err);
+ }
- thumb_info->origin_width = origin_w = image_info.width;
- thumb_info->origin_height = origin_h = image_info.height;
+ thumb_info->origin_width = origin_w;
+ thumb_info->origin_height = origin_h;
//thumb_dbg("image type is %d, width:%d, height:%d", image_type, origin_w, origin_h);
@@ -1033,12 +1020,12 @@ int _media_thumb_image(const char *origin_path,
}
if (image_type == IMG_CODEC_AGIF) {
- err = _media_thumb_agif(origin_path, &image_info, thumb_width, thumb_height, format, thumb_info);
+ err = _media_thumb_agif(origin_path, origin_w, origin_h, thumb_width, thumb_height, format, thumb_info);
} else if (image_type == IMG_CODEC_JPEG) {
- if(is_raw) {
- err = _media_thumb_jpeg_for_raw(origin_path, thumb_width, thumb_height, format, thumb_info, uid);
+ if(is_req_raw == TRUE) {
+ err = _media_thumb_jpeg_for_raw(origin_path, thumb_path, thumb_width, thumb_height, format, thumb_info);
} else {
- err = _media_thumb_jpeg(origin_path, thumb_width, thumb_height, format, thumb_info, uid);
+ err = _media_thumb_jpeg(origin_path, thumb_path, thumb_width, thumb_height, format, thumb_info);
}
} else if (image_type == IMG_CODEC_PNG) {
err = _media_thumb_png(origin_path, thumb_width, thumb_height, format, thumb_info);
@@ -1088,8 +1075,7 @@ int _media_thumb_video(const char *origin_path,
int thumb_width,
int thumb_height,
media_thumb_format format,
- media_thumb_info *thumb_info,
- uid_t uid)
+ media_thumb_info *thumb_info)
{
int err = MS_MEDIA_ERR_NONE;
@@ -1104,7 +1090,59 @@ int _media_thumb_video(const char *origin_path,
bool drm_type = FALSE;
is_drm = drm_type;
- err = mm_file_create_content_attrs(&content, origin_path);
+
+ /* Get Content Tag attribute for orientatin */
+ MMHandleType tag = (MMHandleType) NULL;
+ char *p = NULL;
+ int cdis_value = 0;
+ err = mm_file_create_tag_attrs(&tag, origin_path);
+ mm_util_img_rotate_type rot_type = MM_UTIL_ROTATE_0;
+
+ if (err == MM_ERROR_NONE) {
+ err = mm_file_get_attrs(tag, &err_msg, MM_FILE_TAG_ROTATE, &p, &size, NULL);
+ if (err == MM_ERROR_NONE && size >= 0) {
+ if (p == NULL) {
+ rot_type = MM_UTIL_ROTATE_0;
+ } else {
+ if (strncmp(p, "90", size) == 0) {
+ rot_type = MM_UTIL_ROTATE_90;
+ } else if(strncmp(p, "180", size) == 0) {
+ rot_type = MM_UTIL_ROTATE_180;
+ } else if(strncmp(p, "270", size) == 0) {
+ rot_type = MM_UTIL_ROTATE_270;
+ } else {
+ 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 = MM_UTIL_ROTATE_0;
+ SAFE_FREE(err_msg);
+ }
+
+ err = mm_file_get_attrs(tag, &err_msg, MM_FILE_TAG_CDIS, &cdis_value, NULL);
+ if (err != MM_ERROR_NONE) {
+ cdis_value = 0;
+ SAFE_FREE(err_msg);
+ }
+
+ } else {
+ rot_type = MM_UTIL_ROTATE_0;
+ cdis_value = 0;
+ }
+
+ err = mm_file_destroy_tag_attrs(tag);
+ if (err != MM_ERROR_NONE) {
+ thumb_err("fail to free tag attr - err(%x)", err);
+ }
+
+ if (cdis_value == 1) {
+ thumb_warn("This is CDIS vlaue 1");
+ err = mm_file_create_content_attrs_safe(&content, origin_path);
+ } else {
+ err = mm_file_create_content_attrs(&content, origin_path);
+ }
if (err != MM_ERROR_NONE) {
thumb_err("mm_file_create_content_attrs fails : %d", err);
@@ -1148,17 +1186,10 @@ int _media_thumb_video(const char *origin_path,
return MS_MEDIA_ERR_INTERNAL;
}
- media_thumb_type thumb_type;
- if (thumb_width == _media_thumb_get_width(MEDIA_THUMB_LARGE)) {
- thumb_type = MEDIA_THUMB_LARGE;
- } else {
- thumb_type = MEDIA_THUMB_SMALL;
- }
-
thumb_info->origin_width = width;
thumb_info->origin_height = height;
- err = _media_thumb_get_proper_thumb_size(thumb_type, width, height, &thumb_width, &thumb_height);
+ err = _media_thumb_get_proper_thumb_size(width, height, &thumb_width, &thumb_height);
if (width > thumb_width || height > thumb_height) {
err = _media_thumb_resize_data(frame,
@@ -1180,48 +1211,15 @@ int _media_thumb_video(const char *origin_path,
thumb_info->width = width;
thumb_info->height = height;
thumb_info->data = malloc(size);
+ if (thumb_info->data == NULL) {
+ thumb_err("memory allcation failed" );
+ mm_file_destroy_content_attrs(content);
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
memcpy(thumb_info->data, frame, size);
}
mm_file_destroy_content_attrs(content);
-
- /* Get Content Tag attribute for orientatin */
- MMHandleType tag = (MMHandleType) NULL;
- char *p = NULL;
- int size = -1;
- err = mm_file_create_tag_attrs(&tag, origin_path);
- mm_util_img_rotate_type rot_type = MM_UTIL_ROTATE_0;
-
- if (err == MM_ERROR_NONE) {
- err = mm_file_get_attrs(tag, &err_msg, MM_FILE_TAG_ROTATE, &p, &size, NULL);
- if (err == MM_ERROR_NONE && size >= 0) {
-
- if (p == NULL) {
- rot_type = MM_UTIL_ROTATE_0;
- } else {
- if (strncmp(p, "90", size) == 0) {
- rot_type = MM_UTIL_ROTATE_90;
- } else if(strncmp(p, "180", size) == 0) {
- rot_type = MM_UTIL_ROTATE_180;
- } else if(strncmp(p, "270", size) == 0) {
- rot_type = MM_UTIL_ROTATE_270;
- } else {
- rot_type = MM_UTIL_ROTATE_0;
- }
- }
- } else {
- rot_type = MM_UTIL_ROTATE_0;
- SAFE_FREE(err_msg);
- }
- } else {
- rot_type = MM_UTIL_ROTATE_0;
- }
-
- err = mm_file_destroy_tag_attrs(tag);
- if (err != MM_ERROR_NONE) {
- thumb_err("fail to free tag attr - err(%x)", err);
- }
-
if (rot_type == MM_UTIL_ROTATE_90 || rot_type == MM_UTIL_ROTATE_180 || rot_type == MM_UTIL_ROTATE_270) {
/* Start to decode to rotate */
unsigned char *rotated = NULL;
@@ -1281,24 +1279,6 @@ 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;
@@ -1333,8 +1313,6 @@ static char* _media_thumb_mmc_get_path(uid_t uid)
}
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;
}
@@ -1374,56 +1352,58 @@ static char* _media_thumb_phone_get_path(uid_t uid)
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 *hash_name = NULL;
+ /*char *thumb_dir = NULL;*/
char file_ext[255] = { 0 };
+ int ret_len = 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;
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
}
_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) {
+ /*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);
+ if(hash_name == NULL)
+ {
+ thumb_err("_media_thumb_generate_hash_name fail");
+ return MS_MEDIA_ERR_INTERNAL;
+ }
- 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;
+ if (store_type == THUMB_PHONE) {
+ ret_len = snprintf(thumb_hash_path, max_thumb_path - 1, "%s/.%s-%s.jpg", _media_thumb_phone_get_path(uid), file_ext, hash_name);
+ } else if (store_type == THUMB_MMC) {
+ ret_len = snprintf(thumb_hash_path, max_thumb_path - 1, "%s/.%s-%s.jpg", _media_thumb_mmc_get_path(uid), file_ext, hash_name);
+ } else {
+ ret_len = snprintf(thumb_hash_path, max_thumb_path - 1, "%s/.%s-%s.jpg", _media_thumb_phone_get_path(uid), file_ext, hash_name);
}
+ if ((ret_len < 0) || (ret_len > (int)max_thumb_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 0;
+ return MS_MEDIA_ERR_NONE;
}
@@ -1474,4 +1454,4 @@ int _media_thumb_save_to_file_with_evas(unsigned char *data,
ecore_evas_free(ee);
return MS_MEDIA_ERR_INTERNAL;
}
-} \ No newline at end of file
+}
diff --git a/src/media-thumbnail.c b/src/media-thumbnail.c
index 39d2ebf..e5f6c2b 100755
--- a/src/media-thumbnail.c
+++ b/src/media-thumbnail.c
@@ -24,77 +24,9 @@
#include "media-thumb-util.h"
#include "media-thumb-internal.h"
#include "media-thumb-ipc.h"
-//#include "media-thumb-db.h"
#include <glib.h>
-int thumbnail_request_from_db(const char *origin_path, char *thumb_path, int max_length, uid_t uid)
-{
- int err = MS_MEDIA_ERR_NONE;
- //int need_update_db = 0;
- media_thumb_info thumb_info;
-
- if (origin_path == NULL || thumb_path == NULL) {
- thumb_err("Invalid parameter");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- if (!g_file_test
- (origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
- thumb_err("Original path(%s) doesn't exist.", origin_path);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- if (max_length <= 0) {
- thumb_err("Length is invalid");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- int store_type = -1;
- store_type = _media_thumb_get_store_type_by_path(origin_path);
-
- if ((store_type != THUMB_PHONE) && (store_type != THUMB_MMC)) {
- thumb_err("origin path(%s) is invalid", origin_path);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- thumb_dbg_slog("Path : %s", origin_path);
-
- /* Request for thumb file to the daemon "Thumbnail generator" */
- err = _media_thumb_request(THUMB_REQUEST_DB_INSERT, MEDIA_THUMB_LARGE, origin_path, thumb_path, max_length, &thumb_info, uid);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_request failed : %d", err);
- return err;
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int thumbnail_request_save_to_file(const char *origin_path, media_thumb_type thumb_type, const char *thumb_path, uid_t uid)
-{
- int err = MS_MEDIA_ERR_NONE;
-
- if (origin_path == NULL || thumb_path == NULL) {
- thumb_err("Invalid parameter");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- media_thumb_info thumb_info;
- char tmp_thumb_path[MAX_PATH_SIZE + 1] = {0,};
-
- strncpy(tmp_thumb_path, thumb_path, sizeof(tmp_thumb_path));
- tmp_thumb_path[sizeof(tmp_thumb_path) - 1] = '\0';
-
- /* Request for thumb file to the daemon "Thumbnail generator" */
- err = _media_thumb_request(THUMB_REQUEST_SAVE_FILE, thumb_type, origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info, uid);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_request failed : %d", err);
- return err;
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
int thumbnail_request_from_db_with_size(const char *origin_path, char *thumb_path, int max_length, int *origin_width, int *origin_height, uid_t uid)
{
int err = MS_MEDIA_ERR_NONE;
@@ -133,7 +65,7 @@ int thumbnail_request_from_db_with_size(const char *origin_path, char *thumb_pat
thumb_dbg_slog("Path : %s", origin_path);
/* Request for thumb file to the daemon "Thumbnail generator" */
- err = _media_thumb_request(THUMB_REQUEST_DB_INSERT, MEDIA_THUMB_LARGE, origin_path, thumb_path, max_length, &thumb_info, uid);
+ err = _media_thumb_request(THUMB_REQUEST_DB_INSERT, origin_path, thumb_path, max_length, &thumb_info, uid);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_request failed : %d", err);
return err;
@@ -150,12 +82,11 @@ int thumbnail_request_extract_all_thumbs(uid_t uid)
int err = MS_MEDIA_ERR_NONE;
media_thumb_info thumb_info;
- media_thumb_type thumb_type = MEDIA_THUMB_LARGE;
char tmp_origin_path[MAX_PATH_SIZE] = {0,};
char tmp_thumb_path[MAX_PATH_SIZE] = {0,};
/* Request for thumb file to the daemon "Thumbnail generator" */
- err = _media_thumb_request(THUMB_REQUEST_ALL_MEDIA, thumb_type, tmp_origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info, uid);
+ err = _media_thumb_request(THUMB_REQUEST_ALL_MEDIA, tmp_origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info, uid);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_request failed : %d", err);
return err;
@@ -194,7 +125,7 @@ int thumbnail_request_from_db_async(const char *origin_path, ThumbFunc func, voi
userData->user_data = user_data;
/* Request for thumb file to the daemon "Thumbnail generator" */
- err = _media_thumb_request_async(THUMB_REQUEST_DB_INSERT, MEDIA_THUMB_LARGE, origin_path, userData, uid);
+ err = _media_thumb_request_async(THUMB_REQUEST_DB_INSERT, origin_path, userData, uid);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_request failed : %d", err);
SAFE_FREE(userData);
@@ -246,14 +177,12 @@ int thumbnail_request_cancel_media(const char *origin_path, uid_t uid)
{
int err = MS_MEDIA_ERR_NONE;
- media_thumb_type thumb_type = MEDIA_THUMB_LARGE;
-
if (origin_path == NULL) {
thumb_err("Invalid parameter");
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
- err = _media_thumb_request_async(THUMB_REQUEST_CANCEL_MEDIA, thumb_type, origin_path, NULL, uid);
+ err = _media_thumb_request_async(THUMB_REQUEST_CANCEL_MEDIA, origin_path, NULL, uid);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_request failed : %d", err);
return err;
@@ -291,9 +220,9 @@ int thumbnail_request_cancel_all(bool is_raw_data, uid_t uid)
/* Request for thumb file to the daemon "Thumbnail generator" */
if(is_raw_data) {
- err = _media_thumb_request(THUMB_REQUEST_CANCEL_ALL_RAW_DATA, MEDIA_THUMB_LARGE, tmp_origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info, uid);
+ err = _media_thumb_request(THUMB_REQUEST_CANCEL_ALL_RAW_DATA, tmp_origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info, uid);
} else {
- err = _media_thumb_request(THUMB_REQUEST_CANCEL_ALL, MEDIA_THUMB_LARGE, tmp_origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info, uid);
+ err = _media_thumb_request(THUMB_REQUEST_CANCEL_ALL, tmp_origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info, uid);
}
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_request failed : %d", err);
diff --git a/src/util/media-thumb-db.c b/src/util/media-thumb-db.c
index 76c737e..0dceec7 100755
--- a/src/util/media-thumb-db.c
+++ b/src/util/media-thumb-db.c
@@ -257,6 +257,10 @@ int _media_thumb_update_thumb_path_to_db(sqlite3 *handle,
thumb_dbg("Query success");
}
+ sqlite3_free(path_string);
+ sqlite3_free(thumbpath_string);
+ sqlite3_free(query_string);
+
return err;
}
@@ -285,6 +289,9 @@ int _media_thumb_update_wh_to_db(sqlite3 *handle,
thumb_dbg("Query success");
}
+ sqlite3_free(path_string);
+ sqlite3_free(query_string);
+
return err;
}
@@ -314,6 +321,9 @@ int _media_thumb_update_thumb_path_wh_to_db(sqlite3 *handle,
thumb_dbg("Query success");
}
+ sqlite3_free(path_string);
+ sqlite3_free(query_string);
+
return err;
}
diff --git a/src/util/media-thumb-debug.c b/src/util/media-thumb-debug.c
index a9ce049..9515505 100755
--- a/src/util/media-thumb-debug.c
+++ b/src/util/media-thumb-debug.c
@@ -27,7 +27,7 @@
#ifdef _PERFORMANCE_CHECK_
static long g_time_usec = 0L;
-#endif
+
#ifdef _USE_LOG_FILE_
static FILE *g_log_fp = NULL;
@@ -109,3 +109,4 @@ thumb_print_debug_time_ex(long start, long end, const char *func_name,
totaltime);
#endif
}
+#endif \ No newline at end of file
diff --git a/src/util/media-thumb-util.c b/src/util/media-thumb-util.c
index 3ba1c06..c487b6e 100755
--- a/src/util/media-thumb-util.c
+++ b/src/util/media-thumb-util.c
@@ -27,52 +27,12 @@
#include <aul.h>
#include <string.h>
-int _media_thumb_get_width(media_thumb_type thumb_type)
-{
- if (thumb_type == MEDIA_THUMB_LARGE) {
- return THUMB_LARGE_WIDTH;
- } else if (thumb_type == MEDIA_THUMB_SMALL) {
- return THUMB_SMALL_WIDTH;
- } else {
- return -1;
- }
-}
-
-int _media_thumb_get_height(media_thumb_type thumb_type)
-{
- if (thumb_type == MEDIA_THUMB_LARGE) {
- return THUMB_LARGE_HEIGHT;
- } else if (thumb_type == MEDIA_THUMB_SMALL) {
- return THUMB_SMALL_HEIGHT;
- } else {
- return -1;
- }
-}
-
-int _media_thumb_get_file_ext(const char *file_path, char *file_ext, int max_len)
-{
- int i = 0;
-
- for (i = strlen(file_path); i >= 0; i--) {
- if ((file_path[i] == '.') && (i < strlen(file_path))) {
- strncpy(file_ext, &file_path[i + 1], max_len);
- return 0;
- }
-
- /* meet the dir. no ext */
- if (file_path[i] == '/') {
- return -1;
- }
- }
-
- return -1;
-}
-
int
_media_thumb_get_file_type(const char *file_full_path)
{
int ret = 0;
char mimetype[255] = {0,};
+ const char *unsupported_type = "image/tiff";
if (file_full_path == NULL)
return MS_MEDIA_ERR_INVALID_PARAMETER;
@@ -116,6 +76,10 @@ _media_thumb_get_file_type(const char *file_full_path)
/* categorize from mimetype */
if (strstr(mimetype, "image") != NULL) {
+ if (!strcmp(mimetype, unsupported_type)) {
+ thumb_warn("This is unsupport file type");
+ return THUMB_NONE_TYPE;
+ }
return THUMB_IMAGE_TYPE;
} else if (strstr(mimetype, "video") != NULL) {
return THUMB_VIDEO_TYPE;
@@ -149,4 +113,23 @@ int _media_thumb_remove_file(const char *path)
thumb_stderror("fail to remove file[%s] result");
return FALSE;
}
+}
+
+int _media_thumb_get_file_ext(const char *file_path, char *file_ext, int max_len)
+{
+ int i = 0;
+
+ for (i = (int)strlen(file_path); i >= 0; i--) {
+ if ((file_path[i] == '.') && (i < (int)strlen(file_path))) {
+ strncpy(file_ext, &file_path[i + 1], max_len);
+ return 0;
+ }
+
+ /* meet the dir. no ext */
+ if (file_path[i] == '/') {
+ return -1;
+ }
+ }
+
+ return -1;
} \ No newline at end of file
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644
index 0000000..93480e5
--- /dev/null
+++ b/test/CMakeLists.txt
@@ -0,0 +1,13 @@
+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 mmutil-imgp mmutil-jpeg libmedia-utils vconf libtzplatform-config)
+
+FOREACH(flag ${pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -fPIE")
+
+ADD_EXECUTABLE(test-thumb ${TEST-THUMB})
+TARGET_LINK_LIBRARIES(test-thumb ${pkgs_LDFLAGS} ${MEDIATHUMB-LIB} )
diff --git a/test/test-thumb.c b/test/test-thumb.c
index 5c390e9..92919cd 100755
--- a/test/test-thumb.c
+++ b/test/test-thumb.c
@@ -23,9 +23,10 @@
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
+#include <Evas.h>
+#include <Ecore_Evas.h>
#include <mm_util_imgp.h>
#include <mm_util_jpeg.h>
-#include <stdbool.h>
#include "media-thumbnail.h"
#include "thumb-server-internal.h"
@@ -33,16 +34,75 @@
#include "media-thumb-ipc.h"
#include "media-thumb-util.h"
-int save_to_file_with_gdk(unsigned char *data, int w, int h, int is_bgra)
+int save_to_file_with_evas(unsigned char *data, int w, int h, int is_bgra)
{
- GError *error = NULL;
-
- gdk_pixbuf_save(data,"/mnt/nfs/test.jpg","jpeg", &error, NULL);
- if (error) {
- thumb_dbg ("Error saving image file /mnt/nfs/test.jpg ");
- g_error_free (error);
+ ecore_evas_init();
+
+ Ecore_Evas *ee =
+ ecore_evas_buffer_new(w, h);
+ Evas *evas = ecore_evas_get(ee);
+
+ Evas_Object *img = NULL;
+ img = evas_object_image_add(evas);
+
+ if (img == NULL) {
+ printf("image object is NULL\n");
+ ecore_evas_free(ee);
+ ecore_evas_shutdown();
return -1;
}
+
+ 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 (!is_bgra) {
+ unsigned char *m = NULL;
+ m = evas_object_image_data_get(img, 1);
+#if 1 /* Use self-logic to convert from RGB888 to RGBA */
+ int i = 0, j;
+ for (j = 0; j < w * 3 * h;
+ j += 3) {
+ m[i++] = (data[j + 2]);
+ m[i++] = (data[j + 1]);
+ m[i++] = (data[j]);
+ m[i++] = 0x0;
+ }
+
+#else /* Use mmf api to convert from RGB888 to RGBA */
+ int mm_ret = 0;
+ if ((mm_ret =
+ mm_util_convert_colorspace(data,
+ w,
+ h,
+ MM_UTIL_IMG_FMT_RGB888,
+ m,
+ MM_UTIL_IMG_FMT_BGRA8888))
+ < 0) {
+ printf
+ ("Failed to change from rgb888 to argb8888 %d\n",
+ mm_ret);
+ return -1;
+ }
+#endif /* End of use mmf api to convert from RGB888 to RGBA */
+
+ evas_object_image_data_set(img, m);
+ evas_object_image_data_update_add(img, 0, 0, w, h);
+ } else {
+ evas_object_image_data_set(img, data);
+ evas_object_image_data_update_add(img, 0, 0, w, h);
+ }
+
+ if (evas_object_image_save
+ (img, "/mnt/nfs/test.jpg", NULL,
+ "quality=50 compress=2")) {
+ printf("evas_object_image_save success\n");
+ } else {
+ printf("evas_object_image_save failed\n");
+ }
+
+ ecore_evas_shutdown();
+
return 0;
}
@@ -63,79 +123,48 @@ int main(int argc, char *argv[])
if (origin_path && (mode == 1)) {
printf("Test _thumbnail_get_data\n");
#if 0
- GdkPixbuf *data = NULL;
+ unsigned char *data = NULL;
int thumb_size = 0;
int thumb_w = 0;
int thumb_h = 0;
int origin_w = 0;
int origin_h = 0;
int alpha = FALSE;
+ bool is_saved = FALSE;
+ char *thumb_path = "thumbnail_path.jpg";
- media_thumb_type thumb_type = MEDIA_THUMB_LARGE;
- //media_thumb_type thumb_type = MEDIA_THUMB_SMALL;
- //media_thumb_format thumb_format = MEDIA_THUMB_BGRA;
- media_thumb_format thumb_format = MEDIA_THUMB_RGB888;
+ media_thumb_format thumb_format = MEDIA_THUMB_BGRA;
+ //media_thumb_format thumb_format = MEDIA_THUMB_RGB888;
int is_bgra = 1;
//int is_bgra = 0;
- long start = thumb_get_debug_time();
+ //long start = thumb_get_debug_time();
- err = _thumbnail_get_data(origin_path, thumb_type, thumb_format, &data, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h, &alpha, tzplatform_getuid(TZ_USER_NAME));
+ err = _thumbnail_get_data(origin_path, thumb_format, thumb_path, &data, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h, &alpha, &is_saved);
if (err < 0) {
printf("_thumbnail_get_data failed - %d\n", err);
return -1;
}
-
- printf("Size : %d, W:%d, H:%d\n", thumb_size, thumb_w, thumb_h);
+
+ printf("Size : %d, W:%d, H:%d\n", thumb_size, thumb_w, thumb_h);
printf("Origin W:%d, Origin H:%d\n", origin_w, origin_h);
- err = save_to_file_with_gdk(data, thumb_w, thumb_h, is_bgra);
- if (err < 0) {
- printf("_thumbnail_get_data failed - %d\n", err);
- return -1;
- } else {
- printf("file save success\n");
+ if (is_saved == FALSE) {
+ err = save_to_file_with_evas(data, thumb_w, thumb_h, is_bgra);
+ if (err < 0) {
+ printf("save_to_file_with_evas failed - %d\n", err);
+ return -1;
+ } else {
+ printf("file save success\n");
+ }
}
SAFE_FREE(data);
- long end = thumb_get_debug_time();
- printf("Time : %f\n", ((double)(end - start) / (double)CLOCKS_PER_SEC));
+ //long end = thumb_get_debug_time();
+ //printf("Time : %f\n", ((double)(end - start) / (double)CLOCKS_PER_SEC));
#endif
- } else if (mode == 2) {
- printf("Test thumbnail_request_from_db\n");
- //const char *origin_path = "/opt/media/test/movie1.mp4";
- //const char *origin_path = "/opt/media/test/high.jpg";
- //const char *origin_path = "/opt/media/test/movie2.avi";
- char thumb_path[MAX_PATH_SIZE + 1];
-
- err = thumbnail_request_from_db(origin_path, thumb_path, sizeof(thumb_path), tzplatform_getuid(TZ_USER_NAME));
- if (err < 0) {
- printf("thumbnail_request_from_db failed : %d\n", err);
- return -1;
- }
-
- printf("Success!! (%s)\n", thumb_path);
- } else if (mode == 3) {
- printf("Test thumbnail_request_save_to_file\n");
- const char *thumb_path = NULL;
-
- if (argv[3]) {
- thumb_path = argv[3];
- } else {
- printf("3 mode requires target path of thumbnail\n");
- return -1;
- }
-
- err = thumbnail_request_save_to_file(origin_path, MEDIA_THUMB_LARGE, thumb_path, tzplatform_getuid(TZ_USER_NAME));
- if (err < 0) {
- printf("thumbnail_request_save_to_file failed : %d\n", err);
- return -1;
- }
-
- printf("Success!!\n");
} else if (origin_path && mode == 4) {
- printf("Test thumbnail_generate_hash_code\n");
printf("Success!!\n");
} else if (mode == 5) {
printf("Test thumbnail_request_extract_all_thumbs\n");