Remove unneccessary 'image_h' when image is decoded 89/183289/1 accepted/tizen/unified/20180706.062143 submit/tizen/20180704.232304
authorJiyong Min <jiyong.min@samsung.com>
Wed, 4 Jul 2018 06:38:01 +0000 (15:38 +0900)
committerJiyong Min <jiyong.min@samsung.com>
Wed, 4 Jul 2018 06:39:50 +0000 (15:39 +0900)
Change-Id: I12f70554a7281deb7f7e01426aef745020d48956

packaging/capi-media-image-util.spec
src/image_util_decode.c

index 5fa4ee1..42a9aab 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       capi-media-image-util
 Summary:    A Image Utility library in Tizen Native API
-Version:    0.1.40
+Version:    0.1.41
 Release:    2
 Group:      Multimedia/API
 License:    Apache-2.0
index 87f1a9b..043b00a 100755 (executable)
@@ -108,68 +108,6 @@ static int _image_util_decode_check_image_type(const unsigned char *image_buffer
        return IMAGE_UTIL_ERROR_NONE;
 }
 
-static int _image_util_decode_create_jpeg_handle(decode_encode_s * handle)
-{
-       image_util_retvm_if((handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
-
-       /* It is needed to reuse decode handle for C#, so it shoud be reallocated */
-       IMAGE_UTIL_SAFE_FREE(handle->image_h);
-
-       mm_util_jpeg_yuv_data *_handle = (mm_util_jpeg_yuv_data *) calloc(1, sizeof(mm_util_jpeg_yuv_data));
-       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->down_scale = IMAGE_UTIL_DOWNSCALE_1_1;
-
-       return IMAGE_UTIL_ERROR_NONE;
-}
-
-static int _image_util_decode_create_png_handle(decode_encode_s * handle)
-{
-       image_util_retvm_if((handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
-
-       /* It is needed to reuse decode handle for C#, so it shoud be reallocated */
-       IMAGE_UTIL_SAFE_FREE(handle->image_h);
-
-       mm_util_png_data *_handle = (mm_util_png_data *) calloc(1, sizeof(mm_util_png_data));
-       image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
-
-       handle->image_h = (mm_util_imgp_h) _handle;
-
-       return IMAGE_UTIL_ERROR_NONE;
-}
-
-static int _image_util_decode_create_gif_handle(decode_encode_s * handle)
-{
-       image_util_retvm_if((handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
-
-       /* It is needed to reuse decode handle for C#, so it shoud be reallocated */
-       IMAGE_UTIL_SAFE_FREE(handle->image_h);
-
-       mm_util_gif_data *_handle = (mm_util_gif_data *) calloc(1, sizeof(mm_util_gif_data));
-       image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
-
-       handle->image_h = (mm_util_imgp_h) _handle;
-
-       return IMAGE_UTIL_ERROR_NONE;
-}
-
-static int _image_util_decode_create_bmp_handle(decode_encode_s * handle)
-{
-       image_util_retvm_if((handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
-
-       /* It is needed to reuse decode handle for C#, so it shoud be reallocated */
-       IMAGE_UTIL_SAFE_FREE(handle->image_h);
-
-       mm_util_bmp_data *_handle = (mm_util_bmp_data *) calloc(1, sizeof(mm_util_bmp_data));
-       image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
-
-       handle->image_h = (mm_util_imgp_h) _handle;
-
-       return IMAGE_UTIL_ERROR_NONE;
-}
-
 int image_util_decode_create(image_util_decode_h * handle)
 {
        image_util_fenter();
@@ -182,9 +120,9 @@ int image_util_decode_create(image_util_decode_h * handle)
        _handle->src_buffer = NULL;
        _handle->dst_buffer = NULL;
        _handle->path = NULL;
-       _handle->image_h = NULL;
        _handle->mode = MODE_DECODE;
        _handle->image_type = _NOT_SUPPORTED_IMAGE_TYPE;
+       _handle->colorspace = IMAGE_UTIL_COLORSPACE_RGBA8888;
 
        *handle = (image_util_decode_h) _handle;
 
@@ -200,16 +138,12 @@ static int _image_util_decode_create_image_handle(image_util_decode_h handle)
 
        switch (_handle->image_type) {
        case IMAGE_UTIL_JPEG:
-               err = _image_util_decode_create_jpeg_handle(_handle);
+               _handle->down_scale = IMAGE_UTIL_DOWNSCALE_1_1;
                break;
        case IMAGE_UTIL_PNG:
-               err = _image_util_decode_create_png_handle(_handle);
-               break;
        case IMAGE_UTIL_GIF:
-               err = _image_util_decode_create_gif_handle(_handle);
-               break;
        case IMAGE_UTIL_BMP:
-               err = _image_util_decode_create_bmp_handle(_handle);
+               /* do nothing... */
                break;
        default:
                err = IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
@@ -288,7 +222,6 @@ int image_util_decode_set_input_buffer(image_util_decode_h handle, const unsigne
        _handle->src_buffer = (void *)calloc(1, sizeof(void *));
        if (_handle->src_buffer == NULL) {
                image_util_error("The memory of input buffer was not allocated");
-               IMAGE_UTIL_SAFE_FREE(_handle->image_h);
                return IMAGE_UTIL_ERROR_OUT_OF_MEMORY;
        }
 
@@ -343,73 +276,77 @@ static int _image_util_decode_internal(decode_encode_s * _handle)
 {
        int err = MM_UTIL_ERROR_NONE;
 
-       image_util_retvm_if((_handle == NULL || _handle->image_h == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "invalid parameter");
+       image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "invalid parameter");
        switch (_handle->image_type) {
        case IMAGE_UTIL_JPEG:
                {
-                       mm_util_jpeg_yuv_data *jpeg_data = (mm_util_jpeg_yuv_data *) _handle->image_h;
+                       mm_util_jpeg_yuv_data jpeg_data;
+                       memset(&jpeg_data, 0, sizeof(mm_util_jpeg_yuv_data));
 
                        if (_handle->path)
-                                       err = mm_util_decode_from_jpeg_file(_handle->path, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_JPEG), _convert_decode_scale_tbl[_handle->down_scale], jpeg_data);
+                                       err = mm_util_decode_from_jpeg_file(_handle->path, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_JPEG), _convert_decode_scale_tbl[_handle->down_scale], &jpeg_data);
                        else
-                                       err = mm_util_decode_from_jpeg_memory(_handle->src_buffer[0], _handle->src_size, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_JPEG), _convert_decode_scale_tbl[_handle->down_scale], jpeg_data);
+                                       err = mm_util_decode_from_jpeg_memory(_handle->src_buffer[0], _handle->src_size, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_JPEG), _convert_decode_scale_tbl[_handle->down_scale], &jpeg_data);
 
                        if (err == MM_UTIL_ERROR_NONE) {
-                               *(_handle->dst_buffer) = jpeg_data->data;
-                               _handle->dst_size = (unsigned long long)jpeg_data->size;
-                               _handle->width = jpeg_data->width;
-                               _handle->height = jpeg_data->height;
+                               *(_handle->dst_buffer) = jpeg_data.data;
+                               _handle->dst_size = (unsigned long long)jpeg_data.size;
+                               _handle->width = jpeg_data.width;
+                               _handle->height = jpeg_data.height;
                        }
                }
                break;
        case IMAGE_UTIL_PNG:
                {
-                       mm_util_png_data *png_data = (mm_util_png_data *) _handle->image_h;
+                       mm_util_png_data png_data;
+                       memset(&png_data, 0, sizeof(mm_util_png_data));
 
                        if (_handle->path)
-                               err = mm_util_decode_from_png_file(_handle->path, png_data);
+                               err = mm_util_decode_from_png_file(_handle->path, &png_data);
                        else
-                               err = mm_util_decode_from_png_memory(_handle->src_buffer[0], (size_t)_handle->src_size, png_data);
+                               err = mm_util_decode_from_png_memory(_handle->src_buffer[0], (size_t)_handle->src_size, &png_data);
 
                        if (err == MM_UTIL_ERROR_NONE) {
-                               *(_handle->dst_buffer) = png_data->data;
-                               _handle->dst_size = (unsigned long long)png_data->size;
-                               _handle->width = png_data->width;
-                               _handle->height = png_data->height;
+                               *(_handle->dst_buffer) = png_data.data;
+                               _handle->dst_size = (unsigned long long)png_data.size;
+                               _handle->width = png_data.width;
+                               _handle->height = png_data.height;
                        }
                }
                break;
        case IMAGE_UTIL_GIF:
                {
-                       mm_util_gif_data *gif_data = (mm_util_gif_data *) _handle->image_h;
+                       mm_util_gif_data gif_data;
+                       memset(&gif_data, 0, sizeof(mm_util_gif_data));
 
                        if (_handle->path)
-                               err = mm_util_decode_from_gif_file(gif_data, _handle->path);
+                               err = mm_util_decode_from_gif_file(&gif_data, _handle->path);
                        else
-                               err = mm_util_decode_from_gif_memory(gif_data, _handle->src_buffer[0]);
+                               err = mm_util_decode_from_gif_memory(&gif_data, _handle->src_buffer[0]);
 
                        if (err == MM_UTIL_ERROR_NONE) {
-                               *(_handle->dst_buffer) = gif_data->data;
-                               _handle->dst_size = gif_data->size;
-                               _handle->width = gif_data->width;
-                               _handle->height = gif_data->height;
+                               *(_handle->dst_buffer) = gif_data.data;
+                               _handle->dst_size = gif_data.size;
+                               _handle->width = gif_data.width;
+                               _handle->height = gif_data.height;
                        }
                }
                break;
        case IMAGE_UTIL_BMP:
                {
-                       mm_util_bmp_data *bmp_data = (mm_util_bmp_data *) _handle->image_h;
+                       mm_util_bmp_data bmp_data;
+                       memset(&bmp_data, 0, sizeof(mm_util_bmp_data));
 
                        if (_handle->path)
-                               err = mm_util_decode_from_bmp_file(_handle->path, bmp_data);
+                               err = mm_util_decode_from_bmp_file(_handle->path, &bmp_data);
                        else
-                               err = mm_util_decode_from_bmp_memory(_handle->src_buffer[0], (size_t)_handle->src_size, bmp_data);
+                               err = mm_util_decode_from_bmp_memory(_handle->src_buffer[0], (size_t)_handle->src_size, &bmp_data);
 
                        if (err == MM_UTIL_ERROR_NONE) {
-                               *(_handle->dst_buffer) = bmp_data->data;
-                               _handle->dst_size = (unsigned long long)bmp_data->size;
-                               _handle->width = bmp_data->width;
-                               _handle->height = bmp_data->height;
+                               *(_handle->dst_buffer) = bmp_data.data;
+                               _handle->dst_size = (unsigned long long)bmp_data.size;
+                               _handle->width = bmp_data.width;
+                               _handle->height = bmp_data.height;
                        }
                }
                break;
@@ -527,8 +464,6 @@ int image_util_decode_destroy(image_util_decode_h handle)
 
        IMAGE_UTIL_DECODE_HANDLE_CHECK(handle);
 
-       IMAGE_UTIL_SAFE_FREE(_handle->image_h);
-
        /* g_thread_exit(handle->thread); */
        if (_handle->thread) {
                g_thread_join(_handle->thread);