Refactoring: Integrate redundant checking the parameter and error handling 15/276915/13
authorjiyong.min <jiyong.min@samsung.com>
Tue, 28 Jun 2022 01:55:42 +0000 (10:55 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Mon, 4 Jul 2022 06:00:21 +0000 (15:00 +0900)
 - Checking the parameter has been repeated at several functions.
   So it was moved to check in the internal function before actually used.

Change-Id: Ia184d5b651cabebd1b3f2d5f55cde8f92817bee0

magick/mm_util_magick.c

index 50d7d58c71ce5e3064b0d7606dc3370916fd83a8..bfbe926d0c954bc9085a4d5bd21af19561be9640 100644 (file)
@@ -28,6 +28,7 @@
 #include "mm_util_private.h"
 #include "mm_util_magick.h"
 
+
 static bool __mm_util_check_rotation(mm_util_rotate_type_e rotation);
 static void __mm_util_magick_fatal_error_handler(const ExceptionType excep, const char *reason, const char *message) MAGICK_FUNC_NORETURN;
 
@@ -119,8 +120,9 @@ static const char * __mm_util_get_map(mm_util_color_format_e format)
        }
 }
 
-static Image * __mm_util_constitute_image(mm_util_image_h handle)
+static int __mm_util_constitute_image(mm_util_image_h handle, Image **image)
 {
+       int ret = MM_UTIL_ERROR_NONE;
        mm_image_info_s *_handle = (mm_image_info_s*)handle;
        const char *map = NULL;
        Image *_image = NULL;
@@ -128,36 +130,43 @@ static Image * __mm_util_constitute_image(mm_util_image_h handle)
 
        mm_util_fenter();
 
-       mm_util_retvm_if(!handle, NULL, "invalid handle");
+       mm_util_retvm_if(!handle, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle");
+       mm_util_retvm_if(!image, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid image");
 
        map = __mm_util_get_map(_handle->color);
-       mm_util_retvm_if(!map, NULL, "fail to get map");
+       mm_util_retvm_if(!map, MM_UTIL_ERROR_INVALID_PARAMETER, "fail to get map");
 
        GetExceptionInfo(&exception);
 
        /* Read image from buffer */
        _image = ConstituteImage(_handle->width, _handle->height, map, CharPixel, _handle->data, &exception);
-       if (_image == NULL) {
+       if (_image) {
+               *image = _image;
+       } else {
                mm_util_error("Error: Getting Image failed.");
                if (exception.severity != UndefinedException)
                        CatchException(&exception);
+               ret = MM_UTIL_ERROR_INVALID_OPERATION;
        }
 
        DestroyExceptionInfo(&exception);
 
        mm_util_fleave();
 
-       return _image;
+       return ret;
 }
 
-static Image * __mm_util_rotate_image(Image *image, mm_util_rotate_type_e rotation)
+static int __mm_util_rotate_image(Image *image, mm_util_rotate_type_e rotation, Image **rotated_image)
 {
+       int ret = MM_UTIL_ERROR_NONE;
        Image *_processed_image = NULL;
        ExceptionInfo exception;
 
        mm_util_fenter();
 
-       mm_util_retvm_if(image == NULL, NULL, "invalid image");
+       mm_util_retvm_if(!image, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid image");
+       mm_util_retvm_if(!__mm_util_check_rotation(rotation), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid rotation [%d]", rotation);
+       mm_util_retvm_if(!rotated_image, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid rotated_image");
 
        GetExceptionInfo(&exception);
 
@@ -184,21 +193,25 @@ static Image * __mm_util_rotate_image(Image *image, mm_util_rotate_type_e rotati
                break;
        }
 
-       if (_processed_image == NULL) {
+       if (_processed_image) {
+               *rotated_image = _processed_image;
+       } else {
                mm_util_error("Error: Image processing failed.");
                if (exception.severity != UndefinedException)
                        CatchException(&exception);
+               ret = MM_UTIL_ERROR_INVALID_OPERATION;
        }
 
        DestroyExceptionInfo(&exception);
 
        mm_util_fleave();
 
-       return _processed_image;
+       return ret;
 }
 
-static Image * __mm_util_resize_image(Image *image, unsigned int width, unsigned int height)
+static int __mm_util_resize_image(Image *image, unsigned int width, unsigned int height, Image **resized_image)
 {
+       int ret = MM_UTIL_ERROR_NONE;
        Image *_processed_image = NULL;
        Image *_sampled_image = NULL;
        ExceptionInfo exception;
@@ -207,7 +220,12 @@ static Image * __mm_util_resize_image(Image *image, unsigned int width, unsigned
 
        mm_util_fenter();
 
-       mm_util_retvm_if(image == NULL, NULL, "invalid image");
+       mm_util_retvm_if(!image, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid image");
+       mm_util_retvm_if(width == 0 || height == 0, MM_UTIL_ERROR_INVALID_PARAMETER,
+                               "invalid request[%u * %u]", width, height);
+       mm_util_retvm_if((image->columns < width) || (image->rows < height), MM_UTIL_ERROR_INVALID_PARAMETER,
+                               "request[%u * %u] is larger than image [%lu * %lu]", width, height, image->columns, image->rows);
+       mm_util_retvm_if(!resized_image, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid resized_image");
 
        GetExceptionInfo(&exception);
 
@@ -222,10 +240,13 @@ static Image * __mm_util_resize_image(Image *image, unsigned int width, unsigned
        else
                _processed_image = ScaleImage(image, width, height, &exception);
 
-       if (_processed_image == NULL) {
+       if (_processed_image) {
+               *resized_image = _processed_image;
+       } else {
                mm_util_error("Error: Resizing Image failed.");
                if (exception.severity != UndefinedException)
                        CatchException(&exception);
+               ret = MM_UTIL_ERROR_INVALID_OPERATION;
        }
 
        DestroyImageList(_sampled_image);
@@ -234,38 +255,31 @@ static Image * __mm_util_resize_image(Image *image, unsigned int width, unsigned
 
        mm_util_fleave();
 
-       return _processed_image;
+       return ret;
 }
 
-static Image * __mm_util_read_image_from_file(const char *path)
+static Image * __mm_util_read_image(ImageInfo *image_info)
 {
-       ImageInfo *_image_info = NULL;
        Image *_image = NULL;
        ExceptionInfo exception;
 
        mm_util_fenter();
 
-       mm_util_retvm_if(!MMUTIL_STRING_VALID(path), NULL, "invalid path");
+       mm_util_retvm_if(!image_info, NULL, "invalid image_info");
 
        GetExceptionInfo(&exception);
 
-       _image_info = CloneImageInfo(0);
-       mm_util_retvm_if(!_image_info, NULL, "Error: CloneImageInfo failed.");
-       g_strlcpy(_image_info->filename, path, sizeof(_image_info->filename));
-
-       AddDefinition(_image_info, "jpeg", "dct-method", "FASTEST", &exception);
-       AddDefinition(_image_info, "jpeg", "block-smoothing", "FALSE", &exception);
-       AddDefinition(_image_info, "jpeg", "fancy-upsampling", "FALSE", &exception);
-
-       _image = ReadImage(_image_info, &exception);
+       AddDefinition(image_info, "jpeg", "dct-method", "FASTEST", &exception);
+       AddDefinition(image_info, "jpeg", "block-smoothing", "FALSE", &exception);
+       AddDefinition(image_info, "jpeg", "fancy-upsampling", "FALSE", &exception);
 
-       if (_image == NULL) {
+       _image = ReadImage(image_info, &exception);
+       if (!_image) {
                mm_util_error("Error: Reading Image failed.");
                if (exception.severity != UndefinedException)
                        CatchException(&exception);
        }
 
-       DestroyImageInfo(_image_info);
        DestroyExceptionInfo(&exception);
 
        mm_util_fleave();
@@ -273,42 +287,60 @@ static Image * __mm_util_read_image_from_file(const char *path)
        return _image;
 }
 
-static Image * __mm_util_read_image_from_buffer(const void *buf, size_t buf_size)
+static int __mm_util_read_image_from_file(const char *path, Image **image)
 {
        ImageInfo *_image_info = NULL;
        Image *_image = NULL;
-       ExceptionInfo exception;
 
        mm_util_fenter();
 
-       mm_util_retvm_if(!buf, NULL, "invalid buf");
-       mm_util_retvm_if(buf_size == 0, NULL, "invalid buf_size");
-
-       GetExceptionInfo(&exception);
+       mm_util_retvm_if(!MMUTIL_STRING_VALID(path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid path");
+       mm_util_retvm_if(!image, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid image");
 
        _image_info = CloneImageInfo(0);
-       mm_util_retvm_if(!_image_info, NULL, "Error: CloneImageInfo failed.");
-       _image_info->blob = (void *)buf;
-       _image_info->length = buf_size;
+       mm_util_retvm_if(!_image_info, MM_UTIL_ERROR_INVALID_OPERATION, "Error: CloneImageInfo failed.");
+       g_strlcpy(_image_info->filename, path, sizeof(_image_info->filename));
 
-       AddDefinition(_image_info, "jpeg", "dct-method", "FASTEST", &exception);
-       AddDefinition(_image_info, "jpeg", "block-smoothing", "FALSE", &exception);
-       AddDefinition(_image_info, "jpeg", "fancy-upsampling", "FALSE", &exception);
+       _image = __mm_util_read_image(_image_info);
+       DestroyImageInfo(_image_info);
+       if (!_image) {
+               mm_util_error("Error: __mm_util_read_image failed.");
+               return MM_UTIL_ERROR_INVALID_OPERATION;
+       }
+       *image = _image;
 
-       _image = ReadImage(_image_info, &exception);
+       mm_util_fleave();
 
-       if (_image == NULL) {
-               mm_util_error("Error: Reading Image failed.");
-               if (exception.severity != UndefinedException)
-                       CatchException(&exception);
-       }
+       return MM_UTIL_ERROR_NONE;
+}
+
+static int __mm_util_read_image_from_buffer(const void *buf, size_t buf_size, Image **image)
+{
+       ImageInfo *_image_info = NULL;
+       Image *_image = NULL;
+
+       mm_util_fenter();
+
+       mm_util_retvm_if(!buf, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid buf");
+       mm_util_retvm_if(buf_size == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid buf_size");
+       mm_util_retvm_if(!image, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid image");
+
+       _image_info = CloneImageInfo(0);
+       mm_util_retvm_if(!_image_info, MM_UTIL_ERROR_INVALID_OPERATION, "Error: CloneImageInfo failed.");
+       _image_info->blob = (void *)buf;
+       _image_info->length = buf_size;
 
+       _image = __mm_util_read_image(_image_info);
        DestroyImageInfo(_image_info);
-       DestroyExceptionInfo(&exception);
+       if (!_image) {
+               mm_util_error("Error: __mm_util_read_image failed.");
+               return MM_UTIL_ERROR_INVALID_OPERATION;
+       }
+       *image = _image;
 
        mm_util_fleave();
 
-       return _image;
+       return MM_UTIL_ERROR_NONE;
 }
 
 static int __mm_util_write_image_to_file(Image *image, mm_util_enc_opt_t *option, const char *out_path)
@@ -320,16 +352,15 @@ static int __mm_util_write_image_to_file(Image *image, mm_util_enc_opt_t *option
 
        mm_util_fenter();
 
-       mm_util_retvm_if(image == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid image");
+       mm_util_retvm_if(!image, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid image");
        mm_util_retvm_if(!MMUTIL_STRING_VALID(out_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid out_path");
 
        GetExceptionInfo(&exception);
 
        _image_info = CloneImageInfo(0);
-       mm_util_retvm_if(_image_info == NULL, MM_UTIL_ERROR_INVALID_OPERATION, "Error: CloneImageInfo failed.");
+       mm_util_retvm_if(!_image_info, MM_UTIL_ERROR_INVALID_OPERATION, "Error: CloneImageInfo failed.");
 
        SAFE_STRLCPY(image->filename, out_path, sizeof(image->filename));
-       image->filename[MaxTextExtent-1] = '\0';
 
        DeleteImageProfile(image, "EXIF");
        DeleteImageProfile(image, "8BIM");
@@ -409,10 +440,10 @@ static int __mm_util_dispatch_image(Image *image, mm_util_color_format_e format,
        pixels_size = sizeof(unsigned char) * strlen(map) * width * height;
        pixels = MagickMalloc(pixels_size);
 
-       if (pixels == NULL) {
+       if (!pixels) {
                mm_util_error("Error: MagickMalloc failed.");
                ret = MM_UTIL_ERROR_OUT_OF_MEMORY;
-               goto ERROR;
+               goto END;
        }
 
        ret = DispatchImage(image, 0, 0, width, height, map, CharPixel, pixels, &exception);
@@ -423,7 +454,7 @@ static int __mm_util_dispatch_image(Image *image, mm_util_color_format_e format,
 
                MagickFree(pixels);
                ret = MM_UTIL_ERROR_INVALID_OPERATION;
-               goto ERROR;
+               goto END;
        }
 
        ret = mm_image_create_image(width, height, format, pixels, pixels_size, dispatched_image);
@@ -432,7 +463,7 @@ static int __mm_util_dispatch_image(Image *image, mm_util_color_format_e format,
 
        MagickFree(pixels);
 
-ERROR:
+END:
 
        DestroyExceptionInfo(&exception);
 
@@ -506,31 +537,25 @@ int mm_util_rotate_B_B(mm_util_image_h src_handle, mm_util_rotate_type_e rotatio
        Image *_processed_image = NULL;
        ExceptionInfo exception;
 
-       mm_util_retvm_if(!src_handle, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_handle");
-       mm_util_retvm_if(!__mm_util_check_rotation(rotation), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid rotation [%d]", rotation);
-       mm_util_retvm_if(!dst_handle, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_handle");
-
        mm_util_debug("rotation [%d]", rotation);
 
        __mm_util_init(&exception);
 
-       _image = __mm_util_constitute_image(src_handle);
-       if (_image == NULL) {
+       ret = __mm_util_constitute_image(src_handle, &_image);
+       if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("Error: __mm_util_constitute_image failed.");
-               ret = MM_UTIL_ERROR_INVALID_OPERATION;
-               goto ERROR;
+               goto END;
        }
 
-       _processed_image = __mm_util_rotate_image(_image, rotation);
-       if (_processed_image == NULL) {
+       ret = __mm_util_rotate_image(_image, rotation, &_processed_image);
+       if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("Error: __mm_util_rotate_image failed.");
-               ret = MM_UTIL_ERROR_INVALID_OPERATION;
-               goto ERROR;
+               goto END;
        }
 
        ret = __mm_util_dispatch_image(_processed_image, _src_handle->color, dst_handle);
 
-ERROR:
+END:
 
        __mm_util_finalize(_image, _processed_image, &exception);
 
@@ -546,31 +571,25 @@ int mm_util_rotate_B_P(mm_util_image_h src_handle, mm_util_rotate_type_e rotatio
        Image *_processed_image = NULL;
        ExceptionInfo exception;
 
-       mm_util_retvm_if(!src_handle, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_handle");
-       mm_util_retvm_if(!__mm_util_check_rotation(rotation), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid rotation [%d]", rotation);
-       mm_util_retvm_if(!MMUTIL_STRING_VALID(dst_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_path");
-
        mm_util_sec_debug("rotation [%d] dst_path [%s]", rotation, dst_path);
 
        __mm_util_init(&exception);
 
-       _image = __mm_util_constitute_image(src_handle);
-       if (_image == NULL) {
+       ret = __mm_util_constitute_image(src_handle, &_image);
+       if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("Error: __mm_util_constitute_image failed.");
-               ret = MM_UTIL_ERROR_INVALID_OPERATION;
-               goto ERROR;
+               goto END;
        }
 
-       _processed_image = __mm_util_rotate_image(_image, rotation);
-       if (_processed_image == NULL) {
+       ret = __mm_util_rotate_image(_image, rotation, &_processed_image);
+       if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("Error: __mm_util_rotate_image failed.");
-               ret = MM_UTIL_ERROR_INVALID_OPERATION;
-               goto ERROR;
+               goto END;
        }
 
        ret = __mm_util_write_image_to_file(_processed_image, NULL, dst_path);
 
-ERROR:
+END:
 
        __mm_util_finalize(_image, _processed_image, &exception);
 
@@ -586,31 +605,25 @@ int mm_util_rotate_P_B(const char *src_path, mm_util_rotate_type_e rotation, mm_
        Image *_processed_image = NULL;
        ExceptionInfo exception;
 
-       mm_util_retvm_if(!MMUTIL_STRING_VALID(src_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_path");
-       mm_util_retvm_if(!__mm_util_check_rotation(rotation), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid rotation [%d]", rotation);
-       mm_util_retvm_if(!dst_handle, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_handle");
-
        mm_util_sec_debug("src_path [%s] rotation [%d] req_format [%d]", src_path, rotation, req_format);
 
        __mm_util_init(&exception);
 
-       _image = __mm_util_read_image_from_file(src_path);
-       if (_image == NULL) {
+       ret = __mm_util_read_image_from_file(src_path, &_image);
+       if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("Error: __mm_util_read_image_from_file failed.");
-               ret = MM_UTIL_ERROR_INVALID_OPERATION;
-               goto ERROR;
+               goto END;
        }
 
-       _processed_image = __mm_util_rotate_image(_image, rotation);
-       if (_processed_image == NULL) {
+       ret = __mm_util_rotate_image(_image, rotation, &_processed_image);
+       if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("Error: __mm_util_rotate_image failed.");
-               ret = MM_UTIL_ERROR_INVALID_OPERATION;
-               goto ERROR;
+               goto END;
        }
 
        ret = __mm_util_dispatch_image(_processed_image, req_format, dst_handle);
 
-ERROR:
+END:
 
        __mm_util_finalize(_image, _processed_image, &exception);
 
@@ -627,31 +640,23 @@ int mm_util_rotate_P_P(const char *src_path, mm_util_rotate_type_e rotation, con
        Image *_processed_image = NULL;
        ExceptionInfo exception;
 
-       mm_util_retvm_if(!MMUTIL_STRING_VALID(src_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_path");
-       mm_util_retvm_if(!__mm_util_check_rotation(rotation), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid rotation [%d]", rotation);
-       mm_util_retvm_if(!MMUTIL_STRING_VALID(dst_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_path");
-
-       mm_util_sec_debug("src_path [%s] rotation [%d] dst_path [%s]", src_path, rotation, dst_path);
-
        __mm_util_init(&exception);
 
-       _image = __mm_util_read_image_from_file(src_path);
-       if (_image == NULL) {
+       ret = __mm_util_read_image_from_file(src_path, &_image);
+       if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("Error: __mm_util_read_image_from_file failed.");
-               ret = MM_UTIL_ERROR_INVALID_OPERATION;
-               goto ERROR;
+               goto END;
        }
 
-       _processed_image = __mm_util_rotate_image(_image, rotation);
-       if (_processed_image == NULL) {
+       ret = __mm_util_rotate_image(_image, rotation, &_processed_image);
+       if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("Error: __mm_util_rotate_image failed.");
-               ret = MM_UTIL_ERROR_INVALID_OPERATION;
-               goto ERROR;
+               goto END;
        }
 
        ret = __mm_util_write_image_to_file(_processed_image, NULL, dst_path);
 
-ERROR:
+END:
 
        __mm_util_finalize(_image, _processed_image, &exception);
 
@@ -668,37 +673,25 @@ int mm_util_resize_B_B(mm_util_image_h src_handle, unsigned int req_width, unsig
        Image *_processed_image = NULL;
        ExceptionInfo exception;
 
-       mm_util_retvm_if(!src_handle, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_handle");
-       mm_util_retvm_if((req_width == 0) || (req_height == 0), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid size W[%d] H[%d]", req_width, req_height);
-       mm_util_retvm_if(!dst_handle, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_handle");
-
        mm_util_debug("req_width [%u] req_height [%u]", req_width, req_height);
 
        __mm_util_init(&exception);
 
-       _image = __mm_util_constitute_image(src_handle);
-       if (_image == NULL) {
+       ret = __mm_util_constitute_image(src_handle, &_image);
+       if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("Error: __mm_util_constitute_image failed.");
-               ret = MM_UTIL_ERROR_INVALID_OPERATION;
-               goto ERROR;
-       }
-
-       if ((_image->columns < req_width) || (_image->rows < req_height)) {
-               mm_util_error("Wrong Size. image [%lu * %lu], request [%u * %u]", _image->columns, _image->rows, req_width, req_height);
-               ret = MM_UTIL_ERROR_INVALID_PARAMETER;
-               goto ERROR;
+               goto END;
        }
 
-       _processed_image = __mm_util_resize_image(_image, req_width, req_height);
-       if (_processed_image == NULL) {
+       ret = __mm_util_resize_image(_image, req_width, req_height, &_processed_image);
+       if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("Error: __mm_util_resize_image failed.");
-               ret = MM_UTIL_ERROR_INVALID_OPERATION;
-               goto ERROR;
+               goto END;
        }
 
        ret = __mm_util_dispatch_image(_processed_image, _src_handle->color, dst_handle);
 
-ERROR:
+END:
 
        __mm_util_finalize(_image, _processed_image, &exception);
 
@@ -714,37 +707,25 @@ int mm_util_resize_B_P(mm_util_image_h src_handle, unsigned int req_width, unsig
        Image *_processed_image = NULL;
        ExceptionInfo exception;
 
-       mm_util_retvm_if(!src_handle, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_handle");
-       mm_util_retvm_if((req_width == 0) || (req_height == 0), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid size W[%d] H[%d]", req_width, req_height);
-       mm_util_retvm_if(!MMUTIL_STRING_VALID(dst_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_path");
-
        mm_util_sec_debug("req_width [%u] req_height [%u] dst_path [%s]", req_width, req_height, dst_path);
 
        __mm_util_init(&exception);
 
-       _image = __mm_util_constitute_image(src_handle);
-       if (_image == NULL) {
+       ret = __mm_util_constitute_image(src_handle, &_image);
+       if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("Error: __mm_util_constitute_image failed.");
-               ret = MM_UTIL_ERROR_INVALID_OPERATION;
-               goto ERROR;
+               goto END;
        }
 
-       if ((_image->columns < req_width) || (_image->rows < req_height)) {
-               mm_util_error("Wrong Size. image [%lu * %lu], request [%u * %u]", _image->columns, _image->rows, req_width, req_height);
-               ret = MM_UTIL_ERROR_INVALID_PARAMETER;
-               goto ERROR;
-       }
-
-       _processed_image = __mm_util_resize_image(_image, req_width, req_height);
-       if (_processed_image == NULL) {
+       ret = __mm_util_resize_image(_image, req_width, req_height, &_processed_image);
+       if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("Error: __mm_util_resize_image failed.");
-               ret = MM_UTIL_ERROR_INVALID_OPERATION;
-               goto ERROR;
+               goto END;
        }
 
        ret = __mm_util_write_image_to_file(_processed_image, NULL, dst_path);
 
-ERROR:
+END:
 
        __mm_util_finalize(_image, _processed_image, &exception);
 
@@ -760,37 +741,25 @@ int mm_util_resize_P_B(const char *src_path, unsigned int req_width, unsigned in
        Image *_processed_image = NULL;
        ExceptionInfo exception;
 
-       mm_util_retvm_if(!MMUTIL_STRING_VALID(src_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_path");
-       mm_util_retvm_if((req_width == 0) || (req_height == 0), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid size W[%d] H[%d]", req_width, req_height);
-       mm_util_retvm_if(!dst_handle, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_handle");
-
        mm_util_sec_debug("src_path [%s] req_width [%u] req_height [%u]", src_path, req_width, req_height);
 
        __mm_util_init(&exception);
 
-       _image = __mm_util_read_image_from_file(src_path);
-       if (_image == NULL) {
+       ret = __mm_util_read_image_from_file(src_path, &_image);
+       if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("Error: __mm_util_read_image_from_file failed.");
-               ret = MM_UTIL_ERROR_INVALID_OPERATION;
-               goto ERROR;
-       }
-
-       if ((_image->columns < req_width) || (_image->rows < req_height)) {
-               mm_util_error("Wrong Size. image [%lu * %lu], request [%u * %u]", _image->columns, _image->rows, req_width, req_height);
-               ret = MM_UTIL_ERROR_INVALID_PARAMETER;
-               goto ERROR;
+               goto END;
        }
 
-       _processed_image = __mm_util_resize_image(_image, req_width, req_height);
-       if (_processed_image == NULL) {
+       ret = __mm_util_resize_image(_image, req_width, req_height, &_processed_image);
+       if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("Error: __mm_util_resize_image failed.");
-               ret = MM_UTIL_ERROR_INVALID_OPERATION;
-               goto ERROR;
+               goto END;
        }
 
        ret = __mm_util_dispatch_image(_processed_image, req_format, dst_handle);
 
-ERROR:
+END:
 
        __mm_util_finalize(_image, _processed_image, &exception);
 
@@ -806,37 +775,25 @@ int mm_util_resize_P_P(const char *src_path, unsigned int req_width, unsigned in
        Image *_processed_image = NULL;
        ExceptionInfo exception;
 
-       mm_util_retvm_if(!MMUTIL_STRING_VALID(src_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_path");
-       mm_util_retvm_if((req_width == 0) || (req_height == 0), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid size W[%d] H[%d]", req_width, req_height);
-       mm_util_retvm_if(!MMUTIL_STRING_VALID(dst_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_path");
-
        mm_util_sec_debug("src_path [%s] req_width [%u] req_height [%u] dst_path [%s]", src_path, req_width, req_height, dst_path);
 
        __mm_util_init(&exception);
 
-       _image = __mm_util_read_image_from_file(src_path);
-       if (_image == NULL) {
+       ret = __mm_util_read_image_from_file(src_path, &_image);
+       if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("Error: __mm_util_read_image_from_file failed.");
-               ret = MM_UTIL_ERROR_INVALID_OPERATION;
-               goto ERROR;
+               goto END;
        }
 
-       if ((_image->columns < req_width) || (_image->rows < req_height)) {
-               mm_util_error("Wrong Size. image [%lu * %lu], request [%u * %u]", _image->columns, _image->rows, req_width, req_height);
-               ret = MM_UTIL_ERROR_INVALID_PARAMETER;
-               goto ERROR;
-       }
-
-       _processed_image = __mm_util_resize_image(_image, req_width, req_height);
-       if (_processed_image == NULL) {
+       ret = __mm_util_resize_image(_image, req_width, req_height, &_processed_image);
+       if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("Error: __mm_util_resize_image failed.");
-               ret = MM_UTIL_ERROR_INVALID_OPERATION;
-               goto ERROR;
+               goto END;
        }
 
        ret = __mm_util_write_image_to_file(_processed_image, NULL, dst_path);
 
-ERROR:
+END:
 
        __mm_util_finalize(_image, _processed_image, &exception);
 
@@ -852,23 +809,19 @@ int mm_util_convert_B_B(mm_util_image_h src_handle, mm_util_color_format_e req_f
        Image *_image = NULL;
        ExceptionInfo exception;
 
-       mm_util_retvm_if(!src_handle, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_handle");
-       mm_util_retvm_if(!dst_handle, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_handle");
-
        mm_util_debug("input format [%d] req_format [%d]", _src_handle->color, req_format);
 
        __mm_util_init(&exception);
 
-       _image = __mm_util_constitute_image(src_handle);
-       if (_image == NULL) {
+       ret = __mm_util_constitute_image(src_handle, &_image);
+       if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("Error: __mm_util_constitute_image failed.");
-               ret = MM_UTIL_ERROR_INVALID_OPERATION;
-               goto ERROR;
+               goto END;
        }
 
        ret = __mm_util_dispatch_image(_image, req_format, dst_handle);
 
-ERROR:
+END:
 
        __mm_util_finalize(_image, NULL, &exception);
 
@@ -882,23 +835,19 @@ int mm_util_decode_image_from_file(const char *path, mm_util_color_format_e form
        int ret = MM_UTIL_ERROR_NONE;
        Image *_image = NULL;
 
-       mm_util_retvm_if(!MMUTIL_STRING_VALID(path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid path");
-       mm_util_retvm_if(!decoded_image, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid decoded_image");
-
        mm_util_sec_debug("path [%s] format [%d]", path, format);
 
        __mm_util_init(NULL);
 
-       _image = __mm_util_read_image_from_file(path);
-       if (_image == NULL) {
+       ret = __mm_util_read_image_from_file(path, &_image);
+       if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("Error: __mm_util_read_image_from_file failed.");
-               ret = MM_UTIL_ERROR_INVALID_OPERATION;
-               goto ERROR;
+               goto END;
        }
 
        ret = __mm_util_dispatch_image(_image, format, decoded_image);
 
-ERROR:
+END:
 
        __mm_util_finalize(_image, NULL, NULL);
 
@@ -912,24 +861,19 @@ int mm_util_decode_image_from_buffer(const void *buf, size_t buf_size, mm_util_c
        int ret = MM_UTIL_ERROR_NONE;
        Image *_image = NULL;
 
-       mm_util_retvm_if(!buf, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid buf");
-       mm_util_retvm_if(buf_size == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid buf_size");
-       mm_util_retvm_if(!decoded_image, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid decoded_image");
-
        mm_util_sec_debug("path [%p] buf_size [%zu] format [%d]", buf, buf_size, format);
 
        __mm_util_init(NULL);
 
-       _image = __mm_util_read_image_from_buffer(buf, buf_size);
-       if (_image == NULL) {
-               mm_util_error("Error: __mm_util_read_image_from_file failed.");
-               ret = MM_UTIL_ERROR_INVALID_OPERATION;
-               goto ERROR;
+       ret = __mm_util_read_image_from_buffer(buf, buf_size, &_image);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               mm_util_error("Error: __mm_util_read_image_from_buffer failed.");
+               goto END;
        }
 
        ret = __mm_util_dispatch_image(_image, format, decoded_image);
 
-ERROR:
+END:
 
        __mm_util_finalize(_image, NULL, NULL);
 
@@ -945,9 +889,7 @@ int mm_util_encode_image_to_file(mm_util_image_h decoded_image, mm_util_enc_opt_
        mm_util_image_h converted_image = NULL, source = NULL;
        mm_util_enc_opt_t *_opt = (mm_util_enc_opt_t *)opt;
 
-       mm_util_retvm_if(!decoded_image, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid decoded_image");
        mm_util_retvm_if(!_opt, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid opt");
-       mm_util_retvm_if(!MMUTIL_STRING_VALID(path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid path");
 
        mm_util_sec_debug("path [%s]", path);
 
@@ -965,7 +907,7 @@ int mm_util_encode_image_to_file(mm_util_image_h decoded_image, mm_util_enc_opt_
                        ret = mm_util_convert_B_B(decoded_image, MM_UTIL_COLOR_RGB24, &converted_image);
                        if (ret != MM_UTIL_ERROR_NONE) {
                                mm_util_error("Error: mm_util_convert_B_B failed.");
-                               goto ERROR;
+                               goto END;
                        }
                }
        }
@@ -974,16 +916,15 @@ int mm_util_encode_image_to_file(mm_util_image_h decoded_image, mm_util_enc_opt_
 
        __mm_util_init(NULL);
 
-       _image = __mm_util_constitute_image(source);
-       if (_image == NULL) {
+       ret = __mm_util_constitute_image(source, &_image);
+       if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("Error: __mm_util_constitute_image failed.");
-               ret = MM_UTIL_ERROR_INVALID_OPERATION;
-               goto ERROR;
+               goto END;
        }
 
        ret = __mm_util_write_image_to_file(_image, _opt, path);
 
-ERROR:
+END:
 
        __mm_util_finalize(_image, NULL, NULL);
 
@@ -999,10 +940,7 @@ int mm_util_encode_image_to_buffer(mm_util_image_h decoded_image, mm_util_enc_op
        int ret = MM_UTIL_ERROR_NONE;
        char *tmp_file = NULL;
 
-       mm_util_retvm_if(!decoded_image, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid decoded_image");
        mm_util_retvm_if(!opt, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid opt");
-       mm_util_retvm_if(!buf, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid buf");
-       mm_util_retvm_if(buf_size == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid buf_size");
 
        ret = __mm_util_make_tmp_file(((mm_util_enc_opt_t *)opt)->codec, &tmp_file);
        mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "Error: __mm_util_make_tmp_file failed.");
@@ -1010,14 +948,14 @@ int mm_util_encode_image_to_buffer(mm_util_image_h decoded_image, mm_util_enc_op
        ret = mm_util_encode_image_to_file(decoded_image, opt, tmp_file);
        if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("Error: mm_util_encode_image_P failed.");
-               goto ERROR;
+               goto END;
        }
 
        ret = mm_util_file_read(tmp_file, buf, buf_size);
        if (ret != MM_UTIL_ERROR_NONE)
                mm_util_error("Error: mm_util_file_read failed.");
 
-ERROR:
+END:
 
        if (g_remove(tmp_file) != 0)
                mm_util_sec_debug("Temporary file was not removed [%s]", tmp_file);
@@ -1038,32 +976,20 @@ int mm_util_resize_and_rotate_P_P(const char *src_path, unsigned int req_width,
        ExceptionInfo exception;
        mm_util_rotate_type_e rotation = MM_UTIL_ROTATE_0;
 
-       mm_util_retvm_if(!MMUTIL_STRING_VALID(src_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_path");
-       mm_util_retvm_if((req_width == 0) || (req_height == 0), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid size W[%d] H[%d]", req_width, req_height);
-       mm_util_retvm_if(!MMUTIL_STRING_VALID(dst_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_path");
-
        mm_util_sec_debug("src_path [%s] req_width [%u] req_height [%u] dst_path [%s]", src_path, req_width, req_height, dst_path);
 
        __mm_util_init(&exception);
 
-       _image = __mm_util_read_image_from_file(src_path);
-       if (_image == NULL) {
+       ret = __mm_util_read_image_from_file(src_path, &_image);
+       if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("Error: __mm_util_read_image_from_file failed.");
-               ret = MM_UTIL_ERROR_INVALID_OPERATION;
-               goto ERROR;
+               goto END;
        }
 
-       if ((_image->columns < req_width) || (_image->rows < req_height)) {
-               mm_util_error("Wrong Size. image [%lu * %lu], request [%u * %u]", _image->columns, _image->rows, req_width, req_height);
-               ret = MM_UTIL_ERROR_INVALID_PARAMETER;
-               goto ERROR;
-       }
-
-       _resized_image = __mm_util_resize_image(_image, req_width, req_height);
-       if (_resized_image == NULL) {
+       ret = __mm_util_resize_image(_image, req_width, req_height, &_resized_image);
+       if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("Error: __mm_util_resize_image failed.");
-               ret = MM_UTIL_ERROR_INVALID_OPERATION;
-               goto ERROR;
+               goto END;
        }
 
        switch(_resized_image->orientation) {
@@ -1088,11 +1014,10 @@ int mm_util_resize_and_rotate_P_P(const char *src_path, unsigned int req_width,
        }
 
        if (rotation != MM_UTIL_ROTATE_0) {
-               _rotated_image = __mm_util_rotate_image(_resized_image, rotation);
-               if (_rotated_image == NULL) {
-                       mm_util_error("Error: __mm_util_resize_image failed.");
-                       ret = MM_UTIL_ERROR_INVALID_OPERATION;
-                       goto ERROR;
+               ret = __mm_util_rotate_image(_image, rotation, &_rotated_image);
+               if (ret != MM_UTIL_ERROR_NONE) {
+                       mm_util_error("Error: __mm_util_rotate_image failed.");
+                       goto END;
                }
        }
 
@@ -1109,7 +1034,7 @@ int mm_util_resize_and_rotate_P_P(const char *src_path, unsigned int req_width,
 
        ret = __mm_util_write_image_to_file(_write_image, NULL, dst_path);
 
-ERROR:
+END:
 
        DestroyImageList(_image);
        __mm_util_finalize(_resized_image, _rotated_image, &exception);