Skip to content

Commit

Permalink
[mms-lib] Implemented libjpeg-based scaling
Browse files Browse the repository at this point in the history
Now ImageMagick is only used for scaling non-JPEG images.
  • Loading branch information
monich committed Mar 2, 2014
1 parent e4e1f4d commit 88a1cb1
Show file tree
Hide file tree
Showing 20 changed files with 997 additions and 81 deletions.
15 changes: 1 addition & 14 deletions .gitignore
@@ -1,27 +1,14 @@
*~
build
mms-engine/mms-engine.pro.user
mms-engine/build
mms-lib/mms-lib.pro.user
mms-lib/build
mms-lib/test/coverage/full.gcov
mms-lib/test/coverage/mms-lib.gcov
mms-lib/test/coverage/results
mms-lib/test/media_type/build
mms-lib/test/mms_codec/build
mms-lib/test/mms_lib_test.ncb
mms-lib/test/mms_lib_test.opt
mms-lib/test/read_report/build
mms-lib/test/retrieve/build
mms-lib/test/retrieve_cancel/build
mms-lib/test/retrieve_no_proxy/build
mms-ofono/mms-ofono.pro.user
mms-ofono/build
mms-handler-dbus/mms-handler-dbus.pro.user
mms-handler-dbus/build
mms-handler-dbus/test/mms_handler_dbus_server/build
mms-handler-dbus/test/mms_handler_dbus_server/test_mms_handler_dbus_server.pro.user
mms-handler-dbus/test/mms_handler_dbus_client/build
mms-dump/build
mms-dump/mms_dump.ncb
mms-dump/mms_dump.opt
mms-send/build
2 changes: 1 addition & 1 deletion mms-engine/Makefile
Expand Up @@ -90,7 +90,7 @@ endif
DEBUG_CFLAGS = $(DEBUG_FLAGS) $(DEBUG_DEFS) $(CFLAGS)
RELEASE_CFLAGS = $(RELEASE_FLAGS) $(RELEASE_DEFS) $(CFLAGS)

