static int _image_util_decode_internal(decode_s * _handle, unsigned long *res_width, unsigned long *res_height, size_t *res_size)
{
int err = MM_UTIL_ERROR_NONE;
- unsigned long _width = 0;
- unsigned long _height = 0;
- size_t _size = 0;
-
image_util_fenter();
image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "invalid parameter");
image_util_retvm_if(res_height == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid res_height");
image_util_retvm_if(res_size == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid res_size");
+ mm_image_info_s image_info;
+ memset(&image_info, 0, sizeof(mm_image_info_s));
+
switch (_handle->image_type) {
case IMAGE_UTIL_JPEG:
{
- mm_image_info_s jpeg_data;
- memset(&jpeg_data, 0, sizeof(mm_image_info_s));
-
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], &image_info);
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);
-
- if (err == MM_UTIL_ERROR_NONE) {
- *(_handle->dst_buffer) = jpeg_data.data;
- _size = jpeg_data.size;
- _width = jpeg_data.width;
- _height = jpeg_data.height;
- } else {
- image_util_error("fail to decode jpeg [%d]", err);
- }
+ 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], &image_info);
}
break;
case IMAGE_UTIL_PNG:
{
- mm_image_info_s png_data;
- memset(&png_data, 0, sizeof(mm_image_info_s));
-
if (_handle->path)
- err = mm_util_decode_from_png_file(_handle->path, &png_data);
+ err = mm_util_decode_from_png_file(_handle->path, &image_info);
else
- 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;
- _size = png_data.size;
- _width = png_data.width;
- _height = png_data.height;
- } else {
- image_util_error("fail to decode png [%d]", err);
- }
+ err = mm_util_decode_from_png_memory(_handle->src_buffer[0], (size_t)_handle->src_size, &image_info);
}
break;
case IMAGE_UTIL_GIF:
{
- 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(_handle->path, &image_info);
else
- 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;
- _size = gif_data.size;
- _width = gif_data.width;
- _height = gif_data.height;
- } else {
- image_util_error("fail to decode gif [%d]", err);
- }
+ err = mm_util_decode_from_gif_memory(_handle->src_buffer[0], &image_info);
}
break;
case IMAGE_UTIL_BMP:
{
- mm_image_info_s bmp_data;
- memset(&bmp_data, 0, sizeof(mm_image_info_s));
-
if (_handle->path)
- err = mm_util_decode_from_bmp_file(_handle->path, &bmp_data);
+ err = mm_util_decode_from_bmp_file(_handle->path, &image_info);
else
- 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;
- _size = bmp_data.size;
- _width = bmp_data.width;
- _height = bmp_data.height;
- } else {
- image_util_error("fail to decode bmp [%d]", err);
- }
+ err = mm_util_decode_from_bmp_memory(_handle->src_buffer[0], (size_t)_handle->src_size, &image_info);
}
break;
default:
break;
}
- *res_width = _width;
- *res_height = _height;
- *res_size = _size;
+ if (err == MM_UTIL_ERROR_NONE) {
+ *(_handle->dst_buffer) = image_info.data;
+ *res_width = image_info.width;
+ *res_height = image_info.height;
+ *res_size = image_info.size;
+ } else {
+ *(_handle->dst_buffer) = NULL;
+ *res_width = 0;
+ *res_height = 0;
+ *res_size = 0;
+ image_util_error("fail to decode image [%d]", err);
+ }
image_util_debug("dst_buffer(%p) width (%lu) height (%lu) dst_size (%zu)", *(_handle->dst_buffer), *res_width, *res_height, *res_size);