Remove useless codes and rearrange codes 11/191311/2
authorjiyong.min <jiyong.min@samsung.com>
Tue, 16 Oct 2018 01:55:45 +0000 (10:55 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Tue, 16 Oct 2018 04:31:58 +0000 (13:31 +0900)
Change-Id: If2c571b6192d0db0f00aa3c28466084a0b3a12d3

include/image_util_private.h
src/image_util_encode.c
src/image_util_internal.c

index 8f6beb4..c040907 100755 (executable)
@@ -135,21 +135,19 @@ typedef struct {
 
 typedef struct {
        image_util_type_e image_type;
-       void **src_buffer;
-       size_t src_size;
+       mm_image_info_s src;
+       mm_image_info_s **sources;
+       unsigned int source_count;
        void **dst_buffer;
        size_t dst_size;
        size_t gif_encode_size;
        char *path;
        void *image_h;
-       unsigned long width;
-       unsigned long height;
        int quality;
        image_util_png_compression_e compression;
        unsigned int current_buffer_count;
        unsigned int current_resolution_count;
        unsigned int current_delay_count;
-       image_util_colorspace_e colorspace;
        encode_cb_s *_encode_cb;
 
        /* for async */
index d241c65..8e5dd25 100755 (executable)
 #include <image_util.h>
 #include <image_util_private.h>
 
-static int _image_util_encode_get_gif_frame(mm_gif_file_h gif_data, unsigned int index, mm_image_info_s **frame)
+static gboolean __is_invalid_image_info(mm_image_info_s image_info)
 {
-       int err = MM_UTIL_ERROR_NONE;
-       image_util_retvm_if((gif_data == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
-       image_util_retvm_if((frame == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
-
-       err = mm_util_gif_enocde_get_image_handle(gif_data, (int)index, frame);
-       image_util_retvm_if((err != MM_UTIL_ERROR_NONE), _image_error_capi(err), "mm_util_gif_enocde_get_image_handle failed %d", err);
+       if (image_info.width == 0 || image_info.height == 0 || image_info.data == NULL)
+               return TRUE;
+       else
+               return FALSE;
+}
 
-       if (*frame == NULL) {
-               err = mm_util_gif_image_create(gif_data, frame);
-               image_util_retvm_if((err != MM_UTIL_ERROR_NONE), _image_error_capi(err), "mm_util_gif_image_create failed %d", err);
+static int __allocate_source_buffer(encode_s *handle)
+{
+       image_util_fenter();
+       image_util_retvm_if(handle == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid handle");
 
-               err = mm_util_gif_enocde_set_image_handle(gif_data, *frame);
-               if (err != MM_UTIL_ERROR_NONE) {
-                       image_util_error("mm_util_gif_enocde_set_image_handle is failed %d", err);
-                       mm_util_gif_image_destory(*frame);
-                       return _image_error_capi(err);
-               }
+       if (handle->sources == NULL) {
+               handle->sources = calloc(1, sizeof(mm_image_info_s *));
+               image_util_retvm_if((handle->sources == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+               handle->sources[0] = calloc(1, sizeof(mm_image_info_s));
+               image_util_retvm_if((handle->sources[0] == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+       } else {
+               handle->sources = realloc(handle->sources, sizeof(mm_image_info_s *) * (handle->source_count + 1));
+               image_util_retvm_if((handle->sources == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+               handle->sources[handle->source_count] = calloc(1, sizeof(mm_image_info_s));
+               image_util_retvm_if((handle->sources[handle->source_count] == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
        }
-       return _image_error_capi(err);
+
+       handle->sources[handle->source_count]->color = IMAGE_UTIL_COLORSPACE_RGBA8888;
+       handle->source_count++;
+
+       image_util_fleave();
+       return IMAGE_UTIL_ERROR_NONE;
 }
 
-static void _image_util_encode_destroy_image_handle(encode_s * handle)
+static void __free_source_buffer(encode_s *handle)
 {
-       image_util_retm_if((handle == NULL), "Invalid Handle");
-       void *image_handle = (void *)(handle->image_h);
-       image_util_retm_if((image_handle == NULL), "Invalid image handle");
+       unsigned int i = 0;
+
+       image_util_fenter();
+       image_util_retm_if(handle == NULL || handle->sources == NULL, "Invalid handle");
 
-       if (handle->image_type == IMAGE_UTIL_GIF)
-               mm_util_gif_encode_destroy(image_handle);
+       for(i = 0; i < handle->source_count; i++) {
+               IMAGE_UTIL_SAFE_FREE(handle->sources[i]);
+       }
+       IMAGE_UTIL_SAFE_FREE(handle->sources);
 
-       IMAGE_UTIL_SAFE_FREE(image_handle);
+       image_util_fleave();
 }
 
 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_fenter();
        image_util_retvm_if(handle == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid handle");
@@ -72,35 +82,22 @@ int image_util_encode_create(image_util_type_e image_type, image_util_encode_h *
        image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
 
        _handle->image_type = image_type;
-       _handle->src_buffer = NULL;
        _handle->dst_buffer = NULL;
        _handle->path = NULL;
-       _handle->image_h = NULL;
        _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;
 
-       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;
-               }
+       memset(&_handle->src, 0, sizeof(mm_image_info_s));
+       _handle->src.color = IMAGE_UTIL_COLORSPACE_RGBA8888;
+       _handle->source_count = 0;
+       __allocate_source_buffer(_handle);
 
-               _handle->image_h = (void *) _image_handle;
+       if (_handle->image_type == IMAGE_UTIL_GIF) {
+               err = mm_util_gif_encode_create(&_handle->image_h);
+               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_util_encode_h) _handle;
@@ -113,53 +110,27 @@ int image_util_encode_set_resolution(image_util_encode_h handle, unsigned long w
        int err = IMAGE_UTIL_ERROR_NONE;
        encode_s *_handle = (encode_s *) handle;
 
-       image_util_retvm_if(_handle->image_h == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid parameter");
        image_util_retvm_if((width == 0 || height == 0), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid resolution");
 
-       switch (_handle->image_type) {
-       case IMAGE_UTIL_JPEG:
-       case IMAGE_UTIL_PNG:
-       case IMAGE_UTIL_BMP:
-               {
-                       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:
-               {
-                       mm_gif_file_h gif_data = (mm_gif_file_h)_handle->image_h;
-
-                       image_util_retvm_if((width > INT_MAX) || (height > INT_MAX), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid resolution");
-
-                       if (_handle->current_resolution_count == 0) {
-                               _handle->width = width;
-                               _handle->height = height;
-                               mm_util_gif_encode_set_resolution(gif_data, width, height);
-                       }
-                       mm_image_info_s * frame = NULL;
-                       err = _image_util_encode_get_gif_frame(gif_data, _handle->current_resolution_count, &frame);
-                       image_util_retvm_if((err != IMAGE_UTIL_ERROR_NONE), err, "_image_util_encode_get_gif_frame failed %d", err);
-
-                       _handle->current_resolution_count++;
-
-                       return err;
+       /* multi-src for a-gif */
+       if (_handle->image_type == IMAGE_UTIL_GIF) {
+               if (_handle->source_count <= _handle->current_resolution_count) {
+                       err = __allocate_source_buffer(_handle);
+                       image_util_retvm_if(err != IMAGE_UTIL_ERROR_NONE, err, "__allocate_source_buffer is failed");
                }
-               break;
-       default:
-               err = IMAGE_UTIL_ERROR_INVALID_PARAMETER;
-               break;
+               _handle->sources[_handle->current_resolution_count]->width = width;
+               _handle->sources[_handle->current_resolution_count]->height = height;
+               _handle->current_resolution_count++;
+       } else {
+               _handle->src.width = width;
+               _handle->src.height = height;
        }
 
-       _handle->width = width;
-       _handle->height = height;
-
        return err;
 }
 
 int image_util_encode_set_colorspace(image_util_encode_h handle, image_util_colorspace_e colorspace)
 {
-       int err = IMAGE_UTIL_ERROR_NONE;
        encode_s *_handle = (encode_s *) handle;
 
        IMAGE_UTIL_TYPE_CHECK(_handle->image_type);
@@ -167,14 +138,13 @@ int image_util_encode_set_colorspace(image_util_encode_h handle, image_util_colo
        image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
        image_util_retvm_if((is_supported_colorspace(colorspace, _handle->image_type) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
 
-       _handle->colorspace = colorspace;
+       _handle->src.color = colorspace;
 
-       return err;
+       return IMAGE_UTIL_ERROR_NONE;
 }
 
 int image_util_encode_set_quality(image_util_encode_h handle, int quality)
 {
-       int err = IMAGE_UTIL_ERROR_NONE;
        encode_s *_handle = (encode_s *) handle;
 
        IMAGE_UTIL_SUPPORT_TYPE_CHECK(_handle->image_type, IMAGE_UTIL_JPEG);
@@ -183,12 +153,11 @@ int image_util_encode_set_quality(image_util_encode_h handle, int quality)
 
        _handle->quality = quality;
 
-       return err;
+       return IMAGE_UTIL_ERROR_NONE;
 }
 
 int image_util_encode_set_png_compression(image_util_encode_h handle, image_util_png_compression_e compression)
 {
-       int err = IMAGE_UTIL_ERROR_NONE;
        encode_s *_handle = (encode_s *) handle;
 
        IMAGE_UTIL_SUPPORT_TYPE_CHECK(_handle->image_type, IMAGE_UTIL_PNG);
@@ -197,29 +166,25 @@ int image_util_encode_set_png_compression(image_util_encode_h handle, image_util
 
        _handle->compression = compression;
 
-       return err;
+       return IMAGE_UTIL_ERROR_NONE;
 }
 
 int image_util_encode_set_gif_frame_delay_time(image_util_encode_h handle, unsigned long long delay_time)
 {
        int err = IMAGE_UTIL_ERROR_NONE;
        encode_s *_handle = (encode_s *) handle;
-       mm_gif_file_h gif_data = NULL;
 
        IMAGE_UTIL_SUPPORT_TYPE_CHECK(_handle->image_type, IMAGE_UTIL_GIF);
 
-       gif_data = (mm_gif_file_h) _handle->image_h;
-       image_util_retvm_if(gif_data == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid gif data");
-
        image_util_retvm_if((delay_time > INT_MAX), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid delay time");
 
-       mm_image_info_s * frame = NULL;
-       err = _image_util_encode_get_gif_frame(gif_data, _handle->current_delay_count, &frame);
-       image_util_retvm_if((err != IMAGE_UTIL_ERROR_NONE), err, "_image_util_encode_get_gif_frame failed %d", err);
-
-       if (frame != NULL)
-               frame->delay_time = (int)delay_time;
+       /* multi-src for a-gif */
+       if (_handle->source_count <= _handle->current_delay_count) {
+               err = __allocate_source_buffer(_handle);
+               image_util_retvm_if(err != IMAGE_UTIL_ERROR_NONE, err, "__allocate_source_buffer is failed");
+       }
 
+       _handle->sources[_handle->current_delay_count]->delay_time = (int)delay_time;
        _handle->current_delay_count++;
 
        return err;
@@ -232,25 +197,16 @@ int image_util_encode_set_input_buffer(image_util_encode_h handle, const unsigne
 
        image_util_retvm_if((src_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid input buffer");
 
-       /* initialize buffer and value for source buffer */
+       /* multi-src for a-gif */
        if (_handle->image_type == IMAGE_UTIL_GIF) {
-               mm_gif_file_h gif_data = (mm_gif_file_h) _handle->image_h;
-               mm_image_info_s * frame = NULL;
-               image_util_retvm_if(gif_data == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid gif data");
-
-               err = _image_util_encode_get_gif_frame(gif_data, _handle->current_buffer_count, &frame);
-               image_util_retvm_if((err != IMAGE_UTIL_ERROR_NONE), err, "_image_util_encode_get_gif_frame failed %d", err);
-
-               if (frame != NULL)
-                       frame->data = (void *)src_buffer;;
-
+               if (_handle->source_count <= _handle->current_buffer_count) {
+                       err = __allocate_source_buffer(_handle);
+                       image_util_retvm_if(err != IMAGE_UTIL_ERROR_NONE, err, "__allocate_source_buffer is failed");
+               }
+               _handle->sources[_handle->current_buffer_count]->data = (void *)src_buffer;
                _handle->current_buffer_count++;
        } else {
-               if (_handle->src_buffer == NULL)
-                       _handle->src_buffer = (void *)calloc(1, sizeof(void *));
-               image_util_retvm_if(_handle->src_buffer == NULL, IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "calloc fail");
-
-               _handle->src_buffer[_handle->current_buffer_count] = (void *)src_buffer;
+               _handle->src.data = (void *)src_buffer;
        }
 
        return err;
@@ -258,7 +214,6 @@ int image_util_encode_set_input_buffer(image_util_encode_h handle, const unsigne
 
 int image_util_encode_set_output_path(image_util_encode_h handle, const char *path)
 {
-       int err = IMAGE_UTIL_ERROR_NONE;
        encode_s *_handle = (encode_s *) handle;
 
        image_util_retvm_if(!IMAGE_UTIL_STRING_VALID(path), IMAGE_UTIL_ERROR_NO_SUCH_FILE, "Invalid path");
@@ -271,12 +226,11 @@ int image_util_encode_set_output_path(image_util_encode_h handle, const char *pa
        _handle->path = g_strndup(path, strlen(path));
        image_util_retvm_if(_handle->path == NULL, IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
 
-       return err;
+       return IMAGE_UTIL_ERROR_NONE;
 }
 
 int image_util_encode_set_output_buffer(image_util_encode_h handle, unsigned char **dst_buffer)
 {
-       int err = IMAGE_UTIL_ERROR_NONE;
        encode_s *_handle = (encode_s *) handle;
 
        image_util_retvm_if(dst_buffer == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid output buffer");
@@ -285,86 +239,54 @@ int image_util_encode_set_output_buffer(image_util_encode_h handle, unsigned cha
 
        _handle->dst_buffer = (void **)dst_buffer;
 
-       return err;
+       return IMAGE_UTIL_ERROR_NONE;
 }
 
 static int _image_util_encode_internal(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");
+       image_util_retvm_if((_handle->image_type != IMAGE_UTIL_GIF && __is_invalid_image_info(_handle->src)), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid input");
+       image_util_retvm_if((_handle->image_type == IMAGE_UTIL_GIF && (_handle->sources == NULL || __is_invalid_image_info(*_handle->sources[0]))), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid input");
 
        switch (_handle->image_type) {
        case IMAGE_UTIL_JPEG:
                {
-                       mm_image_info_s *jpeg_data = (mm_image_info_s *) _handle->image_h;
-                       size_t size = 0;
-
-                       jpeg_data->data = _handle->src_buffer[0];
-                       jpeg_data->color = TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_JPEG);
-
                        if (_handle->path)
-                               err = mm_util_jpeg_encode_to_file(jpeg_data, _handle->quality, _handle->path);
+                               err = mm_util_jpeg_encode_to_file(&_handle->src, _handle->quality, _handle->path);
                        else
-                               err = mm_util_encode_to_jpeg_memory(jpeg_data, _handle->quality, _handle->dst_buffer, &size);
-
-                       if (err == MM_UTIL_ERROR_NONE)
-                               _handle->dst_size = (unsigned long long)size;
+                               err = mm_util_encode_to_jpeg_memory(&_handle->src, _handle->quality, _handle->dst_buffer, &_handle->dst_size);
                }
                break;
        case IMAGE_UTIL_PNG:
                {
-                       mm_image_info_s *png_data = (mm_image_info_s *) _handle->image_h;
-                       size_t size = 0;
-
-                       png_data->data = _handle->src_buffer[0];
-
                        if (_handle->path)
-                               err = mm_util_encode_to_png_file(png_data, _handle->compression, _handle->path);
+                               err = mm_util_encode_to_png_file(&_handle->src, _handle->compression, _handle->path);
                        else
-                               err = mm_util_encode_to_png_memory(png_data, _handle->compression, _handle->dst_buffer, &size);
-
-                       if (err == MM_UTIL_ERROR_NONE)
-                               _handle->dst_size = (unsigned long long)size;
+                               err = mm_util_encode_to_png_memory(&_handle->src, _handle->compression, _handle->dst_buffer, &_handle->dst_size);
                }
                break;
        case IMAGE_UTIL_GIF:
                {
-                       mm_gif_file_h gif_data = (mm_gif_file_h)_handle->image_h;
-                       size_t encoded_buffer_size = 0;
-
-                       image_util_debug("[Count] buffer:%d, resolution:%d, delay:%d", _handle->current_buffer_count, _handle->current_resolution_count, _handle->current_delay_count);
-                       if ((_handle->current_buffer_count > 1) && ((_handle->current_buffer_count != _handle->current_resolution_count) || (_handle->current_buffer_count != _handle->current_delay_count))) {
+                       image_util_debug("[Count] source_count:%u, buffer:%u, resolution:%u, delay:%u", _handle->source_count, _handle->current_buffer_count, _handle->current_resolution_count, _handle->current_delay_count);
+                       if ((_handle->source_count > 1) && ((_handle->source_count != _handle->current_buffer_count) || (_handle->source_count != _handle->current_resolution_count) || (_handle->source_count != _handle->current_delay_count))) {
                                image_util_error("Total frame count does not match with the data set, for animated gif encoding");
                                return IMAGE_UTIL_ERROR_INVALID_OPERATION;
-                       } else if ((_handle->current_buffer_count > 0) && ((_handle->current_buffer_count != _handle->current_resolution_count))) {
-                               image_util_error("Total frame count does not match with the data set, for gif encoding");
-                               return IMAGE_UTIL_ERROR_INVALID_OPERATION;
                        }
 
                        if (_handle->path)
-                               err = mm_util_encode_to_gif_file(gif_data, _handle->path);
+                               err = mm_util_encode_to_gif_file(_handle->sources, _handle->source_count, _handle->path);
                        else
-                               err = mm_util_encode_to_gif_memory(gif_data, _handle->dst_buffer, &encoded_buffer_size);
-
-                       if (encoded_buffer_size != 0)
-                               _handle->dst_size = (unsigned long long)encoded_buffer_size;
+                               err = mm_util_encode_to_gif_memory(_handle->sources, _handle->source_count, _handle->dst_buffer, &_handle->dst_size);
                }
                break;
        case IMAGE_UTIL_BMP:
                {
-                       mm_image_info_s *bmp_data = (mm_image_info_s *) _handle->image_h;
-                       size_t size = 0;
-
-                       bmp_data->data = _handle->src_buffer[0];
-
                        if (_handle->path)
-                               err = mm_util_encode_bmp_to_file(bmp_data, _handle->path);
+                               err = mm_util_encode_bmp_to_file(&_handle->src, _handle->path);
                        else
-                               err = mm_util_encode_bmp_to_memory(bmp_data, _handle->dst_buffer, &size);
-
-                       if (err == MM_UTIL_ERROR_NONE)
-                               _handle->dst_size = size;
+                               err = mm_util_encode_bmp_to_memory(&_handle->src, _handle->dst_buffer, &_handle->dst_size);
                }
                break;
        default:
@@ -372,6 +294,8 @@ static int _image_util_encode_internal(encode_s * _handle)
                break;
        }
 
+       __free_source_buffer(_handle);
+
        return _image_error_capi(err);
 }
 
@@ -380,9 +304,8 @@ int image_util_encode_run(image_util_encode_h handle, unsigned long long *size)
        int err = IMAGE_UTIL_ERROR_NONE;
        encode_s *_handle = (encode_s *) handle;
 
-       image_util_retvm_if((_handle->path == NULL && _handle->dst_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid output");
-       image_util_retvm_if(_handle->image_type != IMAGE_UTIL_GIF && _handle->src_buffer == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid input");
-       image_util_retvm_if((_image_util_check_resolution(_handle->width, _handle->height) == false), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid resolution");
+       image_util_retvm_if(_handle == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
+       image_util_retvm_if(size == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
        err = _image_util_encode_internal(_handle);
        image_util_retvm_if((err != IMAGE_UTIL_ERROR_NONE), err, "_image_util_encode_internal failed");
@@ -435,9 +358,7 @@ int image_util_encode_run_async(image_util_encode_h handle, image_util_encode_co
        int err = IMAGE_UTIL_ERROR_NONE;
        encode_s *_handle = (encode_s *) handle;
 
-       image_util_retvm_if((_handle->path == NULL && _handle->dst_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid output");
-       image_util_retvm_if(_handle->image_type != IMAGE_UTIL_GIF && _handle->src_buffer == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid input");
-       image_util_retvm_if((_image_util_check_resolution(_handle->width, _handle->height) == false), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid resolution");
+       image_util_retvm_if(_handle == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
        image_util_retvm_if((completed_cb == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid callback");
        image_util_retvm_if((_handle->thread != NULL), IMAGE_UTIL_ERROR_INVALID_OPERATION, "The thread is alread running");
 
@@ -467,16 +388,15 @@ int image_util_encode_destroy(image_util_encode_h handle)
 
        image_util_debug("image_util_encode_destroy");
 
-       _image_util_encode_destroy_image_handle(_handle);
-
        /* g_thread_exit(handle->thread); */
        if (_handle->thread) {
                g_thread_join(_handle->thread);
                IMAGE_UTIL_SAFE_FREE(_handle->_encode_cb);
        }
 
+       __free_source_buffer(_handle);
+
        IMAGE_UTIL_SAFE_FREE(_handle->path);
-       IMAGE_UTIL_SAFE_FREE(_handle->src_buffer);
        IMAGE_UTIL_SAFE_FREE(_handle);
 
        return err;
index a3c4f44..3a6dd81 100755 (executable)
@@ -165,7 +165,6 @@ int image_util_frame_set_frame(image_util_frame_h frame_h, unsigned char *buffer
        frame->data = calloc(1, size);
        if (frame->data == NULL) {
                image_util_error("Memory allocation failed");
-               mm_util_gif_image_destory(frame);
                return IMAGE_UTIL_ERROR_OUT_OF_MEMORY;
        }
 
@@ -197,8 +196,9 @@ int image_util_encode_add_frame(image_util_encode_h encode_h, image_util_frame_h
        mm_image_info_s *frame = (mm_image_info_s *)frame_h;
        image_util_retvm_if((encode->image_h == NULL), IMAGE_UTIL_ERROR_INVALID_OPERATION, "The image handle is wrong");
        image_util_retvm_if((encode->image_type != IMAGE_UTIL_GIF), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "The image type(%d) is not supported.", encode->image_type);
-       image_util_retvm_if((frame->width == 0) || (frame->height == 0), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid parameter");
-       image_util_retvm_if(frame->data == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       image_util_retvm_if((frame->width == 0) || (frame->height == 0), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid frame");
+//     image_util_retvm_if((frame->width != encode->width) || (frame->height != encode->height), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid frame");
+       image_util_retvm_if(frame->data == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid frame");
 
        mm_gif_file_h gif_data = (mm_gif_file_h)encode->image_h;