From 40ca045af71a36a5cad0584d354b78e41b08c07d Mon Sep 17 00:00:00 2001 From: "jiyong.min" Date: Tue, 12 Mar 2019 11:03:16 +0900 Subject: [PATCH] Modify parameter in imgage processing APIs to mm_util_image_h Change-Id: I39ceb170e91ad3948d73d3503e6996698ff775b3 --- imgp/include/mm_util_imgp.h | 19 +- imgp/mm_util_imgp.c | 339 +++++++++++++++------------------- imgp/test/mm_util_imgp_testsuite.c | 300 ++++++++++++++++++++---------- imgp/unittest/libmm_imgp_unittest.cpp | 264 +++++++------------------- jpeg/mm_util_jpeg.c | 54 ++---- 5 files changed, 447 insertions(+), 529 deletions(-) mode change 100755 => 100644 imgp/mm_util_imgp.c mode change 100755 => 100644 jpeg/mm_util_jpeg.c diff --git a/imgp/include/mm_util_imgp.h b/imgp/include/mm_util_imgp.h index 73bdb9c..0df3692 100644 --- a/imgp/include/mm_util_imgp.h +++ b/imgp/include/mm_util_imgp.h @@ -42,20 +42,11 @@ typedef enum { } mm_util_img_rotate_type; int mm_util_get_image_size(mm_util_color_format_e format, unsigned int width, unsigned int height, size_t *imgsize); -int mm_util_convert_colorspace(const unsigned char *src, unsigned int src_width, unsigned int src_height, - mm_util_color_format_e src_format, mm_util_color_format_e dst_format, unsigned char **dst, - unsigned int *result_buf_width, unsigned int *result_buf_height, size_t *result_buf_size); -int mm_util_resize_image(const unsigned char *src, unsigned int src_width, unsigned int src_height, - mm_util_color_format_e src_format, unsigned int dst_width, unsigned int dst_height, unsigned char **dst, - unsigned int *result_buf_width, unsigned int *result_buf_height, size_t *result_buf_size); -int mm_util_rotate_image(const unsigned char *src, unsigned int src_width, unsigned int src_height, - mm_util_color_format_e src_format, mm_util_img_rotate_type angle, unsigned char **dst, - unsigned int *result_buf_width, unsigned int *result_buf_height, size_t *result_buf_size); -int mm_util_crop_image(const unsigned char *src, unsigned int src_width, unsigned int src_height, - mm_util_color_format_e src_format, unsigned int crop_start_x, unsigned int crop_start_y, - unsigned int crop_dest_width, unsigned int crop_dest_height, unsigned char **dst, - unsigned int *result_buf_width, unsigned int *result_buf_height, size_t *result_buf_size); - +int mm_util_convert_colorspace(mm_util_image_h src, mm_util_color_format_e color, mm_util_image_h *dst); +int mm_util_resize_image(mm_util_image_h src, unsigned int width, unsigned int height, mm_util_image_h *dst); +int mm_util_rotate_image(mm_util_image_h src, mm_util_img_rotate_type angle, mm_util_image_h *dst); +int mm_util_crop_image(mm_util_image_h src, unsigned int start_x, unsigned int start_y, + unsigned int width, unsigned int height, mm_util_image_h *dst); #ifdef __cplusplus } diff --git a/imgp/mm_util_imgp.c b/imgp/mm_util_imgp.c old mode 100755 new mode 100644 index af9f5e2..655960a --- a/imgp/mm_util_imgp.c +++ b/imgp/mm_util_imgp.c @@ -200,8 +200,8 @@ static int __mm_util_get_crop_image_size(mm_util_color_format_e format, unsigned mm_util_fenter(); - mm_util_retvm_if(imgsize == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid imgsize"); - mm_util_retvm_if(__check_valid_picture_size(width, height) != MM_UTIL_ERROR_NONE, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid width and height"); + mm_util_retvm_if(imgsize == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid imgsize"); + mm_util_retvm_if(__check_valid_picture_size(width, height) != MM_UTIL_ERROR_NONE, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid width and height"); *imgsize = 0; @@ -279,7 +279,7 @@ static int __mm_set_imgp_info_s(imgp_info_s *_imgp_info_s, mm_util_color_format_ { int ret = MM_UTIL_ERROR_NONE; - mm_util_retvm_if(_imgp_info_s == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid _imgp_info_s"); + mm_util_retvm_if(_imgp_info_s == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid _imgp_info_s"); _imgp_info_s->src_format = src_format; _imgp_info_s->src_width = src_width; @@ -475,31 +475,25 @@ static bool __mm_util_check_format(mm_util_color_format_e color_format) return FALSE; } -int mm_util_convert_colorspace(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_color_format_e src_format, mm_util_color_format_e dst_format, unsigned char **dst, unsigned int *result_buf_width, unsigned int *result_buf_height, size_t *result_buf_size) +int mm_util_convert_colorspace(mm_util_image_h src, mm_util_color_format_e color, mm_util_image_h *dst) { int ret = MM_UTIL_ERROR_NONE; IMGPInfoFunc _mm_util_imgp_func = NULL; GModule *_module = NULL; unsigned char *output_buffer = NULL; - unsigned int res_w = 0; - unsigned int res_h = 0; - unsigned char *res_buffer = NULL; - size_t res_buffer_size = 0; - - mm_util_retvm_if(src == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src"); - mm_util_retvm_if(dst == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst"); - mm_util_retvm_if((IS_VALID_COLOR(src_format) == FALSE), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_format [%d]", src_format); - mm_util_retvm_if((IS_VALID_COLOR(dst_format) == FALSE), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_format [%d]", dst_format); - mm_util_retvm_if((__mm_util_check_format(src_format) == FALSE), MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported src_format [%d]", src_format); - mm_util_retvm_if((__mm_util_check_format(dst_format) == FALSE), MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported dst_format [%d]", dst_format); - mm_util_retvm_if(dst == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst"); - mm_util_retvm_if(result_buf_width == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_width"); - mm_util_retvm_if(result_buf_height == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_height"); - mm_util_retvm_if(result_buf_size == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_size"); - - mm_util_debug("src_width [%d] src_height [%d] src_format[%d] dst_format[%d]", src_width, src_height, src_format, dst_format); - - _mm_util_imgp_func = __mm_util_initialize(IMGP_CSC, src_format, dst_format, &_module); + mm_image_info_s *_src = (mm_image_info_s *)src; + mm_util_image_h _convert_image = NULL; + + mm_util_fenter(); + + mm_util_retvm_if(!IS_VALID_IMAGE(src), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid src"); + mm_util_retvm_if(!__mm_util_check_format(color), MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "Not supported format [%d]", color); + mm_util_retvm_if(!dst, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid dst"); + + mm_util_debug("[Input] format[%d]", color); + mm_image_debug_image(src, "Input"); + + _mm_util_imgp_func = __mm_util_initialize(IMGP_CSC, _src->color, color, &_module); if (_mm_util_imgp_func == NULL) { mm_util_error("ERROR - __mm_util_initialize"); return MM_UTIL_ERROR_INVALID_OPERATION; @@ -512,79 +506,73 @@ int mm_util_convert_colorspace(const unsigned char *src, unsigned int src_width, goto ERROR; } - res_w = src_width; - res_h = src_height; - - ret = __mm_set_imgp_info_s(_imgp_info_s, src_format, src_width, src_height, dst_format, src_width, src_height, MM_UTIL_ROTATE_0); + ret = __mm_set_imgp_info_s(_imgp_info_s, _src->color, _src->width, _src->height, color, _src->width, _src->height, MM_UTIL_ROTATE_0); if (ret != MM_UTIL_ERROR_NONE) { mm_util_error("__mm_set_imgp_info_s failed"); ret = MM_UTIL_ERROR_INVALID_OPERATION; goto ERROR; } - ret = _mm_util_imgp_func(_imgp_info_s, src, &output_buffer, IMGP_CSC); + ret = _mm_util_imgp_func(_imgp_info_s, _src->data, &output_buffer, IMGP_CSC); if (ret != MM_UTIL_ERROR_NONE) { mm_util_error("image processing failed"); goto ERROR; } if ((_imgp_info_s->dst_width != _imgp_info_s->output_stride || _imgp_info_s->dst_height != _imgp_info_s->output_elevation)) { - ret = mm_util_crop_image(output_buffer, _imgp_info_s->output_stride, _imgp_info_s->output_elevation, dst_format, 0, 0, _imgp_info_s->dst_width, _imgp_info_s->dst_height, &res_buffer, &res_w, &res_h, &res_buffer_size); + ret = mm_image_create_image(_imgp_info_s->output_stride, _imgp_info_s->output_elevation, color, output_buffer, _imgp_info_s->buffer_size, &_convert_image); if (ret != MM_UTIL_ERROR_NONE) { - mm_util_error("mm_util_crop_image failed"); - MMUTIL_SAFE_FREE(output_buffer); + mm_util_error("mm_image_create_image failed"); ret = MM_UTIL_ERROR_INVALID_OPERATION; goto ERROR; } - MMUTIL_SAFE_FREE(output_buffer); - *dst = res_buffer; - *result_buf_size = res_buffer_size; + ret = mm_util_crop_image(_convert_image, 0, 0, _imgp_info_s->dst_width, _imgp_info_s->dst_height, dst); + mm_image_destroy_image(_convert_image); + if (ret != MM_UTIL_ERROR_NONE) { + mm_util_error("mm_util_crop_image failed"); + ret = MM_UTIL_ERROR_INVALID_OPERATION; + goto ERROR; + } } else { - *dst = output_buffer; - *result_buf_size = _imgp_info_s->buffer_size; + ret = mm_image_create_image(_src->width, _src->height, color, output_buffer, _imgp_info_s->buffer_size, dst); + if (ret != MM_UTIL_ERROR_NONE) { + mm_util_error("mm_image_create_image failed"); + ret = MM_UTIL_ERROR_INVALID_OPERATION; + goto ERROR; + } } - *result_buf_width = res_w; - *result_buf_height = res_h; - - mm_util_debug("dst[%p] result_buf_w[%u] result_buf_h[%u] output_stride[%u] output_elevation[%u]", dst, *result_buf_width, *result_buf_height, _imgp_info_s->output_stride, _imgp_info_s->output_elevation); - ERROR: /* Finalize */ __mm_util_imgp_finalize(_module, _imgp_info_s); + MMUTIL_SAFE_FREE(output_buffer); mm_util_fleave(); return ret; } -int mm_util_resize_image(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_color_format_e src_format, unsigned int dst_width, unsigned int dst_height, unsigned char **dst, unsigned int *result_buf_width, unsigned int *result_buf_height, size_t *result_buf_size) +int mm_util_resize_image(mm_util_image_h src, unsigned int width, unsigned int height, mm_util_image_h *dst) { int ret = MM_UTIL_ERROR_NONE; IMGPInfoFunc _mm_util_imgp_func = NULL; GModule *_module = NULL; unsigned char *output_buffer = NULL; - unsigned int res_w = 0; - unsigned int res_h = 0; - unsigned char *res_buffer = NULL; - size_t res_buffer_size = 0; - - mm_util_retvm_if(src == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src"); - mm_util_retvm_if(src_width == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_width"); - mm_util_retvm_if(src_height == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_height"); - mm_util_retvm_if((IS_VALID_COLOR(src_format) == FALSE), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_format [%d]", src_format); - mm_util_retvm_if((__mm_util_check_format(src_format) == FALSE), MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported src_format [%d]", src_format); - mm_util_retvm_if(dst == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst"); - mm_util_retvm_if(dst_width == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_width"); - mm_util_retvm_if(dst_height == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_height"); - mm_util_retvm_if(result_buf_width == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_width"); - mm_util_retvm_if(result_buf_height == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_height"); - mm_util_retvm_if(result_buf_size == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_size"); - - mm_util_debug("src_width [%d] src_height [%d] src_format[%d]", src_width, src_height, src_format); - - _mm_util_imgp_func = __mm_util_initialize(IMGP_RSZ, src_format, 0, &_module); + mm_image_info_s *_src = (mm_image_info_s *)src; + mm_util_image_h _resize_image = NULL; + + mm_util_fenter(); + + mm_util_retvm_if(!IS_VALID_IMAGE(src), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid src"); + mm_util_retvm_if(width == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid width"); + mm_util_retvm_if(height == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid height"); + mm_util_retvm_if(!dst, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid dst"); + + mm_util_debug("[Input] width[%u] height[%u]", width, height); + mm_image_debug_image(src, "Input"); + + _mm_util_imgp_func = __mm_util_initialize(IMGP_RSZ, _src->color, 0, &_module); mm_util_retvm_if(_mm_util_imgp_func == NULL, MM_UTIL_ERROR_INVALID_OPERATION, "fail __mm_util_initialize"); imgp_info_s *_imgp_info_s = (imgp_info_s *) calloc(1, sizeof(imgp_info_s)); @@ -594,10 +582,7 @@ int mm_util_resize_image(const unsigned char *src, unsigned int src_width, unsig goto ERROR; } - res_w = dst_width; - res_h = dst_height; - - ret = __mm_set_imgp_info_s(_imgp_info_s, src_format, src_width, src_height, src_format, dst_width, dst_height, MM_UTIL_ROTATE_0); + ret = __mm_set_imgp_info_s(_imgp_info_s, _src->color, _src->width, _src->height, _src->color, width, height, MM_UTIL_ROTATE_0); if (ret != MM_UTIL_ERROR_NONE) { mm_util_error("__mm_set_imgp_info_s failed [%d]", ret); ret = MM_UTIL_ERROR_INVALID_OPERATION; @@ -612,7 +597,7 @@ int mm_util_resize_image(const unsigned char *src, unsigned int src_width, unsig } } - ret = _mm_util_imgp_func(_imgp_info_s, src, &output_buffer, IMGP_RSZ); + ret = _mm_util_imgp_func(_imgp_info_s, _src->data, &output_buffer, IMGP_RSZ); mm_util_debug("_mm_util_imgp_func, ret: %d", ret); if (ret != MM_UTIL_ERROR_NONE) { mm_util_error("image processing failed"); @@ -620,62 +605,60 @@ int mm_util_resize_image(const unsigned char *src, unsigned int src_width, unsig } if ((_imgp_info_s->dst_width != _imgp_info_s->output_stride || _imgp_info_s->dst_height != _imgp_info_s->output_elevation)) { - ret = mm_util_crop_image(output_buffer, _imgp_info_s->output_stride, _imgp_info_s->output_elevation, src_format, 0, 0, _imgp_info_s->dst_width, _imgp_info_s->dst_height, &res_buffer, &res_w, &res_h, &res_buffer_size); + ret = mm_image_create_image(_imgp_info_s->output_stride, _imgp_info_s->output_elevation, _src->color, output_buffer, _imgp_info_s->buffer_size, &_resize_image); if (ret != MM_UTIL_ERROR_NONE) { - mm_util_error("mm_util_crop_image failed"); - MMUTIL_SAFE_FREE(output_buffer); + mm_util_error("mm_image_create_image failed"); ret = MM_UTIL_ERROR_INVALID_OPERATION; goto ERROR; } - MMUTIL_SAFE_FREE(output_buffer); - *dst = res_buffer; - *result_buf_size = res_buffer_size; - + ret = mm_util_crop_image(_resize_image, 0, 0, _imgp_info_s->dst_width, _imgp_info_s->dst_height, dst); + mm_image_destroy_image(_resize_image); + if (ret != MM_UTIL_ERROR_NONE) { + mm_util_error("mm_util_crop_image failed"); + ret = MM_UTIL_ERROR_INVALID_OPERATION; + goto ERROR; + } } else { - *dst = output_buffer; - *result_buf_size = _imgp_info_s->buffer_size; + ret = mm_image_create_image(width, height, _src->color, output_buffer, _imgp_info_s->buffer_size, dst); + if (ret != MM_UTIL_ERROR_NONE) { + mm_util_error("mm_image_create_image failed"); + ret = MM_UTIL_ERROR_INVALID_OPERATION; + goto ERROR; + } } - *result_buf_width = res_w; - *result_buf_height = res_h; - - mm_util_debug("dst[%p] result_buf_w[%u] result_buf_h[%u] output_stride[%u] output_elevation[%u]", dst, *result_buf_width, *result_buf_height, _imgp_info_s->output_stride, _imgp_info_s->output_elevation); - ERROR: /* Finalize */ __mm_util_imgp_finalize(_module, _imgp_info_s); + MMUTIL_SAFE_FREE(output_buffer); mm_util_fleave(); return ret; } -int mm_util_rotate_image(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_color_format_e src_format, mm_util_img_rotate_type angle, unsigned char **dst, unsigned int *result_buf_width, unsigned int *result_buf_height, size_t *result_buf_size) +int mm_util_rotate_image(mm_util_image_h src, mm_util_img_rotate_type angle, mm_util_image_h *dst) { int ret = MM_UTIL_ERROR_NONE; IMGPInfoFunc _mm_util_imgp_func = NULL; GModule *_module = NULL; unsigned char *output_buffer = NULL; - unsigned int res_w = 0; - unsigned int res_h = 0; - unsigned char *res_buffer = NULL; - size_t res_buffer_size = 0; - - mm_util_retvm_if(src == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src"); - mm_util_retvm_if(src_width == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_width"); - mm_util_retvm_if(src_height == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_height"); - mm_util_retvm_if((IS_VALID_COLOR(src_format) == FALSE), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_format [%d]", src_format); - mm_util_retvm_if((__mm_util_check_format(src_format) == FALSE), MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported src_format [%d]", src_format); - mm_util_retvm_if((angle < MM_UTIL_ROTATE_0) || (angle >= MM_UTIL_ROTATE_NUM), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid angle [%d]", angle); - mm_util_retvm_if(dst == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst"); - mm_util_retvm_if(result_buf_width == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_width"); - mm_util_retvm_if(result_buf_height == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_height"); - mm_util_retvm_if(result_buf_size == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_size"); - - mm_util_debug("src_w[%u] src_h[%u] src_format[%u] angle[%u]", src_width, src_height, src_format, angle); - - _mm_util_imgp_func = __mm_util_initialize(IMGP_ROT, src_format, 0, &_module); + unsigned int uint_w = 0; + unsigned int uint_h = 0; + mm_image_info_s *_src = (mm_image_info_s *)src; + mm_util_image_h _rotate_image = NULL; + + mm_util_fenter(); + + mm_util_retvm_if(!IS_VALID_IMAGE(src), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid src"); + mm_util_retvm_if((angle < MM_UTIL_ROTATE_0) || (angle >= MM_UTIL_ROTATE_NUM), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid angle [%d]", angle); + mm_util_retvm_if(!dst, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid dst"); + + mm_util_debug("[Input] angle[%d]", angle); + mm_image_debug_image(src, "Input"); + + _mm_util_imgp_func = __mm_util_initialize(IMGP_ROT, _src->color, 0, &_module); if (_mm_util_imgp_func == NULL) { mm_util_error("ERROR - __mm_util_initialize"); return MM_UTIL_ERROR_INVALID_OPERATION; @@ -689,14 +672,14 @@ int mm_util_rotate_image(const unsigned char *src, unsigned int src_width, unsig } if ((angle == MM_UTIL_ROTATE_90) || (angle == MM_UTIL_ROTATE_270)) { - res_w = src_height; - res_h = src_width; + uint_w = _src->height; + uint_h = _src->width; } else { - res_w = src_width; - res_h = src_height; + uint_w = _src->width; + uint_h = _src->height; } - ret = __mm_set_imgp_info_s(_imgp_info_s, src_format, src_width, src_height, src_format, res_w, res_h, angle); + ret = __mm_set_imgp_info_s(_imgp_info_s, _src->color, _src->width, _src->height, _src->color, uint_w, uint_h, angle); mm_util_debug("__mm_set_imgp_info_s"); if (ret != MM_UTIL_ERROR_NONE) { mm_util_error("__mm_set_imgp_info_s failed"); @@ -712,7 +695,7 @@ int mm_util_rotate_image(const unsigned char *src, unsigned int src_width, unsig } } - ret = _mm_util_imgp_func(_imgp_info_s, src, &output_buffer, IMGP_ROT); + ret = _mm_util_imgp_func(_imgp_info_s, _src->data, &output_buffer, IMGP_ROT); if (ret != MM_UTIL_ERROR_NONE) { mm_util_error("image processing failed"); goto ERROR; @@ -731,122 +714,108 @@ int mm_util_rotate_image(const unsigned char *src, unsigned int src_width, unsig start_x = 0; start_y = _imgp_info_s->output_elevation - _imgp_info_s->dst_height; } - ret = mm_util_crop_image(output_buffer, _imgp_info_s->output_stride, _imgp_info_s->output_elevation, src_format, start_x, start_y, _imgp_info_s->dst_width, _imgp_info_s->dst_height, &res_buffer, &res_w, &res_h, &res_buffer_size); + ret = mm_image_create_image(_imgp_info_s->output_stride, _imgp_info_s->output_elevation, _src->color, output_buffer, _imgp_info_s->buffer_size, &_rotate_image); if (ret != MM_UTIL_ERROR_NONE) { - mm_util_error("mm_util_crop_image failed"); - MMUTIL_SAFE_FREE(output_buffer); + mm_util_error("mm_image_create_image failed"); ret = MM_UTIL_ERROR_INVALID_OPERATION; goto ERROR; } - MMUTIL_SAFE_FREE(output_buffer); - *dst = res_buffer; - *result_buf_size = res_buffer_size; + ret = mm_util_crop_image(_rotate_image, 0, 0, start_x, start_y, dst); + mm_image_destroy_image(_rotate_image); + if (ret != MM_UTIL_ERROR_NONE) { + mm_util_error("mm_util_crop_image failed"); + ret = MM_UTIL_ERROR_INVALID_OPERATION; + goto ERROR; + } } else { - *dst = output_buffer; - *result_buf_size = _imgp_info_s->buffer_size; + ret = mm_image_create_image(uint_w, uint_h, _src->color, output_buffer, _imgp_info_s->buffer_size, dst); + if (ret != MM_UTIL_ERROR_NONE) { + mm_util_error("mm_image_create_image failed"); + ret = MM_UTIL_ERROR_INVALID_OPERATION; + goto ERROR; + } } - *result_buf_width = res_w; - *result_buf_height = res_h; - - mm_util_debug("dst[%p] result_buf_w[%u] result_buf_h[%u] output_stride[%u] output_elevation[%u]", dst, *result_buf_width, *result_buf_height, _imgp_info_s->output_stride, _imgp_info_s->output_elevation); - ERROR: /* Finalize */ __mm_util_imgp_finalize(_module, _imgp_info_s); + MMUTIL_SAFE_FREE(output_buffer); mm_util_fleave(); return ret; } -int mm_util_crop_image(const unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_color_format_e src_format, -unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_width, unsigned int crop_dest_height, unsigned char **dst, unsigned int *result_buf_width, unsigned int *result_buf_height, size_t *result_buf_size) +int mm_util_crop_image(mm_util_image_h src, unsigned int start_x, unsigned int start_y, unsigned int width, unsigned int height, mm_util_image_h *dst) { int ret = MM_UTIL_ERROR_NONE; - size_t dst_buf_size = 0; - unsigned char *dst_buffer = NULL; - unsigned int res_w = 0; - unsigned int res_h = 0; - - mm_util_retvm_if(src == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src"); - mm_util_retvm_if(src_width == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_width"); - mm_util_retvm_if(src_height == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_height"); - mm_util_retvm_if((IS_VALID_COLOR(src_format) == FALSE), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_format [%d]", src_format); - mm_util_retvm_if((__mm_util_check_format(src_format) == FALSE), MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported src_format [%d]", src_format); - mm_util_retvm_if(dst == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst"); - mm_util_retvm_if(result_buf_width == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_width"); - mm_util_retvm_if(result_buf_height == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_height"); - mm_util_retvm_if(result_buf_size == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid result_buf_size"); - mm_util_retvm_if((crop_start_x + crop_dest_width == 0), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid crop_width [%d]]", crop_dest_width); - mm_util_retvm_if((crop_start_y + crop_dest_height == 0), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid crop_height [%d]", crop_dest_height); - mm_util_retvm_if((crop_start_x + crop_dest_width > src_width), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid position [%d]]", crop_start_x); - mm_util_retvm_if((crop_start_y + crop_dest_height > src_height), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid position [%d]", crop_start_y); - - mm_util_debug("[Input] src[%p] src_width[%u] src_height[%u] src_format[%d] crop_start_x[%u] crop_start_y[%u] crop_dest_width[%u] crop_dest_height[%u]", - src, src_width, src_height, src_format, crop_start_x, crop_start_y, crop_dest_width, crop_dest_height); - - __mm_util_get_crop_image_size(src_format, crop_dest_width, crop_dest_height, &dst_buf_size); - mm_util_retvm_if(dst_buf_size == 0, MM_UTIL_ERROR_INVALID_OPERATION, "fail to get dst_buf_size"); - - dst_buffer = calloc(1, dst_buf_size); - mm_util_retvm_if(dst_buffer == NULL, MM_UTIL_ERROR_OUT_OF_MEMORY, "memory alloc fail"); - - res_w = crop_dest_width; - res_h = crop_dest_height; - - switch (src_format) { + mm_image_info_s *_src = (mm_image_info_s *)src; + unsigned int _width = width; + unsigned int _height = height; + unsigned char *_buffer = NULL; + size_t _buffer_size = 0; + + mm_util_fenter(); + + mm_util_retvm_if(!IS_VALID_IMAGE(src), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid src"); + mm_util_retvm_if((start_x + width > _src->width), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid position [%u][%u]", start_x, width); + mm_util_retvm_if((start_y + height > _src->height), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid position [%u][%u]", start_y, height); + mm_util_retvm_if(!dst, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid dst"); + + mm_util_debug("[Input] start_x[%u] start_y[%u] width[%u] height[%u]", start_x, start_y, width, height); + mm_image_debug_image(src, "Input"); + + if (_src->color == MM_UTIL_COLOR_I420 || _src->color == MM_UTIL_COLOR_YUV420) { + if ((_width % 2) != 0) { + mm_util_warn("#YUV Width value(%u) must be even at least# ", _width); + _width = ((_width+1)>>1)<<1; + mm_util_debug("Image isplay is suceeded when YUV crop width value %u", _width); + } + + if ((_height % 2) != 0) { /* height value must be also even when crop yuv image */ + mm_util_warn("#YUV Height value(%u) must be even at least# ", _height); + _height = ((_height+1)>>1)<<1; + mm_util_debug("Image isplay is suceeded when YUV crop height value %u", _height); + } + } + + __mm_util_get_crop_image_size(_src->color, _width, _height, &_buffer_size); + mm_util_retvm_if(!_buffer_size, MM_UTIL_ERROR_INVALID_OPERATION, "fail to get dst_buf_size"); + + _buffer = calloc(1, _buffer_size); + mm_util_retvm_if(!_buffer, MM_UTIL_ERROR_OUT_OF_MEMORY, "Memory allocation failed"); + + switch (_src->color) { case MM_UTIL_COLOR_RGB16: { - ret = __mm_util_crop_rgb16(src, src_width, src_height, crop_start_x, crop_start_y, res_w, res_h, dst_buffer); + ret = __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, src_width, src_height, crop_start_x, crop_start_y, res_w, res_h, dst_buffer); + ret = __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, src_width, src_height, crop_start_x, crop_start_y, res_w, res_h, dst_buffer); + ret = __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: { - if ((crop_dest_width % 2) != 0) { - mm_util_warn("#YUV Width value(%d) must be even at least# ", crop_dest_width); - res_w = ((crop_dest_width+1)>>1)<<1; - mm_util_debug("Image isplay is suceeded when YUV crop width value %d", res_w); - } - - if ((crop_dest_height % 2) != 0) { /* height value must be also even when crop yuv image */ - mm_util_warn("#YUV Height value(%d) must be even at least# ", crop_dest_height); - res_h = ((crop_dest_height+1)>>1)<<1; - mm_util_debug("Image isplay is suceeded when YUV crop height value %d", res_h); - } - - MMUTIL_SAFE_FREE(dst_buffer); - __mm_util_get_crop_image_size(src_format, res_w, res_h, &dst_buf_size); - mm_util_retvm_if(dst_buf_size == 0, MM_UTIL_ERROR_INVALID_OPERATION, "fail to get dst_buf_size"); - - dst_buffer = calloc(1, dst_buf_size); - mm_util_retvm_if(dst_buffer == NULL, MM_UTIL_ERROR_OUT_OF_MEMORY, "memory alloc fail"); - - ret = __mm_util_crop_yuv420(src, src_width, src_height, crop_start_x, crop_start_y, res_w, res_h, dst_buffer); + ret = __mm_util_crop_yuv420(_src->data, _src->width, _src->height, start_x, start_y, _width, _height, _buffer); break; } default: mm_util_debug("Not supported format"); - MMUTIL_SAFE_FREE(dst_buffer); - ret = MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT; + MMUTIL_SAFE_FREE(_buffer); + return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT; } - *result_buf_size = dst_buf_size; - *dst = dst_buffer; - *result_buf_width = res_w; - *result_buf_height = res_h; + ret = mm_image_create_image(_width, _height, _src->color, _buffer, _buffer_size, dst); + MMUTIL_SAFE_FREE(_buffer); mm_util_fleave(); return ret; @@ -862,8 +831,8 @@ int mm_util_get_image_size(mm_util_color_format_e format, unsigned int width, un mm_util_fenter(); - mm_util_retvm_if((imgsize == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid imgsize"); - mm_util_retvm_if((IS_VALID_COLOR(format) == FALSE), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid format [%d]", format); + mm_util_retvm_if((imgsize == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid imgsize"); + mm_util_retvm_if((IS_VALID_COLOR(format) == FALSE), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid format [%d]", format); mm_util_retvm_if((__check_valid_picture_size(width, height) != MM_UTIL_ERROR_NONE), MM_UTIL_ERROR_INVALID_PARAMETER, "image width & height is too big"); *imgsize = 0; diff --git a/imgp/test/mm_util_imgp_testsuite.c b/imgp/test/mm_util_imgp_testsuite.c index a67124e..4d4bfd7 100644 --- a/imgp/test/mm_util_imgp_testsuite.c +++ b/imgp/test/mm_util_imgp_testsuite.c @@ -26,10 +26,43 @@ #include #include #include +#include #include #include -#define IMGP_FREE(src) { if (src != NULL) {g_free(src); src = NULL; } } +#define IMGP_FREE(src) { if (src != NULL) {g_free(src); src = NULL; } } +#define SAFE_IMAGE_FREE(x) { if (x != NULL) { mm_image_destroy_image(x); x = NULL; } } + +typedef struct { + /* for source image */ + char *path; + unsigned int width; + unsigned int height; + unsigned int colorspace; + void *data; + size_t size; + + /* for parameter in image processing */ + char *cmd; + unsigned int x; + unsigned int y; + unsigned int w; + unsigned int h; + unsigned int rot; + unsigned int cs; +} input_params; + +typedef struct { + /* for destination image */ + char path[PATH_MAX]; + unsigned int width; + unsigned int height; + unsigned char *data; + size_t size; +} output_values; + +static input_params g_args; +static output_values g_transformed; static gboolean _read_file(char *path, void **data, size_t *length) { @@ -37,27 +70,27 @@ static gboolean _read_file(char *path, void **data, size_t *length) long len = 0; if (!path || !data || length == 0) { - fprintf(stderr, "\t[JPEG_testsuite] invalid data %s %p %p\n", path, data, length); + fprintf(stderr, "\t[IMGP_testsuite] invalid data %s %p %p\n", path, data, length); return FALSE; } - fprintf(stderr, "\t[JPEG_testsuite] %s read\n", path); + fprintf(stderr, "\t[IMGP_testsuite] %s read\n", path); fp = fopen(path, "r"); if (fp == NULL) { - fprintf(stderr, "\t[JPEG_testsuite] fopen failed (%d) \n", errno); + fprintf(stderr, "\t[IMGP_testsuite] fopen failed (%d) \n", errno); return FALSE; } if (fseek(fp, 0, SEEK_END) < 0) { - fprintf(stderr, "\t[JPEG_testsuite] fseek failed \n"); + fprintf(stderr, "\t[IMGP_testsuite] fseek failed \n"); fclose(fp); return FALSE; } len = ftell(fp); if (len < 0) { - fprintf(stderr, "\t[JPEG_testsuite] ftell failed \n"); + fprintf(stderr, "\t[IMGP_testsuite] ftell failed \n"); fclose(fp); return FALSE; } @@ -72,7 +105,7 @@ static gboolean _read_file(char *path, void **data, size_t *length) *length = fread(*data, 1, (size_t)len, fp); if (*length != len) { - fprintf(stderr, "\t[JPEG_testsuite] fread failed \n"); + fprintf(stderr, "\t[IMGP_testsuite] fread failed \n"); } fclose(fp); @@ -84,7 +117,7 @@ static gboolean _read_file(char *path, void **data, size_t *length) *length = (size_t)len; - fprintf(stderr, "\t[JPEG_testsuite] %s %zu read DONE\n", path, *length); + fprintf(stderr, "\t[IMGP_testsuite] %s %zu read DONE\n", path, *length); return TRUE; } @@ -95,27 +128,27 @@ static gboolean _write_file(const char *path, void *data, size_t length) size_t len = 0; if (!path || !data || length == 0) { - fprintf(stderr, "\t[JPEG_testsuite] invalid data %s %p %zu\n", path, data, length); + fprintf(stderr, "\t[IMGP_testsuite] invalid data %s %p %zu\n", path, data, length); return FALSE; } - fprintf(stderr, "\t[JPEG_testsuite] %s %p %zu write\n", path, data, length); + fprintf(stderr, "\t[IMGP_testsuite] %s %p %zu write\n", path, data, length); fp = fopen(path, "w"); if (fp == NULL) { - fprintf(stderr, "\t[JPEG_testsuite] fopen failed (%d) \n", errno); + fprintf(stderr, "\t[IMGP_testsuite] fopen failed (%d) \n", errno); return FALSE; } len = fwrite(data, 1, length, fp); if (len != length) { - fprintf(stderr, "\t[JPEG_testsuite] fwrite failed \n"); + fprintf(stderr, "\t[IMGP_testsuite] fwrite failed \n"); } fclose(fp); fp = NULL; - fprintf(stderr, "\t[JPEG_testsuite] %s write DONE\n", path); + fprintf(stderr, "\t[IMGP_testsuite] %s write DONE\n", path); return TRUE; } @@ -135,117 +168,196 @@ gboolean _get_input_data(const char *argv, const unsigned long min, const unsign return TRUE; } -int main(int argc, char *argv[]) +void _print_help(const char *argv0) { - int ret = 0; - void *src = NULL; - unsigned char *dst = NULL; - - if (argc < 12) { - fprintf(stderr, "Usage: %s {filename} {command} src_width src_height src_foramt dst_width dst_height dst_format roation crop_start_x crop_start_y \n", argv[0]); - fprintf(stderr, "ex: %s test.rgb resize 1920 1080 7 1280 720 7 0 0 0 \n", argv[0]); - return ret; - } - - size_t src_size = 0; - char *filename = g_strdup(argv[1]); - char *command = g_strdup(argv[2]); - unsigned int src_width = 0; - unsigned int src_height = 0; - mm_util_color_format_e src_format = 0; - unsigned int dst_width = 0; - unsigned int dst_height = 0; - mm_util_color_format_e dst_format = 0; - mm_util_img_rotate_type rotation = 0; - unsigned int start_x = 0; - unsigned int start_y = 0; - char output_file[40] = {}; - unsigned int res_w = 0; - unsigned int res_h = 0; - size_t res_buffer_size = 0; - - if (filename == NULL || command == NULL) { - fprintf(stderr, "\t[IMGP_testsuite] invalid filename or command\n"); - goto TEST_FAIL; + fprintf(stderr, "\t[usage]\n"); + fprintf(stderr, "\t\t0. %s {path} {command} src_width src_height src_foramt {params} \n", argv0); + fprintf(stderr, "\t\t1. command - convert, resize, rotate and crop \n"); + fprintf(stderr, "\t\t2. %s {path} convert src_width src_height src_foramt format \n", argv0); + fprintf(stderr, "\t\t3. ex: %s test.rgb convert 1920 1080 7 0 \n", argv0); + fprintf(stderr, "\t\t4. %s {path} resize src_width src_height src_foramt width height \n", argv0); + fprintf(stderr, "\t\t5. ex: %s test.rgb resize 1920 1080 7 1280 720 \n", argv0); + fprintf(stderr, "\t\t6. %s {path} rotate src_width src_height src_foramt rotation \n", argv0); + fprintf(stderr, "\t\t7. ex: %s test.rgb rotate 1920 1080 7 1 \n", argv0); + fprintf(stderr, "\t\t8. %s {path} crop src_width src_height src_foramt start_x start_y width height \n", argv0); + fprintf(stderr, "\t\t9. ex: %s test.rgb crop 1920 1080 7 100 100 640 480 \n", argv0); +} + +gboolean _get_arguments(int argc, char *argv[]) +{ + unsigned int index = 1; + + g_args.path = g_strdup(argv[index++]); + g_args.cmd = g_strdup(argv[index++]); + + if (!g_args.path || !g_args.cmd) { + fprintf(stderr, "\t[IMGP_testsuite] invalid path or command\n"); + return FALSE; } - /* get arguments */ - if (FALSE == _get_input_data(argv[3], 0, UINT_MAX, &src_width)) { - fprintf(stderr, "\t[IMGP_testsuite] wrong src_width %s\n", argv[3]); - goto TEST_FAIL; + if (FALSE == _get_input_data(argv[index++], 0, UINT_MAX, &g_args.width)) { + fprintf(stderr, "\t[IMGP_testsuite] wrong src_width %s\n", argv[index-1]); + return FALSE; } - if (FALSE == _get_input_data(argv[4], 0, UINT_MAX, &src_height)) { - fprintf(stderr, "\t[IMGP_testsuite] wrong src_height %s\n", argv[4]); - goto TEST_FAIL; + if (FALSE == _get_input_data(argv[index++], 0, UINT_MAX, &g_args.height)) { + fprintf(stderr, "\t[IMGP_testsuite] wrong src_height %s\n", argv[index-1]); + return FALSE; } - if (FALSE == _get_input_data(argv[5], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &src_format)) { - fprintf(stderr, "\t[IMGP_testsuite] wrong src_format %s\n", argv[5]); - goto TEST_FAIL; + if (FALSE == _get_input_data(argv[index++], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &g_args.colorspace)) { + fprintf(stderr, "\t[IMGP_testsuite] wrong src_format %s\n", argv[index-1]); + return FALSE; } - if (FALSE == _get_input_data(argv[6], 0, UINT_MAX, &dst_width)) { - fprintf(stderr, "\t[IMGP_testsuite] wrong dst_width %s\n", argv[6]); - goto TEST_FAIL; + if (strcmp(g_args.cmd, "convert") == 0) { + if (argc < 7) { + _print_help(argv[0]); + return FALSE; + } + + if (FALSE == _get_input_data(argv[index++], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &g_args.cs)) { + fprintf(stderr, "\t[IMGP_testsuite] wrong dst_format %s\n", argv[index-1]); + return FALSE; + } + } else if (strcmp(g_args.cmd, "resize") == 0) { + if (argc < 8) { + _print_help(argv[0]); + return FALSE; + } + + if (FALSE == _get_input_data(argv[index++], 0, UINT_MAX, &g_args.w)) { + fprintf(stderr, "\t[IMGP_testsuite] wrong dst_width %s\n", argv[index-1]); + return FALSE; + } + if (FALSE == _get_input_data(argv[index++], 0, UINT_MAX, &g_args.h)) { + fprintf(stderr, "\t[IMGP_testsuite] wrong dst_height %s\n", argv[index-1]); + return FALSE; + } + } else if (strcmp(g_args.cmd, "rotate") == 0) { + if (argc < 7) { + _print_help(argv[0]); + return FALSE; + } + + if (FALSE == _get_input_data(argv[index++], MM_UTIL_ROTATE_0, MM_UTIL_ROTATE_NUM - 1, &g_args.rot)) { + fprintf(stderr, "\t[IMGP_testsuite] wrong rotation %s\n", argv[index-1]); + return FALSE; + } + } else if (strcmp(g_args.cmd, "crop") == 0) { + if (argc < 10) { + _print_help(argv[0]); + return FALSE; + } + + if (FALSE == _get_input_data(argv[index++], 0, UINT_MAX, &g_args.x)) { + fprintf(stderr, "\t[IMGP_testsuite] wrong start_x %s\n", argv[index-1]); + return FALSE; + } + if (FALSE == _get_input_data(argv[index++], 0, UINT_MAX, &g_args.y)) { + fprintf(stderr, "\t[IMGP_testsuite] wrong start_y %s\n", argv[index-1]); + return FALSE; + } + if (FALSE == _get_input_data(argv[index++], 0, UINT_MAX, &g_args.w)) { + fprintf(stderr, "\t[IMGP_testsuite] wrong dst_width %s\n", argv[index-1]); + return FALSE; + } + if (FALSE == _get_input_data(argv[index++], 0, UINT_MAX, &g_args.h)) { + fprintf(stderr, "\t[IMGP_testsuite] wrong dst_height %s\n", argv[index-1]); + return FALSE; + } } - if (FALSE == _get_input_data(argv[7], 0, UINT_MAX, &dst_height)) { - fprintf(stderr, "\t[IMGP_testsuite] wrong dst_height %s\n", argv[7]); - goto TEST_FAIL; + + fprintf(stderr, "\t[IMGP_testsuite] cmd: %s, w: %u, h: %u, cs:%u, rot:%u, x: %u, y: %u\n", + g_args.cmd, g_args.w, g_args.h, g_args.cs, g_args.rot, g_args.x, g_args.y); + + return TRUE; +} + +int main(int argc, char *argv[]) +{ + int ret = 0; + mm_util_image_h _src = NULL; + mm_util_image_h _dst = NULL; + + if (argc < 6) { + _print_help(argv[0]); + return 0; } - if (FALSE == _get_input_data(argv[8], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &dst_format)) { - fprintf(stderr, "\t[IMGP_testsuite] wrong dst_format %s\n", argv[8]); + + /* initialize data */ + memset(&g_args, 0, sizeof(g_args)); + memset(&g_transformed, 0, sizeof(g_transformed)); + + /* get arguments */ + if (FALSE == _get_arguments(argc, argv)) { + fprintf(stderr, "\t[IMGP_testsuite] _get_arguments failed\n"); goto TEST_FAIL; } - if (FALSE == _get_input_data(argv[9], MM_UTIL_ROTATE_0, MM_UTIL_ROTATE_NUM - 1, &rotation)) { - fprintf(stderr, "\t[IMGP_testsuite] wrong rotation %s\n", argv[9]); + + /* read input file */ + if (FALSE == _read_file(g_args.path, &g_args.data, &g_args.size)) { + fprintf(stderr, "\t[IMGP_testsuite] reading file(%s) error\n", g_args.path); goto TEST_FAIL; } - if (FALSE == _get_input_data(argv[10], 0, UINT_MAX, &start_x)) { - fprintf(stderr, "\t[IMGP_testsuite] wrong start_x %s\n", argv[10]); + + ret = mm_image_create_image(g_args.width, g_args.height, g_args.colorspace, + (unsigned char *)g_args.data, g_args.size, &_src); + if (ret != MM_UTIL_ERROR_NONE) { + fprintf(stderr, "\t[IMGP_testsuite] ERROR - mm_image_create_image\n"); goto TEST_FAIL; } - if (FALSE == _get_input_data(argv[11], 0, UINT_MAX, &start_y)) { - fprintf(stderr, "\t[IMGP_testsuite] wrong start_y %s\n", argv[11]); + + mm_image_debug_image(_src, "_src"); + + /* test image processing */ + if (strcmp(g_args.cmd, "convert") == 0) + ret = mm_util_convert_colorspace(_src, g_args.cs, &_dst); + else if (strcmp(g_args.cmd, "resize") == 0) + ret = mm_util_resize_image(_src, g_args.w, g_args.h, &_dst); + else if (strcmp(g_args.cmd, "rotate") == 0) + ret = mm_util_rotate_image(_src, g_args.rot, &_dst); + else if (strcmp(g_args.cmd, "crop") == 0) + ret = mm_util_crop_image(_src, g_args.x, g_args.y, g_args.w, g_args.h, &_dst); + else { + fprintf(stderr, "\t[IMGP_testsuite] Wrong command - %s\n", g_args.cmd); goto TEST_FAIL; } - /* read input file */ - if (FALSE == _read_file(filename, &src, &src_size)) { - fprintf(stderr, "\t[IMGP_testsuite] reading file(%s) error\n", filename); + if (ret == MM_UTIL_ERROR_NONE) { + fprintf(stderr, "\t[IMGP_testsuite] Success - %s\n", g_args.cmd); + } else { + fprintf(stderr, "\t[IMGP_testsuite] ERROR - %s\n", g_args.cmd); goto TEST_FAIL; } - fprintf(stderr, "command: %s src_width: %d, src_height: %d, src_format: %d, dst_width: %d, dst_height: %d, dst_format:%d, rotation:%d\n", command, src_width, src_height, src_format, dst_width, dst_height, dst_format, rotation); - - /* ready output file */ - snprintf(output_file, 40, "result_%s_%d_%d.raw", command, dst_width, dst_height); + if (!mm_image_is_valid_image(_dst)) { + fprintf(stderr, "\t[IMGP_testsuite] ERROR - mm_image_is_valid_image\n"); + goto TEST_FAIL; + } - if (strcmp(command, "convert") == 0) - ret = mm_util_convert_colorspace(src, src_width, src_height, src_format, dst_format, &dst, &res_w, &res_h, &res_buffer_size); - else if (strcmp(command, "resize") == 0) - ret = mm_util_resize_image(src, src_width, src_height, src_format, dst_width, dst_height, &dst, &res_w, &res_h, &res_buffer_size); - else if (strcmp(command, "rotate") == 0) - ret = mm_util_rotate_image(src, src_width, src_height, src_format, rotation, &dst, &res_w, &res_h, &res_buffer_size); - else if (strcmp(command, "crop") == 0) - ret = mm_util_crop_image(src, src_width, src_height, src_format, start_x, start_y, dst_width, dst_height, &dst, &res_w, &res_h, &res_buffer_size); + mm_image_debug_image(_dst, "_dst"); - if (ret == MM_UTIL_ERROR_NONE) { - fprintf(stderr, "Success - %s\n", command); - } else { - fprintf(stderr, "ERROR - %s\n", command); + ret = mm_image_get_image(_dst, &g_transformed.width, &g_transformed.height, + NULL, &g_transformed.data, &g_transformed.size); + if (ret != MM_UTIL_ERROR_NONE) { + fprintf(stderr, "\t[IMGP_testsuite] ERROR - mm_image_get_image\n"); goto TEST_FAIL; } + /* ready output file */ + snprintf(g_transformed.path, PATH_MAX, "result_%s_%ux%u.raw", g_args.cmd, g_transformed.width, g_transformed.height); + /* write output file */ - if (FALSE == _write_file(output_file, dst, res_buffer_size)) { - fprintf(stderr, "\t[IMGP_testsuite] writing file(%s) error\n", output_file); + if (FALSE == _write_file(g_transformed.path, (void *)g_transformed.data, g_transformed.size)) { + fprintf(stderr, "\t[IMGP_testsuite] writing file(%s) error\n", g_transformed.path); goto TEST_FAIL; } TEST_FAIL: - - IMGP_FREE(src); - IMGP_FREE(dst); - IMGP_FREE(command); - IMGP_FREE(filename); + SAFE_IMAGE_FREE(_src); + SAFE_IMAGE_FREE(_dst); + IMGP_FREE(g_transformed.data); + IMGP_FREE(g_args.data); + IMGP_FREE(g_args.cmd); + IMGP_FREE(g_args.path); return 0; } diff --git a/imgp/unittest/libmm_imgp_unittest.cpp b/imgp/unittest/libmm_imgp_unittest.cpp index 521aebd..9352169 100644 --- a/imgp/unittest/libmm_imgp_unittest.cpp +++ b/imgp/unittest/libmm_imgp_unittest.cpp @@ -41,285 +41,149 @@ class libmm_imgp_Test : public ::testing::Test { TEST(libmm_imgp_Test, mm_util_convert_colorspace_p) { int ret = MM_UTIL_ERROR_NONE; - mm_util_image_h decode_image_h = NULL; - mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_ARGB, NULL, 0, 0}; - unsigned char *data = NULL; - unsigned int width = 0; - unsigned int height = 0; - size_t size = 0;; - - ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_ARGB, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image_h); - EXPECT_EQ(ret, MM_UTIL_ERROR_NONE); - EXPECT_TRUE(mm_image_is_valid_image(decode_image_h)); + mm_util_image_h decode_image = NULL; + mm_util_image_h convert_image = NULL; - ret = mm_image_get_image(decode_image_h, &decode_image.width, &decode_image.height, NULL, (unsigned char **)&decode_image.data, &decode_image.size); + ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_ARGB, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image); EXPECT_EQ(ret, MM_UTIL_ERROR_NONE); + EXPECT_TRUE(mm_image_is_valid_image(decode_image)); - ret = mm_util_convert_colorspace((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, MM_UTIL_COLOR_RGB24, &data, &width, &height, &size); + ret = mm_util_convert_colorspace(decode_image, MM_UTIL_COLOR_RGB24, &convert_image); EXPECT_EQ(ret, MM_UTIL_ERROR_NONE); - EXPECT_TRUE(data != NULL); - EXPECT_EQ(width, 640); - EXPECT_EQ(height, 480); - EXPECT_NE(size, 0); - - mm_image_destroy_image(decode_image_h); - if (decode_image.data) - free(decode_image.data); - if (data) - free(data); + EXPECT_TRUE(mm_image_is_valid_image(convert_image)); + + mm_image_destroy_image(decode_image); + mm_image_destroy_image(convert_image); } TEST(libmm_imgp_Test, mm_util_convert_colorspace_n) { int ret = MM_UTIL_ERROR_NONE; - mm_util_image_h decode_image_h = NULL; - mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_RGB24, NULL, 0, 0}; - unsigned char *data = NULL; - unsigned int width = 0; - unsigned int height = 0; - size_t size = 0;; - - ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_ARGB, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image_h); - EXPECT_EQ(ret, MM_UTIL_ERROR_NONE); - EXPECT_TRUE(mm_image_is_valid_image(decode_image_h)); + mm_util_image_h decode_image = NULL; + mm_util_image_h convert_image = NULL; - ret = mm_image_get_image(decode_image_h, &decode_image.width, &decode_image.height, NULL, (unsigned char **)&decode_image.data, &decode_image.size); + ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_ARGB, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image); EXPECT_EQ(ret, MM_UTIL_ERROR_NONE); + EXPECT_TRUE(mm_image_is_valid_image(decode_image)); - ret = mm_util_convert_colorspace(NULL, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, MM_UTIL_COLOR_RGB24, &data, &width, &height, &size); + ret = mm_util_convert_colorspace(NULL, MM_UTIL_COLOR_RGB24, &convert_image); EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER); - ret = mm_util_convert_colorspace((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, MM_UTIL_COLOR_RGB24, NULL, &width, &height, &size); + ret = mm_util_convert_colorspace(decode_image, MM_UTIL_COLOR_RGB24, NULL); EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER); - ret = mm_util_convert_colorspace((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, MM_UTIL_COLOR_RGB24, &data, NULL, &height, &size); - EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER); - - ret = mm_util_convert_colorspace((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, MM_UTIL_COLOR_RGB24, &data, &width, NULL, &size); - EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER); - - ret = mm_util_convert_colorspace((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, MM_UTIL_COLOR_RGB24, &data, &width, &height, NULL); - EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER); - - mm_image_destroy_image(decode_image_h); - if (decode_image.data) - free(decode_image.data); + mm_image_destroy_image(decode_image); } TEST(libmm_imgp_Test, mm_util_resize_image_p) { int ret = MM_UTIL_ERROR_NONE; - mm_util_image_h decode_image_h = NULL; - mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_ARGB, NULL, 0, 0}; - unsigned char *data = NULL; - unsigned int width = 0; - unsigned int height = 0; - size_t size = 0;; - - ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_ARGB, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image_h); - EXPECT_EQ(ret, MM_UTIL_ERROR_NONE); - EXPECT_TRUE(mm_image_is_valid_image(decode_image_h)); + mm_util_image_h decode_image = NULL; + mm_util_image_h resize_image = NULL; - ret = mm_image_get_image(decode_image_h, &decode_image.width, &decode_image.height, NULL, (unsigned char **)&decode_image.data, &decode_image.size); + ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_ARGB, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image); EXPECT_EQ(ret, MM_UTIL_ERROR_NONE); + EXPECT_TRUE(mm_image_is_valid_image(decode_image)); - ret = mm_util_resize_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 320, 240, &data, &width, &height, &size); + ret = mm_util_resize_image(decode_image, 320, 240, &resize_image); EXPECT_EQ(ret, MM_UTIL_ERROR_NONE); - EXPECT_TRUE(data != NULL); - EXPECT_EQ(width, 320); - EXPECT_EQ(height, 240); - EXPECT_NE(size, 0); - - mm_image_destroy_image(decode_image_h); - if (decode_image.data) - free(decode_image.data); - if (data) - free(data); + EXPECT_TRUE(mm_image_is_valid_image(resize_image)); + + mm_image_destroy_image(decode_image); + mm_image_destroy_image(resize_image); } TEST(libmm_imgp_Test, mm_util_resize_image_n) { int ret = MM_UTIL_ERROR_NONE; - mm_util_image_h decode_image_h = NULL; - mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_RGB24, NULL, 0, 0}; - unsigned char *data = NULL; - unsigned int width = 0; - unsigned int height = 0; - size_t size = 0;; - - ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_ARGB, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image_h); - EXPECT_EQ(ret, MM_UTIL_ERROR_NONE); - EXPECT_TRUE(mm_image_is_valid_image(decode_image_h)); + mm_util_image_h decode_image = NULL; + mm_util_image_h resize_image = NULL; - ret = mm_image_get_image(decode_image_h, &decode_image.width, &decode_image.height, NULL, (unsigned char **)&decode_image.data, &decode_image.size); + ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_ARGB, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image); EXPECT_EQ(ret, MM_UTIL_ERROR_NONE); + EXPECT_TRUE(mm_image_is_valid_image(decode_image)); - ret = mm_util_resize_image(NULL, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 320, 240, &data, &width, &height, &size); - EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER); - - ret = mm_util_resize_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 0, 240, &data, &width, &height, &size); - EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER); - - ret = mm_util_resize_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 320, 0, &data, &width, &height, &size); - EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER); - - ret = mm_util_resize_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 320, 240, NULL, &width, &height, &size); - EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER); - - ret = mm_util_resize_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 320, 240, &data, NULL, &height, &size); - EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER); - - ret = mm_util_resize_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 320, 240, &data, &width, NULL, &size); + ret = mm_util_resize_image(NULL, 320, 240, &resize_image); EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER); - ret = mm_util_resize_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 320, 240, &data, &width, &height, NULL); + ret = mm_util_resize_image(decode_image, 320, 240, NULL); EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER); - mm_image_destroy_image(decode_image_h); - if (decode_image.data) - free(decode_image.data); + mm_image_destroy_image(decode_image); } TEST(libmm_imgp_Test, mm_util_rotate_image_p) { int ret = MM_UTIL_ERROR_NONE; - mm_util_image_h decode_image_h = NULL; - mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_ARGB, NULL, 0, 0}; - unsigned char *data = NULL; - unsigned int width = 0; - unsigned int height = 0; - size_t size = 0;; - - ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_ARGB, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image_h); - EXPECT_EQ(ret, MM_UTIL_ERROR_NONE); - EXPECT_TRUE(mm_image_is_valid_image(decode_image_h)); + mm_util_image_h decode_image = NULL; + mm_util_image_h rotate_image = NULL; - ret = mm_image_get_image(decode_image_h, &decode_image.width, &decode_image.height, NULL, (unsigned char **)&decode_image.data, &decode_image.size); + ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_ARGB, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image); EXPECT_EQ(ret, MM_UTIL_ERROR_NONE); + EXPECT_TRUE(mm_image_is_valid_image(decode_image)); - ret = mm_util_rotate_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, MM_UTIL_ROTATE_90, &data, &width, &height, &size); + ret = mm_util_rotate_image(decode_image, MM_UTIL_ROTATE_90, &rotate_image); EXPECT_EQ(ret, MM_UTIL_ERROR_NONE); - EXPECT_TRUE(data != NULL); - EXPECT_EQ(width, 480); - EXPECT_EQ(height, 640); - EXPECT_NE(size, 0); - - mm_image_destroy_image(decode_image_h); - if (decode_image.data) - free(decode_image.data); - if (data) - free(data); + EXPECT_TRUE(mm_image_is_valid_image(rotate_image)); + + mm_image_destroy_image(decode_image); + mm_image_destroy_image(rotate_image); } TEST(libmm_imgp_Test, mm_util_rotate_image_n) { int ret = MM_UTIL_ERROR_NONE; - mm_util_image_h decode_image_h = NULL; - mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_RGB24, NULL, 0, 0}; - unsigned char *data = NULL; - unsigned int width = 0; - unsigned int height = 0; - size_t size = 0;; - - ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_ARGB, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image_h); - EXPECT_EQ(ret, MM_UTIL_ERROR_NONE); - EXPECT_TRUE(mm_image_is_valid_image(decode_image_h)); + mm_util_image_h decode_image = NULL; + mm_util_image_h rotate_image = NULL; - ret = mm_image_get_image(decode_image_h, &decode_image.width, &decode_image.height, NULL, (unsigned char **)&decode_image.data, &decode_image.size); + ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_ARGB, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image); EXPECT_EQ(ret, MM_UTIL_ERROR_NONE); + EXPECT_TRUE(mm_image_is_valid_image(decode_image)); - ret = mm_util_rotate_image(NULL, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, MM_UTIL_ROTATE_90, &data, &width, &height, &size); + ret = mm_util_rotate_image(NULL, MM_UTIL_ROTATE_90, &rotate_image); EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER); - ret = mm_util_rotate_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, MM_UTIL_ROTATE_90, NULL, &width, &height, &size); + ret = mm_util_rotate_image(decode_image, MM_UTIL_ROTATE_90, NULL); EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER); - ret = mm_util_rotate_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, MM_UTIL_ROTATE_90, &data, NULL, &height, &size); - EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER); - - ret = mm_util_rotate_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, MM_UTIL_ROTATE_90, &data, &width, NULL, &size); - EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER); - - ret = mm_util_rotate_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, MM_UTIL_ROTATE_90, &data, &width, &height, NULL); - EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER); - - mm_image_destroy_image(decode_image_h); - if (decode_image.data) - free(decode_image.data); + mm_image_destroy_image(decode_image); } TEST(libmm_imgp_Test, mm_util_crop_image_p) { int ret = MM_UTIL_ERROR_NONE; - mm_util_image_h decode_image_h = NULL; - mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_ARGB, NULL, 0, 0}; - unsigned char *data = NULL; - unsigned int width = 0; - unsigned int height = 0; - size_t size = 0;; - - ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_ARGB, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image_h); - EXPECT_EQ(ret, MM_UTIL_ERROR_NONE); - EXPECT_TRUE(mm_image_is_valid_image(decode_image_h)); + mm_util_image_h decode_image = NULL; + mm_util_image_h crop_image = NULL; - ret = mm_image_get_image(decode_image_h, &decode_image.width, &decode_image.height, NULL, (unsigned char **)&decode_image.data, &decode_image.size); + ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_ARGB, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image); EXPECT_EQ(ret, MM_UTIL_ERROR_NONE); + EXPECT_TRUE(mm_image_is_valid_image(decode_image)); - ret = mm_util_crop_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 0, 0, 320, 240, &data, &width, &height, &size); + ret = mm_util_crop_image(decode_image, 0, 0, 320, 240, &crop_image); EXPECT_EQ(ret, MM_UTIL_ERROR_NONE); - EXPECT_TRUE(data != NULL); - EXPECT_EQ(width, 320); - EXPECT_EQ(height, 240); - EXPECT_NE(size, 0); - - mm_image_destroy_image(decode_image_h); - if (decode_image.data) - free(decode_image.data); - if (data) - free(data); + EXPECT_TRUE(mm_image_is_valid_image(crop_image)); + + mm_image_destroy_image(decode_image); + mm_image_destroy_image(crop_image); } TEST(libmm_imgp_Test, mm_util_crop_image_n) { int ret = MM_UTIL_ERROR_NONE; - mm_util_image_h decode_image_h = NULL; - mm_image_info_s decode_image = {0, 0, MM_UTIL_COLOR_RGB24, NULL, 0, 0}; - unsigned char *data = NULL; - unsigned int width = 0; - unsigned int height = 0; - size_t size = 0;; - - ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_ARGB, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image_h); - EXPECT_EQ(ret, MM_UTIL_ERROR_NONE); - EXPECT_TRUE(mm_image_is_valid_image(decode_image_h)); + mm_util_image_h decode_image = NULL; + mm_util_image_h crop_image = NULL; - ret = mm_image_get_image(decode_image_h, &decode_image.width, &decode_image.height, NULL, (unsigned char **)&decode_image.data, &decode_image.size); + ret = mm_util_decode_from_jpeg_file(DECODE_FILE_PATH, MM_UTIL_COLOR_ARGB, MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &decode_image); EXPECT_EQ(ret, MM_UTIL_ERROR_NONE); + EXPECT_TRUE(mm_image_is_valid_image(decode_image)); - ret = mm_util_crop_image(NULL, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 0, 0, 320, 240, &data, &width, &height, &size); - EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER); - - ret = mm_util_crop_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 0, 0, 0, 240, &data, &width, &height, &size); - EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER); - - ret = mm_util_crop_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 0, 0, 320, 0, &data, &width, &height, &size); - EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER); - - ret = mm_util_crop_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 0, 0, 320, 240, NULL, &width, &height, &size); - EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER); - - ret = mm_util_crop_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 0, 0, 320, 240, &data, NULL, &height, &size); - EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER); - - ret = mm_util_crop_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 0, 0, 320, 240, &data, &width, NULL, &size); + ret = mm_util_crop_image(NULL, 0, 0, 320, 240, &crop_image); EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER); - ret = mm_util_crop_image((const unsigned char *)decode_image.data, decode_image.width, decode_image.height, MM_UTIL_COLOR_ARGB, 0, 0, 320, 240, &data, &width, &height, NULL); + ret = mm_util_crop_image(decode_image, 0, 0, 320, 240, NULL); EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER); - mm_image_destroy_image(decode_image_h); - if (decode_image.data) - free(decode_image.data); + mm_image_destroy_image(decode_image); } int main(int argc, char **argv) diff --git a/jpeg/mm_util_jpeg.c b/jpeg/mm_util_jpeg.c old mode 100755 new mode 100644 index a50eb0d..82b9300 --- a/jpeg/mm_util_jpeg.c +++ b/jpeg/mm_util_jpeg.c @@ -465,23 +465,10 @@ static int __mm_image_decode_with_libjpeg(mm_util_jpeg_cont_format_e control_for return ret; } -static int __mm_util_jpeg_convert_colorspace(mm_util_image_h image, mm_util_image_h *converted) -{ - int ret = MM_UTIL_ERROR_NONE; - mm_image_info_s *_image = (mm_image_info_s *)image; - unsigned int dst_w = 0, dst_h = 0; - unsigned char *dst_data = NULL; - size_t dst_data_size = 0; - - ret = mm_util_convert_colorspace(_image->data, _image->width, _image->height, MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NV12, &dst_data, &dst_w, &dst_h, &dst_data_size); - mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "fail to mm_util_convert_colorspace [%d]", ret); - - return mm_image_create_image(dst_w, dst_h, MM_UTIL_COLOR_NV12, dst_data, dst_data_size, converted); -} - int mm_util_jpeg_encode_to_file(mm_image_info_s *decoded, int quality, const char *filename) { int ret = MM_UTIL_ERROR_NONE; + mm_image_info_s *_converted_image = NULL; mm_util_fenter(); @@ -499,16 +486,15 @@ int mm_util_jpeg_encode_to_file(mm_image_info_s *decoded, int quality, const cha mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "mm_util_safe_fopen fail (%d)", ret); if (decoded->color == MM_UTIL_COLOR_NV12) { - unsigned int res_w = 0; - unsigned int res_h = 0; - size_t res_buffer_size = 0; - unsigned char *dst = NULL; - - ret = mm_util_convert_colorspace(decoded->data, decoded->width, decoded->height, MM_UTIL_COLOR_NV12, MM_UTIL_COLOR_YUV420, &dst, &res_w, &res_h, &res_buffer_size); - ret = __mm_image_encode_with_libjpeg(MM_UTIL_JPEG_FILE, dst, res_w, res_h, MM_UTIL_COLOR_YUV420, quality, fp, NULL, NULL); - - MMUTIL_SAFE_FREE(dst); + ret = mm_util_convert_colorspace(decoded, MM_UTIL_COLOR_YUV420, (mm_util_image_h *)&_converted_image); + if (ret != MM_UTIL_ERROR_NONE) { + mm_util_error("mm_util_convert_image failed (%d)", ret); + mm_util_safe_fclose(fp); + return ret; + } + ret = __mm_image_encode_with_libjpeg(MM_UTIL_JPEG_FILE, _converted_image->data, _converted_image->width, _converted_image->height, MM_UTIL_COLOR_YUV420, quality, fp, NULL, NULL); + mm_image_destroy_image(_converted_image); } else { ret = __mm_image_encode_with_libjpeg(MM_UTIL_JPEG_FILE, decoded->data, decoded->width, decoded->height, decoded->color, quality, fp, NULL, NULL); } @@ -533,8 +519,8 @@ int mm_util_jpeg_encode_to_memory(void **mem, unsigned int *size, unsigned char mm_util_retvm_if(size == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid size"); - decoded.width = (unsigned long)width; - decoded.height = (unsigned long)height; + decoded.width = width; + decoded.height = height; decoded.color = color; decoded.data = src; @@ -549,6 +535,7 @@ int mm_util_jpeg_encode_to_memory(void **mem, unsigned int *size, unsigned char int mm_util_encode_to_jpeg_memory(mm_image_info_s *decoded, int quality, void **mem, size_t *size) { int ret = MM_UTIL_ERROR_NONE; + mm_image_info_s *_converted_image = NULL; mm_util_fenter(); @@ -563,16 +550,11 @@ int mm_util_encode_to_jpeg_memory(mm_image_info_s *decoded, int quality, void ** mm_util_debug("#START# libjpeg"); if (decoded->color == MM_UTIL_COLOR_NV12) { - unsigned int res_w = 0; - unsigned int res_h = 0; - size_t res_buffer_size = 0; - unsigned char *dst = NULL; - - ret = mm_util_convert_colorspace(decoded->data, decoded->width, decoded->height, MM_UTIL_COLOR_NV12, MM_UTIL_COLOR_YUV420, &dst, &res_w, &res_h, &res_buffer_size); - ret = __mm_image_encode_with_libjpeg(MM_UTIL_JPEG_MEM, dst, res_w, res_h, MM_UTIL_COLOR_YUV420, quality, NULL, mem, size); - - MMUTIL_SAFE_FREE(dst); + ret = mm_util_convert_colorspace(decoded, MM_UTIL_COLOR_YUV420, (mm_util_image_h *)&_converted_image); + mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "mm_util_convert_image fail (%d)", ret); + ret = __mm_image_encode_with_libjpeg(MM_UTIL_JPEG_MEM, _converted_image->data, _converted_image->width, _converted_image->height, MM_UTIL_COLOR_YUV420, quality, NULL, mem, size); + mm_image_destroy_image(_converted_image); } else { ret = __mm_image_encode_with_libjpeg(MM_UTIL_JPEG_MEM, decoded->data, decoded->width, decoded->height, decoded->color, quality, NULL, mem, size); } @@ -608,7 +590,7 @@ int mm_util_decode_from_jpeg_file(const char *file_path, mm_util_color_format_e if (fmt == MM_UTIL_COLOR_NV12) { ret = __mm_image_decode_with_libjpeg(MM_UTIL_JPEG_FILE, fp, NULL, 0, MM_UTIL_COLOR_YUV420, downscale, &_decoded); if (ret == MM_UTIL_ERROR_NONE) - ret = __mm_util_jpeg_convert_colorspace(_decoded, decoded); + ret = mm_util_convert_colorspace(_decoded, MM_UTIL_COLOR_NV12, decoded); mm_image_destroy_image(_decoded); } else { ret = __mm_image_decode_with_libjpeg(MM_UTIL_JPEG_FILE, fp, NULL, 0, fmt, downscale, decoded); @@ -643,7 +625,7 @@ int mm_util_decode_from_jpeg_memory(void *memory, const size_t src_size, mm_util if (fmt == MM_UTIL_COLOR_NV12) { ret = __mm_image_decode_with_libjpeg(MM_UTIL_JPEG_MEM, NULL, memory, src_size, MM_UTIL_COLOR_YUV420, downscale, &_decoded); if (ret == MM_UTIL_ERROR_NONE) - ret = __mm_util_jpeg_convert_colorspace(_decoded, decoded); + ret = mm_util_convert_colorspace(_decoded, MM_UTIL_COLOR_NV12, decoded); mm_image_destroy_image(_decoded); } else { ret = __mm_image_decode_with_libjpeg(MM_UTIL_JPEG_MEM, NULL, memory, src_size, fmt, downscale, decoded); -- 2.7.4