Just Unify image_util_encode_create() and __image_util_create_img_handle() 60/191260/1
authorhj kim <backto.kim@samsung.com>
Mon, 15 Oct 2018 06:05:40 +0000 (15:05 +0900)
committerhj kim <backto.kim@samsung.com>
Mon, 15 Oct 2018 06:05:40 +0000 (15:05 +0900)
Change-Id: I71f68e590f710403b94a708a4c3a862ff7f4f14d

src/image_util_encode.c

index 48ce66f..716823c 100755 (executable)
@@ -58,52 +58,15 @@ static void _image_util_encode_destroy_image_handle(encode_s * handle)
        IMAGE_UTIL_SAFE_FREE(image_handle);
 }
 
-static int __image_util_create_img_handle(image_util_type_e image_type, encode_s * handle)
+int image_util_encode_create(image_util_type_e image_type, image_util_encode_h * handle)
 {
        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");
-
-       _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");
-
-       handle->image_h = (void *) _image_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);
-
-               err = mm_util_gif_encode_create(&_gif_handle);
-               image_util_retvm_if((err != MM_UTIL_ERROR_NONE),  _image_error_capi(err), "Error - mm_util_gif_encode_create is failed (%d)", err);
-
-               handle->image_h = (void *) _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 err;
-}
-
-int image_util_encode_create(image_util_type_e image_type, image_util_encode_h * handle)
-{
-       int err = IMAGE_UTIL_ERROR_NONE;
-
        image_util_fenter();
-       image_util_retvm_if(handle == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       image_util_retvm_if(handle == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid handle");
+       image_util_retvm_if((image_type < IMAGE_UTIL_JPEG) || (image_type > IMAGE_UTIL_BMP), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid image_type [%d]", image_type);
 
        encode_s *_handle = (encode_s *) calloc(1, sizeof(encode_s));
        image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
@@ -116,12 +79,28 @@ int image_util_encode_create(image_util_type_e image_type, image_util_encode_h *
        _handle->current_buffer_count = 0;
        _handle->current_resolution_count = 0;
        _handle->current_delay_count = 0;
+       _handle->colorspace = IMAGE_UTIL_COLORSPACE_RGBA8888;
+       _handle->quality = 75;
+       _handle->compression = IMAGE_UTIL_PNG_COMPRESSION_6;
 
-       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);
-               return err;
+       if (image_type == IMAGE_UTIL_GIF) {
+               err = mm_util_gif_encode_create(&_gif_handle);
+               if (err != MM_UTIL_ERROR_NONE) {
+                       IMAGE_UTIL_SAFE_FREE(_handle);
+                       image_util_error("Error - mm_util_gif_encode_create is failed (%d)", err);
+                       return _image_error_capi(err);
+               }
+
+               _handle->image_h = (void *) _gif_handle;
+       } else {
+               _image_handle = (mm_image_info_s *) calloc(1, sizeof(mm_image_info_s));
+               if (_image_handle == NULL) {
+                       IMAGE_UTIL_SAFE_FREE(_handle);
+                       image_util_error("OUT_OF_MEMORY");
+                       return IMAGE_UTIL_ERROR_OUT_OF_MEMORY;
+               }
+
+               _handle->image_h = (void *) _image_handle;
        }
 
        *handle = (image_util_encode_h) _handle;