return ret;
}
-static int __mm_confirm_dst_width_height(unsigned int src_width, unsigned int src_height, unsigned int *dst_width, unsigned int *dst_height, mm_util_img_rotate_type angle)
-{
- int ret = MM_UTIL_ERROR_NONE;
-
- mm_util_retvm_if(dst_width == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_width");
- mm_util_retvm_if(dst_height == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_height");
-
- mm_util_fenter();
-
- switch (angle) {
- case MM_UTIL_ROTATE_0:
- case MM_UTIL_ROTATE_180:
- case MM_UTIL_ROTATE_FLIP_HORZ:
- case MM_UTIL_ROTATE_FLIP_VERT:
- if (*dst_width != src_width) {
- mm_util_debug("*dst_width: %d", *dst_width);
- *dst_width = src_width;
- mm_util_debug("#Confirmed# *dst_width: %d", *dst_width);
- }
- if (*dst_height != src_height) {
- mm_util_debug("*dst_height: %d", *dst_height);
- *dst_height = src_height;
- mm_util_debug("#Confirmed# *dst_height: %d", *dst_height);
- }
- break;
- case MM_UTIL_ROTATE_90:
- case MM_UTIL_ROTATE_270:
- if (*dst_width != src_height) {
- mm_util_debug("*dst_width: %d", *dst_width);
- *dst_width = src_height;
- mm_util_debug("#Confirmed# *dst_width: %d", *dst_width);
- }
- if (*dst_height != src_width) {
- mm_util_debug("*dst_height: %d", *dst_height);
- *dst_height = src_width;
- mm_util_debug("#Confirmed# *dst_height: %d", *dst_height);
- }
- break;
-
- default:
- mm_util_error("Not supported rotate value");
- return MM_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- return ret;
-}
-
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)
{
int ret = MM_UTIL_ERROR_NONE;
dst_buf[dst_index] = res_buffer;
src_index = dst_index;
- src_width = handle->dst_width;
- src_height = handle->dst_height;
+ src_width = res_w;
+ src_height = res_h;
} else if (handle->set_resize) {
dst_index++;
mm_util_get_image_size(src_format, handle->dst_width, handle->dst_height, &res_buffer_size);
if (handle->set_convert) {
dst_index++;
+
mm_util_get_image_size(handle->dst_format, src_width, src_height, &res_buffer_size);
dst_buf[dst_index] = calloc(1, res_buffer_size);
if (dst_buf[dst_index] == NULL) {
if (handle->set_rotate) {
dst_index++;
- switch (handle->rotation) {
- case MM_UTIL_ROTATION_90:
- case MM_UTIL_ROTATION_270:
- mm_util_get_image_size(src_format, src_height, src_width, &res_buffer_size);
- break;
- default:
- mm_util_get_image_size(src_format, src_width, src_height, &res_buffer_size);
- break;
- }
- dst_buf[dst_index] = calloc(1, res_buffer_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_rotate_image(dst_buf[src_index], src_width, src_height, src_format, dst_buf[dst_index], &handle->dst_width, &handle->dst_height, handle->rotation);
+ ret = mm_util_rotate_image(dst_buf[src_index], src_width, src_height, src_format, handle->rotation, &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_rotate_image failed");
return ret;
}
+
+ dst_buf[dst_index] = res_buffer;
src_index = dst_index;
- src_width = handle->dst_width;
- src_height = handle->dst_height;
+ src_width = res_w;
+ src_height = res_h;
}
if (dst_buf[dst_index] != NULL && res_buffer_size != 0) {
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, unsigned char *dst, unsigned int *dst_width, unsigned int *dst_height, mm_util_img_rotate_type angle)
+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 ret = MM_UTIL_ERROR_NONE;
IMGPInfoFunc _mm_util_imgp_func = NULL;
mm_util_retvm_if(src_height == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_height");
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(dst_width == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_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_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);
goto ERROR;
}
- 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_PARAMETER;
- goto ERROR;
+ if ((angle == MM_UTIL_ROTATE_90) || (angle == MM_UTIL_ROTATE_270)) {
+ res_w = src_height;
+ res_h = src_width;
+ } else {
+ res_w = src_width;
+ res_h = src_height;
}
- ret = __mm_set_imgp_info_s(_imgp_info_s, src_format, src_width, src_height, src_format, *dst_width, *dst_height, angle);
+ ret = __mm_set_imgp_info_s(_imgp_info_s, src_format, src_width, src_height, src_format, res_w, res_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");
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");
+ MMUTIL_SAFE_FREE(output_buffer);
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;
+
+ MMUTIL_SAFE_FREE(output_buffer);
+ *dst = res_buffer;
+ *result_buf_size = res_buffer_size;
} else {
- memcpy(dst, output_buffer, _imgp_info_s->buffer_size);
- *dst_width = _imgp_info_s->dst_width;
- *dst_height = _imgp_info_s->dst_height;
+ *dst = output_buffer;
+ *result_buf_size = _imgp_info_s->buffer_size;
}
+ *result_buf_width = res_w;
+ *result_buf_height = res_h;
+
/* Output result*/
- 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);
+ 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);
- MMUTIL_SAFE_FREE(res_buffer);
-
mm_util_fleave();
return ret;
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(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 > 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);