return MM_UTIL_ERROR_INVALID_PARAMETER;
}
+ mm_util_fenter();
+
switch (angle) {
case MM_UTIL_ROTATE_0:
case MM_UTIL_ROTATE_180:
_imgp_info_s->buffer_size = 0;
_imgp_info_s->angle = angle;
- mm_util_debug("src_width[%u] src_height[%u] dst_width[%u] dst_height[%u] rotation_value[%d]", _imgp_info_s->src_width, _imgp_info_s->src_height, _imgp_info_s->dst_width, _imgp_info_s->dst_height, _imgp_info_s->angle);
+ mm_util_debug("src_w[%u] src_h[%u] dst_w[%u] dst_h[%u] rotation[%d]", _imgp_info_s->src_width, _imgp_info_s->src_height, _imgp_info_s->dst_width, _imgp_info_s->dst_height, _imgp_info_s->angle);
return ret;
}
unsigned int src_width = 0, src_height = 0;
mm_util_color_format_e src_format = -1;
unsigned int src_index = 0, dst_index = 0;
+ unsigned int res_w = 0;
+ unsigned int res_h = 0;
+ unsigned char *res_buffer = NULL;
+ size_t res_buffer_size = 0;
if (handle == NULL) {
mm_util_error("Invalid arguments [tag null]");
return MM_UTIL_ERROR_INVALID_OPERATION;
}
memcpy(dst_buf[src_index], handle->src->data, handle->src->size);
+
if (handle->set_crop) {
dst_index++;
- __mm_util_get_crop_image_size(src_format, handle->dst_width, handle->dst_height, &dst_buf_size);
- dst_buf[dst_index] = calloc(1, dst_buf_size);
- if (dst_buf[dst_index] == NULL) {
- mm_util_error("[multi func] memory allocation error");
- __mm_destroy_temp_buffer(dst_buf);
- return MM_UTIL_ERROR_INVALID_OPERATION;
- }
- ret = mm_util_crop_image(dst_buf[src_index], src_width, src_height, src_format,
- handle->start_x, handle->start_y, &handle->dst_width, &handle->dst_height, dst_buf[dst_index]);
+
+ ret = mm_util_crop_image(dst_buf[src_index], src_width, src_height, src_format, handle->start_x, handle->start_y, handle->dst_width, handle->dst_height, &res_buffer, &res_w, &res_h, &res_buffer_size);
if (ret != MM_UTIL_ERROR_NONE) {
__mm_destroy_temp_buffer(dst_buf);
mm_util_error("mm_util_crop_image failed");
return ret;
}
+ dst_buf[dst_index] = res_buffer;
+
src_index = dst_index;
src_width = handle->dst_width;
src_height = handle->dst_height;
GModule *_module = NULL;
unsigned char *output_buffer = NULL;
unsigned int output_buffer_size = 0;
+ 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");
goto ERROR;
}
- mm_util_debug("Sucess __mm_set_imgp_info_s");
-
ret = __mm_util_get_buffer_size(dst_format, src_width, src_height, &output_buffer_size);
if (ret != MM_UTIL_ERROR_NONE) {
mm_util_error("__mm_util_get_buffer_size failed");
}
if ((_imgp_info_s->dst_width != _imgp_info_s->output_stride || _imgp_info_s->dst_height != _imgp_info_s->output_elevation) && __mm_is_rgb_format(src_format)) {
- 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, dst);
+ 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);
if (ret != MM_UTIL_ERROR_NONE) {
mm_util_error("mm_util_crop_image failed");
ret = MM_UTIL_ERROR_INVALID_OPERATION;
goto ERROR;
}
+ memcpy(dst, res_buffer, res_buffer_size);
} else {
memcpy(dst, output_buffer, _imgp_info_s->buffer_size);
}
__mm_util_imgp_finalize(_module, _imgp_info_s);
MMUTIL_SAFE_FREE(output_buffer);
+ MMUTIL_SAFE_FREE(res_buffer);
mm_util_fleave();
GModule *_module = NULL;
unsigned char *output_buffer = NULL;
unsigned int output_buffer_size = 0;
+ 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");
goto ERROR;
}
- mm_util_debug("Sucess __mm_set_imgp_info_s");
-
if (g_strrstr(g_module_name(_module), GST)) {
if (__mm_gst_can_resize_format(_imgp_info_s->src_format) == FALSE) {
mm_util_error("#RESIZE ERROR# IMAGE_NOT_SUPPORT_FORMAT");
}
if ((_imgp_info_s->dst_width != _imgp_info_s->output_stride || _imgp_info_s->dst_height != _imgp_info_s->output_elevation) && __mm_is_rgb_format(src_format)) {
- 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, dst);
- *dst_width = _imgp_info_s->dst_width;
- *dst_height = _imgp_info_s->dst_height;
+ 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);
+ if (ret != MM_UTIL_ERROR_NONE) {
+ mm_util_error("mm_util_crop_image failed");
+ ret = MM_UTIL_ERROR_INVALID_OPERATION;
+ goto ERROR;
+ }
+ memcpy(dst, res_buffer, res_buffer_size);
+ *dst_width = res_w;
+ *dst_height = res_h;
} else {
memcpy(dst, output_buffer, _imgp_info_s->buffer_size);
*dst_width = _imgp_info_s->dst_width;
__mm_util_imgp_finalize(_module, _imgp_info_s);
MMUTIL_SAFE_FREE(output_buffer);
+ MMUTIL_SAFE_FREE(res_buffer);
mm_util_fleave();
GModule *_module = NULL;
unsigned char *output_buffer = NULL;
unsigned int output_buffer_size = 0;
+ 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(dst_height == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_height");
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_debug("src_width [%d] src_height [%d] src_format[%d]", src_width, src_height, src_format);
+ 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);
if (_mm_util_imgp_func == NULL) {
goto ERROR;
}
- mm_util_debug("__mm_confirm_dst_width_height");
ret = __mm_confirm_dst_width_height(src_width, src_height, dst_width, dst_height, angle);
if (ret != MM_UTIL_ERROR_NONE) {
mm_util_error("dst_width || dest_height size Error");
ret = MM_UTIL_ERROR_INVALID_OPERATION;
goto ERROR;
}
- mm_util_debug("Sucess __mm_set_imgp_info_s");
if (g_strrstr(g_module_name(_module), GST)) {
if (__mm_gst_can_rotate_format(_imgp_info_s->src_format) == FALSE) {
start_x = 0;
start_y = _imgp_info_s->output_elevation - _imgp_info_s->dst_height;
}
- 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, dst);
+ 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);
+ if (ret != MM_UTIL_ERROR_NONE) {
+ mm_util_error("mm_util_crop_image failed");
+ ret = MM_UTIL_ERROR_INVALID_OPERATION;
+ goto ERROR;
+ }
+ memcpy(dst, res_buffer, res_buffer_size);
*dst_width = _imgp_info_s->dst_width;
*dst_height = _imgp_info_s->dst_height;
} else {
}
/* Output result*/
- mm_util_debug("dst: %p dst_width: %d, dst_height: %d, output_stride: %d, output_elevation: %d",
- dst, _imgp_info_s->dst_width, _imgp_info_s->dst_height, _imgp_info_s->output_stride, _imgp_info_s->output_elevation);
+ mm_util_debug("dst[%p] dst_w[%u] dst_h[%u] output_stride[%u] output_elevation[%u]", dst, _imgp_info_s->dst_width, _imgp_info_s->dst_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);
+ MMUTIL_SAFE_FREE(res_buffer);
mm_util_fleave();
}
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 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 ret = MM_UTIL_ERROR_NONE;
+ unsigned int 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((IS_MM_UTIL_COLOR_FORMAT(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((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_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);
+ 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) {
case MM_UTIL_COLOR_RGB24: {
- ret = __mm_util_crop_rgb888(src, src_width, src_height, crop_start_x, crop_start_y, *crop_dest_width, *crop_dest_height, dst);
+ ret = __mm_util_crop_rgb888(src, src_width, src_height, crop_start_x, crop_start_y, res_w, res_h, dst_buffer);
break;
}
case MM_UTIL_COLOR_RGB16: {
- ret = __mm_util_crop_rgb565(src, src_width, src_height, crop_start_x, crop_start_y, *crop_dest_width, *crop_dest_height, dst);
+ ret = __mm_util_crop_rgb565(src, src_width, src_height, crop_start_x, crop_start_y, res_w, res_h, dst_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_rgba32(src, src_width, src_height, crop_start_x, crop_start_y, *crop_dest_width, *crop_dest_height, dst);
+ ret = __mm_util_crop_rgba32(src, src_width, src_height, crop_start_x, crop_start_y, res_w, res_h, dst_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);
- *crop_dest_width = ((*crop_dest_width+1)>>1)<<1;
- mm_util_debug("Image isplay is suceeded when YUV crop width value %d", *crop_dest_width);
+ 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);
- *crop_dest_height = ((*crop_dest_height+1)>>1)<<1;
- mm_util_debug("Image isplay is suceeded when YUV crop height value %d", *crop_dest_height);
+ 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);
}
- ret = __mm_util_crop_yuv420(src, src_width, src_height, crop_start_x, crop_start_y, *crop_dest_width, *crop_dest_height, dst);
+ 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);
break;
}
default:
mm_util_debug("Not supported format");
+ MMUTIL_SAFE_FREE(dst_buffer);
ret = MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
}
+ *result_buf_size = (size_t)dst_buf_size;
+ *dst = dst_buffer;
+ *result_buf_width = res_w;
+ *result_buf_height = res_h;
+
mm_util_fleave();
return ret;
*imgsize = size;
break;
-
case MM_UTIL_COLOR_NV12:
case MM_UTIL_COLOR_NV12_TILED:
case MM_UTIL_COLOR_NV21: