Just rearragne the codes 25/190625/1
authorhj kim <backto.kim@samsung.com>
Thu, 4 Oct 2018 07:55:52 +0000 (16:55 +0900)
committerhj kim <backto.kim@samsung.com>
Thu, 4 Oct 2018 07:55:52 +0000 (16:55 +0900)
Change-Id: I203a46b13dbcd3bd7971e66a372f8ebe340e030e

src/image_util_encode.c

index f02aeec..cef1772 100755 (executable)
@@ -58,58 +58,44 @@ static void _image_util_encode_destroy_image_handle(decode_encode_s * handle)
        IMAGE_UTIL_SAFE_FREE(image_handle);
 }
 
-static int _image_util_encode_create_jpeg_handle(decode_encode_s * handle)
+static int __image_util_create_img_handle(image_util_type_e image_type, decode_encode_s * handle)
 {
-       image_util_retvm_if((handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
-
-       mm_image_info_s *_handle = (mm_image_info_s *) calloc(1, sizeof(mm_image_info_s));
-       image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
-
-       handle->image_h = (mm_util_imgp_h) _handle;
-       handle->colorspace = IMAGE_UTIL_COLORSPACE_RGBA8888;
-       handle->quality = 75;
-
-       return IMAGE_UTIL_ERROR_NONE;
-}
-
-static int _image_util_encode_create_png_handle(decode_encode_s * handle)
-{
-       image_util_retvm_if((handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
-
-       mm_image_info_s *_handle = (mm_image_info_s *) calloc(1, sizeof(mm_image_info_s));
-       image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
-
-       handle->image_h = (mm_util_imgp_h) _handle;
-       handle->compression = IMAGE_UTIL_PNG_COMPRESSION_6;
-
-       return IMAGE_UTIL_ERROR_NONE;
-}
-
-static int _image_util_encode_create_gif_handle(decode_encode_s * handle)
-{
-       int err = MM_UTIL_ERROR_NONE;
-       mm_gif_file_h _handle = NULL;
+       int err = IMAGE_UTIL_ERROR_NONE;
+       mm_image_info_s *_image_handle = NULL;
+       mm_gif_file_h _gif_handle = NULL;
 
        image_util_retvm_if((handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
 
-       err = mm_util_gif_encode_create(&_handle);
-       image_util_retvm_if((err != MM_UTIL_ERROR_NONE),  _image_error_capi(ERR_TYPE_ENCODE, err), "Error - mm_util_gif_encode_create is failed (%d)", err);
-
-       handle->image_h = (mm_util_imgp_h) _handle;
+       _image_handle = (mm_image_info_s *) calloc(1, sizeof(mm_image_info_s));
+       image_util_retvm_if((_image_handle == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
 
-       return IMAGE_UTIL_ERROR_NONE;
-}
+       handle->image_h = (mm_util_imgp_h) _image_handle;
 
-static int _image_util_encode_create_bmp_handle(decode_encode_s * handle)
-{
-       image_util_retvm_if((handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
+       switch (image_type) {
+       case IMAGE_UTIL_JPEG:
+               handle->colorspace = IMAGE_UTIL_COLORSPACE_RGBA8888;
+               handle->quality = 75;
+               break;
+       case IMAGE_UTIL_PNG:
+               handle->compression = IMAGE_UTIL_PNG_COMPRESSION_6;
+               break;
+       case IMAGE_UTIL_GIF:
+               IMAGE_UTIL_SAFE_FREE(_image_handle);
 
-       mm_image_info_s *_handle = (mm_image_info_s *) calloc(1, sizeof(mm_image_info_s));
-       image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+               err = mm_util_gif_encode_create(&_gif_handle);
+               image_util_retvm_if((err != MM_UTIL_ERROR_NONE),  _image_error_capi(ERR_TYPE_ENCODE, err), "Error - mm_util_gif_encode_create is failed (%d)", err);
 
-       handle->image_h = (mm_util_imgp_h) _handle;
+               handle->image_h = (mm_util_imgp_h) _gif_handle;
+               break;
+       case IMAGE_UTIL_BMP:
+               break;
+       default:
+               image_util_error("Invalid image type [%d]", image_type);
+               err = IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
+               break;
+       }
 
-       return IMAGE_UTIL_ERROR_NONE;
+       return err;
 }
 
 int image_util_encode_create(image_util_type_e image_type, image_util_encode_h * handle)
@@ -132,24 +118,7 @@ int image_util_encode_create(image_util_type_e image_type, image_util_encode_h *
        _handle->current_resolution_count = 0;
        _handle->current_delay_count = 0;
 
-       switch (image_type) {
-       case IMAGE_UTIL_JPEG:
-               err = _image_util_encode_create_jpeg_handle(_handle);
-               break;
-       case IMAGE_UTIL_PNG:
-               err = _image_util_encode_create_png_handle(_handle);
-               break;
-       case IMAGE_UTIL_GIF:
-               err = _image_util_encode_create_gif_handle(_handle);
-               break;
-       case IMAGE_UTIL_BMP:
-               err = _image_util_encode_create_bmp_handle(_handle);
-               break;
-       default:
-               err = IMAGE_UTIL_ERROR_INVALID_PARAMETER;
-               break;
-       }
-
+       err = __image_util_create_img_handle(image_type, _handle);
        if (err != IMAGE_UTIL_ERROR_NONE) {
                image_util_error("Error - create image handle");
                IMAGE_UTIL_SAFE_FREE(_handle);
@@ -172,17 +141,12 @@ int image_util_encode_set_resolution(image_util_encode_h handle, unsigned long w
 
        switch (_handle->image_type) {
        case IMAGE_UTIL_JPEG:
-               {
-                       mm_image_info_s *jpeg_data = (mm_image_info_s *) _handle->image_h;
-                       jpeg_data->width = width;
-                       jpeg_data->height = height;
-               }
-               break;
        case IMAGE_UTIL_PNG:
+       case IMAGE_UTIL_BMP:
                {
-                       mm_image_info_s *png_data = (mm_image_info_s *) _handle->image_h;
-                       png_data->width = width;
-                       png_data->height = height;
+                       mm_image_info_s *_image_handle = (mm_image_info_s *) _handle->image_h;
+                       _image_handle->width = width;
+                       _image_handle->height = height;
                }
                break;
        case IMAGE_UTIL_GIF:
@@ -208,13 +172,6 @@ int image_util_encode_set_resolution(image_util_encode_h handle, unsigned long w
                        return err;
                }
                break;
-       case IMAGE_UTIL_BMP:
-               {
-                       mm_image_info_s *bmp_data = (mm_image_info_s *) _handle->image_h;
-                       bmp_data->width = width;
-                       bmp_data->height = height;
-               }
-               break;
        default:
                err = IMAGE_UTIL_ERROR_INVALID_PARAMETER;
                break;