#include <mm_util_png.h>
#include <mm_util_gif.h>
#include <mm_util_bmp.h>
+#include <mm_util_image.h>
#include <image_util.h>
#include <image_util_private.h>
image_util_retvm_if(err != IMAGE_UTIL_ERROR_NONE, err, "__allocate_source_buffer is failed");
}
_handle->gif_encode_info.sources[_handle->gif_encode_info.current_buffer_count]->data = (void *)src_buffer;
+ _handle->gif_encode_info.sources[_handle->gif_encode_info.current_buffer_count]->size = TEMP_DATA_SIZE;
_handle->gif_encode_info.current_buffer_count++;
} else {
_handle->src.data = (void *)src_buffer;
static int _image_util_encode_internal(encode_s * _handle)
{
int err = MM_UTIL_ERROR_NONE;
+ mm_util_image_h _src = NULL;
- 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->gif_encode_info.sources == NULL || __is_invalid_image_info(*_handle->gif_encode_info.sources[0]))), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid input");
+ image_util_retvm_if(!_handle, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid _handle");
+ image_util_retvm_if((_handle->image_type != IMAGE_UTIL_GIF && __is_invalid_image_info(_handle->src)), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid image");
+ image_util_retvm_if((_handle->image_type == IMAGE_UTIL_GIF && (!_handle->gif_encode_info.sources || __is_invalid_image_info(*_handle->gif_encode_info.sources[0]))), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid gif");
+
+ image_util_fenter();
+
+ if (_handle->image_type != IMAGE_UTIL_GIF) {
+ err = mm_image_create_image(_handle->src.width, _handle->src.height, _handle->src.color, _handle->src.data, TEMP_DATA_SIZE, &_src);
+ image_util_retvm_if(err != MM_UTIL_ERROR_NONE, _image_error_capi(err), "fail to mm_image_create_image");
+ }
switch (_handle->image_type) {
case IMAGE_UTIL_JPEG:
{
if (_handle->path)
- err = mm_util_jpeg_encode_to_file(&_handle->src, _handle->quality, _handle->path);
+ err = mm_util_jpeg_encode_to_file(_src, _handle->quality, _handle->path);
else
- err = mm_util_encode_to_jpeg_memory(&_handle->src, _handle->quality, _handle->dst_buffer, &_handle->dst_size);
+ err = mm_util_encode_to_jpeg_memory(_src, _handle->quality, _handle->dst_buffer, &_handle->dst_size);
}
break;
case IMAGE_UTIL_PNG:
{
if (_handle->path)
- err = mm_util_encode_to_png_file(&_handle->src, _handle->compression, _handle->path);
+ err = mm_util_encode_to_png_file(_src, _handle->compression, _handle->path);
else
- err = mm_util_encode_to_png_memory(&_handle->src, _handle->compression, _handle->dst_buffer, &_handle->dst_size);
+ err = mm_util_encode_to_png_memory(_src, _handle->compression, _handle->dst_buffer, &_handle->dst_size);
}
break;
case IMAGE_UTIL_GIF:
}
if (_handle->path)
- err = mm_util_encode_to_gif_file(_handle->gif_encode_info.sources, _handle->gif_encode_info.source_count, _handle->path);
+ err = mm_util_encode_to_gif_file((mm_util_image_h *)_handle->gif_encode_info.sources, _handle->gif_encode_info.source_count, _handle->path);
else
- err = mm_util_encode_to_gif_memory(_handle->gif_encode_info.sources, _handle->gif_encode_info.source_count, _handle->dst_buffer, &_handle->dst_size);
+ err = mm_util_encode_to_gif_memory((mm_util_image_h *)_handle->gif_encode_info.sources, _handle->gif_encode_info.source_count, _handle->dst_buffer, &_handle->dst_size);
}
break;
case IMAGE_UTIL_BMP:
{
if (_handle->path)
- err = mm_util_encode_bmp_to_file(&_handle->src, _handle->path);
+ err = mm_util_encode_bmp_to_file(_src, _handle->path);
else
- err = mm_util_encode_bmp_to_memory(&_handle->src, _handle->dst_buffer, &_handle->dst_size);
+ err = mm_util_encode_bmp_to_memory(_src, _handle->dst_buffer, &_handle->dst_size);
}
break;
default:
break;
}
- __free_source_buffer(_handle);
+ mm_image_destroy_image(_src);
+ __free_source_buffer(_handle); /* free gif_encode_info.sources */
+
+ image_util_fleave();
return _image_error_capi(err);
}