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();
_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;
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;
_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;
}
{
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;
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);