Add new rotate and resize APIs those are use GraphickMagicK 51/166851/13
authorhj kim <backto.kim@samsung.com>
Fri, 12 Jan 2018 06:30:13 +0000 (15:30 +0900)
committerhj kim <backto.kim@samsung.com>
Fri, 19 Jan 2018 02:26:49 +0000 (11:26 +0900)
Change-Id: I2cb2a02be97fdfebf308733250bf4b236f27340e

CMakeLists.txt
common/include/mm_util_debug.h
common/include/mm_util_private.h
magick/CMakeLists.txt [new file with mode: 0755]
magick/include/mm_util_magick.h [new file with mode: 0755]
magick/mm_util_magick.c [new file with mode: 0755]
magick/mmutil-magick.pc.in [new file with mode: 0755]
magick/test/CMakeLists.txt [new file with mode: 0755]
magick/test/mm_util_magick_testsuite.c [new file with mode: 0755]
packaging/libmm-utility.spec

index 5f7e87c..853406c 100755 (executable)
@@ -22,6 +22,7 @@ ADD_SUBDIRECTORY(imgcv)
 ADD_SUBDIRECTORY(imgp)
 ADD_SUBDIRECTORY(jpeg)
 ADD_SUBDIRECTORY(png)
+ADD_SUBDIRECTORY(magick)
 
 IF(UNIX)
 
index 4903e77..0ef1599 100755 (executable)
@@ -38,6 +38,7 @@ extern "C"
 #define FONT_COLOR_RESET    "\033[0m"
 #define FONT_COLOR_RED      "\033[31m"
 #define FONT_COLOR_YELLOW      "\033[33m"
+#define FONT_COLOR_CYAN     "\033[36m"
 
 #define mm_util_debug(fmt, arg...) do { \
                LOGD(FONT_COLOR_RESET""fmt"", ##arg);     \
@@ -55,6 +56,10 @@ extern "C"
                LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg);     \
        } while (0)
 
+#define mm_util_sec_debug(fmt, arg...) do { \
+               SECURE_LOGD(FONT_COLOR_CYAN""fmt""FONT_COLOR_RESET, ##arg);     \
+       } while (0)
+
 #define mm_util_fenter() do { \
                LOGD(FONT_COLOR_YELLOW"<ENTER>"FONT_COLOR_RESET); \
        } while (0)
index 08e757e..2de2601 100755 (executable)
@@ -36,6 +36,7 @@ extern "C" {
 #define MMUTIL_SAFE_FREE(x)                            { if (x) { free(x); x = NULL; } }
 #define MMUTIL_SAFE_G_FREE(x)                  { if (x) { g_free(x); x = NULL; } }
 #define MMUTIL_SAFE_STRCPY(dst, src, n)        g_strlcpy(dst, src, n)
+#define MMUTIL_STRING_VALID(str)       ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
 
 #ifdef __cplusplus
 }
