From afbf9636e12ffda51cf55ea6c81acb7e2340259b Mon Sep 17 00:00:00 2001 From: "jiyong.min" Date: Mon, 30 Dec 2019 14:17:57 +0900 Subject: [PATCH] Code refactoring for internal functions Change-Id: I438990856d26110827c3158e12866958dfc6b73b --- gif/mm_util_gif.c | 42 +++++++++++++------------- imgcv/mm_util_imgcv.cpp | 47 ++++++++++++----------------- imgp/mm_util_imgp.c | 41 +++++++------------------- jpeg/mm_util_jpeg.c | 30 +++++++++---------- magick/mm_util_info.c | 70 +++++++++++++++++++++----------------------- packaging/libmm-utility.spec | 2 +- 6 files changed, 99 insertions(+), 133 deletions(-) diff --git a/gif/mm_util_gif.c b/gif/mm_util_gif.c index 7e69fae..a6ba1b6 100644 --- a/gif/mm_util_gif.c +++ b/gif/mm_util_gif.c @@ -392,7 +392,7 @@ static int __gif_extract_rgb(mm_image_info_s *gif_image, unsigned long num_of_pi return MM_UTIL_ERROR_NONE; } -int __gif_make_color_map(mm_image_info_s *gif_image, ColorMapObject **color_map, GifByteType **intermediate_image, unsigned long *intermediate_image_size) +static int __gif_make_color_map(mm_image_info_s *gif_image, ColorMapObject **color_map, GifByteType **intermediate_image, unsigned long *intermediate_image_size) { int ret = MM_UTIL_ERROR_NONE; int colormap_size = DEFAULT_COLORMAP_SIZE; @@ -443,7 +443,7 @@ SUCCESS: return ret; } -static int _gif_encode_open_mem(gif_file_s *gif_file) +static int __gif_encode_open_mem(gif_file_s *gif_file) { mm_util_fenter(); mm_util_retvm_if(gif_file == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid parameter"); @@ -459,7 +459,7 @@ static int _gif_encode_open_mem(gif_file_s *gif_file) return MM_UTIL_ERROR_NONE; } -static int _gif_encode_close_file(GifFileType *gft) +static int __gif_encode_close_file(GifFileType *gft) { mm_util_fenter(); mm_util_retvm_if(gft == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid parameter"); @@ -473,7 +473,7 @@ static int _gif_encode_close_file(GifFileType *gft) return MM_UTIL_ERROR_NONE; } -int __write_gif_to_file(gif_file_s *handle) +static int __write_gif_to_file(gif_file_s *handle) { int ret = MM_UTIL_ERROR_NONE; FILE *fp = NULL; @@ -494,7 +494,7 @@ int __write_gif_to_file(gif_file_s *handle) return ret; } -int __write_gif_to_buffer(gif_file_s *handle) +static int __write_gif_to_buffer(gif_file_s *handle) { unsigned char *_buffer = NULL; @@ -513,7 +513,7 @@ int __write_gif_to_buffer(gif_file_s *handle) return MM_UTIL_ERROR_NONE; } -int _gif_image_write_image(gif_file_s *gif_file, mm_image_info_s *gif_image) +static int __gif_image_write_image(gif_file_s *gif_file, mm_image_info_s *gif_image) { int ret = MM_UTIL_ERROR_NONE; ColorMapObject *color_map = NULL; @@ -554,7 +554,7 @@ int _gif_image_write_image(gif_file_s *gif_file, mm_image_info_s *gif_image) return MM_UTIL_ERROR_NONE; } -int _gif_image_create_ext_block(int function, int byte_count, ExtensionBlock **ext_block) +static int __gif_image_create_ext_block(int function, int byte_count, ExtensionBlock **ext_block) { ExtensionBlock *_ext_block = NULL; @@ -582,7 +582,7 @@ int _gif_image_create_ext_block(int function, int byte_count, ExtensionBlock **e return MM_UTIL_ERROR_NONE; } -int _gif_image_write_ext_block(gif_file_s *gif_file, unsigned int delay_time) +static int __gif_image_write_ext_block(gif_file_s *gif_file, unsigned int delay_time) { int ret = MM_UTIL_ERROR_NONE; ExtensionBlock *_ext_block = NULL; @@ -590,8 +590,8 @@ int _gif_image_write_ext_block(gif_file_s *gif_file, unsigned int delay_time) mm_util_retvm_if(gif_file == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid parameter"); - ret = _gif_image_create_ext_block(GRAPHICS_EXT_FUNC_CODE, GRAPHIC_EXT_BLOCK_SIZE, &_ext_block); - mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "_gif_image_alloc_ext_block failed"); + ret = __gif_image_create_ext_block(GRAPHICS_EXT_FUNC_CODE, GRAPHIC_EXT_BLOCK_SIZE, &_ext_block); + mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "__gif_image_create_ext_block failed"); /* use fixed graphics control */ graphic_control_block.DisposalMode = DISPOSAL_UNSPECIFIED; @@ -665,8 +665,8 @@ static int __mm_util_gif_encode_start(mm_gif_file_h gif_file_h, unsigned int wid mm_util_fenter(); - ret = _gif_encode_open_mem(gif_file); - mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "_gif_encode_open_mem failed"); + ret = __gif_encode_open_mem(gif_file); + mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "__gif_encode_open_mem failed"); /* To initialize data after GifFile opened */ EGifSetGifVersion(gif_file->GifFile, TRUE); @@ -674,7 +674,7 @@ static int __mm_util_gif_encode_start(mm_gif_file_h gif_file_h, unsigned int wid /* Write screen description */ if (EGifPutScreenDesc(gif_file->GifFile, width, height, 8 /* color_res */, 0 /* background_color */, NULL) == GIF_ERROR) { mm_util_error("could not put screen description"); - _gif_encode_close_file(gif_file->GifFile); + __gif_encode_close_file(gif_file->GifFile); return MM_UTIL_ERROR_INVALID_OPERATION; } @@ -702,12 +702,12 @@ int mm_util_gif_encode_add_image(mm_gif_file_h gif_file_h, mm_image_info_s *gif_ } /* Write graphic control block */ - ret = _gif_image_write_ext_block(gif_file, gif_image->delay_time); - mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "_gif_image_write_ext_block failed"); + ret = __gif_image_write_ext_block(gif_file, gif_image->delay_time); + mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "__gif_image_write_ext_block failed"); /* Write image description & data */ - ret = _gif_image_write_image(gif_file, gif_image); - mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "_gif_image_write_image failed"); + ret = __gif_image_write_image(gif_file, gif_image); + mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "__gif_image_write_image failed"); gif_file->GifFile->ImageCount++; @@ -725,9 +725,9 @@ int mm_util_gif_encode_save(mm_gif_file_h gif_file_h) mm_util_fenter(); - ret = _gif_encode_close_file(gif_file->GifFile); + ret = __gif_encode_close_file(gif_file->GifFile); gif_file->GifFile = NULL; - mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "_gif_encode_close_file failed"); + mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "__gif_encode_close_file failed"); if (gif_file->filename != NULL) ret = __write_gif_to_file(gif_file); @@ -838,8 +838,8 @@ void mm_util_gif_encode_destroy(mm_gif_file_h gif_file_h) mm_util_retm_if(gif_file == NULL, "Invalid parameter"); if (gif_file->GifFile != NULL) { - ret = _gif_encode_close_file(gif_file->GifFile); - mm_util_retm_if(ret != MM_UTIL_ERROR_NONE, "_gif_encode_close_file failed"); + ret = __gif_encode_close_file(gif_file->GifFile); + mm_util_retm_if(ret != MM_UTIL_ERROR_NONE, "__gif_encode_close_file failed"); } MMUTIL_SAFE_G_FREE(gif_file->filename); diff --git a/imgcv/mm_util_imgcv.cpp b/imgcv/mm_util_imgcv.cpp index 2667a8c..0d04d59 100755 --- a/imgcv/mm_util_imgcv.cpp +++ b/imgcv/mm_util_imgcv.cpp @@ -36,7 +36,7 @@ #define DEFAULT_RANGE_SATURATION 256 #define DEFAULT_RANGE_VALUE 256 -static int _mm_util_imgcv_init(mm_util_imgcv_s *handle, int width, int height) +static int __mm_util_imgcv_init(mm_util_imgcv_s *handle, int width, int height) { mm_util_fenter(); @@ -67,7 +67,7 @@ static int _mm_util_imgcv_init(mm_util_imgcv_s *handle, int width, int height) return MM_UTIL_ERROR_NONE; } -static void _mm_util_imgcv_uninit(mm_util_imgcv_s *handle) +static void __mm_util_imgcv_uninit(mm_util_imgcv_s *handle) { mm_util_fenter(); @@ -79,7 +79,7 @@ static void _mm_util_imgcv_uninit(mm_util_imgcv_s *handle) mm_util_fleave(); } -static int _mm_util_imgcv_set_buffer(mm_util_imgcv_s *handle, void *image_buffer) +static int __mm_util_imgcv_set_buffer(mm_util_imgcv_s *handle, void *image_buffer) { mm_util_fenter(); @@ -117,7 +117,7 @@ static void _convert_hsv_to_rgb(int hVal, int sVal, int vVal, float *rVal, float } -static int _mm_util_imgcv_calculate_hist(mm_util_imgcv_s *handle, unsigned char *rgb_r, unsigned char *rgb_g, unsigned char *rgb_b) +static int __mm_util_imgcv_calculate_hist(mm_util_imgcv_s *handle, unsigned char *rgb_r, unsigned char *rgb_g, unsigned char *rgb_b) { int nh = 0; int ns = 0; @@ -204,46 +204,35 @@ int mm_util_cv_extract_representative_color(void *image_buffer, int width, int h { mm_util_fenter(); - if (image_buffer == NULL) { - mm_util_error("#ERROR#: image buffer is NULL"); - return MM_UTIL_ERROR_INVALID_PARAMETER; - } + mm_util_retvm_if(!image_buffer, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid image_buffer"); mm_util_imgcv_s *handle = (mm_util_imgcv_s *)calloc(1, sizeof(mm_util_imgcv_s)); - if (handle == NULL) { - mm_util_error("#ERROR#: fail to create handle"); - return MM_UTIL_ERROR_OUT_OF_MEMORY; - } + mm_util_retvm_if(!handle, MM_UTIL_ERROR_OUT_OF_MEMORY, "fail to create handle"); - int ret = _mm_util_imgcv_init(handle, width, height); + int ret = __mm_util_imgcv_init(handle, width, height); if (ret != MM_UTIL_ERROR_NONE) { - _mm_util_imgcv_uninit(handle); - MMUTIL_SAFE_FREE(handle); - mm_util_error("#ERROR#: Fail to mm_util_imgcv_init: ret=%d", ret); - return ret; + mm_util_error("#ERROR#: Fail to __mm_util_imgcv_init: ret=%d", ret); + goto ERROR; } - ret = _mm_util_imgcv_set_buffer(handle, image_buffer); + ret = __mm_util_imgcv_set_buffer(handle, image_buffer); if (ret != MM_UTIL_ERROR_NONE) { - _mm_util_imgcv_uninit(handle); - MMUTIL_SAFE_FREE(handle); - mm_util_error("#ERROR#: Fail to mm_util_imgcv_set_buffer: ret=%d", ret); - return ret; + mm_util_error("#ERROR#: Fail to __mm_util_imgcv_set_buffer: ret=%d", ret); + goto ERROR; } - ret = _mm_util_imgcv_calculate_hist(handle, r_color, g_color, b_color); + ret = __mm_util_imgcv_calculate_hist(handle, r_color, g_color, b_color); if (ret != MM_UTIL_ERROR_NONE) { - _mm_util_imgcv_uninit(handle); - MMUTIL_SAFE_FREE(handle); - mm_util_error("#ERROR#: Fail to mm_util_imgcv_calculate_hist: ret=%d", ret); - return ret; + mm_util_error("#ERROR#: Fail to __mm_util_imgcv_calculate_hist: ret=%d", ret); + goto ERROR; } - _mm_util_imgcv_uninit(handle); +ERROR: + __mm_util_imgcv_uninit(handle); MMUTIL_SAFE_FREE(handle); mm_util_fleave(); - return MM_UTIL_ERROR_NONE; + return ret; } diff --git a/imgp/mm_util_imgp.c b/imgp/mm_util_imgp.c index 4355e1a..b0d5c8d 100644 --- a/imgp/mm_util_imgp.c +++ b/imgp/mm_util_imgp.c @@ -192,7 +192,6 @@ static gboolean __mm_select_rotate_plugin(mm_util_color_format_e _format) static int __mm_util_get_crop_image_size(mm_util_color_format_e format, unsigned int width, unsigned int height, size_t *imgsize) { - int ret = MM_UTIL_ERROR_NONE; unsigned char x_chroma_shift = 0; unsigned char y_chroma_shift = 0; unsigned int w2, h2, stride, stride2; @@ -272,7 +271,7 @@ static int __mm_util_get_crop_image_size(mm_util_color_format_e format, unsigned mm_util_debug("format: %d, *imgsize: %zu", format, *imgsize); - return ret; + return MM_UTIL_ERROR_NONE; } static int __mm_set_imgp_info_s(imgp_info_s *_imgp_info_s, mm_util_color_format_e src_format, unsigned int src_width, unsigned int src_height, mm_util_color_format_e dst_format, unsigned int dst_width, unsigned int dst_height, mm_util_img_rotate_type angle) @@ -318,14 +317,11 @@ static void __mm_util_imgp_finalize(GModule *module, imgp_info_s *_imgp_info_s) g_module_close(module); MMUTIL_SAFE_FREE(_imgp_info_s); - - return; } -static int __mm_util_crop_rgb32(const unsigned char *src, unsigned int src_width, unsigned int src_height, +static void __mm_util_crop_rgb32(const unsigned char *src, unsigned int src_width, unsigned int src_height, unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_width, unsigned int crop_dest_height, unsigned char *dst) { - int ret = MM_UTIL_ERROR_NONE; unsigned int idx = 0; int src_bytesperline = src_width * 4; int dst_bytesperline = crop_dest_width * 4; @@ -337,14 +333,11 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_wid src += src_bytesperline; dst += dst_bytesperline; } - - return ret; } -static int __mm_util_crop_rgb24(const unsigned char *src, unsigned int src_width, unsigned int src_height, +static void __mm_util_crop_rgb24(const unsigned char *src, unsigned int src_width, unsigned int src_height, unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_width, unsigned int crop_dest_height, unsigned char *dst) { - int ret = MM_UTIL_ERROR_NONE; unsigned int idx = 0; unsigned long src_bytesperline = src_width * 3; unsigned long dst_bytesperline = crop_dest_width * 3; @@ -356,14 +349,11 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_wid src += src_bytesperline; dst += dst_bytesperline; } - - return ret; } -static int __mm_util_crop_rgb16(const unsigned char *src, unsigned int src_width, unsigned int src_height, +static void __mm_util_crop_rgb16(const unsigned char *src, unsigned int src_width, unsigned int src_height, unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_width, unsigned int crop_dest_height, unsigned char *dst) { - int ret = MM_UTIL_ERROR_NONE; unsigned int idx = 0; unsigned long src_bytesperline = src_width * 2; unsigned long dst_bytesperline = crop_dest_width * 2; @@ -375,14 +365,11 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_wid src += src_bytesperline; dst += dst_bytesperline; } - - return ret; } -static int __mm_util_crop_yuv420(const unsigned char *src, unsigned int src_width, unsigned int src_height, +static void __mm_util_crop_yuv420(const unsigned char *src, unsigned int src_width, unsigned int src_height, unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_width, unsigned int crop_dest_height, unsigned char *dst) { - int ret = MM_UTIL_ERROR_NONE; unsigned int idx = 0; unsigned int start_x = crop_start_x; unsigned int start_y = crop_start_y; @@ -411,8 +398,6 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_wid _src += src_width / 2; dst += crop_dest_width / 2; } - - return ret; } static IMGPInfoFunc __mm_util_initialize(imgp_type_e function, mm_util_color_format_e src_format, mm_util_color_format_e dst_format, GModule **module) @@ -788,23 +773,23 @@ int mm_util_crop_image(mm_util_image_h src, unsigned int start_x, unsigned int s switch (_src->color) { case MM_UTIL_COLOR_RGB16: { - ret = __mm_util_crop_rgb16(_src->data, _src->width, _src->height, start_x, start_y, _width, _height, _buffer); + __mm_util_crop_rgb16(_src->data, _src->width, _src->height, start_x, start_y, _width, _height, _buffer); break; } case MM_UTIL_COLOR_RGB24: { - ret = __mm_util_crop_rgb24(_src->data, _src->width, _src->height, start_x, start_y, _width, _height, _buffer); + __mm_util_crop_rgb24(_src->data, _src->width, _src->height, start_x, start_y, _width, _height, _buffer); break; } case MM_UTIL_COLOR_ARGB: case MM_UTIL_COLOR_BGRA: case MM_UTIL_COLOR_RGBA: case MM_UTIL_COLOR_BGRX: { - ret = __mm_util_crop_rgb32(_src->data, _src->width, _src->height, start_x, start_y, _width, _height, _buffer); + __mm_util_crop_rgb32(_src->data, _src->width, _src->height, start_x, start_y, _width, _height, _buffer); break; } case MM_UTIL_COLOR_I420: case MM_UTIL_COLOR_YUV420: { - ret = __mm_util_crop_yuv420(_src->data, _src->width, _src->height, start_x, start_y, _width, _height, _buffer); + __mm_util_crop_yuv420(_src->data, _src->width, _src->height, start_x, start_y, _width, _height, _buffer); break; } default: @@ -813,10 +798,7 @@ int mm_util_crop_image(mm_util_image_h src, unsigned int start_x, unsigned int s return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT; } - if (ret == MM_UTIL_ERROR_NONE) - ret = mm_image_create_image(_width, _height, _src->color, _buffer, _buffer_size, dst); - else - mm_util_error("crop is failed (%d)", ret); + ret = mm_image_create_image(_width, _height, _src->color, _buffer, _buffer_size, dst); MMUTIL_SAFE_FREE(_buffer); mm_util_fleave(); @@ -826,7 +808,6 @@ int mm_util_crop_image(mm_util_image_h src, unsigned int start_x, unsigned int s int mm_util_get_image_size(mm_util_color_format_e format, unsigned int width, unsigned int height, size_t *imgsize) { - int ret = MM_UTIL_ERROR_NONE; unsigned char x_chroma_shift = 0; unsigned char y_chroma_shift = 0; unsigned int w2, h2, stride, stride2; @@ -907,6 +888,6 @@ int mm_util_get_image_size(mm_util_color_format_e format, unsigned int width, un mm_util_debug("format: %u, *imgsize: %zu", format, *imgsize); - return ret; + return MM_UTIL_ERROR_NONE; } diff --git a/jpeg/mm_util_jpeg.c b/jpeg/mm_util_jpeg.c index c3d77e6..afed1ed 100644 --- a/jpeg/mm_util_jpeg.c +++ b/jpeg/mm_util_jpeg.c @@ -74,7 +74,7 @@ static gboolean __is_supported_color_format_with_libjpeg(mm_util_color_format_e return _bool; } -static gboolean _mm_util_is_supported_color_format(mm_util_color_format_e color_format) +static gboolean __mm_util_is_supported_color_format(mm_util_color_format_e color_format) { gboolean _bool = FALSE; @@ -269,7 +269,7 @@ static int __jpeg_encode_yuv(j_compress_ptr cinfo, unsigned int width, unsigned return MM_UTIL_ERROR_NONE; } -static int _mm_util_jpeg_encode(mm_util_jpeg_ctrl_format_e control_format, mm_util_image_h decoded, int quality, FILE *fp, void **mem, size_t *csize) +static int __mm_util_jpeg_encode(mm_util_jpeg_ctrl_format_e control_format, mm_util_image_h decoded, int quality, FILE *fp, void **mem, size_t *csize) { int ret = MM_UTIL_ERROR_NONE; mm_image_info_s *_decoded = (mm_image_info_s *)decoded; @@ -366,7 +366,7 @@ static int _mm_util_jpeg_encode(mm_util_jpeg_ctrl_format_e control_format, mm_ut return ret; } -static int _mm_util_jpeg_decode(mm_util_jpeg_ctrl_format_e control_format, FILE *fp, void *src, size_t size, mm_util_color_format_e color_format, mm_util_jpeg_decode_downscale downscale, mm_util_image_h *decoded) +static int __mm_util_jpeg_decode(mm_util_jpeg_ctrl_format_e control_format, FILE *fp, void *src, size_t size, mm_util_color_format_e color_format, mm_util_jpeg_decode_downscale downscale, mm_util_image_h *decoded) { int ret = MM_UTIL_ERROR_NONE; struct jpeg_decompress_struct dinfo; @@ -499,7 +499,7 @@ int mm_util_jpeg_encode_to_file(mm_util_image_h decoded, int quality, const char mm_util_retvm_if(!file_path, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid file_path"); mm_util_retvm_if(!IS_VALID_IMAGE(decoded), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid image"); - mm_util_retvm_if((!_mm_util_is_supported_color_format(_decoded->color)), MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported fmt [%d]", _decoded->color); + mm_util_retvm_if((!__mm_util_is_supported_color_format(_decoded->color)), MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported fmt [%d]", _decoded->color); mm_util_retvm_if((quality < 1) || (quality > 100), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid quality [%d]", quality); FILE *fp = NULL; @@ -514,10 +514,10 @@ int mm_util_jpeg_encode_to_file(mm_util_image_h decoded, int quality, const char return ret; } - ret = _mm_util_jpeg_encode(MM_UTIL_JPEG_FILE, _converted_image, quality, fp, NULL, NULL); + ret = __mm_util_jpeg_encode(MM_UTIL_JPEG_FILE, _converted_image, quality, fp, NULL, NULL); mm_image_destroy_image(_converted_image); } else { - ret = _mm_util_jpeg_encode(MM_UTIL_JPEG_FILE, decoded, quality, fp, NULL, NULL); + ret = __mm_util_jpeg_encode(MM_UTIL_JPEG_FILE, decoded, quality, fp, NULL, NULL); } fsync((int)(fp->_fileno)); @@ -559,17 +559,17 @@ int mm_util_encode_to_jpeg_memory(mm_util_image_h decoded, int quality, void **b mm_util_retvm_if(!buffer, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid buffer"); mm_util_retvm_if(!size, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid size"); mm_util_retvm_if(!IS_VALID_IMAGE(decoded), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid image"); - mm_util_retvm_if((!_mm_util_is_supported_color_format(_decoded->color)), MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported color [%d]", _decoded->color); + mm_util_retvm_if((!__mm_util_is_supported_color_format(_decoded->color)), MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported color [%d]", _decoded->color); mm_util_retvm_if((quality < 1) || (quality > 100), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid quality [%d]", quality); if (_decoded->color == MM_UTIL_COLOR_NV12) { ret = mm_util_convert_colorspace(decoded, MM_UTIL_COLOR_YUV420, &_converted_image); mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "mm_util_convert_image fail (%d)", ret); - ret = _mm_util_jpeg_encode(MM_UTIL_JPEG_MEM, _converted_image, quality, NULL, buffer, size); + ret = __mm_util_jpeg_encode(MM_UTIL_JPEG_MEM, _converted_image, quality, NULL, buffer, size); mm_image_destroy_image(_converted_image); } else { - ret = _mm_util_jpeg_encode(MM_UTIL_JPEG_MEM, decoded, quality, NULL, buffer, size); + ret = __mm_util_jpeg_encode(MM_UTIL_JPEG_MEM, decoded, quality, NULL, buffer, size); } mm_util_fleave(); @@ -587,7 +587,7 @@ int mm_util_decode_from_jpeg_file(const char *file_path, mm_util_color_format_e mm_util_retvm_if(!MMUTIL_STRING_VALID(file_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid file_path"); mm_util_retvm_if((IS_VALID_COLOR(fmt) == FALSE), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid fmt [%d]", fmt); - mm_util_retvm_if((!_mm_util_is_supported_color_format(fmt)), MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported fmt [%d]", fmt); + mm_util_retvm_if((!__mm_util_is_supported_color_format(fmt)), MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported fmt [%d]", fmt); mm_util_retvm_if(!decoded, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid image handle"); if ((downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1) && (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_2) @@ -600,12 +600,12 @@ int mm_util_decode_from_jpeg_file(const char *file_path, mm_util_color_format_e mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "mm_util_safe_fopen fail (%d)", ret); if (fmt == MM_UTIL_COLOR_NV12) { - ret = _mm_util_jpeg_decode(MM_UTIL_JPEG_FILE, fp, NULL, 0, MM_UTIL_COLOR_YUV420, downscale, &_decoded); + ret = __mm_util_jpeg_decode(MM_UTIL_JPEG_FILE, fp, NULL, 0, MM_UTIL_COLOR_YUV420, downscale, &_decoded); if (ret == MM_UTIL_ERROR_NONE) ret = mm_util_convert_colorspace(_decoded, MM_UTIL_COLOR_NV12, decoded); mm_image_destroy_image(_decoded); } else { - ret = _mm_util_jpeg_decode(MM_UTIL_JPEG_FILE, fp, NULL, 0, fmt, downscale, decoded); + ret = __mm_util_jpeg_decode(MM_UTIL_JPEG_FILE, fp, NULL, 0, fmt, downscale, decoded); } mm_util_safe_fclose(fp); @@ -625,7 +625,7 @@ int mm_util_decode_from_jpeg_memory(void *memory, const size_t src_size, mm_util mm_util_retvm_if(!memory, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid jpeg image"); mm_util_retvm_if(!src_size, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_size"); mm_util_retvm_if((IS_VALID_COLOR(fmt) == FALSE), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid fmt [%d]", fmt); - mm_util_retvm_if((!_mm_util_is_supported_color_format(fmt)), MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported fmt [%d]", fmt); + mm_util_retvm_if((!__mm_util_is_supported_color_format(fmt)), MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported fmt [%d]", fmt); mm_util_retvm_if(!decoded, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid image handle"); if ((downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1) && (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_2) @@ -635,12 +635,12 @@ int mm_util_decode_from_jpeg_memory(void *memory, const size_t src_size, mm_util } if (fmt == MM_UTIL_COLOR_NV12) { - ret = _mm_util_jpeg_decode(MM_UTIL_JPEG_MEM, NULL, memory, src_size, MM_UTIL_COLOR_YUV420, downscale, &_decoded); + ret = __mm_util_jpeg_decode(MM_UTIL_JPEG_MEM, NULL, memory, src_size, MM_UTIL_COLOR_YUV420, downscale, &_decoded); if (ret == MM_UTIL_ERROR_NONE) ret = mm_util_convert_colorspace(_decoded, MM_UTIL_COLOR_NV12, decoded); mm_image_destroy_image(_decoded); } else { - ret = _mm_util_jpeg_decode(MM_UTIL_JPEG_MEM, NULL, memory, src_size, fmt, downscale, decoded); + ret = __mm_util_jpeg_decode(MM_UTIL_JPEG_MEM, NULL, memory, src_size, fmt, downscale, decoded); } mm_util_fleave(); diff --git a/magick/mm_util_info.c b/magick/mm_util_info.c index 8e63a22..895150a 100644 --- a/magick/mm_util_info.c +++ b/magick/mm_util_info.c @@ -43,7 +43,7 @@ static unsigned char gIfegGIFHeader[] = { "GIF" }; static unsigned char gIfegBMPHeader[] = { 0x42, 0x4D }; static unsigned char gIfegWBMPHeader[] = { 0x00, 0x00 }; -void __ImgGetFileAttributes(const char *szPathName, unsigned long *pFileAttr) +static void __ImgGetFileAttributes(const char *szPathName, unsigned long *pFileAttr) { FILE *f = NULL; @@ -57,33 +57,31 @@ void __ImgGetFileAttributes(const char *szPathName, unsigned long *pFileAttr) } } -static unsigned int _IfegReadUINT(unsigned char *pBuffer) +static unsigned int __IfegReadUINT(unsigned char *pBuffer) { return (((*pBuffer) << 24) | ((*(pBuffer + 1)) << 16) | ((*(pBuffer + 2)) << 8) | (*(pBuffer + 3))); } -static unsigned int _ReadBE16bitsToUINT(unsigned char *pBuffer) +static unsigned int __ReadBE16bitsToUINT(unsigned char *pBuffer) { return ((*pBuffer) << 8 | (*(pBuffer + 1))); } -static unsigned int _ReadLE16bitsToUINT(unsigned char *pBuffer) +static unsigned int __ReadLE16bitsToUINT(unsigned char *pBuffer) { return ((*pBuffer) | ((*(pBuffer + 1)) << 8)); } -static unsigned int _ReadLE32bitsToUINT(unsigned char *pBuffer) +static unsigned int __ReadLE32bitsToUINT(unsigned char *pBuffer) { return ((*pBuffer) | ((*(pBuffer + 1)) << 8) | ((*(pBuffer + 2)) << 16) | ((*(pBuffer + 3)) << 24)); } -static int _ImgGetImageInfo(FILE *hFile, unsigned long fileSize, char *fileExt, mm_util_img_codec_type *type, unsigned int *width, unsigned int *height) +static int __ImgGetImageInfo(FILE *hFile, unsigned long fileSize, char *fileExt, mm_util_img_codec_type *type, unsigned int *width, unsigned int *height) { unsigned long fileread; unsigned char EncodedDataBuffer[4096]; - int ret = MM_UTIL_ERROR_NONE; - mm_util_retvm_if((type == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "type is null"); mm_util_retvm_if((width == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "width is null"); mm_util_retvm_if((height == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "height is null"); @@ -96,7 +94,7 @@ static int _ImgGetImageInfo(FILE *hFile, unsigned long fileSize, char *fileExt, memset(EncodedDataBuffer, 0, 4096); fileread = fread(EncodedDataBuffer, sizeof(char), MINIMUM_HEADER_BYTES, hFile); - mm_util_retvm_if((fileread < MINIMUM_HEADER_BYTES), ret, "IMG_CODEC_UNKNOWN_TYPE"); + mm_util_retvm_if((fileread < MINIMUM_HEADER_BYTES), MM_UTIL_ERROR_INVALID_PARAMETER, "IMG_CODEC_UNKNOWN_TYPE"); if (memcmp(EncodedDataBuffer, gIfegJPEGHeader, JPG_HEADER_LENGTH) == 0) { unsigned char header_type[JPG_HEADER_TYPE_LENGTH]; @@ -123,7 +121,7 @@ static int _ImgGetImageInfo(FILE *hFile, unsigned long fileSize, char *fileExt, memset(header_type, 0, JPG_HEADER_TYPE_LENGTH); fileread = fread(header_type, sizeof(char), JPG_HEADER_TYPE_LENGTH, hFile); - mm_util_retvm_if((fileread < JPG_HEADER_TYPE_LENGTH), ret, "IMG_CODEC_UNKNOWN_TYPE in JPEG"); + mm_util_retvm_if((fileread < JPG_HEADER_TYPE_LENGTH), MM_UTIL_ERROR_INVALID_PARAMETER, "IMG_CODEC_UNKNOWN_TYPE in JPEG"); if (header_type[0] != 0xFF) { mm_util_warn("Failed to get w / h from jpeg at index [%llu] and go to next block.", i); @@ -135,17 +133,17 @@ static int _ImgGetImageInfo(FILE *hFile, unsigned long fileSize, char *fileExt, if (header_type[1] == 0xC0 || header_type[1] == 0xC2) { memset(image_size, 0, JPG_IMAGE_SIZE_LENGTH); fileread = fread(image_size, sizeof(char), JPG_IMAGE_SIZE_LENGTH, hFile); - mm_util_retvm_if((fileread < JPG_IMAGE_SIZE_LENGTH), ret, "IMG_CODEC_UNKNOWN_TYPE in JPEG"); + mm_util_retvm_if((fileread < JPG_IMAGE_SIZE_LENGTH), MM_UTIL_ERROR_INVALID_PARAMETER, "IMG_CODEC_UNKNOWN_TYPE in JPEG"); - *width = _ReadBE16bitsToUINT(image_size + 5); - *height = _ReadBE16bitsToUINT(image_size + 3); + *width = __ReadBE16bitsToUINT(image_size + 5); + *height = __ReadBE16bitsToUINT(image_size + 3); break; } else { i += JPG_HEADER_TYPE_LENGTH; memset(block_size, 0, JPG_BLOCK_SIZE_LENGTH); fileread = fread(block_size, sizeof(char), JPG_BLOCK_SIZE_LENGTH, hFile); - mm_util_retvm_if((fileread < JPG_BLOCK_SIZE_LENGTH), ret, "IMG_CODEC_UNKNOWN_TYPE in JPEG"); - block_length = (unsigned short)_ReadBE16bitsToUINT(block_size); + mm_util_retvm_if((fileread < JPG_BLOCK_SIZE_LENGTH), MM_UTIL_ERROR_INVALID_PARAMETER, "IMG_CODEC_UNKNOWN_TYPE in JPEG"); + block_length = (unsigned short)__ReadBE16bitsToUINT(block_size); mm_util_sec_debug("new block length : %u", block_length); if (fseek(hFile, block_length - JPG_BLOCK_SIZE_LENGTH, SEEK_CUR) < 0) { @@ -160,11 +158,11 @@ static int _ImgGetImageInfo(FILE *hFile, unsigned long fileSize, char *fileExt, /*********************** PNG *************************/ else if (memcmp(EncodedDataBuffer, gIfegPNGHeader, PNG_HEADER_LENGTH) == 0) { fileread = fread(EncodedDataBuffer, sizeof(char), 32, hFile); - mm_util_retvm_if((fileread < 32), ret, "IMG_CODEC_UNKNOWN_TYPE in PNG"); + mm_util_retvm_if((fileread < 32), MM_UTIL_ERROR_INVALID_PARAMETER, "IMG_CODEC_UNKNOWN_TYPE in PNG"); /* Get Image width & height */ - *width = _IfegReadUINT((EncodedDataBuffer + 8)); - *height = _IfegReadUINT((EncodedDataBuffer + 12)); + *width = __IfegReadUINT((EncodedDataBuffer + 8)); + *height = __IfegReadUINT((EncodedDataBuffer + 12)); mm_util_sec_debug("IMG_CODEC_PNG"); *type = IMG_CODEC_PNG; @@ -173,21 +171,21 @@ static int _ImgGetImageInfo(FILE *hFile, unsigned long fileSize, char *fileExt, else if (memcmp(EncodedDataBuffer, gIfegBMPHeader, BMP_HEADER_LENGTH) == 0) { /* Parse BMP File and get image width and image height */ fileread = fread(&EncodedDataBuffer[8], sizeof(char), 18, hFile); - mm_util_retvm_if((fileread < 18), ret, "IMG_CODEC_UNKNOWN_TYPE in BMP"); + mm_util_retvm_if((fileread < 18), MM_UTIL_ERROR_INVALID_PARAMETER, "IMG_CODEC_UNKNOWN_TYPE in BMP"); - *width = _ReadLE32bitsToUINT(EncodedDataBuffer + 18); + *width = __ReadLE32bitsToUINT(EncodedDataBuffer + 18); // add the reference function abs(). may have negative height values in bmp header. - *height = abs(_ReadLE32bitsToUINT(EncodedDataBuffer + 22)); + *height = abs(__ReadLE32bitsToUINT(EncodedDataBuffer + 22)); mm_util_sec_debug("IMG_CODEC_BMP"); *type = IMG_CODEC_BMP; } /*********************** GIF *************************/ else if (memcmp(EncodedDataBuffer, gIfegGIFHeader, GIF_HEADER_LENGTH) == 0) { - mm_util_retvm_if((MINIMUM_HEADER_BYTES + 4 > fileSize), ret, "IMG_CODEC_UNKNOWN_TYPE in GIF"); + mm_util_retvm_if((MINIMUM_HEADER_BYTES + 4 > fileSize), MM_UTIL_ERROR_INVALID_PARAMETER, "IMG_CODEC_UNKNOWN_TYPE in GIF"); fileread = fread(&EncodedDataBuffer[8], sizeof(char), 4, hFile); - mm_util_retvm_if((fileread < 4), ret, "IMG_CODEC_UNKNOWN_TYPE in GIF"); + mm_util_retvm_if((fileread < 4), MM_UTIL_ERROR_INVALID_PARAMETER, "IMG_CODEC_UNKNOWN_TYPE in GIF"); if (EncodedDataBuffer[0] != 'G' || EncodedDataBuffer[1] != 'I' || EncodedDataBuffer[2] != 'F' || EncodedDataBuffer[3] < '0' @@ -195,11 +193,11 @@ static int _ImgGetImageInfo(FILE *hFile, unsigned long fileSize, char *fileExt, || EncodedDataBuffer[4] > '9' || EncodedDataBuffer[5] < 'A' || EncodedDataBuffer[5] > 'z') { mm_util_warn("IMG_CODEC_UNKNOWN_TYPE in GIF"); - return ret; + return MM_UTIL_ERROR_INVALID_PARAMETER; } - *width = _ReadLE16bitsToUINT(EncodedDataBuffer + 6); - *height = _ReadLE16bitsToUINT(EncodedDataBuffer + 8); + *width = __ReadLE16bitsToUINT(EncodedDataBuffer + 6); + *height = __ReadLE16bitsToUINT(EncodedDataBuffer + 8); mm_util_sec_debug("IMG_CODEC_GIF"); *type = IMG_CODEC_GIF; @@ -213,11 +211,13 @@ static int _ImgGetImageInfo(FILE *hFile, unsigned long fileSize, char *fileExt, mm_util_sec_debug("IMG_CODEC_WBMP"); *type = IMG_CODEC_WBMP; } + mm_util_sec_debug("Image Width : %u, Height : %u", *width, *height); - return ret; + + return MM_UTIL_ERROR_NONE; } -static int _ImgGetFileExt(const char *path, char *file_ext, int max_len) +static int __ImgGetFileExt(const char *path, char *file_ext, int max_len) { int i = 0; @@ -242,14 +242,10 @@ int mm_util_extract_image_info(const char *path, mm_util_img_codec_type *type, u char file_ext[10] = { 0, }; int ret = MM_UTIL_ERROR_NONE; - if (path == NULL) - return MM_UTIL_ERROR_INVALID_PARAMETER; + mm_util_retvm_if(!path, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid path"); hFile = fopen(path, "rb"); - if (hFile == NULL) { - mm_util_error("file open error: %s", path); - return MM_UTIL_ERROR_INVALID_PARAMETER; - } + mm_util_retvm_if(!hFile, MM_UTIL_ERROR_INVALID_PARAMETER, "file open error: %s", path); __ImgGetFileAttributes(path, &file_size); if (file_size == 0) { @@ -257,11 +253,11 @@ int mm_util_extract_image_info(const char *path, mm_util_img_codec_type *type, u return MM_UTIL_ERROR_INVALID_PARAMETER; } - ret = _ImgGetFileExt(path, file_ext, sizeof(file_ext)); + ret = __ImgGetFileExt(path, file_ext, sizeof(file_ext)); if (ret != MM_UTIL_ERROR_NONE) - mm_util_warn("_ImgGetFileExt failed"); + mm_util_warn("__ImgGetFileExt failed"); - ret = _ImgGetImageInfo(hFile, file_size, file_ext, type, width, height); + ret = __ImgGetImageInfo(hFile, file_size, file_ext, type, width, height); if (fseek(hFile, 0, SEEK_SET) < 0) mm_util_stderror("fseek failed"); diff --git a/packaging/libmm-utility.spec b/packaging/libmm-utility.spec index 7521824..e6bcfa1 100755 --- a/packaging/libmm-utility.spec +++ b/packaging/libmm-utility.spec @@ -1,6 +1,6 @@ Name: libmm-utility Summary: Multimedia Framework Utility Library -Version: 0.1.34 +Version: 0.1.35 Release: 0 Group: System/Libraries License: Apache-2.0 -- 2.7.4