[Image-util] optimize & improve image-util 98/42798/2 submit/tizen/20150703.010515
authorJi Yong Min <jiyong.min@samsung.com>
Thu, 2 Jul 2015 09:51:57 +0000 (18:51 +0900)
committerJi Yong Min <jiyong.min@samsung.com>
Thu, 2 Jul 2015 09:57:48 +0000 (18:57 +0900)
- Add to support NV12 format for encoding/decoding
- Add testsuite & update code for coding convention
- Add description for return value

Change-Id: I8314afe7a4b738d7a657b1bcbbda75e15871fe89
Signed-off-by: Jiyong Min <jiyong.min@samsung.com>
include/image_util.h
include/image_util_private.h
include/image_util_type.h
src/image_util.c
test/CMakeLists.txt
test/image_util_test.c [new file with mode: 0755]
test/multimeida_image_util_test.c [deleted file]

index 323ad6c..0bd0fc3 100755 (executable)
@@ -75,6 +75,7 @@ int image_util_transform_create(transformation_h *handle);
 *
 * @retval #IMAGE_UTIL_ERROR_NONE Successful
 * @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
 * @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion
 * @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED The application does not have the hardware acceleration
 *
@@ -97,6 +98,7 @@ int image_util_transform_set_hardware_acceleration(transformation_h handle, bool
 *
 * @retval #IMAGE_UTIL_ERROR_NONE Successful
 * @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
 * @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion
 * @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Not supported format
 *
@@ -112,6 +114,8 @@ int image_util_transform_set_colorspace(transformation_h handle, image_util_colo
 * @brief Sets the information of the resizing
 * @since_tizen 2.3
 *
+* @remarks image_util_transform_set_resolution and image_util_transform_set_crop_area can't do that at the same time.
+*
 * @param[in] handle The handle to image util transform
 * @param[in] width The width of image buffer
 * @param[in] height The height of image buffer
@@ -121,6 +125,7 @@ int image_util_transform_set_colorspace(transformation_h handle, image_util_colo
 *
 * @retval #IMAGE_UTIL_ERROR_NONE Successful
 * @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
 * @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion
 *
 * @pre image_util_transform_create().
@@ -143,6 +148,7 @@ int image_util_transform_set_resolution(transformation_h handle, unsigned int wi
 *
 * @retval #IMAGE_UTIL_ERROR_NONE Successful
 * @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
 * @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion
 *
 * @pre image_util_transform_create().
@@ -157,6 +163,8 @@ int image_util_transform_set_rotation(transformation_h handle, image_util_rotati
 * @brief Sets the information of the cropping
 * @since_tizen 2.3
 *
+* @remarks image_util_transform_set_resolution and image_util_transform_set_crop_area can't do that at the same time.
+*
 * @param[in] handle The handle to image util transform
 * @param[in] start_x The start x position of cropped image buffer
 * @param[in] start_y The start y position of cropped image buffer
@@ -168,6 +176,7 @@ int image_util_transform_set_rotation(transformation_h handle, image_util_rotati
 *
 * @retval #IMAGE_UTIL_ERROR_NONE Successful
 * @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
 * @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion
 *
 * @pre image_util_transform_create().
@@ -183,13 +192,14 @@ int image_util_transform_set_crop_area(transformation_h handle, unsigned int sta
 * @since_tizen 2.3
 *
 * @param[in] handle The handle to image util transform
-* @param[in,out] colorspace The colorspace of the image buffer
+* @param[in, out] colorspace The colorspace of the image buffer
 *
 * @return @c 0 on success,
 *               otherwise a negative error value
 *
 * @retval #IMAGE_UTIL_ERROR_NONE Successful
 * @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
 * @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Not supported format
 *
 * @pre image_util_transform_create().\n
@@ -205,14 +215,15 @@ int image_util_transform_get_colorspace(transformation_h handle, image_util_colo
 * @since_tizen 2.3
 *
 * @param[in] handle The handle to image util transform
-* @param[in,out] width The width of source image buffer
-* @param[in,out] height The height of source image buffer
+* @param[in, out] width The width of source image buffer
+* @param[in, out] height The height of source image buffer
 *
 * @return @c 0 on success,
 *               otherwise a negative error value
 *
 * @retval #IMAGE_UTIL_ERROR_NONE Successful
 * @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
 * @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion
 *
 * @pre image_util_transform_create().\n
@@ -221,20 +232,21 @@ int image_util_transform_get_colorspace(transformation_h handle, image_util_colo
 * @see image_util_transform_create()
 * @see image_util_transform_destroy()
 */
-int image_util_transform_get_resolution(transformation_h handle, unsigned int *width , unsigned int *height);
+int image_util_transform_get_resolution(transformation_h handle, unsigned int *width, unsigned int *height);
 
 /**
 * @brief Gets the information of the rotating
 * @since_tizen 2.3
 *
 * @param[in] handle The handle to image util transform
-* @param[in,out] rotation The rotation value of image buffer
+* @param[in, out] rotation The rotation value of image buffer
 *
 * @return @c 0 on success,
 *               otherwise a negative error value
 *
 * @retval #IMAGE_UTIL_ERROR_NONE Successful
 * @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
 * @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion
 *
 * @pre image_util_transform_create().\n
@@ -250,16 +262,17 @@ int image_util_transform_get_rotation(transformation_h handle, image_util_rotati
 * @since_tizen 2.3
 *
 * @param[in] handle The handle to image util transform
-* @param[in,out] start_x The start x position of cropped source image buffer
-* @param[in,out] start_y The start y position of cropped source image buffer
-* @param[in,out] end_x The end x position of cropped source image buffer
-* @param[in,out] end_y The end y position of cropped source image buffer
+* @param[in, out] start_x The start x position of cropped source image buffer
+* @param[in, out] start_y The start y position of cropped source image buffer
+* @param[in, out] end_x The end x position of cropped source image buffer
+* @param[in, out] end_y The end y position of cropped source image buffer
 *
 * @return @c 0 on success,
 *               otherwise a negative error value
 *
 * @retval #IMAGE_UTIL_ERROR_NONE Successful
 * @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
 * @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion
 *
 * @pre image_util_transform_create().\n
@@ -274,9 +287,10 @@ int image_util_transform_get_crop_area(transformation_h handle, unsigned int *st
 * @brief Transform the image for given image util handle.
 * @since_tizen 2.3
 *
-*@remarks If H/W acceleration is not set, transformation is done via S/W acceleration.
+* @remarks If H/W acceleration is not set, transformation is done via S/W acceleration.
 *
-* @details The function execute asynchronously, which contains complete callback
+* @details The function execute asynchronously, which contains complete callback \n
+*          If you set more than two transforming, the order of running is crop or resolution, colorspace converting, rotaion. \n
 *
 * @param[in] handle The handle of transform
 * @param[in] src The handle to image util transform
@@ -288,6 +302,7 @@ int image_util_transform_get_crop_area(transformation_h handle, unsigned int *st
 *
 * @retval #IMAGE_UTIL_ERROR_NONE Successful
 * @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
 * @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion
 *
 * @see image_util_transform_create()
@@ -336,7 +351,7 @@ int image_util_transform_destroy(transformation_h handle);
 * @see image_util_decode_jpeg()
 * @see image_util_decode_jpeg_from_memory()
 */
-typedef bool (*image_util_supported_jpeg_colorspace_cb)( image_util_colorspace_e colorspace , void * user_data);
+typedef bool(*image_util_supported_jpeg_colorspace_cb)(image_util_colorspace_e colorspace, void *user_data);
 
 /**
 * @brief Retrieves all supported JPEG encoding/decoding colorspace by invoking a callback function once for each one.
@@ -358,7 +373,7 @@ typedef bool (*image_util_supported_jpeg_colorspace_cb)( image_util_colorspace_e
 * @see image_util_decode_jpeg()
 * @see image_util_decode_jpeg_from_memory()
 */
-int image_util_foreach_supported_jpeg_colorspace(image_util_supported_jpeg_colorspace_cb callback, void * user_data);
+int image_util_foreach_supported_jpeg_colorspace(image_util_supported_jpeg_colorspace_cb callback, void *user_data);
 
 /**
 * @brief Calculates the size of the image buffer for the specified resolution and colorspace.
@@ -382,7 +397,7 @@ int image_util_foreach_supported_jpeg_colorspace(image_util_supported_jpeg_color
 * @see image_util_encode_jpeg()
 * @see image_util_encode_jpeg_to_memory()
 */
-int image_util_calculate_buffer_size(int width , int height, image_util_colorspace_e colorspace  , unsigned int *size);
+int image_util_calculate_buffer_size(int width, int height, image_util_colorspace_e colorspace , unsigned int *size);
 
 /**
 * @internal
@@ -391,7 +406,7 @@ int image_util_calculate_buffer_size(int width , int height, image_util_colorspa
 *
 * @remarks You must get the @a dest buffer size using image_util_transform_calculate_buffer_size().
 *
-* @param[in,out] dest The image buffer for result \n
+* @param[in, out] dest The image buffer for result \n
 *                     Must be allocated by the user
 * @param[in] dest_colorspace The colorspace to be converted
 * @param[in] src The source image buffer
@@ -411,7 +426,7 @@ int image_util_calculate_buffer_size(int width , int height, image_util_colorspa
 * @see image_util_transform_create()
 * @see image_util_transform_destroy()
 */
-int image_util_convert_colorspace( unsigned char * dest , image_util_colorspace_e dest_colorspace , const unsigned char * src ,  int width, int height, image_util_colorspace_e src_colorspace);
+int image_util_convert_colorspace(unsigned char *dest, image_util_colorspace_e dest_colorspace, const unsigned char *src,  int width, int height, image_util_colorspace_e src_colorspace);
 
 /**
 * @internal
@@ -420,10 +435,10 @@ int image_util_convert_colorspace( unsigned char * dest , image_util_colorspace_
 *
 * @remarks Because of YUV format padding, the destination image size can be adjusted.
 *
-* @param[in,out] dest The image buffer for result \n
+* @param[in, out] dest The image buffer for result \n
 *                     Must be allocated by the user.
-* @param[in,out] dest_width The image width to resize, and resized width
-* @param[in,out] dest_height The image height to resize, and resized height
+* @param[in, out] dest_width The image width to resize, and resized width
+* @param[in, out] dest_height The image height to resize, and resized height
 * @param[in] src The image buffer for the original image
 * @param[in] src_width The original image width
 * @param[in] src_height The original image height
@@ -440,7 +455,7 @@ int image_util_convert_colorspace( unsigned char * dest , image_util_colorspace_
 *
 * @see image_util_transform_calculate_buffer_size()
 */
-int image_util_resize(unsigned char * dest, int *dest_width , int *dest_height, const unsigned char * src, int src_width, int src_height , image_util_colorspace_e colorspace);
+int image_util_resize(unsigned char *dest, int *dest_width, int *dest_height, const unsigned char *src, int src_width, int src_height, image_util_colorspace_e colorspace);
 
 /**
 * @internal
@@ -459,7 +474,7 @@ int image_util_resize(unsigned char * dest, int *dest_width , int *dest_height,
 * #IMAGE_UTIL_COLORSPACE_RGBA8888\n
 * #IMAGE_UTIL_COLORSPACE_BGRX8888\n.
 *
-* @param[in,out] dest The image buffer for result \n
+* @param[in, out] dest The image buffer for result \n
 *                     Must be allocated by the user.
 * @param[out] dest_width The rotated image width
 * @param[out] dest_height The rotated image height
@@ -479,7 +494,7 @@ int image_util_resize(unsigned char * dest, int *dest_width , int *dest_height,
 *
 * @see image_util_transform_calculate_buffer_size()
 */
-int image_util_rotate(unsigned char * dest, int *dest_width, int *dest_height, image_util_rotation_e dest_rotation, const unsigned char * src, int src_width, int src_height, image_util_colorspace_e colorspace);
+int image_util_rotate(unsigned char *dest, int *dest_width, int *dest_height, image_util_rotation_e dest_rotation, const unsigned char *src, int src_width, int src_height, image_util_colorspace_e colorspace);
 
 /**
 * @internal
@@ -497,7 +512,7 @@ int image_util_rotate(unsigned char * dest, int *dest_width, int *dest_height, i
 * #IMAGE_UTIL_COLORSPACE_RGBA8888\n
 * #IMAGE_UTIL_COLORSPACE_BGRX8888\n.
 *
-* @param[in,out] dest The image buffer for result. Must be allocated by you
+* @param[in, out] dest The image buffer for result. Must be allocated by you
 * @param[in] x The starting x-axis of crop
 * @param[in] y The starting y-axis of crop
 * @param[in/out] width  The image width to crop, and cropped width
@@ -517,7 +532,7 @@ int image_util_rotate(unsigned char * dest, int *dest_width, int *dest_height, i
 *
 * @see image_util_transform_calculate_buffer_size()
 */
-int image_util_crop(unsigned char * dest, int x , int y, int* width, int *height, const unsigned char *src, int src_width, int src_height, image_util_colorspace_e colorspace);
+int image_util_crop(unsigned char *dest, int x, int y, int *width, int *height, const unsigned char *src, int src_width, int src_height, image_util_colorspace_e colorspace);
 
 
 
@@ -529,7 +544,7 @@ int image_util_crop(unsigned char * dest, int x , int y, int* width, int *height
 * @remarks You must release @a image_buffer using free().\n
 *                 http://tizen.org/privilege/mediastorage is needed if input or output path are relevant to media storage.\n
 *                 http://tizen.org/privilege/externalstorage is needed if input or output path are relevant to external storage.\n
-*                 If you decode the JPEG image which has odd numbered width or height to YUV colorspace,\n
+*                 If you decode the JPEG image which has odd numbered width or height to YUV colorspace, \n
 *                 the width or height of decoded data will be rounded down to even numbered width or height.
 *
 * @param[in] path The image file path
@@ -553,14 +568,14 @@ int image_util_crop(unsigned char * dest, int x , int y, int* width, int *height
 * @see image_util_decode_jpeg_from_memory()
 * @see image_util_foreach_supported_jpeg_colorspace()
 */
-int image_util_decode_jpeg( const char *path , image_util_colorspace_e colorspace, unsigned char ** image_buffer , int *width , int *height , unsigned int *size);
+int image_util_decode_jpeg(const char *path, image_util_colorspace_e colorspace, unsigned char **image_buffer, int *width, int *height, unsigned int *size);
 
 /**
 * @brief Decodes the JPEG image(in memory) to the buffer.
 * @since_tizen 2.3
 *
 * @remarks You must release @a image_buffer using free().\n
-*                  If you decode the JPEG image which has odd numbered width or height to YUV colorspace,\n
+*                  If you decode the JPEG image which has odd numbered width or height to YUV colorspace, \n
 *                  the width or height of decoded data will be rounded down to even numbered width or height.
 *
 * @param[in] jpeg_buffer The JPEG image buffer
@@ -571,7 +586,7 @@ int image_util_decode_jpeg( const char *path , image_util_colorspace_e colorspac
 * @param[out] height The image height
 * @param[out] size The image buffer size
 *
-* @return @c 0 on success,
+* @return 0 on success,
 *           otherwise a negative error value
 *
 * @retval #IMAGE_UTIL_ERROR_NONE Successful
@@ -585,7 +600,7 @@ int image_util_decode_jpeg( const char *path , image_util_colorspace_e colorspac
 * @see image_util_decode_jpeg()
 * @see image_util_foreach_supported_jpeg_colorspace()
 */
-int image_util_decode_jpeg_from_memory( const unsigned char * jpeg_buffer , int jpeg_size , image_util_colorspace_e colorspace, unsigned char ** image_buffer , int *width , int *height , unsigned int *size);
+int image_util_decode_jpeg_from_memory(const unsigned char *jpeg_buffer, int jpeg_size, image_util_colorspace_e colorspace, unsigned char **image_buffer, int *width, int *height, unsigned int *size);
 
 /**
 * @brief Decodes the JPEG image to the buffer with downscale decoding option.
@@ -594,7 +609,7 @@ int image_util_decode_jpeg_from_memory( const unsigned char * jpeg_buffer , int
 * @remarks You must release @a image_buffer using free().\n
 *                 http://tizen.org/privilege/mediastorage is needed if input or output path are relevant to media storage.\n
 *                 http://tizen.org/privilege/externalstorage is needed if input or output path are relevant to external storage.\n
-*                 If you decode the JPEG image which has odd numbered width or height to YUV colorspace,\n
+*                 If you decode the JPEG image which has odd numbered width or height to YUV colorspace, \n
 *                 the width or height of decoded data will be rounded down to even numbered width or height.
 *
 * @param[in] path The image file path
@@ -619,14 +634,14 @@ int image_util_decode_jpeg_from_memory( const unsigned char * jpeg_buffer , int
 * @see image_util_decode_jpeg_from_memory()
 * @see image_util_foreach_supported_jpeg_colorspace()
 */
-int image_util_decode_jpeg_with_downscale( const char *path, image_util_colorspace_e colorspace, image_util_scale_e downscale, unsigned char ** image_buffer, int *width, int *height, unsigned int *size);
+int image_util_decode_jpeg_with_downscale(const char *path, image_util_colorspace_e colorspace, image_util_scale_e downscale, unsigned char **image_buffer, int *width, int *height, unsigned int *size);
 
 /**
 * @brief Decodes the JPEG image(in memory) to the buffer with downscale decoding option.
 * @since_tizen 2.4
 *
 * @remarks You must release @a image_buffer using free().\n
-*                   If you decode the JPEG image which has odd numbered width or height to YUV colorspace,\n
+*                   If you decode the JPEG image which has odd numbered width or height to YUV colorspace, \n
 *                   the width or height of decoded data will be rounded down to even numbered width or height.
 *
 * @param[in] jpeg_buffer The JPEG image buffer
@@ -652,7 +667,7 @@ int image_util_decode_jpeg_with_downscale( const char *path, image_util_colorspa
 * @see image_util_decode_jpeg()
 * @see image_util_foreach_supported_jpeg_colorspace()
 */
-int image_util_decode_jpeg_from_memory_with_downscale( const unsigned char * jpeg_buffer, int jpeg_size, image_util_colorspace_e colorspace, image_util_scale_e downscale, unsigned char ** image_buffer, int *width, int *height, unsigned int *size);
+int image_util_decode_jpeg_from_memory_with_downscale(const unsigned char *jpeg_buffer, int jpeg_size, image_util_colorspace_e colorspace, image_util_scale_e downscale, unsigned char **image_buffer, int *width, int *height, unsigned int *size);
 
 /**
 * @brief Encodes the image to the JPEG image.
@@ -665,7 +680,7 @@ int image_util_decode_jpeg_from_memory_with_downscale( const unsigned char * jpe
 * @param[in] width The original image width
 * @param[in] height The original image height
 * @param[in] colorspace The original image colorspace
-* @param[in] quality The quality for JPEG image encoding (1 ~ 100)
+* @param[in] quality The quality for JPEG image encoding(1 ~ 100)
 * @param[in] path The file path to be created
 *
 * @return 0 on success,
@@ -682,7 +697,7 @@ int image_util_decode_jpeg_from_memory_with_downscale( const unsigned char * jpe
 * @see image_util_foreach_supported_jpeg_colorspace()
 * @see image_util_encode_jpeg_to_memory()
 */
-int image_util_encode_jpeg( const unsigned char *buffer, int width, int height, image_util_colorspace_e colorspace,  int quality, const char *path);
+int image_util_encode_jpeg(const unsigned char *buffer, int width, int height, image_util_colorspace_e colorspace,  int quality, const char *path);
 
 /**
 * @brief Encodes the image to the JPEG image
@@ -694,7 +709,7 @@ int image_util_encode_jpeg( const unsigned char *buffer, int width, int height,
 * @param[in] width The image width
 * @param[in] height The image height
 * @param[in] colorspace The original image colorspace
-* @param[in] quality The quality for JPEG image encoding (1 ~ 100)
+* @param[in] quality The quality for JPEG image encoding(1 ~ 100)
 * @param[out] jpeg_buffer The created JPEG image buffer \n
 *                         The buffer is created by frameworks
 * @param[out] jpeg_size The created jpeg image buffer size
@@ -713,7 +728,7 @@ int image_util_encode_jpeg( const unsigned char *buffer, int width, int height,
 * @see image_util_foreach_supported_jpeg_colorspace()
 * @see image_util_encode_jpeg()
 */
-int image_util_encode_jpeg_to_memory(const unsigned char *image_buffer, int width, int height, image_util_colorspace_e colorspace, int quality,  unsigned char** jpeg_buffer, unsigned int *jpeg_size);
+int image_util_encode_jpeg_to_memory(const unsigned char *image_buffer, int width, int height, image_util_colorspace_e colorspace, int quality,  unsigned char **jpeg_buffer, unsigned int *jpeg_size);
 
 
 
index 63f2a02..fbbdee2 100755 (executable)
@@ -24,15 +24,13 @@ extern "C"
 {
 #endif
 
-typedef struct
-{
+typedef struct {
        void *user_data;
        media_packet_h dst;
        image_util_transform_completed_cb image_processing_completed_cb;
 } image_util_cb_s;
 
-typedef struct
-{
+typedef struct {
        media_packet_h src;
        media_packet_h dst;
        image_util_colorspace_e colorspace;
index e3db8ad..1d81fba 100755 (executable)
@@ -43,66 +43,64 @@ extern "C"
  */
 typedef enum
 {
-    IMAGE_UTIL_ERROR_NONE =              TIZEN_ERROR_NONE,                /**< Successful */
-    IMAGE_UTIL_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,   /**< Invalid parameter */
-    IMAGE_UTIL_ERROR_OUT_OF_MEMORY =     TIZEN_ERROR_OUT_OF_MEMORY,       /**< Out of memory */
-    IMAGE_UTIL_ERROR_NO_SUCH_FILE  = TIZEN_ERROR_NO_SUCH_FILE,            /**< No such file */
-    IMAGE_UTIL_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION,   /**< Internal error */
-    IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT = TIZEN_ERROR_IMAGE_UTIL | 0x01,   /**< Not supported format */
-    IMAGE_UTIL_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED,   /**< Permission denied  */
-    IMAGE_UTIL_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED          /**< Not supported */
-} image_util_error_e;
+       IMAGE_UTIL_ERROR_NONE =              TIZEN_ERROR_NONE,                /**< Successful */
+       IMAGE_UTIL_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,   /**< Invalid parameter */
+       IMAGE_UTIL_ERROR_OUT_OF_MEMORY =     TIZEN_ERROR_OUT_OF_MEMORY,       /**< Out of memory */
+       IMAGE_UTIL_ERROR_NO_SUCH_FILE  = TIZEN_ERROR_NO_SUCH_FILE,            /**< No such file */
+       IMAGE_UTIL_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION,   /**< Internal error */
+       IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT = TIZEN_ERROR_IMAGE_UTIL | 0x01,   /**< Not supported format */
+       IMAGE_UTIL_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED,   /**< Permission denied  */
+       IMAGE_UTIL_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED          /**< Not supported */
+}
+image_util_error_e;
 
 /**
  * @brief Enumeration for colorspace.
  * @since_tizen 2.3
  */
-typedef enum
-{
-       IMAGE_UTIL_COLORSPACE_YV12,     /**< YV12 - YCrCb planar format */
-       IMAGE_UTIL_COLORSPACE_YUV422,   /**< YUV422 - planar */
-       IMAGE_UTIL_COLORSPACE_I420,     /**< YUV420 - planar */
-       IMAGE_UTIL_COLORSPACE_NV12,     /**< NV12- planar */
-
-       IMAGE_UTIL_COLORSPACE_UYVY,     /**< UYVY - packed */
-       IMAGE_UTIL_COLORSPACE_YUYV,     /**< YUYV - packed */
-
-       IMAGE_UTIL_COLORSPACE_RGB565,   /**< RGB565, high-byte is Blue */
-       IMAGE_UTIL_COLORSPACE_RGB888,   /**< RGB888, high-byte is Blue */
-       IMAGE_UTIL_COLORSPACE_ARGB8888, /**< ARGB8888, high-byte is Blue */
-
-       IMAGE_UTIL_COLORSPACE_BGRA8888, /**< BGRA8888, high-byte is Alpha */
-       IMAGE_UTIL_COLORSPACE_RGBA8888, /**< RGBA8888, high-byte is Alpha */
-       IMAGE_UTIL_COLORSPACE_BGRX8888, /**< BGRX8888, high-byte is X */
-       IMAGE_UTIL_COLORSPACE_NV21,     /**< NV12- planar */
-       IMAGE_UTIL_COLORSPACE_NV16,     /**< NV16- planar */
-       IMAGE_UTIL_COLORSPACE_NV61,     /**< NV61- planar */
-}image_util_colorspace_e;
+typedef enum {
+    IMAGE_UTIL_COLORSPACE_YV12,     /**< YV12 - YCrCb planar format */
+    IMAGE_UTIL_COLORSPACE_YUV422,   /**< YUV422 - planar */
+    IMAGE_UTIL_COLORSPACE_I420,     /**< YUV420 - planar */
+    IMAGE_UTIL_COLORSPACE_NV12,     /**< NV12- planar */
+
+    IMAGE_UTIL_COLORSPACE_UYVY,     /**< UYVY - packed */
+    IMAGE_UTIL_COLORSPACE_YUYV,     /**< YUYV - packed */
+
+    IMAGE_UTIL_COLORSPACE_RGB565,   /**< RGB565, high-byte is Blue */
+    IMAGE_UTIL_COLORSPACE_RGB888,   /**< RGB888, high-byte is Blue */
+    IMAGE_UTIL_COLORSPACE_ARGB8888, /**< ARGB8888, high-byte is Blue */
+
+    IMAGE_UTIL_COLORSPACE_BGRA8888, /**< BGRA8888, high-byte is Alpha */
+    IMAGE_UTIL_COLORSPACE_RGBA8888, /**< RGBA8888, high-byte is Alpha */
+    IMAGE_UTIL_COLORSPACE_BGRX8888, /**< BGRX8888, high-byte is X */
+    IMAGE_UTIL_COLORSPACE_NV21,     /**< NV12- planar */
+    IMAGE_UTIL_COLORSPACE_NV16,     /**< NV16- planar */
+    IMAGE_UTIL_COLORSPACE_NV61,     /**< NV61- planar */
+} image_util_colorspace_e;
 
 /**
  * @brief Enumeration for scale decoding.
  * @since_tizen 2.4
  */
-typedef enum
-{
-       IMAGE_UTIL_DOWNSCALE_1_1, /** 1/1 downscale */
-       IMAGE_UTIL_DOWNSCALE_1_2,       /** 1/2 downscale */
-       IMAGE_UTIL_DOWNSCALE_1_4,       /** 1/4 downscale */
-       IMAGE_UTIL_DOWNSCALE_1_8,       /** 1/8 downscale */
+typedef enum {
+    IMAGE_UTIL_DOWNSCALE_1_1, /** 1/1 downscale */
+    IMAGE_UTIL_DOWNSCALE_1_2,  /** 1/2 downscale */
+    IMAGE_UTIL_DOWNSCALE_1_4,  /** 1/4 downscale */
+    IMAGE_UTIL_DOWNSCALE_1_8,  /** 1/8 downscale */
 } image_util_scale_e;
 
 /**
  * @brief Enumeration for rotation.
  * @since_tizen 2.3
  */
-typedef enum
-{
-       IMAGE_UTIL_ROTATION_NONE = 0,   /**< None */
-       IMAGE_UTIL_ROTATION_90,                 /**< Rotation 90 degree */
-       IMAGE_UTIL_ROTATION_180,                        /**< Rotation 180 degree */
-       IMAGE_UTIL_ROTATION_270,                        /**< Rotation 270 degree */
-       IMAGE_UTIL_ROTATION_FLIP_HORZ,  /**< Flip horizontal */
-       IMAGE_UTIL_ROTATION_FLIP_VERT,  /**< Flip vertical */
+typedef enum {
+    IMAGE_UTIL_ROTATION_NONE = 0,      /**< None */
+    IMAGE_UTIL_ROTATION_90,                    /**< Rotation 90 degree */
+    IMAGE_UTIL_ROTATION_180,                   /**< Rotation 180 degree */
+    IMAGE_UTIL_ROTATION_270,                   /**< Rotation 270 degree */
+    IMAGE_UTIL_ROTATION_FLIP_HORZ,     /**< Flip horizontal */
+    IMAGE_UTIL_ROTATION_FLIP_VERT,     /**< Flip vertical */
 } image_util_rotation_e;
 
 /**
@@ -120,11 +118,11 @@ typedef struct transformation_s *transformation_h;
 * @remarks You must release the @a dst result using media_packet_destroy().
 *
 * @param[in] error_code The error code of image util transfrom
-* @param[in,out] dst The result buffer of image util transform
+* @param[in, out] dst The result buffer of image util transform
 * @param[in] user_data The user data passed from the callback registration function
 * @pre image_util_transform_run() will invoke this function.
 */
-typedef void (*image_util_transform_completed_cb)(media_packet_h *dst, int error_code, void *user_data);
+typedef void(*image_util_transform_completed_cb)(media_packet_h *dst, int error_code, void *user_data);
 
 /**
  * @}
index fb71ece..61d42a8 100755 (executable)
@@ -31,8 +31,8 @@
 #define IMAGE_UTIL_SAFE_FREE(src)      { if(src) {free(src); src = NULL;}}
 
 static int _convert_colorspace_tbl[] = {
-       MM_UTIL_IMG_FMT_YUV420 ,                /* IMAGE_UTIL_COLORSPACE_YUV420 */
-       MM_UTIL_IMG_FMT_YUV422 ,                /* IMAGE_UTIL_COLORSPACE_YUV422 */
+       MM_UTIL_IMG_FMT_YUV420                /* IMAGE_UTIL_COLORSPACE_YUV420 */
+       MM_UTIL_IMG_FMT_YUV422                /* IMAGE_UTIL_COLORSPACE_YUV422 */
        MM_UTIL_IMG_FMT_I420,                   /* IMAGE_UTIL_COLORSPACE_I420 */
        MM_UTIL_IMG_FMT_NV12,                   /* IMAGE_UTIL_COLORSPACE_NV12 */
        MM_UTIL_IMG_FMT_UYVY,                   /* IMAGE_UTIL_COLORSPACE_UYVY */
@@ -53,7 +53,7 @@ static int _convert_encode_colorspace_tbl[] = {
        MM_UTIL_JPEG_FMT_YUV420                                         ,       /* IMAGE_UTIL_COLORSPACE_YUV420 */
        -1                                                                                      ,       /* IMAGE_UTIL_COLORSPACE_YUV422 */
        MM_UTIL_JPEG_FMT_YUV420                                         ,       /* IMAGE_UTIL_COLORSPACE_I420 */
-       -1                                                                                      ,       /* IMAGE_UTIL_COLORSPACE_NV12 */
+       MM_UTIL_JPEG_FMT_NV12                                           ,       /* IMAGE_UTIL_COLORSPACE_NV12 */
        -1                                                                                      ,       /* IMAGE_UTIL_COLORSPACE_UYVY */
        -1                                                                                      ,       /* IMAGE_UTIL_COLORSPACE_YUYV */
        -1                                                                                      ,       /* IMAGE_UTIL_COLORSPACE_RGB565 */
@@ -75,66 +75,67 @@ static int _convert_decode_scale_tbl[] = {
        MM_UTIL_JPEG_DECODE_DOWNSCALE_1_8,
 };
 
-static int _convert_image_util_error_code(const char *func, int code){
+static int _convert_image_util_error_code(const char *func, int code)
+{
        int ret = IMAGE_UTIL_ERROR_INVALID_OPERATION;
        char *errorstr = NULL;
-       switch(code)
-       {
+       switch (code) {
                case MM_ERROR_NONE:
                        ret = IMAGE_UTIL_ERROR_NONE;
-                       errorstr = "ERROR_NONE";
+                       errorstr = strdup("ERROR_NONE");
                        break;
-               case MM_ERROR_IMAGE_FILEOPEN :
-               case IMAGE_UTIL_ERROR_NO_SUCH_FILE :
+               case MM_ERROR_IMAGE_FILEOPEN:
+               case IMAGE_UTIL_ERROR_NO_SUCH_FILE:
                        ret = IMAGE_UTIL_ERROR_NO_SUCH_FILE;
-                       errorstr = "NO_SUCH_FILE";
+                       errorstr = strdup("NO_SUCH_FILE");
                        break;
 
-               case MM_ERROR_IMAGE_INTERNAL :
+               case MM_ERROR_IMAGE_INTERNAL:
                        ret = IMAGE_UTIL_ERROR_INVALID_OPERATION;
-                       errorstr = "INVALID_OPERATION";
+                       errorstr = strdup("INVALID_OPERATION");
                        break;
                case IMAGE_UTIL_ERROR_INVALID_PARAMETER:
+               case MM_ERROR_IMAGEHANDLE_NOT_INITIALIZED:
                case MM_ERROR_NO_DECODED_DATA:
                case MM_ERROR_IMAGE_INVALID_VALUE:
                        ret = IMAGE_UTIL_ERROR_INVALID_PARAMETER;
-                       errorstr = "INVALID_PARAMETER";
+                       errorstr = strdup("INVALID_PARAMETER");
                        break;
                case MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT:
                case MM_ERROR_IMAGE_DEVICE_NOT_SUPPORT:
                        ret = IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
-                       errorstr = "NOT_SUPPORTED_FORMAT";
+                       errorstr = strdup("NOT_SUPPORTED_FORMAT");
+                       break;
+               case MM_ERROR_IMAGE_NO_FREE_SPACE:
+                       ret = IMAGE_UTIL_ERROR_OUT_OF_MEMORY;
+                       errorstr = strdup("OUT_OF_MEMORY");
                        break;
-
-
                default:
                        ret = IMAGE_UTIL_ERROR_INVALID_OPERATION;
-                       errorstr = "INVALID_OPERATION";
+                       errorstr = strdup("INVALID_OPERATION");
 
        }
 
-       LOGD( "[%s] %s(0x%08x)",func, errorstr, ret);
+       LOGD("[%s] %s(0x%08x)", func, errorstr, ret);
+       IMAGE_UTIL_SAFE_FREE(errorstr);
        return ret;
 }
 
 static image_util_error_e _image_util_error_convert(int error)
 {
-       if(error == MM_ERROR_NONE)
-       {
-               LOGD("Error None");
-               return IMAGE_UTIL_ERROR_NONE;
-       }
-       else if(error == MM_ERROR_IMAGE_INVALID_VALUE)
-       {
-               LOGE("INVALID_PARAMETER(0x%08x)", IMAGE_UTIL_ERROR_INVALID_PARAMETER);
-               return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
-       }
-       else if(error == MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT)
-       {
-               LOGE("NOT_SUPPORTED_FORMAT(0x%08x)", IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT);
-               return IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
+       switch (error) {
+               case MM_ERROR_NONE:
+                       LOGD("Error None");
+                       return IMAGE_UTIL_ERROR_NONE;
+               case MM_ERROR_IMAGE_INVALID_VALUE:
+                       LOGE("INVALID_PARAMETER(0x%08x)", IMAGE_UTIL_ERROR_INVALID_PARAMETER);
+                       return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+               case MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT:
+                       LOGE("NOT_SUPPORTED_FORMAT(0x%08x)", IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT);
+                       return IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
+               default:
+                       break;
        }
-
        LOGE("INVALID_OPERATION(0x%08x)", error);
        return IMAGE_UTIL_ERROR_INVALID_OPERATION;
 }
@@ -144,8 +145,7 @@ static void _image_util_transform_completed_cb(media_packet_h *dst, int error, v
        int error_value = IMAGE_UTIL_ERROR_NONE;
        image_util_cb_s *_util_cb = (image_util_cb_s *)user_data;
 
-       if((_util_cb != NULL) && (_util_cb->image_processing_completed_cb != NULL))
-       {
+       if ((_util_cb != NULL) && (_util_cb->image_processing_completed_cb != NULL)) {
                error_value = _image_util_error_convert(error);
                _util_cb->image_processing_completed_cb(dst, error_value, _util_cb->user_data);
        }
@@ -160,12 +160,9 @@ static int _image_util_create_transform_handle(transformation_s *handle)
 
        ret = mm_util_create(&image_h);
 
-       if(ret == MM_ERROR_NONE)
-       {
+       if (ret == MM_ERROR_NONE) {
                handle->image_h = image_h;
-       }
-       else
-       {
+       } else {
                LOGE("Error in mm_util_create");
        }
 
@@ -174,14 +171,12 @@ static int _image_util_create_transform_handle(transformation_s *handle)
 
 static bool _image_util_check_resolution(int width, int height)
 {
-       if(width <= 0)
-       {
+       if (width <= 0) {
                LOGE("invalid width [%d]", width);
                return false;
        }
 
-       if(height <= 0)
-       {
+       if (height <= 0) {
                LOGE("invalid height [%d]", height);
                return false;
        }
@@ -189,34 +184,16 @@ static bool _image_util_check_resolution(int width, int height)
        return true;
 }
 
-int _image_util_check_transcode_is_completed(transformation_s * handle, bool *is_completed)
-{
-       int ret = IMAGE_UTIL_ERROR_NONE;
-
-       if(handle && handle->image_h)
-       {
-               ret = mm_util_transform_is_completed(handle->image_h, is_completed);
-       }
-       else
-       {
-               LOGE("Invalid Handle");
-               return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
-       }
-
-       ret = _convert_image_util_error_code(__func__, ret);
-
-       return ret;
-}
-
-int image_util_foreach_supported_jpeg_colorspace(image_util_supported_jpeg_colorspace_cb callback, void * user_data)
+int image_util_foreach_supported_jpeg_colorspace(image_util_supported_jpeg_colorspace_cb callback, void *user_data)
 {
        int i = 0;
 
-       if( callback == NULL )
+       if (callback == NULL)
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
-       for( i = sizeof(_convert_encode_colorspace_tbl)/sizeof(int) -1; i >= 0; i--) { /* RGB has higher precedence than YUV */
-               if ( _convert_encode_colorspace_tbl[i] != -1)
-                       if( false == callback(i , user_data) )
+       /* RGB has higher precedence than YUV */
+       for (i = sizeof(_convert_encode_colorspace_tbl) / sizeof(int) - 1; i >= 0; i--) {
+               if (_convert_encode_colorspace_tbl[i] != -1)
+                       if (false == callback(i, user_data))
                                return IMAGE_UTIL_ERROR_NONE;
 
        }
@@ -230,15 +207,13 @@ int image_util_transform_create(transformation_h *handle)
 
        LOGD("image_util_create");
 
-       if(handle == NULL)
-       {
+       if (handle == NULL) {
                LOGE("Invalid Handle");
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
        }
 
-       transformation_s *_handle = (transformation_s*)calloc(1,sizeof(transformation_s));
-       if(_handle == NULL)
-       {
+       transformation_s *_handle = (transformation_s *)calloc(1, sizeof(transformation_s));
+       if (_handle == NULL) {
                LOGE("OUT_OF_MEMORY(0x%08x)", IMAGE_UTIL_ERROR_OUT_OF_MEMORY);
                return IMAGE_UTIL_ERROR_OUT_OF_MEMORY;
        }
@@ -253,8 +228,7 @@ int image_util_transform_create(transformation_h *handle)
        _handle->set_crop  = false;
 
        ret = _image_util_create_transform_handle(_handle);
-       if(ret != MM_ERROR_NONE)
-       {
+       if (ret != MM_ERROR_NONE) {
                LOGE("INVALID_OPERATION");
                IMAGE_UTIL_SAFE_FREE(_handle);
                return IMAGE_UTIL_ERROR_INVALID_OPERATION;
@@ -262,28 +236,28 @@ int image_util_transform_create(transformation_h *handle)
 
        *handle = (transformation_h)_handle;
 
-       return ret;
+       return _convert_image_util_error_code(__func__, ret);
 }
 
 int  image_util_transform_set_hardware_acceleration(transformation_h handle, bool mode)
 {
-       transformation_s *_handle = (transformation_s*)handle;
+       transformation_s *_handle = (transformation_s *)handle;
 
        LOGD("Set hardware_acceleration %d", mode);
 
-       if(_handle == NULL)
-       {
+       if (_handle == NULL) {
                LOGE("Invalid Handle");
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
        }
 
-       if(mode == true) {
+#ifndef ENABLE_HW_ACCELERATION
+       if (mode == true) {
                LOGE("hardware acceleration is not supported");
                return IMAGE_UTIL_ERROR_NOT_SUPPORTED;
        }
+#endif
 
-       if(mm_util_set_hardware_acceleration(_handle->image_h, mode) == MM_ERROR_NONE)
-       {
+       if (mm_util_set_hardware_acceleration(_handle->image_h, mode) == MM_ERROR_NONE) {
                LOGD("Set hardware_acceleration %d", mode);
                _handle->hardware_acceleration = mode;
        } else {
@@ -297,19 +271,17 @@ int  image_util_transform_set_hardware_acceleration(transformation_h handle, boo
 int image_util_transform_set_colorspace(transformation_h handle, image_util_colorspace_e colorspace)
 {
        int ret = IMAGE_UTIL_ERROR_NONE;
-       transformation_s *_handle = (transformation_s*)handle;
+       transformation_s *_handle = (transformation_s *)handle;
 
        LOGD("Set colorspace_convert_info [%d]", colorspace);
 
-       if(_handle == NULL)
-       {
+       if (_handle == NULL) {
                LOGE("Invalid Handle");
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
        }
 
        ret = mm_util_set_colorspace_convert(_handle->image_h, colorspace);
-       if(ret != MM_ERROR_NONE)
-       {
+       if (ret != MM_ERROR_NONE) {
                LOGE("IMAGE_UTIL_ERROR_INVALID_OPERATION(0x%08x)", IMAGE_UTIL_ERROR_INVALID_OPERATION);
                return IMAGE_UTIL_ERROR_INVALID_OPERATION;
        }
@@ -317,87 +289,79 @@ int image_util_transform_set_colorspace(transformation_h handle, image_util_colo
        _handle->colorspace = colorspace;
        _handle->set_convert = true;
 
-       return ret;
+       return _convert_image_util_error_code(__func__, ret);
 }
 
 int image_util_transform_set_resolution(transformation_h handle, unsigned int width, unsigned int height)
 {
        int ret = IMAGE_UTIL_ERROR_NONE;
-       transformation_s *_handle = (transformation_s*)handle;
+       transformation_s *_handle = (transformation_s *)handle;
 
        LOGD("Set resize_info w[%d] h[%d]", width, height);
 
-       if(_handle == NULL)
-       {
+       if (_handle == NULL) {
                LOGE("Invalid Handle");
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
        }
 
-       if(_handle->set_crop)
-       {
+       if (_handle->set_crop) {
                LOGE("Crop and Resize can't do at the same time");
                return IMAGE_UTIL_ERROR_INVALID_OPERATION;
        }
 
-       if(_image_util_check_resolution(width, height)) {
+       if (_image_util_check_resolution(width, height)) {
                ret = mm_util_set_resolution(_handle->image_h, width, height);
-               if(ret != MM_ERROR_NONE) {
+               if (ret != MM_ERROR_NONE) {
                        LOGE("IMAGE_UTIL_ERROR_INVALID_OPERATION(0x%08x)", IMAGE_UTIL_ERROR_INVALID_OPERATION);
                        return IMAGE_UTIL_ERROR_INVALID_OPERATION;
                }
                _handle->width = width;
                _handle->height = height;
                _handle->set_resize  = true;
-       }
-       else
-       {
+       } else {
                LOGE("INVALID_PARAMETER");
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
        }
 
-       return ret;
+       return _convert_image_util_error_code(__func__, ret);
 }
 
 int image_util_transform_set_rotation(transformation_h handle, image_util_rotation_e rotation)
 {
        int ret = IMAGE_UTIL_ERROR_NONE;
-       transformation_s *_handle = (transformation_s*)handle;
+       transformation_s *_handle = (transformation_s *)handle;
 
        LOGD("Set rotate_info [%d]", rotation);
 
-       if(_handle == NULL)
-       {
+       if (_handle == NULL) {
                LOGE("Invalid Handle");
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
        }
 
        ret = mm_util_set_rotation(_handle->image_h, rotation);
-       if(ret != MM_ERROR_NONE)
-       {
+       if (ret != MM_ERROR_NONE) {
                LOGE("IMAGE_UTIL_ERROR_INVALID_OPERATION(0x%08x)", IMAGE_UTIL_ERROR_INVALID_OPERATION);
                return IMAGE_UTIL_ERROR_INVALID_OPERATION;
        }
        _handle->rotation = rotation;
        _handle->set_rotate = true;
 
-       return ret;
+       return _convert_image_util_error_code(__func__, ret);
 }
 
 int image_util_transform_set_crop_area(transformation_h handle, unsigned int start_x, unsigned int start_y, unsigned int end_x, unsigned int end_y)
 {
        int ret = IMAGE_UTIL_ERROR_NONE;
-       transformation_s *_handle = (transformation_s*)handle;
+       transformation_s *_handle = (transformation_s *)handle;
        int dest_width;
        int dest_height;
 
-       if(_handle == NULL)
-       {
+       if (_handle == NULL) {
                LOGE("Invalid Handle");
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
        }
 
-       if(_handle->set_resize)
-       {
+       if (_handle->set_resize) {
                LOGE("Crop and Resize can't do at the same time");
                return IMAGE_UTIL_ERROR_INVALID_OPERATION;
        }
@@ -407,10 +371,9 @@ int image_util_transform_set_crop_area(transformation_h handle, unsigned int sta
 
        LOGD("Set crop_info x[%d] y[%d] w[%d] h[%d]", start_x, start_y, dest_width, dest_height);
 
-       if(_image_util_check_resolution(dest_width, dest_height))
-       {
+       if (_image_util_check_resolution(dest_width, dest_height)) {
                ret = mm_util_set_crop_area(_handle->image_h, start_x, start_y, end_x, end_y);
-               if(ret != MM_ERROR_NONE) {
+               if (ret != MM_ERROR_NONE) {
                        LOGE("IMAGE_UTIL_ERROR_INVALID_OPERATION(0x%08x)", IMAGE_UTIL_ERROR_INVALID_OPERATION);
                        return IMAGE_UTIL_ERROR_INVALID_OPERATION;
                }
@@ -419,37 +382,32 @@ int image_util_transform_set_crop_area(transformation_h handle, unsigned int sta
                _handle->end_x = end_x;
                _handle->end_y = end_y;
                _handle->set_crop  = true;
-       }
-       else
-       {
+       } else {
                LOGE("INVALID_PARAMETER");
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
        }
 
-       return ret;
+       return _convert_image_util_error_code(__func__, ret);
 }
 
 int image_util_transform_get_colorspace(transformation_h handle, image_util_colorspace_e *colorspace)
 {
        int ret = IMAGE_UTIL_ERROR_NONE;
-       transformation_s *_handle = (transformation_s*)handle;
+       transformation_s *_handle = (transformation_s *)handle;
 
        LOGD("Get colorspace_convert_info [%d]", colorspace);
 
-       if(_handle == NULL)
-       {
+       if (_handle == NULL) {
                LOGE("Invalid Handle");
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
        }
 
-       if(!_handle->set_convert)
-       {
+       if (!_handle->set_convert) {
                LOGE("Did not set colorspace before");
                return IMAGE_UTIL_ERROR_INVALID_OPERATION;
        }
 
-       if(!colorspace)
-       {
+       if (!colorspace) {
                LOGE("colorspace area parameter error");
                return IMAGE_UTIL_ERROR_INVALID_OPERATION;
        }
@@ -461,24 +419,21 @@ int image_util_transform_get_colorspace(transformation_h handle, image_util_colo
 int image_util_transform_get_resolution(transformation_h handle, unsigned int *width, unsigned int *height)
 {
        int ret = IMAGE_UTIL_ERROR_NONE;
-       transformation_s *_handle = (transformation_s*)handle;
+       transformation_s *_handle = (transformation_s *)handle;
 
        LOGD("Set resize_info w[%d] h[%d]", width, height);
 
-       if(_handle == NULL)
-       {
+       if (_handle == NULL) {
                LOGE("Invalid Handle");
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
        }
 
-       if(!_handle->set_resize)
-       {
+       if (!_handle->set_resize) {
                LOGE("Did not set resolution before");
                return IMAGE_UTIL_ERROR_INVALID_OPERATION;
        }
 
-       if(!width || !height)
-       {
+       if (!width || !height) {
                LOGE("resolution area parameter error");
                return IMAGE_UTIL_ERROR_INVALID_OPERATION;
        }
@@ -492,24 +447,21 @@ int image_util_transform_get_resolution(transformation_h handle, unsigned int *w
 int image_util_transform_get_rotation(transformation_h handle, image_util_rotation_e *rotation)
 {
        int ret = IMAGE_UTIL_ERROR_NONE;
-       transformation_s *_handle = (transformation_s*)handle;
+       transformation_s *_handle = (transformation_s *)handle;
 
        LOGD("Set rotate_info [%d]", rotation);
 
-       if(_handle == NULL)
-       {
+       if (_handle == NULL) {
                LOGE("Invalid Handle");
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
        }
 
-       if(!_handle->set_rotate)
-       {
+       if (!_handle->set_rotate) {
                LOGE("Did not set rotation before");
                return IMAGE_UTIL_ERROR_INVALID_OPERATION;
        }
 
-       if(!rotation)
-       {
+       if (!rotation) {
                LOGE("rotation area parameter error");
                return IMAGE_UTIL_ERROR_INVALID_OPERATION;
        }
@@ -522,22 +474,19 @@ int image_util_transform_get_rotation(transformation_h handle, image_util_rotati
 int image_util_transform_get_crop_area(transformation_h handle, unsigned int *start_x, unsigned int *start_y, unsigned int *end_x, unsigned int *end_y)
 {
        int ret = IMAGE_UTIL_ERROR_NONE;
-       transformation_s *_handle = (transformation_s*)handle;
+       transformation_s *_handle = (transformation_s *)handle;
 
-       if(_handle == NULL)
-       {
+       if (_handle == NULL) {
                LOGE("Invalid Handle");
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
        }
 
-       if(!_handle->set_crop)
-       {
+       if (!_handle->set_crop) {
                LOGE("Did not set crop area before");
                return IMAGE_UTIL_ERROR_INVALID_OPERATION;
        }
 
-       if(!start_x || !start_y || !end_x ||!end_y)
-       {
+       if (!start_x || !start_y || !end_x || !end_y) {
                LOGE("crop area parameter error");
                return IMAGE_UTIL_ERROR_INVALID_OPERATION;
        }
@@ -553,39 +502,36 @@ int image_util_transform_get_crop_area(transformation_h handle, unsigned int *st
 int image_util_transform_run(transformation_h handle, media_packet_h src, image_util_transform_completed_cb completed_cb, void *user_data)
 {
        int ret = IMAGE_UTIL_ERROR_NONE;
-       transformation_s *_handle = (transformation_s*)handle;
+       transformation_s *_handle = (transformation_s *)handle;
 
        LOGD("image_util_transform");
 
-       if(_handle == NULL)
-       {
+       if (_handle == NULL) {
                LOGE("Invalid Handle");
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
        }
 
-       if(completed_cb)
-       {
-               _handle->_util_cb = (image_util_cb_s*)calloc(1, sizeof(image_util_cb_s));
-               if(!_handle->_util_cb) {
+       if (completed_cb) {
+               if (_handle->_util_cb != NULL) {
+                       IMAGE_UTIL_SAFE_FREE(_handle->_util_cb);
+                       _handle->_util_cb = NULL;
+               }
+               _handle->_util_cb = (image_util_cb_s *)calloc(1, sizeof(image_util_cb_s));
+               if (!_handle->_util_cb) {
                        LOGE("Out of memory");
                        return IMAGE_UTIL_ERROR_OUT_OF_MEMORY;
                }
 
                _handle->_util_cb->user_data = user_data;
                _handle->_util_cb->image_processing_completed_cb = completed_cb;
-       }
-       else
-       {
-               LOGE("INVALID_PARAMETER[completed_cb] (0x%08x)", IMAGE_UTIL_ERROR_INVALID_PARAMETER);
+       } else {
+               LOGE("INVALID_PARAMETER[completed_cb](0x%08x)", IMAGE_UTIL_ERROR_INVALID_PARAMETER);
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
        }
 
-       if(_handle->_util_cb && src && (_handle->set_convert || _handle->set_resize || _handle->set_rotate || _handle->set_crop))
-       {
+       if (_handle->_util_cb && src && (_handle->set_convert || _handle->set_resize || _handle->set_rotate || _handle->set_crop)) {
                ret = mm_util_transform(_handle->image_h, src, (mm_util_completed_callback)_image_util_transform_completed_cb, (void *)_handle->_util_cb);
-       }
-       else
-       {
+       } else {
                LOGE("INVALID_PARAMETER[transform] (0x%08x)", IMAGE_UTIL_ERROR_INVALID_PARAMETER);
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
        }
@@ -595,12 +541,11 @@ int image_util_transform_run(transformation_h handle, media_packet_h src, image_
 int image_util_transform_destroy(transformation_h handle)
 {
        int ret = IMAGE_UTIL_ERROR_NONE;
-       transformation_s *_handle = (transformation_s*)handle;
+       transformation_s *_handle = (transformation_s *)handle;
 
        LOGD("image_util_destroy");
 
-       if(_handle == NULL)
-       {
+       if (_handle == NULL) {
                LOGE("Invalid Handle");
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
        }
@@ -610,57 +555,57 @@ int image_util_transform_destroy(transformation_h handle)
        IMAGE_UTIL_SAFE_FREE(_handle->_util_cb);
        IMAGE_UTIL_SAFE_FREE(_handle);
 
-       return ret;
+       return _convert_image_util_error_code(__func__, ret);
 }
 
-int image_util_convert_colorspace( unsigned char * dest , image_util_colorspace_e dest_colorspace , const unsigned char * src ,  int width, int height, image_util_colorspace_e src_colorspace)
+int image_util_convert_colorspace(unsigned char *dest, image_util_colorspace_e dest_colorspace, const unsigned char *src,  int width, int height, image_util_colorspace_e src_colorspace)
 {
        int ret = IMAGE_UTIL_ERROR_NONE;
 
-       if( dest == NULL || src == NULL )
+       if (dest == NULL || src == NULL)
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
-       if( dest_colorspace < 0 || dest_colorspace >= sizeof(_convert_colorspace_tbl)/sizeof(int))
+       if (dest_colorspace < 0 || dest_colorspace >= sizeof(_convert_colorspace_tbl) / sizeof(int))
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
-       if( src_colorspace < 0 || src_colorspace >= sizeof(_convert_colorspace_tbl)/sizeof(int))
+       if (src_colorspace < 0 || src_colorspace >= sizeof(_convert_colorspace_tbl) / sizeof(int))
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
 
 
-       ret = mm_util_convert_colorspace(src, width, height, _convert_colorspace_tbl[src_colorspace] , dest, _convert_colorspace_tbl[dest_colorspace]);
+       ret = mm_util_convert_colorspace(src, width, height, _convert_colorspace_tbl[src_colorspace], dest, _convert_colorspace_tbl[dest_colorspace]);
 
        return _convert_image_util_error_code(__func__, ret);
 }
 
 
-int image_util_calculate_buffer_size(int width , int height, image_util_colorspace_e colorspace  ,unsigned int *size)
+int image_util_calculate_buffer_size(int width, int height, image_util_colorspace_e colorspace , unsigned int *size)
 {
        int ret = IMAGE_UTIL_ERROR_NONE;
 
-       if( colorspace < 0 || width <= 0 || height <= 0 || colorspace >= sizeof(_convert_colorspace_tbl)/sizeof(int) || size == NULL)
+       if (colorspace < 0 || width <= 0 || height <= 0 || colorspace >= sizeof(_convert_colorspace_tbl) / sizeof(int) || size == NULL)
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
 
        ret = mm_util_get_image_size(_convert_colorspace_tbl[colorspace], width, height, size);
        return _convert_image_util_error_code(__func__, ret);
 }
 
-int image_util_resize(unsigned char * dest, int *dest_width , int *dest_height, const unsigned char * src, int src_width, int src_height , image_util_colorspace_e colorspace)
+int image_util_resize(unsigned char *dest, int *dest_width, int *dest_height, const unsigned char *src, int src_width, int src_height, image_util_colorspace_e colorspace)
 {
        int ret = IMAGE_UTIL_ERROR_NONE;
 
-       if( dest == NULL || src == NULL )
+       if (dest == NULL || src == NULL)
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
-       if( colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl)/sizeof(int))
+       if (colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl) / sizeof(int))
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
-       ifdest_width == NULL || dest_height == NULL)
+       if (dest_width == NULL || dest_height == NULL)
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
 
-       if( *dest_width <= 0 || *dest_height <= 0 )
+       if (*dest_width <= 0 || *dest_height <= 0)
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
 
        unsigned int dest_w, dest_h;
        dest_w = *dest_width;
        dest_h = *dest_height;
-       ret = mm_util_resize_image(src, src_width, src_height, _convert_colorspace_tbl[colorspace], dest,&dest_w, &dest_h);
-       if( ret == 0){
+       ret = mm_util_resize_image(src, src_width, src_height, _convert_colorspace_tbl[colorspace], dest, &dest_w, &dest_h);
+       if (ret == 0) {
                *dest_width = dest_w;
                *dest_height = dest_h;
        }
@@ -668,46 +613,46 @@ int image_util_resize(unsigned char * dest, int *dest_width , int *dest_height,
        return _convert_image_util_error_code(__func__, ret);
 }
 
-int image_util_rotate(unsigned char * dest, int *dest_width, int *dest_height, image_util_rotation_e dest_rotation, const unsigned char * src, int src_width, int src_height, image_util_colorspace_e colorspace)
+int image_util_rotate(unsigned char *dest, int *dest_width, int *dest_height, image_util_rotation_e dest_rotation, const unsigned char *src, int src_width, int src_height, image_util_colorspace_e colorspace)
 {
        int ret = IMAGE_UTIL_ERROR_NONE;
 
-       if( dest == NULL || src == NULL )
+       if (dest == NULL || src == NULL)
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
-       if( colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl)/sizeof(int))
+       if (colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl) / sizeof(int))
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
-       if( dest_rotation < 0 || dest_rotation > IMAGE_UTIL_ROTATION_FLIP_VERT )
+       if (dest_rotation < 0 || dest_rotation > IMAGE_UTIL_ROTATION_FLIP_VERT)
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
-       ifdest_width == NULL || dest_height == NULL)
+       if (dest_width == NULL || dest_height == NULL)
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
 
        unsigned int dest_w, dest_h;
-       ret = mm_util_rotate_image(src, src_width, src_height, _convert_colorspace_tbl[colorspace], dest,&dest_w, &dest_h, dest_rotation);
-       if( ret == 0){
+       ret = mm_util_rotate_image(src, src_width, src_height, _convert_colorspace_tbl[colorspace], dest, &dest_w, &dest_h, dest_rotation);
+       if (ret == 0) {
                *dest_width = dest_w;
                *dest_height = dest_h;
        }
        return _convert_image_util_error_code(__func__, ret);
 }
 
-int image_util_crop(unsigned char * dest, int x , int y, int* width, int* height, const unsigned char *src, int src_width, int src_height, image_util_colorspace_e colorspace)
+int image_util_crop(unsigned char *dest, int x, int y, int *width, int *height, const unsigned char *src, int src_width, int src_height, image_util_colorspace_e colorspace)
 {
        int ret = IMAGE_UTIL_ERROR_NONE;
 
-       if( dest == NULL || src == NULL )
+       if (dest == NULL || src == NULL)
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
-       if( colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl)/sizeof(int))
+       if (colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl) / sizeof(int))
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
-       if( width == NULL )
+       if (width == NULL)
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
-       if( src_width <= x  || src_height <= y || src_width < x+*width || src_height< y+*height)
+       if (src_width <= x  || src_height <= y || src_width < x + *width || src_height < y + *height)
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
 
        unsigned int dest_w, dest_h;
        dest_w = *width;
        dest_h = *height;
-       ret = mm_util_crop_image( src, src_width, src_height, _convert_colorspace_tbl[colorspace], x, y, &dest_w, &dest_h, dest);
-       if( ret == 0){
+       ret = mm_util_crop_image(src, src_width, src_height, _convert_colorspace_tbl[colorspace], x, y, &dest_w, &dest_h, dest);
+       if (ret == 0) {
                *width = dest_w;
                *height = dest_h;
        }
@@ -715,153 +660,157 @@ int image_util_crop(unsigned char * dest, int x , int y, int* width, int* height
        return _convert_image_util_error_code(__func__, ret);
 }
 
-int image_util_decode_jpeg( const char *path , image_util_colorspace_e colorspace, unsigned char ** image_buffer , int *width , int *height , unsigned int *size)
+int image_util_decode_jpeg(const char *path, image_util_colorspace_e colorspace, unsigned char **image_buffer, int *width, int *height, unsigned int *size)
 {
        int ret = IMAGE_UTIL_ERROR_NONE;
 
-       ifpath == NULL || image_buffer == NULL || size == NULL)
+       if (path == NULL || image_buffer == NULL || size == NULL)
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
-       if(strlen (path) == 0)
+       if (strlen(path) == 0)
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_NO_SUCH_FILE);
-       if( colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl)/sizeof(int))
+       if (colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl) / sizeof(int))
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
-       if( _convert_encode_colorspace_tbl[colorspace] == -1 )
+       if (_convert_encode_colorspace_tbl[colorspace] == -1)
                return _convert_image_util_error_code(__func__, MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT);
 
-       mm_util_jpeg_yuv_data decoded = { 0, 0, 0, NULL};
+       mm_util_jpeg_yuv_data decoded;
+       memset(&decoded, 0, sizeof(mm_util_jpeg_yuv_data));
 
-       ret = mm_util_decode_from_jpeg_file(&decoded, (char*)path, _convert_encode_colorspace_tbl[colorspace]);
-       if( ret == 0 ){
+       ret = mm_util_decode_from_jpeg_file(&decoded, path, _convert_encode_colorspace_tbl[colorspace]);
+       if (ret == 0) {
                *image_buffer = decoded.data;
-               if(width)
+               if (width)
                        *width = decoded.width;
-               if(height)
+               if (height)
                        *height = decoded.height;
-               if(size)
+               if (size)
                        *size = decoded.size;
        }
        return _convert_image_util_error_code(__func__, ret);
 }
 
-int image_util_decode_jpeg_from_memory( const unsigned char * jpeg_buffer , int jpeg_size , image_util_colorspace_e colorspace, unsigned char ** image_buffer , int *width , int *height , unsigned int *size)
+int image_util_decode_jpeg_from_memory(const unsigned char *jpeg_buffer, int jpeg_size, image_util_colorspace_e colorspace, unsigned char **image_buffer, int *width, int *height, unsigned int *size)
 {
        int ret = IMAGE_UTIL_ERROR_NONE;
 
-       ifjpeg_buffer == NULL || image_buffer == NULL || size == NULL)
+       if (jpeg_buffer == NULL || image_buffer == NULL || size == NULL)
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
-       if( colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl)/sizeof(int))
+       if (colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl) / sizeof(int))
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
-       if( _convert_encode_colorspace_tbl[colorspace] == -1 )
+       if (_convert_encode_colorspace_tbl[colorspace] == -1)
                return _convert_image_util_error_code(__func__, MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT);
 
        mm_util_jpeg_yuv_data decoded;
+       memset(&decoded, 0, sizeof(mm_util_jpeg_yuv_data));
 
-       ret = mm_util_decode_from_jpeg_memory(&decoded , jpeg_buffer, jpeg_size, _convert_encode_colorspace_tbl[colorspace] );
+       ret = mm_util_decode_from_jpeg_memory(&decoded, (void *)jpeg_buffer, jpeg_size, _convert_encode_colorspace_tbl[colorspace]);
 
-       if( ret == 0 ){
+       if (ret == 0) {
                *image_buffer = decoded.data;
-               if(width)
+               if (width)
                        *width = decoded.width;
-               if(height)
+               if (height)
                        *height = decoded.height;
-               if(size)
+               if (size)
                        *size = decoded.size;
        }
 
        return _convert_image_util_error_code(__func__, ret);
 }
 
-int image_util_decode_jpeg_with_downscale( const char *path, image_util_colorspace_e colorspace, image_util_scale_e downscale, unsigned char ** image_buffer, int *width, int *height, unsigned int *size)
+int image_util_decode_jpeg_with_downscale(const char *path, image_util_colorspace_e colorspace, image_util_scale_e downscale, unsigned char **image_buffer, int *width, int *height, unsigned int *size)
 {
        int ret = IMAGE_UTIL_ERROR_NONE;
 
-       ifpath == NULL || image_buffer == NULL || size == NULL)
+       if (path == NULL || image_buffer == NULL || size == NULL)
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
-       if(strlen (path) == 0)
+       if (strlen(path) == 0)
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_NO_SUCH_FILE);
-       if( colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl)/sizeof(int))
+       if (colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl) / sizeof(int))
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
-       if( _convert_encode_colorspace_tbl[colorspace] == -1 )
+       if (_convert_encode_colorspace_tbl[colorspace] == -1)
                return _convert_image_util_error_code(__func__, MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT);
-       if( downscale < 0 || downscale >= sizeof(_convert_decode_scale_tbl)/sizeof(int))
+       if (downscale < 0 || downscale >= sizeof(_convert_decode_scale_tbl) / sizeof(int))
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
 
-       mm_util_jpeg_yuv_data decoded = { 0, 0, 0, NULL};
+       mm_util_jpeg_yuv_data decoded;
+       memset(&decoded, 0, sizeof(mm_util_jpeg_yuv_data));
 
-       ret = mm_util_decode_from_jpeg_file_with_downscale(&decoded, (char*)path, _convert_encode_colorspace_tbl[colorspace], _convert_decode_scale_tbl[downscale]);
-       if( ret == 0 ){
+       ret = mm_util_decode_from_jpeg_file_with_downscale(&decoded, path, _convert_encode_colorspace_tbl[colorspace], _convert_decode_scale_tbl[downscale]);
+       if (ret == 0) {
                *image_buffer = decoded.data;
-               if(width)
+               if (width)
                        *width = decoded.width;
-               if(height)
+               if (height)
                        *height = decoded.height;
-               if(size)
+               if (size)
                        *size = decoded.size;
        }
        return _convert_image_util_error_code(__func__, ret);
 }
 
-int image_util_decode_jpeg_from_memory_with_downscale( const unsigned char * jpeg_buffer, int jpeg_size, image_util_colorspace_e colorspace, image_util_scale_e downscale, unsigned char ** image_buffer, int *width, int *height, unsigned int *size)
+int image_util_decode_jpeg_from_memory_with_downscale(const unsigned char *jpeg_buffer, int jpeg_size, image_util_colorspace_e colorspace, image_util_scale_e downscale, unsigned char **image_buffer, int *width, int *height, unsigned int *size)
 {
        int ret = IMAGE_UTIL_ERROR_NONE;
 
-       ifjpeg_buffer == NULL || image_buffer == NULL || size == NULL)
+       if (jpeg_buffer == NULL || image_buffer == NULL || size == NULL)
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
-       if( colorspace < 0 ||colorspace >= sizeof(_convert_colorspace_tbl)/sizeof(int))
+       if (colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl) / sizeof(int))
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
-       if( _convert_encode_colorspace_tbl[colorspace] == -1 )
+       if (_convert_encode_colorspace_tbl[colorspace] == -1)
                return _convert_image_util_error_code(__func__, MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT);
-       if( downscale < 0 || downscale >= sizeof(_convert_decode_scale_tbl)/sizeof(int))
+       if (downscale < 0 || downscale >= sizeof(_convert_decode_scale_tbl) / sizeof(int))
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
 
        mm_util_jpeg_yuv_data decoded;
+       memset(&decoded, 0, sizeof(mm_util_jpeg_yuv_data));
 
-       ret = mm_util_decode_from_jpeg_memory_with_downscale(&decoded, jpeg_buffer, jpeg_size, _convert_encode_colorspace_tbl[colorspace], _convert_decode_scale_tbl[downscale]);
+       ret = mm_util_decode_from_jpeg_memory_with_downscale(&decoded, (void *)jpeg_buffer, jpeg_size, _convert_encode_colorspace_tbl[colorspace], _convert_decode_scale_tbl[downscale]);
 
-       if( ret == 0 ){
+       if (ret == 0) {
                *image_buffer = decoded.data;
-               if(width)
+               if (width)
                        *width = decoded.width;
-               if(height)
+               if (height)
                        *height = decoded.height;
-               if(size)
+               if (size)
                        *size = decoded.size;
        }
 
        return _convert_image_util_error_code(__func__, ret);
 }
 
-int image_util_encode_jpeg( const unsigned char *buffer, int width, int height, image_util_colorspace_e colorspace,  int quality, const char *path)
+int image_util_encode_jpeg(const unsigned char *buffer, int width, int height, image_util_colorspace_e colorspace,  int quality, const char *path)
 {
        int ret = IMAGE_UTIL_ERROR_NONE;
 
-       if( path == NULL || buffer == NULL )
+       if (path == NULL || buffer == NULL)
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
-       if(strlen (path) == 0)
+       if (strlen(path) == 0)
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_NO_SUCH_FILE);
-       if( colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl)/sizeof(int))
+       if (colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl) / sizeof(int))
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
-       if( _convert_encode_colorspace_tbl[colorspace] == -1 )
+       if (_convert_encode_colorspace_tbl[colorspace] == -1)
                return _convert_image_util_error_code(__func__, MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT);
 
-       ret = mm_util_jpeg_encode_to_file(path, buffer, width, height, _convert_encode_colorspace_tbl[colorspace], quality);
+       ret = mm_util_jpeg_encode_to_file(path, (void *)buffer, width, height, _convert_encode_colorspace_tbl[colorspace], quality);
        return _convert_image_util_error_code(__func__, ret);
 }
 
-int image_util_encode_jpeg_to_memory( const unsigned char *image_buffer, int width, int height, image_util_colorspace_e colorspace, int quality,  unsigned char** jpeg_buffer, unsigned int *jpeg_size)
+int image_util_encode_jpeg_to_memory(const unsigned char *image_buffer, int width, int height, image_util_colorspace_e colorspace, int quality,  unsigned char **jpeg_buffer, unsigned int *jpeg_size)
 {
        int ret = IMAGE_UTIL_ERROR_NONE;
        int isize;
 
-       if( jpeg_buffer == NULL || image_buffer == NULL || jpeg_size == NULL )
+       if (jpeg_buffer == NULL || image_buffer == NULL || jpeg_size == NULL)
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
-       if( colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl)/sizeof(int))
+       if (colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl) / sizeof(int))
                return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
-       if( _convert_encode_colorspace_tbl[colorspace] == -1 )
+       if (_convert_encode_colorspace_tbl[colorspace] == -1)
                return _convert_image_util_error_code(__func__, MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT);
 
-       ret = mm_util_jpeg_encode_to_memory( (void**)jpeg_buffer, &isize, image_buffer, width, height, _convert_encode_colorspace_tbl[colorspace] , quality );
-       if( ret == 0 )
+       ret = mm_util_jpeg_encode_to_memory((void **)jpeg_buffer, &isize, (void *)image_buffer, width, height, _convert_encode_colorspace_tbl[colorspace], quality);
+       if (ret == 0)
                *jpeg_size = isize;
 
        return _convert_image_util_error_code(__func__, ret);
index d2f30d9..7c57a1d 100755 (executable)
@@ -1,7 +1,8 @@
 SET(fw_test "${fw_name}-test")
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(${fw_test} REQUIRED glib-2.0 elementary evas ecore edje ecore-x )
+pkg_check_modules(${fw_test} REQUIRED glib-2.0)
+
 FOREACH(flag ${${fw_test}_CFLAGS})
     SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
     MESSAGE(${flag})
@@ -9,13 +10,12 @@ ENDFOREACH()
 
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -pie -Wall")
 
-#ADD_EXECUTABLE("system-sensor" system-sensor.c)
-#TARGET_LINK_LIBRARIES("system-sensor" ${fw_name} ${${fw_test}_LDFLAGS})
-
 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})
+    ADD_EXECUTABLE(${fw_test} ${src})
+    TARGET_LINK_LIBRARIES(${fw_test} ${fw_name} ${${fw_test}_LDFLAGS})
 ENDFOREACH()
+
+#INSTALL(TARGETS ${fw_test} DESTINATION bin)
diff --git a/test/image_util_test.c b/test/image_util_test.c
new file mode 100755 (executable)
index 0000000..1fa1614
--- /dev/null
@@ -0,0 +1,631 @@
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* 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 <glib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <image_util.h>
+#include <image_util_type.h>
+#include <mm_error.h>
+
+#define MAX_STRING_LEN 128
+#define IMAGE_FORMAT_LABEL_BUFFER_SIZE 4
+
+#define IMAGE_UTIL_SAFE_FREE(src)      { if(src) {free(src); src = NULL;}}
+
+
+GMainLoop *g_loop = NULL;
+transformation_h g_handle = NULL;
+media_packet_h g_src = NULL;
+media_packet_h g_result = NULL;
+char *g_path = NULL;
+unsigned int g_width = 0;
+unsigned int g_height = 0;
+int g_format = -1;
+
+GCond *g_thread_cond = NULL;
+GMutex *g_thread_mutex = NULL;
+
+enum {
+    CURRENT_STATE_MAIN_MENU,
+    CURRENT_STATE_SET_IMAGE_MENU,
+};
+
+enum {
+    CURRENT_STATE_SET_IMAGE_NONE,
+    CURRENT_STATE_SET_IMAGE_PATH,
+    CURRENT_STATE_SET_IMAGE_WIDTH,
+    CURRENT_STATE_SET_IMAGE_HEIGHT,
+    CURRENT_STATE_SET_IMAGE_FORMAT,
+};
+
+int g_menu_state = CURRENT_STATE_MAIN_MENU;
+int g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_NONE;
+
+void _wait()
+{
+       g_mutex_lock(g_thread_mutex);
+       g_printf("waiting... untill finishing transform \n");
+       g_cond_wait(g_thread_cond, g_thread_mutex);
+       g_printf("<=== get signal from callback \n");
+       g_mutex_unlock(g_thread_mutex);
+}
+
+void _signal()
+{
+       g_mutex_lock(g_thread_mutex);
+       g_cond_signal(g_thread_cond);
+       g_printf("===> send signal to test proc \n");
+       g_mutex_unlock(g_thread_mutex);
+}
+
+media_format_mimetype_e
+_image_util_mapping_imgp_format_to_mime(image_util_colorspace_e colorspace)
+{
+       media_format_mimetype_e mimetype = -1;
+
+       switch (colorspace) {
+               case IMAGE_UTIL_COLORSPACE_NV12:
+                       mimetype = MEDIA_FORMAT_NV12;
+                       break;
+               case IMAGE_UTIL_COLORSPACE_NV16:
+                       mimetype = MEDIA_FORMAT_NV16;
+                       break;
+               case IMAGE_UTIL_COLORSPACE_YUYV:
+                       mimetype = MEDIA_FORMAT_YUYV;
+                       break;
+               case IMAGE_UTIL_COLORSPACE_UYVY:
+                       mimetype = MEDIA_FORMAT_UYVY;
+                       break;
+               case IMAGE_UTIL_COLORSPACE_YUV422:
+                       mimetype = MEDIA_FORMAT_422P;
+                       break;
+               case IMAGE_UTIL_COLORSPACE_I420:
+                       mimetype = MEDIA_FORMAT_I420;
+                       break;
+               case IMAGE_UTIL_COLORSPACE_NV21:
+                       mimetype = MEDIA_FORMAT_YV12;
+                       break;
+               case IMAGE_UTIL_COLORSPACE_RGB565:
+                       mimetype = MEDIA_FORMAT_RGB565;
+                       break;
+               case IMAGE_UTIL_COLORSPACE_RGB888:
+                       mimetype = MEDIA_FORMAT_RGB888;
+                       break;
+               case IMAGE_UTIL_COLORSPACE_RGBA8888:
+                       mimetype = MEDIA_FORMAT_RGBA;
+                       break;
+               case IMAGE_UTIL_COLORSPACE_ARGB8888:
+                       mimetype = MEDIA_FORMAT_ARGB;
+                       break;
+               case IMAGE_UTIL_COLORSPACE_BGRA8888:
+               case IMAGE_UTIL_COLORSPACE_BGRX8888:
+               case IMAGE_UTIL_COLORSPACE_NV61:
+               default:
+                       mimetype = -1;
+                       g_printf("Not Supported Format");
+                       break;
+       }
+
+       g_printf("imgp fmt: %d mimetype fmt: %d", colorspace, mimetype);
+       return mimetype;
+}
+
+bool test_transform_completed_cb(media_packet_h *packet, image_util_error_e error, void *user_data)
+{
+       uint64_t size = 0;
+       char output_file[25] = {};
+
+       media_format_h dst_fmt;
+       media_format_mimetype_e dst_mimetype;
+       int dst_width, dst_height, dst_avg_bps, dst_max_bps;
+       char *output_fmt = NULL;
+
+       g_printf("test_transform_completed_cb============= [%d] \n", error);
+       if (error == MM_ERROR_NONE) {
+               g_printf("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) {
+                               g_printf("Imedia_packet_get_format");
+                               _signal();
+                               return FALSE;
+                       }
+
+                       if (g_result != NULL) {
+                               media_packet_destroy(g_result);
+                       }
+                       media_packet_create_alloc(dst_fmt, NULL, NULL, &g_result);
+                       if (media_packet_get_buffer_size(g_result, &size) != MM_ERROR_NONE) {
+                               g_printf("Imedia_packet_get_format)");
+                               media_format_unref(dst_fmt);
+                               _signal();
+                               return FALSE;
+                       }
+                       g_printf("g_result: %p [%d] \n", g_result, size);
+
+                       if (media_format_get_video_info(dst_fmt, &dst_mimetype, &dst_width, &dst_height, &dst_avg_bps, &dst_max_bps) == MEDIA_FORMAT_ERROR_NONE) {
+                               memset(output_fmt, 0, IMAGE_FORMAT_LABEL_BUFFER_SIZE);
+                               if (dst_mimetype  == MEDIA_FORMAT_YV12 || dst_mimetype == MEDIA_FORMAT_422P || dst_mimetype == MEDIA_FORMAT_I420
+                                   || dst_mimetype == MEDIA_FORMAT_NV12 || dst_mimetype == MEDIA_FORMAT_UYVY || dst_mimetype == MEDIA_FORMAT_YUYV) {
+                                       strncpy(output_fmt, "yuv", strlen("yuv"));
+                               } else {
+                                       strncpy(output_fmt, "rgb", strlen("rgb"));
+                               }
+                               g_printf("[mimetype: %d] W x H : %d x %d \n", dst_mimetype, dst_width, dst_height);
+                               snprintf(output_file, 25, "result_%dx%d.%s", dst_width, dst_height, output_fmt);
+                       }
+               }
+
+               FILE *fpout = fopen(output_file, "w");
+               if (fpout) {
+                       media_packet_get_buffer_size(*packet, &size);
+                       void *dst = NULL;
+                       if (media_packet_get_buffer_data_ptr(*packet, &dst) != MM_ERROR_NONE) {
+                               IMAGE_UTIL_SAFE_FREE(dst);
+                               IMAGE_UTIL_SAFE_FREE(output_fmt);
+                               fclose(fpout);
+                               g_printf("[dst] media_packet_get_extra \n");
+                               _signal();
+                               return FALSE;
+                       }
+                       g_printf("dst: %p [%d] \n", dst, size);
+                       fwrite(dst, 1, size, fpout);
+                       g_printf("FREE \n");
+                       fclose(fpout);
+               }
+
+               g_printf("write result \n");
+               g_printf("Free (output_fmt) \n");
+               IMAGE_UTIL_SAFE_FREE(output_fmt);
+       } else {
+               g_printf("[ERROR] complete cb");
+               _signal();
+               return FALSE;
+       }
+
+       media_packet_destroy(*packet);
+
+       _signal();
+
+       return TRUE;
+}
+
+static int
+create_media_packet()
+{
+       int ret = 0;
+       media_format_h fmt;
+       void *src;
+       void *ptr;
+       if (media_format_create(&fmt) == MEDIA_FORMAT_ERROR_NONE) {
+               if (media_format_set_video_mime(fmt, _image_util_mapping_imgp_format_to_mime(g_format)) != MEDIA_FORMAT_ERROR_NONE) {
+                       media_format_unref(fmt);
+                       g_printf("[Error] Set - video mime\n");
+                       return MM_ERROR_IMAGE_INVALID_VALUE;
+               }
+
+               if (media_format_set_video_width(fmt, g_width) != MEDIA_FORMAT_ERROR_NONE) {
+                       media_format_unref(fmt);
+                       g_printf("[Error] Set - video width\n");
+                       return MM_ERROR_IMAGE_INVALID_VALUE;
+               }
+
+               if (media_format_set_video_height(fmt, g_height) != MEDIA_FORMAT_ERROR_NONE) {
+                       media_format_unref(fmt);
+                       g_printf("[Error] Set - video heigh\nt");
+                       return MM_ERROR_IMAGE_INVALID_VALUE;
+               }
+
+               if (media_format_set_video_avg_bps(fmt, 2000000) != MEDIA_FORMAT_ERROR_NONE) {
+                       media_format_unref(fmt);
+                       g_printf("[Error] Set - video avg bps\n");
+                       return MM_ERROR_IMAGE_INVALID_VALUE;
+               }
+
+               if (media_format_set_video_max_bps(fmt, 15000000) != MEDIA_FORMAT_ERROR_NONE) {
+                       media_format_unref(fmt);
+                       g_printf("[Error] Set - video max bps\n");
+                       return MM_ERROR_IMAGE_INVALID_VALUE;
+               }
+
+               g_printf("media_format_set_video_info success! file:%s, w:%d, h:%d, %d\n", g_path, g_width, g_height, _image_util_mapping_imgp_format_to_mime(g_format));
+       } else {
+               g_printf("media_format_create failed...");
+       }
+
+       ret = media_packet_create_alloc(fmt, NULL, NULL, &g_src);
+       if (ret == MM_ERROR_NONE) {
+               g_printf("Success - media_packet_create_alloc\n");
+               uint64_t size = 0;
+               if (media_packet_get_buffer_size(g_src, &size) == MEDIA_PACKET_ERROR_NONE) {
+                       ptr = malloc(size);
+                       if (ptr == NULL) {
+                               g_printf("\tmemory allocation failed\n");
+                               return MM_ERROR_IMAGE_INTERNAL;
+                       }
+                       if (media_packet_get_buffer_data_ptr(g_src, &ptr) == MEDIA_PACKET_ERROR_NONE) {
+                               FILE *fp = fopen(g_path, "r");
+                               if (fp == NULL) {
+                                       g_printf("\tfile open failed %d\n", errno);
+                                       return MM_ERROR_IMAGE_INTERNAL;
+                               }
+                               src = malloc(size);
+                               if (src == NULL) {
+                                       g_printf("\tmemory allocation failed\n");
+                                       return MM_ERROR_IMAGE_INTERNAL;
+                               }
+                               if (fread(src, 1, (int)size, fp)) {
+                                       g_printf("#Success# fread\n");
+                                       memcpy(ptr, src, (int)size);
+                                       g_printf("memcpy\n");
+                               } else {
+                                       g_printf("#Error# fread\n");
+                               }
+                       }
+               }
+       } else {
+               media_format_unref(fmt);
+               g_printf("ERROR - media_packet_create_alloc");
+               return ret;
+       }
+       media_format_unref(fmt);
+       return ret;
+}
+
+static void _create()
+{
+       int ret = 0;
+       if (g_handle != NULL) {
+               ret = image_util_transform_destroy(g_handle);
+               if (ret != IMAGE_UTIL_ERROR_NONE) {
+                       g_printf("[%d]Error image_util_transform_destroy [%d]\n", __LINE__, ret);
+               } else {
+                       g_printf("[%d]Success image_util_transform_destroy [%d]\n", __LINE__, ret);
+               }
+       }
+       ret = image_util_transform_create(&g_handle);
+       if (ret != IMAGE_UTIL_ERROR_NONE) {
+               g_printf("[%d]Error image_util_transform_create [%d]\n", __LINE__, ret);
+       } else {
+               g_printf("[%d]Success image_util_transform_create [%d]\n", __LINE__, ret);
+       }
+}
+
+static void _set_image()
+{
+       int ret = 0;
+       if (g_src) {
+               media_packet_destroy(g_src);
+               g_printf("[%d]Success source packet is destroyed \n", __LINE__);
+       }
+       ret = create_media_packet();
+       if (ret == MM_ERROR_NONE) {
+               g_printf("Success - Create_media_packet\n");
+       } else {
+               g_printf("Error - Create_media_packet\n");
+       }
+}
+
+static void _destroy()
+{
+       int ret = 0;
+
+       if (g_handle) {
+               ret = image_util_transform_destroy(g_handle);
+               if (ret != IMAGE_UTIL_ERROR_NONE) {
+                       g_printf("[%d]Error image_util_transform_destroy [%d]\n", __LINE__, ret);
+               } else {
+                       g_printf("[%d]Success image_util_transform_destroy [%d]\n", __LINE__, ret);
+               }
+       } else {
+               g_printf("[%d]Error handle was already destroyed \n", __LINE__);
+       }
+       g_handle = NULL;
+}
+
+static void _transform(char *cmd)
+{
+       int ret = 0;
+       unsigned int width = 0;
+       unsigned int height = 0;
+       image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_RGB888;
+       image_util_rotation_e angle;
+       int start_x;
+       int start_y;
+       int end_x;
+       int end_y;
+
+       if (!strcmp("convert", cmd)) {
+               colorspace = IMAGE_UTIL_COLORSPACE_RGB888;
+
+               ret = image_util_transform_set_colorspace(g_handle, colorspace);
+               if (ret != IMAGE_UTIL_ERROR_NONE) {
+                       g_printf("[%d]error image_util_set colorspace [%d]\n", __LINE__, ret);
+                       return;
+               }
+       }
+
+       if (!strcmp("resize", cmd)) {
+               width = 480;
+               height = 360;
+
+               ret = image_util_transform_set_resolution(g_handle, width, height);
+               if (ret != IMAGE_UTIL_ERROR_NONE) {
+                       g_printf("[%d]Error image_util_set resolution [%d]\n", __LINE__, ret);
+                       return;
+               }
+       }
+
+       if (!strcmp("rotate", cmd)) {
+               angle = 1;
+
+               ret = image_util_transform_set_rotation(g_handle, angle);
+               if (ret != IMAGE_UTIL_ERROR_NONE) {
+                       g_printf("[%d]Error image_util_set colorspace [%d]\n", __LINE__, ret);
+                       return;
+               }
+       }
+
+       if (!strcmp("crop", cmd)) {
+               start_x = 500;
+               start_y = 500;
+               end_x = 700;
+               end_y = 700;
+
+               ret = image_util_transform_set_crop_area(g_handle, start_x, start_y, end_x, end_y);
+               if (ret != IMAGE_UTIL_ERROR_NONE) {
+                       g_printf("[%d]Error image_util_set colorspace [%d]\n", __LINE__, ret);
+                       return;
+               }
+       }
+
+       if (!strcmp("run", cmd)) {
+               ret = image_util_transform_run(g_handle, g_src, test_transform_completed_cb, NULL);
+               if (ret != IMAGE_UTIL_ERROR_NONE) {
+                       g_printf("[%d]Error image_util_transform [%d]\n", __LINE__, ret);
+                       return;
+               }
+               _wait();
+       }
+
+}
+
+void quit(void)
+{
+       if (g_loop)
+               g_main_loop_quit(g_loop);
+}
+
+void reset_current_menu_state()
+{
+       g_menu_state = CURRENT_STATE_MAIN_MENU;
+       return;
+}
+
+static void display_set_image_menu(void)
+{
+       g_print("\n");
+       g_print("====================================================\n");
+       g_print("    image-util Core-API test: Main menu v0.2\n");
+       g_print("----------------------------------------------------\n");
+       g_print("1. set image path \n");
+       g_print("2. set image width \n");
+       g_print("3. set image height \n");
+       g_print("4. set image format \n");
+       g_print("0. back \n");
+       g_print("----------------------------------------------------\n");
+       g_print("====================================================\n");
+
+}
+
+static void display_menu(void)
+{
+       g_print("\n");
+       g_print("====================================================\n");
+       g_print("   image-util Core-API test: Main menu v0.2\n");
+       g_print("----------------------------------------------------\n");
+       g_print("1. create handle \n");
+       g_print("2. set image \n");
+       g_print("3. set convert \n");
+       g_print("4. set crop \n");
+       g_print("5. set resize \n");
+       g_print("6. set rotate \n");
+       g_print("7. run \n");
+       g_print("8. run with result \n");
+       g_print("9. destroy handle \n");
+       g_print("0. quit \n");
+       g_print("----------------------------------------------------\n");
+       g_print("====================================================\n");
+
+}
+
+static void interpret_set_image_cmd(char *cmd)
+{
+       int len = strlen(cmd);
+       if (g_menu_set_image_state == CURRENT_STATE_SET_IMAGE_NONE) {
+               if (len == 1) {
+                       if (!strncmp(cmd, "1", len)) {
+                               g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_PATH;
+                               g_print("Path: ");
+                       } else if (!strncmp(cmd, "2", len)) {
+                               g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_WIDTH;
+                               g_print("Width: ");
+                       } else if (!strncmp(cmd, "3", len)) {
+                               g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_HEIGHT;
+                               g_print("height: ");
+                       } else if (!strncmp(cmd, "4", len)) {
+                               g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_FORMAT;
+                               g_print("Format: ");
+                       } else if (!strncmp(cmd, "0", len)) {
+                               _set_image();
+                               reset_current_menu_state();
+                               display_menu();
+                       }
+               } else {
+                       g_print("wrong command\n");
+                       display_set_image_menu();
+               }
+       } else if (g_menu_set_image_state == CURRENT_STATE_SET_IMAGE_PATH) {
+               IMAGE_UTIL_SAFE_FREE(g_path);
+               g_path = (char *)g_malloc(MAX_STRING_LEN * sizeof(char *));
+               memset(g_path, 0x00, MAX_STRING_LEN);
+               snprintf(g_path, MAX_STRING_LEN, "%s", cmd);
+               g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_NONE;
+               display_set_image_menu();
+       } else if (g_menu_set_image_state == CURRENT_STATE_SET_IMAGE_WIDTH) {
+               g_width = atoi(cmd);
+               g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_NONE;
+               display_set_image_menu();
+       } else if (g_menu_set_image_state == CURRENT_STATE_SET_IMAGE_HEIGHT) {
+               g_height = atoi(cmd);
+               g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_NONE;
+               display_set_image_menu();
+       } else if (g_menu_set_image_state == CURRENT_STATE_SET_IMAGE_FORMAT) {
+               g_format = atoi(cmd);
+               g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_NONE;
+               display_set_image_menu();
+       }
+}
+
+static void interpret_cmd(char *cmd)
+{
+       int len = strlen(cmd);
+       if (g_menu_state == CURRENT_STATE_MAIN_MENU) {
+               if (len == 1) {
+                       if (!strncmp(cmd, "1", len)) {
+                               _create();
+                       } else if (!strncmp(cmd, "2", len)) {
+                               g_menu_state = CURRENT_STATE_SET_IMAGE_MENU;
+                               g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_NONE;
+                               display_set_image_menu();
+                               return;
+                       } else if (!strncmp(cmd, "3", len)) {
+                               _transform("convert");
+                       } else if (!strncmp(cmd, "4", len)) {
+                               _transform("crop");
+                       } else if (!strncmp(cmd, "5", len)) {
+                               _transform("resize");
+                       } else if (!strncmp(cmd, "6", len)) {
+                               _transform("rotate");
+                       } else if (!strncmp(cmd, "7", len)) {
+                               _transform("run");
+                       } else if (!strncmp(cmd, "9", len)) {
+                               _destroy();
+                       } else if (!strncmp(cmd, "0", len)) {
+                               quit();
+                       }
+               } else {
+                       g_print("wrong command\n");
+               }
+
+               display_menu();
+       } else if (g_menu_state == CURRENT_STATE_SET_IMAGE_MENU) {
+               interpret_set_image_cmd(cmd);
+       } else {
+               g_print("wrong menu state\n");
+       }
+}
+
+gboolean input(GIOChannel *channel)
+{
+       gchar buf[MAX_STRING_LEN];
+       gsize read;
+       GError *error = NULL;
+
+       g_io_channel_read_chars(channel, buf, MAX_STRING_LEN, &read, &error);
+
+       buf[read] = '\0';
+       g_strstrip(buf);
+       interpret_cmd(buf);
+
+       return TRUE;
+}
+
+int main(int argc, char **argv)
+{
+       int ret = IMAGE_UTIL_ERROR_NONE;
+
+       GIOChannel *stdin_channel = NULL;
+       stdin_channel = g_io_channel_unix_new(0);
+       g_io_channel_set_flags(stdin_channel, G_IO_FLAG_NONBLOCK, NULL);
+       g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, NULL);
+
+       if (argc < 4) {
+               g_printf("Usage: image_utl_test filename width height format \n");
+               return ret;
+       }
+
+       g_handle = NULL;
+       g_src = NULL;
+       g_path = (char *)g_malloc(MAX_STRING_LEN * sizeof(char *));
+       memset(g_path, 0x00, MAX_STRING_LEN);
+       snprintf(g_path, MAX_STRING_LEN, "%s", argv[1]);
+       g_width = atoi(argv[2]);
+       g_height = atoi(argv[3]);
+       g_format = atoi(argv[4]);
+
+       g_thread_mutex = g_mutex_new();
+       g_thread_cond = g_cond_new();
+
+       ret = image_util_transform_create(&g_handle);
+       if (ret != IMAGE_UTIL_ERROR_NONE) {
+               g_printf("[%d]Error image_util_transform_create [%d]\n", __LINE__, ret);
+               goto Exit;
+       }
+
+       bool hardware_acceleration = FALSE;
+
+       ret = create_media_packet();
+       if (ret == MM_ERROR_NONE) {
+               g_printf("Success - Create_media_packet\n");
+       } else {
+               g_printf("Error - Create_media_packet\n");
+               goto Exit;
+       }
+
+       ret = image_util_transform_set_hardware_acceleration(g_handle, hardware_acceleration);
+       if (ret != IMAGE_UTIL_ERROR_NONE) {
+               g_printf("[%d]Error image_util_transform_set_hardware_acceleration condition [%d]\n", __LINE__, ret);
+               goto Exit;
+       }
+
+       display_menu();
+
+       g_loop = g_main_loop_new(NULL, FALSE);
+
+       g_main_loop_run(g_loop);
+       g_main_loop_unref(g_loop);
+
+Exit:
+       g_mutex_free(g_thread_mutex);
+       g_cond_free(g_thread_cond);
+       if (g_path) {
+               IMAGE_UTIL_SAFE_FREE(g_path);
+               g_printf("[%d]Success file path is destroyed \n", __LINE__);
+       } else {
+               g_printf("[%d]Error file path was already destroyed \n", __LINE__);
+       }
+       if (g_src) {
+               media_packet_destroy(g_src);
+               g_printf("[%d]Success source packet is destroyed \n", __LINE__);
+       } else {
+               g_printf("[%d]Error source packet was already destroyed \n", __LINE__);
+       }
+       _destroy();
+
+       return 0;
+}
diff --git a/test/multimeida_image_util_test.c b/test/multimeida_image_util_test.c
deleted file mode 100755 (executable)
index 43e6be0..0000000
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
-* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
-*
-* 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 <image_util.h>
-
-GMainLoop *g_loop = NULL;
-
-bool test_transform_completed_cb(media_packet_h *dst, image_util_error_e error, void *user_data)
-{
-       transformation_s *transform = (transformation_s *)user_data;
-       printf("test_transform_completed_cb============= [%d]\n", error);
-
-       if(error == MM_ERROR_NONE) {
-               printf("completed");
-               *dst = transform->dst;
-               if(g_loop)
-                       g_main_loop_quit(g_loop);
-       } else {
-               printf("[ERROR] complete cb");
-               GThread * destroy_thread = g_thread_new(NULL, image_util_destroy, transform);
-               g_thread_unref(destroy_thread);
-       }
-
-       return TRUE;
-}
-
-static int
-create_media_packet(media_format_h *packet)
-{
-       int ret = 0;
-       media_format_h fmt;
-       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);
-                       printf("[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);
-                       printf("[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);
-                       printf("[Error] Set - video height");
-                       return MM_ERROR_IMAGE_INVALID_VALUE;
-               }
-
-               if(media_format_set_video_avg_bps(fmt, 2000000) != MEDIA_FORMAT_ERROR_NONE) {
-                       media_format_unref(fmt);
-                       printf("[Error] Set - video avg bps");
-                       return MM_ERROR_IMAGE_INVALID_VALUE;
-               }
-
-               if(media_format_set_video_max_bps(fmt, 15000000) != MEDIA_FORMAT_ERROR_NONE) {
-                       media_format_unref(fmt);
-                       printf("[Error] Set - video max bps");
-                       return MM_ERROR_IMAGE_INVALID_VALUE;
-               }
-
-               printf("media_format_set_video_info success! w:320, h:240, MEDIA_FORMAT_I420\n");
-       }
-       else {
-               printf("media_format_create failed...");
-       }
-
-       ret = media_packet_create_alloc(fmt, (media_packet_finalize_cb)transform_completed_cb, NULL, packet);
-       if(ret == MM_ERROR_NONE) {
-               printf("Success - media_packet_create_alloc");
-       } else {
-               media_format_unref(fmt);
-               printf("ERROR - media_packet_create_alloc");
-               return ret;
-       }
-       media_format_unref(fmt);
-       return ret;
-}
-
-int main(int argc, char ** argv)
-{
-       transformation_h handle = NULL;
-       media_packet_h src;
-       int ret = IMAGE_UTIL_ERROR_NONE;
-
-       ret = image_util_create(&handle);
-       if(ret != IMAGE_UTIL_ERROR_NONE)
-       {
-               printf("[%d]error image_util_create [%d]\n", __LINE__, ret);
-       }
-
-       unsigned int width = 0;
-       unsigned int height = 0;
-       int colorspace = 0;
-       mm_util_img_rotate_type angle;
-       int start_x;
-       int start_y;
-       int end_x;
-       int end_y;
-       bool hardware_acceleration = FALSE;
-
-       ret = create_media_packet(&src);
-       if(ret == MM_ERROR_NONE) {
-               printf("Success - Create_media_packet");
-       } else {
-               printf("ERROR - Create_media_packet");
-               return ret;
-       }
-
-       ret = image_util_transform_set_hardware_acceleration(handle, hardware_acceleration);
-       if(ret != IMAGE_UTIL_ERROR_NONE)
-       {
-               printf("[%d]error image_util_set condition [%d]\n", __LINE__, ret);
-               return 0;
-       }
-
-       if (!strcmp("convert", argv[1])) {
-               colorspace = atoi(argv[2]);
-
-               ret = image_util_transform_set_colorspace(handle, colorspace);
-               if(ret != IMAGE_UTIL_ERROR_NONE)
-               {
-                       printf("[%d]error image_util_set colorspace [%d]\n", __LINE__, ret);
-                       return 0;
-               }
-       }
-
-       if (!strcmp("resize", argv[1])) {
-               width = atoi(argv[2]);
-               height = atoi(argv[3]);
-
-               ret = image_util_transform_set_resolution(handle, width, height);
-               if(ret != IMAGE_UTIL_ERROR_NONE)
-               {
-                       printf("[%d]error image_util_set resolution [%d]\n", __LINE__, ret);
-                       return 0;
-               }
-       }
-
-       if (!strcmp("rotate", argv[1])) {
-               angle = atoi(argv[2]);
-
-               ret = image_util_transform_set_rotation(handle, angle);
-               if(ret != IMAGE_UTIL_ERROR_NONE)
-               {
-                       printf("[%d]error image_util_set colorspace [%d]\n", __LINE__, ret);
-                       return 0;
-               }
-       }
-
-       if (!strcmp("crop", argv[1])) {
-               start_x = atoi(argv[2]);
-               start_y = atoi(argv[3]);
-               end_x atoi(argv[4]);
-               end_y atoi(argv[5]);
-
-               ret = image_util_transform_set_crop_area(handle, start_x, start_y, end_x, end_y);
-               if(ret != IMAGE_UTIL_ERROR_NONE)
-               {
-                       printf("[%d]error image_util_set colorspace [%d]\n", __LINE__, ret);
-                       return 0;
-               }
-       }
-
-       ret = image_util_transform_run(handle, src, test_transform_completed_cb, handle);
-       if(ret != IMAGE_UTIL_ERROR_NONE)
-       {
-               printf("[%d]error image_util_transform [%d]\n", __LINE__, ret);
-       }
-
-       if(ret != IMAGE_UTIL_ERROR_NONE)
-               goto Exit;
-
-       g_loop = g_main_loop_new(NULL, FALSE);
-
-       g_main_loop_run(g_loop);
-       g_main_loop_unref(g_loop);
-
-Exit:
-       ret = image_util_destroy(handle);
-       if(ret != IMAGE_UTIL_ERROR_NONE)
-       {
-               printf("[%d]error image_util_destroy [%d]\n", __LINE__, ret);
-       }
-       else
-       {
-               printf("[%d]Success image_util_destroy [%d]\n", __LINE__, ret);
-       }
-
-       if(_util_s != NULL)
-               free(_util_s);
-
-       return 0;
-}