diff --git a/magick/CMakeLists.txt b/magick/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..932d2a8
--- /dev/null
@@ -0,0 +1,71 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(fw_name "mmutil_magick")
+
+PROJECT(${fw_name})
+
+SET(VERSION_MAJOR 0)
+SET(VERSION "${VERSION_MAJOR}.0.0")
+SET(CMAKE_INSTALL_PREFIX /usr)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+SET(INC_DIR
+       include
+       )
+INCLUDE_DIRECTORIES(${INC_DIR}
+       ../common/include
+       )
+
+SET(dependents "dlog glib-2.0 GraphicsMagick")
+SET(pc_dependents "dlog capi-base-common")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${fw_name} REQUIRED ${dependents})
+FOREACH(flag ${${fw_name}_CFLAGS})
+    SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+
+IF("${ARCH}" STREQUAL "arm")
+    ADD_DEFINITIONS("-DTARGET")
+ENDIF("${ARCH}" STREQUAL "arm")
+
+ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
+ADD_DEFINITIONS("-DLIBPREFIX=\"${LIB_INSTALL_DIR}\"")
+ADD_DEFINITIONS("-DTIZEN_DEBUG")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}")
+
+aux_source_directory(. SOURCES)
+ADD_LIBRARY(${fw_name} SHARED ${SOURCES})
+TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS} bmp nsbmp)
+SET_TARGET_PROPERTIES(${fw_name}
+       PROPERTIES
+       VERSION ${VERSION}
+       SOVERSION ${VERSION_MAJOR}
+       CLEAN_DIRECT_OUTPUT 1
+)
+
+INSTALL(TARGETS ${fw_name} DESTINATION ${LIB_INSTALL_DIR})
+INSTALL(
+        DIRECTORY ${INC_DIR}/ DESTINATION include/mmf
+        FILES_MATCHING
+        PATTERN "*_internal.h" EXCLUDE
+        PATTERN "*_private.h" EXCLUDE
+        PATTERN "${INC_DIR}/*.h"
+        )
+
+SET(PC_NAME mmutil-magick)
+SET(PC_REQUIRED ${pc_dependents})
+SET(PC_LDFLAGS -l${fw_name})
+SET(PC_FILE_NAME ${PC_NAME}.pc.in)
+
+CONFIGURE_FILE(
+    ${PC_FILE_NAME}
+    ${CMAKE_CURRENT_SOURCE_DIR}/${PC_NAME}.pc
+    @ONLY
+)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PC_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+
+ADD_SUBDIRECTORY(test)
diff --git a/magick/include/mm_util_magick.h b/magick/include/mm_util_magick.h
new file mode 100755 (executable)
index 0000000..5000687
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * libmm-utility
+ *
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: YoungHun Kim <yh8004.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __MM_UTILITY_MAGICK_H__
+#define __MM_UTILITY_MAGICK_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "mm_util_type.h"
+
+typedef void *mm_util_image_h;
+
+/**
+ * Image formats
+ */
+typedef enum {
+       MM_UTIL_IMG_FMT_RGB888,         /**< RGB888 pixel format */
+       MM_UTIL_IMG_FMT_ARGB8888,      /**< ARGB8888 pixel format */
+       MM_UTIL_IMG_FMT_BGRA8888,      /**< BGRA8888 pixel format */
+       MM_UTIL_IMG_FMT_RGBA8888,      /**< RGBA8888 pixel format */
+       MM_UTIL_IMG_FMT_NUM,             /**< Number of image formats */
+} mm_util_magick_format;
+
+
+/**
+ * Image rotation types
+ */
+typedef enum {
+       MM_UTIL_ROTATE_0 = 0,               /**< Rotation 0 degree - no effect */
+       MM_UTIL_ROTATE_90 = 90,              /**< Rotation 90 degree */
+       MM_UTIL_ROTATE_180 = 180,             /**< Rotation 180 degree */
+       MM_UTIL_ROTATE_270 = 270,             /**< Rotation 270 degree */
+       MM_UTIL_ROTATE_FLIP_HORZ,       /**< Flip horizontal */
+       MM_UTIL_ROTATE_FLIP_VERT,       /**< Flip vertial */
+       MM_UTIL_ROTATE_NUM              /**< Number of rotation types */
+} mm_util_magick_rotate_type;
+
+int mm_util_create_handle(mm_util_image_h *handle, const unsigned char *buffer, unsigned int width, unsigned int height, size_t size, mm_util_magick_format format);
+
+/*You must release buffer using free().*/
+int mm_util_get_image(mm_util_image_h handle, unsigned char **buffer, unsigned int *width, unsigned int *height, size_t *size, mm_util_magick_format *format);
+int mm_util_destroy_handle(mm_util_image_h handle);
+
+//src path and dst path must be the same format.
+int mm_util_rotate_B_B(mm_util_image_h src_handle, mm_util_magick_rotate_type angle, mm_util_image_h *dst_handle);
+int mm_util_rotate_B_P(mm_util_image_h src_handle, mm_util_magick_rotate_type angle, const char *dst_path);
+int mm_util_rotate_P_B(const char *src_path, mm_util_magick_rotate_type angle, mm_util_magick_format req_format, mm_util_image_h *dst_handle);
+int mm_util_rotate_P_P(const char *src_path, mm_util_magick_rotate_type angle, const char *dst_path);
+
+int mm_util_resize_B_B(mm_util_image_h src_handle, unsigned int req_width, unsigned int req_height, mm_util_image_h *dst_handle);
+int mm_util_resize_B_P(mm_util_image_h src_handle, unsigned int req_width, unsigned int req_height, const char *dst_path);
+int mm_util_resize_P_B(const char *src_path, unsigned int req_width, unsigned int req_height, mm_util_magick_format req_format, mm_util_image_h *dst_handle);
+int mm_util_resize_P_P(const char *src_path, unsigned int req_width, unsigned int req_height, const char *dst_path);
+
+#endif /*__MM_UTILITY_MAGICK_H__*/
diff --git a/magick/mm_util_magick.c b/magick/mm_util_magick.c
new file mode 100755 (executable)
index 0000000..b552508
--- /dev/null
@@ -0,0 +1,762 @@
+/*
+ * libmm-utility
+ *
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: YoungHun Kim <yh8004.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdbool.h>
+#include <magick/api.h>
+#include "mm_util_private.h"
+#include "mm_util_magick.h"
+
+typedef struct _util_image_s {
+       unsigned char *buffer;
+       unsigned int width;
+       unsigned int height;
+       size_t size;
+       mm_util_magick_format format;
+} util_image_s;
+
+static bool __mm_util_check_angle(mm_util_magick_rotate_type angle);
+
+static void __mm_util_init(ExceptionInfo *exception)
+{
+       InitializeMagick(NULL);
+
+       if (exception != NULL)
+               GetExceptionInfo(exception);
+
+       return;
+}
+
+static void __mm_util_finalize(Image *image_1, Image *image_2, ImageInfo *imageInfo, ExceptionInfo *exception)
+{
+
+       if (image_1 != NULL)
+               DestroyImage(image_1);
+
+       if (image_2 != NULL)
+               DestroyImage(image_2);
+
+       if (imageInfo != NULL)
+               DestroyImageInfo(imageInfo);
+
+       if (exception != NULL)
+               DestroyExceptionInfo(exception);
+
+       DestroyMagick();
+
+       return;
+}
+
+static int __mm_util_get_map(mm_util_magick_format format, char **map)
+{
+       mm_util_retvm_if(map == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid map");
+
+       switch (format) {
+       case MM_UTIL_IMG_FMT_RGB888:
+               *map = g_strdup("RGB");
+               break;
+       case MM_UTIL_IMG_FMT_ARGB8888:
+               *map = g_strdup("ARGB");
+               break;
+       case MM_UTIL_IMG_FMT_BGRA8888:
+               *map = g_strdup("BGRA");
+               break;
+       case MM_UTIL_IMG_FMT_RGBA8888:
+               *map = g_strdup("RGBA");
+               break;
+       default:
+               mm_util_error("Not supported format. [%d]", format);
+               return MM_UTIL_ERROR_INVALID_PARAMETER;
+       }
+
+       return MM_UTIL_ERROR_NONE;
+}
+
+static Image * __mm_util_constitute_image(mm_util_image_h handle, const char *map)
+{
+       util_image_s *_handle = (util_image_s*)handle;
+       Image *_image = NULL;
+       ExceptionInfo exception;
+
+       mm_util_fenter();
+
+       mm_util_retvm_if(handle == NULL, NULL, "invalid handle");
+       mm_util_retvm_if(!MMUTIL_STRING_VALID(map), NULL, "invalid map");
+
+       GetExceptionInfo(&exception);
+
+       /* Read image from buffer */
+       _image = ConstituteImage(_handle->width, _handle->height, map, CharPixel, _handle->buffer, &exception);
+       if (_image == NULL) {
+               mm_util_error("Error: Getting Image failed.");
+               if (exception.severity != UndefinedException)
+                       CatchException(&exception);
+       }
+
+       DestroyExceptionInfo(&exception);
+
+       return _image;
+}
+
+static Image * __mm_util_rotate_image(Image *image, mm_util_magick_rotate_type angle)
+{
+       Image *_processed_image = NULL;
+       ExceptionInfo exception;
+
+       mm_util_fenter();
+
+       mm_util_retvm_if(image == NULL, NULL, "invalid image");
+
+       GetExceptionInfo(&exception);
+
+       if (angle <= MM_UTIL_ROTATE_270) {
+               _processed_image = RotateImage(image, angle, &exception);
+       } else if (angle == MM_UTIL_ROTATE_FLIP_HORZ) {
+               _processed_image = FlopImage(image, &exception);
+       } else if (angle == MM_UTIL_ROTATE_FLIP_VERT) {
+               _processed_image = FlipImage(image, &exception);
+       } else {
+               mm_util_error("Invalid angle. [%d]", angle);
+       }
+
+       if (_processed_image == NULL) {
+               mm_util_error("Error: Image processing failed.");
+               if (exception.severity != UndefinedException)
+                       CatchException(&exception);
+       }
+
+       DestroyExceptionInfo(&exception);
+
+       return _processed_image;
+}
+
+static Image * __mm_util_resize_image(Image *image, unsigned int width, unsigned int height)
+{
+       Image *_processed_image = NULL;
+       ExceptionInfo exception;
+
+       mm_util_fenter();
+
+       mm_util_retvm_if(image == NULL, NULL, "invalid image");
+
+       GetExceptionInfo(&exception);
+
+       _processed_image = ResizeImage(image, width, height, DefaultResizeFilter, 1.0, &exception);
+       if (_processed_image == NULL) {
+               mm_util_error("Error: Image processing failed.");
+               if (exception.severity != UndefinedException)
+                       CatchException(&exception);
+       }
+
+       DestroyExceptionInfo(&exception);
+
+       return _processed_image;
+}
+
+static Image * __mm_util_read_image_from_file(const char *path, ImageInfo **image_info)
+{
+       ImageInfo *_image_info = NULL;
+       Image *_image = NULL;
+       ExceptionInfo exception;
+
+       mm_util_fenter();
+
+       mm_util_retvm_if(!MMUTIL_STRING_VALID(path), NULL, "invalid path");
+       mm_util_retvm_if(image_info == NULL, NULL, "invalid image_info");
+
+       GetExceptionInfo(&exception);
+
+       _image_info = CloneImageInfo(0);
+       g_strlcpy(_image_info->filename, path, sizeof(_image_info->filename));
+
+       _image = ReadImage(_image_info, &exception);
+
+       if (_image == NULL) {
+               mm_util_error("Error: Reading Image failed.");
+               if (exception.severity != UndefinedException)
+                       CatchException(&exception);
+
+               DestroyImageInfo(_image_info);
+       } else {
+               *image_info = _image_info;
+       }
+
+       DestroyExceptionInfo(&exception);
+
+       return _image;
+}
+
+static int __mm_util_write_image_to_file(ImageInfo *image_info, Image *image, const char *out_path)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       ExceptionInfo exception;
+
+       mm_util_fenter();
+
+       mm_util_retvm_if(image_info == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid image_info");
+       mm_util_retvm_if(image == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid image");
+       mm_util_retvm_if(!MMUTIL_STRING_VALID(out_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid out_path");
+
+       GetExceptionInfo(&exception);
+
+       image->filename[MaxTextExtent-1] = '\0';
+       strncpy(image->filename, out_path, sizeof(image->filename));
+       if (WriteImage (image_info, image) == MagickFalse) {
+               mm_util_error("Error: __mm_util_rotate_image failed.");
+               if (exception.severity != UndefinedException)
+                       CatchException(&exception);
+
+               ret = MM_UTIL_ERROR_INVALID_OPERATION;
+       }
+
+       DestroyExceptionInfo(&exception);
+
+       return ret;
+}
+
+static void * __mm_util_write_image_to_buffer(Image *image, unsigned int width, unsigned int height, const char *map, size_t *pixels_size)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       ExceptionInfo exception;
+       size_t _pixels_size = 0;
+       void *pixels = NULL;
+
+       mm_util_fenter();
+
+       mm_util_retvm_if(image == NULL, NULL, "invalid image");
+       mm_util_retvm_if(!MMUTIL_STRING_VALID(map), NULL, "invalid map");
+
+       GetExceptionInfo(&exception);
+
+       _pixels_size = sizeof(unsigned char) * strlen(map) * width *height;
+       pixels = MagickMalloc(_pixels_size);
+
+       if (pixels == NULL) {
+               mm_util_error("Error: calloc failed.");
+               goto ERROR;
+       }
+
+       ret = DispatchImage(image, 0, 0, width, height, map, CharPixel, pixels, &exception);
+       if (ret == MagickFail) {
+               mm_util_error("Failed to Dispatch Image into dst buffer");
+               MagickFree(pixels);
+               pixels = NULL;
+               goto ERROR;
+       }
+
+       *pixels_size = _pixels_size;
+ERROR:
+
+       DestroyExceptionInfo(&exception);
+
+       return pixels;
+}
+
+static bool __mm_util_check_angle(mm_util_magick_rotate_type angle)
+{
+       if ((angle == MM_UTIL_ROTATE_0) || (angle == MM_UTIL_ROTATE_90) || (angle == MM_UTIL_ROTATE_180) || (angle == MM_UTIL_ROTATE_270) ||
+               (angle == MM_UTIL_ROTATE_FLIP_HORZ) || (angle == MM_UTIL_ROTATE_FLIP_VERT))
+               return TRUE;
+       else
+               return FALSE;
+}
+
+int mm_util_create_handle(mm_util_image_h *handle, const unsigned char *buffer, unsigned int width, unsigned int height, size_t size, mm_util_magick_format format)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+
+       mm_util_retvm_if(handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle");
+
+       util_image_s *_handle = (util_image_s*)calloc(1, sizeof(util_image_s));
+       mm_util_retvm_if(_handle == NULL, MM_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+
+       _handle->buffer = (unsigned char *)buffer;
+       _handle->width = width;
+       _handle->height = height;
+       _handle->size = size;
+       _handle->format = format;
+
+       *handle = (mm_util_image_h)_handle;
+
+       return ret;
+}
+
+int mm_util_get_image(mm_util_image_h handle, unsigned char **buffer, unsigned int *width, unsigned int *height, size_t *size, mm_util_magick_format *format)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+
+       mm_util_retvm_if(handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle");
+       mm_util_retvm_if(buffer == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid buffer");
+       mm_util_retvm_if(width == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid width");
+       mm_util_retvm_if(height == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid height");
+       mm_util_retvm_if(size == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid size");
+       mm_util_retvm_if(format == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid format");
+
+       util_image_s *_handle = (util_image_s*)handle;
+
+       *buffer = _handle->buffer;
+       *width = _handle->width;
+       *height = _handle->height;
+       *size = _handle->size;
+       *format = _handle->format;
+
+       return ret;
+}
+
+int mm_util_destroy_handle(mm_util_image_h handle)
+{
+       mm_util_retvm_if(handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle");
+
+       util_image_s *_handle = (util_image_s*)handle;
+
+       MMUTIL_SAFE_FREE(_handle);
+
+       return MM_UTIL_ERROR_NONE;
+}
+
+int mm_util_rotate_B_B(mm_util_image_h src_handle, mm_util_magick_rotate_type angle, mm_util_image_h *dst_handle)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       util_image_s *_src_handle = (util_image_s*)src_handle;
+       char *map = NULL;
+       Image *_image = NULL;
+       Image *_processed_image = NULL;
+       ExceptionInfo exception;
+       size_t pixels_size = 0;
+       void *pixels = 0;
+
+       mm_util_retvm_if(src_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle");
+       mm_util_retvm_if(!__mm_util_check_angle(angle), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid angle [%d]", angle);
+       mm_util_retvm_if(dst_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_handle");
+
+       mm_util_debug("angle [%d]", angle);
+
+       ret = __mm_util_get_map(_src_handle->format, &map);
+       mm_util_retvm_if((ret != MM_UTIL_ERROR_NONE) || (map == NULL), ret, "fail to get map");
+
+       __mm_util_init(&exception);
+
+       _image = __mm_util_constitute_image(src_handle, map);
+       if (_image == NULL) {
+               mm_util_error("Error: __mm_util_constitute_image failed.");
+               ret = MM_UTIL_ERROR_INVALID_OPERATION;
+               goto ERROR;
+       }
+
+       _processed_image = __mm_util_rotate_image(_image, angle);
+       if (_processed_image == NULL) {
+               mm_util_error("Error: __mm_util_rotate_image failed.");
+               ret = MM_UTIL_ERROR_INVALID_OPERATION;
+               goto ERROR;
+       }
+
+       pixels = __mm_util_write_image_to_buffer(_processed_image, _processed_image->columns, _processed_image->rows, map, &pixels_size);
+       if (pixels == NULL) {
+               mm_util_error("Error: __mm_util_write_image_to_buffer failed.");
+               ret = MM_UTIL_ERROR_INVALID_OPERATION;
+               goto ERROR;
+       }
+
+       ret = mm_util_create_handle(dst_handle, pixels, _processed_image->columns, _processed_image->rows, pixels_size, _src_handle->format);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               mm_util_error("Error: __mm_util_write_image_to_buffer failed.");
+               MagickFree(pixels);
+       }
+
+ERROR:
+
+       __mm_util_finalize(_image, _processed_image, NULL, &exception);
+
+       MMUTIL_SAFE_FREE(map);
+
+       return ret;
+}
+
+int mm_util_rotate_B_P(mm_util_image_h src_handle, mm_util_magick_rotate_type angle, const char *dst_path)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       util_image_s *_src_handle = (util_image_s*)src_handle;
+       char *map = NULL;
+       Image *_image = NULL;
+       Image *_processed_image = NULL;
+       ImageInfo *_image_info = NULL;
+       ExceptionInfo exception;
+
+       mm_util_retvm_if(src_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle");
+       mm_util_retvm_if(!__mm_util_check_angle(angle), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid angle [%d]", angle);
+       mm_util_retvm_if(!MMUTIL_STRING_VALID(dst_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_path");
+
+       mm_util_sec_debug("angle [%d] dst_path [%s]", angle, dst_path);
+
+       ret = __mm_util_get_map(_src_handle->format, &map);
+       mm_util_retvm_if((ret != MM_UTIL_ERROR_NONE) || (map == NULL), ret, "fail to get map");
+
+       __mm_util_init(&exception);
+
+       _image = __mm_util_constitute_image(src_handle, map);
+       if (_image == NULL) {
+               mm_util_error("Error: __mm_util_constitute_image failed.");
+               ret = MM_UTIL_ERROR_INVALID_OPERATION;
+               goto ERROR;
+       }
+
+       _processed_image = __mm_util_rotate_image(_image, angle);
+       if (_processed_image == NULL) {
+               mm_util_error("Error: __mm_util_rotate_image failed.");
+               ret = MM_UTIL_ERROR_INVALID_OPERATION;
+               goto ERROR;
+       }
+
+       _image_info = CloneImageInfo(0);
+       ret = __mm_util_write_image_to_file(_image_info, _processed_image, dst_path);
+
+ERROR:
+
+       __mm_util_finalize(_image, _processed_image, _image_info, &exception);
+
+       MMUTIL_SAFE_FREE(map);
+
+       return ret;
+}
+
+int mm_util_rotate_P_B(const char *src_path, mm_util_magick_rotate_type angle, mm_util_magick_format req_format, mm_util_image_h *dst_handle)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       char *map = NULL;
+       Image *_image = NULL;
+       Image *_processed_image = NULL;
+       ImageInfo *_image_info = NULL;
+       ExceptionInfo exception;
+       size_t pixels_size = 0;
+       void *pixels = 0;
+
+       mm_util_retvm_if(!MMUTIL_STRING_VALID(src_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_path");
+       mm_util_retvm_if(!__mm_util_check_angle(angle), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid angle [%d]", angle);
+       mm_util_retvm_if(dst_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_handle");
+
+       mm_util_sec_debug("src_path [%s] angle [%d] req_format [%d]", src_path, angle, req_format);
+
+       ret = __mm_util_get_map(req_format, &map);
+       mm_util_retvm_if((ret != MM_UTIL_ERROR_NONE) || (map == NULL), ret, "fail to get map");
+
+       __mm_util_init(&exception);
+
+       _image = __mm_util_read_image_from_file(src_path, &_image_info);
+       if (_image == NULL) {
+               mm_util_error("Error: __mm_util_read_image_from_file failed.");
+               ret = MM_UTIL_ERROR_INVALID_OPERATION;
+               goto ERROR;
+       }
+
+       _processed_image = __mm_util_rotate_image(_image, angle);
+       if (_processed_image == NULL) {
+               mm_util_error("Error: __mm_util_rotate_image failed.");
+               ret = MM_UTIL_ERROR_INVALID_OPERATION;
+               goto ERROR;
+       }
+
+       pixels = __mm_util_write_image_to_buffer(_processed_image, _processed_image->columns, _processed_image->rows, map, &pixels_size);
+       if (pixels == NULL) {
+               mm_util_error("Error: __mm_util_write_image_to_buffer failed.");
+               ret = MM_UTIL_ERROR_INVALID_OPERATION;
+               goto ERROR;
+       }
+
+       ret = mm_util_create_handle(dst_handle, pixels, _processed_image->columns, _processed_image->rows, pixels_size, req_format);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               mm_util_error("Error: __mm_util_write_image_to_buffer failed.");
+               MagickFree(pixels);
+       }
+
+ERROR:
+
+       __mm_util_finalize(_image, _processed_image, _image_info, &exception);
+
+       MMUTIL_SAFE_FREE(map);
+
+       return ret;
+}
+
+
+int mm_util_rotate_P_P(const char *src_path, mm_util_magick_rotate_type angle, const char *dst_path)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       Image *_image = NULL;
+       Image *_processed_image = NULL;
+       ImageInfo *_image_info = NULL;
+       ExceptionInfo exception;
+
+       mm_util_retvm_if(!MMUTIL_STRING_VALID(src_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_path");
+       mm_util_retvm_if(!__mm_util_check_angle(angle), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid angle [%d]", angle);
+       mm_util_retvm_if(!MMUTIL_STRING_VALID(dst_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_path");
+
+       mm_util_sec_debug("src_path [%s] angle [%d] dst_path [%s]", src_path, angle, dst_path);
+
+       __mm_util_init(&exception);
+
+       _image = __mm_util_read_image_from_file(src_path, &_image_info);
+       if (_image == NULL) {
+               mm_util_error("Error: __mm_util_read_image_from_file failed.");
+               ret = MM_UTIL_ERROR_INVALID_OPERATION;
+               goto ERROR;
+       }
+
+       _processed_image = __mm_util_rotate_image(_image, angle);
+       if (_processed_image == NULL) {
+               mm_util_error("Error: __mm_util_rotate_image failed.");
+               ret = MM_UTIL_ERROR_INVALID_OPERATION;
+               goto ERROR;
+       }
+
+       ret = __mm_util_write_image_to_file(_image_info, _processed_image, dst_path);
+
+ERROR:
+
+       __mm_util_finalize(_image, _processed_image, _image_info, &exception);
+
+       return ret;
+}
+
+int mm_util_resize_B_B(mm_util_image_h src_handle, unsigned int req_width, unsigned int req_height, mm_util_image_h *dst_handle)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       util_image_s *_src_handle = (util_image_s*)src_handle;
+       char *map = NULL;
+       Image *_image = NULL;
+       Image *_processed_image = NULL;
+       ExceptionInfo exception;
+       size_t pixels_size = 0;
+       void *pixels = 0;
+
+       mm_util_retvm_if(src_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle");
+       mm_util_retvm_if((req_width == 0) || (req_height == 0), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid size W[%d] H[%d]", req_width, req_height);
+       mm_util_retvm_if(dst_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_handle");
+
+       mm_util_debug("req_width [%d] req_height [%d]", req_width, req_height);
+
+       ret = __mm_util_get_map(_src_handle->format, &map);
+       mm_util_retvm_if((ret != MM_UTIL_ERROR_NONE) || (map == NULL), ret, "fail to get map");
+
+       __mm_util_init(&exception);
+
+       _image = __mm_util_constitute_image(src_handle, map);
+       if (_image == NULL) {
+               mm_util_error("Error: __mm_util_constitute_image failed.");
+               ret = MM_UTIL_ERROR_INVALID_OPERATION;
+               goto ERROR;
+       }
+
+       if ((_image->columns < req_width) || (_image->rows < req_height)) {
+               mm_util_error("Wrong Size. image [%d * %d], request [%d * %d]", _image->columns, _image->rows, req_width, req_height);
+               ret = MM_UTIL_ERROR_INVALID_PARAMETER;
+               goto ERROR;
+       }
+
+       _processed_image = __mm_util_resize_image(_image, req_width, req_height);
+       if (_processed_image == NULL) {
+               mm_util_error("Error: __mm_util_resize_image failed.");
+               ret = MM_UTIL_ERROR_INVALID_OPERATION;
+               goto ERROR;
+       }
+
+       pixels = __mm_util_write_image_to_buffer(_processed_image, _processed_image->columns, _processed_image->rows, map, &pixels_size);
+       if (pixels == NULL) {
+               mm_util_error("Error: __mm_util_write_image_to_buffer failed.");
+               ret = MM_UTIL_ERROR_INVALID_OPERATION;
+               goto ERROR;
+       }
+
+       ret = mm_util_create_handle(dst_handle, pixels, _processed_image->columns, _processed_image->rows, pixels_size, _src_handle->format);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               mm_util_error("Error: __mm_util_write_image_to_buffer failed.");
+               MagickFree(pixels);
+       }
+
+ERROR:
+
+       __mm_util_finalize(_image, _processed_image, NULL, &exception);
+
+       MMUTIL_SAFE_FREE(map);
+
+       return ret;
+}
+
+int mm_util_resize_B_P(mm_util_image_h src_handle, unsigned int req_width, unsigned int req_height, const char *dst_path)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       util_image_s *_src_handle = (util_image_s*)src_handle;
+       char *map = NULL;
+       Image *_image = NULL;
+       Image *_processed_image = NULL;
+       ImageInfo *_image_info = NULL;
+       ExceptionInfo exception;
+
+       mm_util_retvm_if(src_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle");
+       mm_util_retvm_if((req_width == 0) || (req_height == 0), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid size W[%d] H[%d]", req_width, req_height);
+       mm_util_retvm_if(!MMUTIL_STRING_VALID(dst_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_path");
+
+       mm_util_sec_debug("req_width [%d] req_height [%d] dst_path [%s]", req_width, req_height, dst_path);
+
+       ret = __mm_util_get_map(_src_handle->format, &map);
+       mm_util_retvm_if((ret != MM_UTIL_ERROR_NONE) || (map == NULL), ret, "fail to get map");
+
+       __mm_util_init(&exception);
+
+       _image = __mm_util_constitute_image(src_handle, map);
+       if (_image == NULL) {
+               mm_util_error("Error: __mm_util_constitute_image failed.");
+               ret = MM_UTIL_ERROR_INVALID_OPERATION;
+               goto ERROR;
+       }
+
+       if ((_image->columns < req_width) || (_image->rows < req_height)) {
+               mm_util_error("Wrong Size. image [%d * %d], request [%d * %d]", _image->columns, _image->rows, req_width, req_height);
+               ret = MM_UTIL_ERROR_INVALID_PARAMETER;
+               goto ERROR;
+       }
+
+       _processed_image = __mm_util_resize_image(_image, req_width, req_height);
+       if (_processed_image == NULL) {
+               mm_util_error("Error: __mm_util_resize_image failed.");
+               ret = MM_UTIL_ERROR_INVALID_OPERATION;
+               goto ERROR;
+       }
+
+       _image_info = CloneImageInfo(0);
+       ret = __mm_util_write_image_to_file(_image_info, _processed_image, dst_path);
+
+ERROR:
+
+       __mm_util_finalize(_image, _processed_image, _image_info, &exception);
+
+       MMUTIL_SAFE_FREE(map);
+
+       return ret;
+}
+
+int mm_util_resize_P_B(const char *src_path, unsigned int req_width, unsigned int req_height, mm_util_magick_format req_format, mm_util_image_h *dst_handle)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       char *map = NULL;
+       Image *_image = NULL;
+       Image *_processed_image = NULL;
+       ImageInfo *_image_info = NULL;
+       ExceptionInfo exception;
+       size_t pixels_size = 0;
+       void *pixels = 0;
+
+       mm_util_retvm_if(!MMUTIL_STRING_VALID(src_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_path");
+       mm_util_retvm_if((req_width == 0) || (req_height == 0), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid size W[%d] H[%d]", req_width, req_height);
+       mm_util_retvm_if(dst_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_handle");
+
+       mm_util_sec_debug("src_path [%s] req_width [%d] req_height [%d]", src_path, req_width, req_height);
+
+       ret = __mm_util_get_map(req_format, &map);
+       mm_util_retvm_if((ret != MM_UTIL_ERROR_NONE) || (map == NULL), ret, "fail to get map");
+
+       __mm_util_init(&exception);
+
+       _image = __mm_util_read_image_from_file(src_path, &_image_info);
+       if (_image == NULL) {
+               mm_util_error("Error: __mm_util_read_image_from_file failed.");
+               ret = MM_UTIL_ERROR_INVALID_OPERATION;
+               goto ERROR;
+       }
+
+       if ((_image->columns < req_width) || (_image->rows < req_height)) {
+               mm_util_error("Wrong Size. image [%d * %d], request [%d * %d]", _image->columns, _image->rows, req_width, req_height);
+               ret = MM_UTIL_ERROR_INVALID_PARAMETER;
+               goto ERROR;
+       }
+
+       _processed_image = __mm_util_resize_image(_image, req_width, req_height);
+       if (_processed_image == NULL) {
+               mm_util_error("Error: __mm_util_resize_image failed.");
+               ret = MM_UTIL_ERROR_INVALID_OPERATION;
+               goto ERROR;
+       }
+
+       pixels = __mm_util_write_image_to_buffer(_processed_image, _processed_image->columns, _processed_image->rows, map, &pixels_size);
+       if (pixels == NULL) {
+               mm_util_error("Error: __mm_util_write_image_to_buffer failed.");
+               ret = MM_UTIL_ERROR_INVALID_OPERATION;
+               goto ERROR;
+       }
+
+       ret = mm_util_create_handle(dst_handle, pixels, _processed_image->columns, _processed_image->rows, pixels_size, req_format);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               mm_util_error("Error: __mm_util_write_image_to_buffer failed.");
+               MagickFree(pixels);
+       }
+
+ERROR:
+
+       __mm_util_finalize(_image, _processed_image, _image_info, &exception);
+
+       MMUTIL_SAFE_FREE(map);
+
+       return ret;
+}
+
+int mm_util_resize_P_P(const char *src_path, unsigned int req_width, unsigned int req_height, const char *dst_path)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       Image *_image = NULL;
+       Image *_processed_image = NULL;
+       ImageInfo *_image_info = NULL;
+       ExceptionInfo exception;
+
+       mm_util_retvm_if(!MMUTIL_STRING_VALID(src_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_path");
+       mm_util_retvm_if((req_width == 0) || (req_height == 0), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid size W[%d] H[%d]", req_width, req_height);
+       mm_util_retvm_if(!MMUTIL_STRING_VALID(dst_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_path");
+
+       mm_util_sec_debug("src_path [%s] req_width [%d] req_height [%d] dst_path [%s]", src_path, req_width, req_height, dst_path);
+
+       __mm_util_init(&exception);
+
+       _image = __mm_util_read_image_from_file(src_path, &_image_info);
+       if (_image == NULL) {
+               mm_util_error("Error: __mm_util_read_image_from_file failed.");
+               ret = MM_UTIL_ERROR_INVALID_OPERATION;
+               goto ERROR;
+       }
+
+       if ((_image->columns < req_width) || (_image->rows < req_height)) {
+               mm_util_error("Wrong Size. image [%d * %d], request [%d * %d]", _image->columns, _image->rows, req_width, req_height);
+               ret = MM_UTIL_ERROR_INVALID_PARAMETER;
+               goto ERROR;
+       }
+
+       _processed_image = __mm_util_resize_image(_image, req_width, req_height);
+       if (_processed_image == NULL) {
+               mm_util_error("Error: __mm_util_resize_image failed.");
+               ret = MM_UTIL_ERROR_INVALID_OPERATION;
+               goto ERROR;
+       }
+
+       ret = __mm_util_write_image_to_file(_image_info, _processed_image, dst_path);
+
+ERROR:
+
+       __mm_util_finalize(_image, _processed_image, _image_info, &exception);
+
+       return ret;
+}
+
diff --git a/magick/mmutil-magick.pc.in b/magick/mmutil-magick.pc.in
new file mode 100755 (executable)
index 0000000..3004389
--- /dev/null
@@ -0,0 +1,11 @@
+prefix=@PREFIX@
+exec_prefix=/usr
+libdir=@LIB_INSTALL_DIR@
+includedir=/usr/include/mmf
+
+Name : @PC_NAME@
+Description : Multimedia Framework Utility Library
+Requires : @PC_REQUIRED@
+Version : @VERSION@
+Libs : -L${libdir} @PC_LDFLAGS@
+Cflags : -I${includedir} -DLIBPREFIX=\"${libdir}\"
diff --git a/magick/test/CMakeLists.txt b/magick/test/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..dc7a70f
--- /dev/null
@@ -0,0 +1,18 @@
+SET(fw_name "mmutil_magick")
+SET(fw_test "${fw_name}-test")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${fw_test} REQUIRED glib-2.0 dlog libtzplatform-config)
+FOREACH(flag ${${fw_test}_CFLAGS})
+    SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -fPIE")
+
+aux_source_directory(. sources)
+FOREACH(src ${sources})
+    GET_FILENAME_COMPONENT(src_name ${src} NAME_WE)
+    MESSAGE("${src_name}")
+    ADD_EXECUTABLE(${src_name} ${src})
+    TARGET_LINK_LIBRARIES(${src_name} ${fw_name} ${${fw_test}_LDFLAGS})
+ENDFOREACH()
diff --git a/magick/test/mm_util_magick_testsuite.c b/magick/test/mm_util_magick_testsuite.c
new file mode 100755 (executable)
index 0000000..5523235
--- /dev/null
@@ -0,0 +1,491 @@
+/*
+ * libmm-utility
+ *
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: YoungHun Kim <yh8004.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <mm_util_magick.h>
+
+typedef enum {
+       MM_UTIL_RESIZE,
+       MM_UTIL_ROTATE,
+} mm_util_func_e;
+
+#define MM_UTIL_SAFE_FREE(src) { if (src) { free(src); src = NULL; } }
+
+static int _magick_rotate_P_P_test(mm_util_magick_rotate_type angle);
+static int _magick_rotate_P_B_test(mm_util_magick_rotate_type angle, mm_util_magick_format req_format);
+static int _magick_rotate_B_P_test(mm_util_magick_rotate_type angle, mm_util_magick_format req_format);
+static int _magick_rotate_B_B_test(mm_util_magick_rotate_type angle, mm_util_magick_format req_format);
+static int _magick_resize_P_P_test(unsigned int req_width, unsigned int req_height);
+static int _magick_resize_P_B_test(unsigned int req_width, unsigned int req_height, mm_util_magick_format req_format);
+static int _magick_resize_B_P_test(unsigned int req_width, unsigned int req_height, mm_util_magick_format req_format);
+static int _magick_resize_B_B_test(unsigned int req_width, unsigned int req_height, mm_util_magick_format req_format);
+
+static char *__get_dst_path(mm_util_magick_rotate_type angle)
+{
+       switch (angle) {
+       case MM_UTIL_ROTATE_0:
+               return "/opt/usr/home/owner/dst_0.jpg";
+       case MM_UTIL_ROTATE_90:
+               return "/opt/usr/home/owner/dst_90.jpg";
+       case MM_UTIL_ROTATE_180:
+               return "/opt/usr/home/owner/dst_180.jpg";
+       case MM_UTIL_ROTATE_270:
+               return "/opt/usr/home/owner/dst_270.jpg";
+       case MM_UTIL_ROTATE_FLIP_HORZ:
+               return "/opt/usr/home/owner/dst_H.jpg";
+       case MM_UTIL_ROTATE_FLIP_VERT:
+               return "/opt/usr/home/owner/dst_V.jpg";
+       default:
+               printf("Invalid angle\n");
+               return "/opt/usr/home/owner/dst_default.jpg";
+       }
+
+       return NULL;
+}
+
+static char *__get_dst_raw_path(mm_util_magick_rotate_type angle)
+{
+       switch (angle) {
+       case MM_UTIL_ROTATE_0:
+               return "/opt/usr/home/owner/dst_0.raw";
+       case MM_UTIL_ROTATE_90:
+               return "/opt/usr/home/owner/dst_90.raw";
+       case MM_UTIL_ROTATE_180:
+               return "/opt/usr/home/owner/dst_180.raw";
+       case MM_UTIL_ROTATE_270:
+               return "/opt/usr/home/owner/dst_270.raw";
+       case MM_UTIL_ROTATE_FLIP_HORZ:
+               return "/opt/usr/home/owner/dst_H.raw";
+       case MM_UTIL_ROTATE_FLIP_VERT:
+               return "/opt/usr/home/owner/dst_V.raw";
+       default:
+               printf("Invalid angle\n");
+               return "/opt/usr/home/owner/dst_default.raw";
+       }
+
+       return NULL;
+}
+
+static void __write_to_file(const char *out_path, unsigned char *buffer, size_t buffer_size)
+{
+       FILE *fp = NULL;
+
+       fp = fopen(out_path, "w");
+       if (fp != NULL) {
+               fwrite(buffer, 1, buffer_size, fp);
+               fclose(fp);
+       }
+
+       return;
+}
+
+static void __save_to_file(mm_util_image_h handle, const char *out_path)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       unsigned char *buffer = NULL;
+       unsigned int width = 0;
+       unsigned int height = 0;
+       size_t size = 0;
+       mm_util_magick_format format = MM_UTIL_IMG_FMT_NUM;
+
+       ret = mm_util_get_image(handle, &buffer, &width, &height, &size, &format);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_get_image [%d]\n", ret);
+               return;
+       }
+
+       printf("[save to file] buffer[%p], width[%d], height[%d], size[%d], format [%d], out_path [%s]\n", buffer, width, height, size, format, out_path);
+
+       __write_to_file(out_path, buffer, size);
+
+       MM_UTIL_SAFE_FREE(buffer);
+
+       return;
+}
+
+static int __get_buffer_for_test(mm_util_magick_format req_format, unsigned char **buffer,  unsigned int *width, unsigned int *height, size_t *size, mm_util_magick_format *format)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       mm_util_image_h dst_handle = NULL;
+       char * src_path = "/opt/usr/home/owner/origin.jpg";
+
+       ret = mm_util_resize_P_B(src_path, 4000, 3000, req_format, &dst_handle);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail [%d]\n", ret);
+               return ret;
+       }
+
+       ret = mm_util_get_image(dst_handle, buffer, width, height, size, format);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_get_image [%d]\n", ret);
+               MM_UTIL_SAFE_FREE(*buffer);
+               return ret;
+       }
+
+       printf("[get_buffer] buffer[%p], width[%d], height[%d], size[%d], format [%d]\n", *buffer, *width, *height, *size, *format);
+
+       ret = mm_util_destroy_handle(dst_handle);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_destroy_handle [%d]\n", ret);
+               MM_UTIL_SAFE_FREE(*buffer);
+               return ret;
+       }
+
+       return ret;
+}
+
+static int _magick_rotate_P_P_test(mm_util_magick_rotate_type angle)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       char * src_path = "/opt/usr/home/owner/origin.jpg";
+
+       printf("* Rotate P P Test * angle = [%d]* \n", angle);
+
+       ret = mm_util_rotate_P_P(src_path, angle, __get_dst_path(angle));
+       if (ret != MM_UTIL_ERROR_NONE)
+               printf("Fail mm_util_rotate_P_P [%d]\n", ret);
+
+       return ret;
+}
+
+static int _magick_resize_P_P_test(unsigned int req_width, unsigned int req_height)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       char * src_path = "/opt/usr/home/owner/origin.jpg";
+       char dst_path[1024] = {0, };
+       memset(dst_path, 0x00, sizeof(dst_path));
+       snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/resize_pp_%d_%d.jpg", req_width, req_height);
+       //snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/resize_%d_%d.png", req_width, req_height);
+
+       printf("* Resize P P Test * W * H = [%d * %d], path = [%s] \n", req_width, req_height, dst_path);
+
+       ret = mm_util_resize_P_P(src_path, req_width, req_height, dst_path);
+       if (ret != MM_UTIL_ERROR_NONE)
+               printf("Fail mm_util_resize_P_P [%d]\n", ret);
+
+       return ret;
+}
+
+static int _magick_rotate_P_B_test(mm_util_magick_rotate_type angle, mm_util_magick_format req_format)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       mm_util_image_h dst_handle = NULL;
+       char * src_path = "/opt/usr/home/owner/origin.jpg";
+
+       printf("* Rotate P B Test * angle = [%d] foramt = [%d] \n", angle, req_format);
+
+       ret = mm_util_rotate_P_B(src_path, angle, req_format, &dst_handle);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_rotate_P_B [%d]\n", ret);
+               return ret;
+       }
+
+       __save_to_file(dst_handle, __get_dst_raw_path(angle));
+
+       ret = mm_util_destroy_handle(dst_handle);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_destroy_handle [%d]\n", ret);
+               return ret;
+       }
+
+       return ret;
+}
+
+static int _magick_resize_P_B_test(unsigned int req_width, unsigned int req_height, mm_util_magick_format req_format)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       mm_util_image_h dst_handle = NULL;
+       char * src_path = "/opt/usr/home/owner/origin.jpg";
+       char dst_path[1024] = {0, };
+       memset(dst_path, 0x00, sizeof(dst_path));
+       snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/resize_pb_%d_%d.raw", req_width, req_height);
+
+       printf("* Resize P B Test * W * H [%d * %d], foramt [%d], path [%s]\n", req_width, req_height, req_format, dst_path);
+
+       ret = mm_util_resize_P_B(src_path, req_width, req_height, req_format, &dst_handle);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_resize_P_B [%d]\n", ret);
+               return ret;
+       }
+
+       __save_to_file(dst_handle, dst_path);
+
+       ret = mm_util_destroy_handle(dst_handle);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_destroy_handle [%d]\n", ret);
+               return ret;
+       }
+
+       return ret;
+}
+
+static int _magick_rotate_B_P_test(mm_util_magick_rotate_type angle, mm_util_magick_format req_format)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       mm_util_image_h src_handle = NULL;
+       unsigned char *buffer = NULL;
+       unsigned int width = 0;
+       unsigned int height = 0;
+       size_t size = 0;
+       mm_util_magick_format format = MM_UTIL_IMG_FMT_NUM;
+
+       printf("* Rotate B P Test * angle = [%d] \n", angle);
+
+       ret = __get_buffer_for_test(req_format, &buffer, &width, &height, &size, &format);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail __get_buffer_for_test [%d]\n", ret);
+               return ret;
+       }
+
+       ret = mm_util_create_handle(&src_handle, buffer, width, height, size, format);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_create_handle [%d]\n", ret);
+               MM_UTIL_SAFE_FREE(buffer);
+               return ret;
+       }
+
+       ret = mm_util_rotate_B_P(src_handle, angle, __get_dst_path(angle));
+       if (ret != MM_UTIL_ERROR_NONE)
+               printf("Fail mm_util_rotate_B_P [%d]\n", ret);
+
+       ret = mm_util_destroy_handle(src_handle);
+       if (ret != MM_UTIL_ERROR_NONE)
+               printf("Fail mm_util_destroy_handle [%d]\n", ret);
+
+       MM_UTIL_SAFE_FREE(buffer);
+
+       return ret;
+}
+
+static int _magick_resize_B_P_test(unsigned int req_width, unsigned int req_height, mm_util_magick_format req_format)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       mm_util_image_h src_handle = NULL;
+       unsigned char *buffer = NULL;
+       unsigned int width = 0;
+       unsigned int height = 0;
+       size_t size = 0;
+       mm_util_magick_format format = MM_UTIL_IMG_FMT_NUM;
+       char dst_path[1024] = {0, };
+       memset(dst_path, 0x00, sizeof(dst_path));
+       snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/resize_bp_%d_%d.jpg", req_width, req_height);
+
+       printf("* Resize B P Test * W * H [%d * %d], foramt [%d], path [%s]\n", req_width, req_height, req_format, dst_path);
+
+       ret = __get_buffer_for_test(req_format, &buffer, &width, &height, &size, &format);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail __get_buffer_for_test [%d]\n", ret);
+               return ret;
+       }
+
+       ret = mm_util_create_handle(&src_handle, buffer, width, height, size, format);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_create_handle [%d]\n", ret);
+               MM_UTIL_SAFE_FREE(buffer);
+               return ret;
+       }
+
+       ret = mm_util_resize_B_P(src_handle, req_width, req_height, dst_path);
+       if (ret != MM_UTIL_ERROR_NONE)
+               printf("Fail mm_util_resize_B_P [%d]\n", ret);
+
+       ret = mm_util_destroy_handle(src_handle);
+       if (ret != MM_UTIL_ERROR_NONE)
+               printf("Fail mm_util_destroy_handle [%d]\n", ret);
+
+       MM_UTIL_SAFE_FREE(buffer);
+
+       return ret;
+}
+
+static int _magick_rotate_B_B_test(mm_util_magick_rotate_type angle, mm_util_magick_format req_format)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       mm_util_image_h src_handle = NULL;
+       mm_util_image_h dst_handle = NULL;
+       unsigned char *buffer = NULL;
+       unsigned int width = 0;
+       unsigned int height = 0;
+       size_t size = 0;
+       mm_util_magick_format format = MM_UTIL_IMG_FMT_NUM;
+
+       printf("* Rotate B B Test * angle = [%d] \n", angle);
+
+       ret = __get_buffer_for_test(req_format, &buffer, &width, &height, &size, &format);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail __get_buffer_for_test [%d]\n", ret);
+               return ret;
+       }
+
+       ret = mm_util_create_handle(&src_handle, buffer, width, height, size, format);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_create_handle [%d]\n", ret);
+               MM_UTIL_SAFE_FREE(buffer);
+               return ret;
+       }
+
+       ret = mm_util_rotate_B_B(src_handle, angle, &dst_handle);
+       if (ret != MM_UTIL_ERROR_NONE)
+               printf("Fail mm_util_rotate_B_B [%d]\n", ret);
+
+       MM_UTIL_SAFE_FREE(buffer);
+
+       __save_to_file(dst_handle, __get_dst_raw_path(angle));
+
+       ret = mm_util_destroy_handle(src_handle);
+       if (ret != MM_UTIL_ERROR_NONE)
+               printf("Fail destroy src_handle [%d]\n", ret);
+
+       ret = mm_util_destroy_handle(dst_handle);
+       if (ret != MM_UTIL_ERROR_NONE)
+               printf("Fail destroy dst_handle [%d]\n", ret);
+
+       return ret;
+}
+
+static int _magick_resize_B_B_test(unsigned int req_width, unsigned int req_height, mm_util_magick_format req_format)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       mm_util_image_h src_handle = NULL;
+       mm_util_image_h dst_handle = NULL;
+       unsigned char *buffer = NULL;
+       unsigned int width = 0;
+       unsigned int height = 0;
+       size_t size = 0;
+       mm_util_magick_format format = MM_UTIL_IMG_FMT_NUM;
+       char dst_path[1024] = {0, };
+       memset(dst_path, 0x00, sizeof(dst_path));
+       snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/resize_bb_%d_%d.raw", req_width, req_height);
+
+       printf("* Resize B B Test * W * H [%d * %d], foramt [%d], path [%s]\n", req_width, req_height, req_format, dst_path);
+
+       ret = __get_buffer_for_test(req_format, &buffer, &width, &height, &size, &format);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail __get_buffer_for_test [%d]\n", ret);
+               return ret;
+       }
+
+       ret = mm_util_create_handle(&src_handle, buffer, width, height, size, format);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_create_handle [%d]\n", ret);
+               MM_UTIL_SAFE_FREE(buffer);
+               return ret;
+       }
+
+       ret = mm_util_resize_B_B(src_handle, req_width, req_height, &dst_handle);
+       if (ret != MM_UTIL_ERROR_NONE)
+               printf("Fail mm_util_resize_B_B [%d]\n", ret);
+
+       MM_UTIL_SAFE_FREE(buffer);
+
+       __save_to_file(dst_handle, dst_path);
+
+       ret = mm_util_destroy_handle(src_handle);
+       if (ret != MM_UTIL_ERROR_NONE)
+               printf("Fail destroy src_handle [%d]\n", ret);
+
+       ret = mm_util_destroy_handle(dst_handle);
+       if (ret != MM_UTIL_ERROR_NONE)
+               printf("Fail destroy dst_handle [%d]\n", ret);
+
+       return ret;
+}
+
+int main(int argc, char *argv[])
+{
+       int ret = MM_UTIL_ERROR_NONE;
+
+
+       if (argv[1] == NULL) {
+               printf("Choose menu!! ex) mm_util_magick_testsuite 1\n");
+
+       } else if (strcmp(argv[1], "1") == 0) {
+               ret = _magick_rotate_P_P_test(MM_UTIL_ROTATE_0);
+               ret = _magick_rotate_P_P_test(MM_UTIL_ROTATE_90);
+               ret = _magick_rotate_P_P_test(MM_UTIL_ROTATE_180);
+               ret = _magick_rotate_P_P_test(MM_UTIL_ROTATE_270);
+               ret = _magick_rotate_P_P_test(MM_UTIL_ROTATE_FLIP_HORZ);
+               ret = _magick_rotate_P_P_test(MM_UTIL_ROTATE_FLIP_VERT);
+
+       } else if (strcmp(argv[1], "2") == 0) {
+               ret = _magick_rotate_P_B_test(MM_UTIL_ROTATE_0, MM_UTIL_IMG_FMT_ARGB8888);
+               ret = _magick_rotate_P_B_test(MM_UTIL_ROTATE_90, MM_UTIL_IMG_FMT_RGB888);
+               ret = _magick_rotate_P_B_test(MM_UTIL_ROTATE_180, MM_UTIL_IMG_FMT_ARGB8888);
+               ret = _magick_rotate_P_B_test(MM_UTIL_ROTATE_270, MM_UTIL_IMG_FMT_BGRA8888);
+               ret = _magick_rotate_P_B_test(MM_UTIL_ROTATE_FLIP_HORZ, MM_UTIL_IMG_FMT_RGBA8888);
+               ret = _magick_rotate_P_B_test(MM_UTIL_ROTATE_FLIP_VERT, MM_UTIL_IMG_FMT_RGBA8888);
+
+       } else if (strcmp(argv[1], "3") == 0) {
+               ret = _magick_rotate_B_P_test(MM_UTIL_ROTATE_0, MM_UTIL_IMG_FMT_ARGB8888);
+               ret = _magick_rotate_B_P_test(MM_UTIL_ROTATE_90, MM_UTIL_IMG_FMT_RGB888);
+               ret = _magick_rotate_B_P_test(MM_UTIL_ROTATE_180, MM_UTIL_IMG_FMT_ARGB8888);
+               ret = _magick_rotate_B_P_test(MM_UTIL_ROTATE_270, MM_UTIL_IMG_FMT_BGRA8888);
+               ret = _magick_rotate_B_P_test(MM_UTIL_ROTATE_FLIP_HORZ, MM_UTIL_IMG_FMT_RGBA8888);
+               ret = _magick_rotate_B_P_test(MM_UTIL_ROTATE_FLIP_VERT, MM_UTIL_IMG_FMT_RGBA8888);
+
+       } else if (strcmp(argv[1], "4") == 0) {
+               ret = _magick_rotate_B_B_test(MM_UTIL_ROTATE_0, MM_UTIL_IMG_FMT_ARGB8888);
+               ret = _magick_rotate_B_B_test(MM_UTIL_ROTATE_90, MM_UTIL_IMG_FMT_RGB888);
+               ret = _magick_rotate_B_B_test(MM_UTIL_ROTATE_180, MM_UTIL_IMG_FMT_ARGB8888);
+               ret = _magick_rotate_B_B_test(MM_UTIL_ROTATE_270, MM_UTIL_IMG_FMT_BGRA8888);
+               ret = _magick_rotate_B_B_test(MM_UTIL_ROTATE_FLIP_HORZ, MM_UTIL_IMG_FMT_RGBA8888);
+               ret = _magick_rotate_B_B_test(MM_UTIL_ROTATE_FLIP_VERT, MM_UTIL_IMG_FMT_RGBA8888);
+               ret = _magick_rotate_B_B_test(100, MM_UTIL_IMG_FMT_RGBA8888);   //invalid parameter
+
+       } else if (strcmp(argv[1], "5") == 0) {
+               ret = _magick_resize_P_P_test(3000, 2000);
+               ret = _magick_resize_P_P_test(199, 299);
+               ret = _magick_resize_P_P_test(3, 2);
+               ret = _magick_resize_P_P_test(10000, 10000);
+               ret = _magick_resize_P_P_test(0, 2000); //invalid parameter
+
+       } else if (strcmp(argv[1], "6") == 0) {
+               ret = _magick_resize_P_B_test(3000, 2000, MM_UTIL_IMG_FMT_RGB888);
+               ret = _magick_resize_P_B_test(199, 299, MM_UTIL_IMG_FMT_ARGB8888);
+               ret = _magick_resize_P_B_test(3, 2, MM_UTIL_IMG_FMT_BGRA8888);
+               ret = _magick_resize_P_B_test(1000, 999, MM_UTIL_IMG_FMT_RGBA8888);
+               ret = _magick_resize_P_B_test(10000, 999, MM_UTIL_IMG_FMT_RGBA8888);
+
+       } else if (strcmp(argv[1], "7") == 0) {
+               ret = _magick_resize_B_P_test(3000, 2000, MM_UTIL_IMG_FMT_RGB888);
+               ret = _magick_resize_B_P_test(199, 299, MM_UTIL_IMG_FMT_ARGB8888);
+               ret = _magick_resize_B_P_test(3, 2, MM_UTIL_IMG_FMT_BGRA8888);
+               ret = _magick_resize_B_P_test(1000, 999, MM_UTIL_IMG_FMT_RGBA8888);
+               ret = _magick_resize_B_P_test(10000, 999, MM_UTIL_IMG_FMT_RGBA8888);
+
+       } else if (strcmp(argv[1], "8") == 0) {
+               ret = _magick_resize_B_B_test(3000, 2000, MM_UTIL_IMG_FMT_RGB888);
+               ret = _magick_resize_B_B_test(199, 299, MM_UTIL_IMG_FMT_ARGB8888);
+               ret = _magick_resize_B_B_test(3, 2, MM_UTIL_IMG_FMT_BGRA8888);
+               ret = _magick_resize_B_B_test(1000, 999, MM_UTIL_IMG_FMT_RGBA8888);
+               ret = _magick_resize_B_B_test(10000, 999, MM_UTIL_IMG_FMT_RGBA8888);
+
+       } else if (strcmp(argv[1], "9") == 0) {
+
+       } else {
+               printf("Invalid parameter\n");
+       }
+
+       return ret;
+}
+
index 56247f7..bb767aa 100755 (executable)
@@ -22,6 +22,7 @@ BuildRequires:  libpng-devel
 BuildRequires:  giflib-devel
 BuildRequires:  libbmp-devel
 BuildRequires:  libnsbmp-devel
+BuildRequires:  pkgconfig(GraphicsMagick)
 BuildRoot:  %{_tmppath}/%{name}-%{version}-build
 
 %description