Remove mmlog & fix bugs for image transform 28/48628/2 accepted/tizen/mobile/20150925.012805 accepted/tizen/tv/20150925.012816 accepted/tizen/wearable/20150925.012823 submit/tizen/20150924.075606 submit/tizen_common/20151015.190624 submit/tizen_common/20151019.135620
authorJi Yong Min <jiyong.min@samsung.com>
Thu, 24 Sep 2015 03:43:39 +0000 (12:43 +0900)
committerJi Yong Min <jiyong.min@samsung.com>
Thu, 24 Sep 2015 06:12:57 +0000 (15:12 +0900)
Change-Id: I0c1735cc48492d0b424a9b95cb3b419946023aca
Signed-off-by: Jiyong Min <jiyong.min@samsung.com>
Makefile.am [changed mode: 0644->0755]
configure.ac
imgp/Makefile.am
imgp/include/mm_util_debug.h [new file with mode: 0755]
imgp/include/mm_util_imgp_internal.h
imgp/mm_util_imgp.c
imgp/test/mm_util_imgp_testsuite.c
jpeg/mm_util_jpeg.c
jpeg/test/mm_util_jpeg_testsuite.c
packaging/libmm-utility.spec

old mode 100644 (file)
new mode 100755 (executable)
index ddbe7d0..6aba095 100755 (executable)
@@ -37,9 +37,9 @@ PKG_CHECK_MODULES(MMCOMMON, mm-common)
 AC_SUBST(MMCOMMON_CFLAGS)
 AC_SUBST(MMCOMMON_LIBS)
 
-PKG_CHECK_MODULES(MMLOG, mm-log)
-AC_SUBST(MMLOG_CFLAGS)
-AC_SUBST(MMLOG_LIBS)
+PKG_CHECK_MODULES(DLOG, dlog)
+AC_SUBST(DLOG_CFLAGS)
+AC_SUBST(DLOG_LIBS)
 
 PKG_CHECK_MODULES(GLIB, glib-2.0)
 AC_SUBST(GLIB_CFLAGS)
index 125acbc..01320d7 100755 (executable)
@@ -4,7 +4,8 @@ lib_LTLIBRARIES = libmmutil_imgp.la
 
 installmmutil_imgpdir = $(includedir)/mmf
 installmmutil_imgp_HEADERS = include/mm_util_imgp.h
-noinst_HEADERS = include/mm_util_imgp_internal.h
+noinst_HEADERS = include/mm_util_imgp_internal.h \
+                 include/mm_util_debug.h
 
 libmmutil_imgp_la_SOURCES = mm_util_imgp.c
 
@@ -20,7 +21,7 @@ libmmutil_imgp_la_CFLAGS = -I$(srcdir)/include \
                            $(DRI2PROTO_CFLAGS) \
                            $(DRI2_CFLAGS) \
                            $(TBM_CFLAGS) \
-                           $(MMLOG_CFLAGS) -DMMF_LOG_OWNER=0x0100 -DMMF_DEBUG_PREFIX=\"MMF-IMAGE\"
+                           $(DLOG_CFLAGS)
 
 libmmutil_imgp_la_LIBADD = $(MMCOMMON_LIBS) \
                            $(GLIB_LIBS) \
@@ -32,9 +33,9 @@ libmmutil_imgp_la_LIBADD = $(MMCOMMON_LIBS) \
                            $(DRI2PROTO_LIBS) \
                            $(DRI2_LIBS) \
                            $(TBM_LIBS) \
-                           $(MMLOG_LIBS)
+                           $(DLOG_LIBS)
 
-libmmutil_imgp_la_CFLAGS += -lcapi-media-tool -lttrace $(MMLOG_CFLAGS) -DMMF_LOG_OWNER=0x0100 -DMMF_DEBUG_PREFIX=\"MMF-IMAGE\" -DLIBPREFIX=\"$(libdir)\"
+libmmutil_imgp_la_CFLAGS += -lcapi-media-tool -lttrace $(MMLOG_CFLAGS) -DLIBPREFIX=\"$(libdir)\"
 
 pcfiles = mmutil-imgp.pc
 pkgconfigdir = $(libdir)/pkgconfig
diff --git a/imgp/include/mm_util_debug.h b/imgp/include/mm_util_debug.h
new file mode 100755 (executable)
index 0000000..e72aca6
--- /dev/null
@@ -0,0 +1,86 @@
+/*\r
+ * libmm-utility\r
+ *\r
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
+ *\r
+ * Contact: YoungHun Kim <yh8004.kim@samsung.com>\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ */\r
+#ifndef __MM_UTILITY_DEBUG_H__\r
+#define __MM_UTILITY_DEBUG_H__\r
+\r
+#include <dlog.h>\r
+\r
+#ifdef __cplusplus\r
+extern "C"\r
+{\r
+#endif\r
+\r
+#ifdef LOG_TAG\r
+#undef LOG_TAG\r
+#endif\r
+\r
+#define LOG_TAG "MM_UTIL"\r
+\r
+#define FONT_COLOR_RESET    "\033[0m"\r
+#define FONT_COLOR_RED      "\033[31m"\r
+\r
+#define mm_util_debug(fmt, arg...) do { \\r
+               LOGD(FONT_COLOR_RESET""fmt"", ##arg);     \\r
+       } while (0)\r
+\r
+#define mm_util_info(fmt, arg...) do { \\r
+               LOGI(FONT_COLOR_RESET""fmt"", ##arg);     \\r
+       } while (0)\r
+\r
+#define mm_util_warn(fmt, arg...) do { \\r
+               LOGW(FONT_COLOR_RESET""fmt"", ##arg);     \\r
+       } while (0)\r
+\r
+#define mm_util_error(fmt, arg...) do { \\r
+               LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg);     \\r
+       } while (0)\r
+\r
+#define mm_util_fenter() do { \\r
+               LOGD(FONT_COLOR_RESET"<Enter>");     \\r
+       } while (0)\r
+\r
+#define mm_util_fleave() do { \\r
+               LOGD(FONT_COLOR_RESET"<Leave>");     \\r
+       } while (0)\r
+\r
+#define mm_util_retm_if(expr, fmt, arg...) do { \\r
+               if(expr) { \\r
+                       LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg);     \\r
+                       return; \\r
+               } \\r
+       } while (0)\r
+\r
+#define mm_util_retvm_if(expr, val, fmt, arg...) do { \\r
+               if(expr) { \\r
+                       LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg);     \\r
+                       return (val); \\r
+               } \\r
+       } while (0)\r
+\r
+/**\r
+* @}\r
+*/\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /*__MM_UTILITY_DEBUG_H__*/\r
index 9baad28..41caf4c 100755 (executable)
@@ -30,7 +30,6 @@
 #endif
 
 #include <gmodule.h>
-#include <mm_debug.h>
 #include <mm_types.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -47,7 +46,7 @@
 #define PATH_GSTCS_LIB                                 LIBPREFIX "/libmmutil_imgp_gstcs.so"
 
 #define IMGP_FUNC_NAME                                 "mm_imgp"
-#define IMGP_FREE(src) { if(src) {g_free(src); src = NULL;} }
+#define IMGP_FREE(src) { if(src != NULL) {g_free(src); src = NULL;} }
 #define SCMN_IMGB_MAX_PLANE         (4)
 #define MAX_SRC_BUF_NUM          12    /* Max number of upstream src plugins's buffer */
 #define MAX_DST_BUF_NUM          12
@@ -91,6 +90,7 @@ typedef struct _imgp_info_s
        unsigned int dst_height;
        unsigned int output_stride;
        unsigned int output_elevation;
+       unsigned int buffer_size;
        mm_util_img_rotate_type angle;
 } imgp_info_s;
 
index fdd0ea1..ff32999 100755 (executable)
@@ -20,6 +20,7 @@
  */
 #include <limits.h>
 #include <mm_debug.h>
+#include "mm_util_debug.h"
 #include "mm_util_imgp.h"
 #include "mm_util_imgp_internal.h"
 #include <gmodule.h>
@@ -50,40 +51,39 @@ static int check_valid_picture_size(int width, int height)
        if((int)width>0 && (int)height>0 && (width+128)*(unsigned long long)(height+128) < INT_MAX/4) {
                return MM_ERROR_NONE;
        }
+
        return MM_ERROR_IMAGE_INVALID_VALUE;
 }
 
 static void __mm_destroy_temp_buffer(unsigned char *buffer[])
 {
        int i = 0;
-       for(i=0; i < 4; i++) {
-               if (buffer[i] != NULL)
-                       free(buffer[i]);
+
+       for(i = 0; i < 4; i++) {
+               IMGP_FREE(buffer[i]);
        }
 }
 
 static gboolean __mm_cannot_convert_format(mm_util_img_format src_format, mm_util_img_format dst_format )
 {
        gboolean _bool=FALSE;
-       debug_log("src_format: %d, dst_format:%d", src_format, dst_format);
+
+       mm_util_debug("src_format: %d, dst_format:%d", src_format, dst_format);
+
        if((dst_format == MM_UTIL_IMG_FMT_NV16) || (dst_format == MM_UTIL_IMG_FMT_NV61) ||
                ((src_format == MM_UTIL_IMG_FMT_YUV422) && (dst_format == MM_UTIL_IMG_FMT_NV12_TILED)) ||
-
                ((src_format == MM_UTIL_IMG_FMT_NV12) && (dst_format == MM_UTIL_IMG_FMT_NV12_TILED)) ||
-
                ((src_format == MM_UTIL_IMG_FMT_UYVY) && (dst_format == MM_UTIL_IMG_FMT_NV12_TILED)) ||
-
                ((src_format == MM_UTIL_IMG_FMT_YUYV) && (dst_format == MM_UTIL_IMG_FMT_NV12_TILED)) ||
-
                ((src_format == MM_UTIL_IMG_FMT_RGB565) && (dst_format == MM_UTIL_IMG_FMT_NV12_TILED)) ||
-
                ((src_format == MM_UTIL_IMG_FMT_RGB888) && (dst_format == MM_UTIL_IMG_FMT_NV12_TILED)) ||
-
                ((src_format == MM_UTIL_IMG_FMT_BGRX8888) && (dst_format == MM_UTIL_IMG_FMT_NV12_TILED)) ||
-
-               ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_YUV422)) || ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_UYVY)) ||
-               ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_YUYV)) || ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_ARGB8888)) ||
-               ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_RGBA8888)) ||((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_BGRX8888)) ) {
+               ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_YUV422)) ||
+               ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_UYVY)) ||
+               ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_YUYV)) ||
+               ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_ARGB8888)) ||
+               ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_RGBA8888)) ||
+               ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_BGRX8888)) ) {
 
                _bool = TRUE;
        }
@@ -94,78 +94,108 @@ static gboolean __mm_cannot_convert_format(mm_util_img_format src_format, mm_uti
 static gboolean __mm_gst_can_resize_format(char* __format_label)
 {
        gboolean _bool = FALSE;
-       debug_log("Format label: %s",__format_label);
+
+       mm_util_debug("Format label: %s",__format_label);
+
        if(strcmp(__format_label, "AYUV") == 0
                || strcmp(__format_label, "UYVY") == 0 ||strcmp(__format_label, "Y800") == 0 || strcmp(__format_label, "I420") == 0 || strcmp(__format_label, "YV12") == 0
                || strcmp(__format_label, "RGB888") == 0 || strcmp(__format_label, "RGB565") == 0 || strcmp(__format_label, "BGR888") == 0 || strcmp(__format_label, "RGBA8888") == 0
-               || strcmp(__format_label, "ARGB8888") == 0 ||strcmp(__format_label, "BGRA8888") == 0 ||strcmp(__format_label, "ABGR8888") == 0 ||strcmp(__format_label, "RGBX") == 0
-               ||strcmp(__format_label, "XRGB") == 0 ||strcmp(__format_label, "BGRX") == 0 ||strcmp(__format_label, "XBGR") == 0 ||strcmp(__format_label, "Y444") == 0
-               ||strcmp(__format_label, "Y42B") == 0 ||strcmp(__format_label, "YUY2") == 0 ||strcmp(__format_label, "YUYV") == 0 ||strcmp(__format_label, "UYVY") == 0
-               ||strcmp(__format_label, "Y41B") == 0 ||strcmp(__format_label, "Y16") == 0 ||strcmp(__format_label, "Y800") == 0 ||strcmp(__format_label, "Y8") == 0
-               ||strcmp(__format_label, "GREY") == 0 ||strcmp(__format_label, "AY64") == 0 || strcmp(__format_label, "YUV422") == 0) {
+               || strcmp(__format_label, "ARGB8888") == 0 ||strcmp(__format_label, "BGRA8888") == 0 || strcmp(__format_label, "ABGR8888") == 0 || strcmp(__format_label, "RGBX") == 0
+               || strcmp(__format_label, "XRGB") == 0 || strcmp(__format_label, "BGRX") == 0 || strcmp(__format_label, "XBGR") == 0 || strcmp(__format_label, "Y444") == 0
+               || strcmp(__format_label, "Y42B") == 0 || strcmp(__format_label, "YUY2") == 0 || strcmp(__format_label, "YUYV") == 0 || strcmp(__format_label, "UYVY") == 0
+               || strcmp(__format_label, "Y41B") == 0 || strcmp(__format_label, "Y16") == 0 || strcmp(__format_label, "Y800") == 0 || strcmp(__format_label, "Y8") == 0
+               || strcmp(__format_label, "GREY") == 0 || strcmp(__format_label, "AY64") == 0 || strcmp(__format_label, "YUV422") == 0) {
 
                _bool=TRUE;
        }
+
        return _bool;
 }
 
 static gboolean __mm_gst_can_rotate_format(const char* __format_label)
 {
        gboolean _bool = FALSE;
-       debug_log("Format label: %s boolean: %d",__format_label, _bool);
+
+       mm_util_debug("Format label: %s boolean: %d", __format_label, _bool);
+
        if(strcmp(__format_label, "I420") == 0 ||strcmp(__format_label, "YV12") == 0 || strcmp(__format_label, "IYUV") == 0
                || strcmp(__format_label, "RGB888") == 0||strcmp(__format_label, "BGR888") == 0 ||strcmp(__format_label, "RGBA8888") == 0
                || strcmp(__format_label, "ARGB8888") == 0 ||strcmp(__format_label, "BGRA8888") == 0 ||strcmp(__format_label, "ABGR8888") == 0 ) {
+
                _bool=TRUE;
        }
-       debug_log("boolean: %d",_bool);
+
+       mm_util_debug("boolean: %d",_bool);
+
        return _bool;
 }
 
 static gboolean __mm_select_convert_plugin(mm_util_img_format src_format, mm_util_img_format dst_format )
 {
        gboolean _bool=FALSE;
-       debug_log("src_format: %d, dst_format:%d", src_format, dst_format);
-       if(((src_format == MM_UTIL_IMG_FMT_YUV420) && (dst_format == MM_UTIL_IMG_FMT_NV12)) || ((src_format == MM_UTIL_IMG_FMT_YUV420) && (dst_format == MM_UTIL_IMG_FMT_RGB565)) ||
-               ((src_format == MM_UTIL_IMG_FMT_YUV420) && (dst_format == MM_UTIL_IMG_FMT_RGB888)) || ((src_format == MM_UTIL_IMG_FMT_YUV420) && (dst_format == MM_UTIL_IMG_FMT_ARGB8888)) ||
-               ((src_format == MM_UTIL_IMG_FMT_YUV420) && (dst_format == MM_UTIL_IMG_FMT_BGRA8888)) || ((src_format == MM_UTIL_IMG_FMT_YUV420) && (dst_format == MM_UTIL_IMG_FMT_RGBA8888)) ||
+
+       mm_util_debug("src_format: %d, dst_format:%d", src_format, dst_format);
+
+       if(((src_format == MM_UTIL_IMG_FMT_YUV420) && (dst_format == MM_UTIL_IMG_FMT_NV12)) ||
+               ((src_format == MM_UTIL_IMG_FMT_YUV420) && (dst_format == MM_UTIL_IMG_FMT_RGB565)) ||
+               ((src_format == MM_UTIL_IMG_FMT_YUV420) && (dst_format == MM_UTIL_IMG_FMT_RGB888)) ||
+               ((src_format == MM_UTIL_IMG_FMT_YUV420) && (dst_format == MM_UTIL_IMG_FMT_ARGB8888)) ||
+               ((src_format == MM_UTIL_IMG_FMT_YUV420) && (dst_format == MM_UTIL_IMG_FMT_BGRA8888)) ||
+               ((src_format == MM_UTIL_IMG_FMT_YUV420) && (dst_format == MM_UTIL_IMG_FMT_RGBA8888)) ||
                ((src_format == MM_UTIL_IMG_FMT_YUV420) && (dst_format == MM_UTIL_IMG_FMT_NV12_TILED)) ||
 
-               ((src_format == MM_UTIL_IMG_FMT_I420) && (dst_format == MM_UTIL_IMG_FMT_NV12)) || ((src_format == MM_UTIL_IMG_FMT_I420) && (dst_format == MM_UTIL_IMG_FMT_RGB565)) ||
-               ((src_format == MM_UTIL_IMG_FMT_I420) && (dst_format == MM_UTIL_IMG_FMT_RGB888)) || ((src_format == MM_UTIL_IMG_FMT_I420) && (dst_format == MM_UTIL_IMG_FMT_ARGB8888)) ||
-               ((src_format == MM_UTIL_IMG_FMT_I420) && (dst_format == MM_UTIL_IMG_FMT_BGRA8888)) || ((src_format == MM_UTIL_IMG_FMT_I420) && (dst_format == MM_UTIL_IMG_FMT_RGBA8888)) ||
+               ((src_format == MM_UTIL_IMG_FMT_I420) && (dst_format == MM_UTIL_IMG_FMT_NV12)) ||
+               ((src_format == MM_UTIL_IMG_FMT_I420) && (dst_format == MM_UTIL_IMG_FMT_RGB565)) ||
+               ((src_format == MM_UTIL_IMG_FMT_I420) && (dst_format == MM_UTIL_IMG_FMT_RGB888)) ||
+               ((src_format == MM_UTIL_IMG_FMT_I420) && (dst_format == MM_UTIL_IMG_FMT_ARGB8888)) ||
+               ((src_format == MM_UTIL_IMG_FMT_I420) && (dst_format == MM_UTIL_IMG_FMT_BGRA8888)) ||
+               ((src_format == MM_UTIL_IMG_FMT_I420) && (dst_format == MM_UTIL_IMG_FMT_RGBA8888)) ||
                ((src_format == MM_UTIL_IMG_FMT_I420) && (dst_format == MM_UTIL_IMG_FMT_NV12_TILED)) ||
 
-               ((src_format == MM_UTIL_IMG_FMT_NV12) && (dst_format == MM_UTIL_IMG_FMT_YUV420)) || ((src_format == MM_UTIL_IMG_FMT_NV12) && (dst_format == MM_UTIL_IMG_FMT_I420)) ||
-               ((src_format == MM_UTIL_IMG_FMT_NV12) && (dst_format == MM_UTIL_IMG_FMT_RGB565)) || ((src_format == MM_UTIL_IMG_FMT_NV12) && (dst_format == MM_UTIL_IMG_FMT_RGB888)) ||
-               ((src_format == MM_UTIL_IMG_FMT_NV12) && (dst_format == MM_UTIL_IMG_FMT_ARGB8888)) || ((src_format == MM_UTIL_IMG_FMT_NV12) && (dst_format == MM_UTIL_IMG_FMT_BGRA8888)) ||
+               ((src_format == MM_UTIL_IMG_FMT_NV12) && (dst_format == MM_UTIL_IMG_FMT_YUV420)) ||
+               ((src_format == MM_UTIL_IMG_FMT_NV12) && (dst_format == MM_UTIL_IMG_FMT_I420)) ||
+               ((src_format == MM_UTIL_IMG_FMT_NV12) && (dst_format == MM_UTIL_IMG_FMT_RGB565)) ||
+               ((src_format == MM_UTIL_IMG_FMT_NV12) && (dst_format == MM_UTIL_IMG_FMT_RGB888)) ||
+               ((src_format == MM_UTIL_IMG_FMT_NV12) && (dst_format == MM_UTIL_IMG_FMT_ARGB8888)) ||
+               ((src_format == MM_UTIL_IMG_FMT_NV12) && (dst_format == MM_UTIL_IMG_FMT_BGRA8888)) ||
                ((src_format == MM_UTIL_IMG_FMT_NV12) && (dst_format == MM_UTIL_IMG_FMT_RGBA8888)) ||
 
-               ((src_format == MM_UTIL_IMG_FMT_UYVY) && (dst_format == MM_UTIL_IMG_FMT_RGB565)) || ((src_format == MM_UTIL_IMG_FMT_UYVY) && (dst_format == MM_UTIL_IMG_FMT_RGB888)) ||
+               ((src_format == MM_UTIL_IMG_FMT_UYVY) && (dst_format == MM_UTIL_IMG_FMT_RGB565)) ||
+               ((src_format == MM_UTIL_IMG_FMT_UYVY) && (dst_format == MM_UTIL_IMG_FMT_RGB888)) ||
 
-               ((src_format == MM_UTIL_IMG_FMT_YUYV) && (dst_format == MM_UTIL_IMG_FMT_RGB565)) || ((src_format == MM_UTIL_IMG_FMT_YUYV) && (dst_format == MM_UTIL_IMG_FMT_RGB888)) ||
-               ((src_format == MM_UTIL_IMG_FMT_YUYV) && (dst_format == MM_UTIL_IMG_FMT_ARGB8888)) || ((src_format == MM_UTIL_IMG_FMT_YUYV) && (dst_format == MM_UTIL_IMG_FMT_BGRA8888)) ||
+               ((src_format == MM_UTIL_IMG_FMT_YUYV) && (dst_format == MM_UTIL_IMG_FMT_RGB565)) ||
+               ((src_format == MM_UTIL_IMG_FMT_YUYV) && (dst_format == MM_UTIL_IMG_FMT_RGB888)) ||
+               ((src_format == MM_UTIL_IMG_FMT_YUYV) && (dst_format == MM_UTIL_IMG_FMT_ARGB8888)) ||
+               ((src_format == MM_UTIL_IMG_FMT_YUYV) && (dst_format == MM_UTIL_IMG_FMT_BGRA8888)) ||
                ((src_format == MM_UTIL_IMG_FMT_YUYV) && (dst_format == MM_UTIL_IMG_FMT_RGBA8888)) ||
 
-               ((src_format == MM_UTIL_IMG_FMT_RGB565) && (dst_format == MM_UTIL_IMG_FMT_YUV420)) || ((src_format == MM_UTIL_IMG_FMT_RGB565) && (dst_format == MM_UTIL_IMG_FMT_I420)) ||
+               ((src_format == MM_UTIL_IMG_FMT_RGB565) && (dst_format == MM_UTIL_IMG_FMT_YUV420)) ||
+               ((src_format == MM_UTIL_IMG_FMT_RGB565) && (dst_format == MM_UTIL_IMG_FMT_I420)) ||
                ((src_format == MM_UTIL_IMG_FMT_RGB565) && (dst_format == MM_UTIL_IMG_FMT_NV12)) ||
 
-               ((src_format == MM_UTIL_IMG_FMT_RGB888) && (dst_format == MM_UTIL_IMG_FMT_YUV420)) || ((src_format == MM_UTIL_IMG_FMT_RGB888) && (dst_format == MM_UTIL_IMG_FMT_I420)) ||
+               ((src_format == MM_UTIL_IMG_FMT_RGB888) && (dst_format == MM_UTIL_IMG_FMT_YUV420)) ||
+               ((src_format == MM_UTIL_IMG_FMT_RGB888) && (dst_format == MM_UTIL_IMG_FMT_I420)) ||
                ((src_format == MM_UTIL_IMG_FMT_RGB888) && (dst_format == MM_UTIL_IMG_FMT_NV12)) ||
 
-               ((src_format == MM_UTIL_IMG_FMT_ARGB8888) && (dst_format == MM_UTIL_IMG_FMT_YUV420)) || ((src_format == MM_UTIL_IMG_FMT_ARGB8888) && (dst_format == MM_UTIL_IMG_FMT_I420)) ||
+               ((src_format == MM_UTIL_IMG_FMT_ARGB8888) && (dst_format == MM_UTIL_IMG_FMT_YUV420)) ||
+               ((src_format == MM_UTIL_IMG_FMT_ARGB8888) && (dst_format == MM_UTIL_IMG_FMT_I420)) ||
                ((src_format == MM_UTIL_IMG_FMT_ARGB8888) && (dst_format == MM_UTIL_IMG_FMT_NV12)) ||
 
-               ((src_format == MM_UTIL_IMG_FMT_BGRA8888) && (dst_format == MM_UTIL_IMG_FMT_YUV420)) || ((src_format == MM_UTIL_IMG_FMT_BGRA8888) && (dst_format == MM_UTIL_IMG_FMT_I420)) ||
+               ((src_format == MM_UTIL_IMG_FMT_BGRA8888) && (dst_format == MM_UTIL_IMG_FMT_YUV420)) ||
+               ((src_format == MM_UTIL_IMG_FMT_BGRA8888) && (dst_format == MM_UTIL_IMG_FMT_I420)) ||
                ((src_format == MM_UTIL_IMG_FMT_BGRA8888) && (dst_format == MM_UTIL_IMG_FMT_NV12)) ||
-
-               ((src_format == MM_UTIL_IMG_FMT_RGBA8888) && (dst_format == MM_UTIL_IMG_FMT_YUV420)) || ((src_format == MM_UTIL_IMG_FMT_RGBA8888) && (dst_format == MM_UTIL_IMG_FMT_I420)) ||
-               ((src_format == MM_UTIL_IMG_FMT_RGBA8888) && (dst_format == MM_UTIL_IMG_FMT_NV12)) || ((src_format == MM_UTIL_IMG_FMT_RGBA8888) && (dst_format == MM_UTIL_IMG_FMT_RGB565)) ||
-
-               ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_YUV420)) || ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_I420)) ||
-               ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_NV12)) || ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_RGB565)) ||
+               ((src_format == MM_UTIL_IMG_FMT_RGBA8888) && (dst_format == MM_UTIL_IMG_FMT_YUV420)) ||
+               ((src_format == MM_UTIL_IMG_FMT_RGBA8888) && (dst_format == MM_UTIL_IMG_FMT_I420)) ||
+               ((src_format == MM_UTIL_IMG_FMT_RGBA8888) && (dst_format == MM_UTIL_IMG_FMT_NV12)) ||
+               ((src_format == MM_UTIL_IMG_FMT_RGBA8888) && (dst_format == MM_UTIL_IMG_FMT_RGB565)) ||
+
+               ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_YUV420)) ||
+               ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_I420)) ||
+               ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_NV12)) ||
+               ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_RGB565)) ||
                ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_RGB888)) ||
