pixels = MagickMalloc(_pixels_size);
if (pixels == NULL) {
- mm_util_error("Error: calloc failed.");
+ mm_util_error("Error: MagickMalloc failed.");
goto ERROR;
}
return ret;
}
+
+int mm_util_resize_and_rotate_P_P(const char *src_path, unsigned int req_width, unsigned int req_height, const char *dst_path)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ Image *_image = NULL;
+ Image *_resized_image = NULL;
+ Image *_rotated_image = NULL;
+ ExceptionInfo exception;
+ mm_util_magick_rotate_type angle = MM_UTIL_ROTATE_0;
+
+ mm_util_retvm_if(!MMUTIL_STRING_VALID(src_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_path");
+ mm_util_retvm_if((req_width == 0) || (req_height == 0), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid size W[%d] H[%d]", req_width, req_height);
+ mm_util_retvm_if(!MMUTIL_STRING_VALID(dst_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_path");
+
+ mm_util_sec_debug("src_path [%s] req_width [%u] req_height [%u] dst_path [%s]", src_path, req_width, req_height, dst_path);
+
+ __mm_util_init(&exception);
+
+ _image = __mm_util_read_image_from_file(src_path);
+ if (_image == NULL) {
+ mm_util_error("Error: __mm_util_read_image_from_file failed.");
+ ret = MM_UTIL_ERROR_INVALID_OPERATION;
+ goto ERROR;
+ }
+
+ if ((_image->columns < req_width) || (_image->rows < req_height)) {
+ mm_util_error("Wrong Size. image [%lu * %lu], request [%u * %u]", _image->columns, _image->rows, req_width, req_height);
+ ret = MM_UTIL_ERROR_INVALID_PARAMETER;
+ goto ERROR;
+ }
+
+ _resized_image = __mm_util_resize_image(_image, req_width, req_height);
+ if (_resized_image == NULL) {
+ mm_util_error("Error: __mm_util_resize_image failed.");
+ ret = MM_UTIL_ERROR_INVALID_OPERATION;
+ goto ERROR;
+ }
+
+ switch(_resized_image->orientation) {
+ case TopRightOrientation:
+ case RightTopOrientation:
+ angle = MM_UTIL_ROTATE_90;
+ break;
+ case BottomRightOrientation:
+ case RightBottomOrientation:
+ angle = MM_UTIL_ROTATE_180;
+ break;
+ case BottomLeftOrientation:
+ case LeftBottomOrientation:
+ angle = MM_UTIL_ROTATE_270;
+ break;
+ case TopLeftOrientation:
+ case LeftTopOrientation:
+ break;
+ default:
+ mm_util_warn("Not supported orientation %d. so apply MM_UTIL_ROTATE_0", _resized_image->orientation);
+ break;
+ }
+
+ if (angle != MM_UTIL_ROTATE_0) {
+ _rotated_image = __mm_util_rotate_image(_resized_image, angle);
+ if (_rotated_image == NULL) {
+ mm_util_error("Error: __mm_util_resize_image failed.");
+ ret = MM_UTIL_ERROR_INVALID_OPERATION;
+ goto ERROR;
+ }
+ }
+
+ ret = __mm_util_write_image_to_file(((_rotated_image) ? _rotated_image : _resized_image), dst_path);
+
+ERROR:
+
+ DestroyImageList(_image);
+ __mm_util_finalize(_resized_image, _rotated_image, &exception);
+
+ mm_util_fleave();
+
+ return ret;
+}
static int _magick_resize_B_P_test(unsigned int req_width, unsigned int req_height, mm_util_color_format_e req_format);
static int _magick_resize_B_B_test(unsigned int req_width, unsigned int req_height, mm_util_color_format_e req_format);
static int _magick_convert_B_B_test(mm_util_color_format_e in_format, mm_util_color_format_e out_format);
+static int _magick_resize_and_rotate_P_P_test(unsigned int req_width, unsigned int req_height);
static char *__get_dst_path(mm_util_magick_rotate_type angle)
{
return ret;
}
+static int _magick_resize_and_rotate_P_P_test(unsigned int req_width, unsigned int req_height)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ char * src_path = "/opt/usr/home/owner/origin.jpg";
+ char dst_path[1024] = {0, };
+ memset(dst_path, 0x00, sizeof(dst_path));
+ snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/media/resize_rotate_pp_%u_%u.jpg", req_width, req_height);
+
+ printf("* Resize P P Test * W * H = [%u * %u], path = [%s] \n", req_width, req_height, dst_path);
+
+ ret = mm_util_resize_and_rotate_P_P(src_path, req_width, req_height, dst_path);
+ if (ret != MM_UTIL_ERROR_NONE)
+ printf("Fail mm_util_resize_P_P [%d]\n", ret);
+
+ return ret;
+}
+
int main(int argc, char *argv[])
{
int ret = MM_UTIL_ERROR_NONE;
ret = _magick_convert_B_B_test(MM_UTIL_COLOR_RGBA, MM_UTIL_COLOR_RGB24);
ret = _magick_convert_B_B_test(MM_UTIL_COLOR_BGRA, MM_UTIL_COLOR_RGB24);
+ } else if (strcmp(argv[1], "10") == 0) {
+ ret = _magick_resize_and_rotate_P_P_test(3000, 2000);
+ ret = _magick_resize_and_rotate_P_P_test(199, 299);
+ ret = _magick_resize_and_rotate_P_P_test(3, 2);
+ ret = _magick_resize_and_rotate_P_P_test(10000, 10000);
+ ret = _magick_resize_and_rotate_P_P_test(0, 2000); //invalid parameter
+
} else {
printf("Invalid parameter\n");
}