From: Jiyong Min Date: Thu, 21 Sep 2017 00:39:42 +0000 (+0900) Subject: Modify converting to capi error and simplify error type use X-Git-Tag: accepted/tizen/unified/20170925.150735^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F98%2F151398%2F2;p=platform%2Fcore%2Fapi%2Fimage-util.git Modify converting to capi error and simplify error type use (Before using mm & capi error were mixed) Change-Id: I1676408dbc34ff99803d1f3abe55bbbf38e9a456 Signed-off-by: Jiyong Min --- diff --git a/include/image_util_private.h b/include/image_util_private.h index dba02c8..51753d5 100755 --- a/include/image_util_private.h +++ b/include/image_util_private.h @@ -151,15 +151,20 @@ typedef struct { void *frame_h; } frame_s; +typedef enum { + ERR_TYPE_COMMON, + ERR_TYPE_TRANSFORM, + ERR_TYPE_DECODE, + ERR_TYPE_ENCODE, +} image_util_error_type_e; + gboolean is_valid_colorspace(image_util_colorspace_e colorspace); gboolean is_supported_colorspace(image_util_colorspace_e colorspace, image_util_type_e type); unsigned int get_number_of_colorspace(void); int convert_type_of_colorspace(const image_util_colorspace_e colorspace); int convert_type_of_colorspace_with_image_type(const image_util_colorspace_e colorspace, const image_util_type_e type); - -int _convert_image_util_error_code(const char *func, int code); -image_util_error_e _image_util_error_convert(int error); +int _image_error_capi(image_util_error_type_e error_type, int error_code); bool _image_util_check_resolution(int width, int height); /** diff --git a/packaging/capi-media-image-util.spec b/packaging/capi-media-image-util.spec index 6f81b13..5a58bf2 100755 --- a/packaging/capi-media-image-util.spec +++ b/packaging/capi-media-image-util.spec @@ -1,6 +1,6 @@ Name: capi-media-image-util Summary: A Image Utility library in Tizen Native API -Version: 0.1.27 +Version: 0.1.28 Release: 2 Group: Multimedia/API License: Apache-2.0 diff --git a/src/image_util.c b/src/image_util.c index 3f27342..8f96c43 100755 --- a/src/image_util.c +++ b/src/image_util.c @@ -25,7 +25,7 @@ static void _image_util_transform_completed_cb(media_packet_h * dst, int error, image_util_cb_s *_util_cb = (image_util_cb_s *) user_data; if ((_util_cb != NULL) && (_util_cb->image_processing_completed_cb != NULL)) { - error_value = _image_util_error_convert(error); + error_value = _image_error_capi(ERR_TYPE_TRANSFORM, error); _util_cb->image_processing_completed_cb(dst, error_value, _util_cb->user_data); } @@ -40,12 +40,12 @@ static int _image_util_create_transform_handle(transformation_s * handle) err = mm_util_create(&image_h); if (err != MM_UTIL_ERROR_NONE) { image_util_error("Error - mm_util_create"); - return _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_TRANSFORM, err); } handle->image_h = image_h; - return _convert_image_util_error_code(__func__, err); + return IMAGE_UTIL_ERROR_NONE; } int image_util_foreach_supported_jpeg_colorspace(image_util_supported_jpeg_colorspace_cb callback, void *user_data) @@ -91,12 +91,12 @@ int image_util_transform_create(transformation_h * handle) if (err != MM_UTIL_ERROR_NONE) { image_util_error("Error - create transform handle"); IMAGE_UTIL_SAFE_FREE(_handle); - return _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_TRANSFORM, err); } *handle = (transformation_h) _handle; - return _convert_image_util_error_code(__func__, err); + return IMAGE_UTIL_ERROR_NONE; } int image_util_transform_set_hardware_acceleration(transformation_h handle, bool mode) @@ -114,13 +114,13 @@ int image_util_transform_set_hardware_acceleration(transformation_h handle, bool err = mm_util_set_hardware_acceleration(_handle->image_h, mode); if (err != MM_UTIL_ERROR_NONE) { image_util_error("Error - Set hardware_acceleration"); - return _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_TRANSFORM, err); } image_util_debug("Set hardware_acceleration %d", mode); _handle->hardware_acceleration = mode; - return _convert_image_util_error_code(__func__, err); + return IMAGE_UTIL_ERROR_NONE; } int image_util_transform_set_colorspace(transformation_h handle, image_util_colorspace_e colorspace) @@ -135,13 +135,13 @@ int image_util_transform_set_colorspace(transformation_h handle, image_util_colo err = mm_util_set_colorspace_convert(_handle->image_h, colorspace); if (err != MM_UTIL_ERROR_NONE) { image_util_error("Error - Set colorspace convert"); - return _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_TRANSFORM, err); } _handle->colorspace = colorspace; _handle->set_convert = true; - return _convert_image_util_error_code(__func__, err); + return IMAGE_UTIL_ERROR_NONE; } int image_util_transform_set_resolution(transformation_h handle, unsigned int width, unsigned int height) @@ -158,13 +158,13 @@ int image_util_transform_set_resolution(transformation_h handle, unsigned int wi err = mm_util_set_resolution(_handle->image_h, width, height); if (err != MM_UTIL_ERROR_NONE) { image_util_error("Error - Set resolution"); - return _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_TRANSFORM, err); } _handle->width = width; _handle->height = height; _handle->set_resize = true; - return _convert_image_util_error_code(__func__, err); + return IMAGE_UTIL_ERROR_NONE; } int image_util_transform_set_rotation(transformation_h handle, image_util_rotation_e rotation) @@ -179,12 +179,12 @@ int image_util_transform_set_rotation(transformation_h handle, image_util_rotati err = mm_util_set_rotation(_handle->image_h, rotation); if (err != MM_UTIL_ERROR_NONE) { image_util_error("Error - Set rotation"); - return _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_TRANSFORM, err); } _handle->rotation = rotation; _handle->set_rotate = true; - return _convert_image_util_error_code(__func__, err); + return IMAGE_UTIL_ERROR_NONE; } int image_util_transform_set_crop_area(transformation_h handle, unsigned int start_x, unsigned int start_y, unsigned int end_x, unsigned int end_y) @@ -206,7 +206,7 @@ int image_util_transform_set_crop_area(transformation_h handle, unsigned int sta err = mm_util_set_crop_area(_handle->image_h, start_x, start_y, end_x, end_y); if (err != MM_UTIL_ERROR_NONE) { image_util_error("Error - Set crop area"); - return _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_TRANSFORM, err); } _handle->start_x = start_x; _handle->start_y = start_y; @@ -214,23 +214,15 @@ int image_util_transform_set_crop_area(transformation_h handle, unsigned int sta _handle->end_y = end_y; _handle->set_crop = true; - return _convert_image_util_error_code(__func__, err); + return IMAGE_UTIL_ERROR_NONE; } int image_util_transform_get_colorspace(transformation_h handle, image_util_colorspace_e * colorspace) { - int ret = IMAGE_UTIL_ERROR_NONE; transformation_s *_handle = (transformation_s *) handle; - if (_handle == NULL) { - image_util_error("Invalid Handle"); - return IMAGE_UTIL_ERROR_INVALID_PARAMETER; - } - - if (!colorspace) { - image_util_error("colorspace area parameter error"); - return IMAGE_UTIL_ERROR_INVALID_OPERATION; - } + image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((colorspace == NULL), IMAGE_UTIL_ERROR_INVALID_OPERATION, "colorspace parameter error"); if (!_handle->set_convert) { image_util_error("Did not set colorspace before"); @@ -241,23 +233,15 @@ int image_util_transform_get_colorspace(transformation_h handle, image_util_colo *colorspace = _handle->colorspace; - return ret; + return IMAGE_UTIL_ERROR_NONE; } int image_util_transform_get_resolution(transformation_h handle, unsigned int *width, unsigned int *height) { - int ret = IMAGE_UTIL_ERROR_NONE; transformation_s *_handle = (transformation_s *) handle; - if (_handle == NULL) { - image_util_error("Invalid Handle"); - return IMAGE_UTIL_ERROR_INVALID_PARAMETER; - } - - if (!width || !height) { - image_util_error("resolution area parameter error"); - return IMAGE_UTIL_ERROR_INVALID_OPERATION; - } + image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((width == NULL || height == NULL), IMAGE_UTIL_ERROR_INVALID_OPERATION, "width or height parameter error"); if (!_handle->set_resize) { image_util_error("Did not set resolution before"); @@ -269,23 +253,15 @@ int image_util_transform_get_resolution(transformation_h handle, unsigned int *w *width = _handle->width; *height = _handle->height; - return ret; + return IMAGE_UTIL_ERROR_NONE; } int image_util_transform_get_rotation(transformation_h handle, image_util_rotation_e * rotation) { - int ret = IMAGE_UTIL_ERROR_NONE; transformation_s *_handle = (transformation_s *) handle; - if (_handle == NULL) { - image_util_error("Invalid Handle"); - return IMAGE_UTIL_ERROR_INVALID_PARAMETER; - } - - if (!rotation) { - image_util_error("rotation area parameter error"); - return IMAGE_UTIL_ERROR_INVALID_OPERATION; - } + image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((rotation == NULL), IMAGE_UTIL_ERROR_INVALID_OPERATION, "rotation parameter error"); if (!_handle->set_rotate) { image_util_error("Did not set rotation before"); @@ -296,23 +272,15 @@ int image_util_transform_get_rotation(transformation_h handle, image_util_rotati *rotation = _handle->rotation; - return ret; + return IMAGE_UTIL_ERROR_NONE; } int image_util_transform_get_crop_area(transformation_h handle, unsigned int *start_x, unsigned int *start_y, unsigned int *end_x, unsigned int *end_y) { - int ret = IMAGE_UTIL_ERROR_NONE; transformation_s *_handle = (transformation_s *) handle; - if (_handle == NULL) { - image_util_error("Invalid Handle"); - return IMAGE_UTIL_ERROR_INVALID_PARAMETER; - } - - if (!start_x || !start_y || !end_x || !end_y) { - image_util_error("crop area parameter error"); - return IMAGE_UTIL_ERROR_INVALID_OPERATION; - } + image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((start_x == NULL || start_y == NULL || end_x == NULL || end_y == NULL), IMAGE_UTIL_ERROR_INVALID_OPERATION, "crop area parameter error"); if (!_handle->set_crop) { image_util_error("Did not set crop area before"); @@ -324,7 +292,7 @@ int image_util_transform_get_crop_area(transformation_h handle, unsigned int *st *end_x = _handle->end_x; *end_y = _handle->end_y; - return ret; + return IMAGE_UTIL_ERROR_NONE; } int image_util_transform_run(transformation_h handle, media_packet_h src, image_util_transform_completed_cb completed_cb, void *user_data) @@ -352,7 +320,7 @@ int image_util_transform_run(transformation_h handle, media_packet_h src, image_ if (_handle->_util_cb) err = mm_util_transform(_handle->image_h, src, (mm_util_completed_callback) _image_util_transform_completed_cb, (void *)_handle->_util_cb); - return _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_TRANSFORM, err); } int image_util_transform_destroy(transformation_h handle) @@ -372,7 +340,7 @@ int image_util_transform_destroy(transformation_h handle) IMAGE_UTIL_SAFE_FREE(_handle->_util_cb); IMAGE_UTIL_SAFE_FREE(_handle); - return _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_TRANSFORM, err); } int image_util_calculate_buffer_size(int width, int height, image_util_colorspace_e colorspace, unsigned int *size) @@ -384,7 +352,8 @@ int image_util_calculate_buffer_size(int width, int height, image_util_colorspac image_util_retvm_if((size == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "size is null"); err = mm_util_get_image_size(TYPECAST_COLOR(colorspace), width, height, size); - return _convert_image_util_error_code(__func__, err); + + return _image_error_capi(ERR_TYPE_COMMON, err); } int image_util_extract_color_from_memory(const unsigned char *image_buffer, int width, int height, unsigned char *rgb_r, unsigned char *rgb_g, unsigned char *rgb_b) @@ -416,7 +385,7 @@ int image_util_extract_color_from_memory(const unsigned char *image_buffer, int module = NULL; } - return _convert_image_util_error_code(__func__, ret); + return _image_error_capi(ERR_TYPE_COMMON, ret); } int image_util_foreach_supported_colorspace(image_util_type_e image_type, image_util_supported_colorspace_cb callback, void *user_data) diff --git a/src/image_util_decode.c b/src/image_util_decode.c index ca3e22d..4561a07 100755 --- a/src/image_util_decode.c +++ b/src/image_util_decode.c @@ -41,7 +41,7 @@ static int _image_util_decode_read_header(const char *path, unsigned char **buff unsigned char *read_buffer = NULL; image_util_retvm_if(!IMAGE_UTIL_STRING_VALID(path), IMAGE_UTIL_ERROR_NO_SUCH_FILE, "Invalid path"); - image_util_retvm_if(buffer == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid buffer"); + image_util_retvm_if(buffer == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid buffer"); fp = fopen(path, "r"); if (fp == NULL) { @@ -92,8 +92,8 @@ static int _image_util_decode_check_image_type(const unsigned char *image_buffer ,}; unsigned int i = 0; - image_util_retvm_if((image_buffer == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid buffer"); - image_util_retvm_if((image_type == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid type"); + image_util_retvm_if((image_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid buffer"); + image_util_retvm_if((image_type == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid type"); *image_type = _NOT_SUPPORTED_IMAGE_TYPE; /* init */ for (i = 0; i < sizeof(image_header) / sizeof(image_header[0]); i++) { @@ -117,80 +117,70 @@ static void _image_util_decode_destroy_image_handle(decode_encode_s * handle) static int _image_util_decode_create_jpeg_handle(decode_encode_s * handle) { - int err = MM_UTIL_ERROR_NONE; - - image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid 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_decode_destroy_image_handle(handle); 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), MM_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY(0x%08x)", MM_UTIL_ERROR_OUT_OF_MEMORY); + 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 = sizeof(image_util_scale_e); - return err; + return IMAGE_UTIL_ERROR_NONE; } static int _image_util_decode_create_png_handle(decode_encode_s * handle) { - int err = MM_UTIL_ERROR_NONE; - - image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid 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_decode_destroy_image_handle(handle); mm_util_png_data *_handle = (mm_util_png_data *) calloc(1, sizeof(mm_util_png_data)); - image_util_retvm_if((_handle == NULL), MM_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY(0x%08x)", MM_UTIL_ERROR_OUT_OF_MEMORY); + image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); mm_util_init_decode_png(_handle); handle->image_h = (mm_util_imgp_h) _handle; - return err; + return IMAGE_UTIL_ERROR_NONE; } static int _image_util_decode_create_gif_handle(decode_encode_s * handle) { - int err = MM_UTIL_ERROR_NONE; - - image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid 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_decode_destroy_image_handle(handle); mm_util_gif_data *_handle = (mm_util_gif_data *) calloc(1, sizeof(mm_util_gif_data)); - image_util_retvm_if((_handle == NULL), MM_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY(0x%08x)", MM_UTIL_ERROR_OUT_OF_MEMORY); + image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); handle->image_h = (mm_util_imgp_h) _handle; - return err; + return IMAGE_UTIL_ERROR_NONE; } static int _image_util_decode_create_bmp_handle(decode_encode_s * handle) { - int err = MM_UTIL_ERROR_NONE; - - image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid 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_decode_destroy_image_handle(handle); mm_util_bmp_data *_handle = (mm_util_bmp_data *) calloc(1, sizeof(mm_util_bmp_data)); - image_util_retvm_if((_handle == NULL), MM_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY(0x%08x)", MM_UTIL_ERROR_OUT_OF_MEMORY); + image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); handle->image_h = (mm_util_imgp_h) _handle; - return err; + return IMAGE_UTIL_ERROR_NONE; } int image_util_decode_create(image_util_decode_h * handle) { - int err = MM_UTIL_ERROR_NONE; - image_util_debug("image_util_decode_create"); image_util_retvm_if((handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); @@ -207,12 +197,12 @@ int image_util_decode_create(image_util_decode_h * handle) *handle = (image_util_decode_h) _handle; - return _convert_image_util_error_code(__func__, err); + return IMAGE_UTIL_ERROR_NONE; } static int _image_util_decode_create_image_handle(image_util_decode_h handle) { - int err = MM_UTIL_ERROR_NONE; + int err = IMAGE_UTIL_ERROR_NONE; decode_encode_s *_handle = (decode_encode_s *) handle; if (_handle == NULL || _handle->is_decode == FALSE) { @@ -234,16 +224,14 @@ static int _image_util_decode_create_image_handle(image_util_decode_h handle) err = _image_util_decode_create_bmp_handle(_handle); break; default: - err = MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT; + err = IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT; break; } - if (err != MM_UTIL_ERROR_NONE) { + if (err != IMAGE_UTIL_ERROR_NONE) image_util_error("Error - create image handle"); - return _convert_image_util_error_code(__func__, err); - } - return _convert_image_util_error_code(__func__, err); + return err; } int image_util_decode_set_input_path(image_util_decode_h handle, const char *path) @@ -329,7 +317,6 @@ int image_util_decode_set_input_buffer(image_util_decode_h handle, const unsigne int image_util_decode_set_output_buffer(image_util_decode_h handle, unsigned char **dst_buffer) { - int err = IMAGE_UTIL_ERROR_NONE; decode_encode_s *_handle = (decode_encode_s *) handle; if (_handle == NULL || _handle->is_decode == FALSE) { @@ -343,12 +330,11 @@ int image_util_decode_set_output_buffer(image_util_decode_h handle, unsigned cha _handle->dst_buffer = (void **)dst_buffer; - return err; + return IMAGE_UTIL_ERROR_NONE; } int image_util_decode_set_colorspace(image_util_encode_h handle, image_util_colorspace_e colorspace) { - int err = IMAGE_UTIL_ERROR_NONE; decode_encode_s *_handle = (decode_encode_s *) handle; if (_handle == NULL || _handle->is_decode == FALSE) { @@ -367,12 +353,11 @@ int image_util_decode_set_colorspace(image_util_encode_h handle, image_util_colo _handle->colorspace = colorspace; - return err; + return IMAGE_UTIL_ERROR_NONE; } int image_util_decode_set_jpeg_downscale(image_util_encode_h handle, image_util_scale_e down_scale) { - int err = IMAGE_UTIL_ERROR_NONE; decode_encode_s *_handle = (decode_encode_s *) handle; if (_handle == NULL || _handle->is_decode == FALSE) { @@ -387,7 +372,7 @@ int image_util_decode_set_jpeg_downscale(image_util_encode_h handle, image_util_ _handle->down_scale = down_scale; - return err; + return IMAGE_UTIL_ERROR_NONE; } static int _image_util_decode_internal(decode_encode_s * _handle) @@ -402,7 +387,7 @@ static int _image_util_decode_internal(decode_encode_s * _handle) jpeg_data = (mm_util_jpeg_yuv_data *) _handle->image_h; if (jpeg_data == NULL) { image_util_error("Invalid jpeg data"); - return MM_UTIL_ERROR_INVALID_PARAMETER; + return IMAGE_UTIL_ERROR_INVALID_PARAMETER; } if (_handle->path) { @@ -432,7 +417,7 @@ static int _image_util_decode_internal(decode_encode_s * _handle) png_data = (mm_util_png_data *) _handle->image_h; if (png_data == NULL) { image_util_error("Invalid png data"); - return MM_UTIL_ERROR_INVALID_PARAMETER; + return IMAGE_UTIL_ERROR_INVALID_PARAMETER; } if (_handle->path) @@ -455,7 +440,7 @@ static int _image_util_decode_internal(decode_encode_s * _handle) gif_data = (mm_util_gif_data *) _handle->image_h; if (gif_data == NULL) { image_util_error("Invalid gif data"); - return MM_UTIL_ERROR_INVALID_PARAMETER; + return IMAGE_UTIL_ERROR_INVALID_PARAMETER; } if (_handle->path) @@ -478,7 +463,7 @@ static int _image_util_decode_internal(decode_encode_s * _handle) bmp_data = (mm_util_bmp_data *) _handle->image_h; if (bmp_data == NULL) { image_util_error("Invalid bmp data"); - return MM_UTIL_ERROR_INVALID_PARAMETER; + return IMAGE_UTIL_ERROR_INVALID_PARAMETER; } if (_handle->path) @@ -495,16 +480,16 @@ static int _image_util_decode_internal(decode_encode_s * _handle) } break; default: - err = MM_UTIL_ERROR_INVALID_PARAMETER; + return IMAGE_UTIL_ERROR_INVALID_PARAMETER; break; } - return err; + return _image_error_capi(ERR_TYPE_DECODE, err); } int image_util_decode_run(image_util_decode_h handle, unsigned long *width, unsigned long *height, unsigned long long *size) { - int err = MM_UTIL_ERROR_NONE; + int err = IMAGE_UTIL_ERROR_NONE; decode_encode_s *_handle = (decode_encode_s *) handle; if (_handle == NULL || _handle->is_decode == FALSE) { @@ -518,9 +503,9 @@ int image_util_decode_run(image_util_decode_h handle, unsigned long *width, unsi err = _image_util_decode_internal(_handle); - if (err != MM_UTIL_ERROR_NONE) { + if (err != IMAGE_UTIL_ERROR_NONE) { image_util_error("Error - decode run"); - return _convert_image_util_error_code(__func__, err); + return err; } if (width) @@ -530,13 +515,13 @@ int image_util_decode_run(image_util_decode_h handle, unsigned long *width, unsi if (size) *size = _handle->dst_size; - return _convert_image_util_error_code(__func__, err); + return err; } gpointer _image_util_decode_thread(gpointer data) { decode_encode_s *_handle = (decode_encode_s *) data; - int err = MM_UTIL_ERROR_NONE; + int err = IMAGE_UTIL_ERROR_NONE; if (!_handle) { image_util_error("[ERROR] - handle"); @@ -544,14 +529,14 @@ gpointer _image_util_decode_thread(gpointer data) } err = _image_util_decode_internal(_handle); - if (err == MM_UTIL_ERROR_NONE) + if (err == IMAGE_UTIL_ERROR_NONE) image_util_debug("Success - decode_internal"); else image_util_error("Error - decode_internal"); if (_handle->_decode_cb) { image_util_debug("completed_cb"); - _handle->_decode_cb->image_decode_completed_cb(_convert_image_util_error_code(__func__, err), _handle->_decode_cb->user_data, _handle->width, _handle->height, _handle->dst_size); + _handle->_decode_cb->image_decode_completed_cb(err, _handle->_decode_cb->user_data, _handle->width, _handle->height, _handle->dst_size); } image_util_debug("exit thread"); @@ -561,24 +546,22 @@ gpointer _image_util_decode_thread(gpointer data) static int _image_util_decode_create_thread(decode_encode_s * handle) { - int err = MM_UTIL_ERROR_NONE; - - image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); - image_util_retvm_if((handle->thread != NULL), MM_UTIL_ERROR_INVALID_OPERATION, "A thread is alread running"); + image_util_retvm_if((handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((handle->thread != NULL), IMAGE_UTIL_ERROR_INVALID_OPERATION, "A thread is alread running"); /*create threads */ handle->thread = g_thread_new("decode_thread", (GThreadFunc) _image_util_decode_thread, (gpointer) handle); if (!handle->thread) { image_util_error("ERROR - create thread"); - return MM_UTIL_ERROR_INVALID_OPERATION; + return IMAGE_UTIL_ERROR_INVALID_OPERATION; } - return err; + return IMAGE_UTIL_ERROR_NONE; } int image_util_decode_run_async(image_util_decode_h handle, image_util_decode_completed_cb completed_cb, void *user_data) { - int err = MM_UTIL_ERROR_NONE; + int err = IMAGE_UTIL_ERROR_NONE; decode_encode_s *_handle = (decode_encode_s *) handle; if (_handle == NULL || _handle->is_decode == FALSE) { @@ -590,7 +573,7 @@ int image_util_decode_run_async(image_util_decode_h handle, image_util_decode_co return IMAGE_UTIL_ERROR_INVALID_PARAMETER; } image_util_retvm_if((completed_cb == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid callback"); - image_util_retvm_if((_handle->thread != NULL), MM_UTIL_ERROR_INVALID_OPERATION, "A thread is alread running"); + image_util_retvm_if((_handle->thread != NULL), IMAGE_UTIL_ERROR_INVALID_OPERATION, "A thread is alread running"); if (_handle->_decode_cb != NULL) { IMAGE_UTIL_SAFE_FREE(_handle->_decode_cb); @@ -604,17 +587,16 @@ int image_util_decode_run_async(image_util_decode_h handle, image_util_decode_co _handle->_decode_cb->image_decode_completed_cb = completed_cb; err = _image_util_decode_create_thread(_handle); - if (err != MM_UTIL_ERROR_NONE) { + if (err != IMAGE_UTIL_ERROR_NONE) { IMAGE_UTIL_SAFE_FREE(_handle->_decode_cb); _handle->_decode_cb = NULL; } - return _convert_image_util_error_code(__func__, err); + return err; } int image_util_decode_destroy(image_util_decode_h handle) { - int err = IMAGE_UTIL_ERROR_NONE; decode_encode_s *_handle = (decode_encode_s *) handle; image_util_debug("image_util_decode_destroy"); @@ -634,8 +616,9 @@ int image_util_decode_destroy(image_util_decode_h handle) IMAGE_UTIL_SAFE_FREE(_handle->src_buffer); IMAGE_UTIL_SAFE_FREE(_handle); - return err; + return IMAGE_UTIL_ERROR_NONE; } + int image_util_decode_jpeg(const char *path, image_util_colorspace_e colorspace, unsigned char **image_buffer, int *width, int *height, unsigned int *size) { int err = MM_UTIL_ERROR_NONE; @@ -662,7 +645,7 @@ int image_util_decode_jpeg(const char *path, image_util_colorspace_e colorspace, if (size) *size = decoded.size; } - return _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_DECODE, err); } int image_util_decode_jpeg_from_memory(const unsigned char *jpeg_buffer, int jpeg_size, image_util_colorspace_e colorspace, unsigned char **image_buffer, int *width, int *height, unsigned int *size) @@ -692,7 +675,7 @@ int image_util_decode_jpeg_from_memory(const unsigned char *jpeg_buffer, int jpe *size = decoded.size; } - return _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_DECODE, err); } int image_util_decode_jpeg_with_downscale(const char *path, image_util_colorspace_e colorspace, image_util_scale_e downscale, unsigned char **image_buffer, int *width, int *height, unsigned int *size) @@ -722,7 +705,7 @@ int image_util_decode_jpeg_with_downscale(const char *path, image_util_colorspac if (size) *size = decoded.size; } - return _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_DECODE, err); } int image_util_decode_jpeg_from_memory_with_downscale(const unsigned char *jpeg_buffer, int jpeg_size, image_util_colorspace_e colorspace, image_util_scale_e downscale, unsigned char **image_buffer, int *width, int *height, unsigned int *size) @@ -753,5 +736,5 @@ int image_util_decode_jpeg_from_memory_with_downscale(const unsigned char *jpeg_ *size = decoded.size; } - return _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_DECODE, err); } diff --git a/src/image_util_encode.c b/src/image_util_encode.c index 2029a0d..b0d287a 100755 --- a/src/image_util_encode.c +++ b/src/image_util_encode.c @@ -26,28 +26,28 @@ static int _image_util_encode_get_gif_frame(mm_gif_file_h gif_data, unsigned int index, mm_gif_image_h *frame) { int err = MM_UTIL_ERROR_NONE; - image_util_retvm_if((gif_data == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); - image_util_retvm_if((frame == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + 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); if (err != MM_UTIL_ERROR_NONE) { image_util_error("mm_util_gif_enocde_get_image_handle is failed %d", err); - return _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_ENCODE, err); } if (*frame == NULL) { err = mm_util_gif_image_create(gif_data, frame); if (err != MM_UTIL_ERROR_NONE) { image_util_error("mm_util_gif_image_create is failed %d", err); - return _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_ENCODE, err); } 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 _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_ENCODE, err); } } - return err; + return _image_error_capi(ERR_TYPE_ENCODE, err); } static void _image_util_encode_destroy_image_handle(decode_encode_s * handle) @@ -64,34 +64,30 @@ static void _image_util_encode_destroy_image_handle(decode_encode_s * handle) static int _image_util_encode_create_jpeg_handle(decode_encode_s * handle) { - int err = MM_UTIL_ERROR_NONE; - - image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); 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), MM_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY(0x%08x)", MM_UTIL_ERROR_OUT_OF_MEMORY); + 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->quality = 75; - return err; + return IMAGE_UTIL_ERROR_NONE; } static int _image_util_encode_create_png_handle(decode_encode_s * handle) { - int err = MM_UTIL_ERROR_NONE; - - image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); mm_util_png_data *_handle = (mm_util_png_data *) calloc(1, sizeof(mm_util_png_data)); - image_util_retvm_if((_handle == NULL), MM_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY(0x%08x)", MM_UTIL_ERROR_OUT_OF_MEMORY); + image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); mm_util_init_encode_png(_handle); handle->image_h = (mm_util_imgp_h) _handle; - return err; + return IMAGE_UTIL_ERROR_NONE; } static int _image_util_encode_create_gif_handle(decode_encode_s * handle) @@ -99,33 +95,31 @@ static int _image_util_encode_create_gif_handle(decode_encode_s * handle) int err = MM_UTIL_ERROR_NONE; mm_gif_file_h _handle = NULL; - image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); err = mm_util_gif_encode_create(&_handle); - image_util_retvm_if((err != MM_UTIL_ERROR_NONE), _convert_image_util_error_code(__func__, err), "Error - mm_util_gif_encode_create is failed (%d)", err); + image_util_retvm_if((err != MM_UTIL_ERROR_NONE), _image_error_capi(ERR_TYPE_ENCODE, err), "Error - mm_util_gif_encode_create is failed (%d)", err); handle->image_h = (mm_util_imgp_h) _handle; - return err; + return IMAGE_UTIL_ERROR_NONE; } static int _image_util_encode_create_bmp_handle(decode_encode_s * handle) { - int err = MM_UTIL_ERROR_NONE; - - image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); mm_util_bmp_data *_handle = (mm_util_bmp_data *) calloc(1, sizeof(mm_util_bmp_data)); - image_util_retvm_if((_handle == NULL), MM_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY(0x%08x)", MM_UTIL_ERROR_OUT_OF_MEMORY); + image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); handle->image_h = (mm_util_imgp_h) _handle; - return err; + return IMAGE_UTIL_ERROR_NONE; } int image_util_encode_create(image_util_type_e image_type, image_util_encode_h * handle) { - int err = MM_UTIL_ERROR_NONE; + int err = IMAGE_UTIL_ERROR_NONE; image_util_debug("image_util_encode_create"); @@ -159,19 +153,19 @@ int image_util_encode_create(image_util_type_e image_type, image_util_encode_h * err = _image_util_encode_create_bmp_handle(_handle); break; default: - err = MM_UTIL_ERROR_INVALID_PARAMETER; + err = IMAGE_UTIL_ERROR_INVALID_PARAMETER; break; } - if (err != MM_UTIL_ERROR_NONE) { + if (err != IMAGE_UTIL_ERROR_NONE) { image_util_error("Error - create image handle"); IMAGE_UTIL_SAFE_FREE(_handle); - return _convert_image_util_error_code(__func__, err); + return err; } *handle = (image_util_encode_h) _handle; - return _convert_image_util_error_code(__func__, err); + return err; } int image_util_encode_set_resolution(image_util_encode_h handle, unsigned long width, unsigned long height) @@ -229,14 +223,14 @@ int image_util_encode_set_resolution(image_util_encode_h handle, unsigned long w } mm_gif_image_h frame = NULL; err = _image_util_encode_get_gif_frame(gif_data, _handle->current_resolution_count, &frame); - if (err != MM_UTIL_ERROR_NONE) { + if (err != IMAGE_UTIL_ERROR_NONE) { image_util_error("_image_util_encode_get_gif_frame is failed %d", err); - return _convert_image_util_error_code(__func__, err); + return err; } err = mm_util_gif_image_set_position(frame, 0, 0, (int)width, (int)height); if (err != MM_UTIL_ERROR_NONE) { image_util_error("mm_util_gif_image_set_position is failed %d", err); - return _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_ENCODE, err); } _handle->current_resolution_count++; @@ -364,14 +358,14 @@ int image_util_encode_set_gif_frame_delay_time(image_util_encode_h handle, unsig mm_gif_image_h frame = NULL; err = _image_util_encode_get_gif_frame(gif_data, _handle->current_delay_count, &frame); - if (err != MM_UTIL_ERROR_NONE) { + if (err != IMAGE_UTIL_ERROR_NONE) { image_util_error("_image_util_encode_get_gif_frame is failed %d", err); - return _convert_image_util_error_code(__func__, err); + return err; } err = mm_util_gif_image_set_delay_time(frame, (int)delay_time); if (err != MM_UTIL_ERROR_NONE) { image_util_error("mm_util_gif_image_set_delay_time is failed %d", err); - return _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_ENCODE, err); } _handle->current_delay_count++; @@ -401,14 +395,14 @@ int image_util_encode_set_input_buffer(image_util_encode_h handle, const unsigne return IMAGE_UTIL_ERROR_INVALID_PARAMETER; } err = _image_util_encode_get_gif_frame(gif_data, _handle->current_buffer_count, &frame); - if (err != MM_UTIL_ERROR_NONE) { + if (err != IMAGE_UTIL_ERROR_NONE) { image_util_error("_image_util_encode_get_gif_frame is failed %d", err); - return _convert_image_util_error_code(__func__, err); + return err; } err = mm_util_gif_image_set_image(frame, src_buffer); if (err != MM_UTIL_ERROR_NONE) { image_util_error("mm_util_gif_image_set_delay_time is failed %d", err); - return _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_ENCODE, err); } _handle->current_buffer_count++; } else { @@ -484,7 +478,7 @@ static int _image_util_encode_internal(decode_encode_s * _handle) png_data = (mm_util_png_data *) _handle->image_h; if (png_data == NULL) { image_util_error("Invalid png data"); - return MM_UTIL_ERROR_INVALID_PARAMETER; + return IMAGE_UTIL_ERROR_INVALID_PARAMETER; } if (_handle->path) @@ -507,15 +501,15 @@ static int _image_util_encode_internal(decode_encode_s * _handle) unsigned long encoded_buffer_size = 0; if (gif_data == NULL) { image_util_error("Invalid gif data"); - return MM_UTIL_ERROR_INVALID_PARAMETER; + return IMAGE_UTIL_ERROR_INVALID_PARAMETER; } 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_error("Total frame count does not match with the data set, for animated gif encoding"); - return MM_UTIL_ERROR_INVALID_OPERATION; + 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 MM_UTIL_ERROR_INVALID_OPERATION; + return IMAGE_UTIL_ERROR_INVALID_OPERATION; } if (_handle->path) err = mm_util_gif_encode_set_file(gif_data, _handle->path); @@ -523,12 +517,12 @@ static int _image_util_encode_internal(decode_encode_s * _handle) err = mm_util_gif_encode_set_mem(gif_data, _handle->dst_buffer, &encoded_buffer_size); if (err != MM_UTIL_ERROR_NONE) { image_util_error("mm_util_gif_encode_set_file | mm_util_gif_encode_set_mem is failed(%d)", err); - return _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_ENCODE, err); } err = mm_util_gif_encode(gif_data); if (err != MM_UTIL_ERROR_NONE) { image_util_error("mm_util_gif_encode is failed(%d)", err); - return _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_ENCODE, err); } if (encoded_buffer_size != 0) _handle->dst_size = (unsigned long long)encoded_buffer_size; @@ -541,7 +535,7 @@ static int _image_util_encode_internal(decode_encode_s * _handle) bmp_data = (mm_util_bmp_data *) _handle->image_h; if (bmp_data == NULL) { image_util_error("Invalid bmp data"); - return MM_UTIL_ERROR_INVALID_PARAMETER; + return IMAGE_UTIL_ERROR_INVALID_PARAMETER; } bmp_data->data = _handle->src_buffer[0]; @@ -565,16 +559,16 @@ static int _image_util_encode_internal(decode_encode_s * _handle) } break; default: - err = MM_UTIL_ERROR_INVALID_PARAMETER; + return IMAGE_UTIL_ERROR_INVALID_PARAMETER; break; } - return err; + return _image_error_capi(ERR_TYPE_ENCODE, err); } int image_util_encode_run(image_util_encode_h handle, unsigned long long *size) { - int err = MM_UTIL_ERROR_NONE; + int err = IMAGE_UTIL_ERROR_NONE; decode_encode_s *_handle = (decode_encode_s *) handle; if (_handle == NULL || _handle->is_decode == TRUE) { @@ -594,21 +588,21 @@ int image_util_encode_run(image_util_encode_h handle, unsigned long long *size) err = _image_util_encode_internal(_handle); _handle->is_encoded = TRUE; - if (err != MM_UTIL_ERROR_NONE) { + if (err != IMAGE_UTIL_ERROR_NONE) { image_util_error("Error - encode run"); - return _convert_image_util_error_code(__func__, err); + return err; } if (size) *size = _handle->dst_size; - return _convert_image_util_error_code(__func__, err); + return err; } gpointer _image_util_encode_thread(gpointer data) { decode_encode_s *_handle = (decode_encode_s *) data; - int err = MM_UTIL_ERROR_NONE; + int err = IMAGE_UTIL_ERROR_NONE; if (!_handle) { image_util_error("[ERROR] - handle"); @@ -616,14 +610,14 @@ gpointer _image_util_encode_thread(gpointer data) } err = _image_util_encode_internal(_handle); - if (err == MM_UTIL_ERROR_NONE) + if (err == IMAGE_UTIL_ERROR_NONE) image_util_debug("Success - encode_internal"); else image_util_error("Error - encode_internal"); if (_handle->_encode_cb) { image_util_debug("completed_cb"); - _handle->_encode_cb->image_encode_completed_cb(_convert_image_util_error_code(__func__, err), _handle->_encode_cb->user_data, _handle->dst_size); + _handle->_encode_cb->image_encode_completed_cb(err, _handle->_encode_cb->user_data, _handle->dst_size); } IMAGE_UTIL_SAFE_FREE(_handle->_encode_cb); @@ -636,25 +630,23 @@ gpointer _image_util_encode_thread(gpointer data) static int _image_util_encode_create_thread(decode_encode_s * handle) { - int ret = MM_UTIL_ERROR_NONE; - - image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); - image_util_retvm_if((handle->thread != NULL), MM_UTIL_ERROR_INVALID_OPERATION, "The thread is alread running"); + image_util_retvm_if((handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((handle->thread != NULL), IMAGE_UTIL_ERROR_INVALID_OPERATION, "The thread is alread running"); /*create threads */ handle->thread = g_thread_new("encode_thread", (GThreadFunc) _image_util_encode_thread, (gpointer) handle); if (!handle->thread) { image_util_error("ERROR - create thread"); - return MM_UTIL_ERROR_INVALID_OPERATION; + return IMAGE_UTIL_ERROR_INVALID_OPERATION; } - return ret; + return IMAGE_UTIL_ERROR_NONE; } int image_util_encode_run_async(image_util_encode_h handle, image_util_encode_completed_cb completed_cb, void *user_data) { - int err = MM_UTIL_ERROR_NONE; + int err = IMAGE_UTIL_ERROR_NONE; decode_encode_s *_handle = (decode_encode_s *) handle; if (_handle == NULL || _handle->is_decode == TRUE) { @@ -671,7 +663,7 @@ int image_util_encode_run_async(image_util_encode_h handle, image_util_encode_co } image_util_retvm_if((_image_util_check_resolution(_handle->width, _handle->height) == false), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid resolution"); image_util_retvm_if((completed_cb == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid callback"); - image_util_retvm_if((_handle->thread != NULL), MM_UTIL_ERROR_INVALID_OPERATION, "The thread is alread running"); + image_util_retvm_if((_handle->thread != NULL), IMAGE_UTIL_ERROR_INVALID_OPERATION, "The thread is alread running"); if (_handle->_encode_cb != NULL) { IMAGE_UTIL_SAFE_FREE(_handle->_encode_cb); @@ -684,12 +676,12 @@ int image_util_encode_run_async(image_util_encode_h handle, image_util_encode_co _handle->_encode_cb->image_encode_completed_cb = completed_cb; err = _image_util_encode_create_thread(_handle); - if (err != MM_UTIL_ERROR_NONE) { + if (err != IMAGE_UTIL_ERROR_NONE) { IMAGE_UTIL_SAFE_FREE(_handle->_encode_cb); _handle->_encode_cb = NULL; } - return _convert_image_util_error_code(__func__, err); + return err; } int image_util_encode_destroy(image_util_encode_h handle) @@ -732,7 +724,7 @@ int image_util_encode_jpeg(const unsigned char *buffer, int width, int height, i image_util_retvm_if((is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format"); err = mm_util_jpeg_encode_to_file(path, (void *)buffer, width, height, TYPECAST_COLOR_BY_TYPE(colorspace, IMAGE_UTIL_JPEG), quality); - return _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_ENCODE, err); } int image_util_encode_jpeg_to_memory(const unsigned char *image_buffer, int width, int height, image_util_colorspace_e colorspace, int quality, unsigned char **jpeg_buffer, unsigned int *jpeg_size) @@ -748,6 +740,6 @@ int image_util_encode_jpeg_to_memory(const unsigned char *image_buffer, int widt image_util_retvm_if((is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format"); err = mm_util_jpeg_encode_to_memory((void **)jpeg_buffer, jpeg_size, (void *)image_buffer, width, height, TYPECAST_COLOR_BY_TYPE(colorspace, IMAGE_UTIL_JPEG), quality); - return _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_ENCODE, err); } diff --git a/src/image_util_internal.c b/src/image_util_internal.c index 50afd42..48a6698 100755 --- a/src/image_util_internal.c +++ b/src/image_util_internal.c @@ -31,7 +31,7 @@ int image_util_convert_colorspace(unsigned char *dest, image_util_colorspace_e d err = mm_util_convert_colorspace(src, width, height, TYPECAST_COLOR(src_colorspace), dest, TYPECAST_COLOR(dest_colorspace)); - return _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_TRANSFORM, err); } int image_util_resize(unsigned char *dest, int *dest_width, int *dest_height, const unsigned char *src, int src_width, int src_height, image_util_colorspace_e colorspace) @@ -53,7 +53,7 @@ int image_util_resize(unsigned char *dest, int *dest_width, int *dest_height, co *dest_height = (int)dest_h; } - return _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_TRANSFORM, err); } int image_util_rotate(unsigned char *dest, int *dest_width, int *dest_height, image_util_rotation_e dest_rotation, const unsigned char *src, int src_width, int src_height, image_util_colorspace_e colorspace) @@ -72,7 +72,7 @@ int image_util_rotate(unsigned char *dest, int *dest_width, int *dest_height, im *dest_width = (int)dest_w; *dest_height = (int)dest_h; } - return _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_TRANSFORM, err); } int image_util_crop(unsigned char *dest, int x, int y, int *width, int *height, const unsigned char *src, int src_width, int src_height, image_util_colorspace_e colorspace) @@ -94,23 +94,23 @@ int image_util_crop(unsigned char *dest, int x, int y, int *width, int *height, *height = (int)dest_h; } - return _convert_image_util_error_code(__func__, err); + return _image_error_capi(ERR_TYPE_TRANSFORM, err); } int image_util_frame_create(void *decode_encode_h, image_util_frame_h *frame_h) { - int ret = IMAGE_UTIL_ERROR_NONE; + int ret = MM_UTIL_ERROR_NONE; - image_util_retvm_if((decode_encode_h == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); - image_util_retvm_if((frame_h == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((decode_encode_h == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((frame_h == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); decode_encode_s *image = (decode_encode_s *)decode_encode_h; - image_util_retvm_if((image->image_h == NULL), MM_UTIL_ERROR_INVALID_OPERATION, "The image handle is wrong"); + image_util_retvm_if((image->image_h == NULL), IMAGE_UTIL_ERROR_INVALID_OPERATION, "The image handle is wrong"); frame_s *frame = calloc(1, sizeof(frame_s)); if (frame == NULL) { image_util_error("Memory allocation is failed."); - return MM_UTIL_ERROR_OUT_OF_MEMORY; + return IMAGE_UTIL_ERROR_OUT_OF_MEMORY; } if (image->image_type == IMAGE_UTIL_GIF) { @@ -118,16 +118,16 @@ int image_util_frame_create(void *decode_encode_h, image_util_frame_h *frame_h) mm_gif_image_h gif_frame = NULL; ret = mm_util_gif_image_create(gif_data, &gif_frame); - if (ret != IMAGE_UTIL_ERROR_NONE) { + if (ret != MM_UTIL_ERROR_NONE) { image_util_error("mm_util_gif_image_create is failed(%d).", ret); IMAGE_UTIL_SAFE_FREE(frame); - return MM_UTIL_ERROR_INVALID_OPERATION; + return _image_error_capi(ERR_TYPE_ENCODE, ret); } frame->frame_h = gif_frame; } else { image_util_error("The image type(%d) is not supported.", image->image_type); IMAGE_UTIL_SAFE_FREE(frame); - return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT; + return IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT; } *frame_h = frame; @@ -137,17 +137,17 @@ int image_util_frame_create(void *decode_encode_h, image_util_frame_h *frame_h) int image_util_frame_set_resolution(image_util_frame_h frame_h, const int width, const int height) { - int ret = IMAGE_UTIL_ERROR_NONE; + int ret = MM_UTIL_ERROR_NONE; - image_util_retvm_if((frame_h == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); - image_util_retvm_if((width <= 0) || (height <= 0), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Width or Height"); + image_util_retvm_if((frame_h == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((width <= 0) || (height <= 0), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Width or Height"); frame_s *frame = (frame_s *)frame_h; ret = mm_util_gif_image_set_position(frame->frame_h, 0, 0, width, height); - if (ret != IMAGE_UTIL_ERROR_NONE) { + if (ret != MM_UTIL_ERROR_NONE) { image_util_error("mm_util_gif_image_set_position is failed(%d).", ret); - return MM_UTIL_ERROR_INVALID_OPERATION; + return _image_error_capi(ERR_TYPE_ENCODE, ret); } return IMAGE_UTIL_ERROR_NONE; @@ -155,17 +155,17 @@ int image_util_frame_set_resolution(image_util_frame_h frame_h, const int width, int image_util_frame_set_gif_delay(image_util_frame_h frame_h, const int delay_time) { - int ret = IMAGE_UTIL_ERROR_NONE; + int ret = MM_UTIL_ERROR_NONE; - image_util_retvm_if((frame_h == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); - image_util_retvm_if((delay_time <= 0), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Delay Time"); + image_util_retvm_if((frame_h == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((delay_time <= 0), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Delay Time"); frame_s *frame = (frame_s *)frame_h; ret = mm_util_gif_image_set_delay_time(frame->frame_h, delay_time); - if (ret != IMAGE_UTIL_ERROR_NONE) { + if (ret != MM_UTIL_ERROR_NONE) { image_util_error("mm_util_gif_image_set_delay_time is failed(%d).", ret); - return MM_UTIL_ERROR_INVALID_OPERATION; + return _image_error_capi(ERR_TYPE_ENCODE, ret); } return IMAGE_UTIL_ERROR_NONE; @@ -173,17 +173,17 @@ int image_util_frame_set_gif_delay(image_util_frame_h frame_h, const int delay_t int image_util_frame_set_frame(image_util_frame_h frame_h, unsigned char *buffer) { - int ret = IMAGE_UTIL_ERROR_NONE; + int ret = MM_UTIL_ERROR_NONE; - image_util_retvm_if((frame_h == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); - image_util_retvm_if((buffer == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Buffer"); + image_util_retvm_if((frame_h == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Buffer"); frame_s *frame = (frame_s *)frame_h; ret = mm_util_gif_image_set_image(frame->frame_h, buffer); - if (ret != IMAGE_UTIL_ERROR_NONE) { + if (ret != MM_UTIL_ERROR_NONE) { image_util_error("mm_util_gif_image_set_image is failed(%d).", ret); - return MM_UTIL_ERROR_INVALID_OPERATION; + return _image_error_capi(ERR_TYPE_ENCODE, ret); } return IMAGE_UTIL_ERROR_NONE; @@ -199,16 +199,16 @@ void image_util_frame_destroy(image_util_frame_h frame_h) int image_util_encode_add_frame(image_util_encode_h encode_h, image_util_frame_h frame_h) { - int ret = IMAGE_UTIL_ERROR_NONE; + int ret = MM_UTIL_ERROR_NONE; - image_util_retvm_if((encode_h == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); - image_util_retvm_if((frame_h == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((encode_h == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((frame_h == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); decode_encode_s *encode = (decode_encode_s *)encode_h; frame_s *frame = (frame_s *)frame_h; - image_util_retvm_if((encode->image_h == NULL), MM_UTIL_ERROR_INVALID_OPERATION, "The image handle is wrong"); - image_util_retvm_if((encode->image_type != IMAGE_UTIL_GIF), MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "The image type(%d) is not supported.", encode->image_type); - image_util_retvm_if((frame->frame_h == NULL), MM_UTIL_ERROR_INVALID_OPERATION, "The frame handle is wrong"); + 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->frame_h == NULL), IMAGE_UTIL_ERROR_INVALID_OPERATION, "The frame handle is wrong"); mm_gif_file_h gif_data = (mm_gif_file_h)encode->image_h; @@ -218,15 +218,15 @@ int image_util_encode_add_frame(image_util_encode_h encode_h, image_util_frame_h else ret = mm_util_gif_encode_set_mem(gif_data, encode->dst_buffer, &encode->gif_encode_size); } - if (ret != IMAGE_UTIL_ERROR_NONE) { + if (ret != MM_UTIL_ERROR_NONE) { image_util_error("mm_util_gif_encode_add_image is failed(%d).", ret); - return MM_UTIL_ERROR_INVALID_OPERATION; + return _image_error_capi(ERR_TYPE_ENCODE, ret); } ret = mm_util_gif_encode_add_image(gif_data, (mm_gif_image_h)frame->frame_h); - if (ret != IMAGE_UTIL_ERROR_NONE) { + if (ret != MM_UTIL_ERROR_NONE) { image_util_error("mm_util_gif_encode_add_image is failed(%d).", ret); - return MM_UTIL_ERROR_INVALID_OPERATION; + return _image_error_capi(ERR_TYPE_ENCODE, ret); } encode->current_buffer_count++; @@ -235,21 +235,21 @@ int image_util_encode_add_frame(image_util_encode_h encode_h, image_util_frame_h int image_util_encode_save(image_util_encode_h encode_h, unsigned long long *size) { - int ret = IMAGE_UTIL_ERROR_NONE; + int ret = MM_UTIL_ERROR_NONE; - image_util_retvm_if((encode_h == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((encode_h == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); decode_encode_s *encode = (decode_encode_s *)encode_h; - image_util_retvm_if((encode->image_h == NULL), MM_UTIL_ERROR_INVALID_OPERATION, "The image handle is wrong"); - image_util_retvm_if((encode->image_type != IMAGE_UTIL_GIF), MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "The image type(%d) is not supported.", encode->image_type); + 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); mm_gif_file_h gif_data = (mm_gif_file_h)encode->image_h; ret = mm_util_gif_encode_save(gif_data); - if (ret != IMAGE_UTIL_ERROR_NONE) { + if (ret != MM_UTIL_ERROR_NONE) { image_util_error("mm_util_gif_encode_save is failed(%d).", ret); mm_util_gif_encode_destroy(gif_data); - return MM_UTIL_ERROR_INVALID_OPERATION; + return _image_error_capi(ERR_TYPE_ENCODE, ret); } *size = (unsigned long long)encode->gif_encode_size; diff --git a/src/image_util_private.c b/src/image_util_private.c index 8433b85..185c844 100755 --- a/src/image_util_private.c +++ b/src/image_util_private.c @@ -187,64 +187,37 @@ int convert_type_of_colorspace_with_image_type(const image_util_colorspace_e col return new_colorspace; } -int _convert_image_util_error_code(const char *func, int code) +int _image_error_capi(image_util_error_type_e error_type, int error_code) { - int ret = IMAGE_UTIL_ERROR_INVALID_OPERATION; - char *errorstr = NULL; - switch (code) { - case MM_UTIL_ERROR_NONE: - ret = IMAGE_UTIL_ERROR_NONE; - errorstr = strdup("ERROR_NONE"); - break; - case MM_UTIL_ERROR_NO_SUCH_FILE: - ret = IMAGE_UTIL_ERROR_NO_SUCH_FILE; - errorstr = strdup("NO_SUCH_FILE"); - break; - case MM_UTIL_ERROR_INVALID_PARAMETER: - ret = IMAGE_UTIL_ERROR_INVALID_PARAMETER; - errorstr = strdup("INVALID_PARAMETER"); - break; - case MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT: - ret = IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT; - errorstr = strdup("NOT_SUPPORTED_FORMAT"); - break; - case MM_UTIL_ERROR_OUT_OF_MEMORY: - ret = IMAGE_UTIL_ERROR_OUT_OF_MEMORY; - errorstr = strdup("OUT_OF_MEMORY"); - break; - case MM_UTIL_ERROR_INVALID_OPERATION: - default: - ret = IMAGE_UTIL_ERROR_INVALID_OPERATION; - errorstr = strdup("INVALID_OPERATION"); + if (error_code != MM_UTIL_ERROR_NONE) + image_util_error("[type : %d] error : %d ", error_type, error_code); - } - - image_util_debug("[%s] %s(0x%08x)", func, errorstr, ret); - IMAGE_UTIL_SAFE_FREE(errorstr); - return ret; -} - -image_util_error_e _image_util_error_convert(int error) -{ - switch (error) { - case MM_UTIL_ERROR_NONE: - image_util_debug("Error None"); + /*Error None*/ + if (error_code == MM_UTIL_ERROR_NONE) return IMAGE_UTIL_ERROR_NONE; - case MM_UTIL_ERROR_INVALID_PARAMETER: - image_util_error("INVALID_PARAMETER(0x%08x)", IMAGE_UTIL_ERROR_INVALID_PARAMETER); + + /* Invalid parameter error*/ + else if (error_code == MM_UTIL_ERROR_INVALID_PARAMETER) return IMAGE_UTIL_ERROR_INVALID_PARAMETER; - case MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT: - image_util_error("NOT_SUPPORTED_FORMAT(0x%08x)", IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT); - return IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT; - case MM_UTIL_ERROR_OUT_OF_MEMORY: - image_util_error("OUT_OF_MEMORY(0x%08x)", IMAGE_UTIL_ERROR_OUT_OF_MEMORY); + + else if (error_code == MM_UTIL_ERROR_OUT_OF_MEMORY) return IMAGE_UTIL_ERROR_OUT_OF_MEMORY; - break; - case MM_UTIL_ERROR_INVALID_OPERATION: - default: - image_util_error("INVALID_OPERATION(0x%08x)", error); + + /* No such file error*/ + else if (error_code == MM_UTIL_ERROR_NO_SUCH_FILE) + return IMAGE_UTIL_ERROR_NO_SUCH_FILE; + + /* Internal operation error*/ + else if (error_code == MM_UTIL_ERROR_INVALID_OPERATION) return IMAGE_UTIL_ERROR_INVALID_OPERATION; - } + + /* Not supported format error*/ + else if (error_code == MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT) + return IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT; + + /*ETC*/ + return IMAGE_UTIL_ERROR_INVALID_OPERATION; + } bool _image_util_check_resolution(int width, int height)