-               ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_ARGB8888)) || ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_BGRA8888)) ||
+               ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_ARGB8888)) ||
+               ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_BGRA8888)) ||
                ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_RGBA8888))) {
 
                _bool = TRUE;
@@ -177,20 +207,23 @@ static gboolean __mm_select_convert_plugin(mm_util_img_format src_format, mm_uti
 static gboolean __mm_select_resize_plugin(mm_util_img_format _format)
 {
        gboolean _bool = FALSE;
-       debug_log("_format: %d", _format);
-       if( (_format == MM_UTIL_IMG_FMT_UYVY) || (_format == MM_UTIL_IMG_FMT_YUYV) || (_format == MM_UTIL_IMG_FMT_RGBA8888) || (_format == MM_UTIL_IMG_FMT_BGRX8888) ) {
+
+       mm_util_debug("_format: %d", _format);
+
+       if ((_format == MM_UTIL_IMG_FMT_UYVY) || (_format == MM_UTIL_IMG_FMT_YUYV) || (_format == MM_UTIL_IMG_FMT_RGBA8888) || (_format == MM_UTIL_IMG_FMT_BGRX8888)) {
                _bool = FALSE;
-       }else {
+       } else {
                _bool = TRUE;
        }
+
        return _bool;
 }
 
 static gboolean __mm_select_rotate_plugin(mm_util_img_format _format, unsigned int width, unsigned int height, mm_util_img_rotate_type angle)
 {
-       debug_log("_format: %d (angle: %d)", _format, angle);
+       mm_util_debug("_format: %d (angle: %d)", _format, angle);
 
-       if((_format == MM_UTIL_IMG_FMT_YUV420) || (_format == MM_UTIL_IMG_FMT_I420) || (_format == MM_UTIL_IMG_FMT_NV12)
+       if ((_format == MM_UTIL_IMG_FMT_YUV420) || (_format == MM_UTIL_IMG_FMT_I420) || (_format == MM_UTIL_IMG_FMT_NV12)
                ||(_format == MM_UTIL_IMG_FMT_RGB888 ||_format == MM_UTIL_IMG_FMT_RGB565)) {
                return TRUE;
        }
@@ -198,12 +231,124 @@ static gboolean __mm_select_rotate_plugin(mm_util_img_format _format, unsigned i
        return FALSE;
 }
 
+static gboolean __mm_is_rgb_format(mm_util_img_format format)
+{
+       mm_util_debug("format: %d", format);
+
+       if ((format == MM_UTIL_IMG_FMT_RGB565) ||
+               (format == MM_UTIL_IMG_FMT_RGB888) ||
+               (format == MM_UTIL_IMG_FMT_ARGB8888) ||
+               (format == MM_UTIL_IMG_FMT_BGRA8888) ||
+               (format == MM_UTIL_IMG_FMT_RGBA8888) ||
+               (format == MM_UTIL_IMG_FMT_BGRX8888)) {
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
+int __mm_util_get_buffer_size(mm_util_img_format format, unsigned int width, unsigned int height, unsigned int *imgsize)
+{
+       int ret = MM_ERROR_NONE;
+       unsigned char x_chroma_shift = 0;
+       unsigned char y_chroma_shift = 0;
+       int size, w2, h2, size2;
+       int stride, stride2;
+
+       TTRACE_BEGIN("MM_UTILITY:IMGP:GET_SIZE");
+
+       if (!imgsize) {
+               mm_util_error("imgsize can't be null");
+               TTRACE_END();
+               return MM_ERROR_IMAGE_FILEOPEN;
+       }
+
+       *imgsize = 0;
+
+       if (check_valid_picture_size(width, height) < 0) {
+               mm_util_error("invalid width and height");
+               TTRACE_END();
+               return MM_ERROR_IMAGE_INVALID_VALUE;
+       }
+
+       switch (format)
+       {
+               case MM_UTIL_IMG_FMT_I420:
+               case MM_UTIL_IMG_FMT_YUV420:
+                       x_chroma_shift = 1;
+                       y_chroma_shift = 1;
+                       stride = MM_UTIL_ROUND_UP_4 (width);
+                       h2 = ROUND_UP_X (height, x_chroma_shift);
+                       size = stride * h2;
+                       w2 = DIV_ROUND_UP_X (width, x_chroma_shift);
+                       stride2 = MM_UTIL_ROUND_UP_4 (w2);
+                       h2 = DIV_ROUND_UP_X (height, y_chroma_shift);
+                       size2 = stride2 * h2;
+                       *imgsize = size + 2 * size2;
+                       break;
+               case MM_UTIL_IMG_FMT_YUV422:
+               case MM_UTIL_IMG_FMT_YUYV:
+               case MM_UTIL_IMG_FMT_UYVY:
+               case MM_UTIL_IMG_FMT_NV16:
+               case MM_UTIL_IMG_FMT_NV61:
+                       stride = MM_UTIL_ROUND_UP_4 (width) * 2;
+                       size = stride * height;
+                       *imgsize = size;
+                       break;
+
+               case MM_UTIL_IMG_FMT_RGB565:
+                       stride = MM_UTIL_ROUND_UP_4 (width) * 2;
+                       size = stride * MM_UTIL_ROUND_UP_2(height);
+                       *imgsize = size;
+                       break;
+
+               case MM_UTIL_IMG_FMT_RGB888:
+                       stride = MM_UTIL_ROUND_UP_4 (width) * 3;
+                       size = stride * MM_UTIL_ROUND_UP_2(height);
+                       *imgsize = size;
+                       break;
+
+               case MM_UTIL_IMG_FMT_ARGB8888:
+               case MM_UTIL_IMG_FMT_BGRA8888:
+               case MM_UTIL_IMG_FMT_RGBA8888:
+               case MM_UTIL_IMG_FMT_BGRX8888:
+                       stride = width * 4;
+                       size = stride * MM_UTIL_ROUND_UP_2(height);
+                       *imgsize = size;
+                       break;
+
+
+               case MM_UTIL_IMG_FMT_NV12:
+               case MM_UTIL_IMG_FMT_NV12_TILED:
+                       x_chroma_shift = 1;
+                       y_chroma_shift = 1;
+                       stride = MM_UTIL_ROUND_UP_4 (width);
+                       h2 = ROUND_UP_X (height, y_chroma_shift);
+                       size = stride * h2;
+                       w2 = 2 * DIV_ROUND_UP_X (width, x_chroma_shift);
+                       stride2 = MM_UTIL_ROUND_UP_4 (w2);
+                       h2 = DIV_ROUND_UP_X (height, y_chroma_shift);
+                       size2 = stride2 * h2;
+                       *imgsize = size + size2;
+                       break;
+
+               default:
+                       mm_util_error("Not supported format");
+                       TTRACE_END();
+                       return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
+       }
+       mm_util_debug("format: %d, *imgsize: %d\n", format, *imgsize);
+
+       TTRACE_END();
+       return ret;
+}
+
 static int __mm_confirm_dst_width_height(unsigned int src_width, unsigned int src_height, unsigned int *dst_width, unsigned int *dst_height, mm_util_img_rotate_type angle)
 {
        int ret = MM_ERROR_NONE;
 
-       if(!dst_width || !dst_height) {
-               debug_error("[%s][%05d] dst_width || dst_height Buffer is NULL");
+       if (!dst_width || !dst_height) {
+               mm_util_error("[%s][%05d] dst_width || dst_height Buffer is NULL");
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
@@ -213,34 +358,35 @@ static int __mm_confirm_dst_width_height(unsigned int src_width, unsigned int sr
                case MM_UTIL_ROTATE_FLIP_HORZ:
                case MM_UTIL_ROTATE_FLIP_VERT:
                        if(*dst_width != src_width) {
-                               debug_log("*dst_width: %d", *dst_width);
+                               mm_util_debug("*dst_width: %d", *dst_width);
                                *dst_width = src_width;
-                               debug_log("#Confirmed# *dst_width: %d", *dst_width);
+                               mm_util_debug("#Confirmed# *dst_width: %d", *dst_width);
                        }
                        if(*dst_height != src_height) {
-                               debug_log("*dst_height: %d", *dst_height);
+                               mm_util_debug("*dst_height: %d", *dst_height);
                                *dst_height = src_height;
-                               debug_log("#Confirmed# *dst_height: %d", *dst_height);
+                               mm_util_debug("#Confirmed# *dst_height: %d", *dst_height);
                        }
                        break;
                case MM_UTIL_ROTATE_90:
                case MM_UTIL_ROTATE_270:
                        if(*dst_width != src_height) {
-                               debug_log("*dst_width: %d", *dst_width);
+                               mm_util_debug("*dst_width: %d", *dst_width);
                                *dst_width = src_height;
-                               debug_log("#Confirmed# *dst_width: %d", *dst_width);
+                               mm_util_debug("#Confirmed# *dst_width: %d", *dst_width);
                        }
                        if(*dst_height != src_width) {
-                               debug_log("*dst_height: %d", *dst_height);
+                               mm_util_debug("*dst_height: %d", *dst_height);
                                *dst_height = src_width;
-                               debug_log("#Confirmed# *dst_height: %d", *dst_height);
+                               mm_util_debug("#Confirmed# *dst_height: %d", *dst_height);
                        }
                        break;
 
                default:
-                       debug_error("Not supported rotate value\n");
+                       mm_util_error("Not supported rotate value");
                        return MM_ERROR_IMAGE_INVALID_VALUE;
        }
+
        return ret;
 }
 
@@ -250,7 +396,7 @@ static int __mm_set_format_label(imgp_info_s * _imgp_info_s, mm_util_img_format
        char *src_fmt_lable = NULL;
        char *dst_fmt_lable = NULL;
        if(_imgp_info_s == NULL) {
-               debug_error("_imgp_info_s: 0x%2x", _imgp_info_s);
+               mm_util_error("_imgp_info_s: 0x%2x", _imgp_info_s);
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
@@ -292,7 +438,7 @@ static int __mm_set_format_label(imgp_info_s * _imgp_info_s, mm_util_img_format
                        src_fmt_lable = (char *)"BGRX";
                        break;
                default:
-                       debug_log("[%d] Not supported format", src_fmt_lable);
+                       mm_util_debug("[%d] Not supported format", src_fmt_lable);
                        break;
        }
 
@@ -334,15 +480,15 @@ static int __mm_set_format_label(imgp_info_s * _imgp_info_s, mm_util_img_format
                        dst_fmt_lable = (char *)"BGRX";
                        break;
                default:
-                       debug_error("[%d] Not supported format", dst_format);
+                       mm_util_error("[%d] Not supported format", dst_format);
                        break;
        }
 
        if(src_fmt_lable && dst_fmt_lable) {
-               debug_log("src_fmt_lable: %s dst_fmt_lable: %s", src_fmt_lable, dst_fmt_lable);
+               mm_util_debug("src_fmt_lable: %s dst_fmt_lable: %s", src_fmt_lable, dst_fmt_lable);
                _imgp_info_s->input_format_label = (char*)malloc(strlen(src_fmt_lable) + 1);
                if(_imgp_info_s->input_format_label == NULL) {
-                       debug_error("[input] input_format_label is null");
+                       mm_util_error("[input] input_format_label is null");
                        return MM_ERROR_IMAGE_NO_FREE_SPACE;
                }
                memset(_imgp_info_s->input_format_label, 0, strlen(src_fmt_lable) + 1);
@@ -350,18 +496,19 @@ static int __mm_set_format_label(imgp_info_s * _imgp_info_s, mm_util_img_format
 
                _imgp_info_s->output_format_label = (char*)malloc(strlen(dst_fmt_lable) + 1);
                if(_imgp_info_s->output_format_label == NULL) {
-                       debug_error("[input] input_format_label is null");
+                       mm_util_error("[input] input_format_label is null");
                        IMGP_FREE(_imgp_info_s->input_format_label);
                        return MM_ERROR_IMAGE_NO_FREE_SPACE;
                }
                memset(_imgp_info_s->output_format_label, 0, strlen(dst_fmt_lable) + 1);
                strncpy(_imgp_info_s->output_format_label, dst_fmt_lable, strlen(dst_fmt_lable));
 
-               debug_log("input_format_label: %s output_format_label: %s", _imgp_info_s->input_format_label, _imgp_info_s->output_format_label);
+               mm_util_debug("input_format_label: %s output_format_label: %s", _imgp_info_s->input_format_label, _imgp_info_s->output_format_label);
        }else {
-               debug_error("[error] src_fmt_lable && dst_fmt_lable");
+               mm_util_error("[error] src_fmt_lable && dst_fmt_lable");
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
+
        return ret;
 }
 
@@ -370,26 +517,27 @@ static int __mm_set_imgp_info_s(imgp_info_s * _imgp_info_s, mm_util_img_format s
        int ret = MM_ERROR_NONE;
 
        if(_imgp_info_s == NULL) {
-               debug_error("_imgp_info_s is NULL");
+               mm_util_error("_imgp_info_s is NULL");
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        ret = __mm_set_format_label(_imgp_info_s, src_format, dst_format);
        if(ret != MM_ERROR_NONE) {
-               debug_error("[input] mm_set_format_label error");
+               mm_util_error("[input] mm_set_format_label error");
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
-       _imgp_info_s->src_format=src_format;
+       _imgp_info_s->src_format = src_format;
        _imgp_info_s->src_width = src_width;
        _imgp_info_s->src_height= src_height;
 
-       _imgp_info_s->dst_format=dst_format;
+       _imgp_info_s->dst_format = dst_format;
        _imgp_info_s->dst_width = dst_width;
        _imgp_info_s->dst_height = dst_height;
+       _imgp_info_s->buffer_size = 0;
        _imgp_info_s->angle= angle;
 
-       debug_log("[input] format label: %s width: %d height: %d [output] format label: %s width: %d height: %d rotation_value: %d",
+       mm_util_debug("[input] format label: %s width: %d height: %d [output] format label: %s width: %d height: %d rotation_value: %d",
        _imgp_info_s->input_format_label, _imgp_info_s->src_width, _imgp_info_s->src_height,
        _imgp_info_s->output_format_label, _imgp_info_s->dst_width, _imgp_info_s->dst_height, _imgp_info_s->angle);
 
@@ -399,42 +547,42 @@ static int __mm_set_imgp_info_s(imgp_info_s * _imgp_info_s, mm_util_img_format s
 static GModule * __mm_util_imgp_initialize(imgp_plugin_type_e _imgp_plugin_type_e)
 {
        GModule *module = NULL;
-       debug_log("#Start dlopen#");
+       mm_util_fenter();
 
        if( _imgp_plugin_type_e == IMGP_NEON ) {
                module = g_module_open(PATH_NEON_LIB, G_MODULE_BIND_LAZY);
        }else if( _imgp_plugin_type_e == IMGP_GSTCS) {
                module = g_module_open(PATH_GSTCS_LIB, G_MODULE_BIND_LAZY);
        }
-       debug_log("#Success g_module_open#");
+
        if( module == NULL ) {
-               debug_error("%s | %s module open failed", PATH_NEON_LIB, PATH_GSTCS_LIB);
+               mm_util_error("%s | %s module open failed", PATH_NEON_LIB, PATH_GSTCS_LIB);
                return NULL;
        }
-       debug_log("module: %p, g_module_name: %s", module, g_module_name (module));
+       mm_util_debug("module: %p, g_module_name: %s", module, g_module_name (module));
+
        return module;
 }
 
 static IMGPInfoFunc __mm_util_imgp_process(GModule *module)
 {
        IMGPInfoFunc mm_util_imgp_func = NULL;
+       mm_util_fenter();
 
        if(module == NULL) {
-               debug_error("module is NULL");
+               mm_util_error("module is NULL");
                return NULL;
        }
 
-       debug_log("#__mm_util_imgp_process#");
-
        g_module_symbol(module, IMGP_FUNC_NAME, (gpointer*)&mm_util_imgp_func);
-       debug_log("mm_util_imgp_func: %p", mm_util_imgp_func);
+       mm_util_debug("mm_util_imgp_func: %p", mm_util_imgp_func);
 
        return mm_util_imgp_func;
 }
 
 static int _mm_util_transform_packet_finalize_callback(media_packet_h packet, int err, void* userdata)
 {
-       debug_log("==> finalize callback func is called [%d] \n", err);
+       mm_util_debug("==> finalize callback func is called [%d] \n", err);
        return MEDIA_PACKET_FINALIZE;
 }
 
@@ -443,12 +591,12 @@ static int __mm_util_imgp_finalize(GModule *module, imgp_info_s *_imgp_info_s)
        int ret = MM_ERROR_NONE;
 
        if(module) {
-               debug_log("module : %p", module);
+               mm_util_debug("module : %p", module);
                g_module_close( module );
-               debug_log("#End g_module_close#");
+               mm_util_debug("#End g_module_close#");
                module = NULL;
        }else {
-               debug_error("#module is NULL#");
+               mm_util_error("#module is NULL#");
                ret = MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
@@ -467,7 +615,7 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_wid
        int src_bytesperline = src_width * 4;
        int dst_bytesperline = crop_dest_width * 4;
 
-       debug_log("[Input] src: 0x%2x src, src_width: %d src_height: %d src_format: %d crop_start_x: %d crop_start_y: %d crop_dest_width: %d crop_dest_height: %d\n",
+       mm_util_debug("[Input] src: 0x%2x src, src_width: %d src_height: %d src_format: %d crop_start_x: %d crop_start_y: %d crop_dest_width: %d crop_dest_height: %d\n",
        src, src_width, src_height, src_format, crop_start_x, crop_start_y, crop_dest_width, crop_dest_height);
        src += crop_start_y * src_bytesperline + 4 * crop_start_x;
 
@@ -488,7 +636,7 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_wid
        int src_bytesperline = src_width * 3;
        int dst_bytesperline = crop_dest_width * 3;
 
-       debug_log("[Input] src: 0x%2x src, src_width: %d src_height: %d src_format: %d crop_start_x: %d crop_start_y: %d crop_dest_width: %d crop_dest_height: %d\n",
+       mm_util_debug("[Input] src: 0x%2x src, src_width: %d src_height: %d src_format: %d crop_start_x: %d crop_start_y: %d crop_dest_width: %d crop_dest_height: %d\n",
        src, src_width, src_height, src_format, crop_start_x, crop_start_y, crop_dest_width, crop_dest_height);
        src += crop_start_y * src_bytesperline + 3 * crop_start_x;
 
@@ -509,7 +657,7 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_wid
        int src_bytesperline = src_width * 2;
        int dst_bytesperline = crop_dest_width * 2;
 
-       debug_log("[Input] src: 0x%2x src, src_width: %d src_height: %d src_format: %d crop_start_x: %d crop_start_y: %d crop_dest_width: %d crop_dest_height: %d\n",
+       mm_util_debug("[Input] src: 0x%2x src, src_width: %d src_height: %d src_format: %d crop_start_x: %d crop_start_y: %d crop_dest_width: %d crop_dest_height: %d\n",
        src, src_width, src_height, src_format, crop_start_x, crop_start_y, crop_dest_width, crop_dest_height);
        src += crop_start_y * src_bytesperline + 2 * crop_start_x;
 
@@ -529,7 +677,7 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_wid
        unsigned int idx = 0;
        int start_x = crop_start_x;
        int start_y = crop_start_y;
-       debug_log("[Input] src: 0x%2x src, src_width: %d src_height: %d src_format: %d crop_start_x: %d crop_start_y: %d crop_dest_width: %d crop_dest_height: %d\n",
+       mm_util_debug("[Input] src: 0x%2x src, src_width: %d src_height: %d src_format: %d crop_start_x: %d crop_start_y: %d crop_dest_width: %d crop_dest_height: %d\n",
        src, src_width, src_height, src_format, crop_start_x, crop_start_y, crop_dest_width, crop_dest_height);
        const unsigned char *_src = src + start_y * src_width + start_x;
 
@@ -563,17 +711,17 @@ static bool __mm_util_check_resolution(unsigned int width, unsigned int height)
 {
        if(width == 0)
        {
-               debug_error("invalid width [%d]", width);
-               return false;
+               mm_util_error("invalid width [%d]", width);
+               return FALSE;
        }
 
        if(height == 0)
        {
-               debug_error("invalid height [%d]", height);
-               return false;
+               mm_util_error("invalid height [%d]", height);
+               return FALSE;
        }
 
-       return true;
+       return TRUE;
 }
 
 static int __mm_util_handle_init(mm_util_s *handle)
@@ -581,13 +729,13 @@ static int __mm_util_handle_init(mm_util_s *handle)
        int ret = MM_ERROR_NONE;
 
        if (!handle) {
-               debug_error("[ERROR] - handle");
+               mm_util_error("[ERROR] - handle");
                return MM_ERROR_IMAGE_INTERNAL;
        }
 
        /* private values init */
-       handle->src = 0;
-       handle->dst = 0;
+       handle->src = NULL;
+       handle->dst = NULL;
        handle->drm_fd = -1;
        handle->dst_format = MM_UTIL_IMG_FMT_NUM;
        handle->dst_format_mime = -1;
@@ -617,7 +765,7 @@ static int __mm_util_handle_refresh(mm_util_s *handle)
        int ret = MM_ERROR_NONE;
 
        if (!handle) {
-               debug_error("[ERROR] - handle");
+               mm_util_error("[ERROR] - handle");
                return MM_ERROR_IMAGE_INTERNAL;
        }
 
@@ -681,11 +829,11 @@ static media_format_mimetype_e __mm_util_mapping_imgp_format_to_mime(mm_util_img
                        break;
                default:
                        mimetype = -1;
-                       debug_error("Not Supported Format [%d]", format);
+                       mm_util_error("Not Supported Format [%d]", format);
                        break;
        }
 
-       debug_log("imgp fmt: %d mimetype fmt: %d", format, mimetype);
+       mm_util_debug("imgp fmt: %d mimetype fmt: %d", format, mimetype);
 
        return mimetype;
 }
@@ -733,11 +881,11 @@ static mm_util_img_format __mm_util_mapping_mime_format_to_imgp(media_format_mim
                        break;
                default:
                        format = -1;
-                       debug_error("Not Supported Format [%d]", mimetype);
+                       mm_util_error("Not Supported Format [%d]", mimetype);
                        break;
        }
 
-       debug_log("mimetype: %d imgp fmt: %d", mimetype, format);
+       mm_util_debug("mimetype: %d imgp fmt: %d", mimetype, format);
 
        return format;
 }
@@ -749,45 +897,45 @@ gpointer _mm_util_thread_repeate(gpointer data)
        gint64 end_time = 0;
 
        if (!handle) {
-               debug_error("[ERROR] - handle");
+               mm_util_error("[ERROR] - handle");
                return NULL;
        }
 
        while (!handle->is_finish) {
                end_time = g_get_monotonic_time() + 1 * G_TIME_SPAN_SECOND;
-               debug_log("waiting...");
+               mm_util_debug("waiting...");
                g_mutex_lock (&(handle->thread_mutex));
                g_cond_wait_until(&(handle->thread_cond), &(handle->thread_mutex), end_time);
-               debug_log("<=== get run transform thread signal");
+               mm_util_debug("<=== get run transform thread signal");
                g_mutex_unlock (&(handle->thread_mutex));
 
                if (handle->is_finish) {
-                       debug_log("exit loop");
+                       mm_util_debug("exit loop");
                        break;
                }
 
                media_packet_h pop_data = (media_packet_h) g_async_queue_try_pop(handle->queue);
 
                if(!pop_data) {
-                       debug_error("[NULL] Queue data");
+                       mm_util_error("[NULL] Queue data");
                } else {
                        ret = __mm_util_transform_exec(handle, pop_data); /* Need to block */
                        if(ret == MM_ERROR_NONE) {
-                               debug_log("Success - transform_exec");
+                               mm_util_debug("Success - transform_exec");
                        } else{
-                               debug_error("Error - transform_exec");
+                               mm_util_error("Error - transform_exec");
                        }
                        if(handle->_util_cb->completed_cb) {
-                               debug_log("completed_cb");
+                               mm_util_debug("completed_cb");
                                handle->_util_cb->completed_cb(&handle->dst_packet, ret, handle->_util_cb->user_data);
-                               debug_log("completed_cb %p", &handle->dst);
+                               mm_util_debug("completed_cb %p", &handle->dst);
                        }
 
                        __mm_util_handle_refresh(handle);
                }
        }
 
-       debug_log("exit thread");
+       mm_util_debug("exit thread");
 
        return NULL;
 }
@@ -797,7 +945,7 @@ static int __mm_util_create_thread(mm_util_s *handle)
        int ret = MM_ERROR_NONE;
 
        if (!handle) {
-               debug_error("[ERROR] - handle");
+               mm_util_error("[ERROR] - handle");
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
@@ -807,7 +955,7 @@ static int __mm_util_create_thread(mm_util_s *handle)
        if(!handle->queue) {
                handle->queue = g_async_queue_new();
        } else {
-               debug_error("ERROR - async queue is already created");
+               mm_util_error("ERROR - async queue is already created");
        }
 
        g_cond_init(&(handle->thread_cond));
@@ -815,7 +963,7 @@ static int __mm_util_create_thread(mm_util_s *handle)
        /*create threads*/
        handle->thread = g_thread_new("transform_thread", (GThreadFunc)_mm_util_thread_repeate, (gpointer)handle);
        if(!handle->thread) {
-               debug_error("ERROR - create thread");
+               mm_util_error("ERROR - create thread");
                return MM_ERROR_IMAGE_INTERNAL;
        }
 
@@ -832,28 +980,28 @@ static int __mm_util_processing(mm_util_s *handle)
        unsigned int src_index = 0, dst_index = 0;
 
        if(handle == NULL) {
-               debug_error ("Invalid arguments [tag null]\n");
+               mm_util_error ("Invalid arguments [tag null]");
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if(handle->src_packet == NULL) {
-               debug_error ("[src] media_packet_h");
+               mm_util_error ("[src] media_packet_h");
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if(handle->dst_packet == NULL) {
-               debug_error ("[dst] media_packet_h");
+               mm_util_error ("[dst] media_packet_h");
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if(handle->src_buf_size) {
                handle->src = NULL;
                if(media_packet_get_buffer_data_ptr(handle->src_packet, &handle->src) != MM_ERROR_NONE) {
-                       debug_error ("[src] media_packet_get_extra");
+                       mm_util_error ("[src] media_packet_get_extra");
                        IMGP_FREE(handle->src);
                        return MM_ERROR_IMAGE_INVALID_VALUE;
                }
-               debug_log("src buffer pointer: %p", handle->src);
+               mm_util_debug("src buffer pointer: %p", handle->src);
        }
 
        if(handle->dst_buf_size) {
@@ -861,19 +1009,19 @@ static int __mm_util_processing(mm_util_s *handle)
                if(media_packet_get_buffer_data_ptr(handle->dst_packet, &handle->dst) != MM_ERROR_NONE) {
                        IMGP_FREE(handle->src);
                        IMGP_FREE(handle->dst);
-                       debug_error ("[dst] media_packet_get_extra");
+                       mm_util_error ("[dst] media_packet_get_extra");
                        return MM_ERROR_IMAGE_INVALID_VALUE;
                }
        }
 
-       debug_log("src: %p, dst: %p", handle->src, handle->dst);
+       mm_util_debug("src: %p, dst: %p", handle->src, handle->dst);
 
        dst_buf[src_index] = g_malloc(handle->src_buf_size);
        src_width = handle->src_width;
        src_height = handle->src_height;
        src_format = handle->src_format;
        if (dst_buf[src_index] == NULL) {
-               debug_error ("[multi func] memory allocation error");
+               mm_util_error ("[multi func] memory allocation error");
                IMGP_FREE(handle->src);
                IMGP_FREE(handle->dst);
                return MM_ERROR_IMAGE_INTERNAL;
@@ -884,7 +1032,7 @@ static int __mm_util_processing(mm_util_s *handle)
                mm_util_get_image_size(src_format, handle->dst_width, handle->dst_height, &dst_buf_size);
                dst_buf[dst_index] = g_malloc(dst_buf_size);
                if (dst_buf[dst_index] == NULL) {
-                       debug_error ("[multi func] memory allocation error");
+                       mm_util_error ("[multi func] memory allocation error");
                        IMGP_FREE(handle->src);
                        IMGP_FREE(handle->dst);
                        __mm_destroy_temp_buffer(dst_buf);
@@ -896,8 +1044,8 @@ static int __mm_util_processing(mm_util_s *handle)
                        IMGP_FREE(handle->src);
                        IMGP_FREE(handle->dst);
                        __mm_destroy_temp_buffer(dst_buf);
-                       debug_error("mm_util_crop_image failed");
-                       return MM_ERROR_IMAGE_INTERNAL;
+                       mm_util_error("mm_util_crop_image failed");
+                       return ret;
                }
                src_index = dst_index;
                src_width = handle->dst_width;
@@ -907,7 +1055,7 @@ static int __mm_util_processing(mm_util_s *handle)
                mm_util_get_image_size(src_format, handle->dst_width, handle->dst_height, &dst_buf_size);
                dst_buf[dst_index] = g_malloc(dst_buf_size);
                if (dst_buf[dst_index] == NULL) {
-                       debug_error ("[multi func] memory allocation error");
+                       mm_util_error ("[multi func] memory allocation error");
                        IMGP_FREE(handle->src);
                        IMGP_FREE(handle->dst);
                        __mm_destroy_temp_buffer(dst_buf);
@@ -918,8 +1066,8 @@ static int __mm_util_processing(mm_util_s *handle)
                        IMGP_FREE(handle->src);
                        IMGP_FREE(handle->dst);
                        __mm_destroy_temp_buffer(dst_buf);
-                       debug_error("mm_util_resize_image failed");
-                       return MM_ERROR_IMAGE_INTERNAL;
+                       mm_util_error("mm_util_resize_image failed");
+                       return ret;
                }
                src_index = dst_index;
                src_width = handle->dst_width;
@@ -931,7 +1079,7 @@ static int __mm_util_processing(mm_util_s *handle)
                mm_util_get_image_size(handle->dst_format, handle->dst_width, handle->dst_height, &dst_buf_size);
                dst_buf[dst_index] = g_malloc(dst_buf_size);
                if (dst_buf[dst_index] == NULL) {
-                       debug_error ("[multi func] memory allocation error");
+                       mm_util_error ("[multi func] memory allocation error");
                        IMGP_FREE(handle->src);
                        IMGP_FREE(handle->dst);
                        __mm_destroy_temp_buffer(dst_buf);
@@ -942,8 +1090,8 @@ static int __mm_util_processing(mm_util_s *handle)
                        IMGP_FREE(handle->src);
                        IMGP_FREE(handle->dst);
                        __mm_destroy_temp_buffer(dst_buf);
-                       debug_error("mm_util_convert_colorspace failed");
-                       return MM_ERROR_IMAGE_INTERNAL;
+                       mm_util_error("mm_util_convert_colorspace failed");
+                       return ret;
                }
                src_index = dst_index;
                src_format = handle->dst_format;
@@ -967,7 +1115,7 @@ static int __mm_util_processing(mm_util_s *handle)
                mm_util_get_image_size(src_format, handle->dst_width, handle->dst_height, &dst_buf_size);
                dst_buf[dst_index] = g_malloc(dst_buf_size);
                if (dst_buf[dst_index] == NULL) {
-                       debug_error ("[multi func] memory allocation error");
+                       mm_util_error ("[multi func] memory allocation error");
                        IMGP_FREE(handle->src);
                        IMGP_FREE(handle->dst);
                        __mm_destroy_temp_buffer(dst_buf);
@@ -978,8 +1126,8 @@ static int __mm_util_processing(mm_util_s *handle)
                        IMGP_FREE(handle->src);
                        IMGP_FREE(handle->dst);
                        __mm_destroy_temp_buffer(dst_buf);
-                       debug_error("mm_util_rotate_image failed");
-                       return MM_ERROR_IMAGE_INTERNAL;
+                       mm_util_error("mm_util_rotate_image failed");
+                       return ret;
                }
                src_index = dst_index;
                src_width = handle->dst_width;
@@ -992,6 +1140,8 @@ static int __mm_util_processing(mm_util_s *handle)
        }
        __mm_destroy_temp_buffer(dst_buf);
 
+       mm_util_error("mm_util_processing was finished");
+
        return ret;
 }
 
@@ -1006,42 +1156,42 @@ static int __mm_util_transform_exec(mm_util_s * handle, media_packet_h src_packe
        uint64_t size = 0;
 
        if(media_packet_get_format(src_packet, &src_fmt) != MM_ERROR_NONE) {
-               debug_error("Imedia_packet_get_format)");
+               mm_util_error("Imedia_packet_get_format)");
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if(media_format_get_video_info(src_fmt, &src_mimetype, &src_width, &src_height, &src_avg_bps, &src_max_bps) == MEDIA_FORMAT_ERROR_NONE) {
-               debug_log("[Fotmat: %d] W x H : %d x %d", src_mimetype, src_width, src_height);
+               mm_util_debug("[Fotmat: %d] W x H : %d x %d", src_mimetype, src_width, src_height);
        }
 
        if(__mm_util_check_resolution(src_width, src_height)) {
                /* src */
                handle->src_packet = src_packet;
-               debug_log("src_packet: %p handle->src_packet: %p 0x%2x [W X H] %d X %d", src_packet, handle->src_packet, src_fmt, src_width, src_height);
+               mm_util_debug("src_packet: %p handle->src_packet: %p 0x%2x [W X H] %d X %d", src_packet, handle->src_packet, src_fmt, src_width, src_height);
                if(handle->src_packet) {
                        handle->src_format = __mm_util_mapping_mime_format_to_imgp(src_mimetype);
                        handle->src_width = src_width;
                        handle->src_height = src_height;
                } else {
-                       debug_error("[Error] handle->src");
+                       mm_util_error("[Error] handle->src");
                        media_format_unref(src_fmt);
                        return MM_ERROR_IMAGEHANDLE_NOT_INITIALIZED;
                }
 
                if(media_packet_get_buffer_size(handle->src_packet, &size) == MM_ERROR_NONE) {
                        handle->src_buf_size = (guint)size;
-                       debug_log("src buffer(%p) %d size: %d", handle->src_packet, handle->src_packet, handle->src_buf_size);
+                       mm_util_debug("src buffer(%p) %d size: %d", handle->src_packet, handle->src_packet, handle->src_buf_size);
                } else {
-                       debug_error("Error buffer size");
+                       mm_util_error("Error buffer size");
                }
 
                if(handle->dst_format == MM_UTIL_IMG_FMT_NUM) {
-                       debug_log("dst format is changed");
+                       mm_util_debug("dst format is changed");
                        handle->dst_format = handle->src_format;
                        handle->dst_format_mime = src_mimetype;
                }
 
-               debug_log("src: %p handle->src_packet: %p (%d),(%d X %d)", src_packet, handle->src_packet, handle->src_packet, handle->src_width, handle->src_height);
+               mm_util_debug("src: %p handle->src_packet: %p (%d),(%d X %d)", src_packet, handle->src_packet, handle->src_packet, handle->src_width, handle->src_height);
                if (handle->set_rotate) {
                        if ((handle->set_crop) || (handle->set_resize)) {
                                switch(handle->dst_rotation) {
@@ -1070,7 +1220,7 @@ static int __mm_util_transform_exec(mm_util_s * handle, media_packet_h src_packe
                                                dst_height = handle->dst_height = handle->src_height;
                                                break;
                                        default:
-                                               debug_error("[Error] Wrong dst_rotation");
+                                               mm_util_error("[Error] Wrong dst_rotation");
                                                break;
                                }
                        }
@@ -1083,68 +1233,68 @@ static int __mm_util_transform_exec(mm_util_s * handle, media_packet_h src_packe
                                dst_height = handle->dst_height = handle->src_height;
                        }
                }
-               debug_log("dst (%d X %d)", dst_width, dst_height);
+               mm_util_debug("dst (%d X %d)", dst_width, dst_height);
                if(media_format_make_writable(src_fmt, &dst_fmt) != MEDIA_FORMAT_ERROR_NONE) {
                        media_format_unref(src_fmt);
-                       debug_error("[Error] Writable - dst format");
+                       mm_util_error("[Error] Writable - dst format");
                        return MM_ERROR_IMAGE_INVALID_VALUE;
                }
 
                if(media_format_set_video_mime(dst_fmt, handle->dst_format_mime) != MEDIA_FORMAT_ERROR_NONE) {
                        media_format_unref(src_fmt);
                        media_format_unref(dst_fmt);
-                       debug_error("[Error] Set - video mime");
+                       mm_util_error("[Error] Set - video mime");
                        return MM_ERROR_IMAGE_INVALID_VALUE;
                }
 
                if(media_format_set_video_width(dst_fmt, dst_width) != MEDIA_FORMAT_ERROR_NONE) {
                        media_format_unref(src_fmt);
                        media_format_unref(dst_fmt);
-                       debug_error("[Error] Set - video width");
+                       mm_util_error("[Error] Set - video width");
                        return MM_ERROR_IMAGE_INVALID_VALUE;
                }
 
                if(media_format_set_video_height(dst_fmt, dst_height) != MEDIA_FORMAT_ERROR_NONE) {
                        media_format_unref(src_fmt);
                        media_format_unref(dst_fmt);
-                       debug_error("[Error] Set - video height");
+                       mm_util_error("[Error] Set - video height");
                        return MM_ERROR_IMAGE_INVALID_VALUE;
                }
 
                if(media_format_set_video_avg_bps(dst_fmt, src_avg_bps) != MEDIA_FORMAT_ERROR_NONE) {
                        media_format_unref(src_fmt);
                        media_format_unref(dst_fmt);
-                       debug_error("[Error] Set - video avg bps");
+                       mm_util_error("[Error] Set - video avg bps");
                        return MM_ERROR_IMAGE_INVALID_VALUE;
                }
 
                if(media_format_set_video_max_bps(dst_fmt, src_max_bps) != MEDIA_FORMAT_ERROR_NONE) {
                        media_format_unref(src_fmt);
                        media_format_unref(dst_fmt);
-                       debug_error("[Error] Set - video max bps");
+                       mm_util_error("[Error] Set - video max bps");
                        return MM_ERROR_IMAGE_INVALID_VALUE;
                }
 
                if(media_packet_create_alloc(dst_fmt, (media_packet_finalize_cb)_mm_util_transform_packet_finalize_callback, NULL, &handle->dst_packet) != MM_ERROR_NONE) {
-                       debug_error("[Error] Create allocation memory");
+                       mm_util_error("[Error] Create allocation memory");
                        media_format_unref(src_fmt);
                        media_format_unref(dst_fmt);
                        return MM_ERROR_IMAGE_INVALID_VALUE;
                } else {
-                       debug_log("Success - dst media packet");
+                       mm_util_debug("Success - dst media packet");
                        if(media_packet_get_buffer_size(handle->dst_packet, &size) != MM_ERROR_NONE) {
-                               debug_error("Imedia_packet_get_format)");
+                               mm_util_error("Imedia_packet_get_format)");
                                media_format_unref(src_fmt);
                                media_format_unref(dst_fmt);
                                return MM_ERROR_IMAGE_INVALID_VALUE;
                        }
                        handle->dst_buf_size = (guint)size;
-                       debug_log("handle->src_packet: %p [%d] %d X %d (%d) => handle->dst_packet: %p [%d] %d X %d (%d)",
+                       mm_util_debug("handle->src_packet: %p [%d] %d X %d (%d) => handle->dst_packet: %p [%d] %d X %d (%d)",
                                handle->src_packet, handle->src_format, handle->src_width, handle->src_height, handle->src_buf_size,
                                handle->dst_packet, handle->dst_format,dst_width, dst_height, handle->dst_buf_size);
                }
        }else {
-               debug_error("%d %d", src_width, src_height);
+               mm_util_error("%d %d", src_width, src_height);
                media_format_unref(src_fmt);
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
@@ -1152,7 +1302,7 @@ static int __mm_util_transform_exec(mm_util_s * handle, media_packet_h src_packe
        ret = __mm_util_processing(handle);
 
        if(ret != MM_ERROR_NONE) {
-               debug_error("__mm_util_processing failed");
+               mm_util_error("__mm_util_processing failed");
                IMGP_FREE(handle);
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
@@ -1169,7 +1319,7 @@ _mm_util_handle_finalize(mm_util_s *handle)
        int ret = MM_ERROR_NONE;
 
        if (!handle) {
-               debug_error("[ERROR] - handle");
+               mm_util_error("[ERROR] - handle");
                return MM_ERROR_IMAGE_INTERNAL;
        }
 
@@ -1178,7 +1328,7 @@ _mm_util_handle_finalize(mm_util_s *handle)
                handle->is_finish = TRUE;
                g_mutex_lock (&(handle->thread_mutex));
                g_cond_signal(&(handle->thread_cond));
-               debug_log("===> send signal(finish) to transform_thread");
+               mm_util_debug("===> send signal(finish) to transform_thread");
                g_mutex_unlock (&(handle->thread_mutex));
 
                g_thread_join(handle->thread);
@@ -1193,7 +1343,7 @@ _mm_util_handle_finalize(mm_util_s *handle)
 
        g_cond_clear(&(handle->thread_cond));
 
-       debug_log("Success - Finalize Handle");
+       mm_util_debug("Success - Finalize Handle");
 
        return ret;
 }
@@ -1205,20 +1355,20 @@ int mm_util_create(MMHandleType* MMHandle)
        TTRACE_BEGIN("MM_UTILITY:IMGP:CREATE");
 
        if(MMHandle == NULL) {
-               debug_error ("Invalid arguments [tag null]\n");
+               mm_util_error ("Invalid arguments [tag null]");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        mm_util_s *handle = calloc(1,sizeof(mm_util_s));
        if (!handle) {
-               debug_error("[ERROR] - _handle");
+               mm_util_error("[ERROR] - _handle");
                ret = MM_ERROR_IMAGE_INTERNAL;
        }
 
        ret = __mm_util_handle_init (handle);
        if(ret != MM_ERROR_NONE) {
-               debug_error("_mm_util_handle_init failed");
+               mm_util_error("_mm_util_handle_init failed");
                IMGP_FREE(handle);
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
@@ -1226,11 +1376,11 @@ int mm_util_create(MMHandleType* MMHandle)
 
        ret = __mm_util_create_thread(handle);
        if(ret != MM_ERROR_NONE) {
-               debug_error("ERROR - Create thread");
+               mm_util_error("ERROR - Create thread");
                TTRACE_END();
                return ret;
        } else {
-               debug_log("Success -__mm_util_create_thread");
+               mm_util_debug("Success -__mm_util_create_thread");
        }
 
        *MMHandle = (MMHandleType)handle;
@@ -1247,7 +1397,7 @@ int mm_util_set_hardware_acceleration(MMHandleType MMHandle, bool mode)
        TTRACE_BEGIN("MM_UTILITY:IMGP:SET_HARDWARE_ACCELERATION");
 
        if (!handle) {
-               debug_error("[ERROR] - handle");
+               mm_util_error("[ERROR] - handle");
                TTRACE_END();
                return MM_ERROR_IMAGE_INTERNAL;
        }
@@ -1266,14 +1416,14 @@ int mm_util_set_colorspace_convert(MMHandleType MMHandle, mm_util_img_format col
        TTRACE_BEGIN("MM_UTILITY:IMGP:SET_HARDWARE_ACCELERATION");
 
        if (!handle) {
-               debug_error("[ERROR] - handle");
+               mm_util_error("[ERROR] - handle");
                return MM_ERROR_IMAGE_INTERNAL;
        }
 
        handle->set_convert = TRUE;
        handle->dst_format = colorspace;
        handle->dst_format_mime = __mm_util_mapping_imgp_format_to_mime(colorspace);
-       debug_log("imgp fmt: %d mimetype: %d", handle->dst_format, handle->dst_format_mime);
+       mm_util_debug("imgp fmt: %d mimetype: %d", handle->dst_format, handle->dst_format_mime);
 
        TTRACE_END();
        return ret;
@@ -1287,7 +1437,7 @@ int mm_util_set_resolution(MMHandleType MMHandle, unsigned int width, unsigned i
        TTRACE_BEGIN("MM_UTILITY:IMGP:SET_RESOLUTION");
 
        if (!handle) {
-               debug_error("[ERROR] - handle");
+               mm_util_error("[ERROR] - handle");
                return MM_ERROR_IMAGE_INTERNAL;
        }
 
@@ -1307,7 +1457,7 @@ int mm_util_set_rotation(MMHandleType MMHandle, mm_util_img_rotate_type rotation
        TTRACE_BEGIN("MM_UTILITY:IMGP:SET_ROTATION");
 
        if (!handle) {
-               debug_error("[ERROR] - handle");
+               mm_util_error("[ERROR] - handle");
                TTRACE_END();
                return MM_ERROR_IMAGE_INTERNAL;
        }
@@ -1330,7 +1480,7 @@ int mm_util_set_crop_area(MMHandleType MMHandle, unsigned int start_x, unsigned
        unsigned int dest_height = end_y - start_y;
 
        if (!handle) {
-               debug_error("[ERROR] - handle");
+               mm_util_error("[ERROR] - handle");
                TTRACE_END();
                return MM_ERROR_IMAGE_INTERNAL;
        }
@@ -1353,21 +1503,21 @@ int mm_util_transform(MMHandleType MMHandle, media_packet_h src_packet, mm_util_
        TTRACE_BEGIN("MM_UTILITY:IMGP:TRANSFORM");
 
        if (!handle) {
-               debug_error("[ERROR] - handle");
+               mm_util_error("[ERROR] - handle");
                TTRACE_END();
                return MM_ERROR_IMAGE_INTERNAL;
        }
 
        if(!src_packet) {
-               debug_error("[ERROR] - src_packet");
+               mm_util_error("[ERROR] - src_packet");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        } else {
-               debug_log("src: %p", src_packet);
+               mm_util_debug("src: %p", src_packet);
        }
 
        if(!completed_callback) {
-               debug_error("[ERROR] - completed_callback");
+               mm_util_error("[ERROR] - completed_callback");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
@@ -1378,15 +1528,15 @@ int mm_util_transform(MMHandleType MMHandle, media_packet_h src_packet, mm_util_
                handle->_util_cb->completed_cb= completed_callback;
                handle->_util_cb->user_data = user_data;
        } else {
-               debug_error("[ERROR] _util_cb_s");
+               mm_util_error("[ERROR] _util_cb_s");
        }
 
        if(handle->queue) {
-               debug_log("g_async_queue_push");
+               mm_util_debug("g_async_queue_push");
                g_async_queue_push (handle->queue, GINT_TO_POINTER(src_packet));
                g_mutex_lock (&(handle->thread_mutex));
                g_cond_signal(&(handle->thread_cond));
-               debug_log("===> send signal to transform_thread");
+               mm_util_debug("===> send signal to transform_thread");
                g_mutex_unlock (&(handle->thread_mutex));
        }
 
@@ -1403,19 +1553,19 @@ int mm_util_transform_is_completed(MMHandleType MMHandle, bool *is_completed)
        TTRACE_BEGIN("MM_UTILITY:IMGP:TRANSFORM_IS_COMPLETED");
 
        if (!handle) {
-               debug_error("[ERROR] - handle");
+               mm_util_error("[ERROR] - handle");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if (!is_completed) {
-               debug_error("[ERROR] - is_completed");
+               mm_util_error("[ERROR] - is_completed");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        *is_completed = handle->is_completed;
-       debug_log("[Transform....] %d", *is_completed);
+       mm_util_debug("[Transform....] %d", *is_completed);
 
        TTRACE_END();
        return ret;
@@ -1429,21 +1579,21 @@ int mm_util_destroy(MMHandleType MMHandle)
        TTRACE_BEGIN("MM_UTILITY:IMGP:DESTROY");
 
        if (!handle) {
-               debug_error("[ERROR] - handle");
+               mm_util_error("[ERROR] - handle");
                TTRACE_END();
                return MM_ERROR_IMAGEHANDLE_NOT_INITIALIZED;
        }
 
        /* Close */
        if(_mm_util_handle_finalize(handle) != MM_ERROR_NONE) {
-               debug_error("_mm_util_handle_finalize)");
+               mm_util_error("_mm_util_handle_finalize)");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        IMGP_FREE(handle->_util_cb);
        IMGP_FREE(handle);
-       debug_log("Success - Destroy Handle");
+       mm_util_debug("Success - Destroy Handle");
 
        TTRACE_END();
        return ret;
@@ -1452,141 +1602,188 @@ int mm_util_destroy(MMHandleType MMHandle)
 EXPORT_API int mm_util_convert_colorspace(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format, unsigned char *dst, mm_util_img_format dst_format)
 {
        int ret = MM_ERROR_NONE;
+       unsigned char *output_buffer = NULL;
+       unsigned int output_buffer_size = 0;
 
        TTRACE_BEGIN("MM_UTILITY:IMGP:CONVERT_COLORSPACE");
 
-       if(!src || !dst) {
-               debug_error("invalid mm_util_convert_colorspace\n");
+       mm_util_fenter();
+
+       if (!src || !dst) {
+               mm_util_error("invalid src or dst");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
-       if( (src_format < MM_UTIL_IMG_FMT_YUV420) || (src_format > MM_UTIL_IMG_FMT_NUM) || (dst_format < MM_UTIL_IMG_FMT_YUV420) || (dst_format > MM_UTIL_IMG_FMT_NUM) ) {
-               debug_error("#ERROR# src_format: %d || dst_format:%d value ", src_format, dst_format);
+       if ((src_format < MM_UTIL_IMG_FMT_YUV420) || (src_format > MM_UTIL_IMG_FMT_NUM) || (dst_format < MM_UTIL_IMG_FMT_YUV420) || (dst_format > MM_UTIL_IMG_FMT_NUM)) {
+               mm_util_error("#ERROR# src_format : [%d] dst_format : [%d] value ", src_format, dst_format);
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
-       debug_log("#START#");
-
-       if(__mm_cannot_convert_format(src_format, dst_format)) {
-               debug_error("#ERROR# Cannot Support Image Format Convert");
+       if (__mm_cannot_convert_format(src_format, dst_format)) {
+               mm_util_error("#ERROR# Cannot Support Image Format Convert");
                TTRACE_END();
                return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        }
 
-       debug_log("[src] 0x%2x (%d x %d) [dst] 0x%2x", src, src_width, src_height, dst);
+       mm_util_debug("[src] 0x%2x (%d x %d) [dst] 0x%2x", src, src_width, src_height, dst);
 
        imgp_info_s* _imgp_info_s=(imgp_info_s*)g_malloc0(sizeof(imgp_info_s));
-       if(_imgp_info_s == NULL) {
-               debug_error("ERROR - alloc handle");
+       if (_imgp_info_s == NULL) {
+               mm_util_error("ERROR - alloc handle");
                TTRACE_END();
-               return MM_ERROR_IMAGEHANDLE_NOT_INITIALIZED;
+               return MM_ERROR_IMAGE_NO_FREE_SPACE;
        }
+
        IMGPInfoFunc _mm_util_imgp_func = NULL;
        GModule *_module = NULL;
        imgp_plugin_type_e _imgp_plugin_type_e = 0;
 
        /* Initialize */
-       if(__mm_select_convert_plugin(src_format, dst_format)) {
+       if (__mm_select_convert_plugin(src_format, dst_format)) {
                _imgp_plugin_type_e = IMGP_NEON;
-       }else {
+       } else {
                _imgp_plugin_type_e = IMGP_GSTCS;
        }
-       debug_log("plugin type: %d", _imgp_plugin_type_e);
+
+       mm_util_debug("plugin type: %d", _imgp_plugin_type_e);
+
        _module = __mm_util_imgp_initialize(_imgp_plugin_type_e);
-       debug_log("__mm_util_imgp_initialize: %p", _module);
+       mm_util_debug("__mm_util_imgp_initialize: %p", _module);
+
        if(_module == NULL) { /* when IMGP_NEON is NULL */
                _imgp_plugin_type_e = IMGP_GSTCS;
-               debug_log("You use %s module", PATH_GSTCS_LIB);
+               mm_util_debug("You use %s module", PATH_GSTCS_LIB);
                _module = __mm_util_imgp_initialize(_imgp_plugin_type_e);
        }
-       debug_log("mm_util_imgp_func: %p", _module);
+       mm_util_debug("mm_util_imgp_func: %p", _module);
 
        ret = __mm_set_imgp_info_s(_imgp_info_s, src_format, src_width, src_height, dst_format, src_width, src_height, MM_UTIL_ROTATE_0);
        if(ret != MM_ERROR_NONE) {
-               debug_error("__mm_set_imgp_info_s failed");
+               mm_util_error("__mm_set_imgp_info_s failed");
                __mm_util_imgp_finalize(_module, _imgp_info_s);
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
-       debug_log("Sucess __mm_set_imgp_info_s");
+       mm_util_debug("Sucess __mm_set_imgp_info_s");
+
+       ret = __mm_util_get_buffer_size(dst_format, src_width, src_height, &output_buffer_size);
+       if (ret != MM_ERROR_NONE) {
+               mm_util_error("__mm_set_imgp_info_s failed");
+               __mm_util_imgp_finalize(_module, _imgp_info_s);
+               TTRACE_END();
+               return ret;
+       }
+
+       output_buffer = (unsigned char*)malloc(output_buffer_size);
+       if (output_buffer == NULL) {
+               mm_util_error("malloc failed");
+               __mm_util_imgp_finalize(_module, _imgp_info_s);
+               TTRACE_END();
+               return MM_ERROR_IMAGE_NO_FREE_SPACE;
+       }
+       mm_util_debug("malloc outputbuffer: %p (%d)", output_buffer, output_buffer_size);
 
        /* image processing */
        _mm_util_imgp_func = __mm_util_imgp_process(_module);
-       debug_log("Sucess __mm_util_imgp_process");
+       mm_util_debug("Sucess __mm_util_imgp_process");
 
-       if(_mm_util_imgp_func) {
-               ret=_mm_util_imgp_func(_imgp_info_s, src, dst, IMGP_CSC);
+       if (_mm_util_imgp_func) {
+               ret=_mm_util_imgp_func(_imgp_info_s, src, output_buffer, IMGP_CSC);
                if (ret != MM_ERROR_NONE)
                {
-                       debug_error("image processing failed");
+                       mm_util_error("image processing failed");
                        __mm_util_imgp_finalize(_module, _imgp_info_s);
+                       IMGP_FREE(output_buffer);
                        TTRACE_END();
-                       return MM_ERROR_IMAGE_INVALID_VALUE;
+                       return ret;
                }
-       }else {
-               debug_error("g_module_symbol failed");
+       } else {
+               mm_util_error("g_module_symbol failed");
                __mm_util_imgp_finalize(_module, _imgp_info_s);
+               IMGP_FREE(output_buffer);
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
+       if ((_imgp_info_s->dst_width != _imgp_info_s->output_stride || _imgp_info_s->dst_height != _imgp_info_s->output_elevation) && __mm_is_rgb_format(src_format)) {
+               ret = mm_util_crop_image(output_buffer, _imgp_info_s->output_stride, _imgp_info_s->output_elevation, dst_format, 0, 0, &_imgp_info_s->dst_width, &_imgp_info_s->dst_height, dst);
+               if(ret != MM_ERROR_NONE) {
+                       mm_util_error("__mm_util_imgp_finalize failed");
+                       IMGP_FREE(output_buffer);
+                       TTRACE_END();
+                       return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
+               }
+       } else {
+               memcpy(dst, output_buffer, _imgp_info_s->buffer_size);
+       }
+
        /* Output result*/
-       debug_log("dst: %p dst_width: %d, dst_height: %d, output_stride: %d, output_elevation: %d",
+       mm_util_debug("dst: %p dst_width: %d, dst_height: %d, output_stride: %d, output_elevation: %d",
                        dst, _imgp_info_s->dst_width, _imgp_info_s->dst_height, _imgp_info_s->output_stride, _imgp_info_s->output_elevation);
-       debug_log("#Success# dst");
 
        /* Finalize */
        ret = __mm_util_imgp_finalize(_module, _imgp_info_s);
        if(ret != MM_ERROR_NONE) {
-               debug_error("__mm_util_imgp_finalize failed");
+               mm_util_error("__mm_util_imgp_finalize failed");
+               IMGP_FREE(output_buffer);
                TTRACE_END();
                return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        }
 
+       IMGP_FREE(output_buffer);
+
+       mm_util_fleave();
+
        TTRACE_END();
+
        return ret;
 }
 
 EXPORT_API int mm_util_resize_image(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format, unsigned char *dst, unsigned int *dst_width, unsigned int *dst_height)
 {
        int ret = MM_ERROR_NONE;
+       unsigned char *output_buffer = NULL;
+       unsigned int output_buffer_size = 0;
 
        TTRACE_BEGIN("MM_UTILITY:IMGP:RESIZE_IMAGE");
 
-       if(!src || !dst) {
-               debug_error("invalid argument\n");
+       mm_util_fenter();
+
+       if (!src || !dst) {
+               mm_util_error("invalid argument");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
-       if( (src_format < MM_UTIL_IMG_FMT_YUV420) || (src_format > MM_UTIL_IMG_FMT_NUM) ) {
-               debug_error("#ERROR# src_format value ");
+       if ((src_format < MM_UTIL_IMG_FMT_YUV420) || (src_format > MM_UTIL_IMG_FMT_NUM)) {
+               mm_util_error("#ERROR# src_format value ");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
-       if!dst_width || !dst_height ) {
-               debug_error("#ERROR# dst width/height buffer is NULL");
+       if (!dst_width || !dst_height ) {
+               mm_util_error("#ERROR# dst width/height buffer is NULL");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
-       if!src_width || !src_height) {
-               debug_error("#ERROR# src_width || src_height valuei is 0 ");
+       if (!src_width || !src_height) {
+               mm_util_error("#ERROR# src_width || src_height valuei is 0 ");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
-       debug_log("[src] 0x%2x (%d x %d) [dst] 0x%2x", src, src_width, src_height, dst);
+       mm_util_debug("[src] 0x%2x (%d x %d) [dst] 0x%2x", src, src_width, src_height, dst);
 
        imgp_info_s* _imgp_info_s=(imgp_info_s*)g_malloc0(sizeof(imgp_info_s));
        if(_imgp_info_s == NULL) {
-               debug_error("ERROR - alloc handle");
+               mm_util_error("ERROR - alloc handle");
                TTRACE_END();
-               return MM_ERROR_IMAGEHANDLE_NOT_INITIALIZED;
+               return MM_ERROR_IMAGE_NO_FREE_SPACE;
        }
+
        IMGPInfoFunc _mm_util_imgp_func = NULL;
        GModule *_module = NULL;
        imgp_plugin_type_e _imgp_plugin_type_e = 0;
@@ -1597,122 +1794,157 @@ EXPORT_API int mm_util_resize_image(const unsigned char *src, unsigned int src_w
        }else {
                _imgp_plugin_type_e = IMGP_GSTCS;
        }
-       debug_log("plugin type: %d", _imgp_plugin_type_e);
+       mm_util_debug("plugin type: %d", _imgp_plugin_type_e);
+
        _module = __mm_util_imgp_initialize(_imgp_plugin_type_e);
-       debug_log("__mm_util_imgp_initialize: %p", _module);
+       mm_util_debug("__mm_util_imgp_initialize: %p", _module);
        if(_module == NULL) /* when IMGP_NEON is NULL */
        {
                _imgp_plugin_type_e = IMGP_GSTCS;
-               debug_log("You use %s module", PATH_GSTCS_LIB);
+               mm_util_debug("You use %s module", PATH_GSTCS_LIB);
                _module = __mm_util_imgp_initialize(_imgp_plugin_type_e);
        }
 
-       debug_log("__mm_set_imgp_info_s");
+       mm_util_debug("__mm_set_imgp_info_s");
        ret =__mm_set_imgp_info_s(_imgp_info_s, src_format, src_width, src_height, src_format, *dst_width, *dst_height, MM_UTIL_ROTATE_0);
-       debug_log("__mm_set_imgp_info_s ret: %d", ret);
        if(ret != MM_ERROR_NONE) {
-               debug_error("__mm_set_imgp_info_s failed");
+               mm_util_error("__mm_set_imgp_info_s failed [%d]", ret);
                __mm_util_imgp_finalize(_module, _imgp_info_s);
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
-       debug_log("Sucess __mm_set_imgp_info_s");
+
+       mm_util_debug("Sucess __mm_set_imgp_info_s");
 
        if(g_strrstr(g_module_name (_module), GST)) {
                if(__mm_gst_can_resize_format(_imgp_info_s->input_format_label) == FALSE) {
-                       debug_error("[%s][%05d] #RESIZE ERROR# IMAGE_NOT_SUPPORT_FORMAT");
+                       mm_util_error("[%s][%05d] #RESIZE ERROR# IMAGE_NOT_SUPPORT_FORMAT");
                        __mm_util_imgp_finalize(_module, _imgp_info_s);
                        TTRACE_END();
                        return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
                }
        }
 
+       ret = __mm_util_get_buffer_size(src_format, *dst_width, *dst_height, &output_buffer_size);
+       if (ret != MM_ERROR_NONE) {
+               mm_util_error("__mm_set_imgp_info_s failed");
+               __mm_util_imgp_finalize(_module, _imgp_info_s);
+               TTRACE_END();
+               return ret;
+       }
+
+       output_buffer = (unsigned char*)malloc(output_buffer_size);
+       if (output_buffer == NULL) {
+               mm_util_error("malloc failed");
+               __mm_util_imgp_finalize(_module, _imgp_info_s);
+               TTRACE_END();
+               return MM_ERROR_IMAGE_NO_FREE_SPACE;
+       }
+
+       mm_util_debug("malloc outputbuffer: %p (%d)", output_buffer, output_buffer_size);
+
        /* image processing */
        _mm_util_imgp_func = __mm_util_imgp_process(_module);
-       debug_log("Sucess __mm_util_imgp_process");
-       if(_mm_util_imgp_func) {
-               ret=_mm_util_imgp_func(_imgp_info_s, src, dst, IMGP_RSZ);
-               debug_log("_mm_util_imgp_func, ret: %d", ret);
+       mm_util_debug("Sucess __mm_util_imgp_process");
+       if (_mm_util_imgp_func) {
+               ret=_mm_util_imgp_func(_imgp_info_s, src, output_buffer, IMGP_RSZ);
+               mm_util_debug("_mm_util_imgp_func, ret: %d", ret);
                if (ret != MM_ERROR_NONE)
                {
-                       debug_error("image processing failed");
+                       mm_util_error("image processing failed");
                        __mm_util_imgp_finalize(_module, _imgp_info_s);
+                       IMGP_FREE(output_buffer);
                        TTRACE_END();
-                       return MM_ERROR_IMAGE_INVALID_VALUE;
+                       return ret;
                }
-       }else {
-               debug_error("g_module_symbol failed");
+       } else {
+               mm_util_error("g_module_symbol failed");
                __mm_util_imgp_finalize(_module, _imgp_info_s);
+               IMGP_FREE(output_buffer);
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
+       if ((_imgp_info_s->dst_width != _imgp_info_s->output_stride || _imgp_info_s->dst_height != _imgp_info_s->output_elevation) && __mm_is_rgb_format(src_format)) {
+               mm_util_crop_image(output_buffer, _imgp_info_s->output_stride, _imgp_info_s->output_elevation, src_format, 0, 0, &_imgp_info_s->dst_width, &_imgp_info_s->dst_height, dst);
+               *dst_width = _imgp_info_s->dst_width;
+               *dst_height = _imgp_info_s->dst_height;
+       } else {
+               memcpy(dst, output_buffer, _imgp_info_s->buffer_size);
+               *dst_width = _imgp_info_s->dst_width;
+               *dst_height = _imgp_info_s->dst_height;
+       }
+
        /* Output result*/
-       debug_log("dst: %p dst_width: %d, dst_height: %d, output_stride: %d, output_elevation: %d",
+       mm_util_debug("dst: %p dst_width: %d, dst_height: %d, output_stride: %d, output_elevation: %d",
                        dst, _imgp_info_s->dst_width, _imgp_info_s->dst_height, _imgp_info_s->output_stride, _imgp_info_s->output_elevation);
-       debug_log("#Success# dst");
-
-       *dst_width = _imgp_info_s->dst_width;
-       *dst_height = _imgp_info_s->dst_height;
 
        /* Finalize */
        ret = __mm_util_imgp_finalize(_module, _imgp_info_s);
        if(ret != MM_ERROR_NONE) {
-               debug_error("__mm_util_imgp_finalize failed");
+               mm_util_error("__mm_util_imgp_finalize failed");
+               IMGP_FREE(output_buffer);
                TTRACE_END();
                return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        }
 
+       IMGP_FREE(output_buffer);
+
+       mm_util_fenter();
+
        TTRACE_END();
+
        return ret;
 }
 
 EXPORT_API int mm_util_rotate_image(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format, unsigned char *dst, unsigned int *dst_width, unsigned int *dst_height, mm_util_img_rotate_type angle)
 {
        int ret = MM_ERROR_NONE;
+       unsigned char *output_buffer = NULL;
+       unsigned int output_buffer_size = 0;
 
        TTRACE_BEGIN("MM_UTILITY:IMGP:ROTATE_IMAGE");
 
-       if(!src || !dst) {
-               debug_error("invalid argument\n");
+       mm_util_fenter();
+
+       if (!src || !dst) {
+               mm_util_error("invalid argument");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
-       if( (src_format < MM_UTIL_IMG_FMT_YUV420) || (src_format > MM_UTIL_IMG_FMT_NUM) ) {
-               debug_error("#ERROR# src_format value");
+       if ((src_format < MM_UTIL_IMG_FMT_YUV420) || (src_format > MM_UTIL_IMG_FMT_NUM)) {
+               mm_util_error("#ERROR# src_format value");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
-       if( !dst_width || !dst_height ) {
-               debug_error("#ERROR# dst width/height buffer is NUL");
+       if ( !dst_width || !dst_height ) {
+               mm_util_error("#ERROR# dst width/height buffer is NUL");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
-       if( !src_width || !src_height) {
-               debug_error("#ERROR# src_width || src_height value is 0 ");
+       if ( !src_width || !src_height) {
+               mm_util_error("#ERROR# src_width || src_height value is 0 ");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
-       if( (angle < MM_UTIL_ROTATE_0) || (angle > MM_UTIL_ROTATE_NUM) ) {
-               debug_error("#ERROR# angle vaule");
+       if ((angle < MM_UTIL_ROTATE_0) || (angle > MM_UTIL_ROTATE_NUM)) {
+               mm_util_error("#ERROR# angle vaule");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
-       debug_log("[src] 0x%2x (%d x %d) [dst] 0x%2x", src, src_width, src_height, dst);
+       mm_util_debug("[src] 0x%2x (%d x %d) [dst] 0x%2x", src, src_width, src_height, dst);
 
-       debug_log("#START#");
        imgp_info_s* _imgp_info_s=(imgp_info_s*)g_malloc0(sizeof(imgp_info_s));
        if(_imgp_info_s == NULL) {
-               debug_error("ERROR - alloc handle");
+               mm_util_error("ERROR - alloc handle");
                TTRACE_END();
                return MM_ERROR_IMAGEHANDLE_NOT_INITIALIZED;
        }
-       unsigned int dst_size=0;
        IMGPInfoFunc _mm_util_imgp_func = NULL;
        GModule *_module = NULL;
        imgp_plugin_type_e _imgp_plugin_type_e = 0;
@@ -1723,79 +1955,123 @@ EXPORT_API int mm_util_rotate_image(const unsigned char *src, unsigned int src_w
        }else {
                _imgp_plugin_type_e = IMGP_GSTCS;
        }
-       debug_log("plugin type: %d", _imgp_plugin_type_e);
+       mm_util_debug("plugin type: %d", _imgp_plugin_type_e);
 
        _module = __mm_util_imgp_initialize(_imgp_plugin_type_e);
-       debug_log("__mm_util_imgp_initialize: %p", _module);
+       mm_util_debug("__mm_util_imgp_initialize: %p", _module);
        if(_module == NULL) { /* when IMGP_NEON is NULL */
                _imgp_plugin_type_e = IMGP_GSTCS;
-               debug_log("You use %s module", PATH_GSTCS_LIB);
+               mm_util_debug("You use %s module", PATH_GSTCS_LIB);
                _module = __mm_util_imgp_initialize(_imgp_plugin_type_e);
        }
 
-       debug_log("__mm_confirm_dst_width_height");
+       mm_util_debug("__mm_confirm_dst_width_height");
        ret = __mm_confirm_dst_width_height(src_width, src_height, dst_width, dst_height, angle);
        if(ret != MM_ERROR_NONE) {
-               debug_error("dst_width || dest_height size Error");
+               mm_util_error("dst_width || dest_height size Error");
                __mm_util_imgp_finalize(_module, _imgp_info_s);
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        ret = __mm_set_imgp_info_s(_imgp_info_s, src_format, src_width, src_height, src_format, *dst_width, *dst_height, angle);
-       debug_log("__mm_set_imgp_info_s");
+       mm_util_debug("__mm_set_imgp_info_s");
        if(ret != MM_ERROR_NONE) {
-               debug_error("__mm_set_imgp_info_s failed");
+               mm_util_error("__mm_set_imgp_info_s failed");
                __mm_util_imgp_finalize(_module, _imgp_info_s);
                TTRACE_END();
                return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        }
-       debug_log("Sucess __mm_set_imgp_info_s");
+       mm_util_debug("Sucess __mm_set_imgp_info_s");
 
        if(g_strrstr(g_module_name (_module), GST)) {
                if(__mm_gst_can_rotate_format(_imgp_info_s->input_format_label) == FALSE) {
-                       debug_error("[%s][%05d] #gstreamer ROTATE ERROR# IMAGE_NOT_SUPPORT_FORMAT");
+                       mm_util_error("[%s][%05d] #gstreamer ROTATE ERROR# IMAGE_NOT_SUPPORT_FORMAT");
                        __mm_util_imgp_finalize(_module, _imgp_info_s);
                        TTRACE_END();
                        return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
                }
        }
 
+       ret = __mm_util_get_buffer_size(src_format, *dst_width, *dst_height, &output_buffer_size);
+       if (ret != MM_ERROR_NONE) {
+               mm_util_error("__mm_set_imgp_info_s failed");
+               __mm_util_imgp_finalize(_module, _imgp_info_s);
+               TTRACE_END();
+               return ret;
+       }
+
+       output_buffer = (unsigned char*)malloc(output_buffer_size);
+       if (output_buffer == NULL) {
+               mm_util_error("malloc failed");
+               __mm_util_imgp_finalize(_module, _imgp_info_s);
+               TTRACE_END();
+               return MM_ERROR_IMAGE_NO_FREE_SPACE;
+       }
+
+       mm_util_debug("malloc outputbuffer: %p (%d)", output_buffer, output_buffer_size);
+
        /* image processing */
        _mm_util_imgp_func = __mm_util_imgp_process(_module);
-       debug_log("Sucess __mm_util_imgp_process");
-       if(_mm_util_imgp_func) {
-               ret=_mm_util_imgp_func(_imgp_info_s, src, dst, IMGP_ROT);
+       mm_util_debug("Sucess __mm_util_imgp_process");
+       if (_mm_util_imgp_func) {
+               ret=_mm_util_imgp_func(_imgp_info_s, src, output_buffer, IMGP_ROT);
                if (ret!= MM_ERROR_NONE)        {
-                       debug_error("image processing failed");
+                       mm_util_error("image processing failed");
                        __mm_util_imgp_finalize(_module, _imgp_info_s);
+                       IMGP_FREE(output_buffer);
                        TTRACE_END();
-                       return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
+                       return ret;
                }
-       }else {
-               debug_error("g_module_symbol failed");
+       } else {
+               mm_util_error("g_module_symbol failed");
                __mm_util_imgp_finalize(_module, _imgp_info_s);
+               IMGP_FREE(output_buffer);
                TTRACE_END();
                return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        }
 
-       /* Output result*/
-       debug_log("dst: %p dst_width: %d, dst_height: %d, output_stride: %d, output_elevation: %d, dst_size: %d",
-                       dst, _imgp_info_s->dst_width, _imgp_info_s->dst_height, _imgp_info_s->output_stride, _imgp_info_s->output_elevation,dst_size);
-       debug_log("#Success# dst");
+       if ((_imgp_info_s->dst_width != _imgp_info_s->output_stride || _imgp_info_s->dst_height != _imgp_info_s->output_elevation) && __mm_is_rgb_format(src_format)) {
+               unsigned int start_x = 0;
+               unsigned int start_y = 0;
+               if (angle == MM_UTIL_ROTATE_90) {
+                       start_x = 0;
+                       start_y = 0;
+               } else if (angle == MM_UTIL_ROTATE_180) {
+                       start_x = _imgp_info_s->output_stride-_imgp_info_s->dst_width;
+                       start_y = 0;
+               } else if (angle == MM_UTIL_ROTATE_270) {
+                       start_x = 0;
+                       start_y = _imgp_info_s->output_elevation - _imgp_info_s->dst_height;
+               }
+               mm_util_crop_image(output_buffer, _imgp_info_s->output_stride, _imgp_info_s->output_elevation, src_format, start_x, start_y, &_imgp_info_s->dst_width, &_imgp_info_s->dst_height, dst);
+               *dst_width = _imgp_info_s->dst_width;
+               *dst_height = _imgp_info_s->dst_height;
+       } else {
+               memcpy(dst, output_buffer, _imgp_info_s->buffer_size);
+               *dst_width = _imgp_info_s->dst_width;
+               *dst_height = _imgp_info_s->dst_height;
+       }
 
-       *dst_width = _imgp_info_s->dst_width;
-       *dst_height = _imgp_info_s->dst_height;
+       /* Output result*/
+       mm_util_debug("dst: %p dst_width: %d, dst_height: %d, output_stride: %d, output_elevation: %d",
+                       dst, _imgp_info_s->dst_width, _imgp_info_s->dst_height, _imgp_info_s->output_stride, _imgp_info_s->output_elevation);
 
        /* Finalize */
        ret = __mm_util_imgp_finalize(_module, _imgp_info_s);
        if(ret != MM_ERROR_NONE) {
-               debug_error("__mm_util_imgp_finalize failed");
+               mm_util_error("__mm_util_imgp_finalize failed");
+               IMGP_FREE(output_buffer);
                TTRACE_END();
                return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        }
 
+       IMGP_FREE(output_buffer);
+
+       mm_util_fleave();
+
        TTRACE_END();
+
        return ret;
 }
 
@@ -1807,19 +2083,19 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int *crop_dest_wi
        TTRACE_BEGIN("MM_UTILITY:IMGP:CROP_IMAGE");
 
        if (!src || !dst) {
-               debug_error("invalid argument\n");
+               mm_util_error("invalid argument");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (src_format < MM_UTIL_IMG_FMT_YUV420) || (src_format > MM_UTIL_IMG_FMT_NUM) ) {
-               debug_error("#ERROR# src_format value");
+               mm_util_error("#ERROR# src_format value");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (crop_start_x +*crop_dest_width > src_width) || (crop_start_y +*crop_dest_height > src_height) ) {
-               debug_error("#ERROR# dest width | height value");
+               mm_util_error("#ERROR# dest width | height value");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
@@ -1845,20 +2121,21 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int *crop_dest_wi
                        if((*crop_dest_width %2) !=0) {
                                debug_warning("#YUV Width value(%d) must be even at least# ", *crop_dest_width);
                                *crop_dest_width = ((*crop_dest_width+1)>>1)<<1;
-                               debug_log("Image isplay is suceeded when YUV crop width value %d ",*crop_dest_width);
+                               mm_util_debug("Image isplay is suceeded when YUV crop width value %d ",*crop_dest_width);
                        }
 
                        if((*crop_dest_height%2) !=0) { /* height value must be also even when crop yuv image */
                                debug_warning("#YUV Height value(%d) must be even at least# ", *crop_dest_height);
                                *crop_dest_height = ((*crop_dest_height+1)>>1)<<1;
-                               debug_log("Image isplay is suceeded when YUV crop height value %d ",*crop_dest_height);
+                               mm_util_debug("Image isplay is suceeded when YUV crop height value %d ",*crop_dest_height);
                        }
 
                        ret = __mm_util_crop_yuv420(src, src_width, src_height, src_format, crop_start_x, crop_start_y, *crop_dest_width, *crop_dest_height, dst);
                        break;
                        }
                default:
-                       debug_log("Not supported format");
+                       mm_util_debug("Not supported format");
+                       ret = MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        }
 
        TTRACE_END();
@@ -1876,23 +2153,21 @@ EXPORT_API int mm_util_get_image_size(mm_util_img_format format, unsigned int wi
        TTRACE_BEGIN("MM_UTILITY:IMGP:GET_SIZE");
 
        if (!imgsize) {
-               debug_error("imgsize can't be null\n");
+               mm_util_error("imgsize can't be null");
                TTRACE_END();
                return MM_ERROR_IMAGE_FILEOPEN;
        }
 
        *imgsize = 0;
 
-
        if (check_valid_picture_size(width, height) < 0) {
-               debug_error("invalid width and height\n");
+               mm_util_error("invalid width and height");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        switch (format)
        {
-
                case MM_UTIL_IMG_FMT_I420:
                case MM_UTIL_IMG_FMT_YUV420:
                        x_chroma_shift = 1;
@@ -1911,19 +2186,19 @@ EXPORT_API int mm_util_get_image_size(mm_util_img_format format, unsigned int wi
                case MM_UTIL_IMG_FMT_UYVY:
                case MM_UTIL_IMG_FMT_NV16:
                case MM_UTIL_IMG_FMT_NV61:
-                       stride = MM_UTIL_ROUND_UP_4 (width * 2);
+                       stride = MM_UTIL_ROUND_UP_4 (width) * 2;
                        size = stride * height;
                        *imgsize = size;
                        break;
 
                case MM_UTIL_IMG_FMT_RGB565:
-                       stride = MM_UTIL_ROUND_UP_4 (width * 2);
+                       stride = MM_UTIL_ROUND_UP_4 (width) * 2;
                        size = stride * height;
                        *imgsize = size;
                        break;
 
                case MM_UTIL_IMG_FMT_RGB888:
-                       stride = MM_UTIL_ROUND_UP_4 (width * 3);
+                       stride = MM_UTIL_ROUND_UP_4 (width) * 3;
                        size = stride * height;
                        *imgsize = size;
                        break;
@@ -1953,12 +2228,13 @@ EXPORT_API int mm_util_get_image_size(mm_util_img_format format, unsigned int wi
                        break;
 
                default:
-                       debug_error("Not supported format\n");
+                       mm_util_error("Not supported format");
                        TTRACE_END();
                        return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        }
-       debug_log("format: %d, *imgsize: %d\n", format, *imgsize);
+       mm_util_debug("format: %d, *imgsize: %d\n", format, *imgsize);
 
        TTRACE_END();
        return ret;
 }
+
index df9d181..6cc1211 100755 (executable)
@@ -20,6 +20,7 @@
  */
 #include "mm_util_imgp.h"
 #include "mm_util_imgp_internal.h"
+#include "mm_util_debug.h"
 #include <mm_error.h>
 #define ONE_ALL 0
 #define IMAGE_FORMAT_LABEL_BUFFER_SIZE 4
@@ -29,7 +30,7 @@ bool completed = false;
 
 int packet_finalize_callback(media_packet_h packet, int err, void* userdata)
 {
-       debug_log("==> finalize callback func is called [%d] \n", err);
+       mm_util_debug("==> finalize callback func is called [%d] \n", err);
        return MEDIA_PACKET_FINALIZE;
 }
 
@@ -38,7 +39,7 @@ transform_completed_cb(media_packet_h *packet, int error, void *user_param)
 {
        uint64_t size = 0;
        char output_file[25] = {};
-       debug_log("MMHandle: 0x%2x", MMHandle);
+       mm_util_debug("MMHandle: 0x%2x", MMHandle);
 
        media_format_h dst_fmt;
        media_format_mimetype_e dst_mimetype;
@@ -46,11 +47,12 @@ transform_completed_cb(media_packet_h *packet, int error, void *user_param)
        char *output_fmt = NULL;
 
        if(error == MM_ERROR_NONE) {
-               debug_log("completed");
+               mm_util_debug("completed");
                output_fmt = (char*)malloc(sizeof(char) * IMAGE_FORMAT_LABEL_BUFFER_SIZE);
                if(output_fmt) {
                        if(media_packet_get_format(*packet, &dst_fmt) != MM_ERROR_NONE) {
-                               debug_error("Imedia_packet_get_format");
+                               mm_util_error("Imedia_packet_get_format");
+                               IMGP_FREE(output_fmt);
                                return FALSE;
                        }
 
@@ -62,7 +64,7 @@ transform_completed_cb(media_packet_h *packet, int error, void *user_param)
                                } else {
                                        strncpy(output_fmt,"rgb", strlen("rgb"));
                                }
-                               debug_log("[mimetype: %d] W x H : %d x %d", dst_mimetype, dst_width, dst_height);
+                               mm_util_debug("[mimetype: %d] W x H : %d x %d", dst_mimetype, dst_width, dst_height);
                                snprintf(output_file, 25, "result_%dx%d.%s", dst_width,dst_height, output_fmt);
                        }
                }
@@ -75,24 +77,24 @@ transform_completed_cb(media_packet_h *packet, int error, void *user_param)
                                IMGP_FREE(dst);
                                IMGP_FREE(output_fmt);
                                fclose(fpout);
-                               debug_error ("[dst] media_packet_get_extra");
+                               mm_util_error ("[dst] media_packet_get_extra");
                                return FALSE;
                        }
-                       debug_log("dst: %p [%d]", dst, size);
+                       mm_util_debug("dst: %p [%d]", dst, size);
                        fwrite(dst, 1, size, fpout);
-                       debug_log("FREE");
+                       mm_util_debug("FREE");
                        fclose(fpout);
                }
 
-               debug_log("write result");
-               debug_log("Free (output_fmt)");
+               mm_util_debug("write result");
+               mm_util_debug("Free (output_fmt)");
                IMGP_FREE(output_fmt);
        } else {
-               debug_error("[ERROR] complete cb");
+               mm_util_error("[ERROR] complete cb");
        }
 
        completed = true;
-       debug_log("Destory - dst packet");
+       mm_util_debug("Destory - dst packet");
        media_packet_destroy(*packet);
 
        return TRUE;
@@ -107,16 +109,16 @@ int main(int argc, char *argv[])
        media_packet_h src_packet;
 
        if (argc < 1) {
-               debug_error("[%s][%05d] Usage: ./mm_image_testsuite filename [yuv420 | yuv420p | yuv422 | uyvy | vyuy | nv12 | nv12t | rgb565 | rgb888 | argb | jpeg] width height\n");
+               mm_util_error("[%s][%05d] Usage: ./mm_image_testsuite filename [yuv420 | yuv420p | yuv422 | uyvy | vyuy | nv12 | nv12t | rgb565 | rgb888 | argb | jpeg] width height\n");
                return ret;
        }
 
        /* Create Transform */
        ret = mm_util_create (&MMHandle);
        if(ret == MM_ERROR_NONE) {
-               debug_log("Success - Create Transcode Handle [MMHandle: 0x%2x]", MMHandle);
+               mm_util_debug("Success - Create Transcode Handle [MMHandle: 0x%2x]", MMHandle);
        } else {
-               debug_log("ERROR - Create Transcode Handle");
+               mm_util_debug("ERROR - Create Transcode Handle");
                return ret;
        }
 
@@ -126,119 +128,119 @@ int main(int argc, char *argv[])
        if(media_format_create(&fmt) == MEDIA_FORMAT_ERROR_NONE) {
                if(media_format_set_video_mime(fmt, MEDIA_FORMAT_I420) != MEDIA_FORMAT_ERROR_NONE) {
                        media_format_unref(fmt);
-                       debug_error("[Error] Set - video mime");
+                       mm_util_error("[Error] Set - video mime");
                        return MM_ERROR_IMAGE_INVALID_VALUE;
                }
 
                if(media_format_set_video_width(fmt, 320) != MEDIA_FORMAT_ERROR_NONE) {
                        media_format_unref(fmt);
-                       debug_error("[Error] Set - video width");
+                       mm_util_error("[Error] Set - video width");
                        return MM_ERROR_IMAGE_INVALID_VALUE;
                }
 
                if(media_format_set_video_height(fmt, 240) != MEDIA_FORMAT_ERROR_NONE) {
                        media_format_unref(fmt);
-                       debug_error("[Error] Set - video height");
+                       mm_util_error("[Error] Set - video height");
                        return MM_ERROR_IMAGE_INVALID_VALUE;
                }
 
                if(media_format_set_video_avg_bps(fmt, 15000000) != MEDIA_FORMAT_ERROR_NONE) {
                        media_format_unref(fmt);
-                       debug_error("[Error] Set - video avg bps");
+                       mm_util_error("[Error] Set - video avg bps");
                        return MM_ERROR_IMAGE_INVALID_VALUE;
                }
 
                if(media_format_set_video_max_bps(fmt, 20000000) != MEDIA_FORMAT_ERROR_NONE) {
                        media_format_unref(fmt);
-                       debug_error("[Error] Set - video max bps");
+                       mm_util_error("[Error] Set - video max bps");
                        return MM_ERROR_IMAGE_INVALID_VALUE;
                }
 
-               debug_log("media_format_set_video_info success! w:320, h:240, MEDIA_FORMAT_I420\n");
+               mm_util_debug("media_format_set_video_info success! w:320, h:240, MEDIA_FORMAT_I420\n");
        }
        else {
-               debug_error("media_format_create failed...");
+               mm_util_error("media_format_create failed...");
        }
 
        ret = media_packet_create_alloc(fmt, (media_packet_finalize_cb)packet_finalize_callback, NULL, &src_packet);
        if(ret == MM_ERROR_NONE) {
-               debug_log("Success - Create Media Packet(%p)", src_packet);
+               mm_util_debug("Success - Create Media Packet(%p)", src_packet);
                uint64_t size =0;
                if (media_packet_get_buffer_size(src_packet, &size) == MEDIA_PACKET_ERROR_NONE) {
                        ptr = malloc(size);
                        if (ptr == NULL) {
-                               debug_log("\tmemory allocation failed\n");
+                               mm_util_debug("\tmemory allocation failed\n");
                                return MM_ERROR_IMAGE_INTERNAL;
                        }
                        if (media_packet_get_buffer_data_ptr(src_packet, &ptr) == MEDIA_PACKET_ERROR_NONE) {
                                FILE *fp = fopen(argv[1], "r");
                                if (fp == NULL) {
-                                       debug_log("\tfile open failed %d\n", errno);
+                                       mm_util_debug("\tfile open failed %d\n", errno);
                                        return MM_ERROR_IMAGE_INTERNAL;
                                }
                                src = malloc(size);
                                if (src == NULL) {
-                                       debug_log("\tmemory allocation failed\n");
+                                       mm_util_debug("\tmemory allocation failed\n");
                                        return MM_ERROR_IMAGE_INTERNAL;
                                }
                                if(fread(src, 1, (int)size, fp)) {
-                                       debug_log("#Success# fread");
+                                       mm_util_debug("#Success# fread");
                                        memcpy(ptr, src, (int)size);
-                                       debug_log("memcpy");
+                                       mm_util_debug("memcpy");
                                } else {
-                                       debug_error("#Error# fread");
+                                       mm_util_error("#Error# fread");
                                }
                        }
                }
        } else {
-               debug_log("ERROR - Create Media Packet");
+               mm_util_debug("ERROR - Create Media Packet");
                return ret;
        }
 
        /* Set Source */
        ret = mm_util_set_hardware_acceleration(MMHandle, atoi(argv[2]));
        if(ret == MM_ERROR_NONE) {
-               debug_log("Success - Set hardware_acceleration");
+               mm_util_debug("Success - Set hardware_acceleration");
        } else {
-               debug_log("ERROR - Set hardware_acceleration");
+               mm_util_debug("ERROR - Set hardware_acceleration");
                return ret;
        }
 
        ret = mm_util_set_resolution(MMHandle, 176, 144);
        if(ret == MM_ERROR_NONE) {
-               debug_log("Success - Set Convert Info");
+               mm_util_debug("Success - Set Convert Info");
        } else {
                media_format_unref(fmt);
-               debug_log("ERROR - Set Convert Info");
+               mm_util_debug("ERROR - Set Convert Info");
                return ret;
        }
 
        /* Transform */
        ret = mm_util_transform(MMHandle, src_packet, (mm_util_completed_callback) transform_completed_cb, handle);
        if(ret == MM_ERROR_NONE) {
-               debug_log("Success - Transform");
+               mm_util_debug("Success - Transform");
        } else {
                media_format_unref(fmt);
-               debug_error("ERROR - Transform");
+               mm_util_error("ERROR - Transform");
                return ret;
        }
 
-       debug_log("Wait...");
+       mm_util_debug("Wait...");
        while (false == completed) {} // polling
 
        ret = mm_util_destroy(MMHandle);
        if(ret == MM_ERROR_NONE) {
-               debug_log("Success - Destroy");
+               mm_util_debug("Success - Destroy");
        } else {
                media_format_unref(fmt);
-               debug_error("ERROR - Destroy");
+               mm_util_error("ERROR - Destroy");
                return ret;
        }
 
        media_format_unref(fmt);
-       debug_log("Destory - src packet");
+       mm_util_debug("Destory - src packet");
        media_packet_destroy(src_packet);
-       debug_log("destroy");
+       mm_util_debug("destroy");
 
        return ret;
 }
index 66f3597..193be24 100755 (executable)
@@ -48,6 +48,7 @@
 #include <mm_attrs_private.h>
 #include "mm_util_jpeg.h"
 #include "mm_util_imgp.h"
+#include "mm_util_debug.h"
 #ifdef ENABLE_TTRACE
 #include <ttrace.h>
 #define TTRACE_BEGIN(NAME) traceBegin(TTRACE_TAG_IMAGE, NAME)
 #define mm_util_stderror(fmt) do { \
                        char buf[ERR_BUF_LENGHT] = {0,}; \
                        strerror_r(errno, buf, ERR_BUF_LENGHT); \
-                       debug_error(fmt" : standard error= [%s]", buf); \
+                       mm_util_error(fmt" : standard error= [%s]", buf); \
                } while (0)
 
+#define IMG_JPEG_FREE(src) { if(src != NULL) {free(src); src = NULL;} }
+
 #if LIBJPEG_TURBO
 #define PAD(v, p) ((v+(p)-1)&(~((p)-1)))
 #define _throwtj() {printf("TurboJPEG ERROR:\n%s\n", tjGetErrorStr());}
@@ -130,7 +133,7 @@ mm_image_codec_writeJPEG(unsigned char *jpegBuf, unsigned long jpegSize, char *f
 {
        FILE *file=fopen(filename, "wb");
        if(!file || fwrite(jpegBuf, jpegSize, 1, file)!=1) {
-               debug_error("ERROR: Could not write to %s", filename);
+               mm_util_error("ERROR: Could not write to %s", filename);
                mm_util_stderror("ERROR: Could not write");
        }
 
@@ -149,16 +152,16 @@ _mm_decode_libjpeg_turbo_decompress(tjhandle handle, unsigned char *jpegBuf, uns
        tjscalingfactor*sf=tjGetScalingFactors(&n), sf1={1, 1};
 
        if(jpegBuf == NULL) {
-               debug_error("jpegBuf is NULL");
+               mm_util_error("jpegBuf is NULL");
                return;
        }
 
-       debug_log("0x%2x, 0x%2x ", jpegBuf[0], jpegBuf[1]);
+       mm_util_debug("0x%2x, 0x%2x ", jpegBuf[0], jpegBuf[1]);
 
        _tj(tjDecompressHeader2(handle, jpegBuf, jpegSize, &_hdrw, &_hdrh, &_hdrsubsamp));
 
        if(!sf || !n) {
-               debug_error(" scaledfactor is NULL");
+               mm_util_error(" scaledfactor is NULL");
                return;
        }
 
@@ -170,43 +173,43 @@ _mm_decode_libjpeg_turbo_decompress(tjhandle handle, unsigned char *jpegBuf, uns
 
        scaledWidth=TJSCALED(_hdrw, _sf);
        scaledHeight=TJSCALED(_hdrh, _sf);
-       debug_log("_hdrw:%d _hdrh:%d, _hdrsubsamp:%d, scaledWidth:%d, scaledHeight:%d",  _hdrw, _hdrh, _hdrsubsamp, scaledWidth, scaledHeight);
+       mm_util_debug("_hdrw:%d _hdrh:%d, _hdrsubsamp:%d, scaledWidth:%d, scaledHeight:%d",  _hdrw, _hdrh, _hdrsubsamp, scaledWidth, scaledHeight);
 
        if(input_fmt==MM_UTIL_JPEG_FMT_YUV420 || input_fmt==MM_UTIL_JPEG_FMT_YUV422) {
-               debug_log("JPEG -> YUV %s ... ", subName[_hdrsubsamp]);
+               mm_util_debug("JPEG -> YUV %s ... ", subName[_hdrsubsamp]);
        } else if(input_fmt==MM_UTIL_JPEG_FMT_RGB888) {
-               debug_log("JPEG -> RGB %d/%d ... ", _sf.num, _sf.denom);
+               mm_util_debug("JPEG -> RGB %d/%d ... ", _sf.num, _sf.denom);
        }
 
        if(input_fmt==MM_UTIL_JPEG_FMT_YUV420 || input_fmt==MM_UTIL_JPEG_FMT_YUV422) {
                dstSize=TJBUFSIZEYUV(_hdrw, _hdrh, _hdrsubsamp);
-               debug_log("MM_UTIL_JPEG_FMT_YUV420 dstSize: %d  _hdrsubsamp:%d TJBUFSIZEYUV(w, h, _hdrsubsamp): %d",
+               mm_util_debug("MM_UTIL_JPEG_FMT_YUV420 dstSize: %d  _hdrsubsamp:%d TJBUFSIZEYUV(w, h, _hdrsubsamp): %d",
                        dstSize, _hdrsubsamp, TJBUFSIZEYUV(_hdrw, _hdrh, _hdrsubsamp));
        }
        else if(input_fmt==MM_UTIL_JPEG_FMT_RGB888)
        {
                dstSize=scaledWidth*scaledHeight*tjPixelSize[TJPF_RGB];
-               debug_log("MM_UTIL_JPEG_FMT_RGB888 dstSize: %d _hdrsubsamp:%d", dstSize, _hdrsubsamp);
+               mm_util_debug("MM_UTIL_JPEG_FMT_RGB888 dstSize: %d _hdrsubsamp:%d", dstSize, _hdrsubsamp);
        }
 
        if((decoded_data->data=(void*)malloc(dstSize))==NULL) {
-               debug_error("dstBuf is NULL");
+               mm_util_error("dstBuf is NULL");
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
-       debug_log("dstBuf:%p", decoded_data->data);
+       mm_util_debug("dstBuf:%p", decoded_data->data);
 
        if(input_fmt==MM_UTIL_JPEG_FMT_YUV420 || input_fmt==MM_UTIL_JPEG_FMT_YUV422) {
                _tj(tjDecompressToYUV(handle, jpegBuf, jpegSize, decoded_data->data, TD_BU));
-               debug_log("MM_UTIL_JPEG_FMT_YUV420, dstBuf: %d", decoded_data->data);
+               mm_util_debug("MM_UTIL_JPEG_FMT_YUV420, dstBuf: %d", decoded_data->data);
                decoded_data->format=input_fmt;
        }
        else if(input_fmt==MM_UTIL_JPEG_FMT_RGB888) {
                _tj(tjDecompress2(handle, jpegBuf, jpegSize, decoded_data->data, scaledWidth, 0, scaledHeight, TJPF_RGB, TD_BU));
-               debug_log("MM_UTIL_JPEG_FMT_RGB888, dstBuf: %p", decoded_data->data);
+               mm_util_debug("MM_UTIL_JPEG_FMT_RGB888, dstBuf: %p", decoded_data->data);
                decoded_data->format=MM_UTIL_JPEG_FMT_RGB888;
        } else {
-               debug_error("[%s][%05d] We can't support the IMAGE format");
+               mm_util_error("[%s][%05d] We can't support the IMAGE format");
                return;
        }
 
@@ -220,7 +223,7 @@ _mm_decode_libjpeg_turbo_decompress(tjhandle handle, unsigned char *jpegBuf, uns
        else if(input_fmt==MM_UTIL_JPEG_FMT_YUV420 ||input_fmt==MM_UTIL_JPEG_FMT_YUV422)
        {
                if(_hdrsubsamp == TJSAMP_422) {
-                       debug_log("_hdrsubsamp == TJSAMP_422", decoded_data->width, _hdrw);
+                       mm_util_debug("_hdrsubsamp == TJSAMP_422", decoded_data->width, _hdrw);
                        decoded_data->width=MM_JPEG_ROUND_UP_2(_hdrw);
                } else {
                        if(_hdrw% 4 != 0) {
@@ -231,7 +234,7 @@ _mm_decode_libjpeg_turbo_decompress(tjhandle handle, unsigned char *jpegBuf, uns
                }
 
                if(_hdrsubsamp == TJSAMP_420) {
-                       debug_log("_hdrsubsamp == TJSAMP_420", decoded_data->width, _hdrw);
+                       mm_util_debug("_hdrsubsamp == TJSAMP_420", decoded_data->width, _hdrw);
                        if(_hdrh% 4 != 0) {
                                decoded_data->height=MM_JPEG_ROUND_UP_4(_hdrh);
                        } else {
@@ -255,7 +258,7 @@ mm_image_decode_from_jpeg_file_with_libjpeg_turbo(mm_util_jpeg_yuv_data * decode
 
        void *src = fopen(pFileName, "rb" );
        if(src == NULL) {
-               debug_error("Error [%s] failed", pFileName);
+               mm_util_error("Error [%s] failed", pFileName);
                mm_util_stderror("Error file open failed");
                return MM_ERROR_IMAGE_FILEOPEN;
        }
@@ -265,22 +268,22 @@ mm_image_decode_from_jpeg_file_with_libjpeg_turbo(mm_util_jpeg_yuv_data * decode
 
        if((dhandle=tjInitDecompress())==NULL) {
                fclose(src);
-               debug_error("dhandle=tjInitDecompress()) is NULL");
+               mm_util_error("dhandle=tjInitDecompress()) is NULL");
                return MM_ERROR_IMAGEHANDLE_NOT_INITIALIZED;
        }
        srcBuf=(unsigned char *)malloc(sizeof(char) * jpegSize);
        if(srcBuf==NULL) {
                fclose(src);
                tjDestroy(dhandle);
-               debug_error("srcBuf is NULL");
+               mm_util_error("srcBuf is NULL");
                return MM_ERROR_IMAGE_NO_FREE_SPACE;
        }
 
        fread(srcBuf,1, jpegSize, src);
-       debug_log("srcBuf[0]: 0x%2x, srcBuf[1]: 0x%2x, jpegSize:%d", srcBuf[0], srcBuf[1], jpegSize);
+       mm_util_debug("srcBuf[0]: 0x%2x, srcBuf[1]: 0x%2x, jpegSize:%d", srcBuf[0], srcBuf[1], jpegSize);
        _mm_decode_libjpeg_turbo_decompress(dhandle, srcBuf, jpegSize, TD_BU, decoded_data, input_fmt);
        fclose(src);
-       debug_log("fclose");
+       mm_util_debug("fclose");
 
        if(dhandle) {
                tjDestroy(dhandle);
@@ -301,18 +304,18 @@ mm_image_decode_from_jpeg_memory_with_libjpeg_turbo(mm_util_jpeg_yuv_data * deco
        int TD_BU=0;
 
        if((dhandle=tjInitDecompress())==NULL) {
-               debug_error("dhandle=tjInitDecompress()) is NULL");
+               mm_util_error("dhandle=tjInitDecompress()) is NULL");
                return MM_ERROR_IMAGEHANDLE_NOT_INITIALIZED;
        }
        srcBuf=(unsigned char *)malloc(sizeof(char) * size);
        if(srcBuf==NULL) {
                fclose(src);
                tjDestroy(dhandle);
-               debug_error("srcBuf is NULL");
+               mm_util_error("srcBuf is NULL");
                return MM_ERROR_IMAGE_NO_FREE_SPACE;
        }
 
-       debug_log("srcBuf[0]: 0x%2x, srcBuf[1]: 0x%2x, jpegSize:%d", srcBuf[0], srcBuf[1], size);
+       mm_util_debug("srcBuf[0]: 0x%2x, srcBuf[1]: 0x%2x, jpegSize:%d", srcBuf[0], srcBuf[1], size);
        _mm_decode_libjpeg_turbo_decompress(dhandle, src, size, TD_BU, decoded_data, input_fmt);
 
        if(dhandle) {
@@ -335,42 +338,41 @@ _mm_encode_libjpeg_turbo_compress(tjhandle handle, void *src, unsigned char **ds
        srcBuf=(unsigned char *)malloc(jpegSize);
 
        if(srcBuf==NULL) {
-               debug_error("srcBuf is NULL");
+               mm_util_error("srcBuf is NULL");
                return;
        } else {
-               debug_log("srcBuf: 0x%2x", srcBuf);
+               mm_util_debug("srcBuf: 0x%2x", srcBuf);
                if(fmt==MM_UTIL_JPEG_FMT_RGB888) {
                        initBuf(srcBuf, w, h, TJPF_RGB, flags);
                } else if(fmt==MM_UTIL_JPEG_FMT_YUV420 || fmt==MM_UTIL_JPEG_FMT_YUV422) {
                        initBuf(srcBuf, w, h, TJPF_GRAY, flags);
                } else {
-                       free(srcBuf);
-                       debug_error("[%s][%05d] We can't support the IMAGE format");
+                       IMG_JPEG_FREE(srcBuf);
+                       mm_util_error("[%s][%05d] We can't support the IMAGE format");
                        return;
                }
                memcpy(srcBuf, src, jpegSize);
        }
 
        if(*dstBuf && *dstSize>0) memset(*dstBuf, 0, *dstSize);
-       debug_log("Done.");
+       mm_util_debug("Done.");
        *dstSize=TJBUFSIZE(w, h);
        if(fmt==MM_UTIL_JPEG_FMT_RGB888) {
                _tj(tjCompress2(handle, srcBuf, w, 0, h, TJPF_RGB, dstBuf, dstSize, TJPF_RGB, jpegQual, flags));
-               debug_log("*dstSize: %d", *dstSize);
+               mm_util_debug("*dstSize: %d", *dstSize);
        } else if(fmt==MM_UTIL_JPEG_FMT_YUV420) {
                *dstSize=TJBUFSIZEYUV(w, h, TJSAMP_420);
                _tj(tjEncodeYUV2(handle, srcBuf, w, 0, h, TJPF_RGB, *dstBuf, TJSAMP_420, flags));
-               debug_log("*dstSize: %d \t decode_yuv_subsample: %d TJBUFSIZE(w, h):%d", *dstSize, TJSAMP_420, TJBUFSIZE(w, h));
+               mm_util_debug("*dstSize: %d \t decode_yuv_subsample: %d TJBUFSIZE(w, h):%d", *dstSize, TJSAMP_420, TJBUFSIZE(w, h));
        } else if(fmt==MM_UTIL_JPEG_FMT_YUV422) {
                *dstSize=TJBUFSIZEYUV(w, h, TJSAMP_422);
                _tj(tjEncodeYUV2(handle, srcBuf, w, 0, h, TJPF_RGB, *dstBuf, TJSAMP_422, flags));
-               debug_log("*dstSize: %d \t decode_yuv_subsample: %d TJBUFSIZE(w, h):%d", *dstSize, TJSAMP_422, TJBUFSIZE(w, h));
+               mm_util_debug("*dstSize: %d \t decode_yuv_subsample: %d TJBUFSIZE(w, h):%d", *dstSize, TJSAMP_422, TJBUFSIZE(w, h));
        } else {
-               debug_error("fmt:%d  is wrong", fmt);
-       }
-       if(srcBuf) {
-               free(srcBuf);
+               mm_util_error("fmt:%d  is wrong", fmt);
        }
+
+       IMG_JPEG_FREE(srcBuf);
 }
 
 static int
@@ -383,27 +385,27 @@ mm_image_encode_to_jpeg_file_with_libjpeg_turbo(char *filename, void* src, int w
        int TD_BU=0;
        FILE *fout=fopen(filename, "w+");
        if(fout == NULL) {
-               debug_error("FILE OPEN FAIL [%s] failed", filename);
+               mm_util_error("FILE OPEN FAIL [%s] failed", filename);
                mm_util_stderror("FILE OPEN FAIL");
                return MM_ERROR_IMAGE_FILEOPEN;
        }
-       debug_log("fmt: %d", fmt);
+       mm_util_debug("fmt: %d", fmt);
 
        size=TJBUFSIZE(width, height);
        if((dstBuf=(unsigned char *)tjAlloc(size))==NULL) {
                fclose(fout);
-               debug_error("dstBuf is NULL");
+               mm_util_error("dstBuf is NULL");
                return MM_ERROR_IMAGE_NO_FREE_SPACE;
        }
 
        if((chandle=tjInitCompress())==NULL) {
                fclose(fout);
                tjFree(dstBuf);
-               debug_error("dstBuf is NULL");
+               mm_util_error("dstBuf is NULL");
                return MM_ERROR_IMAGEHANDLE_NOT_INITIALIZED;
        }
        _mm_encode_libjpeg_turbo_compress(chandle, src, &dstBuf, &size, width, height, quality, TD_BU, fmt);
-       debug_log("dstBuf: %p\t size: %d", dstBuf, size);
+       mm_util_debug("dstBuf: %p\t size: %d", dstBuf, size);
        fwrite(dstBuf, 1, size, fout);
        fclose(fout);
        if(chandle) {
@@ -412,7 +414,7 @@ mm_image_encode_to_jpeg_file_with_libjpeg_turbo(char *filename, void* src, int w
        if(dstBuf) {
                tjFree(dstBuf);
        }
-       debug_log("Done");
+       mm_util_debug("Done");
        return iErrorCode;
 }
 
@@ -425,28 +427,28 @@ mm_image_encode_to_jpeg_memory_with_libjpeg_turbo(void **mem, int *csize, void *
 
        *csize=TJBUFSIZE(w, h);
        if(fmt==MM_UTIL_JPEG_FMT_RGB888) {
-               debug_log("MM_UTIL_JPEG_FMT_RGB888 size: %d", *csize);
+               mm_util_debug("MM_UTIL_JPEG_FMT_RGB888 size: %d", *csize);
        }else if(fmt==MM_UTIL_JPEG_FMT_YUV420 ||fmt==MM_UTIL_JPEG_FMT_YUV422) {
-               debug_log("TJSAMP_420 ||TJSAMP_422 size: %d",*csize);
+               mm_util_debug("TJSAMP_420 ||TJSAMP_422 size: %d",*csize);
        }else {
-                       debug_error("We can't support the IMAGE format");
+                       mm_util_error("We can't support the IMAGE format");
                        return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        }
 
        if((*mem=(unsigned char *)tjAlloc(*csize))==NULL) {
-               debug_error("dstBuf is NULL");
+               mm_util_error("dstBuf is NULL");
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if((chandle=tjInitCompress())==NULL) {
                tjFree(*mem);
-               debug_error("chandle is NULL");
+               mm_util_error("chandle is NULL");
                return MM_ERROR_IMAGEHANDLE_NOT_INITIALIZED;
        }
 
-       debug_log("width: %d height: %d, size: %d", w, h, *csize);
+       mm_util_debug("width: %d height: %d, size: %d", w, h, *csize);
        _mm_encode_libjpeg_turbo_compress(chandle, rawdata, mem, csize, w, h, quality, TD_BU, fmt);
-       debug_log("dstBuf: %p &dstBuf:%p size: %d", *mem, mem, *csize);
+       mm_util_debug("dstBuf: %p &dstBuf:%p size: %d", *mem, mem, *csize);
        if(chandle) {
                tjDestroy(chandle);
        }
@@ -507,7 +509,7 @@ static int mm_image_encode_to_jpeg_file_with_libjpeg(const char *pFileName, void
        JSAMPROW y[16],cb[16],cr[16]; /* y[2][5] = color sample of row 2 and pixel column 5; (one plane) */
        JSAMPARRAY data[3]; /* t[0][2][5] = color sample 0 of row 2 and column 5 */
        if(!pFileName) {
-               debug_error("pFileName");
+               mm_util_error("pFileName");
                return MM_ERROR_IMAGE_FILEOPEN;
        }
 
@@ -515,14 +517,14 @@ static int mm_image_encode_to_jpeg_file_with_libjpeg(const char *pFileName, void
        data[1] = cb;
        data[2] = cr;
 
-       debug_log("Enter");
+       mm_util_debug("Enter");
 
        cinfo.err = jpeg_std_error(&jerr);
 
        jpeg_create_compress(&cinfo);
 
        if ((fpWriter = fopen(pFileName, "wb")) == NULL) {
-               debug_error("[infile] file open [%s] failed", pFileName);
+               mm_util_error("[infile] file open [%s] failed", pFileName);
                mm_util_stderror("file open failed");
                return MM_ERROR_IMAGE_FILEOPEN;
        }
@@ -531,17 +533,17 @@ static int mm_image_encode_to_jpeg_file_with_libjpeg(const char *pFileName, void
        cinfo.image_width = width;
        cinfo.image_height = height;
        if (fmt ==MM_UTIL_JPEG_FMT_YUV420 ||fmt ==MM_UTIL_JPEG_FMT_YUV422 || fmt ==MM_UTIL_JPEG_FMT_UYVY) {
-               debug_log("[mm_image_encode_to_jpeg_file_with_libjpeg] jpeg_stdio_dest for YUV");
-               debug_log("[Height] %d", height);
+               mm_util_debug("[mm_image_encode_to_jpeg_file_with_libjpeg] jpeg_stdio_dest for YUV");
+               mm_util_debug("[Height] %d", height);
                _height = MM_JPEG_ROUND_DOWN_16(height);
                flag = height - _height;
 
                cinfo.input_components = 3;
                cinfo.in_color_space = JCS_YCbCr;
-               debug_log("JCS_YCbCr [%d] ", flag);
+               mm_util_debug("JCS_YCbCr [%d] ", flag);
 
                jpeg_set_defaults(&cinfo);
-               debug_log("jpeg_set_defaults");
+               mm_util_debug("jpeg_set_defaults");
 
                cinfo.raw_data_in = TRUE; /*  Supply downsampled data */
                cinfo.do_fancy_downsampling = FALSE;
@@ -558,11 +560,11 @@ static int mm_image_encode_to_jpeg_file_with_libjpeg(const char *pFileName, void
                cinfo.comp_info[2].v_samp_factor = 1;
 
                jpeg_set_quality(&cinfo, quality, TRUE);
-               debug_log("jpeg_set_quality");
+               mm_util_debug("jpeg_set_quality");
                cinfo.dct_method = JDCT_FASTEST;
 
                jpeg_start_compress(&cinfo, TRUE);
-               debug_log("jpeg_start_compress");
+               mm_util_debug("jpeg_start_compress");
 
                if(flag) {
                        void *large_rect = malloc (width);
@@ -570,15 +572,15 @@ static int mm_image_encode_to_jpeg_file_with_libjpeg(const char *pFileName, void
                        if(large_rect) {
                                memset(large_rect, 0x10, width);
                        } else {
-                               free(small_rect);
-                               debug_error("large rectangle memory");
+                               IMG_JPEG_FREE(small_rect);
+                               mm_util_error("large rectangle memory");
                                return MM_ERROR_IMAGEHANDLE_NOT_INITIALIZED;
                        }
                        if(small_rect) {
                                memset(small_rect, 0x80, width);
                        } else {
-                               free(large_rect);
-                               debug_error("small rectangle memory");
+                               IMG_JPEG_FREE(large_rect);
+                               mm_util_error("small rectangle memory");
                                return MM_ERROR_IMAGEHANDLE_NOT_INITIALIZED;
                        }
 
@@ -607,8 +609,8 @@ static int mm_image_encode_to_jpeg_file_with_libjpeg(const char *pFileName, void
                                }
                        }
                        jpeg_write_raw_data(&cinfo, data, 16);
-                       free(large_rect);
-                       free(small_rect);
+                       IMG_JPEG_FREE(large_rect);
+                       IMG_JPEG_FREE(small_rect);
                } else {
                        for (j = 0; j < height; j += 16) {
                                for (i = 0; i < 16; i++) {
@@ -621,13 +623,13 @@ static int mm_image_encode_to_jpeg_file_with_libjpeg(const char *pFileName, void
                                jpeg_write_raw_data(&cinfo, data, 16);
                        }
                }
-               debug_log("#for loop#");
+               mm_util_debug("#for loop#");
 
                jpeg_finish_compress(&cinfo);
-               debug_log("jpeg_finish_compress");
+               mm_util_debug("jpeg_finish_compress");
 
                jpeg_destroy_compress(&cinfo);
-               debug_log("jpeg_destroy_compress");
+               mm_util_debug("jpeg_destroy_compress");
        } 
 
        else if (fmt == MM_UTIL_JPEG_FMT_RGB888 ||fmt == MM_UTIL_JPEG_FMT_GraySacle || fmt == MM_UTIL_JPEG_FMT_RGBA8888 || fmt == MM_UTIL_JPEG_FMT_BGRA8888 || fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
@@ -637,31 +639,31 @@ static int mm_image_encode_to_jpeg_file_with_libjpeg(const char *pFileName, void
                if(fmt == MM_UTIL_JPEG_FMT_RGB888) {
                        cinfo.input_components = 3;
                        cinfo.in_color_space = JCS_RGB;
-                       debug_log("JCS_RGB");
+                       mm_util_debug("JCS_RGB");
                } else if(fmt == MM_UTIL_JPEG_FMT_GraySacle) {
                        cinfo.input_components = 1; /* one colour component */
                        cinfo.in_color_space = JCS_GRAYSCALE;
-                       debug_log("JCS_GRAYSCALE");
+                       mm_util_debug("JCS_GRAYSCALE");
                } else if(fmt == MM_UTIL_JPEG_FMT_RGBA8888) {
                        cinfo.input_components = 4; /* one colour component */
                        cinfo.in_color_space = JCS_EXT_RGBA;
-                       debug_log("JCS_EXT_RGBA");
+                       mm_util_debug("JCS_EXT_RGBA");
                } else if(fmt == MM_UTIL_JPEG_FMT_BGRA8888) {
                        cinfo.input_components = 4;
                        cinfo.in_color_space = JCS_EXT_BGRA;
-                       debug_log("JCS_EXT_BGRA");
+                       mm_util_debug("JCS_EXT_BGRA");
                } else if(fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
                        cinfo.input_components = 4;
                        cinfo.in_color_space = JCS_EXT_ARGB;
-                       debug_log("JCS_EXT_ARGB");
+                       mm_util_debug("JCS_EXT_ARGB");
                }
 
                jpeg_set_defaults(&cinfo);
-               debug_log("jpeg_set_defaults");
+               mm_util_debug("jpeg_set_defaults");
                jpeg_set_quality(&cinfo, quality, TRUE);
-               debug_log("jpeg_set_quality");
+               mm_util_debug("jpeg_set_quality");
                jpeg_start_compress(&cinfo, TRUE);
-               debug_log("jpeg_start_compress");
+               mm_util_debug("jpeg_start_compress");
                if(fmt == MM_UTIL_JPEG_FMT_RGB888) {
                        iRowStride = width * 3;
                } else if(fmt == MM_UTIL_JPEG_FMT_GraySacle) {
@@ -676,18 +678,18 @@ static int mm_image_encode_to_jpeg_file_with_libjpeg(const char *pFileName, void
                        row_pointer[0] = & image_buffer[cinfo.next_scanline * iRowStride];
                        jpeg_write_scanlines(&cinfo, row_pointer, 1);
                }
-               debug_log("while");
+               mm_util_debug("while");
                jpeg_finish_compress(&cinfo);
-               debug_log("jpeg_finish_compress");
+               mm_util_debug("jpeg_finish_compress");
 
                jpeg_destroy_compress(&cinfo);
-               debug_log("jpeg_destroy_compress");
+               mm_util_debug("jpeg_destroy_compress");
        } else {
-               debug_error("We can't encode the IMAGE format");
+               mm_util_error("We can't encode the IMAGE format");
                return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        }
        fsync((int)(fpWriter->_fileno));
-       debug_log("[fsync] FILE");
+       mm_util_debug("[fsync] FILE");
        fclose(fpWriter);
        return iErrorCode;
 }
@@ -709,17 +711,17 @@ mm_image_encode_to_jpeg_memory_with_libjpeg(void **mem, int *csize, void *rawdat
        data[1] = cb;
        data[2] = cr;
 
-       debug_log("Enter");
-       debug_log("#Before Enter#, mem: %p\t rawdata:%p\t width: %d\t height: %d\t fmt: %d\t quality: %d"
+       mm_util_debug("Enter");
+       mm_util_debug("#Before Enter#, mem: %p\t rawdata:%p\t width: %d\t height: %d\t fmt: %d\t quality: %d"
                , mem, rawdata, width, height, fmt, quality);
 
        if(rawdata == NULL) {
-               debug_error("Exit on error -rawdata");
+               mm_util_error("Exit on error -rawdata");
                return MM_ERROR_IMAGE_NO_FREE_SPACE;
        }
 
        if (mem == NULL) {
-               debug_error("Exit on error -mem");
+               mm_util_error("Exit on error -mem");
                return MM_ERROR_IMAGE_NO_FREE_SPACE;
        }
 
@@ -727,21 +729,21 @@ mm_image_encode_to_jpeg_memory_with_libjpeg(void **mem, int *csize, void *rawdat
 
        jpeg_create_compress(&cinfo);
 
-       debug_log("[mm_image_encode_to_jpeg_memory_with_libjpeg] #After jpeg_mem_dest#, mem: %p\t width: %d\t height: %d\t fmt: %d\t quality: %d"
+       mm_util_debug("[mm_image_encode_to_jpeg_memory_with_libjpeg] #After jpeg_mem_dest#, mem: %p\t width: %d\t height: %d\t fmt: %d\t quality: %d"
                , mem, width, height, fmt, quality);
 
        jpeg_mem_dest(&cinfo, (unsigned char **)mem, &size);
        cinfo.image_width = width;
        cinfo.image_height = height;
        if (fmt ==MM_UTIL_JPEG_FMT_YUV420 ||fmt ==MM_UTIL_JPEG_FMT_YUV422 || fmt ==MM_UTIL_JPEG_FMT_UYVY) {
-               debug_log("[mm_image_encode_to_jpeg_file_with_libjpeg] jpeg_stdio_dest for YUV");
+               mm_util_debug("[mm_image_encode_to_jpeg_file_with_libjpeg] jpeg_stdio_dest for YUV");
                _height = MM_JPEG_ROUND_DOWN_16(height);
                flag = height - _height;
 
                cinfo.input_components = 3;
                cinfo.in_color_space = JCS_YCbCr;
                jpeg_set_defaults(&cinfo);
-               debug_log("jpeg_set_defaults");
+               mm_util_debug("jpeg_set_defaults");
 
                cinfo.raw_data_in = TRUE; /* Supply downsampled data */
                cinfo.do_fancy_downsampling = FALSE;
@@ -758,11 +760,11 @@ mm_image_encode_to_jpeg_memory_with_libjpeg(void **mem, int *csize, void *rawdat
                cinfo.comp_info[2].v_samp_factor = 1;
 
                jpeg_set_quality(&cinfo, quality, TRUE);
-               debug_log("jpeg_set_quality");
+               mm_util_debug("jpeg_set_quality");
                cinfo.dct_method = JDCT_FASTEST;
 
                jpeg_start_compress(&cinfo, TRUE);
-               debug_log("jpeg_start_compress");
+               mm_util_debug("jpeg_start_compress");
 
                if(flag) {
                        void *large_rect = malloc (width);
@@ -770,15 +772,15 @@ mm_image_encode_to_jpeg_memory_with_libjpeg(void **mem, int *csize, void *rawdat
                        if(large_rect) {
                                memset(large_rect, 0x10, width);
                        } else {
-                               free(small_rect);
-                               debug_error("large rectangle memory");
+                               IMG_JPEG_FREE(small_rect);
+                               mm_util_error("large rectangle memory");
                                return MM_ERROR_IMAGEHANDLE_NOT_INITIALIZED;
                        }
                        if(small_rect) {
                                memset(small_rect, 0x80, width);
                        } else {
-                               free(large_rect);
-                               debug_error("small rectangle memory");
+                               IMG_JPEG_FREE(large_rect);
+                               mm_util_error("small rectangle memory");
                                return MM_ERROR_IMAGEHANDLE_NOT_INITIALIZED;
                        }
 
@@ -807,8 +809,8 @@ mm_image_encode_to_jpeg_memory_with_libjpeg(void **mem, int *csize, void *rawdat
                                }
                        }
                        jpeg_write_raw_data(&cinfo, data, 16);
-                       free(large_rect);
-                       free(small_rect);
+                       IMG_JPEG_FREE(large_rect);
+                       IMG_JPEG_FREE(small_rect);
                } else {
                        for (j = 0; j < height; j += 16) {
                                for (i = 0; i < 16; i++) {
@@ -821,47 +823,47 @@ mm_image_encode_to_jpeg_memory_with_libjpeg(void **mem, int *csize, void *rawdat
                                jpeg_write_raw_data(&cinfo, data, 16);
                        }
                }
-               debug_log("#for loop#");
+               mm_util_debug("#for loop#");
 
                jpeg_finish_compress(&cinfo);
-               debug_log("jpeg_finish_compress");
+               mm_util_debug("jpeg_finish_compress");
                jpeg_destroy_compress(&cinfo);
-               debug_log("Exit jpeg_destroy_compress, mem: %p\t size:%d", *mem, *csize);
+               mm_util_debug("Exit jpeg_destroy_compress, mem: %p\t size:%d", *mem, *csize);
        }
 
        else if (fmt == MM_UTIL_JPEG_FMT_RGB888 ||fmt == MM_UTIL_JPEG_FMT_GraySacle || fmt == MM_UTIL_JPEG_FMT_RGBA8888 || fmt == MM_UTIL_JPEG_FMT_BGRA8888 || fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
                JSAMPROW row_pointer[1];
                int iRowStride = 0;
 
-               debug_log("MM_UTIL_JPEG_FMT_RGB888");
+               mm_util_debug("MM_UTIL_JPEG_FMT_RGB888");
                if(fmt == MM_UTIL_JPEG_FMT_RGB888) {
                        cinfo.input_components = 3;
                        cinfo.in_color_space = JCS_RGB;
-                       debug_log("JCS_RGB");
+                       mm_util_debug("JCS_RGB");
                } else if(fmt == MM_UTIL_JPEG_FMT_GraySacle) {
                        cinfo.input_components = 1; /* one colour component */
                        cinfo.in_color_space = JCS_GRAYSCALE;
-                       debug_log("JCS_GRAYSCALE");
+                       mm_util_debug("JCS_GRAYSCALE");
                } else if(fmt == MM_UTIL_JPEG_FMT_RGBA8888) {
                        cinfo.input_components = 4;
                        cinfo.in_color_space = JCS_EXT_RGBA;
-                       debug_log("JCS_EXT_RGBA");
+                       mm_util_debug("JCS_EXT_RGBA");
                } else if(fmt == MM_UTIL_JPEG_FMT_BGRA8888) {
                        cinfo.input_components = 4;
                        cinfo.in_color_space = JCS_EXT_BGRA;
-                       debug_log("JCS_EXT_BGRA");
+                       mm_util_debug("JCS_EXT_BGRA");
                } else if(fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
                        cinfo.input_components = 4;
                        cinfo.in_color_space = JCS_EXT_ARGB;
-                       debug_log("JCS_EXT_ARGB");
+                       mm_util_debug("JCS_EXT_ARGB");
                }
 
                jpeg_set_defaults(&cinfo);
-               debug_log("jpeg_set_defaults");
+               mm_util_debug("jpeg_set_defaults");
                jpeg_set_quality(&cinfo, quality, TRUE);
-               debug_log("jpeg_set_quality");
+               mm_util_debug("jpeg_set_quality");
                jpeg_start_compress(&cinfo, TRUE);
-               debug_log("jpeg_start_compress");
+               mm_util_debug("jpeg_start_compress");
                if(fmt == MM_UTIL_JPEG_FMT_RGB888) {
                        iRowStride = width * 3;
                } else if(fmt == MM_UTIL_JPEG_FMT_GraySacle) {
@@ -876,15 +878,15 @@ mm_image_encode_to_jpeg_memory_with_libjpeg(void **mem, int *csize, void *rawdat
                        row_pointer[0] = & image_buffer[cinfo.next_scanline * iRowStride];
                        jpeg_write_scanlines(&cinfo, row_pointer, 1);
                }
-               debug_log("while");
+               mm_util_debug("while");
                jpeg_finish_compress(&cinfo);
-               debug_log("jpeg_finish_compress");
+               mm_util_debug("jpeg_finish_compress");
 
                jpeg_destroy_compress(&cinfo);
 
-               debug_log("Exit");
+               mm_util_debug("Exit");
        }       else {
-               debug_error("We can't encode the IMAGE format");
+               mm_util_error("We can't encode the IMAGE format");
                return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        }
        *csize = (int)size;
@@ -903,14 +905,14 @@ mm_image_decode_from_jpeg_file_with_libjpeg(mm_util_jpeg_yuv_data * decoded_data
        JSAMPROW image, u_image, v_image;
        JSAMPROW row; /* point to buffer[0] */
 
-       debug_log("Enter");
+       mm_util_debug("Enter");
 
        if(!pFileName) {
-               debug_error("pFileName");
+               mm_util_error("pFileName");
                return MM_ERROR_IMAGE_FILEOPEN;
        }
        if(decoded_data == NULL) {
-               debug_error("decoded_data");
+               mm_util_error("decoded_data");
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
        if(decoded_data) {
@@ -919,45 +921,41 @@ mm_image_decode_from_jpeg_file_with_libjpeg(mm_util_jpeg_yuv_data * decoded_data
 
        infile = fopen(pFileName, "rb");
        if(infile == NULL) {
-               debug_error("[infile] file open [%s]", pFileName);
+               mm_util_error("[infile] file open [%s]", pFileName);
                mm_util_stderror("file open failed");
                return MM_ERROR_IMAGE_FILEOPEN;
        }
-       debug_log("infile");
+       mm_util_debug("infile");
        /* allocate and initialize JPEG decompression object   We set up the normal JPEG error routines, then override error_exit. */
        dinfo.err = jpeg_std_error(&jerr.pub);
-       debug_log("jpeg_std_error");
+       mm_util_debug("jpeg_std_error");
        jerr.pub.error_exit = my_error_exit;
-       debug_log("jerr.pub.error_exit ");
+       mm_util_debug("jerr.pub.error_exit ");
 
        /* Establish the setjmp return context for my_error_exit to use. */
        if (setjmp(jerr.setjmp_buffer)) {
                /* If we get here, the JPEG code has signaled an error. We need to clean up the JPEG object, close the input file, and return.*/
-               debug_log("setjmp");
+               mm_util_debug("setjmp");
                jpeg_destroy_decompress(&dinfo);
-               if(decoded_data->data) {
-                       free(decoded_data->data);
-                       decoded_data->data = NULL;
-                       debug_log("free data");
-               }
+               IMG_JPEG_FREE(decoded_data->data);
                fclose(infile);
-               debug_log("fclose");
+               mm_util_debug("fclose");
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
-       debug_log("if(setjmp)");
+       mm_util_debug("if(setjmp)");
        /* Now we can initialize the JPEG decompression object. */
        jpeg_create_decompress(&dinfo);
-       debug_log("jpeg_create_decompress");
+       mm_util_debug("jpeg_create_decompress");
 
        /*specify data source (eg, a file) */
        jpeg_stdio_src(&dinfo, infile);
-       debug_log("jpeg_stdio_src");
+       mm_util_debug("jpeg_stdio_src");
 
        /*read file parameters with jpeg_read_header() */
        jpeg_read_header(&dinfo, TRUE);
 #if PARTIAL_DECODE
-       debug_log("image width: %d height: %d", dinfo.image_width, dinfo.image_height);
+       mm_util_debug("image width: %d height: %d", dinfo.image_width, dinfo.image_height);
        if(dinfo.image_width > ENC_MAX_LEN || dinfo.image_height > ENC_MAX_LEN) {
                dinfo.scale_num = 1;
                dinfo.scale_denom = 8;
@@ -977,22 +975,22 @@ mm_image_decode_from_jpeg_file_with_libjpeg(mm_util_jpeg_yuv_data * decoded_data
        /* set parameters for decompression */
        if (input_fmt == MM_UTIL_JPEG_FMT_RGB888) {
                dinfo.out_color_space=JCS_RGB;
-               debug_log("cinfo.out_color_space=JCS_RGB");
+               mm_util_debug("cinfo.out_color_space=JCS_RGB");
        } else if(input_fmt == MM_UTIL_JPEG_FMT_YUV420 || input_fmt == MM_UTIL_JPEG_FMT_YUV422 || input_fmt == MM_UTIL_JPEG_FMT_UYVY) {
                dinfo.out_color_space=JCS_YCbCr;
-               debug_log("cinfo.out_color_space=JCS_YCbCr");
+               mm_util_debug("cinfo.out_color_space=JCS_YCbCr");
        } else if(input_fmt == MM_UTIL_JPEG_FMT_GraySacle) {
                dinfo.out_color_space=JCS_GRAYSCALE;
-               debug_log("cinfo.out_color_space=JCS_GRAYSCALE");
+               mm_util_debug("cinfo.out_color_space=JCS_GRAYSCALE");
        } else if(input_fmt == MM_UTIL_JPEG_FMT_RGBA8888) {
                dinfo.out_color_space=JCS_EXT_RGBA;
-               debug_log("cinfo.out_color_space=JCS_EXT_RGBA");
+               mm_util_debug("cinfo.out_color_space=JCS_EXT_RGBA");
        } else if(input_fmt == MM_UTIL_JPEG_FMT_BGRA8888) {
                dinfo.out_color_space=JCS_EXT_BGRA;
-               debug_log("cinfo.out_color_space=JCS_EXT_BGRA");
+               mm_util_debug("cinfo.out_color_space=JCS_EXT_BGRA");
        } else if(input_fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
                dinfo.out_color_space=JCS_EXT_ARGB;
-               debug_log("cinfo.out_color_space=JCS_EXT_ARGB");
+               mm_util_debug("cinfo.out_color_space=JCS_EXT_ARGB");
        }
        decoded_data->format = input_fmt;
 
@@ -1014,7 +1012,7 @@ mm_image_decode_from_jpeg_file_with_libjpeg(mm_util_jpeg_yuv_data * decoded_data
 
        /* Make a one-row-high sample array that will go away when done with image */
        buffer = (*dinfo.mem->alloc_sarray) ((j_common_ptr) &dinfo, JPOOL_IMAGE, row_stride, 1);
-       debug_log("JPOOL_IMAGE BUFFER");
+       mm_util_debug("JPOOL_IMAGE BUFFER");
        decoded_data->width = dinfo.output_width;
        decoded_data->height= dinfo.output_height;
        if(input_fmt == MM_UTIL_JPEG_FMT_RGB888 || input_fmt == MM_UTIL_JPEG_FMT_RGBA8888 || input_fmt == MM_UTIL_JPEG_FMT_BGRA8888 || input_fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
@@ -1027,7 +1025,7 @@ mm_image_decode_from_jpeg_file_with_libjpeg(mm_util_jpeg_yuv_data * decoded_data
                decoded_data->size= dinfo.output_height * dinfo.output_width;
        } else{
                jpeg_destroy_decompress(&dinfo);
-               debug_error("[%d] We can't decode the IMAGE format", input_fmt);
+               mm_util_error("[%d] We can't decode the IMAGE format", input_fmt);
                fclose(infile);
                return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        }
@@ -1037,11 +1035,11 @@ mm_image_decode_from_jpeg_file_with_libjpeg(mm_util_jpeg_yuv_data * decoded_data
 
        if(decoded_data->data == NULL) {
                jpeg_destroy_decompress(&dinfo);
-               debug_error("decoded_data->data is NULL");
+               mm_util_error("decoded_data->data is NULL");
                fclose(infile);
                return MM_ERROR_IMAGE_NO_FREE_SPACE;
        }
-       debug_log("decoded_data->data");
+       mm_util_debug("decoded_data->data");
 
        if(input_fmt == MM_UTIL_JPEG_FMT_YUV420 || input_fmt == MM_UTIL_JPEG_FMT_YUV422 || input_fmt == MM_UTIL_JPEG_FMT_UYVY) {
                image = decoded_data->data;
@@ -1074,7 +1072,7 @@ mm_image_decode_from_jpeg_file_with_libjpeg(mm_util_jpeg_yuv_data * decoded_data
                        memcpy(decoded_data->data + state, buffer[0], row_stride);
                        state += row_stride;
                }
-               debug_log("jpeg_read_scanlines");
+               mm_util_debug("jpeg_read_scanlines");
        }
 
        /* Finish decompression */
@@ -1084,7 +1082,7 @@ mm_image_decode_from_jpeg_file_with_libjpeg(mm_util_jpeg_yuv_data * decoded_data
        jpeg_destroy_decompress(&dinfo);
 
        fclose(infile);
-       debug_log("fclose");
+       mm_util_debug("fclose");
 
        return iErrorCode;
 }
@@ -1100,15 +1098,15 @@ mm_image_decode_from_jpeg_memory_with_libjpeg(mm_util_jpeg_yuv_data * decoded_da
        JSAMPROW image, u_image, v_image;
        JSAMPROW row; /* point to buffer[0] */
 
-       debug_log("Enter");
+       mm_util_debug("Enter");
 
        if(src == NULL) {
-               debug_error("[infile] Exit on error");
+               mm_util_error("[infile] Exit on error");
                return MM_ERROR_IMAGE_FILEOPEN;
        }
-       debug_log("infile");
+       mm_util_debug("infile");
        if(decoded_data == NULL) {
-               debug_error("decoded_data");
+               mm_util_error("decoded_data");
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
        if(decoded_data) {
@@ -1117,37 +1115,33 @@ mm_image_decode_from_jpeg_memory_with_libjpeg(mm_util_jpeg_yuv_data * decoded_da
 
        /* allocate and initialize JPEG decompression object   We set up the normal JPEG error routines, then override error_exit. */
        dinfo.err = jpeg_std_error(&jerr.pub);
-       debug_log("jpeg_std_error ");
+       mm_util_debug("jpeg_std_error ");
        jerr.pub.error_exit = my_error_exit;
-       debug_log("jerr.pub.error_exit ");
+       mm_util_debug("jerr.pub.error_exit ");
 
        /* Establish the setjmp return context for my_error_exit to use. */
        if (setjmp(jerr.setjmp_buffer)) {
                /* If we get here, the JPEG code has signaled an error.  We need to clean up the JPEG object, close the input file, and return.*/
-               debug_log("setjmp");
-               if(decoded_data->data) {
-                       free(decoded_data->data);
-                       decoded_data->data = NULL;
-               }
-
+               mm_util_debug("setjmp");
+               IMG_JPEG_FREE(decoded_data->data);
                jpeg_destroy_decompress(&dinfo);
                return MM_ERROR_IMAGE_FILEOPEN;
        }
 
-       debug_log("if(setjmp)");
+       mm_util_debug("if(setjmp)");
        /* Now we can initialize the JPEG decompression object. */
        jpeg_create_decompress(&dinfo);
-       debug_log("jpeg_create_decompress");
+       mm_util_debug("jpeg_create_decompress");
 
        /*specify data source (eg, a file) */
        jpeg_mem_src(&dinfo, src, size);
-       debug_log("jpeg_stdio_src");
+       mm_util_debug("jpeg_stdio_src");
 
        /*read file parameters with jpeg_read_header() */
        jpeg_read_header(&dinfo, TRUE);
-       debug_log("jpeg_read_header");
+       mm_util_debug("jpeg_read_header");
 #if PARTIAL_DECODE
-       debug_log("image width: %d height: %d", dinfo.image_width, dinfo.image_height);
+       mm_util_debug("image width: %d height: %d", dinfo.image_width, dinfo.image_height);
        if(dinfo.image_width > ENC_MAX_LEN || dinfo.image_height > ENC_MAX_LEN) {
                dinfo.scale_num = 1;
                dinfo.scale_denom = 8;
@@ -1167,28 +1161,28 @@ mm_image_decode_from_jpeg_memory_with_libjpeg(mm_util_jpeg_yuv_data * decoded_da
        /* set parameters for decompression */
        if (input_fmt == MM_UTIL_JPEG_FMT_RGB888) {
                dinfo.out_color_space=JCS_RGB;
-               debug_log("cinfo.out_color_space=JCS_RGB");
+               mm_util_debug("cinfo.out_color_space=JCS_RGB");
        } else if(input_fmt == MM_UTIL_JPEG_FMT_YUV420 || input_fmt == MM_UTIL_JPEG_FMT_YUV422 || input_fmt == MM_UTIL_JPEG_FMT_UYVY) {
                dinfo.out_color_space=JCS_YCbCr;
-               debug_log("cinfo.out_color_space=JCS_YCbCr");
+               mm_util_debug("cinfo.out_color_space=JCS_YCbCr");
        } else if(input_fmt == MM_UTIL_JPEG_FMT_GraySacle) {
                dinfo.out_color_space=JCS_GRAYSCALE;
-               debug_log("cinfo.out_color_space=JCS_GRAYSCALE");
+               mm_util_debug("cinfo.out_color_space=JCS_GRAYSCALE");
        } else if(input_fmt == MM_UTIL_JPEG_FMT_RGBA8888) {
                dinfo.out_color_space=JCS_EXT_RGBA;
-               debug_log("cinfo.out_color_space=JCS_EXT_RGBA");
+               mm_util_debug("cinfo.out_color_space=JCS_EXT_RGBA");
        } else if(input_fmt == MM_UTIL_JPEG_FMT_BGRA8888) {
                dinfo.out_color_space=JCS_EXT_BGRA;
-               debug_log("cinfo.out_color_space=JCS_EXT_BGRA");
+               mm_util_debug("cinfo.out_color_space=JCS_EXT_BGRA");
        } else if(input_fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
                dinfo.out_color_space=JCS_EXT_ARGB;
-               debug_log("cinfo.out_color_space=JCS_EXT_ARGB");
+               mm_util_debug("cinfo.out_color_space=JCS_EXT_ARGB");
        }
        decoded_data->format = input_fmt;
 
        /* Start decompressor*/
        jpeg_start_decompress(&dinfo);
-       debug_log("jpeg_start_decompress");
+       mm_util_debug("jpeg_start_decompress");
 
        /* byte-align for YUV format */
        if (input_fmt == MM_UTIL_JPEG_FMT_YUV420 || input_fmt == MM_UTIL_JPEG_FMT_YUV422) {
@@ -1205,7 +1199,7 @@ mm_image_decode_from_jpeg_memory_with_libjpeg(mm_util_jpeg_yuv_data * decoded_da
 
        /* Make a one-row-high sample array that will go away when done with image */
        buffer = (*dinfo.mem->alloc_sarray) ((j_common_ptr) &dinfo, JPOOL_IMAGE, row_stride, 1);
-       debug_log("JPOOL_IMAGE BUFFER");
+       mm_util_debug("JPOOL_IMAGE BUFFER");
        decoded_data->width = dinfo.output_width;
        decoded_data->height= dinfo.output_height;
        if(input_fmt == MM_UTIL_JPEG_FMT_RGB888 || input_fmt == MM_UTIL_JPEG_FMT_RGBA8888 || input_fmt == MM_UTIL_JPEG_FMT_BGRA8888 || input_fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
@@ -1218,7 +1212,7 @@ mm_image_decode_from_jpeg_memory_with_libjpeg(mm_util_jpeg_yuv_data * decoded_da
                decoded_data->size= dinfo.output_height * dinfo.output_width;
        } else{
                jpeg_destroy_decompress(&dinfo);
-               debug_error("[%d] We can't decode the IMAGE format", input_fmt);
+               mm_util_error("[%d] We can't decode the IMAGE format", input_fmt);
                return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        }
 
@@ -1227,10 +1221,10 @@ mm_image_decode_from_jpeg_memory_with_libjpeg(mm_util_jpeg_yuv_data * decoded_da
 
        if(decoded_data->data == NULL) {
                jpeg_destroy_decompress(&dinfo);
-               debug_error("decoded_data->data is NULL");
+               mm_util_error("decoded_data->data is NULL");
                return MM_ERROR_IMAGE_NO_FREE_SPACE;
        }
-       debug_log("decoded_data->data");
+       mm_util_debug("decoded_data->data");
 
        /* while (scan lines remain to be read) jpeg_read_scanlines(...); */
        if(input_fmt == MM_UTIL_JPEG_FMT_YUV420 || input_fmt == MM_UTIL_JPEG_FMT_YUV422 || input_fmt == MM_UTIL_JPEG_FMT_UYVY) {
@@ -1264,18 +1258,18 @@ mm_image_decode_from_jpeg_memory_with_libjpeg(mm_util_jpeg_yuv_data * decoded_da
                        memcpy(decoded_data->data + state, buffer[0], row_stride);
                        state += row_stride;
                }
-               debug_log("jpeg_read_scanlines");
+               mm_util_debug("jpeg_read_scanlines");
        }
 
        /* Finish decompression */
        jpeg_finish_decompress(&dinfo);
-       debug_log("jpeg_finish_decompress");
+       mm_util_debug("jpeg_finish_decompress");
 
        /* Release JPEG decompression object */
        jpeg_destroy_decompress(&dinfo);
-       debug_log("jpeg_destroy_decompress");
+       mm_util_debug("jpeg_destroy_decompress");
 
-       debug_log("fclose");
+       mm_util_debug("fclose");
 
        return iErrorCode;
 }
@@ -1287,7 +1281,7 @@ static int _mm_util_set_exif_entry(ExifData *exif, ExifIfd ifd, ExifTag tag,Exif
        ExifEntry *e = NULL;
 
        if (exif == NULL || format <= 0 || components <= 0 || data == NULL) {
-               debug_error("invalid argument exif = %p format = %d, components = %lu data = %p!",
+               mm_util_error("invalid argument exif = %p format = %d, components = %lu data = %p!",
                        exif, format, components, data);
                return -1;
        }
@@ -1298,7 +1292,7 @@ static int _mm_util_set_exif_entry(ExifData *exif, ExifIfd ifd, ExifTag tag,Exif
        /*create new tag*/
        e = exif_entry_new();
        if (e == NULL) {
-               debug_error("entry create error!");
+               mm_util_error("entry create error!");
                return -1;
        }
 
@@ -1338,36 +1332,36 @@ mm_util_jpeg_encode_to_file(const char *filename, void* src, int width, int heig
        TTRACE_BEGIN("MM_UTILITY:JPEG:ENCODE_TO_FILE");
 
        if( !filename || !src) {
-               debug_error("#ERROR# filename || src buffer is NULL");
+               mm_util_error("#ERROR# filename || src buffer is NULL");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (width <= 0) || (height <= 0)) {
-               debug_error("#ERROR# src_width || src_height value ");
+               mm_util_error("#ERROR# src_width || src_height value ");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (fmt < MM_UTIL_JPEG_FMT_YUV420) || (fmt > MM_UTIL_JPEG_FMT_ARGB8888) ) {
-               debug_error("#ERROR# fmt value");
+               mm_util_error("#ERROR# fmt value");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (quality < 1 ) || (quality>100) ) {
-               debug_error("#ERROR# quality vaule");
+               mm_util_error("#ERROR# quality vaule");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
 #if LIBJPEG_TURBO
-       debug_log("#START# LIBJPEG_TURBO");
+       mm_util_debug("#START# LIBJPEG_TURBO");
        ret=mm_image_encode_to_jpeg_file_with_libjpeg_turbo(filename, src, width, height, fmt, quality);
-       debug_log("#End# libjpeg, Success!! ret: %d", ret);
+       mm_util_debug("#End# libjpeg, Success!! ret: %d", ret);
 
 #else
-       debug_log("#START# LIBJPEG");
+       mm_util_debug("#START# LIBJPEG");
        if(fmt == MM_UTIL_JPEG_FMT_NV12) {
                unsigned int dst_size = 0;
                ret = mm_util_get_image_size(MM_UTIL_IMG_FMT_NV12, (unsigned int)width, (unsigned int)height, &dst_size);
@@ -1376,8 +1370,7 @@ mm_util_jpeg_encode_to_file(const char *filename, void* src, int width, int heig
                if(dst) {
                        ret = mm_util_convert_colorspace(src, width, height,MM_UTIL_IMG_FMT_NV12, dst, MM_UTIL_IMG_FMT_YUV420);
                        ret = mm_image_encode_to_jpeg_file_with_libjpeg(filename, dst, width, height, MM_UTIL_JPEG_FMT_YUV420, quality);
-                       free(dst);
-                       dst=NULL;
+                       IMG_JPEG_FREE(dst);
                } else {
                        TTRACE_END();
                        return MM_ERROR_IMAGE_NO_FREE_SPACE;
@@ -1388,7 +1381,7 @@ mm_util_jpeg_encode_to_file(const char *filename, void* src, int width, int heig
        } else {
                ret = mm_image_encode_to_jpeg_file_with_libjpeg(filename, src, width, height, fmt, quality);
        }
-       debug_log("#END# libjpeg, Success!! ret: %d", ret);
+       mm_util_debug("#END# libjpeg, Success!! ret: %d", ret);
 #endif
        TTRACE_END();
        return ret;
@@ -1402,35 +1395,35 @@ mm_util_jpeg_encode_to_memory(void **mem, int *size, void* src, int width, int h
        TTRACE_BEGIN("MM_UTILITY:JPEG:ENCODE_TO_MEMORY");
 
        if( !mem || !size || !src) {
-               debug_error("#ERROR# filename ||size ||  src buffer is NULL");
+               mm_util_error("#ERROR# filename ||size ||  src buffer is NULL");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (width <= 0) || (height <= 0)) {
-               debug_error("#ERROR# src_width || src_height value ");
+               mm_util_error("#ERROR# src_width || src_height value ");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (fmt < MM_UTIL_JPEG_FMT_YUV420) || (fmt > MM_UTIL_JPEG_FMT_ARGB8888) ) {
-               debug_error("#ERROR# fmt value");
+               mm_util_error("#ERROR# fmt value");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if(  (quality < 1 ) || (quality>100) ) {
-               debug_error("#ERROR# quality vaule");
+               mm_util_error("#ERROR# quality vaule");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        #if LIBJPEG_TURBO
-       debug_log("#START# libjpeg-turbo");
+       mm_util_debug("#START# libjpeg-turbo");
        ret=mm_image_encode_to_jpeg_memory_with_libjpeg_turbo(mem, size, src, width, height, fmt, quality);
-       debug_log("#END# libjpeg-turbo, Success!! ret: %d", ret);
+       mm_util_debug("#END# libjpeg-turbo, Success!! ret: %d", ret);
        #else /* LIBJPEG_TURBO */
-       debug_log("#START# libjpeg");
+       mm_util_debug("#START# libjpeg");
        if(fmt == MM_UTIL_JPEG_FMT_NV12) {
                unsigned int dst_size = 0;
                ret = mm_util_get_image_size(MM_UTIL_IMG_FMT_NV12, (unsigned int)width, (unsigned int)height, &dst_size);
@@ -1439,8 +1432,7 @@ mm_util_jpeg_encode_to_memory(void **mem, int *size, void* src, int width, int h
                if(dst) {
                        ret = mm_util_convert_colorspace(src, width, height,MM_UTIL_IMG_FMT_NV12, dst, MM_UTIL_IMG_FMT_YUV420);
                        ret = mm_image_encode_to_jpeg_memory_with_libjpeg(mem, size, dst, width, height, MM_UTIL_JPEG_FMT_YUV420, quality);
-                       free(dst);
-                       dst = NULL;
+                       IMG_JPEG_FREE(dst);
                } else {
                        TTRACE_END();
                        return MM_ERROR_IMAGE_NO_FREE_SPACE;
@@ -1452,7 +1444,7 @@ mm_util_jpeg_encode_to_memory(void **mem, int *size, void* src, int width, int h
                ret = mm_image_encode_to_jpeg_memory_with_libjpeg(mem, size, src, width, height, fmt, quality);
        }
 #endif /* LIBJPEG_TURBO */
-       debug_log("#END# libjpeg, Success!! ret: %d", ret);
+       mm_util_debug("#END# libjpeg, Success!! ret: %d", ret);
 
        TTRACE_END();
        return ret;
@@ -1468,13 +1460,13 @@ mm_util_decode_from_jpeg_file(mm_util_jpeg_yuv_data *decoded, const char *filena
        TTRACE_BEGIN("MM_UTILITY:JPEG:DECODE_FROM_JPEG_FILE");
 
        if( !decoded || !filename) {
-               debug_error("#ERROR# decoded || filename buffer is NULL");
+               mm_util_error("#ERROR# decoded || filename buffer is NULL");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (fmt < MM_UTIL_JPEG_FMT_YUV420) || (fmt > MM_UTIL_JPEG_FMT_ARGB8888) ) {
-               debug_error("#ERROR# fmt value");
+               mm_util_error("#ERROR# fmt value");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
@@ -1485,24 +1477,25 @@ mm_util_decode_from_jpeg_file(mm_util_jpeg_yuv_data *decoded, const char *filena
        if(fp) {
                read_size = fread((void *)magic, 1, 2, fp);
                if (read_size > 0)
-                       debug_log("Success fread");
+                       mm_util_debug("Success fread");
 
-               debug_log("%x %x", magic[0], magic[1]);
+               mm_util_debug("%x %x", magic[0], magic[1]);
                fclose(fp);
        } else {
-               debug_error("[fp] file open [%s] \t %s", filename, strerror(errno));
+               mm_util_error("[infile] file open [%s]", filename);
+               mm_util_stderror("file open failed");
                TTRACE_END();
                return MM_ERROR_IMAGE_FILEOPEN;
        }
 
        if(magic[0] == 0xff && magic[1] == 0xd8) {
                #if LIBJPEG_TURBO
-               debug_log("#START# LIBJPEG_TURBO");
+               mm_util_debug("#START# LIBJPEG_TURBO");
                ret = mm_image_decode_from_jpeg_file_with_libjpeg_turbo(decoded, filename, fmt);
-               debug_log("decoded->data: %p\t width: %d\t height: %d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size);
-               debug_log("#End# LIBJPEG_TURBO, Success!! ret: %d", ret);
+               mm_util_debug("decoded->data: %p\t width: %d\t height: %d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size);
+               mm_util_debug("#End# LIBJPEG_TURBO, Success!! ret: %d", ret);
                #else
-               debug_log("#START# libjpeg");
+               mm_util_debug("#START# libjpeg");
                if(fmt == MM_UTIL_JPEG_FMT_NV12) {
                        unsigned int dst_size = 0;
                        ret = mm_image_decode_from_jpeg_file_with_libjpeg(decoded, filename, MM_UTIL_IMG_FMT_YUV420, downscale);
@@ -1510,25 +1503,25 @@ mm_util_decode_from_jpeg_file(mm_util_jpeg_yuv_data *decoded, const char *filena
                                int err = MM_ERROR_NONE;
                                err = mm_util_get_image_size(MM_UTIL_IMG_FMT_NV12, decoded->width, decoded->height, &dst_size);
                                if (err != MM_ERROR_NONE)
-                                       debug_error("fail mm_util_get_image_size");
+                                       mm_util_error("fail mm_util_get_image_size");
 
                                unsigned char *dst = NULL;
                                dst = malloc(dst_size);
                                if(dst) {
                                        ret = mm_util_convert_colorspace(decoded->data, decoded->width, decoded->height, MM_UTIL_IMG_FMT_YUV420, dst, MM_UTIL_IMG_FMT_NV12);
-                                       free(decoded->data);
+                                       IMG_JPEG_FREE(decoded->data);
                                        decoded->data = malloc(dst_size);
                                        if (decoded->data == NULL) {
-                                               debug_log("memory allocation failed");
+                                               mm_util_debug("memory allocation failed");
+                                               IMG_JPEG_FREE(dst);
                                                TTRACE_END();
                                                return MM_ERROR_IMAGE_NO_FREE_SPACE;
                                        }
                                        memcpy(decoded->data, dst, dst_size);
                                        decoded->size = dst_size;
-                                       free(dst);
-                                       dst=NULL;
+                                       IMG_JPEG_FREE(dst);
                                } else {
-                                       debug_log("memory allocation failed");
+                                       mm_util_debug("memory allocation failed");
                                        TTRACE_END();
                                        return MM_ERROR_IMAGE_NO_FREE_SPACE;
                                }
@@ -1537,20 +1530,20 @@ mm_util_decode_from_jpeg_file(mm_util_jpeg_yuv_data *decoded, const char *filena
                        ret = mm_image_decode_from_jpeg_file_with_libjpeg(decoded, filename, fmt, downscale);
                }
 
-               debug_log("decoded->data: %p\t width: %d\t height:%d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size);
-               debug_log("#End# libjpeg, Success!! ret: %d", ret);
+               mm_util_debug("decoded->data: %p\t width: %d\t height:%d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size);
+               mm_util_debug("#End# libjpeg, Success!! ret: %d", ret);
                #endif
        } else if(magic[0] == 0x47 && magic[1] == 0x49) {
-               debug_error("Not JPEG IMAGE - GIF");
+               mm_util_error("Not JPEG IMAGE - GIF");
                ret = MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        } else if(magic[0] == 0x89 && magic[1] == 0x50) {
-               debug_error("Not JPEG IMAGE - PNG");
+               mm_util_error("Not JPEG IMAGE - PNG");
                ret = MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        } else if(magic[0] == 0x49 && magic[1] == 0x49) {
-               debug_error("Not JPEG IMAGE - TIFF");
+               mm_util_error("Not JPEG IMAGE - TIFF");
                ret = MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        } else {
-               debug_error("Not JPEG IMAGE");
+               mm_util_error("Not JPEG IMAGE");
                ret = MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        }
 
@@ -1568,32 +1561,32 @@ mm_util_decode_from_jpeg_memory(mm_util_jpeg_yuv_data* decoded, void* src, int s
        mm_util_jpeg_decode_downscale downscale = MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1;
 
        if( !decoded || !src) {
-               debug_error("#ERROR# decoded || src buffer is NULL");
+               mm_util_error("#ERROR# decoded || src buffer is NULL");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if(size < 0) {
-               debug_error("#ERROR# size");
+               mm_util_error("#ERROR# size");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (fmt < MM_UTIL_JPEG_FMT_YUV420) || (fmt > MM_UTIL_JPEG_FMT_ARGB8888) ) {
-               debug_error("#ERROR# fmt value");
+               mm_util_error("#ERROR# fmt value");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        #if LIBJPEG_TURBO
-       debug_log("#START# libjpeg");
+       mm_util_debug("#START# libjpeg");
        ret = mm_image_decode_from_jpeg_memory_with_libjpeg_turbo(decoded, src, size, fmt);
 
-       debug_log("decoded->data: %p\t width: %d\t height: %d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size);
-       debug_log("#END# libjpeg, Success!! ret: %d", ret);
+       mm_util_debug("decoded->data: %p\t width: %d\t height: %d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size);
+       mm_util_debug("#END# libjpeg, Success!! ret: %d", ret);
 
        #else
-       debug_log("#START# libjpeg");
+       mm_util_debug("#START# libjpeg");
        if(fmt == MM_UTIL_JPEG_FMT_NV12) {
                unsigned int dst_size = 0;
                unsigned char *dst = NULL;
@@ -1603,24 +1596,24 @@ mm_util_decode_from_jpeg_memory(mm_util_jpeg_yuv_data* decoded, void* src, int s
                        int err = MM_ERROR_NONE;
                        err = mm_util_get_image_size(MM_UTIL_IMG_FMT_NV12, decoded->width, decoded->height, &dst_size);
                        if (err != MM_ERROR_NONE)
-                                       debug_error("fail mm_util_get_image_size");
+                                       mm_util_error("fail mm_util_get_image_size");
 
                        dst = malloc(dst_size);
                        if(dst) {
                                ret = mm_util_convert_colorspace(decoded->data, decoded->width, decoded->height, MM_UTIL_IMG_FMT_YUV420, dst, MM_UTIL_IMG_FMT_NV12);
-                               free(decoded->data);
+                               IMG_JPEG_FREE(decoded->data);
                                decoded->data = malloc(dst_size);
                                if (decoded->data == NULL) {
-                                       debug_log("memory allocation failed");
+                                       mm_util_debug("memory allocation failed");
+                                       IMG_JPEG_FREE(dst);
                                        TTRACE_END();
                                        return MM_ERROR_IMAGE_NO_FREE_SPACE;
                                }
                                memcpy(decoded->data, dst, dst_size);
                                decoded->size = dst_size;
-                               free(dst);
-                               dst=NULL;
+                               IMG_JPEG_FREE(dst);
                        } else {
-                               debug_log("memory allocation failed");
+                               mm_util_debug("memory allocation failed");
                                TTRACE_END();
                                return MM_ERROR_IMAGE_NO_FREE_SPACE;
                        }
@@ -1629,8 +1622,8 @@ mm_util_decode_from_jpeg_memory(mm_util_jpeg_yuv_data* decoded, void* src, int s
                ret = mm_image_decode_from_jpeg_memory_with_libjpeg(decoded, src, size, fmt, downscale);
        }
 
-       debug_log("decoded->data: %p\t width: %d\t height: %d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size);
-       debug_log("#END# libjpeg, Success!! ret: %d", ret);
+       mm_util_debug("decoded->data: %p\t width: %d\t height: %d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size);
+       mm_util_debug("#END# libjpeg, Success!! ret: %d", ret);
        #endif
 
        TTRACE_END();
@@ -1645,20 +1638,20 @@ mm_util_decode_from_jpeg_file_with_downscale(mm_util_jpeg_yuv_data *decoded, con
        TTRACE_BEGIN("MM_UTILITY:JPEG:DECODE_FROM_JPEG_FILE_WITH_DOWNSCALE");
 
        if( !decoded || !filename) {
-               debug_error("#ERROR# decoded || filename buffer is NULL");
+               mm_util_error("#ERROR# decoded || filename buffer is NULL");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (fmt < MM_UTIL_JPEG_FMT_YUV420) || (fmt > MM_UTIL_JPEG_FMT_ARGB8888) ) {
-               debug_error("#ERROR# fmt value");
+               mm_util_error("#ERROR# fmt value");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1) && (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_2)
                 && (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_4) && (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_8)) {
-               debug_error("#ERROR# fmt value");
+               mm_util_error("#ERROR# fmt value");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
@@ -1669,19 +1662,19 @@ mm_util_decode_from_jpeg_file_with_downscale(mm_util_jpeg_yuv_data *decoded, con
        if(fp) {
                read_size = fread((void *)magic, 1, 2, fp);
                if (read_size > 0)
-                       debug_log("Success fread");
+                       mm_util_debug("Success fread");
 
-               debug_log("%x %x", magic[0], magic[1]);
+               mm_util_debug("%x %x", magic[0], magic[1]);
                fclose(fp);
        }
        if(magic[0] == 0xff && magic[1] == 0xd8) {
                #if LIBJPEG_TURBO
-               debug_log("#START# LIBJPEG_TURBO");
+               mm_util_debug("#START# LIBJPEG_TURBO");
                ret = mm_image_decode_from_jpeg_file_with_libjpeg_turbo(decoded, filename, fmt);
-               debug_log("decoded->data: %p\t width: %d\t height: %d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size);
-               debug_log("#End# LIBJPEG_TURBO, Success!! ret: %d", ret);
+               mm_util_debug("decoded->data: %p\t width: %d\t height: %d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size);
+               mm_util_debug("#End# LIBJPEG_TURBO, Success!! ret: %d", ret);
                #else
-               debug_log("#START# libjpeg");
+               mm_util_debug("#START# libjpeg");
                if(fmt == MM_UTIL_JPEG_FMT_NV12) {
                        unsigned int dst_size = 0;
                        ret = mm_image_decode_from_jpeg_file_with_libjpeg(decoded, filename, MM_UTIL_IMG_FMT_YUV420, downscale);
@@ -1689,25 +1682,25 @@ mm_util_decode_from_jpeg_file_with_downscale(mm_util_jpeg_yuv_data *decoded, con
                                int err = MM_ERROR_NONE;
                                err = mm_util_get_image_size(MM_UTIL_IMG_FMT_NV12, decoded->width, decoded->height, &dst_size);
                                if (err != MM_ERROR_NONE)
-                                       debug_error("fail mm_util_get_image_size");
+                                       mm_util_error("fail mm_util_get_image_size");
 
                                unsigned char *dst = NULL;
                                dst = malloc(dst_size);
                                if(dst) {
                                        ret = mm_util_convert_colorspace(decoded->data, decoded->width, decoded->height, MM_UTIL_IMG_FMT_YUV420, dst, MM_UTIL_IMG_FMT_NV12);
-                                       free(decoded->data);
+                                       IMG_JPEG_FREE(decoded->data);
                                        decoded->data = malloc(dst_size);
                                        if (decoded->data == NULL) {
-                                               debug_log("memory allocation failed");
+                                               mm_util_debug("memory allocation failed");
+                                               IMG_JPEG_FREE(dst);
                                                TTRACE_END();
                                                return MM_ERROR_IMAGE_NO_FREE_SPACE;
                                        }
                                        memcpy(decoded->data, dst, dst_size);
                                        decoded->size = dst_size;
-                                       free(dst);
-                                       dst=NULL;
+                                       IMG_JPEG_FREE(dst);
                                } else {
-                                       debug_log("memory allocation failed");
+                                       mm_util_debug("memory allocation failed");
                                        TTRACE_END();
                                        return MM_ERROR_IMAGE_NO_FREE_SPACE;
                                }
@@ -1716,20 +1709,20 @@ mm_util_decode_from_jpeg_file_with_downscale(mm_util_jpeg_yuv_data *decoded, con
                        ret = mm_image_decode_from_jpeg_file_with_libjpeg(decoded, filename, fmt, downscale);
                }
 
-               debug_log("decoded->data: %p\t width: %d\t height:%d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size);
-               debug_log("#End# libjpeg, Success!! ret: %d", ret);
+               mm_util_debug("decoded->data: %p\t width: %d\t height:%d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size);
+               mm_util_debug("#End# libjpeg, Success!! ret: %d", ret);
                #endif
        } else if(magic[0] == 0x47 && magic[1] == 0x49) {
-               debug_error("Not JPEG IMAGE - GIF");
+               mm_util_error("Not JPEG IMAGE - GIF");
                ret = MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        } else if(magic[0] == 0x89 && magic[1] == 0x50) {
-               debug_error("Not JPEG IMAGE - PNG");
+               mm_util_error("Not JPEG IMAGE - PNG");
                ret = MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        } else if(magic[0] == 0x49 && magic[1] == 0x49) {
-               debug_error("Not JPEG IMAGE - TIFF");
+               mm_util_error("Not JPEG IMAGE - TIFF");
                ret = MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        } else {
-               debug_error("Not JPEG IMAGE");
+               mm_util_error("Not JPEG IMAGE");
                ret = MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
        }
 
@@ -1745,39 +1738,39 @@ mm_util_decode_from_jpeg_memory_with_downscale(mm_util_jpeg_yuv_data* decoded, v
        TTRACE_BEGIN("MM_UTILITY:JPEG:DECODE_FROM_JPEG_MEMORY_WITH_DOWNSCALE");
 
        if( !decoded || !src) {
-               debug_error("#ERROR# decoded || src buffer is NULL");
+               mm_util_error("#ERROR# decoded || src buffer is NULL");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if(size < 0) {
-               debug_error("#ERROR# size");
+               mm_util_error("#ERROR# size");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (fmt < MM_UTIL_JPEG_FMT_YUV420) || (fmt > MM_UTIL_JPEG_FMT_ARGB8888) ) {
-               debug_error("#ERROR# fmt value");
+               mm_util_error("#ERROR# fmt value");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        if( (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1) && (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_2)
                 && (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_4) && (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_8)) {
-               debug_error("#ERROR# fmt value");
+               mm_util_error("#ERROR# fmt value");
                TTRACE_END();
                return MM_ERROR_IMAGE_INVALID_VALUE;
        }
 
        #if LIBJPEG_TURBO
-       debug_log("#START# libjpeg");
+       mm_util_debug("#START# libjpeg");
        ret = mm_image_decode_from_jpeg_memory_with_libjpeg_turbo(decoded, src, size, fmt);
 
-       debug_log("decoded->data: %p\t width: %d\t height: %d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size);
-       debug_log("#END# libjpeg, Success!! ret: %d", ret);
+       mm_util_debug("decoded->data: %p\t width: %d\t height: %d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size);
+       mm_util_debug("#END# libjpeg, Success!! ret: %d", ret);
 
        #else
-       debug_log("#START# libjpeg");
+       mm_util_debug("#START# libjpeg");
        if(fmt == MM_UTIL_JPEG_FMT_NV12) {
                unsigned int dst_size = 0;
                unsigned char *dst = NULL;
@@ -1787,24 +1780,24 @@ mm_util_decode_from_jpeg_memory_with_downscale(mm_util_jpeg_yuv_data* decoded, v
                        int err = MM_ERROR_NONE;
                        err = mm_util_get_image_size(MM_UTIL_IMG_FMT_NV12, decoded->width, decoded->height, &dst_size);
                        if (err != MM_ERROR_NONE)
-                                       debug_error("fail mm_util_get_image_size");
+                                       mm_util_error("fail mm_util_get_image_size");
 
                        dst = malloc(dst_size);
                        if(dst) {
                                ret = mm_util_convert_colorspace(decoded->data, decoded->width, decoded->height, MM_UTIL_IMG_FMT_YUV420, dst, MM_UTIL_IMG_FMT_NV12);
-                               free(decoded->data);
+                               IMG_JPEG_FREE(decoded->data);
                                decoded->data = malloc(dst_size);
                                if (decoded->data == NULL) {
-                                       debug_log("memory allocation failed");
+                                       mm_util_debug("memory allocation failed");
+                                       IMG_JPEG_FREE(dst);
                                        TTRACE_END();
                                        return MM_ERROR_IMAGE_NO_FREE_SPACE;
                                }
                                memcpy(decoded->data, dst, dst_size);
                                decoded->size = dst_size;
-                               free(dst);
-                               dst=NULL;
+                               IMG_JPEG_FREE(dst);
                        } else {
-                               debug_log("memory allocation failed");
+                               mm_util_debug("memory allocation failed");
                                TTRACE_END();
                                return MM_ERROR_IMAGE_NO_FREE_SPACE;
                        }
@@ -1813,8 +1806,8 @@ mm_util_decode_from_jpeg_memory_with_downscale(mm_util_jpeg_yuv_data* decoded, v
                ret = mm_image_decode_from_jpeg_memory_with_libjpeg(decoded, src, size, fmt, downscale);
        }
 
-       debug_log("decoded->data: %p\t width: %d\t height: %d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size);
-       debug_log("#END# libjpeg, Success!! ret: %d", ret);
+       mm_util_debug("decoded->data: %p\t width: %d\t height: %d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size);
+       mm_util_debug("#END# libjpeg, Success!! ret: %d", ret);
        #endif
 
        TTRACE_END();
index 0f91471..874e421 100755 (executable)
@@ -28,7 +28,6 @@
 #include <unistd.h>
 #include <mm_util_jpeg.h>
 #include <mm_error.h>
-#include <mm_debug.h>
 #include <tzplatform_config.h>
 
 #define ENCODE_RESULT_PATH tzplatform_mkpath(TZ_USER_CONTENT, "encode_test.jpg")
@@ -74,9 +73,9 @@ static int _read_file(char *file_name, void **data, int *data_size)
                        return FALSE;
                } else {
                        if(fread(*data, 1, file_size, fp)) {
-                               debug_log("#Success# fread");
+                               fprintf(stderr, "#Success# fread\n");
                        } else {
-                               debug_error("#Error# fread");
+                               fprintf(stderr, "#Error# fread\n");
                                fclose(fp);
                                fp = NULL;
                                return FALSE;
@@ -93,7 +92,7 @@ static int _read_file(char *file_name, void **data, int *data_size)
                        return FALSE;
                }
        } else {
-               debug_error("#Error# ftell");
+               fprintf(stderr, "#Error# ftell\n");
                fclose(fp);
                fp = NULL;
                return FALSE;
index 5370123..f39b8ed 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       libmm-utility
 Summary:    Multimedia Framework Utility Library
-Version:    0.14
+Version:    0.15
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
@@ -9,7 +9,7 @@ Source1001: libmm-utility.manifest
 Requires(post):    /sbin/ldconfig
 Requires(postun):  /sbin/ldconfig
 BuildRequires:  pkgconfig(mm-common)
-BuildRequires:  pkgconfig(mm-log)
+BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(glib-2.0)
 BuildRequires:  pkgconfig(gmodule-2.0)
 BuildRequires:  libjpeg-turbo-devel
@@ -61,6 +61,8 @@ sed -i -e "s#@JPEG_REQPKG@#$JPEG_REQPKG#g" jpeg/mmutil-jpeg.pc
 %install
 rm -rf %{buildroot}
 %make_install
+mkdir -p %{buildroot}/usr/share/license
+cp LICENSE %{buildroot}/usr/share/license/%{name}
 
 %clean
 rm -rf %{buildroot}
@@ -69,8 +71,8 @@ rm -rf %{buildroot}
 %postun -p /sbin/ldconfig
 
 %files
+/usr/share/license/%{name}
 %manifest %{name}.manifest
-%license LICENSE LICENSE.APLv2.0
 %defattr(-,root,root,-)
 %{_libdir}/*.so*