Modify common code like error converting, colorspace converting, those are reloacated... 08/150108/1 accepted/tizen/unified/20170918.093844 submit/tizen/20170915.084033
authorJiyong Min <jiyong.min@samsung.com>
Thu, 14 Sep 2017 09:03:05 +0000 (18:03 +0900)
committerJiyong Min <jiyong.min@samsung.com>
Thu, 14 Sep 2017 09:05:28 +0000 (18:05 +0900)
Change-Id: I6170289860793077e7713b5806d8655d8de563fd
Signed-off-by: Jiyong Min <jiyong.min@samsung.com>
include/image_util_private.h
packaging/capi-media-image-util.spec
src/image_util.c
src/image_util_internal.c
src/image_util_private.c [new file with mode: 0755]

index 07f3d13..c7a8f0d 100755 (executable)
@@ -77,6 +77,11 @@ extern "C"
 
 #define _NOT_SUPPORTED_COLORSPACE      (-1)
 
+#define TYPECAST_COLOR(c)                      convert_type_of_colorspace(c)
+#define TYPECAST_COLOR_BY_TYPE(c, t)   convert_type_of_colorspace_with_image_type(c, t)
+
+#define NUM_OF_COLORSPACE      get_number_of_colorspace()
+
 typedef gboolean(*ModuleFunc)(void *, int, int, unsigned char *, unsigned char *, unsigned char *);
 
 typedef struct {
@@ -147,6 +152,17 @@ typedef struct {
        void *frame_h;
 } frame_s;
 
+gboolean is_valid_colorspace(image_util_colorspace_e colorspace);
+gboolean is_supported_colorspace(image_util_colorspace_e colorspace, image_util_type_e type);
+
+unsigned int get_number_of_colorspace(void);
+int convert_type_of_colorspace(const image_util_colorspace_e colorspace);
+int convert_type_of_colorspace_with_image_type(const image_util_colorspace_e colorspace, const image_util_type_e type);
+
+int _convert_image_util_error_code(const char *func, int code);
+image_util_error_e _image_util_error_convert(int error);
+bool _image_util_check_resolution(int width, int height);
+
 /**
 * @}
 */
index dcbb97b..1b53bc7 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       capi-media-image-util
 Summary:    A Image Utility library in Tizen Native API
-Version:    0.1.25
+Version:    0.1.26
 Release:    2
 Group:      Multimedia/API
 License:    Apache-2.0
index a86a3c3..4484181 100755 (executable)
 #include <stdio.h>
 #include <stdlib.h>
 
-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_I420,           /* IMAGE_UTIL_COLORSPACE_I420 */
-       MM_UTIL_IMG_FMT_NV12,           /* IMAGE_UTIL_COLORSPACE_NV12 */
-       MM_UTIL_IMG_FMT_UYVY,           /* IMAGE_UTIL_COLORSPACE_UYVY */
-       MM_UTIL_IMG_FMT_YUYV,           /* IMAGE_UTIL_COLORSPACE_YUYV */
-       MM_UTIL_IMG_FMT_RGB565,         /* IMAGE_UTIL_COLORSPACE_RGB565 */
-       MM_UTIL_IMG_FMT_RGB888,         /* IMAGE_UTIL_COLORSPACE_RGB888 */
-       MM_UTIL_IMG_FMT_ARGB8888,       /* IMAGE_UTIL_COLORSPACE_ARGB8888 */
-       MM_UTIL_IMG_FMT_BGRA8888,       /* IMAGE_UTIL_COLORSPACE_BGRA8888 */
-       MM_UTIL_IMG_FMT_RGBA8888,       /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
-       MM_UTIL_IMG_FMT_BGRX8888,       /* IMAGE_UTIL_COLORSPACE_BGRX8888 */
-       MM_UTIL_JPEG_FMT_NV21,          /* IMAGE_UTIL_COLORSPACE_NV12 */
-       MM_UTIL_JPEG_FMT_NV16,          /* IMAGE_UTIL_COLORSPACE_NV16 */
-       MM_UTIL_JPEG_FMT_NV61,          /* IMAGE_UTIL_COLORSPACE_NV61 */
-};
-
-static int _convert_jpeg_colorspace_tbl[] = {
-       MM_UTIL_JPEG_FMT_YUV420,        /* IMAGE_UTIL_COLORSPACE_YUV420 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_YUV422 */
-       MM_UTIL_JPEG_FMT_YUV420,        /* IMAGE_UTIL_COLORSPACE_I420 */
-       MM_UTIL_JPEG_FMT_NV12,          /* IMAGE_UTIL_COLORSPACE_NV12 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_UYVY */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_YUYV */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_RGB565 */
-       MM_UTIL_JPEG_FMT_RGB888,        /* IMAGE_UTIL_COLORSPACE_RGB888 */
-       MM_UTIL_JPEG_FMT_ARGB8888,      /* IMAGE_UTIL_COLORSPACE_ARGB8888 */
-       MM_UTIL_JPEG_FMT_BGRA8888,      /* IMAGE_UTIL_COLORSPACE_BGRA8888 */
-       MM_UTIL_JPEG_FMT_RGBA8888,      /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_BGRX8888 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV21 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV16 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV61 */
-};
-
-static int _convert_png_colorspace_tbl[] = {
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_YUV420 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_YUV422 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_I420 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV12 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_UYVY */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_YUYV */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_RGB565 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_RGB888 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_ARGB8888 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_BGRA8888 */
-       MM_UTIL_PNG_COLOR_TYPE_RGB_ALPHA,       /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_BGRX8888 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV21 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV16 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV61 */
-};
-
-static int _convert_gif_colorspace_tbl[] = {
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_YUV420 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_YUV422 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_I420 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV12 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_UYVY */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_YUYV */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_RGB565 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_RGB888 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_ARGB8888 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_BGRA8888 */
-       MM_UTIL_GIF_FMT_RGBA8888,               /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_BGRX8888 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV21 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV16 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV61 */
-};
-
-static int _convert_bmp_colorspace_tbl[] = {
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_YUV420 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_YUV422 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_I420 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV12 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_UYVY */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_YUYV */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_RGB565 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_RGB888 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_ARGB8888 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_BGRA8888 */
-       MM_UTIL_BMP_FMT_RGBA8888,       /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_BGRX8888 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV21 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV16 */
-       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV61 */
-};
-
 static int _convert_decode_scale_tbl[] = {
        MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1,
        MM_UTIL_JPEG_DECODE_DOWNSCALE_1_2,
@@ -123,69 +33,8 @@ static int _convert_decode_scale_tbl[] = {
        MM_UTIL_JPEG_DECODE_DOWNSCALE_1_8,
 };
 
-#define _NUM_OF_COLORSPACE                     (sizeof(_convert_colorspace_tbl)/sizeof(int))
 #define _NUM_OF_SCALE                  (sizeof(_convert_decode_scale_tbl)/sizeof(int))
 
-static int _convert_image_util_error_code(const char *func, int code)
-{
-       int ret = IMAGE_UTIL_ERROR_INVALID_OPERATION;
-       char *errorstr = NULL;
-       switch (code) {
-       case MM_UTIL_ERROR_NONE:
-               ret = IMAGE_UTIL_ERROR_NONE;
-               errorstr = strdup("ERROR_NONE");
-               break;
-       case MM_UTIL_ERROR_NO_SUCH_FILE:
-               ret = IMAGE_UTIL_ERROR_NO_SUCH_FILE;
-               errorstr = strdup("NO_SUCH_FILE");
-               break;
-       case MM_UTIL_ERROR_INVALID_PARAMETER:
-               ret = IMAGE_UTIL_ERROR_INVALID_PARAMETER;
-               errorstr = strdup("INVALID_PARAMETER");
-               break;
-       case MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT:
-               ret = IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
-               errorstr = strdup("NOT_SUPPORTED_FORMAT");
-               break;
-       case MM_UTIL_ERROR_OUT_OF_MEMORY:
-               ret = IMAGE_UTIL_ERROR_OUT_OF_MEMORY;
-               errorstr = strdup("OUT_OF_MEMORY");
-               break;
-       case MM_UTIL_ERROR_INVALID_OPERATION:
-       default:
-               ret = IMAGE_UTIL_ERROR_INVALID_OPERATION;
-               errorstr = strdup("INVALID_OPERATION");
-
-       }
-
-       image_util_debug("[%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)
-{
-       switch (error) {
-       case MM_UTIL_ERROR_NONE:
-               image_util_debug("Error None");
-               return IMAGE_UTIL_ERROR_NONE;
-       case MM_UTIL_ERROR_INVALID_PARAMETER:
-               image_util_error("INVALID_PARAMETER(0x%08x)", IMAGE_UTIL_ERROR_INVALID_PARAMETER);
-               return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
-       case MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT:
-               image_util_error("NOT_SUPPORTED_FORMAT(0x%08x)", IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT);
-               return IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
-       case MM_UTIL_ERROR_OUT_OF_MEMORY:
-               image_util_error("OUT_OF_MEMORY(0x%08x)", IMAGE_UTIL_ERROR_OUT_OF_MEMORY);
-               return IMAGE_UTIL_ERROR_OUT_OF_MEMORY;
-               break;
-       case MM_UTIL_ERROR_INVALID_OPERATION:
-       default:
-               image_util_error("INVALID_OPERATION(0x%08x)", error);
-               return IMAGE_UTIL_ERROR_INVALID_OPERATION;
-       }
-}
-
 static void _image_util_transform_completed_cb(media_packet_h * dst, int error, void *user_data)
 {
        int error_value = IMAGE_UTIL_ERROR_NONE;
@@ -215,61 +64,17 @@ static int _image_util_create_transform_handle(transformation_s * handle)
        return _convert_image_util_error_code(__func__, err);
 }
 
-static bool _image_util_check_resolution(int width, int height)
-{
-       if (width <= 0) {
-               image_util_error("invalid width [%d]", width);
-               return false;
-       }
-
-       if (height <= 0) {
-               image_util_error("invalid height [%d]", height);
-               return false;
-       }
-
-       return true;
-}
-
-static gboolean _is_valid_colorspace(image_util_colorspace_e colorspace)
-{
-       if (colorspace < 0 || colorspace >= _NUM_OF_COLORSPACE)
-               return FALSE;
-
-       return TRUE;
-}
-
-static gboolean _is_supported_colorspace(image_util_colorspace_e colorspace, image_util_type_e type)
-{
-       switch (type) {
-       case IMAGE_UTIL_JPEG:
-               image_util_retvm_if((_convert_jpeg_colorspace_tbl[colorspace] == _NOT_SUPPORTED_COLORSPACE), FALSE, "[jpeg] %d not supported format", colorspace);
-               break;
-       case IMAGE_UTIL_PNG:
-               image_util_retvm_if((_convert_png_colorspace_tbl[colorspace] == _NOT_SUPPORTED_COLORSPACE), FALSE, "[png] %d not supported format", colorspace);
-               break;
-       case IMAGE_UTIL_GIF:
-               image_util_retvm_if((_convert_gif_colorspace_tbl[colorspace] == _NOT_SUPPORTED_COLORSPACE), FALSE, "[gif] %d not supported format", colorspace);
-               break;
-       case IMAGE_UTIL_BMP:
-               image_util_retvm_if((_convert_bmp_colorspace_tbl[colorspace] == _NOT_SUPPORTED_COLORSPACE), FALSE, "[bmp] %d not supported format", colorspace);
-               break;
-       default:
-               image_util_retvm_if((_convert_bmp_colorspace_tbl[colorspace] == _NOT_SUPPORTED_COLORSPACE), FALSE, "Invalid image type");
-       }
-       return TRUE;
-}
-
 int image_util_foreach_supported_jpeg_colorspace(image_util_supported_jpeg_colorspace_cb callback, void *user_data)
 {
-       int idx = _NOT_SUPPORTED_COLORSPACE;
+       int idx = 0;
 
        DEPRECATION_LOGW("image_util_foreach_supported_jpeg_colorspace()", "image_util_foreach_supported_colorspace()");
 
        image_util_retvm_if((callback == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "callback is null");
 
        /* RGB has higher precedence than YUV */
-       for (idx = _NUM_OF_COLORSPACE - 1; idx >= 0; idx--) {
-               if (_is_supported_colorspace(idx, IMAGE_UTIL_JPEG))
+       for (idx = (int)(NUM_OF_COLORSPACE - 1); idx >= 0; idx--) {
+               if (is_supported_colorspace(idx, IMAGE_UTIL_JPEG))
                        if (false == callback(idx, user_data))
                                return IMAGE_UTIL_ERROR_NONE;
 
@@ -586,92 +391,15 @@ int image_util_transform_destroy(transformation_h handle)
        return _convert_image_util_error_code(__func__, err);
 }
 
-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 err = MM_UTIL_ERROR_NONE;
-
-       image_util_retvm_if((dest == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "dest is null");
-       image_util_retvm_if((src == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "src is null");
-       image_util_retvm_if((_is_valid_colorspace(dest_colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid dst_colorspace");
-       image_util_retvm_if((_is_valid_colorspace(src_colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid src_colorspace");
-
-       err = 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__, err);
-}
-
 int image_util_calculate_buffer_size(int width, int height, image_util_colorspace_e colorspace, unsigned int *size)
 {
        int err = MM_UTIL_ERROR_NONE;
 
-       image_util_retvm_if((_is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
+       image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
        image_util_retvm_if((width <= 0 || height <= 0), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid width or Invalid height");
        image_util_retvm_if((size == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "size is null");
 
-       err = mm_util_get_image_size(_convert_colorspace_tbl[colorspace], width, height, size);
-       return _convert_image_util_error_code(__func__, err);
-}
-
-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 err = MM_UTIL_ERROR_NONE;
-
-       image_util_retvm_if((dest == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "dest is null");
-       image_util_retvm_if((src == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "src is null");
-       image_util_retvm_if((_is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
-       image_util_retvm_if((dest_width == NULL || dest_height == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "dest_width or dest_height is null");
-       image_util_retvm_if((*dest_width <= 0 || *dest_height <= 0), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid dest_width or Invalid dest_height");
-
-       unsigned int dest_w, dest_h;
-       dest_w = *dest_width;
-       dest_h = *dest_height;
-       err = mm_util_resize_image(src, src_width, src_height, _convert_colorspace_tbl[colorspace], dest, &dest_w, &dest_h);
-       if (err == MM_UTIL_ERROR_NONE) {
-               *dest_width = (int)dest_w;
-               *dest_height = (int)dest_h;
-       }
-
-       return _convert_image_util_error_code(__func__, err);
-}
-
-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 err = MM_UTIL_ERROR_NONE;
-
-       image_util_retvm_if((dest == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "dest is null");
-       image_util_retvm_if((src == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "src is null");
-       image_util_retvm_if((_is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
-       image_util_retvm_if((dest_rotation < 0 || dest_rotation > IMAGE_UTIL_ROTATION_FLIP_VERT), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid rotation");
-       image_util_retvm_if((dest_width == NULL || dest_height == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "dest_width or dest_height is null");
-
-       unsigned int dest_w, dest_h;
-       err = mm_util_rotate_image(src, src_width, src_height, _convert_colorspace_tbl[colorspace], dest, &dest_w, &dest_h, dest_rotation);
-       if (err == MM_UTIL_ERROR_NONE) {
-               *dest_width = (int)dest_w;
-               *dest_height = (int)dest_h;
-       }
-       return _convert_image_util_error_code(__func__, err);
-}
-
-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 err = MM_UTIL_ERROR_NONE;
-
-       image_util_retvm_if((dest == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "dest is null");
-       image_util_retvm_if((src == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "src is null");
-       image_util_retvm_if((_is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
-       image_util_retvm_if((width == NULL || height == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "width or height is null");
-       image_util_retvm_if((src_width <= x || src_height <= y || src_width < x + *width || src_height < y + *height), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid crop area");
-
-       unsigned int dest_w, dest_h;
-       dest_w = *width;
-       dest_h = *height;
-       err = mm_util_crop_image(src, src_width, src_height, _convert_colorspace_tbl[colorspace], x, y, &dest_w, &dest_h, dest);
-       if (err == MM_UTIL_ERROR_NONE) {
-               *width = (int)dest_w;
-               *height = (int)dest_h;
-       }
-
+       err = mm_util_get_image_size(TYPECAST_COLOR(colorspace), width, height, size);
        return _convert_image_util_error_code(__func__, err);
 }
 
@@ -685,13 +413,13 @@ int image_util_decode_jpeg(const char *path, image_util_colorspace_e colorspace,
        image_util_retvm_if((image_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "image_buffer is null");
        image_util_retvm_if((size == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "size is null");
        image_util_retvm_if((strlen(path) == 0), IMAGE_UTIL_ERROR_NO_SUCH_FILE, "Invalid path");
-       image_util_retvm_if((_is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
-       image_util_retvm_if((_is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
+       image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
+       image_util_retvm_if((is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
 
        mm_util_jpeg_yuv_data decoded;
        memset(&decoded, 0, sizeof(mm_util_jpeg_yuv_data));
 
-       err = mm_util_decode_from_jpeg_file(&decoded, path, _convert_jpeg_colorspace_tbl[colorspace]);
+       err = mm_util_decode_from_jpeg_file(&decoded, path, TYPECAST_COLOR_BY_TYPE(colorspace, IMAGE_UTIL_JPEG));
        if (err == MM_UTIL_ERROR_NONE) {
                *image_buffer = decoded.data;
                if (width)
@@ -713,13 +441,13 @@ int image_util_decode_jpeg_from_memory(const unsigned char *jpeg_buffer, int jpe
        image_util_retvm_if((jpeg_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "jpeg_buffer is null");
        image_util_retvm_if((image_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "image_buffer is null");
        image_util_retvm_if((size == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "size is null");
-       image_util_retvm_if((_is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
-       image_util_retvm_if((_is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
+       image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
+       image_util_retvm_if((is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
 
        mm_util_jpeg_yuv_data decoded;
        memset(&decoded, 0, sizeof(mm_util_jpeg_yuv_data));
 
-       err = mm_util_decode_from_jpeg_memory(&decoded, (void *)jpeg_buffer, (unsigned int)jpeg_size, _convert_jpeg_colorspace_tbl[colorspace]);
+       err = mm_util_decode_from_jpeg_memory(&decoded, (void *)jpeg_buffer, (unsigned int)jpeg_size, TYPECAST_COLOR_BY_TYPE(colorspace, IMAGE_UTIL_JPEG));
 
        if (err == MM_UTIL_ERROR_NONE) {
                *image_buffer = decoded.data;
@@ -744,14 +472,14 @@ int image_util_decode_jpeg_with_downscale(const char *path, image_util_colorspac
        image_util_retvm_if((image_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "image_buffer is null");
        image_util_retvm_if((size == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "size is null");
        image_util_retvm_if((strlen(path) == 0), IMAGE_UTIL_ERROR_NO_SUCH_FILE, "Invalid path");
-       image_util_retvm_if((_is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
-       image_util_retvm_if((_is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
+       image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
+       image_util_retvm_if((is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
        image_util_retvm_if((downscale < 0 || downscale >= _NUM_OF_SCALE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "downsacle is invalid");
 
        mm_util_jpeg_yuv_data decoded;
        memset(&decoded, 0, sizeof(mm_util_jpeg_yuv_data));
 
-       err = mm_util_decode_from_jpeg_file_with_downscale(&decoded, path, _convert_jpeg_colorspace_tbl[colorspace], _convert_decode_scale_tbl[downscale]);
+       err = mm_util_decode_from_jpeg_file_with_downscale(&decoded, path, TYPECAST_COLOR_BY_TYPE(colorspace, IMAGE_UTIL_JPEG), _convert_decode_scale_tbl[downscale]);
        if (err == MM_UTIL_ERROR_NONE) {
                *image_buffer = decoded.data;
                if (width)
@@ -773,14 +501,14 @@ int image_util_decode_jpeg_from_memory_with_downscale(const unsigned char *jpeg_
        image_util_retvm_if((jpeg_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "jpeg_buffer is null");
        image_util_retvm_if((image_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "image_buffer is null");
        image_util_retvm_if((size == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "size is null");
-       image_util_retvm_if((_is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
-       image_util_retvm_if((_is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
+       image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
+       image_util_retvm_if((is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
        image_util_retvm_if((downscale < 0 || downscale >= _NUM_OF_SCALE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "downsacle is invalid");
 
        mm_util_jpeg_yuv_data decoded;
        memset(&decoded, 0, sizeof(mm_util_jpeg_yuv_data));
 
-       err = mm_util_decode_from_jpeg_memory_with_downscale(&decoded, (void *)jpeg_buffer, (unsigned int)jpeg_size, _convert_jpeg_colorspace_tbl[colorspace], _convert_decode_scale_tbl[downscale]);
+       err = mm_util_decode_from_jpeg_memory_with_downscale(&decoded, (void *)jpeg_buffer, (unsigned int)jpeg_size, TYPECAST_COLOR_BY_TYPE(colorspace, IMAGE_UTIL_JPEG), _convert_decode_scale_tbl[downscale]);
 
        if (err == MM_UTIL_ERROR_NONE) {
                *image_buffer = decoded.data;
@@ -804,10 +532,10 @@ int image_util_encode_jpeg(const unsigned char *buffer, int width, int height, i
        image_util_retvm_if((path == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "path is null");
        image_util_retvm_if((buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "buffer is null");
        image_util_retvm_if((strlen(path) == 0), IMAGE_UTIL_ERROR_NO_SUCH_FILE, "Invalid path");
-       image_util_retvm_if((_is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
-       image_util_retvm_if((_is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
+       image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
+       image_util_retvm_if((is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
 
-       err = mm_util_jpeg_encode_to_file(path, (void *)buffer, width, height, _convert_jpeg_colorspace_tbl[colorspace], quality);
+       err = mm_util_jpeg_encode_to_file(path, (void *)buffer, width, height, TYPECAST_COLOR_BY_TYPE(colorspace, IMAGE_UTIL_JPEG), quality);
        return _convert_image_util_error_code(__func__, err);
 }
 
@@ -820,10 +548,10 @@ int image_util_encode_jpeg_to_memory(const unsigned char *image_buffer, int widt
        image_util_retvm_if((jpeg_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "jpeg_buffer is null");
        image_util_retvm_if((image_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "image_buffer is null");
        image_util_retvm_if((jpeg_size == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "jpeg_size is null");
-       image_util_retvm_if((_is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
-       image_util_retvm_if((_is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
+       image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
+       image_util_retvm_if((is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
 
-       err = mm_util_jpeg_encode_to_memory((void **)jpeg_buffer, jpeg_size, (void *)image_buffer, width, height, _convert_jpeg_colorspace_tbl[colorspace], quality);
+       err = mm_util_jpeg_encode_to_memory((void **)jpeg_buffer, jpeg_size, (void *)image_buffer, width, height, TYPECAST_COLOR_BY_TYPE(colorspace, IMAGE_UTIL_JPEG), quality);
        return _convert_image_util_error_code(__func__, err);
 }
 
@@ -861,14 +589,14 @@ int image_util_extract_color_from_memory(const unsigned char *image_buffer, int
 
 int image_util_foreach_supported_colorspace(image_util_type_e image_type, image_util_supported_colorspace_cb callback, void *user_data)
 {
-       int idx = _NOT_SUPPORTED_COLORSPACE;
+       int idx = 0;
 
        image_util_retvm_if((callback == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "callback is null");
 
        if ((image_type == IMAGE_UTIL_JPEG) || (image_type == IMAGE_UTIL_PNG)
                || (image_type == IMAGE_UTIL_GIF) || (image_type == IMAGE_UTIL_BMP)) {
-               for (idx = _NUM_OF_COLORSPACE - 1; idx >= 0; idx--) {
-                       if (_is_supported_colorspace(idx, image_type))
+               for (idx = (int)(NUM_OF_COLORSPACE - 1); idx >= 0; idx--) {
+                       if (is_supported_colorspace(idx, image_type))
                                if (false == callback(idx, user_data))
                                        return IMAGE_UTIL_ERROR_NONE;
 
@@ -1175,10 +903,10 @@ int image_util_decode_set_colorspace(image_util_encode_h handle, image_util_colo
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
        }
 
-       image_util_retvm_if((_is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
+       image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
        if ((_handle->image_type == IMAGE_UTIL_JPEG) || (_handle->image_type == IMAGE_UTIL_PNG)
                || (_handle->image_type == IMAGE_UTIL_GIF) || (_handle->image_type == IMAGE_UTIL_BMP)) {
-               image_util_retvm_if((_is_supported_colorspace(colorspace, _handle->image_type) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
+               image_util_retvm_if((is_supported_colorspace(colorspace, _handle->image_type) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
        } else {
                image_util_error("Invalid image type");
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
@@ -1226,14 +954,14 @@ static int _image_util_decode_internal(decode_encode_s * _handle)
 
                        if (_handle->path) {
                                if (_handle->down_scale < sizeof(image_util_scale_e))
-                                       err = mm_util_decode_from_jpeg_file_with_downscale(jpeg_data, _handle->path, _convert_jpeg_colorspace_tbl[_handle->colorspace], _convert_decode_scale_tbl[_handle->down_scale]);
+                                       err = mm_util_decode_from_jpeg_file_with_downscale(jpeg_data, _handle->path, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_JPEG), _convert_decode_scale_tbl[_handle->down_scale]);
                                else
-                                       err = mm_util_decode_from_jpeg_file(jpeg_data, _handle->path, _convert_jpeg_colorspace_tbl[_handle->colorspace]);
+                                       err = mm_util_decode_from_jpeg_file(jpeg_data, _handle->path, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_JPEG));
                        } else {
                                if (_handle->down_scale < sizeof(image_util_scale_e))
-                                       err = mm_util_decode_from_jpeg_memory_with_downscale(jpeg_data, _handle->src_buffer[0], (unsigned int)_handle->src_size, _convert_jpeg_colorspace_tbl[_handle->colorspace], _convert_decode_scale_tbl[_handle->down_scale]);
+                                       err = mm_util_decode_from_jpeg_memory_with_downscale(jpeg_data, _handle->src_buffer[0], (unsigned int)_handle->src_size, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_JPEG), _convert_decode_scale_tbl[_handle->down_scale]);
                                else
-                                       err = mm_util_decode_from_jpeg_memory(jpeg_data, _handle->src_buffer[0], (unsigned int)_handle->src_size, _convert_jpeg_colorspace_tbl[_handle->colorspace]);
+                                       err = mm_util_decode_from_jpeg_memory(jpeg_data, _handle->src_buffer[0], (unsigned int)_handle->src_size, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_JPEG));
                        }
 
                        if (err == MM_UTIL_ERROR_NONE) {
@@ -1710,11 +1438,11 @@ int image_util_encode_set_colorspace(image_util_encode_h handle, image_util_colo
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
        }
 
-       image_util_retvm_if((_is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
+       image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
 
        if ((_handle->image_type == IMAGE_UTIL_JPEG) || (_handle->image_type == IMAGE_UTIL_PNG)
                || (_handle->image_type == IMAGE_UTIL_GIF) || (_handle->image_type == IMAGE_UTIL_BMP)) {
-               image_util_retvm_if((_is_supported_colorspace(colorspace, _handle->image_type) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
+               image_util_retvm_if((is_supported_colorspace(colorspace, _handle->image_type) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
        } else {
                image_util_error("Invalid image type");
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
@@ -1905,9 +1633,9 @@ static int _image_util_encode_internal(decode_encode_s * _handle)
        case IMAGE_UTIL_JPEG:
                {
                        if (_handle->path)
-                               err = mm_util_jpeg_encode_to_file(_handle->path, _handle->src_buffer[0], _handle->width, _handle->height, _convert_jpeg_colorspace_tbl[_handle->colorspace], _handle->quality);
+                               err = mm_util_jpeg_encode_to_file(_handle->path, _handle->src_buffer[0], _handle->width, _handle->height, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_JPEG), _handle->quality);
                        else
-                               err = mm_util_jpeg_encode_to_memory(_handle->dst_buffer, (unsigned int *)&(_handle->dst_size), _handle->src_buffer[0], _handle->width, _handle->height, _convert_jpeg_colorspace_tbl[_handle->colorspace], _handle->quality);
+                               err = mm_util_jpeg_encode_to_memory(_handle->dst_buffer, (unsigned int *)&(_handle->dst_size), _handle->src_buffer[0], _handle->width, _handle->height, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_JPEG), _handle->quality);
                }
                break;
        case IMAGE_UTIL_PNG:
index e8502ad..50afd42 100755 (executable)
 
 #include <mm_util_gif.h>
 
+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 err = MM_UTIL_ERROR_NONE;
+
+       image_util_retvm_if((dest == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "dest is null");
+       image_util_retvm_if((src == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "src is null");
+       image_util_retvm_if((is_valid_colorspace(dest_colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid dst_colorspace");
+       image_util_retvm_if((is_valid_colorspace(src_colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid src_colorspace");
+
+       err = mm_util_convert_colorspace(src, width, height, TYPECAST_COLOR(src_colorspace), dest, TYPECAST_COLOR(dest_colorspace));
+
+       return _convert_image_util_error_code(__func__, err);
+}
+
+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 err = MM_UTIL_ERROR_NONE;
+
+       image_util_retvm_if((dest == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "dest is null");
+       image_util_retvm_if((src == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "src is null");
+       image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
+       image_util_retvm_if((dest_width == NULL || dest_height == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "dest_width or dest_height is null");
+       image_util_retvm_if((*dest_width <= 0 || *dest_height <= 0), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid dest_width or Invalid dest_height");
+
+       unsigned int dest_w, dest_h;
+       dest_w = *dest_width;
+       dest_h = *dest_height;
+       err = mm_util_resize_image(src, src_width, src_height, TYPECAST_COLOR(colorspace), dest, &dest_w, &dest_h);
+       if (err == MM_UTIL_ERROR_NONE) {
+               *dest_width = (int)dest_w;
+               *dest_height = (int)dest_h;
+       }
+
+       return _convert_image_util_error_code(__func__, err);
+}
+
+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 err = MM_UTIL_ERROR_NONE;
+
+       image_util_retvm_if((dest == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "dest is null");
+       image_util_retvm_if((src == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "src is null");
+       image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
+       image_util_retvm_if((dest_rotation < 0 || dest_rotation > IMAGE_UTIL_ROTATION_FLIP_VERT), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid rotation");
+       image_util_retvm_if((dest_width == NULL || dest_height == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "dest_width or dest_height is null");
+
+       unsigned int dest_w, dest_h;
+       err = mm_util_rotate_image(src, src_width, src_height, TYPECAST_COLOR(colorspace), dest, &dest_w, &dest_h, dest_rotation);
+       if (err == MM_UTIL_ERROR_NONE) {
+               *dest_width = (int)dest_w;
+               *dest_height = (int)dest_h;
+       }
+       return _convert_image_util_error_code(__func__, err);
+}
+
+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 err = MM_UTIL_ERROR_NONE;
+
+       image_util_retvm_if((dest == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "dest is null");
+       image_util_retvm_if((src == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "src is null");
+       image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
+       image_util_retvm_if((width == NULL || height == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "width or height is null");
+       image_util_retvm_if((src_width <= x || src_height <= y || src_width < x + *width || src_height < y + *height), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid crop area");
+
+       unsigned int dest_w, dest_h;
+       dest_w = *width;
+       dest_h = *height;
+       err = mm_util_crop_image(src, src_width, src_height, TYPECAST_COLOR(colorspace), x, y, &dest_w, &dest_h, dest);
+       if (err == MM_UTIL_ERROR_NONE) {
+               *width = (int)dest_w;
+               *height = (int)dest_h;
+       }
+
+       return _convert_image_util_error_code(__func__, err);
+}
+
 int image_util_frame_create(void *decode_encode_h, image_util_frame_h *frame_h)
 {
        int ret = IMAGE_UTIL_ERROR_NONE;
diff --git a/src/image_util_private.c b/src/image_util_private.c
new file mode 100755 (executable)
index 0000000..8433b85
--- /dev/null
@@ -0,0 +1,263 @@
+/*
+* 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_private.h>
+
+#include <mm_util_imgp.h>
+#include <mm_util_jpeg.h>
+#include <mm_util_png.h>
+#include <mm_util_gif.h>
+#include <mm_util_bmp.h>
+
+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_I420,           /* IMAGE_UTIL_COLORSPACE_I420 */
+       MM_UTIL_IMG_FMT_NV12,           /* IMAGE_UTIL_COLORSPACE_NV12 */
+       MM_UTIL_IMG_FMT_UYVY,           /* IMAGE_UTIL_COLORSPACE_UYVY */
+       MM_UTIL_IMG_FMT_YUYV,           /* IMAGE_UTIL_COLORSPACE_YUYV */
+       MM_UTIL_IMG_FMT_RGB565,         /* IMAGE_UTIL_COLORSPACE_RGB565 */
+       MM_UTIL_IMG_FMT_RGB888,         /* IMAGE_UTIL_COLORSPACE_RGB888 */
+       MM_UTIL_IMG_FMT_ARGB8888,       /* IMAGE_UTIL_COLORSPACE_ARGB8888 */
+       MM_UTIL_IMG_FMT_BGRA8888,       /* IMAGE_UTIL_COLORSPACE_BGRA8888 */
+       MM_UTIL_IMG_FMT_RGBA8888,       /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
+       MM_UTIL_IMG_FMT_BGRX8888,       /* IMAGE_UTIL_COLORSPACE_BGRX8888 */
+       MM_UTIL_JPEG_FMT_NV21,          /* IMAGE_UTIL_COLORSPACE_NV12 */
+       MM_UTIL_JPEG_FMT_NV16,          /* IMAGE_UTIL_COLORSPACE_NV16 */
+       MM_UTIL_JPEG_FMT_NV61,          /* IMAGE_UTIL_COLORSPACE_NV61 */
+};
+
+static int _convert_jpeg_colorspace_tbl[] = {
+       MM_UTIL_JPEG_FMT_YUV420,        /* IMAGE_UTIL_COLORSPACE_YUV420 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_YUV422 */
+       MM_UTIL_JPEG_FMT_YUV420,        /* IMAGE_UTIL_COLORSPACE_I420 */
+       MM_UTIL_JPEG_FMT_NV12,          /* IMAGE_UTIL_COLORSPACE_NV12 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_UYVY */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_YUYV */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_RGB565 */
+       MM_UTIL_JPEG_FMT_RGB888,        /* IMAGE_UTIL_COLORSPACE_RGB888 */
+       MM_UTIL_JPEG_FMT_ARGB8888,      /* IMAGE_UTIL_COLORSPACE_ARGB8888 */
+       MM_UTIL_JPEG_FMT_BGRA8888,      /* IMAGE_UTIL_COLORSPACE_BGRA8888 */
+       MM_UTIL_JPEG_FMT_RGBA8888,      /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_BGRX8888 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV21 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV16 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV61 */
+};
+
+static int _convert_png_colorspace_tbl[] = {
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_YUV420 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_YUV422 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_I420 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV12 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_UYVY */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_YUYV */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_RGB565 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_RGB888 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_ARGB8888 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_BGRA8888 */
+       MM_UTIL_PNG_COLOR_TYPE_RGB_ALPHA,       /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_BGRX8888 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV21 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV16 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV61 */
+};
+
+static int _convert_gif_colorspace_tbl[] = {
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_YUV420 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_YUV422 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_I420 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV12 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_UYVY */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_YUYV */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_RGB565 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_RGB888 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_ARGB8888 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_BGRA8888 */
+       MM_UTIL_GIF_FMT_RGBA8888,               /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_BGRX8888 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV21 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV16 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV61 */
+};
+
+static int _convert_bmp_colorspace_tbl[] = {
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_YUV420 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_YUV422 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_I420 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV12 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_UYVY */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_YUYV */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_RGB565 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_RGB888 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_ARGB8888 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_BGRA8888 */
+       MM_UTIL_BMP_FMT_RGBA8888,       /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_BGRX8888 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV21 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV16 */
+       _NOT_SUPPORTED_COLORSPACE,      /* IMAGE_UTIL_COLORSPACE_NV61 */
+};
+
+unsigned int get_number_of_colorspace(void)
+{
+       return (unsigned int)(sizeof(_convert_colorspace_tbl)/sizeof(int));
+}
+
+gboolean is_valid_colorspace(image_util_colorspace_e colorspace)
+{
+       if ((colorspace < IMAGE_UTIL_COLORSPACE_YV12) || (colorspace >= NUM_OF_COLORSPACE))
+               return FALSE;
+
+       return TRUE;
+}
+
+gboolean is_supported_colorspace(image_util_colorspace_e colorspace, image_util_type_e type)
+{
+       switch (type) {
+       case IMAGE_UTIL_JPEG:
+               image_util_retvm_if((_convert_jpeg_colorspace_tbl[colorspace] == _NOT_SUPPORTED_COLORSPACE), FALSE, "[jpeg] %d not supported format", colorspace);
+               break;
+       case IMAGE_UTIL_PNG:
+               image_util_retvm_if((_convert_png_colorspace_tbl[colorspace] == _NOT_SUPPORTED_COLORSPACE), FALSE, "[png] %d not supported format", colorspace);
+               break;
+       case IMAGE_UTIL_GIF:
+               image_util_retvm_if((_convert_gif_colorspace_tbl[colorspace] == _NOT_SUPPORTED_COLORSPACE), FALSE, "[gif] %d not supported format", colorspace);
+               break;
+       case IMAGE_UTIL_BMP:
+               image_util_retvm_if((_convert_bmp_colorspace_tbl[colorspace] == _NOT_SUPPORTED_COLORSPACE), FALSE, "[bmp] %d not supported format", colorspace);
+               break;
+       default:
+               image_util_retvm_if(TRUE, FALSE, "Invalid image type");
+       }
+       return TRUE;
+}
+
+int convert_type_of_colorspace(const image_util_colorspace_e colorspace)
+{
+       if (is_valid_colorspace(colorspace) == FALSE) {
+               return _NOT_SUPPORTED_COLORSPACE;
+       }
+
+       return _convert_colorspace_tbl[colorspace];
+}
+
+int convert_type_of_colorspace_with_image_type(const image_util_colorspace_e colorspace, const image_util_type_e type)
+{
+       int new_colorspace = _NOT_SUPPORTED_COLORSPACE;
+
+       if (is_valid_colorspace(colorspace) == FALSE) {
+               return _NOT_SUPPORTED_COLORSPACE;
+       }
+
+       if (is_supported_colorspace(colorspace, type) == FALSE) {
+               return _NOT_SUPPORTED_COLORSPACE;
+       }
+
+       switch (type) {
+       case IMAGE_UTIL_JPEG:
+               new_colorspace = _convert_jpeg_colorspace_tbl[colorspace];
+               break;
+       case IMAGE_UTIL_PNG:
+               new_colorspace = _convert_png_colorspace_tbl[colorspace];
+               break;
+       case IMAGE_UTIL_GIF:
+               new_colorspace = _convert_gif_colorspace_tbl[colorspace];
+               break;
+       case IMAGE_UTIL_BMP:
+               new_colorspace = _convert_bmp_colorspace_tbl[colorspace];
+               break;
+       default:
+               image_util_error("Invalid image type");
+       }
+
+       return new_colorspace;
+}
+
+int _convert_image_util_error_code(const char *func, int code)
+{
+       int ret = IMAGE_UTIL_ERROR_INVALID_OPERATION;
+       char *errorstr = NULL;
+       switch (code) {
+       case MM_UTIL_ERROR_NONE:
+               ret = IMAGE_UTIL_ERROR_NONE;
+               errorstr = strdup("ERROR_NONE");
+               break;
+       case MM_UTIL_ERROR_NO_SUCH_FILE:
+               ret = IMAGE_UTIL_ERROR_NO_SUCH_FILE;
+               errorstr = strdup("NO_SUCH_FILE");
+               break;
+       case MM_UTIL_ERROR_INVALID_PARAMETER:
+               ret = IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+               errorstr = strdup("INVALID_PARAMETER");
+               break;
+       case MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT:
+               ret = IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
+               errorstr = strdup("NOT_SUPPORTED_FORMAT");
+               break;
+       case MM_UTIL_ERROR_OUT_OF_MEMORY:
+               ret = IMAGE_UTIL_ERROR_OUT_OF_MEMORY;
+               errorstr = strdup("OUT_OF_MEMORY");
+               break;
+       case MM_UTIL_ERROR_INVALID_OPERATION:
+       default:
+               ret = IMAGE_UTIL_ERROR_INVALID_OPERATION;
+               errorstr = strdup("INVALID_OPERATION");
+
+       }
+
+       image_util_debug("[%s] %s(0x%08x)", func, errorstr, ret);
+       IMAGE_UTIL_SAFE_FREE(errorstr);
+       return ret;
+}
+
+image_util_error_e _image_util_error_convert(int error)
+{
+       switch (error) {
+       case MM_UTIL_ERROR_NONE:
+               image_util_debug("Error None");
+               return IMAGE_UTIL_ERROR_NONE;
+       case MM_UTIL_ERROR_INVALID_PARAMETER:
+               image_util_error("INVALID_PARAMETER(0x%08x)", IMAGE_UTIL_ERROR_INVALID_PARAMETER);
+               return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+       case MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT:
+               image_util_error("NOT_SUPPORTED_FORMAT(0x%08x)", IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT);
+               return IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
+       case MM_UTIL_ERROR_OUT_OF_MEMORY:
+               image_util_error("OUT_OF_MEMORY(0x%08x)", IMAGE_UTIL_ERROR_OUT_OF_MEMORY);
+               return IMAGE_UTIL_ERROR_OUT_OF_MEMORY;
+               break;
+       case MM_UTIL_ERROR_INVALID_OPERATION:
+       default:
+               image_util_error("INVALID_OPERATION(0x%08x)", error);
+               return IMAGE_UTIL_ERROR_INVALID_OPERATION;
+       }
+}
+
+bool _image_util_check_resolution(int width, int height)
+{
+       if (width <= 0) {
+               image_util_error("invalid width [%d]", width);
+               return false;
+       }
+
+       if (height <= 0) {
+               image_util_error("invalid height [%d]", height);
+               return false;
+       }
+
+       return true;
+}