Separate gif encode info from encode_s 35/191335/1
authorhj kim <backto.kim@samsung.com>
Tue, 16 Oct 2018 06:23:32 +0000 (15:23 +0900)
committerhj kim <backto.kim@samsung.com>
Tue, 16 Oct 2018 06:23:32 +0000 (15:23 +0900)
Change-Id: If5685da8dfbd96c70b02a45f4a0bc0c807290ea2

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

index c040907..dce2845 100755 (executable)
@@ -134,20 +134,24 @@ typedef struct {
 } encode_cb_s;
 
 typedef struct {
-       image_util_type_e image_type;
-       mm_image_info_s src;
        mm_image_info_s **sources;
        unsigned int source_count;
+       void *image_h;
+       size_t gif_encode_size;
+       unsigned int current_buffer_count;
+       unsigned int current_resolution_count;
+       unsigned int current_delay_count;
+} gif_encode_s;
+
+typedef struct {
+       image_util_type_e image_type;
+       mm_image_info_s src;
        void **dst_buffer;
        size_t dst_size;
-       size_t gif_encode_size;
        char *path;
-       void *image_h;
        int quality;
        image_util_png_compression_e compression;
-       unsigned int current_buffer_count;
-       unsigned int current_resolution_count;
-       unsigned int current_delay_count;
+       gif_encode_s gif_encode_info;
        encode_cb_s *_encode_cb;
 
        /* for async */
index 15b682b..075421d 100755 (executable)
@@ -36,20 +36,20 @@ static int __allocate_source_buffer(encode_s *handle)
        image_util_fenter();
        image_util_retvm_if(handle == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid handle");
 
-       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");
+       if (handle->gif_encode_info.sources == NULL) {
+               handle->gif_encode_info.sources = calloc(1, sizeof(mm_image_info_s *));
+               image_util_retvm_if((handle->gif_encode_info.sources == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+               handle->gif_encode_info.sources[0] = calloc(1, sizeof(mm_image_info_s));
+               image_util_retvm_if((handle->gif_encode_info.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");
+               handle->gif_encode_info.sources = realloc(handle->gif_encode_info.sources, sizeof(mm_image_info_s *) * (handle->gif_encode_info.source_count + 1));
+               image_util_retvm_if((handle->gif_encode_info.sources == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+               handle->gif_encode_info.sources[handle->gif_encode_info.source_count] = calloc(1, sizeof(mm_image_info_s));
+               image_util_retvm_if((handle->gif_encode_info.sources[handle->gif_encode_info.source_count] == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
        }
 
-       handle->sources[handle->source_count]->color = IMAGE_UTIL_COLORSPACE_RGBA8888;
-       handle->source_count++;
+       handle->gif_encode_info.sources[handle->gif_encode_info.source_count]->color = IMAGE_UTIL_COLORSPACE_RGBA8888;
+       handle->gif_encode_info.source_count++;
 
        image_util_fleave();
        return IMAGE_UTIL_ERROR_NONE;
@@ -60,12 +60,12 @@ static void __free_source_buffer(encode_s *handle)
        unsigned int i = 0;
 
        image_util_fenter();
-       image_util_retm_if(handle == NULL || handle->sources == NULL, "Invalid handle");
+       image_util_retm_if(handle == NULL || handle->gif_encode_info.sources == NULL, "Invalid handle");
 
-       for(i = 0; i < handle->source_count; i++) {
-               IMAGE_UTIL_SAFE_FREE(handle->sources[i]);
+       for(i = 0; i < handle->gif_encode_info.source_count; i++) {
+               IMAGE_UTIL_SAFE_FREE(handle->gif_encode_info.sources[i]);
        }
-       IMAGE_UTIL_SAFE_FREE(handle->sources);
+       IMAGE_UTIL_SAFE_FREE(handle->gif_encode_info.sources);
 
        image_util_fleave();
 }
@@ -84,20 +84,23 @@ int image_util_encode_create(image_util_type_e image_type, image_util_encode_h *
        _handle->image_type = image_type;
        _handle->dst_buffer = NULL;
        _handle->path = NULL;
-       _handle->current_buffer_count = 0;
-       _handle->current_resolution_count = 0;
-       _handle->current_delay_count = 0;
        _handle->quality = 75;
        _handle->compression = IMAGE_UTIL_PNG_COMPRESSION_6;
 
        memset(&_handle->src, 0, sizeof(mm_image_info_s));
+       memset(&_handle->gif_encode_info, 0, sizeof(gif_encode_s));
+
        _handle->src.color = IMAGE_UTIL_COLORSPACE_RGBA8888;
-       _handle->source_count = 0;
 
        if (_handle->image_type == IMAGE_UTIL_GIF) {
+               _handle->gif_encode_info.source_count = 0;
+               _handle->gif_encode_info.current_buffer_count = 0;
+               _handle->gif_encode_info.current_resolution_count = 0;
+               _handle->gif_encode_info.current_delay_count = 0;
+
                __allocate_source_buffer(_handle);
 
-               err = mm_util_gif_encode_create(&_handle->image_h);
+               err = mm_util_gif_encode_create(&_handle->gif_encode_info.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);
        }
 
@@ -115,13 +118,13 @@ int image_util_encode_set_resolution(image_util_encode_h handle, unsigned long w
 
        /* multi-src for a-gif */
        if (_handle->image_type == IMAGE_UTIL_GIF) {
-               if (_handle->source_count <= _handle->current_resolution_count) {
+               if (_handle->gif_encode_info.source_count <= _handle->gif_encode_info.current_resolution_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_resolution_count]->width = width;
-               _handle->sources[_handle->current_resolution_count]->height = height;
-               _handle->current_resolution_count++;
+               _handle->gif_encode_info.sources[_handle->gif_encode_info.current_resolution_count]->width = width;
+               _handle->gif_encode_info.sources[_handle->gif_encode_info.current_resolution_count]->height = height;
+               _handle->gif_encode_info.current_resolution_count++;
        } else {
                _handle->src.width = width;
                _handle->src.height = height;
@@ -180,13 +183,13 @@ int image_util_encode_set_gif_frame_delay_time(image_util_encode_h handle, unsig
        image_util_retvm_if((delay_time > INT_MAX), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid delay time");
 
        /* multi-src for a-gif */
-       if (_handle->source_count <= _handle->current_delay_count) {
+       if (_handle->gif_encode_info.source_count <= _handle->gif_encode_info.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++;
+       _handle->gif_encode_info.sources[_handle->gif_encode_info.current_delay_count]->delay_time = (int)delay_time;
+       _handle->gif_encode_info.current_delay_count++;
 
        return err;
 }
@@ -200,12 +203,12 @@ int image_util_encode_set_input_buffer(image_util_encode_h handle, const unsigne
 
        /* multi-src for a-gif */
        if (_handle->image_type == IMAGE_UTIL_GIF) {
-               if (_handle->source_count <= _handle->current_buffer_count) {
+               if (_handle->gif_encode_info.source_count <= _handle->gif_encode_info.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++;
+               _handle->gif_encode_info.sources[_handle->gif_encode_info.current_buffer_count]->data = (void *)src_buffer;
+               _handle->gif_encode_info.current_buffer_count++;
        } else {
                _handle->src.data = (void *)src_buffer;
        }
@@ -249,7 +252,7 @@ static int _image_util_encode_internal(encode_s * _handle)
 
        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");
+       image_util_retvm_if((_handle->image_type == IMAGE_UTIL_GIF && (_handle->gif_encode_info.sources == NULL || __is_invalid_image_info(*_handle->gif_encode_info.sources[0]))), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid input");
 
        switch (_handle->image_type) {
        case IMAGE_UTIL_JPEG:
@@ -270,16 +273,16 @@ static int _image_util_encode_internal(encode_s * _handle)
                break;
        case IMAGE_UTIL_GIF:
                {
-                       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_debug("[Count] source_count:%u, buffer:%u, resolution:%u, delay:%u", _handle->gif_encode_info.source_count, _handle->gif_encode_info.current_buffer_count, _handle->gif_encode_info.current_resolution_count, _handle->gif_encode_info.current_delay_count);
+                       if ((_handle->gif_encode_info.source_count > 1) && ((_handle->gif_encode_info.source_count != _handle->gif_encode_info.current_buffer_count) || (_handle->gif_encode_info.source_count != _handle->gif_encode_info.current_resolution_count) || (_handle->gif_encode_info.source_count != _handle->gif_encode_info.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;
                        }
 
                        if (_handle->path)
-                               err = mm_util_encode_to_gif_file(_handle->sources, _handle->source_count, _handle->path);
+                               err = mm_util_encode_to_gif_file(_handle->gif_encode_info.sources, _handle->gif_encode_info.source_count, _handle->path);
                        else
-                               err = mm_util_encode_to_gif_memory(_handle->sources, _handle->source_count, _handle->dst_buffer, &_handle->dst_size);
+                               err = mm_util_encode_to_gif_memory(_handle->gif_encode_info.sources, _handle->gif_encode_info.source_count, _handle->dst_buffer, &_handle->dst_size);
                }
                break;
        case IMAGE_UTIL_BMP:
index 3a6dd81..77f7ed2 100755 (executable)
@@ -194,19 +194,19 @@ int image_util_encode_add_frame(image_util_encode_h encode_h, image_util_frame_h
 
        encode_s *encode = (encode_s *)encode_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->gif_encode_info.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 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;
+       mm_gif_file_h gif_data = (mm_gif_file_h)encode->gif_encode_info.image_h;
 
-       if (encode->current_buffer_count == 0) {
+       if (encode->gif_encode_info.current_buffer_count == 0) {
                if (encode->path)
                        ret = mm_util_gif_encode_set_file(gif_data, encode->path);
                else
-                       ret = mm_util_gif_encode_set_mem(gif_data, encode->dst_buffer, &encode->gif_encode_size);
+                       ret = mm_util_gif_encode_set_mem(gif_data, encode->dst_buffer, &encode->gif_encode_info.gif_encode_size);
        }
        if (ret != MM_UTIL_ERROR_NONE) {
                image_util_error("mm_util_gif_encode_add_image is failed(%d).", ret);
@@ -218,7 +218,7 @@ int image_util_encode_add_frame(image_util_encode_h encode_h, image_util_frame_h
                image_util_error("mm_util_gif_encode_add_image is failed(%d).", ret);
                return _image_error_capi(ret);
        }
-       encode->current_buffer_count++;
+       encode->gif_encode_info.current_buffer_count++;
 
        return IMAGE_UTIL_ERROR_NONE;
 }
@@ -230,10 +230,10 @@ int image_util_encode_save(image_util_encode_h encode_h, unsigned long long *siz
        image_util_retvm_if((encode_h == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
 
        encode_s *encode = (encode_s *)encode_h;
-       image_util_retvm_if((encode->image_h == NULL), IMAGE_UTIL_ERROR_INVALID_OPERATION, "The image handle is wrong");
+       image_util_retvm_if((encode->gif_encode_info.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);
 
-       mm_gif_file_h gif_data = (mm_gif_file_h)encode->image_h;
+       mm_gif_file_h gif_data = (mm_gif_file_h)encode->gif_encode_info.image_h;
 
        ret = mm_util_gif_encode_save(gif_data);
        if (ret != MM_UTIL_ERROR_NONE) {
@@ -242,8 +242,8 @@ int image_util_encode_save(image_util_encode_h encode_h, unsigned long long *siz
                return _image_error_capi(ret);
        }
 
-       *size = (unsigned long long)encode->gif_encode_size;
-       encode->current_buffer_count = 0;
+       *size = (unsigned long long)encode->gif_encode_info.gif_encode_size;
+       encode->gif_encode_info.current_buffer_count = 0;
 
        return IMAGE_UTIL_ERROR_NONE;
 }