LIBS = $(shell pkg-config --libs $(LIB_PKGS)) -lmagic
LIBS = $(shell pkg-config --libs $(LIB_PKGS)) -lmagic -ljpeg
DEBUG_LIBS = \
$(MMS_OFONO_DEBUG_LIB) \
$(MMS_HANDLER_DEBUG_LIB) \
Expand Down
20 changes: 18 additions & 2 deletions mms-engine/main.c
Expand Up @@ -150,6 +150,7 @@ mms_app_parse_options(
GError* error = NULL;
gboolean session_bus = FALSE;
gint size_limit_kb = opt->config.size_limit/1024;
gdouble megapixels = opt->config.max_pixels / 1000000.0;
char* root_dir_help = g_strdup_printf(
"Root directory for MMS files [%s]",
opt->config.root_dir);
Expand All @@ -162,6 +163,9 @@ mms_app_parse_options(
char* size_limit_help = g_strdup_printf(
"Maximum size for outgoing messages [%d]",
size_limit_kb);
char* megapixels_help = g_strdup_printf(
"Maximum pixel count for outgoing images [%.1f]",
megapixels);
char* description = mms_log_description(mms_app_log_modules,
G_N_ELEMENTS(mms_app_log_modules));

Expand All @@ -177,6 +181,8 @@ mms_app_parse_options(
&opt->config.idle_secs, idle_secs_help, "SEC" },
{ "size-limit", 's', 0, G_OPTION_ARG_INT,
&size_limit_kb, size_limit_help, "KB" },
{ "pix-limit", 'p', 0, G_OPTION_ARG_DOUBLE,
&megapixels, megapixels_help, "MPIX" },
{ "keep-running", 'k', 0, G_OPTION_ARG_NONE, &opt->keep_running,
"Keep running after everything is done", NULL },
{ "keep-temp-files", 't', 0, G_OPTION_ARG_NONE,
Expand All @@ -189,7 +195,7 @@ mms_app_parse_options(
mms_app_option_verbose, "Be verbose (equivalent to -l=verbose)",
NULL },
{ "log-output", 'o', 0, G_OPTION_ARG_CALLBACK, mms_app_option_logtype,
"Log output [stdout]", "<stdout|syslog|glib>" },
"Log output (stdout|syslog|glib) [stdout]", "TYPE" },
{ "log-level", 'l', 0, G_OPTION_ARG_CALLBACK, mms_app_option_loglevel,
"Set log level (repeatable)", "[MODULE:]LEVEL" },
{ NULL }
Expand All @@ -204,11 +210,21 @@ mms_app_parse_options(
g_free(retry_secs_help);
g_free(idle_secs_help);
g_free(size_limit_help);
g_free(megapixels_help);
g_free(description);

if (ok && size_limit_kb >= 0) {
if (ok) {
MMS_INFO("Starting");
if (size_limit_kb >= 0) {
opt->config.size_limit = size_limit_kb * 1024;
} else {
opt->config.size_limit = 0;
}
if (megapixels >= 0) {
opt->config.max_pixels = (int)(megapixels*1000)*1000;
} else {
opt->config.max_pixels = 0;
}
if (opt->dir) opt->config.root_dir = opt->dir;
if (session_bus) {
MMS_DEBUG("Attaching to session bus");
Expand Down
2 changes: 1 addition & 1 deletion mms-engine/mms-engine.pro
Expand Up @@ -35,7 +35,7 @@ CONFIG(debug, debug|release) {
LIBS += $$MMS_LIB_DIR/build/release/libmms-lib.a
}

LIBS += -lmagic
LIBS += -lmagic -ljpeg

MMS_ENGINE_DBUS_XML = $$DBUS_INTERFACE_DIR/org.nemomobile.MmsEngine.xml
MMS_ENGINE_DBUS_H = org.nemomobile.MmsEngine.h
Expand Down
13 changes: 7 additions & 6 deletions mms-lib/Makefile
Expand Up @@ -15,12 +15,13 @@ all: debug release
# Sources
#

SRC = mms_attachment.c mms_attachment_image.c mms_codec.c mms_connection.c \
mms_connman.c mms_dispatcher.c mms_error.c mms_handler.c mms_lib_util.c \
mms_file_util.c mms_log.c mms_message.c mms_task.c mms_task_ack.c \
mms_task_decode.c mms_task_encode.c mms_task_http.c mms_task_notification.c \
mms_task_notifyresp.c mms_task_publish.c mms_task_read.c \
mms_task_retrieve.c mms_task_send.c mms_util.c
SRC = mms_attachment.c mms_attachment_image.c mms_attachment_jpeg.c \
mms_codec.c mms_connection.c mms_connman.c mms_dispatcher.c mms_error.c \
mms_handler.c mms_lib_util.c mms_file_util.c mms_log.c mms_message.c \
mms_task.c mms_task_ack.c mms_task_decode.c mms_task_encode.c \
mms_task_http.c mms_task_notification.c mms_task_notifyresp.c \
mms_task_publish.c mms_task_read.c mms_task_retrieve.c mms_task_send.c \
mms_util.c

#
# Directories
Expand Down
1 change: 1 addition & 0 deletions mms-lib/include/mms_lib_types.h
Expand Up @@ -50,6 +50,7 @@ typedef struct mms_config {
int retry_secs; /* Retry timeout in seconds */
int idle_secs; /* Idle timeout */
gsize size_limit; /* Maximum size of m-Send.req PDU */
guint max_pixels; /* Pixel limit for outbound images */
gboolean keep_temp_files; /* Keep temporary files around */
gboolean attic_enabled; /* Keep unrecognized push message in attic */
gboolean send_dr; /* Allow sending delivery reports */
Expand Down
2 changes: 2 additions & 0 deletions mms-lib/mms-lib.pro
Expand Up @@ -19,6 +19,7 @@ CONFIG(debug, debug|release) {
SOURCES += \
src/mms_attachment.c \
src/mms_attachment_image.c \
src/mms_attachment_jpeg.c \
src/mms_codec.c \
src/mms_connection.c \
src/mms_connman.c \
Expand All @@ -44,6 +45,7 @@ SOURCES += \

HEADERS += \
src/mms_attachment.h \
src/mms_attachment_image.h \
src/mms_codec.h \
src/mms_error.h \
src/mms_file_util.h \
Expand Down
19 changes: 14 additions & 5 deletions mms-lib/src/mms_attachment.c
Expand Up @@ -50,9 +50,10 @@ mms_attachment_finalize(
GObject* object)
{
MMSAttachment* at = MMS_ATTACHMENT(object);
MMS_VERBOSE_("%p", at);
g_mapped_file_unref(at->map);
if (!at->config->keep_temp_files &&
!(at->flags & MMS_ATTACHMENT_DONT_DELETE_FILES)) {
!(at->flags & MMS_ATTACHMENT_KEEP_FILES)) {
char* dir = g_path_get_dirname(at->original_file);
remove(at->original_file);
rmdir(dir);
Expand All @@ -76,9 +77,9 @@ mms_attachment_class_init(
static
void
mms_attachment_init(
MMSAttachment* attachment)
MMSAttachment* at)
{
MMS_VERBOSE_("%p", attachment);
MMS_VERBOSE_("%p", at);
}

static
Expand Down Expand Up @@ -210,6 +211,7 @@ mms_attachment_new(
if (map) {
unsigned int flags = 0;
char* content_type = NULL;
GType type;
MMSAttachment* at;

if (info->content_type) {
Expand Down Expand Up @@ -274,9 +276,16 @@ mms_attachment_new(
}

MMS_DEBUG("%s: %s", path, content_type);
at = g_object_new(g_str_has_prefix(content_type, "image/") ?
MMS_TYPE_ATTACHMENT_IMAGE : MMS_TYPE_ATTACHMENT, NULL);

if (!strcmp(content_type, "image/jpeg")) {
type = MMS_TYPE_ATTACHMENT_JPEG;
} else if (g_str_has_prefix(content_type, "image/")) {
type = MMS_TYPE_ATTACHMENT_IMAGE;
} else {
type = MMS_TYPE_ATTACHMENT;
}

at = g_object_new(type, NULL);
at->config = config;
at->map = map;
at->flags |= flags;
Expand Down
6 changes: 3 additions & 3 deletions mms-lib/src/mms_attachment.h
Expand Up @@ -30,7 +30,7 @@ struct _mms_attachment {
unsigned int flags; /* Flags: */

#define MMS_ATTACHMENT_SMIL (0x01)
#define MMS_ATTACHMENT_DONT_DELETE_FILES (0x02)
#define MMS_ATTACHMENT_KEEP_FILES (0x02)
#define MMS_ATTACHMENT_RESIZABLE (0x04)

};
Expand All @@ -43,10 +43,10 @@ typedef struct mms_attachment_class {

GType mms_attachment_get_type(void);
GType mms_attachment_image_get_type(void);
GType mms_attachment_jpeg_get_type(void);
#define MMS_TYPE_ATTACHMENT (mms_attachment_get_type())
#define MMS_TYPE_ATTACHMENT_IMAGE (mms_attachment_image_get_type())
#define MMS_ATTACHMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \
MMS_TYPE_ATTACHMENT, MMSAttachmentClass))
#define MMS_TYPE_ATTACHMENT_JPEG (mms_attachment_jpeg_get_type())

MMSAttachment*
mms_attachment_new(
Expand Down

0 comments on commit 88a1cb1

Please sign in to comment.